26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
34 $langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
37 $socid =
GETPOST(
'socid',
'int');
39 if ($user->societe_id > 0) $socid = $user->societe_id;
40 if (! empty($conf->comptabilite->enabled)) $result=
restrictedArea($user,
'compta',
'',
'',
'resultat');
41 if (! empty($conf->accounting->enabled)) $result=
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
44 $modecompta = $conf->global->ACCOUNTING_MODE;
47 $sortorder=isset($_GET[
"sortorder"])?$_GET[
"sortorder"]:$_POST[
"sortorder"];
48 $sortfield=isset($_GET[
"sortfield"])?$_GET[
"sortfield"]:$_POST[
"sortfield"];
49 if (! $sortorder) $sortorder=
"asc";
50 if (! $sortfield) $sortfield=
"ref";
53 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
55 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
59 $selected_type =
GETPOST(
'search_type',
'int');
60 if ($selected_type ==
'') $selected_type = -1;
65 $date_startyear =
GETPOST(
"date_startyear");
66 $date_startmonth =
GETPOST(
"date_startmonth");
67 $date_startday =
GETPOST(
"date_startday");
68 $date_endyear =
GETPOST(
"date_endyear");
69 $date_endmonth =
GETPOST(
"date_endmonth");
70 $date_endday =
GETPOST(
"date_endday");
73 $year_current = strftime(
"%Y",
dol_now());
74 $month_current = strftime(
"%m",
dol_now());
75 $year_start = $year_current;
77 $year_current = $year;
78 $month_current = strftime(
"%m",
dol_now());
84 if (empty($date_start) || empty($date_end))
90 $month_start=
GETPOST(
"month")?
GETPOST(
"month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
91 $year_end=$year_start;
92 $month_end=$month_start;
95 if (!
GETPOST(
'year') && $month_start > $month_current)
100 $month_end=$month_start-1;
101 if ($month_end < 1) $month_end=12;
119 $year_start = $tmps[
'year'];
121 $year_end = $tmpe[
'year'];
122 $nbofyear = ($year_end - $year_start) + 1;
124 $commonparams=array();
125 $commonparams[
'modecompta']=$modecompta;
126 $commonparams[
'sortorder'] = $sortorder;
127 $commonparams[
'sortfield'] = $sortfield;
129 $headerparams = array();
130 $headerparams[
'date_startyear'] = $date_startyear;
131 $headerparams[
'date_startmonth'] = $date_startmonth;
132 $headerparams[
'date_startday'] = $date_startday;
133 $headerparams[
'date_endyear'] = $date_endyear;
134 $headerparams[
'date_endmonth'] = $date_endmonth;
135 $headerparams[
'date_endday'] = $date_endday;
136 $headerparams[
'q'] = $q;
138 $tableparams = array();
139 $tableparams[
'search_categ'] = $selected_cat;
140 $tableparams[
'search_type'] = $selected_type;
141 $tableparams[
'subcat'] = ($subcat ===
true)?
'yes':
'';
144 $allparams = array_merge($commonparams, $headerparams, $tableparams);
145 $headerparams = array_merge($commonparams, $headerparams);
146 $tableparams = array_merge($commonparams, $tableparams);
148 foreach($allparams as $key => $value) {
149 $paramslink .=
'&' . $key .
'=' . $value;
163 if ($modecompta==
"BOOKKEEPING") $modecompta=
"CREANCES-DETTES";
164 if ($modecompta==
"BOOKKEEPINGCOLLECTED") $modecompta=
"RECETTES-DEPENSES";
167 if ($modecompta==
"CREANCES-DETTES") {
168 $name=$langs->trans(
"Turnover").
', '.$langs->trans(
"ByProductsAndServices");
169 $calcmode=$langs->trans(
"CalcModeDebt");
172 $description=$langs->trans(
"RulesCADue");
173 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
174 $description.= $langs->trans(
"DepositsAreNotIncluded");
176 $description.= $langs->trans(
"DepositsAreIncluded");
181 else if ($modecompta==
"RECETTES-DEPENSES")
183 $name=$langs->trans(
"TurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
184 $calcmode=$langs->trans(
"CalcModeEngagement");
187 $description=$langs->trans(
"RulesCAIn");
188 $description.= $langs->trans(
"DepositsAreIncluded");
192 else if ($modecompta==
"BOOKKEEPING")
197 else if ($modecompta==
"BOOKKEEPINGCOLLECTED")
203 $period=$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
204 if ($date_end ==
dol_time_plus_duree($date_start, 1,
'y') - 1) $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>';
205 else $periodlink =
'';
207 report_header($name,$namelink,$period,$periodlink,$description,$builddate,$exportlink,$tableparams,$calcmode);
209 if (! empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
223 if ($modecompta ==
'CREANCES-DETTES')
225 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
226 $sql.=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
227 $sql.=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
228 $sql.=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as l";
229 $sql.=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
230 if ($selected_cat === -2)
232 $sql.=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
234 else if ($selected_cat)
236 $sql.=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
238 $sql.=
" WHERE l.fk_facture = f.rowid";
239 $sql.=
" AND f.fk_statut in (1,2)";
240 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
241 $sql.=
" AND f.type IN (0,1,2,5)";
243 $sql.=
" AND f.type IN (0,1,2,3,5)";
245 if ($date_start && $date_end) {
246 $sql.=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
248 if ($selected_type >=0)
250 $sql.=
" AND l.product_type = ".$selected_type;
252 if ($selected_cat === -2)
254 $sql.=
" AND cp.fk_product is null";
256 else if ($selected_cat) {
257 $sql.=
" AND (c.rowid = ".$selected_cat;
258 if ($subcat) $sql.=
" OR c.fk_parent = " . $selected_cat;
260 $sql.=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
262 $sql.=
" AND f.entity = ".$conf->entity;
263 $sql.=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
264 $sql.= $db->order($sortfield,$sortorder);
267 $result = $db->query($sql);
269 $num = $db->num_rows($result);
272 $obj = $db->fetch_object($result);
273 $amount_ht[$obj->rowid] = $obj->amount;
274 $amount[$obj->rowid] = $obj->amount_ttc;
275 $qty[$obj->rowid] = $obj->qty;
276 $name[$obj->rowid] = $obj->ref .
' - ' . $obj->label;
277 $type[$obj->rowid] = $obj->product_type;
278 $catotal_ht+=$obj->amount;
279 $catotal+=$obj->amount_ttc;
280 $qtytotal+=$obj->qty;
289 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
291 foreach($headerparams as $key => $value)
293 print '<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
298 print '<div class="div-table-responsive">';
299 print '<table class="tagtable liste'.($moreforfilter?
" listwithfilterbefore":
"").
'">'.
"\n";
302 print '<tr class="liste_titre">';
304 print $langs->trans(
"Category") .
': ' . $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ',
true);
306 print $langs->trans(
"SubCats") .
'? ';
307 print
'<input type="checkbox" name="subcat" value="yes"';
314 print $langs->trans(
"Type").
': ';
315 $form->select_type_of_lines(isset($selected_type)?$selected_type:-1,
'search_type',1,1,1);
318 print
'<td colspan="5" align="right">';
319 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")).
'">';
323 print
"<tr class=\"liste_titre\">";
325 $langs->trans(
"Product"),
326 $_SERVER[
"PHP_SELF"],
335 $langs->trans(
'Quantity'),
336 $_SERVER[
"PHP_SELF"],
345 $langs->trans(
"Percentage"),
346 $_SERVER[
"PHP_SELF"],
355 $langs->trans(
'AmountHT'),
356 $_SERVER[
"PHP_SELF"],
365 $langs->trans(
"AmountTTC"),
366 $_SERVER[
"PHP_SELF"],
375 $langs->trans(
"Percentage"),
376 $_SERVER[
"PHP_SELF"],
387 foreach($name as $key=>$value) {
389 print
'<tr class="oddeven">';
393 $fullname=$name[$key];
395 $linkname=
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"),$type[$key]==0?
'product':
'service').
' '.$fullname.
'</a>';
397 $linkname=$langs->trans(
"PaymentsNotLinkedToProduct");
403 print
'<td align="right">';
408 print
'<td align="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
411 print
'<td align="right">';
417 print
price($amount_ht[$key]);
422 print
'<td align="right">';
428 print
price($amount[$key]);
433 print
'<td align="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
442 print
'<tr class="liste_total">';
443 print
'<td>'.$langs->trans(
"Total").
'</td>';
444 print
'<td align="right">'.$qtytotal.
'</td>';
445 print
'<td align="right">100%</td>';
446 print
'<td align="right">'.price($catotal_ht).
'</td>';
447 print
'<td align="right">'.price($catotal).
'</td>';
448 print
'<td align="right">100%</td>';
462 print
'<br>'.$langs->trans(
"TurnoverPerProductInCommitmentAccountingNotRelevant") .
'<br>';
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_now($mode='gmt')
Return date for now.
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_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)