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