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