dolibarr 19.0.3
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 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require "../main.inc.php";
31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.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';
35
36
37// Load translation files required by the page
38$langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products"));
39
40
41$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
42
43// Security check
44$socid = GETPOST('socid', 'int');
45if ($user->socid) {
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'societe', $socid, '&societe');
49$object = new Societe($db);
50if ($socid > 0) {
51 $object->fetch($socid);
52}
53
54// Sort & Order fields
55$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
56$sortfield = GETPOST('sortfield', 'aZ09comma');
57$sortorder = GETPOST('sortorder', 'aZ09comma');
58$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
59$optioncss = GETPOST('optioncss', 'alpha');
60
61if (empty($page) || $page == -1) {
62 $page = 0;
63} // If $page is not defined, or '' or -1
64$offset = $limit * $page;
65$pageprev = $page - 1;
66$pagenext = $page + 1;
67if (!$sortorder) {
68 $sortorder = 'DESC';
69}
70if (!$sortfield) {
71 $sortfield = 'dateprint';
72}
73
74// Search fields
75$sref = GETPOST("sref");
76$sprod_fulldescr = GETPOST("sprod_fulldescr");
77$month = GETPOST('month', 'int');
78$year = GETPOST('year', 'int');
79
80// Clean up on purge search criteria ?
81if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
82 $sref = '';
83 $sprod_fulldescr = '';
84 $year = '';
85 $month = '';
86}
87
88// Customer or supplier selected in drop box
89$thirdTypeSelect = GETPOST("third_select_id", 'aZ09');
90$type_element = GETPOST('type_element') ? GETPOST('type_element') : '';
91
92
93// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
94$hookmanager->initHooks(array('consumptionthirdparty', 'globalcard'));
95
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/', $conf->global->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">';
156 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
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['customer'] = $langs->trans("customer");
171 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
172 $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals');
173 }
174 if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
175 $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders');
176 }
177 if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
178 $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
179 }
180 if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
181 $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
182 }
183}
184
185if (isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire')) {
186 $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions');
187}
188
189if ($object->fournisseur) {
190 $langs->load("supplier_proposal");
191 print '<tr><td class="titlefield">';
192 print $langs->trans('SupplierCode').'</td><td colspan="3">';
193 print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_fournisseur));
194 $tmpcheck = $object->check_codefournisseur();
195 if ($tmpcheck != 0 && $tmpcheck != -5) {
196 print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
197 }
198 print '</td></tr>';
199 $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".((int) $socid);
200 $resql = $db->query($sql);
201 if (!$resql) {
202 dol_print_error($db);
203 }
204
205 $obj = $db->fetch_object($resql);
206 $nbCmdsFourn = $obj->nb;
207 $thirdTypeArray['supplier'] = $langs->trans("supplier");
208 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) {
209 $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices');
210 }
211 if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
212 $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
213 }
214 if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
215 $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
216 }
217}
218print '</table>';
219
220print '</div>';
221
222print dol_get_fiche_end();
223print '<br>';
224
225
226print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">';
227print '<input type="hidden" name="token" value="'.newToken().'">';
228
229$sql_select = '';
230$documentstaticline = '';
231/*if ($type_element == 'action')
232{ // Customer : show products from invoices
233 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
234 $documentstatic=new ActionComm($db);
235 $sql_select = 'SELECT f.id as doc_id, f.id as doc_number, \'1\' as doc_type, f.datep as dateprint, ';
236 $tables_from = MAIN_DB_PREFIX."actioncomm as f";
237 $where = " WHERE rbl.parentid = f.id AND f.entity = ".$conf->entity;
238 $dateprint = 'f.datep';
239 $doc_number='f.id';
240}*/
241if ($type_element == 'fichinter') { // Customer : show products from invoices
242 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
243 $documentstatic = new Fichinter($db);
244 $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, ';
245 $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, ';
246 $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.
247 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
248 $where .= " AND f.entity = ".$conf->entity;
249 $dateprint = 'f.datec';
250 $doc_number = 'f.ref';
251}
252if ($type_element == 'invoice') { // Customer : show products from invoices
253 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
254 $documentstatic = new Facture($db);
255 $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, ';
256 $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d";
257 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
258 $where .= " AND d.fk_facture = f.rowid";
259 $where .= " AND f.entity IN (".getEntity('invoice').")";
260 $dateprint = 'f.datef';
261 $doc_number = 'f.ref';
262 $thirdTypeSelect = 'customer';
263}
264if ($type_element == 'propal') {
265 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
266 $documentstatic = new Propal($db);
267 $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,';
268 $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d";
269 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
270 $where .= " AND d.fk_propal = c.rowid";
271 $where .= " AND c.entity = ".$conf->entity;
272 $dateprint = 'c.datep';
273 $doc_number = 'c.ref';
274 $thirdTypeSelect = 'customer';
275}
276if ($type_element == 'order') {
277 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
278 $langs->load('sendings'); // delivery planned date
279 $documentstatic = new Commande($db);
280 $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,';
281 $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d";
282 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
283 $where .= " AND d.fk_commande = c.rowid";
284 $where .= " AND c.entity = ".$conf->entity;
285 $dateprint = 'c.date_commande';
286 $doc_number = 'c.ref';
287 $thirdTypeSelect = 'customer';
288}
289if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
290 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
291 $documentstatic = new FactureFournisseur($db);
292 $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, ';
293 $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d";
294 $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
295 $where .= " AND d.fk_facture_fourn = f.rowid";
296 $where .= " AND f.entity = ".$conf->entity;
297 $dateprint = 'f.datef';
298 $doc_number = 'f.ref';
299 $thirdTypeSelect = 'supplier';
300}
301if ($type_element == 'supplier_proposal') {
302 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
303 $documentstatic = new SupplierProposal($db);
304 $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, ';
305 $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d";
306 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
307 $where .= " AND d.fk_supplier_proposal = c.rowid";
308 $where .= " AND c.entity = ".$conf->entity;
309 $dateprint = 'c.date_valid';
310 $doc_number = 'c.ref';
311 $thirdTypeSelect = 'supplier';
312}
313if ($type_element == 'supplier_order') { // Supplier : Show products from orders.
314 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
315 $langs->load('sendings'); // delivery planned date
316 $documentstatic = new CommandeFournisseur($db);
317 $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, ';
318 $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
319 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
320 $where .= " AND d.fk_commande = c.rowid";
321 $where .= " AND c.entity = ".$conf->entity;
322 $dateprint = 'c.date_valid';
323 $doc_number = 'c.ref';
324 $thirdTypeSelect = 'supplier';
325}
326if ($type_element == 'contract') { // Order
327 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
328 $documentstatic = new Contrat($db);
329 $documentstaticline = new ContratLigne($db);
330 $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,';
331 $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d";
332 $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
333 $where .= " AND d.fk_contrat = c.rowid";
334 $where .= " AND c.entity = ".$conf->entity;
335 $dateprint = 'c.date_valid';
336 $doc_number = 'c.ref';
337 $thirdTypeSelect = 'customer';
338}
339
340$parameters = array();
341$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
342
343if (!empty($sql_select)) {
344 $sql = $sql_select;
345 $sql .= ' d.description as description,';
346 if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
347 $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, ';
348 }
349 if ($type_element == 'supplier_proposal') {
350 $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, ';
351 }
352 if ($type_element == 'contract') {
353 $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, ';
354 }
355 if ($type_element != 'fichinter') {
356 $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, ';
357 }
358 $sql .= " s.rowid as socid ";
359 if ($type_element != 'fichinter') {
360 $sql .= ", p.ref as prod_ref, p.label as product_label";
361 }
362 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
363 if ($type_element != 'fichinter') {
364 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
365 }
366 $sql .= $where;
367 $sql .= dolSqlDateFilter($dateprint, 0, $month, $year);
368 if ($sref) {
369 $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'";
370 }
371 if ($sprod_fulldescr) {
372 // We test both case description is correctly saved of was save after dol_escape_htmltag().
373 $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%' OR d.description LIKE '%".$db->escape(dol_escape_htmltag($sprod_fulldescr))."%'";
374 if (GETPOST('type_element') != 'fichinter') {
375 $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
376 }
377 if (GETPOST('type_element') != 'fichinter') {
378 $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
379 }
380 $sql .= ")";
381 }
382 $sql .= $db->order($sortfield, $sortorder);
383
384 $resql = $db->query($sql);
385 $totalnboflines = $db->num_rows($resql);
386
387 $sql .= $db->plimit($limit + 1, $offset);
388 //print $sql;
389}
390
391$disabled = 0;
392$showempty = 2;
393if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) {
394 $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef");
395 $disabled = 1;
396}
397
398// Define type of elements
399$typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone');
400$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")).'">';
401
402$total_qty = 0;
403$param = '';
404
405if ($sql_select) {
406 $resql = $db->query($sql);
407 if (!$resql) {
408 dol_print_error($db);
409 }
410
411 $num = $db->num_rows($resql);
412
413 $param = "&socid=".urlencode($socid)."&type_element=".urlencode($type_element);
414 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
415 $param .= '&contextpage='.urlencode($contextpage);
416 }
417 if ($limit > 0 && $limit != $conf->liste_limit) {
418 $param .= '&limit='.((int) $limit);
419 }
420 if ($sprod_fulldescr) {
421 $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr);
422 }
423 if ($sref) {
424 $param .= "&sref=".urlencode($sref);
425 }
426 if ($month) {
427 $param .= "&month=".urlencode($month);
428 }
429 if ($year) {
430 $param .= "&year=".urlencode($year);
431 }
432 if ($optioncss) {
433 $param .= '&optioncss='.urlencode($optioncss);
434 }
435
436 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit);
437
438 print '<div class="div-table-responsive-no-min">';
439 print '<table class="liste centpercent">'."\n";
440
441 // Filters
442 print '<tr class="liste_titre">';
443 print '<td class="liste_titre left">';
444 print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
445 print '</td>';
446 print '<td class="liste_titre nowrap center valignmiddle">'; // date
447 print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle');
448 print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
449 print '</td>';
450 // delivery planned date
451 if ($type_element == 'order' || $type_element == 'supplier_order') {
452 print '<td class="liste_titre center"></td>';
453 }
454 print '<td class="liste_titre center">';
455 print '</td>';
456 print '<td class="liste_titre left">';
457 print '<input class="flat" type="text" name="sprod_fulldescr" size="15" value="'.dol_escape_htmltag($sprod_fulldescr).'">';
458 print '</td>';
459 print '<td class="liste_titre center">';
460 print '</td>';
461 print '<td class="liste_titre center">';
462 print '</td>';
463 print '<td class="liste_titre maxwidthsearch">';
464 $searchpicto = $form->showFilterAndCheckAddButtons(0);
465 print $searchpicto;
466 print '</td>';
467 print '</tr>';
468
469 // Titles with sort buttons
470 print '<tr class="liste_titre">';
471 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
472 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
473 // delivery planned date
474 if ($type_element == 'order' || $type_element == 'supplier_order') {
475 print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
476 }
477 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
478 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
479 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
480 print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
481 print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
482 print "</tr>\n";
483
484
485 $i = 0;
486 while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) {
487 $documentstatic->id = $objp->doc_id;
488 $documentstatic->ref = $objp->doc_number;
489 $documentstatic->type = $objp->doc_type;
490 $documentstatic->fk_statut = $objp->status;
491 $documentstatic->fk_status = $objp->status;
492 $documentstatic->statut = $objp->status;
493 $documentstatic->status = $objp->status;
494 $documentstatic->paye = $objp->paid;
495 $documentstatic->alreadypaid = $objp->paid;
496
497 if (is_object($documentstaticline)) {
498 $documentstaticline->statut = $objp->status;
499 }
500
501 print '<tr class="oddeven">';
502 print '<td class="nobordernopadding nowrap" width="100">';
503 print $documentstatic->getNomUrl(1);
504 print '</td>';
505 print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
506 // delivery planned date
507 if ($type_element == 'order' || $type_element == 'supplier_order') {
508 print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
509 }
510
511 // Status
512 print '<td class="center">';
513 if ($type_element == 'contract') {
514 print $documentstaticline->getLibStatut(5);
515 } elseif ($type_element == 'invoice') {
516 print $documentstatic->getLibStatut(5, $objp->paid);
517 } elseif ($type_element == 'supplier_invoice') {
518 print $documentstatic->getLibStatut(5, $objp->paid);
519 } else {
520 print $documentstatic->getLibStatut(5);
521 }
522 print '</td>';
523
524 // Label
525 print '<td class="tdoverflowmax300">';
526
527 // Define text, description and type
528 $text = '';
529 $description = '';
530 $type = 0;
531
532 // Code to show product duplicated from commonobject->printObjectLine
533 if ($objp->fk_product > 0) {
534 $product_static = new Product($db);
535
536 $product_static->type = $objp->fk_product_type;
537 $product_static->id = $objp->fk_product;
538 $product_static->ref = $objp->ref;
539 $product_static->entity = $objp->pentity;
540 $text = $product_static->getNomUrl(1);
541 }
542
543 // Product
544 if ($objp->fk_product > 0) {
545 // Define output language
546 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
547 $prod = new Product($db);
548 $prod->fetch($objp->fk_product);
549
550 $outputlangs = $langs;
551 $newlang = '';
552 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
553 $newlang = GETPOST('lang_id', 'aZ09');
554 }
555 if (empty($newlang)) {
556 $newlang = $object->default_lang;
557 }
558 if (!empty($newlang)) {
559 $outputlangs = new Translate("", $conf);
560 $outputlangs->setDefaultLang($newlang);
561 }
562
563 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
564 } else {
565 $label = $objp->product_label;
566 }
567
568 $text .= ' - '.(!empty($objp->label) ? $objp->label : $label);
569 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
570 }
571
572 if (($objp->info_bits & 2) == 2) { ?>
573 <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>">
574 <?php
575 $txt = '';
576 print img_object($langs->trans("ShowReduc"), 'reduc').' ';
577 if ($objp->description == '(DEPOSIT)') {
578 $txt = $langs->trans("Deposit");
579 } elseif ($objp->description == '(EXCESS RECEIVED)') {
580 $txt = $langs->trans("ExcessReceived");
581 } elseif ($objp->description == '(EXCESS PAID)') {
582 $txt = $langs->trans("ExcessPaid");
583 }
584 //else $txt=$langs->trans("Discount");
585 print $txt;
586 ?>
587 </a>
588 <?php
589 if ($objp->description) {
590 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
591 if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) {
592 $discount = new DiscountAbsolute($db);
593 $discount->fetch($objp->fk_remise_except);
594 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
595 }
596 if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) {
597 $discount = new DiscountAbsolute($db);
598 $discount->fetch($objp->fk_remise_except);
599 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
600 } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) {
601 $discount = new DiscountAbsolute($db);
602 $discount->fetch($objp->fk_remise_except);
603 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
604 } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) {
605 $discount = new DiscountAbsolute($db);
606 $discount->fetch($objp->fk_remise_except);
607 echo($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
608 // Add date of deposit
609 if (getDolGlobalString('INVOICE_ADD_DEPOSIT_DATE')) {
610 echo ' ('.dol_print_date($discount->datec).')';
611 }
612 } else {
613 echo($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description);
614 }
615 }
616 } else {
617 if ($objp->fk_product > 0) {
618 echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, '');
619
620 // Show range
621 echo get_date_range($objp->date_start, $objp->date_end);
622
623 // Add description in form
624 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
625 print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
626 }
627 } else {
628 if (!empty($objp->label) || !empty($objp->description)) {
629 if ($type == 1) {
630 $text = img_object($langs->trans('Service'), 'service');
631 } else {
632 $text = img_object($langs->trans('Product'), 'product');
633 }
634
635 if (!empty($objp->label)) {
636 $text .= ' <strong>'.$objp->label.'</strong>';
637 echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, '', '', $i, 0, '');
638 } else {
639 echo $text.' '.dol_htmlentitiesbr($objp->description);
640 }
641 }
642
643 // Show range
644 echo get_date_range($objp->date_start, $objp->date_end);
645 }
646 }
647
648 /*
649 $prodreftxt='';
650 if ($objp->prod_id > 0)
651 {
652 $productstatic->id = $objp->prod_id;
653 $productstatic->ref = $objp->prod_ref;
654 $productstatic->status = $objp->prod_type;
655 $prodreftxt = $productstatic->getNomUrl(0);
656 if(!empty($objp->product_label)) $prodreftxt .= ' - '.$objp->product_label;
657 }
658 // Show range
659 $prodreftxt .= get_date_range($objp->date_start, $objp->date_end);
660 // Add description in form
661 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE'))
662 {
663 $prodreftxt .= (!empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
664 }
665 */
666 print '</td>';
667
668 //print '<td class="left">'.$prodreftxt.'</td>';
669 if ($type_element == 'invoice' && $objp->doc_type == Facture::TYPE_CREDIT_NOTE) {
670 $objp->prod_qty = -($objp->prod_qty);
671 }
672 print '<td class="right"><span class="amount">'.$objp->prod_qty.'</span></td>';
673 $total_qty += $objp->prod_qty;
674
675 print '<td class="right"><span class="amount">'.price($objp->total_ht).'</span></td>';
676 if (empty($total_ht)) {
677 $total_ht = 0;
678 }
679 $total_ht += (float) $objp->total_ht;
680
681 print '<td class="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>';
682
683 print "</tr>\n";
684 $i++;
685 }
686
687 print '<tr class="liste_total">';
688 print '<td>'.$langs->trans('Total').'</td>';
689 print '<td colspan="3"></td>';
690 // delivery planned date
691 if ($type_element == 'order' || $type_element == 'supplier_order') {
692 print '<td></td>';
693 }
694 print '<td class="right">'.$total_qty.'</td>';
695 print '<td class="right">'.price($total_ht).'</td>';
696 print '<td class="right">'.price(price2num($total_ht / (empty($total_qty) ? 1 : $total_qty), 'MU')).'</td>';
697 print "</table>";
698 print '</div>';
699
700 if ($num > $limit) {
701 print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num);
702 }
703 $db->free($resql);
704} elseif (empty($type_element) || $type_element == -1) {
705 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', (!empty($num) ? $num : 0), '', '');
706
707 print '<table class="liste centpercent">'."\n";
708 // Titles with sort buttons
709 print '<tr class="liste_titre">';
710 print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
711 print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'width="150"', $sortfield, $sortorder, 'center ');
712 print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, '', $sortfield, $sortorder, 'center ');
713 print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'left ');
714 print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, '', $sortfield, $sortorder, 'right ');
715 print "</tr>\n";
716
717 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</span></td></tr>';
718
719 print "</table>";
720} else {
721 print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', '');
722
723 print '<table class="liste centpercent">'."\n";
724
725 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("FeatureNotYetAvailable").'</span></td></tr>';
726
727 print "</table>";
728}
729
730print "</form>";
731
732// End of page
733llxFooter();
734$db->close();
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 contracts.
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 interventions.
Class to manage generation of HTML components Only common components must be here.
Classe 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 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
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
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 '.
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
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.
print_barre_liste($titre, $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.
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.