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