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