27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35 $langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
38 $socid =
GETPOST(
'socid',
'int');
40 if ($user->socid > 0) {
41 $socid = $user->socid;
47 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
51 $modecompta = $conf->global->ACCOUNTING_MODE;
53 $modecompta =
GETPOST(
"modecompta");
56 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
57 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
66 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
67 $selected_soc = (int)
GETPOST(
'search_soc',
'int');
69 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
75 $selected_type =
GETPOST(
'search_type',
'int');
76 if ($selected_type ==
'') {
81 $hookmanager->initHooks(array(
'cabyprodservlist'));
86 $date_startyear =
GETPOST(
"date_startyear");
87 $date_startmonth =
GETPOST(
"date_startmonth");
88 $date_startday =
GETPOST(
"date_startday");
89 $date_endyear =
GETPOST(
"date_endyear");
90 $date_endmonth =
GETPOST(
"date_endmonth");
91 $date_endday =
GETPOST(
"date_endday");
95 $year_start = $year_current;
97 $year_current = $year;
104 if (empty($date_start) || empty($date_end)) {
108 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
109 $year_end = $year_start;
110 $month_end = $month_start;
112 if (!
GETPOST(
'year') && $month_start > $month_current) {
116 $month_end = $month_start - 1;
117 if ($month_end < 1) {
149 $year_start = $tmps[
'year'];
151 $year_end = $tmpe[
'year'];
152 $nbofyear = ($year_end - $year_start) + 1;
154 $commonparams = array();
155 if (!empty($modecompta)) {
156 $commonparams[
'modecompta'] = $modecompta;
158 if (!empty($sortorder)) {
159 $commonparams[
'sortorder'] = $sortorder;
161 if (!empty($sortfield)) {
162 $commonparams[
'sortfield'] = $sortfield;
165 $headerparams = array();
166 if (!empty($date_startyear)) {
167 $headerparams[
'date_startyear'] = $date_startyear;
169 if (!empty($date_startmonth)) {
170 $headerparams[
'date_startmonth'] = $date_startmonth;
172 if (!empty($date_startday)) {
173 $headerparams[
'date_startday'] = $date_startday;
175 if (!empty($date_endyear)) {
176 $headerparams[
'date_endyear'] = $date_endyear;
178 if (!empty($date_endmonth)) {
179 $headerparams[
'date_endmonth'] = $date_endmonth;
181 if (!empty($date_endday)) {
182 $headerparams[
'date_endday'] = $date_endday;
185 $headerparams[
'year'] = $year;
187 if (!empty($month)) {
188 $headerparams[
'month'] = $month;
191 $headerparams[
'q'] = $q;
194 $tableparams = array();
195 if (!empty($selected_cat)) {
196 $tableparams[
'search_categ'] = $selected_cat;
198 if (!empty($selected_soc)) {
199 $tableparams[
'search_soc'] = $selected_soc;
201 if (!empty($selected_type)) {
202 $tableparams[
'search_type'] = $selected_type;
204 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
207 $allparams = array_merge($commonparams, $headerparams, $tableparams);
208 $headerparams = array_merge($commonparams, $headerparams);
209 $tableparams = array_merge($commonparams, $tableparams);
212 foreach ($allparams as $key => $value) {
213 $paramslink .=
'&'.$key.
'='.$value;
227 if ($modecompta ==
"BOOKKEEPING") {
228 $modecompta =
"CREANCES-DETTES";
230 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
231 $modecompta =
"RECETTES-DEPENSES";
238 if ($modecompta ==
"CREANCES-DETTES") {
239 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
240 $calcmode = $langs->trans(
"CalcModeDebt");
243 $description = $langs->trans(
"RulesCADue");
244 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
245 $description .= $langs->trans(
"DepositsAreNotIncluded");
247 $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>';
273 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
275 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
276 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
288 if ($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) {
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")).
'">';
422 $parameters = array();
423 $reshook = $hookmanager->executeHooks(
'printFieldListeTitle', $parameters);
424 print $hookmanager->resPrint;
429 print
"<tr class=\"liste_titre\">";
431 $langs->trans(
"Product"),
432 $_SERVER[
"PHP_SELF"],
441 $langs->trans(
'Quantity'),
442 $_SERVER[
"PHP_SELF"],
451 $langs->trans(
"Percentage"),
452 $_SERVER[
"PHP_SELF"],
461 $langs->trans(
'AmountHT'),
462 $_SERVER[
"PHP_SELF"],
471 $langs->trans(
"AmountTTC"),
472 $_SERVER[
"PHP_SELF"],
481 $langs->trans(
"Percentage"),
482 $_SERVER[
"PHP_SELF"],
493 foreach ($name as $key => $value) {
494 print
'<tr class="oddeven">';
498 $fullname = $name[$key];
500 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
502 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
508 print
'<td class="right">';
513 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
516 print
'<td class="right">';
522 print
price($amount_ht[$key]);
527 print
'<td class="right">';
533 print
price($amount[$key]);
538 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
547 print
'<tr class="liste_total">';
548 print
'<td>'.$langs->trans(
"Total").
'</td>';
549 print
'<td class="right">'.$qtytotal.
'</td>';
550 print
'<td class="right">100%</td>';
551 print
'<td class="right">'.price($catotal_ht).
'</td>';
552 print
'<td class="right">'.price($catotal).
'</td>';
553 print
'<td class="right">100%</td>';
567 print
'<br>'.$langs->trans(
"TurnoverPerProductInCommitmentAccountingNotRelevant").
'<br>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage categories.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
restrictedArea($user, $features, $objectid=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.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.