dolibarr 24.0.0-beta
consumption.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2013 Philippe Berthet <berthet@systune.be>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2013-2015 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
6 * Copyright (C) 2015-2017 Ferran Marcet <fmarcet@2byte.es>
7 * Copyright (C) 2021-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require "../main.inc.php";
39require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
43
44// Load translation files required by the page
45$langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
46
47$action = GETPOST('action', 'aZ09');
48$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
49$optioncss = GETPOST('optioncss', 'alpha');
50
51// Security check
52$socid = GETPOSTINT('socid');
53if ($user->socid) {
54 $socid = $user->socid;
55}
56
57// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
58$hookmanager->initHooks(array('thirdpartyconsumption', 'consumptionthirdparty', 'globalcard'));
59
60$result = restrictedArea($user, 'societe', $socid, '&societe');
61$object = new Societe($db);
62if ($socid > 0) {
63 $object->fetch($socid);
64}
65
66// Sort & Order fields
67$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
68$sortfield = GETPOST('sortfield', 'aZ09comma');
69$sortorder = GETPOST('sortorder', 'aZ09comma');
70$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
71
72if (empty($page) || $page == -1) {
73 $page = 0;
74}
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78if (!$sortorder) {
79 $sortorder = 'DESC';
80}
81if (!$sortfield) {
82 $sortfield = 'dateprint';
83}
84
85// Search fields
86$sref = GETPOST("sref");
87$sprod_fulldescr = GETPOST("sprod_fulldescr");
88$month = GETPOSTINT('month');
89$year = GETPOSTINT('year');
90
91// Clean up on purge search criteria ?
92if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
93 $sref = '';
94 $sprod_fulldescr = '';
95 $year = '';
96 $month = '';
97}
98
99// Customer or supplier selected in drop box
100$thirdTypeSelect = GETPOST("third_select_id", 'aZ09');
101$type_element = GETPOST('type_element') ? GETPOST('type_element') : '';
102
103/*
104 * Actions
105 */
106
107$parameters = array('id' => $socid);
108$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
109if ($reshook < 0) {
110 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111}
112
113
114
115/*
116 * View
117 */
118
119$form = new Form($db);
120$formother = new FormOther($db);
121$productstatic = new Product($db);
122
123$title = $langs->trans("Referers", $object->name);
124if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
125 $title = $object->name." - ".$title;
126}
127$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
128llxHeader('', $title, $help_url);
129
130if (empty($socid)) {
132 exit;
133}
134
135$head = societe_prepare_head($object);
136print dol_get_fiche_head($head, 'consumption', $langs->trans("ThirdParty"), -1, 'company');
137
138$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
139
140dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
141
142print '<div class="fichecenter">';
143
144print '<div class="underbanner clearboth"></div>';
145print '<table class="border centpercent tableforfield">';
146
147// Type Prospect/Customer/Supplier
148print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
149print $object->getTypeUrl(1);
150print '</td></tr>';
151
152//if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'read')) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
153$elementTypeArray = array();
154
155$sql = '';
156$where = '';
157
158if ($object->client) {
159 print '<tr><td class="titlefield">';
160 print $langs->trans('CustomerCode').'</td><td colspan="3">';
161 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
162 $tmpcheck = $object->check_codeclient();
163 if ($tmpcheck != 0 && $tmpcheck != -5) {
164 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
165 }
166 print '</td></tr>';
167 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
168 $resql = $db->query($sql);
169 if (!$resql) {
171 }
172
173 $obj = $db->fetch_object($resql);
174 $nbFactsClient = $obj->nb;
175 $thirdTypeArray = array();
176 $thirdTypeArray['customer'] = $langs->trans("customer");
177 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
178 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
179 }
180 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
181 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
182 }
183 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
184 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
185 }
186 if (isModEnabled('shipping') && $user->hasRight('expedition', 'lire')) {
187 $elementTypeArray['shipment'] = $langs->transnoentitiesnoconv('Shipments');
188 }
189 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
190 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
191 }
192}
193
194if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')) {
195 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
196}
197
198if ($object->fournisseur) {
199 $langs->load("supplier_proposal");
200 print '<tr><td class="titlefield">';
201 print $langs->trans('SupplierCode').'</td><td colspan="3">';
202 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
203 $tmpcheck = $object->check_codefournisseur();
204 if ($tmpcheck != 0 && $tmpcheck != -5) {
205 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
206 }
207 print '</td></tr>';
208 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
209 $resql = $db->query($sql);
210 if (!$resql) {
212 }
213
214 $obj = $db->fetch_object($resql);
215 $nbCmdsFourn = $obj->nb;
216 $thirdTypeArray['supplier'] = $langs->trans("supplier");
217 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
218 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
219 }
220 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
221 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
222 }
223 if (isModEnabled('reception') && $user->hasRight('reception', 'lire')) {
224 $langs->load('receptions');
225 $elementTypeArray['reception'] = $langs->transnoentitiesnoconv('Receptions');
226 }
227 if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
228 $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
229 }
230}
231print '</table>';
232
233print '</div>';
234
235print dol_get_fiche_end();
236print '<br>';
237
238
239print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
240print '<input type="hidden" name="token" value="'.newToken().'">';
241
242$sql_select = '';
243$documentstaticline = '';
244$tables_from = '';
245$dateprint = '';
246$doc_number = '';
247/*if ($type_element == 'action')
248{ // Customer : show products from invoices
249 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
250 $documentstatic=new ActionComm($db);
251 $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
252 $tables_from = MAIN_DB_PREFIX."actioncomm as f";
253 $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
254 $dateprint = 'f.datep';
255 $doc_number='f.id';
256}*/
257$documentstatic = null;
258if ($type_element == 'fichinter') { // Customer : show products from invoices
259 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
260 $documentstatic = new Fichinter($db);
261 $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, NULL as paid, ';
262 $sql_select .= 'NULL as fk_product, NULL as info_bits, NULL as date_start, NULL as date_end, NULL as prod_qty, NULL as total_ht, ';
263 $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines.
264 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
265 $where .= " AND f.entity = ".$conf->entity;
266 $dateprint = 'f.datec';
267 $doc_number = 'f.ref';
268}
269if ($type_element == 'invoice') { // Customer : show products from invoices
270 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
271 $documentstatic = new Facture($db);
272 $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, d.fk_remise_except, ';
273 $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
274 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
275 $where .= " AND d.fk_facture = f.rowid";
276 $where .= " AND f.entity IN (".getEntity('invoice').")";
277 $dateprint = 'f.datef';
278 $doc_number = 'f.ref';
279 $thirdTypeSelect = 'customer';
280}
281if ($type_element == 'propal') {
282 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
283 $documentstatic = new Propal($db);
284 $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, NULL as paid,';
285 $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
286 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
287 $where .= " AND d.fk_propal = c.rowid";
288 $where .= " AND c.entity IN (".getEntity('propal').")";
289 $dateprint = 'c.datep';
290 $doc_number = 'c.ref';
291 $thirdTypeSelect = 'customer';
292}
293if ($type_element == 'order') {
294 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
295 $langs->load('sendings'); // delivery planned date
296 $documentstatic = new Commande($db);
297 $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, NULL as paid, c.date_livraison as delivery_planned_date,';
298 $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
299 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
300 $where .= " AND d.fk_commande = c.rowid";
301 $where .= " AND c.entity IN (".getEntity('commande').")";
302 $dateprint = 'c.date_commande';
303 $doc_number = 'c.ref';
304 $thirdTypeSelect = 'customer';
305}
306if ($type_element == 'shipment') {
307 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
308 $langs->load('sendings');
309 $documentstatic = new Expedition($db);
310 $sql_select = 'SELECT e.rowid as doc_id, e.ref as doc_number, \'1\' as doc_type, e.date_creation as dateprint, e.fk_statut as status, NULL as paid, e.date_delivery as delivery_planned_date,';
311 $tables_from = MAIN_DB_PREFIX."expedition as e,".MAIN_DB_PREFIX."expeditiondet as ed,".MAIN_DB_PREFIX."commandedet as d";
312 $where = " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
313 $where .= " AND ed.fk_expedition = e.rowid";
314 $where .= " AND ed.element_type = 'commande' AND ed.fk_elementdet = d.rowid";
315 $where .= " AND e.entity = ".$conf->entity;
316 $dateprint = 'e.date_creation';
317 $doc_number = 'e.ref';
318 $thirdTypeSelect = 'customer';
319}
320if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
321 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
322 $documentstatic = new FactureFournisseur($db);
323 $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, ';
324 $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
325 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
326 $where .= " AND d.fk_facture_fourn = f.rowid";
327 $where .= " AND f.entity = ".$conf->entity;
328 $dateprint = 'f.datef';
329 $doc_number = 'f.ref';
330 $thirdTypeSelect = 'supplier';
331}
332if ($type_element == 'supplier_proposal') {
333 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
334 $documentstatic = new SupplierProposal($db);
335 $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, NULL as paid, ';
336 $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
337 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
338 $where .= " AND d.fk_supplier_proposal = c.rowid";
339 $where .= " AND c.entity = ".$conf->entity;
340 $dateprint = 'c.date_valid';
341 $doc_number = 'c.ref';
342 $thirdTypeSelect = 'supplier';
343}
344if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
345 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
346 $langs->load('sendings'); // delivery planned date
347 $documentstatic = new CommandeFournisseur($db);
348 $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, NULL as paid, c.date_livraison as delivery_planned_date, ';
349 $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
350 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
351 $where .= " AND d.fk_commande = c.rowid";
352 $where .= " AND c.entity = ".$conf->entity;
353 $dateprint = 'c.date_valid';
354 $doc_number = 'c.ref';
355 $thirdTypeSelect = 'supplier';
356}
357if ($type_element == 'reception') { // Supplier : Show products from orders.
358 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
359 $langs->loadLangs(['sendings', 'receptions']); // delivery planned date
360 $documentstatic = new Reception($db);
361 $sql_select = 'SELECT r.rowid as doc_id, r.ref as doc_number, \'1\' as doc_type, r.date_creation as dateprint, r.fk_statut as status, NULL as paid, r.date_delivery as delivery_planned_date, ';
362 $tables_from = MAIN_DB_PREFIX."reception as r,".MAIN_DB_PREFIX."receptiondet_batch as rd,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
363 $where = " WHERE r.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
364 $where .= " AND rd.fk_reception = r.rowid";
365 $where .= " AND rd.fk_elementdet = d.rowid AND rd.element_type = 'supplier_order'";
366 $where .= " AND r.entity = ".$conf->entity;
367 $dateprint = 'r.date_creation';
368 $doc_number = 'r.ref';
369 $thirdTypeSelect = 'supplier';
370}
371if ($type_element == 'contract') { // Order
372 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
373 $documentstatic = new Contrat($db);
374 $documentstaticline = new ContratLigne($db);
375 $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_contrat as dateprint, d.statut as status, NULL as paid,';
376 $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
377 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
378 $where .= " AND d.fk_contrat = c.rowid";
379 $where .= " AND c.entity = ".$conf->entity;
380 $dateprint = 'c.date_valid';
381 $doc_number = 'c.ref';
382 $thirdTypeSelect = 'customer';
383}
384
385$totalnboflines = 0;
386
387if (!empty($sql_select)) {
388 $sql = $sql_select;
389 $parameters = array();
390 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
391 $sql .= $hookmanager->resPrint;
392 $sql .= ' d.description as description,';
393 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
394 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
395 }
396 if ($type_element == 'supplier_proposal') {
397 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
398 }
399 if ($type_element == 'contract') {
400 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
401 }
402 if ($type_element == 'shipment') {
403 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, ed.qty, ed.qty as prod_qty, ed.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
404 }
405 if ($type_element == 'reception') {
406 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, rd.qty, rd.qty as prod_qty, rd.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
407 }
408 if ($type_element != 'fichinter') {
409 $sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity, ';
410 }
411 $sql .= " s.rowid as socid ";
412 if ($type_element != 'fichinter') {
413 $sql .= ", p.ref as prod_ref, p.label as product_label";
414 }
415 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
416 if ($type_element != 'fichinter') {
417 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
418 }
419 $parameters = array();
420 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
421 $sql .= $hookmanager->resPrint;
422 $sql .= $where;
423 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
424 if ($sref) {
425 $sql .= " AND ".$db->sanitize((string) $doc_number)." LIKE '%".$db->escape($sref)."%'";
426 }
427 if ($sprod_fulldescr) {
428 // We test both case description is correctly saved of was save after dol_escape_htmltag().
429 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
430 if (GETPOST('type_element') != 'fichinter') {
431 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
432 }
433 if (GETPOST('type_element') != 'fichinter') {
434 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
435 }
436 $sql .= ")";
437 }
438
439 $parameters = array('type_element' => $type_element);
440 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
441 $sql .= $hookmanager->resPrint;
442
443 $parameters = array();
444 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
445 $sql .= $hookmanager->resPrint;
446
447 $sql .= $db->order($sortfield, $sortorder);
448
449 $resql = $db->query($sql);
450 $totalnboflines = $db->num_rows($resql);
451
452 $sql .= $db->plimit($limit + 1, $offset);
453 //print $sql;
454}
455
456$disabled = 0;
457$showempty = 2;
458if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
459 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
460 $disabled = 1;
461}
462
463// Define type of elements
464$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
465$button = '<input type="submit" class="button buttonform small" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
466
467$total_qty = 0;
468$total_ht = 0;
469
470$param = '';
471$num = 0;
472
473if ($sql_select && $sql !== '') {
474 $resql = $db->query($sql);
475 if (!$resql) {
477 }
478
479 $num = $db->num_rows($resql);
480
481 $param = "&socid=".urlencode((string) ($socid))."&type_element=".urlencode((string) ($type_element));
482 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
483 $param .= '&contextpage='.urlencode($contextpage);
484 }
485 if ($limit > 0 && $limit != $conf->liste_limit) {
486 $param .= '&limit='.((int) $limit);
487 }
488 if ($sprod_fulldescr) {
489 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
490 }
491 if ($sref) {
492 $param .= "&sref=".urlencode($sref);
493 }
494 if ($month) {
495 $param .= "&month=".urlencode((string) ($month));
496 }
497 if ($year) {
498 $param .= "&year=".urlencode((string) ($year));
499 }
500 if ($optioncss) {
501 $param .= '&optioncss='.urlencode($optioncss);
502 }
503
504 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', 'nogreyscale', $limit);
505
506 print '<div class="div-table-responsive-no-min">';
507 print '<table class="liste centpercent noborder">'."\n";
508
509 // Filters
510 print '<tr class="liste_titre">';
511 print '<th class="liste_titre">';
512 print '<input class="flat width75" type="text" name="sref" value="'.$sref.'">';
513 print '</th>';
514 print '<th class="liste_titre nowrap center valignmiddle">'; // date
515 print $formother->select_month($month ? (string) $month : '-1', 'month', 1, 0, 'valignmiddle');
516 print $formother->selectyear($year ? (string) $year : '-1', 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
517 print '</th>';
518 // delivery planned date
519 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
520 print '<td class="liste_titre center"></td>';
521 }
522 print '<th class="liste_titre center">';
523 print '</th>';
524 print '<th class="liste_titre left">';
525 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
526 print '</th>';
527 print '<th class="liste_titre center">';
528 print '</th>';
529 print '<th class="liste_titre center">';
530 print '</th>';
531 $parameters = array();
532 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
533 print $hookmanager->resPrint;
534 print '<th class="liste_titre maxwidthsearch">';
535 $searchpicto = $form->showFilterAndCheckAddButtons(0);
536 print $searchpicto;
537 print '</th>';
538 print '</tr>';
539
540 // Titles with sort buttons
541 print '<tr class="liste_titre">';
542 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
543 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
544 // delivery planned date
545 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
546 print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
547 }
548 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
549 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
550 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
551 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
552 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
553 $parameters = array('param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
554 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
555 print $hookmanager->resPrint;
556 print "</tr>\n";
557
558 $i = 0;
559 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
560 $documentstatic->id = $objp->doc_id;
561 $documentstatic->ref = $objp->doc_number;
562 $documentstatic->type = $objp->doc_type;
563 $documentstatic->fk_statut = $objp->status;
564 $documentstatic->fk_status = $objp->status;
565 $documentstatic->statut = $objp->status;
566 $documentstatic->status = $objp->status;
567 $documentstatic->paye = $objp->paid;
568 $documentstatic->alreadypaid = $objp->paid;
569 $documentstatic->totalpaid = $objp->paid;
570
571 if (is_object($documentstaticline)) {
572 $documentstaticline->statut = $objp->status;
573 $documentstaticline->status = $objp->status;
574 }
575
576 print '<tr class="oddeven">';
577 print '<td class="nobordernopadding nowraponall">';
578 print $documentstatic->getNomUrl(1);
579 print '</td>';
580 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
581 // delivery planned date
582 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
583 print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
584 }
585
586 // Status
587 print '<td class="center">';
588 if ($type_element == 'contract') {
589 print $documentstaticline->getLibStatut(5);
590 } elseif ($documentstatic == null) {
591 // Do noting - for static analysis
592 } elseif ($type_element == 'invoice') {
593 // @phan-suppress-next-line PhanParamTooMany
594 print $documentstatic->getLibStatut(5, $objp->paid);
595 } elseif ($type_element == 'supplier_invoice') {
596 // @phan-suppress-next-line PhanParamTooMany
597 print $documentstatic->getLibStatut(5, $objp->paid);
598 } else {
599 print $documentstatic->getLibStatut(5);
600 }
601 print '</td>';
602
603 // Label
604 print '<td class="tdoverflowmax300">';
605
606 // Define text, description and type
607 $text = '';
608 $description = '';
609 $type = 0;
610
611 // Code to show product duplicated from commonobject->printObjectLine
612 if ($objp->fk_product > 0) {
613 $product_static = new Product($db);
614
615 $product_static->type = $objp->fk_product_type;
616 $product_static->id = $objp->fk_product;
617 $product_static->ref = $objp->ref;
618 $product_static->entity = $objp->pentity;
619 $text = $product_static->getNomUrl(1);
620 }
621
622 // Product
623 if ($objp->fk_product > 0) {
624 // Define output language
625 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
626 $prod = new Product($db);
627 $prod->fetch($objp->fk_product);
628
629 $outputlangs = $langs;
630 $newlang = '';
631 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
632 $newlang = GETPOST('lang_id', 'aZ09');
633 }
634 if (empty($newlang)) {
635 $newlang = $object->default_lang;
636 }
637 if (!empty($newlang)) {
638 $outputlangs = new Translate("", $conf);
639 $outputlangs->setDefaultLang($newlang);
640 }
641
642 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
643 } else {
644 $label = $objp->product_label;
645 }
646
647 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
648 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
649 }
650
651 if (($objp->info_bits & 2) == 2) { ?>
652 <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
653 <?php
654 $txt = '';
655 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
656 if ($objp->description == '(DEPOSIT)') {
657 $txt = $langs->trans("Deposit");
658 } elseif ($objp->description == '(EXCESS RECEIVED)') {
659 $txt = $langs->trans("ExcessReceived");
660 } elseif ($objp->description == '(EXCESS PAID)') {
661 $txt = $langs->trans("ExcessPaid");
662 }
663 //else $txt=$langs->trans("Discount");
664 print $txt;
665 ?>
666 </a>
667 <?php
668 if ($objp->description) {
669 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
670 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
671 $discount = new DiscountAbsolute($db);
672 $discount->fetch($objp->fk_remise_except);
673 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
674 }
675 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
676 $discount = new DiscountAbsolute($db);
677 $discount->fetch($objp->fk_remise_except);
678 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
679 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
680 $discount = new DiscountAbsolute($db);
681 $discount->fetch($objp->fk_remise_except);
682 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
683 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
684 $discount = new DiscountAbsolute($db);
685 $discount->fetch($objp->fk_remise_except);
686 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
687 // Add date of deposit
688 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
689 echo ' ('.dol_print_date($discount->datec).')';
690 }
691 } else {
692 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
693 }
694 }
695 } else {
696 if ($objp->fk_product > 0) {
697 echo $form->textwithtooltip($text, $description, 3, 0, '', (string) $i, 0, '');
698
699 // Show range
700 echo get_date_range($objp->date_start, $objp->date_end);
701
702 // Add description in form
703 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
704 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
705 }
706 } else {
707 if (!empty($objp->label) || !empty($objp->description)) {
708 if ($type == 1) {
709 $text = img_object($langs->trans('Service'), 'service');
710 } else {
711 $text = img_object($langs->trans('Product'), 'product');
712 }
713
714 if (!empty($objp->label)) {
715 $text .= ' <strong>'.$objp->label.'</strong>';
716 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, 0, '', (string) $i, 0, '');
717 } else {
718 echo $text.' '.dol_htmlentitiesbr($objp->description);
719 }
720 }
721
722 // Show range
723 echo get_date_range($objp->date_start, $objp->date_end);
724 }
725 }
726
727 /*
728 $prodreftxt='';
729 if ($objp->prod_id > 0)
730 {
731 $productstatic->id = $objp->prod_id;
732 $productstatic->ref = $objp->prod_ref;
733 $productstatic->status = $objp->prod_type;
734 $prodreftxt = $productstatic->getNomUrl(0);
735 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
736 }
737 // Show range
738 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
739 // Add description in form
740 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
741 {
742 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
743 }
744 */
745 print '</td>';
746
747 //print '<td class="left">'.$prodreftxt.'</td>';
748 if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
749 $objp->prod_qty = -($objp->prod_qty);
750 }
751 print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
752 $total_qty += $objp->prod_qty;
753
754 print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
755
756 $total_ht += (float) $objp->total_ht;
757
758 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
759 $parameters = array('obj' => $objp);
760 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
761 print $hookmanager->resPrint;
762 print "</tr>\n";
763 $i++;
764 }
765
766 print '<tr class="liste_total">';
767 print '<td>'.$langs->trans('Total').'</td>';
768 print '<td colspan="3"></td>';
769 // delivery planned date
770 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
771 print '<td></td>';
772 }
773 print '<td class="right">'.$total_qty.'</td>';
774 print '<td class="right">'.price($total_ht).'</td>';
775 print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
776 $parameters = array();
777 $reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
778 print $hookmanager->resPrint;
779 print "</table>";
780 print '</div>';
781
782 if ($num > $limit) {
783 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
784 }
785 $db->free($resql);
786} elseif (empty($type_element) || $type_element == -1) {
787 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
788
789 print '<table class="liste centpercent noborder">'."\n";
790 // Titles with sort buttons
791 print '<tr class="liste_titre">';
792 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
793 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
794 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
795 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
796 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
797 print "</tr>\n";
798
799 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
800
801 print "</table>";
802} else {
803 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
804
805 print '<table class="liste centpercent">'."\n";
806
807 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
808
809 print "</table>";
810}
811
812print "</form>";
813
814// End of page
815llxFooter();
816$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage lines of contracts.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage products or services.
Class to manage proposals.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage price ask supplier.
Class to manage translations.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:386
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.