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