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) 2021-2022 Frédéric France <frederic.france@netlogic.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require "../main.inc.php";
32require_once DOL_DOCUMENT_ROOT.'/core/lib/company.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';
36
37
38// Load translation files required by the page
39$langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
40
41
42$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
43
44// Security check
45$socid = GETPOSTINT('socid');
46if ($user->socid) {
47 $socid = $user->socid;
48}
49
50// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
51$hookmanager->initHooks(array('consumptionthirdparty', 'globalcard'));
52
53$result = restrictedArea($user, 'societe', $socid, '&societe');
54$object = new Societe($db);
55if ($socid > 0) {
56 $object->fetch($socid);
57}
58
59// Sort & Order fields
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
64$optioncss = GETPOST('optioncss', 'alpha');
65
66if (empty($page) || $page == -1) {
67 $page = 0;
68} // If $page is not defined, or '' or -1
69$offset = $limit * $page;
70$pageprev = $page - 1;
71$pagenext = $page + 1;
72if (!$sortorder) {
73 $sortorder = 'DESC';
74}
75if (!$sortfield) {
76 $sortfield = 'dateprint';
77}
78
79// Search fields
80$sref = GETPOST("sref");
81$sprod_fulldescr = GETPOST("sprod_fulldescr");
82$month = GETPOSTINT('month');
83$year = GETPOSTINT('year');
84
85// Clean up on purge search criteria ?
86if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
87 $sref = '';
88 $sprod_fulldescr = '';
89 $year = '';
90 $month = '';
91}
92
93// Customer or supplier selected in drop box
94$thirdTypeSelect = GETPOST("third_select_id", 'aZ09');
95$type_element = GETPOST('type_element') ? GETPOST('type_element') : '';
96
97/*
98 * Actions
99 */
100
101$parameters = array('id' => $socid);
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/*
110 * View
111 */
112
113$form = new Form($db);
114$formother = new FormOther($db);
115$productstatic = new Product($db);
116
117$title = $langs->trans("Referers", $object->name);
118if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/thirdpartynameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
119 $title = $object->name." - ".$title;
120}
121$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
122llxHeader('', $title, $help_url);
123
124if (empty($socid)) {
125 dol_print_error($db);
126 exit;
127}
128
129$head = societe_prepare_head($object);
130print dol_get_fiche_head($head, 'consumption', $langs->trans("ThirdParty"), -1, 'company');
131
132$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
133
134dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
135
136print '<div class="fichecenter">';
137
138print '<div class="underbanner clearboth"></div>';
139print '<table class="border centpercent tableforfield">';
140
141// Type Prospect/Customer/Supplier
142print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
143print $object->getTypeUrl(1);
144print '</td></tr>';
145
146if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
147 print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
148}
149
150//if (isModEnabled('agenda') && $user->hasRight('agenda', 'myactions', 'read')) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events');
151$elementTypeArray = array();
152
153if ($object->client) {
154 print '<tr><td class="titlefield">';
155 print $langs->trans('CustomerCode').'</td><td colspan="3">';
157 $tmpcheck = $object->check_codeclient();
158 if ($tmpcheck != 0 && $tmpcheck != -5) {
159 print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
160 }
161 print '</td></tr>';
162 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".((int) $socid);
163 $resql = $db->query($sql);
164 if (!$resql) {
165 dol_print_error($db);
166 }
167
168 $obj = $db->fetch_object($resql);
169 $nbFactsClient = $obj->nb;
170 $thirdTypeArray = array();
171 $thirdTypeArray['customer'] = $langs->trans("customer");
172 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
173 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
174 }
175 if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
176 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
177 }
178 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
179 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
180 }
181 if (isModEnabled('shipping') && $user->hasRight('expedition', 'lire')) {
182 $elementTypeArray['shipment'] = $langs->transnoentitiesnoconv('Shipments');
183 }
184 if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
185 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
186 }
187}
188
189if (isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire')) {
190 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
191}
192
193if ($object->fournisseur) {
194 $langs->load("supplier_proposal");
195 print '<tr><td class="titlefield">';
196 print $langs->trans('SupplierCode').'</td><td colspan="3">';
198 $tmpcheck = $object->check_codefournisseur();
199 if ($tmpcheck != 0 && $tmpcheck != -5) {
200 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
201 }
202 print '</td></tr>';
203 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
204 $resql = $db->query($sql);
205 if (!$resql) {
206 dol_print_error($db);
207 }
208
209 $obj = $db->fetch_object($resql);
210 $nbCmdsFourn = $obj->nb;
211 $thirdTypeArray['supplier'] = $langs->trans("supplier");
212 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
213 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
214 }
215 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
216 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
217 }
218 if (isModEnabled('reception') && $user->hasRight('reception', 'lire')) {
219 $langs->load('receptions');
220 $elementTypeArray['reception'] = $langs->transnoentitiesnoconv('Receptions');
221 }
222 if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
223 $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
224 }
225}
226print '</table>';
227
228print '</div>';
229
230print dol_get_fiche_end();
231print '<br>';
232
233
234print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
235print '<input type="hidden" name="token" value="'.newToken().'">';
236
237$sql_select = '';
238$documentstaticline = '';
239/*if ($type_element == 'action')
240{ // Customer : show products from invoices
241 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
242 $documentstatic=new ActionComm($db);
243 $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
244 $tables_from = MAIN_DB_PREFIX."actioncomm as f";
245 $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
246 $dateprint = 'f.datep';
247 $doc_number='f.id';
248}*/
249if ($type_element == 'fichinter') { // Customer : show products from invoices
250 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
251 $documentstatic = new Fichinter($db);
252 $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, NULL as paid, ';
253 $sql_select .= 'NULL as fk_product, NULL as info_bits, NULL as date_start, NULL as date_end, NULL as prod_qty, NULL as total_ht, ';
254 $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines.
255 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
256 $where .= " AND f.entity = ".$conf->entity;
257 $dateprint = 'f.datec';
258 $doc_number = 'f.ref';
259}
260if ($type_element == 'invoice') { // Customer : show products from invoices
261 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
262 $documentstatic = new Facture($db);
263 $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, d.fk_remise_except, ';
264 $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
265 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
266 $where .= " AND d.fk_facture = f.rowid";
267 $where .= " AND f.entity IN (".getEntity('invoice').")";
268 $dateprint = 'f.datef';
269 $doc_number = 'f.ref';
270 $thirdTypeSelect = 'customer';
271}
272if ($type_element == 'propal') {
273 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
274 $documentstatic = new Propal($db);
275 $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, NULL as paid,';
276 $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
277 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
278 $where .= " AND d.fk_propal = c.rowid";
279 $where .= " AND c.entity = ".$conf->entity;
280 $dateprint = 'c.datep';
281 $doc_number = 'c.ref';
282 $thirdTypeSelect = 'customer';
283}
284if ($type_element == 'order') {
285 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
286 $langs->load('sendings'); // delivery planned date
287 $documentstatic = new Commande($db);
288 $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, NULL as paid, c.date_livraison as delivery_planned_date,';
289 $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
290 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
291 $where .= " AND d.fk_commande = c.rowid";
292 $where .= " AND c.entity = ".$conf->entity;
293 $dateprint = 'c.date_commande';
294 $doc_number = 'c.ref';
295 $thirdTypeSelect = 'customer';
296}
297if ($type_element == 'shipment') {
298 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
299 $langs->load('sendings');
300 $documentstatic = new Expedition($db);
301 $sql_select = 'SELECT e.rowid as doc_id, e.ref as doc_number, \'1\' as doc_type, e.date_creation as dateprint, e.fk_statut as status, NULL as paid, e.date_delivery as delivery_planned_date,';
302 $tables_from = MAIN_DB_PREFIX."expedition as e,".MAIN_DB_PREFIX."expeditiondet as ed,".MAIN_DB_PREFIX."commandedet as d";
303 $where = " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
304 $where .= " AND ed.fk_expedition = e.rowid";
305 $where .= " AND ed.element_type = 'commande' AND ed.fk_elementdet = d.rowid";
306 $where .= " AND e.entity = ".$conf->entity;
307 $dateprint = 'e.date_creation';
308 $doc_number = 'e.ref';
309 $thirdTypeSelect = 'customer';
310}
311if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
312 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
313 $documentstatic = new FactureFournisseur($db);
314 $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, ';
315 $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
316 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
317 $where .= " AND d.fk_facture_fourn = f.rowid";
318 $where .= " AND f.entity = ".$conf->entity;
319 $dateprint = 'f.datef';
320 $doc_number = 'f.ref';
321 $thirdTypeSelect = 'supplier';
322}
323if ($type_element == 'supplier_proposal') {
324 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
325 $documentstatic = new SupplierProposal($db);
326 $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, NULL as paid, ';
327 $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
328 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
329 $where .= " AND d.fk_supplier_proposal = c.rowid";
330 $where .= " AND c.entity = ".$conf->entity;
331 $dateprint = 'c.date_valid';
332 $doc_number = 'c.ref';
333 $thirdTypeSelect = 'supplier';
334}
335if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
336 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
337 $langs->load('sendings'); // delivery planned date
338 $documentstatic = new CommandeFournisseur($db);
339 $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, NULL as paid, c.date_livraison as delivery_planned_date, ';
340 $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
341 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
342 $where .= " AND d.fk_commande = c.rowid";
343 $where .= " AND c.entity = ".$conf->entity;
344 $dateprint = 'c.date_valid';
345 $doc_number = 'c.ref';
346 $thirdTypeSelect = 'supplier';
347}
348if ($type_element == 'reception') { // Supplier : Show products from orders.
349 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
350 $langs->loadLangs(['sendings', 'receptions']); // delivery planned date
351 $documentstatic = new Reception($db);
352 $sql_select = 'SELECT r.rowid as doc_id, r.ref as doc_number, \'1\' as doc_type, r.date_creation as dateprint, r.fk_statut as status, NULL as paid, r.date_delivery as delivery_planned_date, ';
353 $tables_from = MAIN_DB_PREFIX."reception as r,".MAIN_DB_PREFIX."receptiondet_batch as rd,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
354 $where = " WHERE r.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
355 $where .= " AND rd.fk_reception = r.rowid";
356 $where .= " AND rd.fk_elementdet = d.rowid AND rd.element_type = 'supplier_order'";
357 $where .= " AND r.entity = ".$conf->entity;
358 $dateprint = 'r.date_creation';
359 $doc_number = 'r.ref';
360 $thirdTypeSelect = 'supplier';
361}
362if ($type_element == 'contract') { // Order
363 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
364 $documentstatic = new Contrat($db);
365 $documentstaticline = new ContratLigne($db);
366 $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, NULL as paid,';
367 $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
368 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
369 $where .= " AND d.fk_contrat = c.rowid";
370 $where .= " AND c.entity = ".$conf->entity;
371 $dateprint = 'c.date_valid';
372 $doc_number = 'c.ref';
373 $thirdTypeSelect = 'customer';
374}
375
376$parameters = array();
377$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
378
379if (!empty($sql_select)) {
380 $sql = $sql_select;
381 $sql .= ' d.description as description,';
382 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
383 $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, ';
384 }
385 if ($type_element == 'supplier_proposal') {
386 $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, ';
387 }
388 if ($type_element == 'contract') {
389 $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, ';
390 }
391 if ($type_element == 'shipment') {
392 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, ed.qty, ed.qty as prod_qty, ed.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
393 }
394 if ($type_element == 'reception') {
395 $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, rd.qty, rd.qty as prod_qty, rd.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
396 }
397 if ($type_element != 'fichinter') {
398 $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, ';
399 }
400 $sql .= " s.rowid as socid ";
401 if ($type_element != 'fichinter') {
402 $sql .= ", p.ref as prod_ref, p.label as product_label";
403 }
404 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
405 if ($type_element != 'fichinter') {
406 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
407 }
408 $sql .= $where;
409 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
410 if ($sref) {
411 $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
412 }
413 if ($sprod_fulldescr) {
414 // We test both case description is correctly saved of was save after dol_escape_htmltag().
415 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
416 if (GETPOST('type_element') != 'fichinter') {
417 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
418 }
419 if (GETPOST('type_element') != 'fichinter') {
420 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
421 }
422 $sql .= ")";
423 }
424 $sql .= $db->order($sortfield, $sortorder);
425
426 $resql = $db->query($sql);
427 $totalnboflines = $db->num_rows($resql);
428
429 $sql .= $db->plimit($limit + 1, $offset);
430 //print $sql;
431}
432
433$disabled = 0;
434$showempty = 2;
435if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
436 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
437 $disabled = 1;
438}
439
440// Define type of elements
441$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
442$button = '<input type="submit" class="button buttonform small" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
443
444$total_qty = 0;
445$total_ht = 0;
446
447$param = '';
448
449if ($sql_select) {
450 $resql = $db->query($sql);
451 if (!$resql) {
452 dol_print_error($db);
453 }
454
455 $num = $db->num_rows($resql);
456
457 $param = "&socid=".urlencode((string) ($socid))."&type_element=".urlencode((string) ($type_element));
458 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
459 $param .= '&contextpage='.urlencode($contextpage);
460 }
461 if ($limit > 0 && $limit != $conf->liste_limit) {
462 $param .= '&limit='.((int) $limit);
463 }
464 if ($sprod_fulldescr) {
465 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
466 }
467 if ($sref) {
468 $param .= "&sref=".urlencode($sref);
469 }
470 if ($month) {
471 $param .= "&month=".urlencode((string) ($month));
472 }
473 if ($year) {
474 $param .= "&year=".urlencode((string) ($year));
475 }
476 if ($optioncss) {
477 $param .= '&optioncss='.urlencode($optioncss);
478 }
479
480 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit);
481
482 print '<div class="div-table-responsive-no-min">';
483 print '<table class="liste centpercent">'."\n";
484
485 // Filters
486 print '<tr class="liste_titre">';
487 print '<td class="liste_titre left">';
488 print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
489 print '</td>';
490 print '<td class="liste_titre nowrap center valignmiddle">'; // date
491 print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle');
492 print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
493 print '</td>';
494 // delivery planned date
495 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
496 print '<td class="liste_titre center"></td>';
497 }
498 print '<td class="liste_titre center">';
499 print '</td>';
500 print '<td class="liste_titre left">';
501 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
502 print '</td>';
503 print '<td class="liste_titre center">';
504 print '</td>';
505 print '<td class="liste_titre center">';
506 print '</td>';
507 print '<td class="liste_titre maxwidthsearch">';
508 $searchpicto = $form->showFilterAndCheckAddButtons(0);
509 print $searchpicto;
510 print '</td>';
511 print '</tr>';
512
513 // Titles with sort buttons
514 print '<tr class="liste_titre">';
515 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
516 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
517 // delivery planned date
518 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
519 print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
520 }
521 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
522 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
523 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
524 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
525 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
526 print "</tr>\n";
527
528 $i = 0;
529 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
530 $documentstatic->id = $objp->doc_id;
531 $documentstatic->ref = $objp->doc_number;
532 $documentstatic->type = $objp->doc_type;
533 $documentstatic->fk_statut = $objp->status;
534 $documentstatic->fk_status = $objp->status;
535 $documentstatic->statut = $objp->status;
536 $documentstatic->status = $objp->status;
537 $documentstatic->paye = $objp->paid;
538 $documentstatic->alreadypaid = $objp->paid;
539 $documentstatic->totalpaid = $objp->paid;
540
541 if (is_object($documentstaticline)) {
542 $documentstaticline->statut = $objp->status;
543 }
544
545 print '<tr class="oddeven">';
546 print '<td class="nobordernopadding nowrap" width="100">';
547 print $documentstatic->getNomUrl(1);
548 print '</td>';
549 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
550 // delivery planned date
551 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
552 print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
553 }
554
555 // Status
556 print '<td class="center">';
557 if ($type_element == 'contract') {
558 print $documentstaticline->getLibStatut(5);
559 } elseif ($type_element == 'invoice') {
560 // @phan-suppress-next-line PhanParamTooMany
561 print $documentstatic->getLibStatut(5, $objp->paid);
562 } elseif ($type_element == 'supplier_invoice') {
563 // @phan-suppress-next-line PhanParamTooMany
564 print $documentstatic->getLibStatut(5, $objp->paid);
565 } else {
566 print $documentstatic->getLibStatut(5);
567 }
568 print '</td>';
569
570 // Label
571 print '<td class="tdoverflowmax300">';
572
573 // Define text, description and type
574 $text = '';
575 $description = '';
576 $type = 0;
577
578 // Code to show product duplicated from commonobject->printObjectLine
579 if ($objp->fk_product > 0) {
580 $product_static = new Product($db);
581
582 $product_static->type = $objp->fk_product_type;
583 $product_static->id = $objp->fk_product;
584 $product_static->ref = $objp->ref;
585 $product_static->entity = $objp->pentity;
586 $text = $product_static->getNomUrl(1);
587 }
588
589 // Product
590 if ($objp->fk_product > 0) {
591 // Define output language
592 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
593 $prod = new Product($db);
594 $prod->fetch($objp->fk_product);
595
596 $outputlangs = $langs;
597 $newlang = '';
598 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
599 $newlang = GETPOST('lang_id', 'aZ09');
600 }
601 if (empty($newlang)) {
602 $newlang = $object->default_lang;
603 }
604 if (!empty($newlang)) {
605 $outputlangs = new Translate("", $conf);
606 $outputlangs->setDefaultLang($newlang);
607 }
608
609 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
610 } else {
611 $label = $objp->product_label;
612 }
613
614 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
615 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
616 }
617
618 if (($objp->info_bits & 2) == 2) { ?>
619 <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
620 <?php
621 $txt = '';
622 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
623 if ($objp->description == '(DEPOSIT)') {
624 $txt = $langs->trans("Deposit");
625 } elseif ($objp->description == '(EXCESS RECEIVED)') {
626 $txt = $langs->trans("ExcessReceived");
627 } elseif ($objp->description == '(EXCESS PAID)') {
628 $txt = $langs->trans("ExcessPaid");
629 }
630 //else $txt=$langs->trans("Discount");
631 print $txt;
632 ?>
633 </a>
634 <?php
635 if ($objp->description) {
636 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
637 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
638 $discount = new DiscountAbsolute($db);
639 $discount->fetch($objp->fk_remise_except);
640 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
641 }
642 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
643 $discount = new DiscountAbsolute($db);
644 $discount->fetch($objp->fk_remise_except);
645 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
646 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
647 $discount = new DiscountAbsolute($db);
648 $discount->fetch($objp->fk_remise_except);
649 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
650 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
651 $discount = new DiscountAbsolute($db);
652 $discount->fetch($objp->fk_remise_except);
653 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
654 // Add date of deposit
655 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
656 echo ' ('.dol_print_date($discount->datec).')';
657 }
658 } else {
659 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
660 }
661 }
662 } else {
663 if ($objp->fk_product > 0) {
664 echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, '');
665
666 // Show range
667 echo get_date_range($objp->date_start, $objp->date_end);
668
669 // Add description in form
670 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
671 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
672 }
673 } else {
674 if (!empty($objp->label) || !empty($objp->description)) {
675 if ($type == 1) {
676 $text = img_object($langs->trans('Service'), 'service');
677 } else {
678 $text = img_object($langs->trans('Product'), 'product');
679 }
680
681 if (!empty($objp->label)) {
682 $text .= ' <strong>'.$objp->label.'</strong>';
683 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, '', '', $i, 0, '');
684 } else {
685 echo $text.' '.dol_htmlentitiesbr($objp->description);
686 }
687 }
688
689 // Show range
690 echo get_date_range($objp->date_start, $objp->date_end);
691 }
692 }
693
694 /*
695 $prodreftxt='';
696 if ($objp->prod_id > 0)
697 {
698 $productstatic->id = $objp->prod_id;
699 $productstatic->ref = $objp->prod_ref;
700 $productstatic->status = $objp->prod_type;
701 $prodreftxt = $productstatic->getNomUrl(0);
702 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
703 }
704 // Show range
705 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
706 // Add description in form
707 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
708 {
709 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
710 }
711 */
712 print '</td>';
713
714 //print '<td class="left">'.$prodreftxt.'</td>';
715 if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
716 $objp->prod_qty = -($objp->prod_qty);
717 }
718 print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
719 $total_qty += $objp->prod_qty;
720
721 print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
722
723 $total_ht += (float) $objp->total_ht;
724
725 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
726
727 print "</tr>\n";
728 $i++;
729 }
730
731 print '<tr class="liste_total">';
732 print '<td>'.$langs->trans('Total').'</td>';
733 print '<td colspan="3"></td>';
734 // delivery planned date
735 if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
736 print '<td></td>';
737 }
738 print '<td class="right">'.$total_qty.'</td>';
739 print '<td class="right">'.price($total_ht).'</td>';
740 print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
741 print "</table>";
742 print '</div>';
743
744 if ($num > $limit) {
745 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
746 }
747 $db->free($resql);
748} elseif (empty($type_element) || $type_element == -1) {
749 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', (!empty($num) ? $num : 0), '', '');
750
751 print '<table class="liste centpercent">'."\n";
752 // Titles with sort buttons
753 print '<tr class="liste_titre">';
754 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
755 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
756 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
757 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
758 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
759 print "</tr>\n";
760
761 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
762
763 print "</table>";
764} else {
765 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
766
767 print '<table class="liste centpercent">'."\n";
768
769 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
770
771 print "</table>";
772}
773
774print "</form>";
775
776// End of page
777llxFooter();
778$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage lines of contracts.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
const TYPE_CREDIT_NOTE
Credit note invoice.
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 receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage price ask supplier.
Class to manage translations.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:377
llxFooter()
Footer empty.
Definition document.php:107
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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.