dolibarr 25.0.0-alpha
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-2026 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/class/html.formorder.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
44
45// Load translation files required by the page
46$langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
47
48$action = GETPOST('action', 'aZ09');
49$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
50$optioncss = GETPOST('optioncss', 'alpha');
51
52// Security check
53$socid = GETPOSTINT('socid');
54if ($user->socid) {
55 $socid = $user->socid;
56}
57
58// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
59$hookmanager->initHooks(array('thirdpartyconsumption', 'consumptionthirdparty', 'globalcard'));
60
61$result = restrictedArea($user, 'societe', $socid, '&societe');
62$object = new Societe($db);
63if ($socid > 0) {
64 $object->fetch($socid);
65}
66
67// Sort & Order fields
68$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
69$sortfield = GETPOST('sortfield', 'aZ09comma');
70$sortorder = GETPOST('sortorder', 'aZ09comma');
71$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
72
73if (empty($page) || $page == -1) {
74 $page = 0;
75}
76$offset = $limit * $page;
77$pageprev = $page - 1;
78$pagenext = $page + 1;
79if (!$sortorder) {
80 $sortorder = 'DESC';
81}
82if (!$sortfield) {
83 $sortfield = 'dateprint';
84}
85
86// Search fields
87$sref = GETPOST("sref");
88$sprod_fulldescr = GETPOST("sprod_fulldescr");
89$month = GETPOSTINT('month');
90$year = GETPOSTINT('year');
91if (GETPOSTISARRAY('search_status')) {
92 $search_status = implode(',', GETPOST('search_status', 'array:intcomma'));
93} else {
94 $search_status = GETPOST('search_status', 'intcomma');
95}
96
97// Clean up on purge search criteria ?
98if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
99 $sref = '';
100 $sprod_fulldescr = '';
101 $year = '';
102 $month = '';
103 $search_status = '';
104}
105
106// Customer or supplier selected in drop box
107$thirdTypeSelect = GETPOST("third_select_id", 'aZ09');
108$type_element = GETPOST('type_element') ? GETPOST('type_element') : '';
109
110/*
111 * Actions
112 */
113
114$parameters = array('id' => $socid);
115$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
116if ($reshook < 0) {
117 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120
121
122/*
123 * View
124 */
125
126$form = new Form($db);
127$formother = new FormOther($db);
128$formorder = new FormOrder($db);
129$productstatic = new Product($db);
130
131$title = $langs->trans("Referers", $object->name);
132if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
133 $title = $object->name." - ".$title;
134}
135$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
136llxHeader('', $title, $help_url);
137
138if (empty($socid)) {
139 dol_print_error($db);
140 exit;
141}
142
143$head = societe_prepare_head($object);
144print dol_get_fiche_head($head, 'consumption', $langs->trans("ThirdParty"), -1, 'company');
145
146$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
147
148dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
149
150print '<div class="fichecenter">';
151
152print '<div class="underbanner clearboth"></div>';
153print '<table class="border centpercent tableforfield">';
154
155// Type Prospect/Customer/Supplier
156print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
157print $object->getTypeUrl(1);
158print '</td></tr>';
159
160//if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'read')) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
161$elementTypeArray = array();
162
163$sql = '';
164$where = '';
165
166if ($object->client) {
167 print '<tr><td class="titlefield">';
168 print $langs->trans('CustomerCode').'</td><td colspan="3">';
170 $tmpcheck = $object->check_codeclient();
171 if ($tmpcheck != 0 && $tmpcheck != -5) {
172 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
173 }
174 print '</td></tr>';
175 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
176 $resql = $db->query($sql);
177 if (!$resql) {
178 dol_print_error($db);
179 }
180
181 $obj = $db->fetch_object($resql);
182 $nbFactsClient = $obj->nb;
183 $thirdTypeArray = array();
184 $thirdTypeArray['customer'] = $langs->trans("customer");
185 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
186 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
187 }
188 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
189 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
190 }
191 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
192 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
193 }
194 if (isModEnabled('shipping') && $user->hasRight('expedition', 'lire')) {
195 $elementTypeArray['shipment'] = $langs->transnoentitiesnoconv('Shipments');
196 }
197 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
198 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
199 }
200}
201
202if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')) {
203 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
204}
205
206if ($object->fournisseur) {
207 $langs->load("supplier_proposal");
208 print '<tr><td class="titlefield">';
209 print $langs->trans('SupplierCode').'</td><td colspan="3">';
211 $tmpcheck = $object->check_codefournisseur();
212 if ($tmpcheck != 0 && $tmpcheck != -5) {
213 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
214 }
215 print '</td></tr>';
216 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
217 $resql = $db->query($sql);
218 if (!$resql) {
219 dol_print_error($db);
220 }
221
222 $obj = $db->fetch_object($resql);
223 $nbCmdsFourn = $obj->nb;
224 $thirdTypeArray['supplier'] = $langs->trans("supplier");
225 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
226 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
227 }
228 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
229 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
230 }
231 if (isModEnabled('reception') && $user->hasRight('reception', 'lire')) {
232 $langs->load('receptions');
233 $elementTypeArray['reception'] = $langs->transnoentitiesnoconv('Receptions');
234 }
235 if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
236 $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
237 }
238}
239print '</table>';
240
241print '</div>';
242
243print dol_get_fiche_end();
244print '<br>';
245
246
247print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
248print '<input type="hidden" name="token" value="'.newToken().'">';
249
250$sql_select = '';
251$documentstaticline = '';
252$tables_from = '';
253$dateprint = '';
254$doc_number = '';
255/*if ($type_element == 'action')
256{ // Customer : show products from invoices
257 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
258 $documentstatic=new ActionComm($db);
259 $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
260 $tables_from = MAIN_DB_PREFIX."actioncomm as f";
261 $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
262 $dateprint = 'f.datep';
263 $doc_number='f.id';
264}*/
265$documentstatic = null;
266if ($type_element == 'fichinter') { // Customer : show products from invoices
267 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
268 $documentstatic = new Fichinter($db);
269 $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, ';
270 $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, ';
271 $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.
272 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
273 $where .= " AND f.entity = ".((int) $conf->entity);
274 $dateprint = 'f.datec';
275 $doc_number = 'f.ref';
276}
277if ($type_element == 'invoice') { // Customer : show products from invoices
278 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
279 $documentstatic = new Facture($db);
280 $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, ';
281 $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
282 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
283 $where .= " AND d.fk_facture = f.rowid";
284 $where .= " AND f.entity IN (".getEntity('invoice').")";
285 $dateprint = 'f.datef';
286 $doc_number = 'f.ref';
287 $thirdTypeSelect = 'customer';
288}
289if ($type_element == 'propal') {
290 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
291 $documentstatic = new Propal($db);
292 $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,';
293 $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
294 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
295 $where .= " AND d.fk_propal = c.rowid";
296 $where .= " AND c.entity IN (".getEntity('propal').")";
297 $dateprint = 'c.datep';
298 $doc_number = 'c.ref';
299 $thirdTypeSelect = 'customer';
300}
301if ($type_element == 'order') {
302 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
303 $langs->load('sendings'); // delivery planned date
304 $documentstatic = new Commande($db);
305 $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,';
306 $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
307 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
308 $where .= " AND d.fk_commande = c.rowid";
309 $where .= " AND c.entity IN (".getEntity('commande').")";
310 $dateprint = 'c.date_commande';
311 $doc_number = 'c.ref';
312 $thirdTypeSelect = 'customer';
313}
314if ($type_element == 'shipment') {
315 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
316 $langs->load('sendings');
317 $documentstatic = new Expedition($db);
318 $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,';
319 $tables_from = MAIN_DB_PREFIX."expedition as e,".MAIN_DB_PREFIX."expeditiondet as ed,".MAIN_DB_PREFIX."commandedet as d";
320 $where = " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
321 $where .= " AND ed.fk_expedition = e.rowid";
322 $where .= " AND ed.element_type = 'commande' AND ed.fk_elementdet = d.rowid";
323 $where .= " AND e.entity = ".((int) $conf->entity);
324 $dateprint = 'e.date_creation';
325 $doc_number = 'e.ref';
326 $thirdTypeSelect = 'customer';
327}
328if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
329 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
330 $documentstatic = new FactureFournisseur($db);
331 $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, ';
332 $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
333 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
334 $where .= " AND d.fk_facture_fourn = f.rowid";
335 $where .= " AND f.entity = ".((int) $conf->entity);
336 $dateprint = 'f.datef';
337 $doc_number = 'f.ref';
338 $thirdTypeSelect = 'supplier';
339}
340if ($type_element == 'supplier_proposal') {
341 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
342 $documentstatic = new SupplierProposal($db);
343 $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, ';
344 $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
345 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
346 $where .= " AND d.fk_supplier_proposal = c.rowid";
347 $where .= " AND c.entity = ".((int) $conf->entity);
348 $dateprint = 'c.date_valid';
349 $doc_number = 'c.ref';
350 $thirdTypeSelect = 'supplier';
351}
352if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
353 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
354 $langs->load('sendings'); // delivery planned date
355 $documentstatic = new CommandeFournisseur($db);
356 $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, ';
357 $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
358 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
359 $where .= " AND d.fk_commande = c.rowid";
360 $where .= " AND c.entity = ".((int) $conf->entity);
361 $dateprint = 'c.date_valid';
362 $doc_number = 'c.ref';
363 $thirdTypeSelect = 'supplier';
364}
365if ($type_element == 'reception') { // Supplier : Show products from orders.
366 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
367 $langs->loadLangs(['sendings', 'receptions']); // delivery planned date
368 $documentstatic = new Reception($db);
369 $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, ';
370 $tables_from = MAIN_DB_PREFIX."reception as r,".MAIN_DB_PREFIX."receptiondet_batch as rd,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
371 $where = " WHERE r.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
372 $where .= " AND rd.fk_reception = r.rowid";
373 $where .= " AND rd.fk_elementdet = d.rowid AND rd.element_type = 'supplier_order'";
374 $where .= " AND r.entity = ".((int) $conf->entity);
375 $dateprint = 'r.date_creation';
376 $doc_number = 'r.ref';
377 $thirdTypeSelect = 'supplier';
378}
379if ($type_element == 'contract') { // Order
380 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
381 $documentstatic = new Contrat($db);
382 $documentstaticline = new ContratLigne($db);
383 $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,';
384 $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
385 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
386 $where .= " AND d.fk_contrat = c.rowid";
387 $where .= " AND c.entity = ".((int) $conf->entity);
388 $dateprint = 'c.date_valid';
389 $doc_number = 'c.ref';
390 $thirdTypeSelect = 'customer';
391}
392
393$totalnboflines = 0;
394
395if (!empty($sql_select)) {
396 $sql = $sql_select;
397 $parameters = array();
398 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
399 $sql .= $hookmanager->resPrint;
400 $sql .= ' d.description as description,';
401 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
402 $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, ';
403 }
404 if ($type_element == 'supplier_proposal') {
405 $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, ';
406 }
407 if ($type_element == 'contract') {
408 $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, ';
409 }
410 if ($type_element == 'shipment') {
411 $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, ';
412 }
413 if ($type_element == 'reception') {
414 $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, ';
415 }
416 if ($type_element != 'fichinter') {
417 $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, ';
418 }
419 $sql .= " s.rowid as socid ";
420 if ($type_element != 'fichinter') {
421 $sql .= ", p.ref as prod_ref, p.label as product_label";
422 }
423 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
424 if ($type_element != 'fichinter') {
425 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
426 }
427 $parameters = array();
428 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
429 $sql .= $hookmanager->resPrint;
430 $sql .= $where;
431 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
432 if ($sref) {
433 $sql .= " AND ".$db->sanitize((string) $doc_number)." LIKE '%".$db->escape($sref)."%'";
434 }
435 if ($sprod_fulldescr) {
436 // We test both case description is correctly saved of was save after dol_escape_htmltag().
437 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
438 if (GETPOST('type_element') != 'fichinter') {
439 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
440 }
441 if (GETPOST('type_element') != 'fichinter') {
442 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
443 }
444 $sql .= ")";
445 }
446 if ($type_element == 'supplier_order' && $search_status !== '') {
447 $sql .= " AND c.fk_statut IN (".$db->sanitize($search_status).")";
448 }
449
450 $parameters = array('type_element' => $type_element);
451 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
452 $sql .= $hookmanager->resPrint;
453
454 $parameters = array();
455 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
456 $sql .= $hookmanager->resPrint;
457
458 $sql .= $db->order($sortfield, $sortorder);
459
460 $resql = $db->query($sql);
461 $totalnboflines = $db->num_rows($resql);
462
463 $sql .= $db->plimit($limit + 1, $offset);
464 //print $sql;
465}
466
467$disabled = 0;
468$showempty = 2;
469if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
470 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
471 $disabled = 1;
472}
473
474// Define type of elements
475$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
476$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")).'">';
477
478$total_qty = 0;
479$total_ht = 0;
480
481$param = '';
482$num = 0;
483
484if ($sql_select && $sql !== '') {
485 $resql = $db->query($sql);
486 if (!$resql) {
487 dol_print_error($db);
488 }
489
490 $num = $db->num_rows($resql);
491
492 $param = "&socid=".urlencode((string) ($socid))."&type_element=".urlencode((string) ($type_element));
493 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
494 $param .= '&contextpage='.urlencode($contextpage);
495 }
496 if ($limit > 0 && $limit != $conf->liste_limit) {
497 $param .= '&limit='.((int) $limit);
498 }
499 if ($sprod_fulldescr) {
500 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
501 }
502 if ($sref) {
503 $param .= "&sref=".urlencode($sref);
504 }
505 if ($month) {
506 $param .= "&month=".urlencode((string) ($month));
507 }
508 if ($year) {
509 $param .= "&year=".urlencode((string) ($year));
510 }
511 if ($search_status !== '') {
512 $param .= "&search_status=".urlencode($search_status);
513 }
514 if ($optioncss) {
515 $param .= '&optioncss='.urlencode($optioncss);
516 }
517
518 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', 'nogreyscale', $limit);
519
520 print '<div class="div-table-responsive-no-min">';
521 print '<table class="liste centpercent noborder">'."\n";
522
523 // Filters
524 print '<tr class="liste_titre">';
525 print '<th class="liste_titre">';
526 print '<input class="flat width75" type="text" name="sref" value="'.$sref.'">';
527 print '</th>';
528 print '<th class="liste_titre nowrap center valignmiddle">'; // date
529 print $formother->select_month($month ? (string) $month : '-1', 'month', 1, 0, 'valignmiddle');
530 print $formother->selectyear($year ? (string) $year : '-1', 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
531 print '</th>';
532 // delivery planned date
533 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
534 print '<td class="liste_titre center"></td>';
535 }
536 print '<th class="liste_titre center parentonrightofpage">';
537 if ($type_element == 'supplier_order') {
538 $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status', 'search_status width125 onrightofpage');
539 }
540 print '</th>';
541 print '<th class="liste_titre left">';
542 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
543 print '</th>';
544 print '<th class="liste_titre center">';
545 print '</th>';
546 print '<th class="liste_titre center">';
547 print '</th>';
548 $parameters = array();
549 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
550 print $hookmanager->resPrint;
551 print '<th class="liste_titre maxwidthsearch">';
552 $searchpicto = $form->showFilterAndCheckAddButtons(0);
553 print $searchpicto;
554 print '</th>';
555 print '</tr>';
556
557 // Titles with sort buttons
558 print '<tr class="liste_titre">';
559 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
560 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
561 // delivery planned date
562 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
563 print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
564 }
565 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
566 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
567 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
568 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
569 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
570 $parameters = array('param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
571 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
572 print $hookmanager->resPrint;
573 print "</tr>\n";
574
575 $i = 0;
576 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
577 $documentstatic->id = $objp->doc_id;
578 $documentstatic->ref = $objp->doc_number;
579 $documentstatic->type = $objp->doc_type;
580 $documentstatic->fk_statut = $objp->status;
581 $documentstatic->fk_status = $objp->status;
582 $documentstatic->statut = $objp->status;
583 $documentstatic->status = $objp->status;
584 $documentstatic->paye = $objp->paid;
585 $documentstatic->alreadypaid = $objp->paid;
586 $documentstatic->totalpaid = $objp->paid;
587
588 if (is_object($documentstaticline)) {
589 $documentstaticline->statut = $objp->status;
590 $documentstaticline->status = $objp->status;
591 }
592
593 print '<tr class="oddeven">';
594 print '<td class="nobordernopadding nowraponall">';
595 print $documentstatic->getNomUrl(1);
596 print '</td>';
597 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
598 // delivery planned date
599 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
600 print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
601 }
602
603 // Status
604 print '<td class="center">';
605 if ($type_element == 'contract') {
606 print $documentstaticline->getLibStatut(5);
607 } elseif ($documentstatic == null) {
608 // Do noting - for static analysis
609 } elseif ($type_element == 'invoice') {
610 // @phan-suppress-next-line PhanParamTooMany
611 print $documentstatic->getLibStatut(5, $objp->paid);
612 } elseif ($type_element == 'supplier_invoice') {
613 // @phan-suppress-next-line PhanParamTooMany
614 print $documentstatic->getLibStatut(5, $objp->paid);
615 } else {
616 print $documentstatic->getLibStatut(5);
617 }
618 print '</td>';
619
620 // Label
621 print '<td class="tdoverflowmax300">';
622
623 // Define text, description and type
624 $text = '';
625 $description = '';
626 $type = 0;
627
628 // Code to show product duplicated from commonobject->printObjectLine
629 if ($objp->fk_product > 0) {
630 $product_static = new Product($db);
631
632 $product_static->type = $objp->fk_product_type;
633 $product_static->id = $objp->fk_product;
634 $product_static->ref = $objp->ref;
635 $product_static->entity = $objp->pentity;
636 $text = $product_static->getNomUrl(1);
637 }
638
639 // Product
640 if ($objp->fk_product > 0) {
641 // Define output language
642 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
643 $prod = new Product($db);
644 $prod->fetch($objp->fk_product);
645
646 $outputlangs = $langs;
647 $newlang = '';
648 if (GETPOST('lang_id', 'aZ09')) {
649 $newlang = GETPOST('lang_id', 'aZ09');
650 }
651 if (empty($newlang)) {
652 $newlang = $object->default_lang;
653 }
654 if (!empty($newlang)) {
655 $outputlangs = new Translate("", $conf);
656 $outputlangs->setDefaultLang($newlang);
657 }
658
659 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
660 } else {
661 $label = $objp->product_label;
662 }
663
664 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
665 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
666 }
667
668 if (($objp->info_bits & 2) == 2) { ?>
669 <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
670 <?php
671 $txt = '';
672 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
673 if ($objp->description == '(DEPOSIT)') {
674 $txt = $langs->trans("Deposit");
675 } elseif ($objp->description == '(EXCESS RECEIVED)') {
676 $txt = $langs->trans("ExcessReceived");
677 } elseif ($objp->description == '(EXCESS PAID)') {
678 $txt = $langs->trans("ExcessPaid");
679 }
680 //else $txt=$langs->trans("Discount");
681 print $txt;
682 ?>
683 </a>
684 <?php
685 if ($objp->description) {
686 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
687 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
688 $discount = new DiscountAbsolute($db);
689 $discount->fetch($objp->fk_remise_except);
690 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
691 }
692 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
693 $discount = new DiscountAbsolute($db);
694 $discount->fetch($objp->fk_remise_except);
695 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
696 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
697 $discount = new DiscountAbsolute($db);
698 $discount->fetch($objp->fk_remise_except);
699 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
700 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
701 $discount = new DiscountAbsolute($db);
702 $discount->fetch($objp->fk_remise_except);
703 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
704 // Add date of deposit
705 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
706 echo ' ('.dol_print_date($discount->datec).')';
707 }
708 } else {
709 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
710 }
711 }
712 } else {
713 if ($objp->fk_product > 0) {
714 echo $form->textwithtooltip($text, $description, 3, 0, '', (string) $i, 0, '');
715
716 // Show range
717 echo get_date_range($objp->date_start, $objp->date_end);
718
719 // Add description in form
720 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
721 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
722 }
723 } else {
724 if (!empty($objp->label) || !empty($objp->description)) {
725 if ($type == 1) {
726 $text = img_object($langs->trans('Service'), 'service');
727 } else {
728 $text = img_object($langs->trans('Product'), 'product');
729 }
730
731 if (!empty($objp->label)) {
732 $text .= ' <strong>'.$objp->label.'</strong>';
733 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, 0, '', (string) $i, 0, '');
734 } else {
735 echo $text.' '.dol_htmlentitiesbr($objp->description);
736 }
737 }
738
739 // Show range
740 echo get_date_range($objp->date_start, $objp->date_end);
741 }
742 }
743
744 /*
745 $prodreftxt='';
746 if ($objp->prod_id > 0)
747 {
748 $productstatic->id = $objp->prod_id;
749 $productstatic->ref = $objp->prod_ref;
750 $productstatic->status = $objp->prod_type;
751 $prodreftxt = $productstatic->getNomUrl(0);
752 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
753 }
754 // Show range
755 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
756 // Add description in form
757 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
758 {
759 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
760 }
761 */
762 print '</td>';
763
764 //print '<td class="left">'.$prodreftxt.'</td>';
765 if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
766 $objp->prod_qty = -($objp->prod_qty);
767 }
768 print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
769 $total_qty += $objp->prod_qty;
770
771 print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
772
773 $total_ht += (float) $objp->total_ht;
774
775 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
776 $parameters = array('obj' => $objp);
777 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
778 print $hookmanager->resPrint;
779 print "</tr>\n";
780 $i++;
781 }
782
783 print '<tr class="liste_total">';
784 print '<td>'.$langs->trans('Total').'</td>';
785 print '<td colspan="3"></td>';
786 // delivery planned date
787 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
788 print '<td></td>';
789 }
790 print '<td class="right">'.$total_qty.'</td>';
791 print '<td class="right">'.price($total_ht).'</td>';
792 print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
793 $parameters = array();
794 $reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
795 print $hookmanager->resPrint;
796 print "</table>";
797 print '</div>';
798
799 if ($num > $limit) {
800 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
801 }
802 $db->free($resql);
803} elseif (empty($type_element) || $type_element == -1) {
804 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
805
806 print '<table class="liste centpercent noborder">'."\n";
807 // Titles with sort buttons
808 print '<tr class="liste_titre">';
809 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
810 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
811 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
812 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
813 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
814 print "</tr>\n";
815
816 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
817
818 print "</table>";
819} else {
820 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
821
822 print '<table class="liste centpercent">'."\n";
823
824 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
825
826 print "</table>";
827}
828
829print "</form>";
830
831// End of page
832llxFooter();
833$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 manage HTML output components for orders Before adding component here, check they are not in...
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:391
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:
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.