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';
39$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
44if ($user->socid > 0) {
45 $socid = $user->socid;
49$hookmanager->initHooks(array(
'cabyprodservlist'));
51if (isModEnabled(
'comptabilite')) {
54if (isModEnabled(
'accounting')) {
55 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
61 $modecompta =
GETPOST(
"modecompta");
64$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
65$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
74$selected_cat =
GETPOST(
'search_categ',
'intcomma');
75$selected_catsoc =
GETPOST(
'search_categ_soc',
'intcomma');
76$selected_soc =
GETPOST(
'search_soc',
'intcomma');
77$typent_id =
GETPOST(
'typent_id',
'int');
79if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
85$selected_type =
GETPOST(
'search_type',
'intcomma');
86if ($selected_type ==
'') {
93$date_startyear =
GETPOST(
"date_startyear");
94$date_startmonth =
GETPOST(
"date_startmonth");
95$date_startday =
GETPOST(
"date_startday");
96$date_endyear =
GETPOST(
"date_endyear");
97$date_endmonth =
GETPOST(
"date_endmonth");
98$date_endday =
GETPOST(
"date_endday");
102 $year_start = $year_current;
104 $year_current = $year;
111if (empty($date_start) || empty($date_end)) {
116 $year_end = $year_start;
117 $month_end = $month_start;
119 if (!
GETPOST(
'year') && $month_start > $month_current) {
123 $month_end = $month_start - 1;
124 if ($month_end < 1) {
156$year_start = $tmps[
'year'];
158$year_end = $tmpe[
'year'];
159$nbofyear = ($year_end - $year_start) + 1;
161$commonparams = array();
162if (!empty($modecompta)) {
163 $commonparams[
'modecompta'] = $modecompta;
165if (!empty($sortorder)) {
166 $commonparams[
'sortorder'] = $sortorder;
168if (!empty($sortfield)) {
169 $commonparams[
'sortfield'] = $sortfield;
172$headerparams = array();
173if (!empty($date_startyear)) {
174 $headerparams[
'date_startyear'] = $date_startyear;
176if (!empty($date_startmonth)) {
177 $headerparams[
'date_startmonth'] = $date_startmonth;
179if (!empty($date_startday)) {
180 $headerparams[
'date_startday'] = $date_startday;
182if (!empty($date_endyear)) {
183 $headerparams[
'date_endyear'] = $date_endyear;
185if (!empty($date_endmonth)) {
186 $headerparams[
'date_endmonth'] = $date_endmonth;
188if (!empty($date_endday)) {
189 $headerparams[
'date_endday'] = $date_endday;
192 $headerparams[
'year'] = $year;
195 $headerparams[
'month'] = $month;
198 $headerparams[
'q'] = $q;
201$tableparams = array();
202if (!empty($selected_cat)) {
203 $tableparams[
'search_categ'] = $selected_cat;
205if (!empty($selected_catsoc)) {
206 $tableparams[
'search_categ_soc'] = $selected_catsoc;
208if (!empty($selected_soc)) {
209 $tableparams[
'search_soc'] = $selected_soc;
211if (!empty($selected_type)) {
212 $tableparams[
'search_type'] = $selected_type;
214if (!empty($typent_id)) {
215 $tableparams[
'typent_id'] = $typent_id;
217$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
220$allparams = array_merge($commonparams, $headerparams, $tableparams);
221$headerparams = array_merge($commonparams, $headerparams);
222$tableparams = array_merge($commonparams, $tableparams);
225foreach ($allparams as $key => $value) {
226 $paramslink .=
'&'.urlencode($key).
'='.urlencode($value);
236$form =
new Form($db);
240if ($modecompta ==
"BOOKKEEPING") {
241 $modecompta =
"CREANCES-DETTES";
243if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
244 $modecompta =
"RECETTES-DEPENSES";
251if ($modecompta ==
"CREANCES-DETTES") {
252 $name = $langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
253 $calcmode = $langs->trans(
"CalcModeDebt");
256 $description = $langs->trans(
"RulesCADue");
258 $description .= $langs->trans(
"DepositsAreNotIncluded");
260 $description .= $langs->trans(
"DepositsAreIncluded");
263} elseif ($modecompta ==
"RECETTES-DEPENSES") {
264 $name = $langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
265 $calcmode = $langs->trans(
"CalcModePayment");
268 $description = $langs->trans(
"RulesCAIn");
269 $description .= $langs->trans(
"DepositsAreIncluded");
272} elseif ($modecompta ==
"BOOKKEEPING") {
273} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
276$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
278$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
280 $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>';
285report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
287if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
288 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
299if ($modecompta ==
'CREANCES-DETTES') {
300 $sql =
"SELECT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
301 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
302 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
304 $parameters = array();
305 $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
306 $sql .= $hookmanager->resPrint;
308 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
309 $sql .=
",".MAIN_DB_PREFIX.
"facturedet as l";
310 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
311 if ($typent_id > 0) {
312 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
314 $parameters = array();
315 $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
316 $sql .= $hookmanager->resPrint;
318 $sql .=
" WHERE l.fk_facture = f.rowid";
319 $sql .=
" AND f.fk_statut in (1,2)";
320 $sql .=
" AND l.product_type in (0,1)";
322 $sql .=
" AND f.type IN (0,1,2,5)";
324 $sql .=
" AND f.type IN (0,1,2,3,5)";
326 if ($date_start && $date_end) {
327 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
329 if ($selected_type >= 0) {
330 $sql .=
" AND l.product_type = ".((int) $selected_type);
334 $searchCategoryProductOperator = -1;
335 $searchCategoryProductList = array($selected_cat);
337 $TListOfCats = $categorie->get_full_arbo(
'product', $selected_cat, 1);
338 $searchCategoryProductList = array();
339 foreach ($TListOfCats as $key => $cat) {
340 $searchCategoryProductList[] = $cat[
'id'];
343 if (!empty($searchCategoryProductList)) {
344 $searchCategoryProductSqlList = array();
345 $listofcategoryid =
'';
346 foreach ($searchCategoryProductList as $searchCategoryProduct) {
347 if (intval($searchCategoryProduct) == -2) {
348 $searchCategoryProductSqlList[] =
"NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX.
"categorie_product as ck WHERE l.fk_product = ck.fk_product)";
349 } elseif (intval($searchCategoryProduct) > 0) {
350 if ($searchCategoryProductOperator == 0) {
351 $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).
")";
353 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategoryProduct);
357 if ($listofcategoryid) {
358 $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).
"))";
360 if ($searchCategoryProductOperator == 1) {
361 if (!empty($searchCategoryProductSqlList)) {
362 $sql .=
" AND (".implode(
' OR ', $searchCategoryProductSqlList).
")";
365 if (!empty($searchCategoryProductSqlList)) {
366 $sql .=
" AND (".implode(
' AND ', $searchCategoryProductSqlList).
")";
372 $searchCategorySocieteOperator = -1;
373 $searchCategorySocieteList = array($selected_catsoc);
374 if (!empty($searchCategorySocieteList)) {
375 $searchCategorySocieteSqlList = array();
376 $listofcategoryid =
'';
377 foreach ($searchCategorySocieteList as $searchCategorySociete) {
378 if (intval($searchCategorySociete) == -2) {
379 $searchCategorySocieteSqlList[] =
"NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs WHERE f.fk_soc = cs.fk_soc)";
380 } elseif (intval($searchCategorySociete) > 0) {
381 if ($searchCategorySocieteOperator == 0) {
382 $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).
")";
384 $listofcategoryid .= ($listofcategoryid ?
', ' :
'') .((
int) $searchCategorySociete);
388 if ($listofcategoryid) {
389 $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).
"))";
391 if ($searchCategorySocieteOperator == 1) {
392 if (!empty($searchCategorySocieteSqlList)) {
393 $sql .=
" AND (".implode(
' OR ', $searchCategorySocieteSqlList).
")";
396 if (!empty($searchCategorySocieteSqlList)) {
397 $sql .=
" AND (".implode(
' AND ', $searchCategorySocieteSqlList).
")";
402 if ($selected_soc > 0) {
403 $sql .=
" AND f.fk_soc = ".((int) $selected_soc);
406 if ($typent_id > 0) {
407 $sql .=
" AND soc.fk_typent = ".((int) $typent_id);
410 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
412 $parameters = array();
413 $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
414 $sql .= $hookmanager->resPrint;
416 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
417 $sql .= $db->order($sortfield, $sortorder);
420 $result = $db->query($sql);
422 $amount_ht = array();
426 $num = $db->num_rows($result);
429 $obj = $db->fetch_object($result);
431 $amount_ht[$obj->rowid] = $obj->amount;
432 $amount[$obj->rowid] = $obj->amount_ttc;
433 $qty[$obj->rowid] = $obj->qty;
434 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
435 $type[$obj->rowid] = $obj->product_type;
436 $catotal_ht += $obj->amount;
437 $catotal += $obj->amount_ttc;
438 $qtytotal += $obj->qty;
447 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
448 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
450 foreach ($headerparams as $key => $value) {
451 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
456 print
'<div class="div-table-responsive">';
457 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
460 print
'<tr class="liste_titre">';
462 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
463 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
465 print
'<input type="checkbox" class="marginleft" id="subcat" name="subcat" value="yes"';
470 print
'<label for="subcat" class="marginrightonly">'.$langs->trans(
"SubCats").
'?</label>';
472 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', $langs->trans(
"Type"), 1, 1);
476 print
img_picto(
'',
'category',
'class="pictofixedwidth"');
477 print $formother->select_categories(Categorie::TYPE_CUSTOMER, $selected_catsoc,
'search_categ_soc', 0, $langs->trans(
"CustomersProspectsCategoriesShort"));
480 print
' ';
484 print $form->selectarray(
"typent_id", $formcompany->typent_array(0), $typent_id, $langs->trans(
"ThirdPartyType"), 0, 0,
'', 0, 0, 0, $sortparam,
'', 1);
487 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
488 print $form->select_company($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
491 print
'<td colspan="5" class="right">';
492 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")).
'">';
498 print
"<tr class=\"liste_titre\">";
500 $langs->trans(
"Product"),
501 $_SERVER[
"PHP_SELF"],
510 $langs->trans(
'Quantity'),
511 $_SERVER[
"PHP_SELF"],
520 $langs->trans(
"Percentage"),
521 $_SERVER[
"PHP_SELF"],
530 $langs->trans(
'AmountHT'),
531 $_SERVER[
"PHP_SELF"],
540 $langs->trans(
"AmountTTC"),
541 $_SERVER[
"PHP_SELF"],
550 $langs->trans(
"Percentage"),
551 $_SERVER[
"PHP_SELF"],
562 foreach ($name as $key => $value) {
563 print
'<tr class="oddeven">';
567 $fullname = $name[$key];
569 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
571 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
577 print
'<td class="right">';
578 print
price($qty[$key], 1, $langs, 0, 0);
582 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
585 print
'<td class="right">';
591 print
price($amount_ht[$key]);
596 print
'<td class="right">';
602 print
price($amount[$key]);
607 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
616 print
'<tr class="liste_total">';
617 print
'<td>'.$langs->trans(
"Total").
'</td>';
618 print
'<td class="right">'.$qtytotal.
'</td>';
619 print
'<td class="right">100%</td>';
620 print
'<td class="right">'.price($catotal_ht).
'</td>';
621 print
'<td class="right">'.price($catotal).
'</td>';
622 print
'<td class="right">100%</td>';
627 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
638 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.