29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
38$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
43if ($user->socid > 0) {
44 $socid = $user->socid;
46if (isModEnabled(
'comptabilite')) {
49if (isModEnabled(
'accounting')) {
50 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
56 $modecompta =
GETPOST(
"modecompta");
59$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
60$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
69$selected_cat =
GETPOST(
'search_categ',
'intcomma');
70$selected_catsoc =
GETPOST(
'search_categ_soc',
'intcomma');
71$selected_soc =
GETPOST(
'search_soc',
'intcomma');
72$typent_id =
GETPOST(
'typent_id',
'int');
74if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
80$selected_type =
GETPOST(
'search_type',
'intcomma');
81if ($selected_type ==
'') {
86$hookmanager->initHooks(array(
'cabyprodservlist'));
91$date_startyear =
GETPOST(
"date_startyear");
92$date_startmonth =
GETPOST(
"date_startmonth");
93$date_startday =
GETPOST(
"date_startday");
94$date_endyear =
GETPOST(
"date_endyear");
95$date_endmonth =
GETPOST(
"date_endmonth");
96$date_endday =
GETPOST(
"date_endday");
100 $year_start = $year_current;
102 $year_current = $year;
109if (empty($date_start) || empty($date_end)) {
114 $year_end = $year_start;
115 $month_end = $month_start;
117 if (!
GETPOST(
'year') && $month_start > $month_current) {
121 $month_end = $month_start - 1;
122 if ($month_end < 1) {
154$year_start = $tmps[
'year'];
156$year_end = $tmpe[
'year'];
157$nbofyear = ($year_end - $year_start) + 1;
159$commonparams = array();
160if (!empty($modecompta)) {
161 $commonparams[
'modecompta'] = $modecompta;
163if (!empty($sortorder)) {
164 $commonparams[
'sortorder'] = $sortorder;
166if (!empty($sortfield)) {
167 $commonparams[
'sortfield'] = $sortfield;
170$headerparams = array();
171if (!empty($date_startyear)) {
172 $headerparams[
'date_startyear'] = $date_startyear;
174if (!empty($date_startmonth)) {
175 $headerparams[
'date_startmonth'] = $date_startmonth;
177if (!empty($date_startday)) {
178 $headerparams[
'date_startday'] = $date_startday;
180if (!empty($date_endyear)) {
181 $headerparams[
'date_endyear'] = $date_endyear;
183if (!empty($date_endmonth)) {
184 $headerparams[
'date_endmonth'] = $date_endmonth;
186if (!empty($date_endday)) {
187 $headerparams[
'date_endday'] = $date_endday;
190 $headerparams[
'year'] = $year;
193 $headerparams[
'month'] = $month;
196 $headerparams[
'q'] = $q;
199$tableparams = array();
200if (!empty($selected_cat)) {
201 $tableparams[
'search_categ'] = $selected_cat;
203if (!empty($selected_catsoc)) {
204 $tableparams[
'search_categ_soc'] = $selected_catsoc;
206if (!empty($selected_soc)) {
207 $tableparams[
'search_soc'] = $selected_soc;
209if (!empty($selected_type)) {
210 $tableparams[
'search_type'] = $selected_type;
212if (!empty($typent_id)) {
213 $tableparams[
'typent_id'] = $typent_id;
215$tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
218$allparams = array_merge($commonparams, $headerparams, $tableparams);
219$headerparams = array_merge($commonparams, $headerparams);
220$tableparams = array_merge($commonparams, $tableparams);
223foreach ($allparams as $key => $value) {
224 $paramslink .=
'&'.urlencode($key).
'='.urlencode($value);
234$form =
new Form($db);
238if ($modecompta ==
"BOOKKEEPING") {
239 $modecompta =
"CREANCES-DETTES";
241if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
242 $modecompta =
"RECETTES-DEPENSES";
249if ($modecompta ==
"CREANCES-DETTES") {
250 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
251 $calcmode = $langs->trans(
"CalcModeDebt");
254 $description = $langs->trans(
"RulesCADue");
256 $description .= $langs->trans(
"DepositsAreNotIncluded");
258 $description .= $langs->trans(
"DepositsAreIncluded");
261} elseif ($modecompta ==
"RECETTES-DEPENSES") {
262 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
263 $calcmode = $langs->trans(
"CalcModePayment");
266 $description = $langs->trans(
"RulesCAIn");
267 $description .= $langs->trans(
"DepositsAreIncluded");
270} elseif ($modecompta ==
"BOOKKEEPING") {
271} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
274$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
276$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
278 $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>';
283report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
285if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
286 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
297if ($modecompta ==
'CREANCES-DETTES') {
298 $sql =
"SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
299 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
300 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
302 $parameters = array();
303 $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
304 $sql .= $hookmanager->resPrint;
306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
307 $sql .=
",".MAIN_DB_PREFIX.
"facturedet as l";
308 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
310 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
312 $parameters = array();
313 $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
314 $sql .= $hookmanager->resPrint;
316 $sql .=
" WHERE l.fk_facture = f.rowid";
317 $sql .=
" AND f.fk_statut in (1,2)";
318 $sql .=
" AND l.product_type in (0,1)";
320 $sql .=
" AND f.type IN (0,1,2,5)";
322 $sql .=
" AND f.type IN (0,1,2,3,5)";
324 if ($date_start && $date_end) {
325 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
327 if ($selected_type >= 0) {
328 $sql .=
" AND l.product_type = ".((int) $selected_type);
332 $searchCategoryProductOperator = -1;
333 $searchCategoryProductList = array($selected_cat);
335 $TListOfCats = $categorie->get_full_arbo(
'product', $selected_cat, 1);
336 $searchCategoryProductList = array();
337 foreach ($TListOfCats as $key => $cat) {
338 $searchCategoryProductList[] = $cat[
'id'];
341 if (!empty($searchCategoryProductList)) {
342 $searchCategoryProductSqlList = array();
343 $listofcategoryid =
'';
344 foreach ($searchCategoryProductList as $searchCategoryProduct) {
345 if (intval($searchCategoryProduct) == -2) {
346 $searchCategoryProductSqlList[] =
"NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product as ck WHERE l.fk_product = ck.fk_product)";
347 } elseif (intval($searchCategoryProduct) > 0) {
348 if ($searchCategoryProductOperator == 0) {
349 $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).
")";
351 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategoryProduct);
355 if ($listofcategoryid) {
356 $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).
"))";
358 if ($searchCategoryProductOperator == 1) {
359 if (!empty($searchCategoryProductSqlList)) {
360 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
363 if (!empty($searchCategoryProductSqlList)) {
364 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
370 $searchCategorySocieteOperator = -1;
371 $searchCategorySocieteList = array($selected_catsoc);
372 if (!empty($searchCategorySocieteList)) {
373 $searchCategorySocieteSqlList = array();
374 $listofcategoryid =
'';
375 foreach ($searchCategorySocieteList as $searchCategorySociete) {
376 if (intval($searchCategorySociete) == -2) {
377 $searchCategorySocieteSqlList[] =
"NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs WHERE f.fk_soc = cs.fk_soc)";
378 } elseif (intval($searchCategorySociete) > 0) {
379 if ($searchCategorySocieteOperator == 0) {
380 $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).
")";
382 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategorySociete);
386 if ($listofcategoryid) {
387 $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).
"))";
389 if ($searchCategorySocieteOperator == 1) {
390 if (!empty($searchCategorySocieteSqlList)) {
391 $sql .=
" AND (".implode(
' OR ', $searchCategorySocieteSqlList).
")";
394 if (!empty($searchCategorySocieteSqlList)) {
395 $sql .=
" AND (".implode(
' AND ', $searchCategorySocieteSqlList).
")";
400 if ($selected_soc > 0) {
401 $sql .=
" AND f.fk_soc = ".((int) $selected_soc);
405 $sql .=
" AND soc.fk_typent = ".((int) $typent_id);
408 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
410 $parameters = array();
411 $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
412 $sql .= $hookmanager->resPrint;
414 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
415 $sql .= $db->order($sortfield, $sortorder);
418 $result = $db->query($sql);
420 $amount_ht = array();
424 $num = $db->num_rows($result);
427 $obj = $db->fetch_object($result);
429 $amount_ht[$obj->rowid] = $obj->amount;
430 $amount[$obj->rowid] = $obj->amount_ttc;
431 $qty[$obj->rowid] = $obj->qty;
432 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
433 $type[$obj->rowid] = $obj->product_type;
434 $catotal_ht += $obj->amount;
435 $catotal += $obj->amount_ttc;
436 $qtytotal += $obj->qty;
445 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
446 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
448 foreach ($headerparams as $key => $value) {
449 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
454 print
'<div class="div-table-responsive">';
455 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
458 print
'<tr class="liste_titre">';
460 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
461 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
463 print
'<input type="checkbox" class="marginleft" id="subcat" name="subcat" value="yes"';
468 print
'<label for="subcat" class="marginrightonly">'.$langs->trans(
"SubCats").
'?</label>';
470 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', $langs->trans(
"Type"), 1, 1);
474 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
475 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc,
'search_categ_soc', 0, $langs->trans(
"CustomersProspectsCategoriesShort"));
478 print
' ';
482 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, $langs->trans(
"ThirdPartyType"), 0, 0,
'', 0, 0, 0, $sortparam,
'', 1);
485 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
486 print $form->select_company($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
489 print
'<td colspan="5" class="right">';
490 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")).
'">';
496 print
"<tr class=\"liste_titre\">";
498 $langs->trans(
"Product"),
499 $_SERVER[
"PHP_SELF"],
508 $langs->trans(
'Quantity'),
509 $_SERVER[
"PHP_SELF"],
518 $langs->trans(
"Percentage"),
519 $_SERVER[
"PHP_SELF"],
528 $langs->trans(
'AmountHT'),
529 $_SERVER[
"PHP_SELF"],
538 $langs->trans(
"AmountTTC"),
539 $_SERVER[
"PHP_SELF"],
548 $langs->trans(
"Percentage"),
549 $_SERVER[
"PHP_SELF"],
560 foreach ($name as $key => $value) {
561 print
'<tr class="oddeven">';
565 $fullname = $name[$key];
567 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
569 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
575 print
'<td class="right">';
576 print
price($qty[$key], 1, $langs, 0, 0);
580 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
583 print
'<td class="right">';
589 print
price($amount_ht[$key]);
594 print
'<td class="right">';
600 print
price($amount[$key]);
605 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
614 print
'<tr class="liste_total">';
615 print
'<td>'.$langs->trans(
"Total").
'</td>';
616 print
'<td class="right">'.$qtytotal.
'</td>';
617 print
'<td class="right">100%</td>';
618 print
'<td class="right">'.price($catotal_ht).
'</td>';
619 print
'<td class="right">'.price($catotal).
'</td>';
620 print
'<td class="right">100%</td>';
625 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
636 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 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 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.