Go to the documentation of this file.
23 require
'../../main.inc.php';
24 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
31 $langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
34 $modecompta = $conf->global->ACCOUNTING_MODE;
36 $modecompta =
GETPOST(
"modecompta");
39 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
40 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
49 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
50 $selected_soc = (int)
GETPOST(
'search_soc',
'int');
52 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
56 $selected_type =
GETPOST(
'search_type',
'int');
57 if ($selected_type ==
'') {
62 $hookmanager->initHooks(array(
'supplierturnoverbyprodservlist'));
67 $date_startyear =
GETPOST(
"date_startyear");
68 $date_startmonth =
GETPOST(
"date_startmonth");
69 $date_startday =
GETPOST(
"date_startday");
70 $date_endyear =
GETPOST(
"date_endyear");
71 $date_endmonth =
GETPOST(
"date_endmonth");
72 $date_endday =
GETPOST(
"date_endday");
76 $year_start = $year_current;
78 $year_current = $year;
85 if (empty($date_start) || empty($date_end)) {
89 $month_start =
GETPOST(
"month") ?
GETPOST(
"month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
90 $year_end = $year_start;
91 $month_end = $month_start;
93 if (!
GETPOST(
'year') && $month_start > $month_current) {
97 $month_end = $month_start - 1;
130 $year_start = $tmps[
'year'];
132 $year_end = $tmpe[
'year'];
133 $nbofyear = ($year_end - $year_start) + 1;
135 $commonparams = array();
136 if (!empty($modecompta)) {
137 $commonparams[
'modecompta'] = $modecompta;
139 if (!empty($sortorder)) {
140 $commonparams[
'sortorder'] = $sortorder;
142 if (!empty($sortfield)) {
143 $commonparams[
'sortfield'] = $sortfield;
146 $headerparams = array();
147 if (!empty($date_startyear)) {
148 $headerparams[
'date_startyear'] = $date_startyear;
150 if (!empty($date_startmonth)) {
151 $headerparams[
'date_startmonth'] = $date_startmonth;
153 if (!empty($date_startday)) {
154 $headerparams[
'date_startday'] = $date_startday;
156 if (!empty($date_endyear)) {
157 $headerparams[
'date_endyear'] = $date_endyear;
159 if (!empty($date_endmonth)) {
160 $headerparams[
'date_endmonth'] = $date_endmonth;
162 if (!empty($date_endday)) {
163 $headerparams[
'date_endday'] = $date_endday;
166 $headerparams[
'year'] = $year;
168 if (!empty($month)) {
169 $headerparams[
'month'] = $month;
171 $headerparams[
'q'] = $q;
173 $tableparams = array();
174 if (!empty($selected_cat)) {
175 $tableparams[
'search_categ'] = $selected_cat;
177 if (!empty($selected_soc)) {
178 $tableparams[
'search_soc'] = $selected_soc;
180 if (!empty($selected_type)) {
181 $tableparams[
'search_type'] = $selected_type;
183 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
186 $allparams = array_merge($commonparams, $headerparams, $tableparams);
187 $headerparams = array_merge($commonparams, $headerparams);
188 $tableparams = array_merge($commonparams, $tableparams);
190 foreach ($allparams as $key => $value) {
191 $paramslink .=
'&'.$key.
'='.$value;
195 $socid =
GETPOST(
'socid',
'int');
197 if ($user->socid > 0) {
198 $socid = $user->socid;
204 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
218 if ($modecompta ==
"BOOKKEEPING") {
219 $modecompta =
"CREANCES-DETTES";
221 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
222 $modecompta =
"RECETTES-DEPENSES";
226 if ($modecompta ==
"CREANCES-DETTES") {
227 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByProductsAndServices");
228 $calcmode = $langs->trans(
"CalcModeDebt");
231 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
233 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
234 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
235 $calcmode = $langs->trans(
"CalcModeEngagement");
237 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
240 } elseif ($modecompta ==
"BOOKKEEPING") {
241 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
244 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
246 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
248 $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>';
253 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
255 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
256 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
268 if ($modecompta ==
'CREANCES-DETTES') {
269 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
270 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
271 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
273 if ($selected_soc > 0) {
274 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
276 $sql .=
",".MAIN_DB_PREFIX.
"facture_fourn_det as l";
277 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
278 if ($selected_cat === -2) {
279 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
280 } elseif ($selected_cat) {
281 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
283 $sql .=
" WHERE l.fk_facture_fourn = f.rowid";
284 $sql .=
" AND f.fk_statut in (1,2)";
285 $sql .=
" AND f.type IN (0,2)";
287 if ($date_start && $date_end) {
288 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
290 if ($selected_type >= 0) {
291 $sql .=
" AND l.product_type = ".((int) $selected_type);
293 if ($selected_cat === -2) {
294 $sql .=
" AND cp.fk_product is null";
295 } elseif ($selected_cat) {
296 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
298 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
301 $sql .=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
303 if ($selected_soc > 0) {
304 $sql .=
" AND soc.rowid=".((int) $selected_soc);
306 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
307 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
308 $sql .= $db->order($sortfield, $sortorder);
310 dol_syslog(
"supplier_turnover_by_prodserv", LOG_DEBUG);
311 $result = $db->query($sql);
313 $num = $db->num_rows($result);
316 $obj = $db->fetch_object($result);
317 $amount_ht[$obj->rowid] = $obj->amount;
318 $amount[$obj->rowid] = $obj->amount_ttc;
319 $qty[$obj->rowid] = $obj->qty;
320 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
321 $type[$obj->rowid] = $obj->product_type;
322 $catotal_ht += $obj->amount;
323 $catotal += $obj->amount_ttc;
324 $qtytotal += $obj->qty;
333 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
334 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
336 foreach ($headerparams as $key => $value) {
337 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
342 print
'<div class="div-table-responsive">';
343 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
346 print
'<tr class="liste_titre">';
348 print
img_picto(
'',
'category',
'class="paddingrightonly"');
349 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
351 print $langs->trans(
"SubCats").
'? ';
352 print
'<input type="checkbox" name="subcat" value="yes"';
359 print $langs->trans(
"Type").
': ';
360 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', 1, 1, 1);
364 print
img_picto(
'',
'company',
'class="paddingrightonly"');
365 print
$form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
368 print
'<td colspan="5" class="right">';
369 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")).
'">';
373 print
"<tr class=\"liste_titre\">";
375 $langs->trans(
"Product"),
376 $_SERVER[
"PHP_SELF"],
385 $langs->trans(
'Quantity'),
386 $_SERVER[
"PHP_SELF"],
395 $langs->trans(
"Percentage"),
396 $_SERVER[
"PHP_SELF"],
405 $langs->trans(
'AmountHT'),
406 $_SERVER[
"PHP_SELF"],
415 $langs->trans(
"AmountTTC"),
416 $_SERVER[
"PHP_SELF"],
425 $langs->trans(
"Percentage"),
426 $_SERVER[
"PHP_SELF"],
437 foreach ($name as $key => $value) {
438 print
'<tr class="oddeven">';
442 $fullname = $name[$key];
444 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
446 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
452 print
'<td class="right">';
457 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
460 print
'<td class="right">';
461 print
price($amount_ht[$key]);
466 print
'<td class="right">';
467 print
price($amount[$key]);
472 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
481 print
'<tr class="liste_total">';
482 print
'<td>'.$langs->trans(
"Total").
'</td>';
483 print
'<td class="right">'.$qtytotal.
'</td>';
484 print
'<td class="right">100%</td>';
485 print
'<td class="right">'.price($catotal_ht).
'</td>';
486 print
'<td class="right">'.price($catotal).
'</td>';
487 print
'<td class="right">100%</td>';
501 print
'<br>'.$langs->trans(
"TurnoverPerProductInCommitmentAccountingNotRelevant").
'<br>';
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.
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.
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='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
img_next($titlealt='default', $moreatt='')
Show next logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
isModEnabled($module)
Is Dolibarr module enabled.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
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_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...
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.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.