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