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