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