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