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';
47$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
52if ($user->socid > 0) {
53 $socid = $user->socid;
57$hookmanager->initHooks(array(
'cabyprodservlist'));
59if (isModEnabled(
'comptabilite')) {
62if (isModEnabled(
'accounting')) {
63 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
69 $modecompta =
GETPOST(
"modecompta");
72$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
73$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
82$selected_cat =
GETPOST(
'search_categ',
'intcomma');
83$selected_catsoc =
GETPOST(
'search_categ_soc',
'intcomma');
84$selected_soc =
GETPOST(
'search_soc',
'intcomma');
85$typent_id =
GETPOST(
'typent_id',
'int');
87if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
93$selected_type =
GETPOST(
'search_type',
'intcomma');
94if ($selected_type ==
'') {
101$date_startyear =
GETPOST(
"date_startyear");
102$date_startmonth =
GETPOST(
"date_startmonth");
103$date_startday =
GETPOST(
"date_startday");
104$date_endyear =
GETPOST(
"date_endyear");
105$date_endmonth =
GETPOST(
"date_endmonth");
106$date_endday =
GETPOST(
"date_endday");
110 $year_start = $year_current;
112 $year_current = $year;
119if (empty($date_start) || empty($date_end)) {
124 $year_end = $year_start;
125 $month_end = $month_start;
127 if (!
GETPOST(
'year') && $month_start > $month_current) {
131 $month_end = $month_start - 1;
132 if ($month_end < 1) {
164$year_start = $tmps[
'year'];
166$year_end = $tmpe[
'year'];
167$nbofyear = ($year_end - $year_start) + 1;
169$commonparams = array();
170if (!empty($modecompta)) {
171 $commonparams[
'modecompta'] = $modecompta;
173if (!empty($sortorder)) {
174 $commonparams[
'sortorder'] = $sortorder;
176if (!empty($sortfield)) {
177 $commonparams[
'sortfield'] = $sortfield;
180$headerparams = array();
181if (!empty($date_startyear)) {
182 $headerparams[
'date_startyear'] = $date_startyear;
184if (!empty($date_startmonth)) {
185 $headerparams[
'date_startmonth'] = $date_startmonth;
187if (!empty($date_startday)) {
188 $headerparams[
'date_startday'] = $date_startday;
190if (!empty($date_endyear)) {
191 $headerparams[
'date_endyear'] = $date_endyear;
193if (!empty($date_endmonth)) {
194 $headerparams[
'date_endmonth'] = $date_endmonth;
196if (!empty($date_endday)) {
197 $headerparams[
'date_endday'] = $date_endday;
200 $headerparams[
'year'] = $year;
203 $headerparams[
'month'] = $month;
206 $headerparams[
'q'] = $q;
209$tableparams = array();
210if (!empty($selected_cat)) {
211 $tableparams[
'search_categ'] = $selected_cat;
213if (!empty($selected_catsoc)) {
214 $tableparams[
'search_categ_soc'] = $selected_catsoc;
216if (!empty($selected_soc)) {
217 $tableparams[
'search_soc'] = $selected_soc;
219if ($selected_type > 0) {
220 $tableparams[
'search_type'] = $selected_type;
222if (!empty($typent_id)) {
223 $tableparams[
'typent_id'] = $typent_id;
225$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
228$allparams = array_merge($commonparams, $headerparams, $tableparams);
229$headerparams = array_merge($commonparams, $headerparams);
230$tableparams = array_merge($commonparams, $tableparams);
233foreach ($allparams as $key => $value) {
234 $paramslink .=
'&'.urlencode($key).
'='.urlencode($value);
244$form =
new Form($db);
248if ($modecompta ==
"BOOKKEEPING") {
249 $modecompta =
"CREANCES-DETTES";
251if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
252 $modecompta =
"RECETTES-DEPENSES";
265if ($modecompta ==
"CREANCES-DETTES") {
266 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
267 $calcmode = $langs->trans(
"CalcModeDebt");
270 $description = $langs->trans(
"RulesCADue");
272 $description .= $langs->trans(
"DepositsAreNotIncluded");
274 $description .= $langs->trans(
"DepositsAreIncluded");
277} elseif ($modecompta ==
"RECETTES-DEPENSES") {
278 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
279 $calcmode = $langs->trans(
"CalcModePayment");
282 $description = $langs->trans(
"RulesCAIn");
283 $description .= $langs->trans(
"DepositsAreIncluded");
290$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
292$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
294 $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>';
305report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
307if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
308 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
319if ($modecompta ==
'CREANCES-DETTES') {
320 $sql =
"SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
321 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
322 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
324 $parameters = array();
325 $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
326 $sql .= $hookmanager->resPrint;
328 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
329 $sql .=
",".MAIN_DB_PREFIX.
"facturedet as l";
330 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
331 if ($typent_id > 0) {
332 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
334 $parameters = array();
335 $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
336 $sql .= $hookmanager->resPrint;
338 $sql .=
" WHERE l.fk_facture = f.rowid";
339 $sql .=
" AND f.fk_statut in (1,2)";
340 $sql .=
" AND l.product_type in (0,1)";
342 $sql .=
" AND f.type IN (0,1,2,5)";
344 $sql .=
" AND f.type IN (0,1,2,3,5)";
346 if ($date_start && $date_end) {
347 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
349 if ($selected_type >= 0) {
350 $sql .=
" AND l.product_type = ".((int) $selected_type);
354 $searchCategoryProductOperator = -1;
355 $searchCategoryProductList = array($selected_cat);
357 $TListOfCats = $categorie->get_full_arbo(
'product', $selected_cat, 1);
358 $searchCategoryProductList = array();
359 foreach ($TListOfCats as $key => $cat) {
360 $searchCategoryProductList[] = $cat[
'id'];
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).
")";
373 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategoryProduct);
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).
"))";
380 if ($searchCategoryProductOperator == 1) {
381 if (!empty($searchCategoryProductSqlList)) {
382 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
385 if (!empty($searchCategoryProductSqlList)) {
386 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
392 $searchCategorySocieteOperator = -1;
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).
")";
404 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategorySociete);
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).
"))";
411 if ($searchCategorySocieteOperator == 1) {
412 if (!empty($searchCategorySocieteSqlList)) {
413 $sql .=
" AND (".implode(
' OR ', $searchCategorySocieteSqlList).
")";
416 if (!empty($searchCategorySocieteSqlList)) {
417 $sql .=
" AND (".implode(
' AND ', $searchCategorySocieteSqlList).
")";
422 if ($selected_soc > 0) {
423 $sql .=
" AND f.fk_soc = ".((int) $selected_soc);
426 if ($typent_id > 0) {
427 $sql .=
" AND soc.fk_typent = ".((int) $typent_id);
430 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
432 $parameters = array();
433 $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
434 $sql .= $hookmanager->resPrint;
436 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
437 $sql .= $db->order($sortfield, $sortorder);
440 $result = $db->query($sql);
442 $amount_ht = array();
446 $num = $db->num_rows($result);
449 $obj = $db->fetch_object($result);
451 $amount_ht[$obj->rowid] = $obj->amount;
452 $amount[$obj->rowid] = $obj->amount_ttc;
453 $qty[$obj->rowid] = $obj->qty;
454 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
455 $type[$obj->rowid] = $obj->product_type;
456 $catotal_ht += $obj->amount;
457 $catotal += $obj->amount_ttc;
458 $qtytotal += $obj->qty;
467 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
468 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
470 foreach ($headerparams as $key => $value) {
471 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
476 print
'<div class="div-table-responsive">';
477 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
480 print
'<tr class="liste_titre">';
482 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
483 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
485 print
'<input type="checkbox" class="marginleft" id="subcat" name="subcat" value="yes"';
490 print
'<label for="subcat" class="marginrightonly">'.$langs->trans(
"SubCats").
'?</label>';
492 $form->select_type_of_lines($selected_type,
'search_type', $langs->trans(
"Type"), 1, 1);
496 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
497 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc,
'search_categ_soc', 0, $langs->trans(
"CustomersProspectsCategoriesShort"));
500 print
' ';
504 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, $langs->trans(
"ThirdPartyType"), 0, 0,
'', 0, 0, 0, $sortparam,
'', 1);
507 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
508 print $form->select_company($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
511 print
'<td colspan="5" class="right">';
512 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")).
'">';
518 print
"<tr class=\"liste_titre\">";
520 $langs->trans(
"Product"),
521 $_SERVER[
"PHP_SELF"],
530 $langs->trans(
'Quantity'),
531 $_SERVER[
"PHP_SELF"],
540 $langs->trans(
"Percentage"),
541 $_SERVER[
"PHP_SELF"],
550 $langs->trans(
'AmountHT'),
551 $_SERVER[
"PHP_SELF"],
560 $langs->trans(
"AmountTTC"),
561 $_SERVER[
"PHP_SELF"],
570 $langs->trans(
"Percentage"),
571 $_SERVER[
"PHP_SELF"],
582 foreach ($name as $key => $value) {
583 print
'<tr class="oddeven">';
587 $fullname = $name[$key];
589 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
591 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
597 print
'<td class="right">';
598 print
price($qty[$key], 1, $langs, 0, 0);
602 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
605 print
'<td class="right">';
611 print
price($amount_ht[$key]);
616 print
'<td class="right">';
622 print
price($amount[$key]);
627 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
636 print
'<tr class="liste_total">';
637 print
'<td>'.$langs->trans(
"Total").
'</td>';
638 print
'<td class="right">'.$qtytotal.
'</td>';
639 print
'<td class="right">100%</td>';
640 print
'<td class="right">'.price($catotal_ht).
'</td>';
641 print
'<td class="right">'.price($catotal).
'</td>';
642 print
'<td class="right">100%</td>';
647 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
658 print
'<br>'.$langs->trans(
"TurnoverPerProductInCommitmentAccountingNotRelevant").
'<br>';
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.
Class to manage categories.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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.