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