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