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>';
299report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
301if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
302 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
313if ($modecompta ==
'CREANCES-DETTES') {
314 $sql =
"SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
315 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
316 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
318 $parameters = array();
319 $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
320 $sql .= $hookmanager->resPrint;
322 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
323 $sql .=
",".MAIN_DB_PREFIX.
"facturedet as l";
324 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
325 if ($typent_id > 0) {
326 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
328 $parameters = array();
329 $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
330 $sql .= $hookmanager->resPrint;
332 $sql .=
" WHERE l.fk_facture = f.rowid";
333 $sql .=
" AND f.fk_statut in (1,2)";
334 $sql .=
" AND l.product_type in (0,1)";
336 $sql .=
" AND f.type IN (0,1,2,5)";
338 $sql .=
" AND f.type IN (0,1,2,3,5)";
340 if ($date_start && $date_end) {
341 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
343 if ($selected_type >= 0) {
344 $sql .=
" AND l.product_type = ".((int) $selected_type);
348 $searchCategoryProductOperator = -1;
349 $searchCategoryProductList = array($selected_cat);
351 $TListOfCats = $categorie->get_full_arbo(
'product', $selected_cat, 1);
352 $searchCategoryProductList = array();
353 foreach ($TListOfCats as $key => $cat) {
354 $searchCategoryProductList[] = $cat[
'id'];
357 if (!empty($searchCategoryProductList)) {
358 $searchCategoryProductSqlList = array();
359 $listofcategoryid =
'';
360 foreach ($searchCategoryProductList as $searchCategoryProduct) {
361 if (intval($searchCategoryProduct) == -2) {
362 $searchCategoryProductSqlList[] =
"NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product as ck WHERE l.fk_product = ck.fk_product)";
363 } elseif (intval($searchCategoryProduct) > 0) {
364 if ($searchCategoryProductOperator == 0) {
365 $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).
")";
367 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategoryProduct);
371 if ($listofcategoryid) {
372 $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).
"))";
374 if ($searchCategoryProductOperator == 1) {
375 if (!empty($searchCategoryProductSqlList)) {
376 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
379 if (!empty($searchCategoryProductSqlList)) {
380 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
386 $searchCategorySocieteOperator = -1;
387 $searchCategorySocieteList = array($selected_catsoc);
388 if (!empty($searchCategorySocieteList)) {
389 $searchCategorySocieteSqlList = array();
390 $listofcategoryid =
'';
391 foreach ($searchCategorySocieteList as $searchCategorySociete) {
392 if (intval($searchCategorySociete) == -2) {
393 $searchCategorySocieteSqlList[] =
"NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs WHERE f.fk_soc = cs.fk_soc)";
394 } elseif (intval($searchCategorySociete) > 0) {
395 if ($searchCategorySocieteOperator == 0) {
396 $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).
")";
398 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategorySociete);
402 if ($listofcategoryid) {
403 $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).
"))";
405 if ($searchCategorySocieteOperator == 1) {
406 if (!empty($searchCategorySocieteSqlList)) {
407 $sql .=
" AND (".implode(
' OR ', $searchCategorySocieteSqlList).
")";
410 if (!empty($searchCategorySocieteSqlList)) {
411 $sql .=
" AND (".implode(
' AND ', $searchCategorySocieteSqlList).
")";
416 if ($selected_soc > 0) {
417 $sql .=
" AND f.fk_soc = ".((int) $selected_soc);
420 if ($typent_id > 0) {
421 $sql .=
" AND soc.fk_typent = ".((int) $typent_id);
424 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
426 $parameters = array();
427 $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
428 $sql .= $hookmanager->resPrint;
430 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
431 $sql .= $db->order($sortfield, $sortorder);
434 $result = $db->query($sql);
436 $amount_ht = array();
440 $num = $db->num_rows($result);
443 $obj = $db->fetch_object($result);
445 $amount_ht[$obj->rowid] = $obj->amount;
446 $amount[$obj->rowid] = $obj->amount_ttc;
447 $qty[$obj->rowid] = $obj->qty;
448 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
449 $type[$obj->rowid] = $obj->product_type;
450 $catotal_ht += $obj->amount;
451 $catotal += $obj->amount_ttc;
452 $qtytotal += $obj->qty;
461 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
462 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
464 foreach ($headerparams as $key => $value) {
465 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
470 print
'<div class="div-table-responsive">';
471 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
474 print
'<tr class="liste_titre">';
476 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
477 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
479 print
'<input type="checkbox" class="marginleft" id="subcat" name="subcat" value="yes"';
484 print
'<label for="subcat" class="marginrightonly">'.$langs->trans(
"SubCats").
'?</label>';
486 $form->select_type_of_lines($selected_type,
'search_type', $langs->trans(
"Type"), 1, 1);
490 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
491 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc,
'search_categ_soc', 0, $langs->trans(
"CustomersProspectsCategoriesShort"));
494 print
' ';
498 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, $langs->trans(
"ThirdPartyType"), 0, 0,
'', 0, 0, 0, $sortparam,
'', 1);
501 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
502 print $form->select_company($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
505 print
'<td colspan="5" class="right">';
506 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")).
'">';
512 print
"<tr class=\"liste_titre\">";
514 $langs->trans(
"Product"),
515 $_SERVER[
"PHP_SELF"],
524 $langs->trans(
'Quantity'),
525 $_SERVER[
"PHP_SELF"],
534 $langs->trans(
"Percentage"),
535 $_SERVER[
"PHP_SELF"],
544 $langs->trans(
'AmountHT'),
545 $_SERVER[
"PHP_SELF"],
554 $langs->trans(
"AmountTTC"),
555 $_SERVER[
"PHP_SELF"],
564 $langs->trans(
"Percentage"),
565 $_SERVER[
"PHP_SELF"],
576 foreach ($name as $key => $value) {
577 print
'<tr class="oddeven">';
581 $fullname = $name[$key];
583 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
585 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
591 print
'<td class="right">';
592 print
price($qty[$key], 1, $langs, 0, 0);
596 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
599 print
'<td class="right">';
605 print
price($amount_ht[$key]);
610 print
'<td class="right">';
616 print
price($amount[$key]);
621 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
630 print
'<tr class="liste_total">';
631 print
'<td>'.$langs->trans(
"Total").
'</td>';
632 print
'<td class="right">'.$qtytotal.
'</td>';
633 print
'<td class="right">100%</td>';
634 print
'<td class="right">'.price($catotal_ht).
'</td>';
635 print
'<td class="right">'.price($catotal).
'</td>';
636 print
'<td class="right">100%</td>';
641 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
652 print
'<br>'.$langs->trans(
"TurnoverPerProductInCommitmentAccountingNotRelevant").
'<br>';
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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_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.