dolibarr 21.0.0-alpha
cabyprodserv.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Antoine Iauch <aiauch@gpcsolutions.fr>
3 * Copyright (C) 2013-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
5 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
7 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
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
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array("products", "categories", "errors", 'accountancy'));
40
41// Security pack (data & check)
42$socid = GETPOSTINT('socid');
43
44if ($user->socid > 0) {
45 $socid = $user->socid;
46}
47
48// Hook
49$hookmanager->initHooks(array('cabyprodservlist'));
50
51if (isModEnabled('comptabilite')) {
52 $result = restrictedArea($user, 'compta', '', '', 'resultat');
53}
54if (isModEnabled('accounting')) {
55 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
56}
57
58// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
59$modecompta = getDolGlobalString('ACCOUNTING_MODE');
60if (GETPOST("modecompta")) {
61 $modecompta = GETPOST("modecompta");
62}
63
64$sortorder = GETPOST("sortorder", 'aZ09comma');
65$sortfield = GETPOST("sortfield", 'aZ09comma');
66if (!$sortorder) {
67 $sortorder = "asc";
68}
69if (!$sortfield) {
70 $sortfield = "ref";
71}
72
73// Category
74$selected_cat = GETPOST('search_categ', 'intcomma');
75$selected_catsoc = GETPOST('search_categ_soc', 'intcomma');
76$selected_soc = GETPOST('search_soc', 'intcomma');
77$typent_id = GETPOST('typent_id', 'int');
78$subcat = false;
79if (GETPOST('subcat', 'alpha') === 'yes') {
80 $subcat = true;
81}
82$categorie = new Categorie($db);
83
84// product/service
85$selected_type = GETPOST('search_type', 'intcomma');
86if ($selected_type == '') {
87 $selected_type = -1;
88}
89
90// Date range
91$year = GETPOSTINT("year");
92$month = GETPOSTINT("month");
93$date_startyear = GETPOST("date_startyear");
94$date_startmonth = GETPOST("date_startmonth");
95$date_startday = GETPOST("date_startday");
96$date_endyear = GETPOST("date_endyear");
97$date_endmonth = GETPOST("date_endmonth");
98$date_endday = GETPOST("date_endday");
99if (empty($year)) {
100 $year_current = dol_print_date(dol_now(), '%Y');
101 $month_current = dol_print_date(dol_now(), '%m');
102 $year_start = $year_current;
103} else {
104 $year_current = $year;
105 $month_current = dol_print_date(dol_now(), '%m');
106 $year_start = $year;
107}
108$date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
109$date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear"), 'tzserver'); // We use timezone of server so report is same from everywhere
110// Quarter
111if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
112 $q = GETPOSTINT("q");
113 if (empty($q)) {
114 // We define date_start and date_end
115 $month_start = GETPOST("month") ? GETPOST("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
116 $year_end = $year_start;
117 $month_end = $month_start;
118 if (!GETPOST("month")) { // If month not forced
119 if (!GETPOST('year') && $month_start > $month_current) {
120 $year_start--;
121 $year_end--;
122 }
123 $month_end = $month_start - 1;
124 if ($month_end < 1) {
125 $month_end = 12;
126 } else {
127 $year_end++;
128 }
129 }
130 $date_start = dol_get_first_day($year_start, $month_start, false);
131 $date_end = dol_get_last_day($year_end, $month_end, false);
132 } else {
133 if ($q == 1) {
134 $date_start = dol_get_first_day($year_start, 1, false);
135 $date_end = dol_get_last_day($year_start, 3, false);
136 }
137 if ($q == 2) {
138 $date_start = dol_get_first_day($year_start, 4, false);
139 $date_end = dol_get_last_day($year_start, 6, false);
140 }
141 if ($q == 3) {
142 $date_start = dol_get_first_day($year_start, 7, false);
143 $date_end = dol_get_last_day($year_start, 9, false);
144 }
145 if ($q == 4) {
146 $date_start = dol_get_first_day($year_start, 10, false);
147 $date_end = dol_get_last_day($year_start, 12, false);
148 }
149 }
150} else {
151 // TODO We define q
152}
153
154// $date_start and $date_end are defined. We force $year_start and $nbofyear
155$tmps = dol_getdate($date_start);
156$year_start = $tmps['year'];
157$tmpe = dol_getdate($date_end);
158$year_end = $tmpe['year'];
159$nbofyear = ($year_end - $year_start) + 1;
160
161$commonparams = array();
162if (!empty($modecompta)) {
163 $commonparams['modecompta'] = $modecompta;
164}
165if (!empty($sortorder)) {
166 $commonparams['sortorder'] = $sortorder;
167}
168if (!empty($sortfield)) {
169 $commonparams['sortfield'] = $sortfield;
170}
171
172$headerparams = array();
173if (!empty($date_startyear)) {
174 $headerparams['date_startyear'] = $date_startyear;
175}
176if (!empty($date_startmonth)) {
177 $headerparams['date_startmonth'] = $date_startmonth;
178}
179if (!empty($date_startday)) {
180 $headerparams['date_startday'] = $date_startday;
181}
182if (!empty($date_endyear)) {
183 $headerparams['date_endyear'] = $date_endyear;
184}
185if (!empty($date_endmonth)) {
186 $headerparams['date_endmonth'] = $date_endmonth;
187}
188if (!empty($date_endday)) {
189 $headerparams['date_endday'] = $date_endday;
190}
191if (!empty($year)) {
192 $headerparams['year'] = $year;
193}
194if (!empty($month)) {
195 $headerparams['month'] = $month;
196}
197if (!empty($q)) {
198 $headerparams['q'] = $q;
199}
200
201$tableparams = array();
202if (!empty($selected_cat)) {
203 $tableparams['search_categ'] = $selected_cat;
204}
205if (!empty($selected_catsoc)) {
206 $tableparams['search_categ_soc'] = $selected_catsoc;
207}
208if (!empty($selected_soc)) {
209 $tableparams['search_soc'] = $selected_soc;
210}
211if (!empty($selected_type)) {
212 $tableparams['search_type'] = $selected_type;
213}
214if (!empty($typent_id)) {
215 $tableparams['typent_id'] = $typent_id;
216}
217$tableparams['subcat'] = $subcat ? 'yes' : '';
218
219// Adding common parameters
220$allparams = array_merge($commonparams, $headerparams, $tableparams);
221$headerparams = array_merge($commonparams, $headerparams);
222$tableparams = array_merge($commonparams, $tableparams);
223
224$paramslink = "";
225foreach ($allparams as $key => $value) {
226 $paramslink .= '&'.urlencode($key).'='.urlencode($value);
227}
228
229
230/*
231 * View
232 */
233
234llxHeader();
235
236$form = new Form($db);
237$formother = new FormOther($db);
238
239// TODO Report from bookkeeping not yet available, so we switch on report on business events
240if ($modecompta == "BOOKKEEPING") {
241 $modecompta = "CREANCES-DETTES";
242}
243if ($modecompta == "BOOKKEEPINGCOLLECTED") {
244 $modecompta = "RECETTES-DEPENSES";
245}
246
247$exportlink = "";
248$namelink = "";
249
250// Show report header
251if ($modecompta == "CREANCES-DETTES") {
252 $name = $langs->trans("Turnover").', '.$langs->trans("ByProductsAndServices");
253 $calcmode = $langs->trans("CalcModeDebt");
254 //$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
255
256 $description = $langs->trans("RulesCADue");
257 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
258 $description .= $langs->trans("DepositsAreNotIncluded");
259 } else {
260 $description .= $langs->trans("DepositsAreIncluded");
261 }
262 $builddate = dol_now();
263} elseif ($modecompta == "RECETTES-DEPENSES") {
264 $name = $langs->trans("TurnoverCollected").', '.$langs->trans("ByProductsAndServices");
265 $calcmode = $langs->trans("CalcModePayment");
266 //$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
267
268 $description = $langs->trans("RulesCAIn");
269 $description .= $langs->trans("DepositsAreIncluded");
270
271 $builddate = dol_now();
272} elseif ($modecompta == "BOOKKEEPING") {
273} elseif ($modecompta == "BOOKKEEPINGCOLLECTED") {
274}
275
276$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
277$period .= ' - ';
278$period .= $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
279if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) {
280 $periodlink = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start - 1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year_start + 1).'&modecompta='.$modecompta.'">'.img_next().'</a>';
281} else {
282 $periodlink = '';
283}
284
285report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
286
287if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
288 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
289}
290
291
292$name = array();
293
294// SQL request
295$catotal = 0;
296$catotal_ht = 0;
297$qtytotal = 0;
298
299if ($modecompta == 'CREANCES-DETTES') {
300 $sql = "SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
301 $sql .= " SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
302 $sql .= " SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
303
304 $parameters = array();
305 $hookmanager->executeHooks('printFieldListSelect', $parameters);
306 $sql .= $hookmanager->resPrint;
307
308 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
309 $sql .= ",".MAIN_DB_PREFIX."facturedet as l";
310 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
311 if ($typent_id > 0) {
312 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as soc ON (soc.rowid = f.fk_soc)";
313 }
314 $parameters = array();
315 $hookmanager->executeHooks('printFieldListFrom', $parameters);
316 $sql .= $hookmanager->resPrint;
317
318 $sql .= " WHERE l.fk_facture = f.rowid";
319 $sql .= " AND f.fk_statut in (1,2)";
320 $sql .= " AND l.product_type in (0,1)";
321 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
322 $sql .= " AND f.type IN (0,1,2,5)";
323 } else {
324 $sql .= " AND f.type IN (0,1,2,3,5)";
325 }
326 if ($date_start && $date_end) {
327 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
328 }
329 if ($selected_type >= 0) {
330 $sql .= " AND l.product_type = ".((int) $selected_type);
331 }
332
333 // Search for tag/category ($searchCategoryProductList is an array of ID)
334 $searchCategoryProductOperator = -1;
335 $searchCategoryProductList = array($selected_cat);
336 if ($subcat) {
337 $TListOfCats = $categorie->get_full_arbo('product', $selected_cat, 1);
338 $searchCategoryProductList = array();
339 foreach ($TListOfCats as $key => $cat) {
340 $searchCategoryProductList[] = $cat['id'];
341 }
342 }
343 if (!empty($searchCategoryProductList)) {
344 $searchCategoryProductSqlList = array();
345 $listofcategoryid = '';
346 foreach ($searchCategoryProductList as $searchCategoryProduct) {
347 if (intval($searchCategoryProduct) == -2) {
348 $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product)";
349 } elseif (intval($searchCategoryProduct) > 0) {
350 if ($searchCategoryProductOperator == 0) {
351 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
352 } else {
353 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
354 }
355 }
356 }
357 if ($listofcategoryid) {
358 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE l.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
359 }
360 if ($searchCategoryProductOperator == 1) {
361 if (!empty($searchCategoryProductSqlList)) {
362 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
363 }
364 } else {
365 if (!empty($searchCategoryProductSqlList)) {
366 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
367 }
368 }
369 }
370
371 // Search for tag/category ($searchCategorySocieteList is an array of ID)
372 $searchCategorySocieteOperator = -1;
373 $searchCategorySocieteList = array($selected_catsoc);
374 if (!empty($searchCategorySocieteList)) {
375 $searchCategorySocieteSqlList = array();
376 $listofcategoryid = '';
377 foreach ($searchCategorySocieteList as $searchCategorySociete) {
378 if (intval($searchCategorySociete) == -2) {
379 $searchCategorySocieteSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc)";
380 } elseif (intval($searchCategorySociete) > 0) {
381 if ($searchCategorySocieteOperator == 0) {
382 $searchCategorySocieteSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategorySociete).")";
383 } else {
384 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySociete);
385 }
386 }
387 }
388 if ($listofcategoryid) {
389 $searchCategorySocieteSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE f.fk_soc = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
390 }
391 if ($searchCategorySocieteOperator == 1) {
392 if (!empty($searchCategorySocieteSqlList)) {
393 $sql .= " AND (".implode(' OR ', $searchCategorySocieteSqlList).")";
394 }
395 } else {
396 if (!empty($searchCategorySocieteSqlList)) {
397 $sql .= " AND (".implode(' AND ', $searchCategorySocieteSqlList).")";
398 }
399 }
400 }
401
402 if ($selected_soc > 0) {
403 $sql .= " AND f.fk_soc = ".((int) $selected_soc);
404 }
405
406 if ($typent_id > 0) {
407 $sql .= " AND soc.fk_typent = ".((int) $typent_id);
408 }
409
410 $sql .= " AND f.entity IN (".getEntity('invoice').")";
411
412 $parameters = array();
413 $hookmanager->executeHooks('printFieldListWhere', $parameters);
414 $sql .= $hookmanager->resPrint;
415
416 $sql .= " GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
417 $sql .= $db->order($sortfield, $sortorder);
418
419 dol_syslog("cabyprodserv", LOG_DEBUG);
420 $result = $db->query($sql);
421
422 $amount_ht = array();
423 $amount = array();
424 $qty = array();
425 if ($result) {
426 $num = $db->num_rows($result);
427 $i = 0;
428 while ($i < $num) {
429 $obj = $db->fetch_object($result);
430
431 $amount_ht[$obj->rowid] = $obj->amount;
432 $amount[$obj->rowid] = $obj->amount_ttc;
433 $qty[$obj->rowid] = $obj->qty;
434 $name[$obj->rowid] = $obj->ref.'&nbsp;-&nbsp;'.$obj->label;
435 $type[$obj->rowid] = $obj->product_type;
436 $catotal_ht += $obj->amount;
437 $catotal += $obj->amount_ttc;
438 $qtytotal += $obj->qty;
439 $i++;
440 }
441 } else {
442 dol_print_error($db);
443 }
444
445 // Show Array
446 $i = 0;
447 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
448 print '<input type="hidden" name="token" value="'.newToken().'">'."\n";
449 // Extra parameters management
450 foreach ($headerparams as $key => $value) {
451 print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
452 }
453
454 $moreforfilter = '';
455
456 print '<div class="div-table-responsive">';
457 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
458
459 // Category filter
460 print '<tr class="liste_titre">';
461 print '<td>';
462 print img_picto('', 'category', 'class="pictofixedwidth"');
463 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', 0, $langs->trans("Category"));
464 print ' ';
465 print '<input type="checkbox" class="marginleft" id="subcat" name="subcat" value="yes"';
466 if ($subcat) {
467 print ' checked';
468 }
469 print '>';
470 print '<label for="subcat" class="marginrightonly">'.$langs->trans("SubCats").'?</label>';
471 // type filter (produit/service)
472 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1, 'search_type', $langs->trans("Type"), 1, 1);
473
474 // Third party filter
475 print '<br>';
476 print img_picto('', 'category', 'class="pictofixedwidth"');
477 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc, 'search_categ_soc', 0, $langs->trans("CustomersProspectsCategoriesShort"));
478
479 // Type of third party filter
480 print '&nbsp; &nbsp;';
481 $formcompany = new FormCompany($db);
482 // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on ascending label.
483 $sortparam = getDolGlobalString('SOCIETE_SORT_ON_TYPEENT', 'ASC');
484 print $form->selectarray("typent_id", $formcompany->typent_array(0), $typent_id, $langs->trans("ThirdPartyType"), 0, 0, '', 0, 0, 0, $sortparam, '', 1);
485
486 print '<br>';
487 print img_picto('', 'company', 'class="pictofixedwidth"');
488 print $form->select_company($selected_soc, 'search_soc', '', $langs->trans("ThirdParty"));
489 print '</td>';
490
491 print '<td colspan="5" class="right">';
492 print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
493 print '</td>';
494
495 print '</tr>';
496
497 // Array header
498 print "<tr class=\"liste_titre\">";
500 $langs->trans("Product"),
501 $_SERVER["PHP_SELF"],
502 "ref",
503 "",
504 $paramslink,
505 "",
506 $sortfield,
507 $sortorder
508 );
510 $langs->trans('Quantity'),
511 $_SERVER["PHP_SELF"],
512 "qty",
513 "",
514 $paramslink,
515 'class="right"',
516 $sortfield,
517 $sortorder
518 );
520 $langs->trans("Percentage"),
521 $_SERVER["PHP_SELF"],
522 "qty",
523 "",
524 $paramslink,
525 'class="right"',
526 $sortfield,
527 $sortorder
528 );
530 $langs->trans('AmountHT'),
531 $_SERVER["PHP_SELF"],
532 "amount",
533 "",
534 $paramslink,
535 'class="right"',
536 $sortfield,
537 $sortorder
538 );
540 $langs->trans("AmountTTC"),
541 $_SERVER["PHP_SELF"],
542 "amount_ttc",
543 "",
544 $paramslink,
545 'class="right"',
546 $sortfield,
547 $sortorder
548 );
550 $langs->trans("Percentage"),
551 $_SERVER["PHP_SELF"],
552 "amount_ttc",
553 "",
554 $paramslink,
555 'class="right"',
556 $sortfield,
557 $sortorder
558 );
559 print "</tr>\n";
560
561 if (count($name)) {
562 foreach ($name as $key => $value) {
563 print '<tr class="oddeven">';
564
565 // Product
566 print "<td>";
567 $fullname = $name[$key];
568 if ($key > 0) {
569 $linkname = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$key.'">'.img_object($langs->trans("ShowProduct"), $type[$key] == 0 ? 'product' : 'service').' '.$fullname.'</a>';
570 } else {
571 $linkname = $langs->trans("PaymentsNotLinkedToProduct");
572 }
573 print $linkname;
574 print "</td>\n";
575
576 // Quantity
577 print '<td class="right">';
578 print price($qty[$key], 1, $langs, 0, 0);
579 print '</td>';
580
581 // Percent;
582 print '<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).'%' : '&nbsp;').'</td>';
583
584 // Amount w/o VAT
585 print '<td class="right">';
586 /*if ($key > 0) {
587 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?productid='.$key.'">';
588 } else {
589 print '<a href="#">';
590 }*/
591 print price($amount_ht[$key]);
592 //print '</a>';
593 print '</td>';
594
595 // Amount with VAT
596 print '<td class="right">';
597 /*if ($key > 0) {
598 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?productid='.$key.'">';
599 } else {
600 print '<a href="#">';
601 }*/
602 print price($amount[$key]);
603 //print '</a>';
604 print '</td>';
605
606 // Percent;
607 print '<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : '&nbsp;').'</td>';
608
609 // TODO: statistics?
610
611 print "</tr>\n";
612 $i++;
613 }
614
615 // Total
616 print '<tr class="liste_total">';
617 print '<td>'.$langs->trans("Total").'</td>';
618 print '<td class="right">'.$qtytotal.'</td>';
619 print '<td class="right">100%</td>';
620 print '<td class="right">'.price($catotal_ht).'</td>';
621 print '<td class="right">'.price($catotal).'</td>';
622 print '<td class="right">100%</td>';
623 print '</tr>';
624
625 $db->free($result);
626 } else {
627 print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
628 }
629 print "</table>";
630 print '</div>';
631
632 print '</form>';
633} else {
634 // $modecompta != 'CREANCES-DETTES'
635 // "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an
636 // invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ?
637 // Because there is no way to know this, this report is not relevant.
638 print '<br>'.$langs->trans("TurnoverPerProductInCommitmentAccountingNotRelevant").'<br>';
639}
640
641// End of page
642llxFooter();
643$db->close();
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 categories.
Class to build HTML component for third parties management Only common components are here.
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.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:595
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:124
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:614
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
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...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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...
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
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.