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