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