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