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  *
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 
29 // Load Dolibarr environment
30 require "../main.inc.php";
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.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 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
36 
37 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
38 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
39 
40 $id = GETPOST('id', 'int');
41 
42 $object = new Contact($db);
43 if ($id > 0) {
44  $object->fetch($id);
45 }
46 if (empty($object->thirdparty)) {
47  $object->fetch_thirdparty();
48 }
49 $socid = $object->thirdparty->id;
50 
51 // Sort & Order fields
52 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
53 $sortfield = GETPOST('sortfield', 'aZ09comma');
54 $sortorder = GETPOST('sortorder', 'aZ09comma');
55 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
56 if (empty($page) || $page == -1) {
57  $page = 0;
58 } // If $page is not defined, or '' or -1
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 if (!$sortorder) {
63  $sortorder = 'DESC';
64 }
65 if (!$sortfield) {
66  $sortfield = 'dateprint';
67 }
68 
69 // Search fields
70 $sref = GETPOST("sref");
71 $sprod_fulldescr = GETPOST("sprod_fulldescr");
72 $month = GETPOST('month', 'int');
73 $year = GETPOST('year', 'int');
74 
75 // Clean up on purge search criteria ?
76 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
77  $sref = '';
78  $sprod_fulldescr = '';
79  $year = '';
80  $month = '';
81 }
82 // Customer or supplier selected in drop box
83 $thirdTypeSelect = GETPOST("third_select_id");
84 $type_element = GETPOSTISSET('type_element') ?GETPOST('type_element') : '';
85 
86 // Load translation files required by the page
87 $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
88 
89 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
90 $hookmanager->initHooks(array('consumptioncontact'));
91 
92 $result = restrictedArea($user, 'contact', $object->id, 'socpeople&societe');
93 
94 
95 /*
96  * Actions
97  */
98 
99 $parameters = array('id'=>$id);
100 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
101 if ($reshook < 0) {
102  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
103 }
104 
105 
106 /*
107  * View
108  */
109 $form = new Form($db);
110 $formother = new FormOther($db);
111 $productstatic = new Product($db);
112 $objsoc = new Societe($db);
113 
114 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
115 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
116 llxHeader('', $title, $help_url);
117 
118 if (empty($id)) {
119  dol_print_error($db);
120  exit;
121 }
122 
123 $head = contact_prepare_head($object);
124 print dol_get_fiche_head($head, 'consumption', $langs->trans("ContactsAddresses"), -1, 'contact');
125 
126 $linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
127 
128 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
129 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
130 $morehtmlref .= '</a>';
131 
132 $morehtmlref .= '<div class="refidno">';
133 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
134  $objsoc->fetch($socid);
135  // Thirdparty
136  $morehtmlref .= $langs->trans('ThirdParty').' : ';
137  if ($objsoc->id > 0) {
138  $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
139  } else {
140  $morehtmlref .= $langs->trans("ContactNotLinkedToCompany");
141  }
142 }
143 $morehtmlref .= '</div>';
144 
145 dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref);
146 
147 print '<div class="fichecenter">';
148 
149 print '<div class="underbanner clearboth"></div>';
150 print '<table class="border centpercent tableforfield">';
151 
152 // Civility
153 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
154 print $object->getCivilityLabel();
155 print '</td></tr>';
156 
157 if ($object->thirdparty->client) {
158  $thirdTypeArray['customer'] = $langs->trans("customer");
159  if (isModEnabled("propal") && $user->rights->propal->lire) {
160  $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
161  }
162  if (isModEnabled('commande') && $user->rights->commande->lire) {
163  $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
164  }
165  if (isModEnabled('facture') && $user->rights->facture->lire) {
166  $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
167  }
168  if (isModEnabled('contrat') && $user->rights->contrat->lire) {
169  $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
170  }
171 }
172 
173 if (isModEnabled('ficheinter') && $user->rights->ficheinter->lire) {
174  $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
175 }
176 
177 if ($object->thirdparty->fournisseur) {
178  $thirdTypeArray['supplier'] = $langs->trans("supplier");
179  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled("supplier_invoice") && $user->rights->supplier_invoice->lire)) {
180  $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
181  }
182  if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->commande->lire) || (isModEnabled("supplier_order") && $user->rights->supplier_order->lire)) {
183  $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
184  }
185 
186  // There no contact type for supplier proposals
187  // if ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals');
188 }
189 
190 print '</table>';
191 
192 print '</div>';
193 
194 print dol_get_fiche_end();
195 print '<br>';
196 
197 
198 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$id.'">';
199 print '<input type="hidden" name="token" value="'.newToken().'">';
200 
201 $sql_select = '';
202 if ($type_element == 'fichinter') { // Customer : show products from invoices
203  require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
204  $documentstatic = new Fichinter($db);
205  $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, tc.libelle as type_contact_label, ';
206  $tables_from = MAIN_DB_PREFIX.'fichinterdet d';
207  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinter as f ON d.fk_fichinter=f.rowid';
208  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id);
209  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='fichinter' and tc.source='external' and tc.active=1)";
210  $where = ' WHERE f.entity IN ('.getEntity('ficheinter').')';
211  $dateprint = 'f.datec';
212  $doc_number = 'f.ref';
213 } elseif ($type_element == 'invoice') { // Customer : show products from invoices
214  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
215  $documentstatic = new Facture($db);
216  $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, tc.libelle as type_contact_label, ';
217  $tables_from = MAIN_DB_PREFIX.'facturedet d';
218  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON d.fk_facture=f.rowid';
219  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
220  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id);
221  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='facture' and tc.source='external' and tc.active=1)";
222  $where = " WHERE f.entity IN (".getEntity('invoice').")";
223  $dateprint = 'f.datef';
224  $doc_number = 'f.ref';
225  $thirdTypeSelect = 'customer';
226 } elseif ($type_element == 'propal') {
227  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
228  $documentstatic = new Propal($db);
229  $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, tc.libelle as type_contact_label, ';
230  $tables_from = MAIN_DB_PREFIX.'propaldet d';
231  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal as c ON d.fk_propal=c.rowid';
232  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
233  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
234  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='propal' and tc.source='external' and tc.active=1)";
235  $where = ' WHERE c.entity IN ('.getEntity('propal').')';
236  $dateprint = 'c.datep';
237  $doc_number = 'c.ref';
238  $thirdTypeSelect = 'customer';
239 } elseif ($type_element == 'order') {
240  require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
241  $documentstatic = new Commande($db);
242  $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, tc.libelle as type_contact_label, ';
243  $tables_from = MAIN_DB_PREFIX.'commandedet d';
244  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande as c ON d.fk_commande=c.rowid';
245  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
246  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
247  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='commande' and tc.source='external' and tc.active=1)";
248  $where = ' WHERE c.entity IN ('.getEntity('order').')';
249  $dateprint = 'c.date_commande';
250  $doc_number = 'c.ref';
251  $thirdTypeSelect = 'customer';
252 } elseif ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
253  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
254  $documentstatic = new FactureFournisseur($db);
255  $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, tc.libelle as type_contact_label, ';
256  $tables_from = MAIN_DB_PREFIX.'facture_fourn_det d';
257  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn as f ON d.fk_facture_fourn=f.rowid';
258  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
259  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id);
260  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='invoice_supplier' and tc.source='external' and tc.active=1)";
261  $where = ' WHERE f.entity IN ('.getEntity($documentstatic->element).')';
262  $dateprint = 'f.datef';
263  $doc_number = 'f.ref';
264  $thirdTypeSelect = 'supplier';
265  //} elseif ($type_element == 'supplier_proposal') {
266  // require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
267  // $documentstatic=new SupplierProposal($db);
268  // $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, ';
269  // $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
270  // $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
271  // $where.= " AND d.fk_supplier_proposal = c.rowid";
272  // $where.= " AND c.entity = ".$conf->entity;
273  // $dateprint = 'c.date_valid';
274  // $doc_number='c.ref';
275  // $thirdTypeSelect='supplier';
276  //}
277 } elseif ($type_element == 'supplier_order') { // Supplier : Show products from orders.
278  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
279  $documentstatic = new CommandeFournisseur($db);
280  $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, tc.libelle as type_contact_label, ';
281  $tables_from = MAIN_DB_PREFIX.'commande_fournisseurdet d';
282  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur as c ON d.fk_commande=c.rowid';
283  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
284  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
285  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='order_supplier' and tc.source='external' and tc.active=1)";
286  $where = ' WHERE c.entity IN ('.getEntity($documentstatic->element).')';
287  $dateprint = 'c.date_valid';
288  $doc_number = 'c.ref';
289  $thirdTypeSelect = 'supplier';
290 } elseif ($type_element == 'contract') { // Order
291  require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
292  $documentstatic = new Contrat($db);
293  $documentstaticline = new ContratLigne($db);
294  $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, tc.libelle as type_contact_label, ';
295  $tables_from = MAIN_DB_PREFIX.'contratdet d';
296  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contrat as c ON d.fk_contrat=c.rowid';
297  $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
298  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
299  $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='contrat' and tc.source='external' and tc.active=1)";
300  $where = ' WHERE c.entity IN ('.getEntity('contrat').')';
301  $dateprint = 'c.date_valid';
302  $doc_number = 'c.ref';
303  $thirdTypeSelect = 'customer';
304 }
305 
306 $parameters = array();
307 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
308 
309 if (!empty($sql_select)) {
310  $sql = $sql_select;
311  $sql .= ' d.description as description';
312  if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
313  $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, ';
314  }
315  if ($type_element == 'supplier_proposal') {
316  $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, ';
317  }
318  if ($type_element == 'contract') {
319  $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, ';
320  }
321  if ($type_element != 'fichinter') {
322  $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';
323  }
324  $sql .= " ";
325  if ($type_element != 'fichinter') {
326  $sql .= ", p.ref as prod_ref, p.label as product_label";
327  }
328  $sql .= " FROM "/*.MAIN_DB_PREFIX."societe as s, "*/.$tables_from;
329  // if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
330  $sql .= $where;
331  $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
332  if ($sref) {
333  $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
334  }
335  if ($sprod_fulldescr) {
336  $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'";
337  if (GETPOST('type_element') != 'fichinter') {
338  $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
339  }
340  if (GETPOST('type_element') != 'fichinter') {
341  $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
342  }
343  $sql .= ")";
344  }
345  $sql .= $db->order($sortfield, $sortorder);
346  $resql = $db->query($sql);
347  $totalnboflines = $db->num_rows($resql);
348 
349  $sql .= $db->plimit($limit + 1, $offset);
350 }
351 
352 $disabled = 0;
353 $showempty = 2;
354 if (empty($elementTypeArray) && !$object->thirdparty->client && !$object->thirdparty->fournisseur) {
355  $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
356  $disabled = 1;
357 }
358 
359 // Define type of elements
360 $typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
361 $button = '<input type="submit" class="button small" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
362 
363 $param = '';
364 $param .= "&sref=".urlencode($sref);
365 $param .= "&month=".urlencode($month);
366 $param .= "&year=".urlencode($year);
367 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
368 $param .= "&socid=".urlencode($socid);
369 $param .= "&type_element=".urlencode($type_element);
370 
371 $total_qty = 0;
372 $num=0;
373 if ($sql_select) {
374  $resql = $db->query($sql);
375  if (!$resql) {
376  dol_print_error($db);
377  }
378 
379  $num = $db->num_rows($resql);
380 
381  $param = "&socid=".urlencode($socid)."&type_element=".urlencode($type_element)."&id=".urlencode($id);
382  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
383  $param .= '&contextpage='.urlencode($contextpage);
384  }
385  if ($limit > 0 && $limit != $conf->liste_limit) {
386  $param .= '&limit='.urlencode($limit);
387  }
388  if ($sprod_fulldescr) {
389  $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
390  }
391  if ($sref) {
392  $param .= "&sref=".urlencode($sref);
393  }
394  if ($month) {
395  $param .= "&month=".urlencode($month);
396  }
397  if ($year) {
398  $param .= "&year=".urlencode($year);
399  }
400  if ($optioncss != '') {
401  $param .= '&optioncss='.urlencode($optioncss);
402  }
403 
404  print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit);
405 
406  print '<div class="div-table-responsive-no-min">';
407  print '<table class="liste centpercent">'."\n";
408 
409  // Filters
410  print '<tr class="liste_titre">';
411  print '<td class="liste_titre left">';
412  print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
413  print '</td>';
414  print '<td class="liste_titre nowrap center">'; // date
415  print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle');
416  print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 1);
417  print '</td>';
418  print '<td class="liste_titre center">';
419  print '</td>';
420  print '<td class="liste_titre left">';
421  print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
422  print '</td>';
423  print '<td class="liste_titre center">'; // TODO: Add filters !
424  print '</td>';
425  print '<td class="liste_titre center">';
426  print '</td>';
427  print '<td class="liste_titre center">';
428  print '</td>';
429  print '<td class="liste_titre maxwidthsearch">';
430  $searchpicto = $form->showFilterAndCheckAddButtons(0);
431  print $searchpicto;
432  print '</td>';
433  print '</tr>';
434 
435  // Titles with sort buttons
436  print '<tr class="liste_titre">';
437  print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
438  print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
439  print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
440  print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
441  print_liste_field_titre('ContactType', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
442  print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
443  print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
444  print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
445  print "</tr>\n";
446 
447 
448  $i = 0;
449  $total_qty = 0;
450  $total_ht = 0;
451  while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
452  $documentstatic->id = $objp->doc_id;
453  $documentstatic->ref = $objp->doc_number;
454  $documentstatic->type = $objp->doc_type;
455  $documentstatic->fk_statut = $objp->status;
456  $documentstatic->fk_status = $objp->status;
457  $documentstatic->statut = $objp->status;
458  $documentstatic->status = $objp->status;
459  $documentstatic->paye = $objp->paid;
460  $documentstatic->paid = $objp->paid;
461 
462  if (is_object($documentstaticline)) {
463  $documentstaticline->statut = $objp->status;
464  }
465 
466  print '<tr class="oddeven">';
467  print '<td class="nobordernopadding nowrap" width="100">';
468  print $documentstatic->getNomUrl(1);
469  print '</td>';
470  print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
471 
472  // Status
473  print '<td class="center">';
474  if ($type_element == 'contract') {
475  print $documentstaticline->getLibStatut(2);
476  } else {
477  print $documentstatic->getLibStatut(2);
478  }
479  print '</td>';
480 
481  print '<td>';
482 
483  // Define text, description and type
484  $text = ''; $description = ''; $type = 0;
485 
486  // Code to show product duplicated from commonobject->printObjectLine
487  if ($objp->fk_product > 0) {
488  $product_static = new Product($db);
489 
490  $product_static->type = $objp->fk_product_type;
491  $product_static->id = $objp->fk_product;
492  $product_static->ref = $objp->ref;
493  $product_static->entity = $objp->pentity;
494  $text = $product_static->getNomUrl(1);
495  }
496 
497  // Product
498  if ($objp->fk_product > 0) {
499  // Define output language
500  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
501  $prod = new Product($db);
502  $prod->fetch($objp->fk_product);
503 
504  $outputlangs = $langs;
505  $newlang = '';
506  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
507  $newlang = GETPOST('lang_id', 'aZ09');
508  }
509  if (empty($newlang)) {
510  $newlang = $object->default_lang;
511  }
512  if (!empty($newlang)) {
513  $outputlangs = new Translate("", $conf);
514  $outputlangs->setDefaultLang($newlang);
515  }
516 
517  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
518  } else {
519  $label = $objp->product_label;
520  }
521 
522  $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
523  $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
524  }
525 
526  if (($objp->info_bits & 2) == 2) {
527  print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'">';
528  $txt = '';
529  print img_object($langs->trans("ShowReduc"), 'reduc').' ';
530  if ($objp->description == '(DEPOSIT)') {
531  $txt = $langs->trans("Deposit");
532  } elseif ($objp->description == '(EXCESS RECEIVED)') {
533  $txt = $langs->trans("ExcessReceived");
534  } elseif ($objp->description == '(EXCESS PAID)') {
535  $txt = $langs->trans("ExcessPaid");
536  }
537  //else $txt=$langs->trans("Discount");
538  print $txt;
539  print '</a>';
540  if ($objp->description) {
541  if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
542  $discount = new DiscountAbsolute($db);
543  $discount->fetch($objp->fk_remise_except);
544  echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
545  }
546  if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
547  $discount = new DiscountAbsolute($db);
548  $discount->fetch($objp->fk_remise_except);
549  echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
550  } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
551  $discount = new DiscountAbsolute($db);
552  $discount->fetch($objp->fk_remise_except);
553  echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
554  } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
555  $discount = new DiscountAbsolute($db);
556  $discount->fetch($objp->fk_remise_except);
557  echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
558  // Add date of deposit
559  if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
560  echo ' ('.dol_print_date($discount->datec).')';
561  }
562  } else {
563  echo ($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
564  }
565  }
566  } else {
567  if ($objp->fk_product > 0) {
568  echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, '');
569 
570  // Show range
571  echo get_date_range($objp->date_start, $objp->date_end);
572 
573  // Add description in form
574  if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
575  print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
576  }
577  } else {
578  if (!empty($objp->label) || !empty($objp->description)) {
579  if ($type == 1) {
580  $text = img_object($langs->trans('Service'), 'service');
581  } else {
582  $text = img_object($langs->trans('Product'), 'product');
583  }
584 
585  if (!empty($objp->label)) {
586  $text .= ' <strong>'.$objp->label.'</strong>';
587  echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, '', '', $i, 0, '');
588  } else {
589  echo $text.' '.dol_htmlentitiesbr($objp->description);
590  }
591  }
592 
593  // Show range
594  echo get_date_range($objp->date_start, $objp->date_end);
595  }
596  }
597 
598  /*
599  $prodreftxt='';
600  if ($objp->prod_id > 0)
601  {
602  $productstatic->id = $objp->prod_id;
603  $productstatic->ref = $objp->prod_ref;
604  $productstatic->status = $objp->prod_type;
605  $prodreftxt = $productstatic->getNomUrl(0);
606  if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
607  }
608  // Show range
609  $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
610  // Add description in form
611  if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
612  {
613  $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
614  }
615  */
616  print '</td>';
617 
618  print '<td>'.$objp->type_contact_label.'</td>'; // Type of contact label
619 
620  print '<td class="right">'.$objp->prod_qty.'</td>';
621  $total_qty += $objp->prod_qty;
622 
623  print '<td class="right">'.price($objp->total_ht).'</td>';
624  $total_ht += $objp->total_ht;
625 
626  print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
627 
628  print "</tr>\n";
629  $i++;
630  }
631 
632  print '<tr class="liste_total">';
633  print '<td>'.$langs->trans('Total').'</td>';
634  print '<td colspan="3"></td>';
635  print '<td></td>';
636  print '<td class="right">'.$total_qty.'</td>';
637  print '<td class="right">'.price($total_ht).'</td>';
638  print '<td class="right">'.price($total_ht / (empty($total_qty) ? 1 : $total_qty)).'</td>';
639  print "</table>";
640  print '</div>';
641 
642  if ($num > $limit) {
643  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
644  }
645  $db->free($resql);
646 } elseif (empty($type_element) || $type_element == -1) {
647  print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
648 
649  print '<table class="liste centpercent">'."\n";
650  // Titles with sort buttons
651  print '<tr class="liste_titre">';
652  print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
653  print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
654  print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
655  print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
656  print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
657  print "</tr>\n";
658 
659  print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
660 
661  print "</table>";
662 } else {
663  print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
664 
665  print '<table class="liste centpercent">'."\n";
666 
667  print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
668 
669  print "</table>";
670 }
671 
672 print "</form>";
673 
674 // End of page
675 llxFooter();
676 $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 contact/addresses.
Class to manage contracts.
Class to manage lines of contracts.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
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 translations.
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
contact_prepare_head(Contact $object)
Prepare array with list of tabs.
Definition: contact.lib.php:33
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.
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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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.