28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
39$socid =
GETPOST(
'socid',
'int');
41if ($user->socid > 0) {
42 $socid = $user->socid;
44if (isModEnabled(
'comptabilite')) {
47if (isModEnabled(
'accounting')) {
48 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
52$modecompta = $conf->global->ACCOUNTING_MODE;
54 $modecompta =
GETPOST(
"modecompta");
57$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
58$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
67$selected_cat = (int)
GETPOST(
'search_categ',
'int');
68$selected_soc = (int)
GETPOST(
'search_soc',
'int');
70if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
76$selected_type =
GETPOST(
'search_type',
'int');
77if ($selected_type ==
'') {
82$hookmanager->initHooks(array(
'cabyprodservlist'));
87$date_startyear =
GETPOST(
"date_startyear");
88$date_startmonth =
GETPOST(
"date_startmonth");
89$date_startday =
GETPOST(
"date_startday");
90$date_endyear =
GETPOST(
"date_endyear");
91$date_endmonth =
GETPOST(
"date_endmonth");
92$date_endday =
GETPOST(
"date_endday");
96 $year_start = $year_current;
98 $year_current = $year;
105if (empty($date_start) || empty($date_end)) {
109 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
110 $year_end = $year_start;
111 $month_end = $month_start;
113 if (!
GETPOST(
'year') && $month_start > $month_current) {
117 $month_end = $month_start - 1;
118 if ($month_end < 1) {
150$year_start = $tmps[
'year'];
152$year_end = $tmpe[
'year'];
153$nbofyear = ($year_end - $year_start) + 1;
155$commonparams = array();
156if (!empty($modecompta)) {
157 $commonparams[
'modecompta'] = $modecompta;
159if (!empty($sortorder)) {
160 $commonparams[
'sortorder'] = $sortorder;
162if (!empty($sortfield)) {
163 $commonparams[
'sortfield'] = $sortfield;
166$headerparams = array();
167if (!empty($date_startyear)) {
168 $headerparams[
'date_startyear'] = $date_startyear;
170if (!empty($date_startmonth)) {
171 $headerparams[
'date_startmonth'] = $date_startmonth;
173if (!empty($date_startday)) {
174 $headerparams[
'date_startday'] = $date_startday;
176if (!empty($date_endyear)) {
177 $headerparams[
'date_endyear'] = $date_endyear;
179if (!empty($date_endmonth)) {
180 $headerparams[
'date_endmonth'] = $date_endmonth;
182if (!empty($date_endday)) {
183 $headerparams[
'date_endday'] = $date_endday;
186 $headerparams[
'year'] = $year;
189 $headerparams[
'month'] = $month;
192 $headerparams[
'q'] = $q;
195$tableparams = array();
196if (!empty($selected_cat)) {
197 $tableparams[
'search_categ'] = $selected_cat;
199if (!empty($selected_soc)) {
200 $tableparams[
'search_soc'] = $selected_soc;
202if (!empty($selected_type)) {
203 $tableparams[
'search_type'] = $selected_type;
205$tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
208$allparams = array_merge($commonparams, $headerparams, $tableparams);
209$headerparams = array_merge($commonparams, $headerparams);
210$tableparams = array_merge($commonparams, $tableparams);
213foreach ($allparams as $key => $value) {
214 $paramslink .=
'&'.$key.
'='.$value;
224$form =
new Form($db);
228if ($modecompta ==
"BOOKKEEPING") {
229 $modecompta =
"CREANCES-DETTES";
231if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
232 $modecompta =
"RECETTES-DEPENSES";
239if ($modecompta ==
"CREANCES-DETTES") {
240 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
241 $calcmode = $langs->trans(
"CalcModeDebt");
244 $description = $langs->trans(
"RulesCADue");
245 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
246 $description .= $langs->trans(
"DepositsAreNotIncluded");
248 $description .= $langs->trans(
"DepositsAreIncluded");
251} elseif ($modecompta ==
"RECETTES-DEPENSES") {
252 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
253 $calcmode = $langs->trans(
"CalcModeEngagement");
256 $description = $langs->trans(
"RulesCAIn");
257 $description .= $langs->trans(
"DepositsAreIncluded");
260} elseif ($modecompta ==
"BOOKKEEPING") {
261} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
264$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
266$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
268 $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>';
273report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
275if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
276 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
288if ($modecompta ==
'CREANCES-DETTES') {
289 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
290 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
291 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
293 $parameters = array();
294 $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
295 $sql .= $hookmanager->resPrint;
297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
298 if ($selected_soc > 0) {
299 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
301 $sql .=
",".MAIN_DB_PREFIX.
"facturedet as l";
302 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
303 if ($selected_cat === -2) {
304 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
307 $parameters = array();
308 $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
309 $sql .= $hookmanager->resPrint;
311 $sql .=
" WHERE l.fk_facture = f.rowid";
312 $sql .=
" AND f.fk_statut in (1,2)";
313 $sql .=
" AND l.product_type in (0,1)";
314 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
315 $sql .=
" AND f.type IN (0,1,2,5)";
317 $sql .=
" AND f.type IN (0,1,2,3,5)";
319 if ($date_start && $date_end) {
320 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
322 if ($selected_type >= 0) {
323 $sql .=
" AND l.product_type = ".((int) $selected_type);
325 if ($selected_cat === -2) {
326 $sql .=
" AND cp.fk_product is null";
327 } elseif ($selected_cat > 0) {
329 $TListOfCats = $categorie->get_full_arbo(
'product', $selected_cat, 1);
332 foreach ($TListOfCats as $key => $cat) {
334 $listofcatsql .=
",";
336 $listofcatsql .= $cat[
'rowid'];
340 $sql .=
" AND (p.rowid IN ";
341 $sql .=
" (SELECT fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product cp WHERE ";
343 $sql .=
"cp.fk_categorie IN (".$db->sanitize($listofcatsql).
")";
345 $sql .=
"cp.fk_categorie = ".((int) $selected_cat);
349 if ($selected_soc > 0) {
350 $sql .=
" AND soc.rowid=".((int) $selected_soc);
352 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
354 $parameters = array();
355 $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
356 $sql .= $hookmanager->resPrint;
358 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
359 $sql .= $db->order($sortfield, $sortorder);
362 $result = $db->query($sql);
364 $num = $db->num_rows($result);
367 $obj = $db->fetch_object($result);
368 $amount_ht[$obj->rowid] = $obj->amount;
369 $amount[$obj->rowid] = $obj->amount_ttc;
370 $qty[$obj->rowid] = $obj->qty;
371 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
372 $type[$obj->rowid] = $obj->product_type;
373 $catotal_ht += $obj->amount;
374 $catotal += $obj->amount_ttc;
375 $qtytotal += $obj->qty;
384 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
385 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
387 foreach ($headerparams as $key => $value) {
388 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
393 print
'<div class="div-table-responsive">';
394 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
397 print
'<tr class="liste_titre">';
399 print
img_picto(
'',
'category',
'class="paddingrightonly"');
400 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
402 print $langs->trans(
"SubCats").
'? ';
403 print
'<input type="checkbox" name="subcat" value="yes"';
410 print $langs->trans(
"Type").
': ';
411 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', 1, 1, 1);
415 print
img_picto(
'',
'company',
'class="paddingrightonly"');
416 print $form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
419 print
'<td colspan="5" class="right">';
420 print
'<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'',
'', 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'">';
426 print
"<tr class=\"liste_titre\">";
428 $langs->trans(
"Product"),
429 $_SERVER[
"PHP_SELF"],
438 $langs->trans(
'Quantity'),
439 $_SERVER[
"PHP_SELF"],
448 $langs->trans(
"Percentage"),
449 $_SERVER[
"PHP_SELF"],
458 $langs->trans(
'AmountHT'),
459 $_SERVER[
"PHP_SELF"],
468 $langs->trans(
"AmountTTC"),
469 $_SERVER[
"PHP_SELF"],
478 $langs->trans(
"Percentage"),
479 $_SERVER[
"PHP_SELF"],
490 foreach ($name as $key => $value) {
491 print
'<tr class="oddeven">';
495 $fullname = $name[$key];
497 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
499 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
505 print
'<td class="right">';
510 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
513 print
'<td class="right">';
519 print
price($amount_ht[$key]);
524 print
'<td class="right">';
530 print
price($amount[$key]);
535 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
544 print
'<tr class="liste_total">';
545 print
'<td>'.$langs->trans(
"Total").
'</td>';
546 print
'<td class="right">'.$qtytotal.
'</td>';
547 print
'<td class="right">100%</td>';
548 print
'<td class="right">'.price($catotal_ht).
'</td>';
549 print
'<td class="right">'.price($catotal).
'</td>';
550 print
'<td class="right">100%</td>';
564 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()
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 informations (by default a local PHP server timestamp) Re...
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)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
img_next($titlealt='default', $moreatt='')
Show next logo.
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.