dolibarr 25.0.0-alpha
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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
32// Load Dolibarr environment
33require "../main.inc.php";
41require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
45require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
46
47$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
48$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
49
50$action = GETPOST('action', 'aZ');
51$id = GETPOSTINT('id');
52
53$object = new Contact($db);
54if ($id > 0) {
55 $object->fetch($id);
56}
57if (empty($object->thirdparty)) {
58 $object->fetch_thirdparty();
59}
60$socid = !empty($object->thirdparty->id) ? $object->thirdparty->id : null;
61
62// Sort & Order fields
63$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64$sortfield = GETPOST('sortfield', 'aZ09comma');
65$sortorder = GETPOST('sortorder', 'aZ09comma');
66$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
67if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
68 // If $page is not defined, or '' or -1 or if we click on clear filters
69 $page = 0;
70}
71$offset = $limit * $page;
72$pageprev = $page - 1;
73$pagenext = $page + 1;
74if (!$sortorder) {
75 $sortorder = 'DESC';
76}
77if (!$sortfield) {
78 $sortfield = 'dateprint';
79}
80
81// Search fields
82$sref = GETPOST("sref");
83$sprod_fulldescr = GETPOST("sprod_fulldescr");
84$month = GETPOSTINT('month');
85$year = GETPOSTINT('year');
86
87// Clean up on purge search criteria ?
88if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
89 $sref = '';
90 $sprod_fulldescr = '';
91 $year = '';
92 $month = '';
93}
94// Customer or supplier selected in drop box
95$thirdTypeSelect = GETPOST("third_select_id");
96$type_element = GETPOSTISSET('type_element') ? GETPOST('type_element') : '';
97
98// Load translation files required by the page
99$langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
100
101// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
102$hookmanager->initHooks(array('consumptioncontact'));
103
104$result = restrictedArea($user, 'contact', $object->id, 'socpeople&societe');
105
106
107/*
108 * Actions
109 */
110
111$parameters = array('id' => $id);
112$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
113if ($reshook < 0) {
114 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
115}
116
117
118/*
119 * View
120 */
121$form = new Form($db);
122$formother = new FormOther($db);
123$productstatic = new Product($db);
124$objsoc = new Societe($db);
125
126$title = $langs->trans("ContactRelatedItems");
127$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
128
129llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-societe page-contact-card_consumption');
130
131if (empty($id)) {
133 exit;
134}
135
136$head = contact_prepare_head($object);
137print dol_get_fiche_head($head, 'consumption', $langs->trans("ContactsAddresses"), -1, 'contact');
138
139$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
140
141$morehtmlref = '<a href="'.DOL_URL_ROOT.'/contact/vcard.php?id='.$object->id.'" class="refid">';
142$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard', 'class="valignmiddle marginleftonly paddingrightonly"');
143$morehtmlref .= '</a>';
144
145$morehtmlref .= '<div class="refidno">';
146if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
147 $objsoc->fetch($socid);
148 // Thirdparty
149 if ($objsoc->id > 0) {
150 $morehtmlref .= $objsoc->getNomUrl(1, 'contact');
151 } else {
152 $morehtmlref .= '<span class="opacitymedium">'.$langs->trans("ContactNotLinkedToCompany").'</span>';
153 }
154}
155$morehtmlref .= '</div>';
156
157dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref);
158
159print '<div class="fichecenter">';
160
161print '<div class="underbanner clearboth"></div>';
162print '<table class="border centpercent tableforfield">';
163
164// Civility
165if (getDolGlobalString('MAIN_USE_TITLE_FOR_CONTACT')) {
166 print '<tr><td class="titlefield">'.$langs->trans("UserTitle").'</td><td>';
167 print $object->getCivilityLabel();
168 print '</td></tr>';
169}
170
171$thirdTypeArray = array();
172$elementTypeArray = array();
173
174if (!empty($object->thirdparty->client)) {
175 $thirdTypeArray['customer'] = $langs->trans("customer");
176 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
177 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
178 }
179 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
180 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
181 }
182 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
183 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
184 }
185 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
186 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
187 }
188}
189
190if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')) {
191 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
192}
193
194if (!empty($object->thirdparty->fournisseur)) {
195 $thirdTypeArray['supplier'] = $langs->trans("supplier");
196 if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'facture', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
197 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
198 }
199 if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'commande', 'lire')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
200 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
201 }
202
203 // There are no contact type for supplier proposals
204 // 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');
205}
206
207print '</table>';
208
209print '</div>';
210
211print dol_get_fiche_end();
212print '<br>';
213
214
215print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$id.'">';
216print '<input type="hidden" name="token" value="'.newToken().'">';
217
218$documentstatic = null;
219$documentstaticline = null;
220$sql_select = '';
221$doc_number = '';
222$dateprint = '';
223$tables_from = '';
224$where = '';
225if ($type_element == 'fichinter') { // Customer : show products from invoices
226 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
227 $documentstatic = new Fichinter($db);
228 $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, ';
229 $tables_from = MAIN_DB_PREFIX.'fichinterdet d';
230 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinter as f ON d.fk_fichinter=f.rowid';
231 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.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='fichinter' and tc.source='external' and tc.active=1)";
233 $where = ' WHERE f.entity IN ('.getEntity('intervention').')';
234 $dateprint = 'f.datec';
235 $doc_number = 'f.ref';
236} elseif ($type_element == 'invoice') { // Customer : show products from invoices
237 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
238 $documentstatic = new Facture($db);
239 $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, ';
240 $tables_from = MAIN_DB_PREFIX.'facturedet d';
241 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON d.fk_facture=f.rowid';
242 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
243 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id);
244 $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)";
245 $where = " WHERE f.entity IN (".getEntity('invoice').")";
246 $dateprint = 'f.datef';
247 $doc_number = 'f.ref';
248 $thirdTypeSelect = 'customer';
249} elseif ($type_element == 'propal') {
250 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
251 $documentstatic = new Propal($db);
252 $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, ';
253 $tables_from = MAIN_DB_PREFIX.'propaldet d';
254 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal as c ON d.fk_propal=c.rowid';
255 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
256 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
257 $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)";
258 $where = ' WHERE c.entity IN ('.getEntity('propal').')';
259 $dateprint = 'c.datep';
260 $doc_number = 'c.ref';
261 $thirdTypeSelect = 'customer';
262} elseif ($type_element == 'order') {
263 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
264 $documentstatic = new Commande($db);
265 $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, ';
266 $tables_from = MAIN_DB_PREFIX.'commandedet d';
267 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande as c ON d.fk_commande=c.rowid';
268 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
269 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
270 $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)";
271 $where = ' WHERE c.entity IN ('.getEntity('order').')';
272 $dateprint = 'c.date_commande';
273 $doc_number = 'c.ref';
274 $thirdTypeSelect = 'customer';
275} elseif ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
276 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
277 $documentstatic = new FactureFournisseur($db);
278 $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, ';
279 $tables_from = MAIN_DB_PREFIX.'facture_fourn_det d';
280 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn as f ON d.fk_facture_fourn=f.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=f.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='invoice_supplier' and tc.source='external' and tc.active=1)";
284 $where = ' WHERE f.entity IN ('.getEntity($documentstatic->element).')';
285 $dateprint = 'f.datef';
286 $doc_number = 'f.ref';
287 $thirdTypeSelect = 'supplier';
288 //} elseif ($type_element == 'supplier_proposal') {
289 // require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
290 // $documentstatic=new SupplierProposal($db);
291 // $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, ';
292 // $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
293 // $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
294 // $where.= " AND d.fk_supplier_proposal = c.rowid";
295 // $where.= " AND c.entity = ".$conf->entity;
296 // $dateprint = 'c.date_valid';
297 // $doc_number='c.ref';
298 // $thirdTypeSelect='supplier';
299 //}
300} elseif ($type_element == 'supplier_order') { // Supplier : Show products from orders.
301 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
302 $documentstatic = new CommandeFournisseur($db);
303 $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, ';
304 $tables_from = MAIN_DB_PREFIX.'commande_fournisseurdet d';
305 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur as c ON d.fk_commande=c.rowid';
306 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
307 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
308 $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)";
309 $where = ' WHERE c.entity IN ('.getEntity($documentstatic->element).')';
310 $dateprint = 'c.date_valid';
311 $doc_number = 'c.ref';
312 $thirdTypeSelect = 'supplier';
313} elseif ($type_element == 'contract') { // Order
314 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
315 $documentstatic = new Contrat($db);
316 $documentstaticline = new ContratLigne($db);
317 $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, ';
318 $tables_from = MAIN_DB_PREFIX.'contratdet d';
319 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contrat as c ON d.fk_contrat=c.rowid';
320 $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid';
321 $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id);
322 $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)";
323 $where = ' WHERE c.entity IN ('.getEntity('contrat').')';
324 $dateprint = 'c.date_valid';
325 $doc_number = 'c.ref';
326 $thirdTypeSelect = 'customer';
327}
328
329$parameters = array();
330$totalnboflines = 0;
331$sql = '';
332$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
333
334if (!empty($sql_select)) {
335 $sql = $sql_select;
336 $sql .= ' d.description as description';
337 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
338 $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, ';
339 }
340 if ($type_element == 'supplier_proposal') {
341 $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, ';
342 }
343 if ($type_element == 'contract') {
344 $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, ';
345 }
346 if ($type_element != 'fichinter') {
347 $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';
348 }
349 $sql .= " ";
350 if ($type_element != 'fichinter') {
351 $sql .= ", p.ref as prod_ref, p.label as product_label";
352 }
353 $sanitizedtablefrom = $tables_from;
354 $sql .= " FROM ".$sanitizedtablefrom;
355 $sanitizedwhere = $where;
356 $sql .= $sanitizedwhere;
357 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
358 if ($sref && !empty($doc_number)) {
359 $sql .= " AND ".$db->sanitize($doc_number)." LIKE '%".$db->escape($sref)."%'";
360 }
361 if ($sprod_fulldescr) {
362 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'";
363 if (GETPOST('type_element') != 'fichinter') {
364 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
365 }
366 if (GETPOST('type_element') != 'fichinter') {
367 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
368 }
369 $sql .= ")";
370 }
371 $parameters = array('type_element' => $type_element);
372 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
373 $sql .= $hookmanager->resPrint;
374 $sql .= $db->order($sortfield, $sortorder);
375
376 $resql = $db->query($sql);
377 if (!$resql) {
379 }
380 $totalnboflines = $db->num_rows($resql); // TODO Make a SQL count to have a better performance
381
382 $sql .= $db->plimit($limit + 1, $offset);
383}
384
385$disabled = 0;
386$showempty = 2;
387if (empty($elementTypeArray) && !$object->thirdparty->client && !$object->thirdparty->fournisseur) {
388 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
389 $disabled = 1;
390}
391
392// Define type of elements
393$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
394$button = '<input type="submit" class="button small" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
395
396$param = '';
397$param .= "&sref=".urlencode($sref);
398$param .= "&month=".urlencode($month);
399$param .= "&year=".urlencode($year);
400$param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
401if (!empty($socid)) {
402 $param .= "&socid=".urlencode((string) ($socid));
403}
404$param .= "&type_element=".urlencode($type_element);
405
406$total_qty = 0;
407$num = 0;
408if ($sql_select && $documentstatic !== null) {
409 $resql = $db->query($sql);
410 if (!$resql) {
412 }
413
414 $num = $db->num_rows($resql);
415
416 $param = (!empty($socid) ? "&socid=".urlencode((string) ($socid)) : "")."&type_element=".urlencode((string) ($type_element))."&id=".urlencode((string) ($id));
417 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
418 $param .= '&contextpage='.urlencode($contextpage);
419 }
420 if ($limit > 0 && $limit != $conf->liste_limit) {
421 $param .= '&limit='.((int) $limit);
422 }
423 if ($sprod_fulldescr) {
424 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
425 }
426 if ($sref) {
427 $param .= "&sref=".urlencode($sref);
428 }
429 if ($month) {
430 $param .= "&month=".urlencode((string) ($month));
431 }
432 if ($year) {
433 $param .= "&year=".urlencode((string) ($year));
434 }
435 if ($optioncss != '') {
436 $param .= '&optioncss='.urlencode($optioncss);
437 }
438
439 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', 'nogreyscale', $limit);
440
441 print '<div class="div-table-responsive-no-min">';
442 print '<table class="liste centpercent">'."\n";
443
444 // Filters
445 print '<tr class="liste_titre">';
446 print '<td class="liste_titre left">';
447 print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
448 print '</td>';
449 print '<td class="liste_titre nowrap center">'; // date
450 print $formother->select_month($month ? (string) $month : '-1', 'month', 1, 0, 'valignmiddle');
451 print $formother->selectyear($year ? (string) $year : '-1', 'year', 1, 20, 1);
452 print '</td>';
453 print '<td class="liste_titre center">';
454 print '</td>';
455 print '<td class="liste_titre left">';
456 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
457 print '</td>';
458 print '<td class="liste_titre center">'; // TODO: Add filters !
459 print '</td>';
460 print '<td class="liste_titre center">';
461 print '</td>';
462 print '<td class="liste_titre center">';
463 print '</td>';
464 print '<td class="liste_titre maxwidthsearch">';
465 $searchpicto = $form->showFilterAndCheckAddButtons(0);
466 print $searchpicto;
467 print '</td>';
468 print '</tr>';
469
470 // Titles with sort buttons
471 print '<tr class="liste_titre">';
472 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
473 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
474 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
475 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
476 print_liste_field_titre('ContactType', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
477 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
478 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
479 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
480 print "</tr>\n";
481
482
483 $i = 0;
484 $total_qty = 0;
485 $total_ht = 0;
486 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
487 $documentstatic->id = $objp->doc_id;
488 $documentstatic->ref = $objp->doc_number;
489 $documentstatic->type = $objp->doc_type;
490
491 $documentstatic->fk_statut = $objp->status;
492 $documentstatic->statut = $objp->status;
493 $documentstatic->status = $objp->status;
494 if ($type_element == 'invoice' || $type_element == 'supplier_invoice') {
495 $documentstatic->paye = $objp->paid;
496 $documentstatic->paid = $objp->paid;
497 }
498
499 if (is_object($documentstaticline)) {
500 $documentstaticline->statut = $objp->status;
501 }
502
503 print '<tr class="oddeven">';
504 print '<td class="nobordernopadding nowrap" width="100">';
505 print $documentstatic->getNomUrl(1);
506 print '</td>';
507 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
508
509 // Status
510 print '<td class="center">';
511 if ($type_element == 'contract') {
512 print $documentstaticline->getLibStatut(2);
513 } else {
514 print $documentstatic->getLibStatut(2);
515 }
516 print '</td>';
517
518 print '<td>';
519
520 // Define text, description and type
521 $text = '';
522 $description = '';
523 $type = 0;
524
525 // Code to show product duplicated from commonobject->printObjectLine
526 if ($objp->fk_product > 0) {
527 $product_static = new Product($db);
528
529 $product_static->type = $objp->fk_product_type;
530 $product_static->id = $objp->fk_product;
531 $product_static->ref = $objp->ref;
532 $product_static->entity = $objp->pentity;
533 $text = $product_static->getNomUrl(1);
534 }
535
536 // Product
537 if ($objp->fk_product > 0) {
538 // Define output language
539 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
540 $prod = new Product($db);
541 $prod->fetch($objp->fk_product);
542
543 $outputlangs = $langs;
544 $newlang = '';
545 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
546 $newlang = GETPOST('lang_id', 'aZ09');
547 }
548 if (empty($newlang)) {
549 $newlang = $object->default_lang;
550 }
551 if (!empty($newlang)) {
552 $outputlangs = new Translate("", $conf);
553 $outputlangs->setDefaultLang($newlang);
554 }
555
556 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
557 } else {
558 $label = $objp->product_label;
559 }
560
561 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
562 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
563 }
564
565 if (($objp->info_bits & 2) == 2) {
566 print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'">';
567 $txt = '';
568 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
569 if ($objp->description == '(DEPOSIT)') {
570 $txt = $langs->trans("Deposit");
571 } elseif ($objp->description == '(EXCESS RECEIVED)') {
572 $txt = $langs->trans("ExcessReceived");
573 } elseif ($objp->description == '(EXCESS PAID)') {
574 $txt = $langs->trans("ExcessPaid");
575 }
576 //else $txt=$langs->trans("Discount");
577 print $txt;
578 print '</a>';
579 if ($objp->description) {
580 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
581 $discount = new DiscountAbsolute($db);
582 $discount->fetch($objp->fk_remise_except);
583 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
584 }
585 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
586 $discount = new DiscountAbsolute($db);
587 $discount->fetch($objp->fk_remise_except);
588 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
589 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
590 $discount = new DiscountAbsolute($db);
591 $discount->fetch($objp->fk_remise_except);
592 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
593 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
594 $discount = new DiscountAbsolute($db);
595 $discount->fetch($objp->fk_remise_except);
596 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
597 // Add date of deposit
598 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
599 echo ' ('.dol_print_date($discount->datec).')';
600 }
601 } else {
602 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
603 }
604 }
605 } else {
606 if ($objp->fk_product > 0) {
607 echo $form->textwithtooltip($text, $description, 3, 0, '', (string) $i, 0, '');
608
609 // Show range
610 echo get_date_range($objp->date_start, $objp->date_end);
611
612 // Add description in form
613 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
614 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
615 }
616 } else {
617 if (!empty($objp->label) || !empty($objp->description)) {
618 if ($type == 1) {
619 $text = img_object($langs->trans('Service'), 'service');
620 } else {
621 $text = img_object($langs->trans('Product'), 'product');
622 }
623
624 if (!empty($objp->label)) {
625 $text .= ' <strong>'.$objp->label.'</strong>';
626 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, 0, '', (string) $i, 0, '');
627 } else {
628 echo $text.' '.dol_htmlentitiesbr($objp->description);
629 }
630 }
631
632 // Show range
633 echo get_date_range($objp->date_start, $objp->date_end);
634 }
635 }
636
637 /*
638 $prodreftxt='';
639 if ($objp->prod_id > 0)
640 {
641 $productstatic->id = $objp->prod_id;
642 $productstatic->ref = $objp->prod_ref;
643 $productstatic->status = $objp->prod_type;
644 $prodreftxt = $productstatic->getNomUrl(0);
645 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
646 }
647 // Show range
648 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
649 // Add description in form
650 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
651 {
652 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
653 }
654 */
655 print '</td>';
656
657 print '<td>'.$objp->type_contact_label.'</td>'; // Type of contact label
658
659 print '<td class="right">'.$objp->prod_qty.'</td>';
660 $total_qty += $objp->prod_qty;
661
662 print '<td class="right">'.price($objp->total_ht).'</td>';
663 $total_ht += $objp->total_ht;
664
665 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
666
667 print "</tr>\n";
668 $i++;
669 }
670
671 print '<tr class="liste_total">';
672 print '<td>'.$langs->trans('Total').'</td>';
673 print '<td colspan="3"></td>';
674 print '<td></td>';
675 print '<td class="right">'.$total_qty.'</td>';
676 print '<td class="right">'.price($total_ht).'</td>';
677 print '<td class="right">'.price($total_ht / (empty($total_qty) ? 1 : $total_qty)).'</td>';
678 print "</table>";
679 print '</div>';
680
681 if ($num > $limit) {
682 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
683 }
684 $db->free($resql);
685} elseif (empty($type_element) || $type_element == -1) {
686 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
687
688 print '<table class="liste centpercent">'."\n";
689 // Titles with sort buttons
690 print '<tr class="liste_titre">';
691 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
692 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
693 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
694 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
695 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
696 print "</tr>\n";
697
698 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
699
700 print "</table>";
701} else {
702 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '', 0, '', 'nogreyscale', $limit);
703
704 print '<table class="liste centpercent">'."\n";
705
706 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
707
708 print "</table>";
709}
710
711print "</form>";
712
713// End of page
714llxFooter();
715$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage contact/addresses.
Class to manage lines of contracts.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components 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:386
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
Definition html.lib.php:172
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.