dolibarr 23.0.3
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-2025 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)) {
131 dol_print_error($db);
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
155if ($object->client) {
156 print '<tr><td class="titlefield">';
157 print $langs->trans('CustomerCode').'</td><td colspan="3">';
159 $tmpcheck = $object->check_codeclient();
160 if ($tmpcheck != 0 && $tmpcheck != -5) {
161 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
162 }
163 print '</td></tr>';
164 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
165 $resql = $db->query($sql);
166 if (!$resql) {
167 dol_print_error($db);
168 }
169
170 $obj = $db->fetch_object($resql);
171 $nbFactsClient = $obj->nb;
172 $thirdTypeArray = array();
173 $thirdTypeArray['customer'] = $langs->trans("customer");
174 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
175 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
176 }
177 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
178 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
179 }
180 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
181 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
182 }
183 if (isModEnabled('shipping') && $user->hasRight('expedition', 'lire')) {
184 $elementTypeArray['shipment'] = $langs->transnoentitiesnoconv('Shipments');
185 }
186 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
187 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
188 }
189}
190
191if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')) {
192 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
193}
194
195if ($object->fournisseur) {
196 $langs->load("supplier_proposal");
197 print '<tr><td class="titlefield">';
198 print $langs->trans('SupplierCode').'</td><td colspan="3">';
200 $tmpcheck = $object->check_codefournisseur();
201 if ($tmpcheck != 0 && $tmpcheck != -5) {
202 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
203 }
204 print '</td></tr>';
205 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
206 $resql = $db->query($sql);
207 if (!$resql) {
208 dol_print_error($db);
209 }
210
211 $obj = $db->fetch_object($resql);
212 $nbCmdsFourn = $obj->nb;
213 $thirdTypeArray['supplier'] = $langs->trans("supplier");
214 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
215 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
216 }
217 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
218 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
219 }
220 if (isModEnabled('reception') && $user->hasRight('reception', 'lire')) {
221 $langs->load('receptions');
222 $elementTypeArray['reception'] = $langs->transnoentitiesnoconv('Receptions');
223 }
224 if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
225 $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
226 }
227}
228print '</table>';
229
230print '</div>';
231
232print dol_get_fiche_end();
233print '<br>';
234
235
236print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
237print '<input type="hidden" name="token" value="'.newToken().'">';
238
239$sql_select = '';
240$documentstaticline = '';
241$tables_from = '';
242$dateprint = '';
243$doc_number = '';
244/*if ($type_element == 'action')
245{ // Customer : show products from invoices
246 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
247 $documentstatic=new ActionComm($db);
248 $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
249 $tables_from = MAIN_DB_PREFIX."actioncomm as f";
250 $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
251 $dateprint = 'f.datep';
252 $doc_number='f.id';
253}*/
254$documentstatic = null;
255if ($type_element == 'fichinter') { // Customer : show products from invoices
256 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
257 $documentstatic = new Fichinter($db);
258 $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, ';
259 $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, ';
260 $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.
261 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
262 $where .= " AND f.entity = ".$conf->entity;
263 $dateprint = 'f.datec';
264 $doc_number = 'f.ref';
265}
266if ($type_element == 'invoice') { // Customer : show products from invoices
267 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
268 $documentstatic = new Facture($db);
269 $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, ';
270 $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
271 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
272 $where .= " AND d.fk_facture = f.rowid";
273 $where .= " AND f.entity IN (".getEntity('invoice').")";
274 $dateprint = 'f.datef';
275 $doc_number = 'f.ref';
276 $thirdTypeSelect = 'customer';
277}
278if ($type_element == 'propal') {
279 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
280 $documentstatic = new Propal($db);
281 $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,';
282 $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
283 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
284 $where .= " AND d.fk_propal = c.rowid";
285 $where .= " AND c.entity IN (".getEntity('propal').")";
286 $dateprint = 'c.datep';
287 $doc_number = 'c.ref';
288 $thirdTypeSelect = 'customer';
289}
290if ($type_element == 'order') {
291 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
292 $langs->load('sendings'); // delivery planned date
293 $documentstatic = new Commande($db);
294 $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,';
295 $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
296 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
297 $where .= " AND d.fk_commande = c.rowid";
298 $where .= " AND c.entity IN (".getEntity('commande').")";
299 $dateprint = 'c.date_commande';
300 $doc_number = 'c.ref';
301 $thirdTypeSelect = 'customer';
302}
303if ($type_element == 'shipment') {
304 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
305 $langs->load('sendings');
306 $documentstatic = new Expedition($db);
307 $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,';
308 $tables_from = MAIN_DB_PREFIX."expedition as e,".MAIN_DB_PREFIX."expeditiondet as ed,".MAIN_DB_PREFIX."commandedet as d";
309 $where = " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
310 $where .= " AND ed.fk_expedition = e.rowid";
311 $where .= " AND ed.element_type = 'commande' AND ed.fk_elementdet = d.rowid";
312 $where .= " AND e.entity = ".$conf->entity;
313 $dateprint = 'e.date_creation';
314 $doc_number = 'e.ref';
315 $thirdTypeSelect = 'customer';
316}
317if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
318 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
319 $documentstatic = new FactureFournisseur($db);
320 $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, ';
321 $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
322 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
323 $where .= " AND d.fk_facture_fourn = f.rowid";
324 $where .= " AND f.entity = ".$conf->entity;
325 $dateprint = 'f.datef';
326 $doc_number = 'f.ref';
327 $thirdTypeSelect = 'supplier';
328}
329if ($type_element == 'supplier_proposal') {
330 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
331 $documentstatic = new SupplierProposal($db);
332 $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, ';
333 $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
334 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
335 $where .= " AND d.fk_supplier_proposal = c.rowid";
336 $where .= " AND c.entity = ".$conf->entity;
337 $dateprint = 'c.date_valid';
338 $doc_number = 'c.ref';
339 $thirdTypeSelect = 'supplier';
340}
341if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
342 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
343 $langs->load('sendings'); // delivery planned date
344 $documentstatic = new CommandeFournisseur($db);
345 $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, ';
346 $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
347 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
348 $where .= " AND d.fk_commande = c.rowid";
349 $where .= " AND c.entity = ".$conf->entity;
350 $dateprint = 'c.date_valid';
351 $doc_number = 'c.ref';
352 $thirdTypeSelect = 'supplier';
353}
354if ($type_element == 'reception') { // Supplier : Show products from orders.
355 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
356 $langs->loadLangs(['sendings', 'receptions']); // delivery planned date
357 $documentstatic = new Reception($db);
358 $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, ';
359 $tables_from = MAIN_DB_PREFIX."reception as r,".MAIN_DB_PREFIX."receptiondet_batch as rd,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
360 $where = " WHERE r.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
361 $where .= " AND rd.fk_reception = r.rowid";
362 $where .= " AND rd.fk_elementdet = d.rowid AND rd.element_type = 'supplier_order'";
363 $where .= " AND r.entity = ".$conf->entity;
364 $dateprint = 'r.date_creation';
365 $doc_number = 'r.ref';
366 $thirdTypeSelect = 'supplier';
367}
368if ($type_element == 'contract') { // Order
369 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
370 $documentstatic = new Contrat($db);
371 $documentstaticline = new ContratLigne($db);
372 $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,';
373 $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
374 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
375 $where .= " AND d.fk_contrat = c.rowid";
376 $where .= " AND c.entity = ".$conf->entity;
377 $dateprint = 'c.date_valid';
378 $doc_number = 'c.ref';
379 $thirdTypeSelect = 'customer';
380}
381
382$totalnboflines = 0;
383
384if (!empty($sql_select)) {
385 $sql = $sql_select;
386 $parameters = array();
387 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
388 $sql .= $hookmanager->resPrint;
389 $sql .= ' d.description as description,';
390 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
391 $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, ';
392 }
393 if ($type_element == 'supplier_proposal') {
394 $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, ';
395 }
396 if ($type_element == 'contract') {
397 $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, ';
398 }
399 if ($type_element == 'shipment') {
400 $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, ';
401 }
402 if ($type_element == 'reception') {
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, rd.qty, rd.qty as prod_qty, rd.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
404 }
405 if ($type_element != 'fichinter') {
406 $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, ';
407 }
408 $sql .= " s.rowid as socid ";
409 if ($type_element != 'fichinter') {
410 $sql .= ", p.ref as prod_ref, p.label as product_label";
411 }
412 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
413 if ($type_element != 'fichinter') {
414 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
415 }
416 $parameters = array();
417 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
418 $sql .= $hookmanager->resPrint;
419 $sql .= $where;
420 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
421 if ($sref) {
422 $sql .= " AND ".$db->sanitize((string) $doc_number)." LIKE '%".$db->escape($sref)."%'";
423 }
424 if ($sprod_fulldescr) {
425 // We test both case description is correctly saved of was save after dol_escape_htmltag().
426 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
427 if (GETPOST('type_element') != 'fichinter') {
428 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
429 }
430 if (GETPOST('type_element') != 'fichinter') {
431 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
432 }
433 $sql .= ")";
434 }
435
436 $parameters = array('type_element' => $type_element);
437 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
438 $sql .= $hookmanager->resPrint;
439
440 $parameters = array();
441 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
442 $sql .= $hookmanager->resPrint;
443
444 $sql .= $db->order($sortfield, $sortorder);
445
446 $resql = $db->query($sql);
447 $totalnboflines = $db->num_rows($resql);
448
449 $sql .= $db->plimit($limit + 1, $offset);
450 //print $sql;
451}
452
453$disabled = 0;
454$showempty = 2;
455if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
456 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
457 $disabled = 1;
458}
459
460// Define type of elements
461$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
462$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")).'">';
463
464$total_qty = 0;
465$total_ht = 0;
466
467$param = '';
468$num = 0;
469
470if ($sql_select) {
471 $resql = $db->query($sql);
472 if (!$resql) {
473 dol_print_error($db);
474 }
475
476 $num = $db->num_rows($resql);
477
478 $param = "&socid=".urlencode((string) ($socid))."&type_element=".urlencode((string) ($type_element));
479 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
480 $param .= '&contextpage='.urlencode($contextpage);
481 }
482 if ($limit > 0 && $limit != $conf->liste_limit) {
483 $param .= '&limit='.((int) $limit);
484 }
485 if ($sprod_fulldescr) {
486 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
487 }
488 if ($sref) {
489 $param .= "&sref=".urlencode($sref);
490 }
491 if ($month) {
492 $param .= "&month=".urlencode((string) ($month));
493 }
494 if ($year) {
495 $param .= "&year=".urlencode((string) ($year));
496 }
497 if ($optioncss) {
498 $param .= '&optioncss='.urlencode($optioncss);
499 }
500
501 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', 'nogreyscale', $limit);
502
503 print '<div class="div-table-responsive-no-min">';
504 print '<table class="liste centpercent noborder">'."\n";
505
506 // Filters
507 print '<tr class="liste_titre">';
508 print '<th class="liste_titre">';
509 print '<input class="flat width75" type="text" name="sref" value="'.$sref.'">';
510 print '</th>';
511 print '<th class="liste_titre nowrap center valignmiddle">'; // date
512 print $formother->select_month($month ? (string) $month : '-1', 'month', 1, 0, 'valignmiddle');
513 print $formother->selectyear($year ? (string) $year : '-1', 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
514 print '</th>';
515 // delivery planned date
516 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
517 print '<td class="liste_titre center"></td>';
518 }
519 print '<th class="liste_titre center">';
520 print '</th>';
521 print '<th class="liste_titre left">';
522 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
523 print '</th>';
524 print '<th class="liste_titre center">';
525 print '</th>';
526 print '<th class="liste_titre center">';
527 print '</th>';
528 $parameters = array();
529 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
530 print $hookmanager->resPrint;
531 print '<th class="liste_titre maxwidthsearch">';
532 $searchpicto = $form->showFilterAndCheckAddButtons(0);
533 print $searchpicto;
534 print '</th>';
535 print '</tr>';
536
537 // Titles with sort buttons
538 print '<tr class="liste_titre">';
539 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
540 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
541 // delivery planned date
542 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
543 print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
544 }
545 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
546 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
547 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
548 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
549 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
550 $parameters = array('param'=>$param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
551 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
552 print $hookmanager->resPrint;
553 print "</tr>\n";
554
555 $i = 0;
556 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
557 $documentstatic->id = $objp->doc_id;
558 $documentstatic->ref = $objp->doc_number;
559 $documentstatic->type = $objp->doc_type;
560 $documentstatic->fk_statut = $objp->status;
561 $documentstatic->fk_status = $objp->status;
562 $documentstatic->statut = $objp->status;
563 $documentstatic->status = $objp->status;
564 $documentstatic->paye = $objp->paid;
565 $documentstatic->alreadypaid = $objp->paid;
566 $documentstatic->totalpaid = $objp->paid;
567
568 if (is_object($documentstaticline)) {
569 $documentstaticline->statut = $objp->status;
570 $documentstaticline->status = $objp->status;
571 }
572
573 print '<tr class="oddeven">';
574 print '<td class="nobordernopadding nowraponall">';
575 print $documentstatic->getNomUrl(1);
576 print '</td>';
577 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
578 // delivery planned date
579 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
580 print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
581 }
582
583 // Status
584 print '<td class="center">';
585 if ($type_element == 'contract') {
586 print $documentstaticline->getLibStatut(5);
587 } elseif ($documentstatic == null) {
588 // Do noting - for static analysis
589 } elseif ($type_element == 'invoice') {
590 // @phan-suppress-next-line PhanParamTooMany
591 print $documentstatic->getLibStatut(5, $objp->paid);
592 } elseif ($type_element == 'supplier_invoice') {
593 // @phan-suppress-next-line PhanParamTooMany
594 print $documentstatic->getLibStatut(5, $objp->paid);
595 } else {
596 print $documentstatic->getLibStatut(5);
597 }
598 print '</td>';
599
600 // Label
601 print '<td class="tdoverflowmax300">';
602
603 // Define text, description and type
604 $text = '';
605 $description = '';
606 $type = 0;
607
608 // Code to show product duplicated from commonobject->printObjectLine
609 if ($objp->fk_product > 0) {
610 $product_static = new Product($db);
611
612 $product_static->type = $objp->fk_product_type;
613 $product_static->id = $objp->fk_product;
614 $product_static->ref = $objp->ref;
615 $product_static->entity = $objp->pentity;
616 $text = $product_static->getNomUrl(1);
617 }
618
619 // Product
620 if ($objp->fk_product > 0) {
621 // Define output language
622 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
623 $prod = new Product($db);
624 $prod->fetch($objp->fk_product);
625
626 $outputlangs = $langs;
627 $newlang = '';
628 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
629 $newlang = GETPOST('lang_id', 'aZ09');
630 }
631 if (empty($newlang)) {
632 $newlang = $object->default_lang;
633 }
634 if (!empty($newlang)) {
635 $outputlangs = new Translate("", $conf);
636 $outputlangs->setDefaultLang($newlang);
637 }
638
639 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
640 } else {
641 $label = $objp->product_label;
642 }
643
644 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
645 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
646 }
647
648 if (($objp->info_bits & 2) == 2) { ?>
649 <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
650 <?php
651 $txt = '';
652 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
653 if ($objp->description == '(DEPOSIT)') {
654 $txt = $langs->trans("Deposit");
655 } elseif ($objp->description == '(EXCESS RECEIVED)') {
656 $txt = $langs->trans("ExcessReceived");
657 } elseif ($objp->description == '(EXCESS PAID)') {
658 $txt = $langs->trans("ExcessPaid");
659 }
660 //else $txt=$langs->trans("Discount");
661 print $txt;
662 ?>
663 </a>
664 <?php
665 if ($objp->description) {
666 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
667 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
668 $discount = new DiscountAbsolute($db);
669 $discount->fetch($objp->fk_remise_except);
670 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
671 }
672 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
673 $discount = new DiscountAbsolute($db);
674 $discount->fetch($objp->fk_remise_except);
675 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
676 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
677 $discount = new DiscountAbsolute($db);
678 $discount->fetch($objp->fk_remise_except);
679 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
680 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
681 $discount = new DiscountAbsolute($db);
682 $discount->fetch($objp->fk_remise_except);
683 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
684 // Add date of deposit
685 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
686 echo ' ('.dol_print_date($discount->datec).')';
687 }
688 } else {
689 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
690 }
691 }
692 } else {
693 if ($objp->fk_product > 0) {
694 echo $form->textwithtooltip($text, $description, 3, 0, '', (string) $i, 0, '');
695
696 // Show range
697 echo get_date_range($objp->date_start, $objp->date_end);
698
699 // Add description in form
700 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
701 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
702 }
703 } else {
704 if (!empty($objp->label) || !empty($objp->description)) {
705 if ($type == 1) {
706 $text = img_object($langs->trans('Service'), 'service');
707 } else {
708 $text = img_object($langs->trans('Product'), 'product');
709 }
710
711 if (!empty($objp->label)) {
712 $text .= ' <strong>'.$objp->label.'</strong>';
713 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, 0, '', (string) $i, 0, '');
714 } else {
715 echo $text.' '.dol_htmlentitiesbr($objp->description);
716 }
717 }
718
719 // Show range
720 echo get_date_range($objp->date_start, $objp->date_end);
721 }
722 }
723
724 /*
725 $prodreftxt='';
726 if ($objp->prod_id > 0)
727 {
728 $productstatic->id = $objp->prod_id;
729 $productstatic->ref = $objp->prod_ref;
730 $productstatic->status = $objp->prod_type;
731 $prodreftxt = $productstatic->getNomUrl(0);
732 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
733 }
734 // Show range
735 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
736 // Add description in form
737 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
738 {
739 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
740 }
741 */
742 print '</td>';
743
744 //print '<td class="left">'.$prodreftxt.'</td>';
745 if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
746 $objp->prod_qty = -($objp->prod_qty);
747 }
748 print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
749 $total_qty += $objp->prod_qty;
750
751 print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
752
753 $total_ht += (float) $objp->total_ht;
754
755 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
756 $parameters = array('obj' => $objp);
757 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
758 print $hookmanager->resPrint;
759 print "</tr>\n";
760 $i++;
761 }
762
763 print '<tr class="liste_total">';
764 print '<td>'.$langs->trans('Total').'</td>';
765 print '<td colspan="3"></td>';
766 // delivery planned date
767 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
768 print '<td></td>';
769 }
770 print '<td class="right">'.$total_qty.'</td>';
771 print '<td class="right">'.price($total_ht).'</td>';
772 print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
773 $parameters = array();
774 $reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
775 print $hookmanager->resPrint;
776 print "</table>";
777 print '</div>';
778
779 if ($num > $limit) {
780 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
781 }
782 $db->free($resql);
783} elseif (empty($type_element) || $type_element == -1) {
784 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
785
786 print '<table class="liste centpercent noborder">'."\n";
787 // Titles with sort buttons
788 print '<tr class="liste_titre">';
789 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
790 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
791 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
792 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
793 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
794 print "</tr>\n";
795
796 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
797
798 print "</table>";
799} else {
800 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
801
802 print '<table class="liste centpercent">'."\n";
803
804 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
805
806 print "</table>";
807}
808
809print "</form>";
810
811// End of page
812llxFooter();
813$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 permettant la generation de composants html autre 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)
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:385
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.
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.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.