24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
32 $langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
35 $modecompta = $conf->global->ACCOUNTING_MODE;
37 $modecompta =
GETPOST(
"modecompta");
40 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
41 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
50 $selected_cat = (int)
GETPOST(
'search_categ',
'int');
51 $selected_soc = (int)
GETPOST(
'search_soc',
'int');
53 if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
57 $selected_type =
GETPOST(
'search_type',
'int');
58 if ($selected_type ==
'') {
63 $hookmanager->initHooks(array(
'supplierturnoverbyprodservlist'));
68 $date_startyear =
GETPOST(
"date_startyear");
69 $date_startmonth =
GETPOST(
"date_startmonth");
70 $date_startday =
GETPOST(
"date_startday");
71 $date_endyear =
GETPOST(
"date_endyear");
72 $date_endmonth =
GETPOST(
"date_endmonth");
73 $date_endday =
GETPOST(
"date_endday");
77 $year_start = $year_current;
79 $year_current = $year;
86 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;
94 if (!
GETPOST(
'year') && $month_start > $month_current) {
98 $month_end = $month_start - 1;
131 $year_start = $tmps[
'year'];
133 $year_end = $tmpe[
'year'];
134 $nbofyear = ($year_end - $year_start) + 1;
136 $commonparams = array();
137 if (!empty($modecompta)) {
138 $commonparams[
'modecompta'] = $modecompta;
140 if (!empty($sortorder)) {
141 $commonparams[
'sortorder'] = $sortorder;
143 if (!empty($sortfield)) {
144 $commonparams[
'sortfield'] = $sortfield;
147 $headerparams = array();
148 if (!empty($date_startyear)) {
149 $headerparams[
'date_startyear'] = $date_startyear;
151 if (!empty($date_startmonth)) {
152 $headerparams[
'date_startmonth'] = $date_startmonth;
154 if (!empty($date_startday)) {
155 $headerparams[
'date_startday'] = $date_startday;
157 if (!empty($date_endyear)) {
158 $headerparams[
'date_endyear'] = $date_endyear;
160 if (!empty($date_endmonth)) {
161 $headerparams[
'date_endmonth'] = $date_endmonth;
163 if (!empty($date_endday)) {
164 $headerparams[
'date_endday'] = $date_endday;
167 $headerparams[
'year'] = $year;
169 if (!empty($month)) {
170 $headerparams[
'month'] = $month;
172 $headerparams[
'q'] = $q;
174 $tableparams = array();
175 if (!empty($selected_cat)) {
176 $tableparams[
'search_categ'] = $selected_cat;
178 if (!empty($selected_soc)) {
179 $tableparams[
'search_soc'] = $selected_soc;
181 if (!empty($selected_type)) {
182 $tableparams[
'search_type'] = $selected_type;
184 $tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
187 $allparams = array_merge($commonparams, $headerparams, $tableparams);
188 $headerparams = array_merge($commonparams, $headerparams);
189 $tableparams = array_merge($commonparams, $tableparams);
192 foreach ($allparams as $key => $value) {
193 $paramslink .=
'&'.$key.
'='.$value;
197 $socid =
GETPOST(
'socid',
'int');
199 if ($user->socid > 0) {
200 $socid = $user->socid;
206 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
220 if ($modecompta ==
"BOOKKEEPING") {
221 $modecompta =
"CREANCES-DETTES";
223 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
224 $modecompta =
"RECETTES-DEPENSES";
228 if ($modecompta ==
"CREANCES-DETTES") {
229 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByProductsAndServices");
230 $calcmode = $langs->trans(
"CalcModeDebt");
233 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
235 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
236 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
237 $calcmode = $langs->trans(
"CalcModeEngagement");
239 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
242 } elseif ($modecompta ==
"BOOKKEEPING") {
243 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
246 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
248 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
250 $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>';
257 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
259 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
260 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
272 if ($modecompta ==
'CREANCES-DETTES') {
273 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
274 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
275 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
277 if ($selected_soc > 0) {
278 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
280 $sql .=
",".MAIN_DB_PREFIX.
"facture_fourn_det as l";
281 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
282 if ($selected_cat === -2) {
283 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
284 } elseif ($selected_cat) {
285 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
287 $sql .=
" WHERE l.fk_facture_fourn = f.rowid";
288 $sql .=
" AND f.fk_statut in (1,2)";
289 $sql .=
" AND f.type IN (0,2)";
291 if ($date_start && $date_end) {
292 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
294 if ($selected_type >= 0) {
295 $sql .=
" AND l.product_type = ".((int) $selected_type);
297 if ($selected_cat === -2) {
298 $sql .=
" AND cp.fk_product is null";
299 } elseif ($selected_cat) {
300 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
302 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
305 $sql .=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
307 if ($selected_soc > 0) {
308 $sql .=
" AND soc.rowid=".((int) $selected_soc);
310 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
311 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
312 $sql .= $db->order($sortfield, $sortorder);
314 dol_syslog(
"supplier_turnover_by_prodserv", LOG_DEBUG);
315 $resql = $db->query($sql);
317 $num = $db->num_rows(
$resql);
320 $obj = $db->fetch_object(
$resql);
322 $amount_ht[$obj->rowid] = $obj->amount;
323 $amount[$obj->rowid] = $obj->amount_ttc;
324 $qty[$obj->rowid] = $obj->qty;
325 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
326 $type[$obj->rowid] = $obj->product_type;
328 $catotal_ht += $obj->amount;
329 $catotal += $obj->amount_ttc;
330 $qtytotal += $obj->qty;
340 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
341 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
343 foreach ($headerparams as $key => $value) {
344 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
349 print
'<div class="div-table-responsive">';
350 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
353 print
'<tr class="liste_titre">';
355 print
img_picto(
'',
'category',
'class="paddingrightonly"');
356 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"));
358 print $langs->trans(
"SubCats").
'? ';
359 print
'<input type="checkbox" name="subcat" value="yes"';
366 print $langs->trans(
"Type").
': ';
367 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', 1, 1, 1);
371 print
img_picto(
'',
'company',
'class="paddingrightonly"');
372 print
$form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"));
375 print
'<td colspan="5" class="right">';
376 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")).
'">';
380 print
"<tr class=\"liste_titre\">";
382 $langs->trans(
"Product"),
383 $_SERVER[
"PHP_SELF"],
392 $langs->trans(
'Quantity'),
393 $_SERVER[
"PHP_SELF"],
402 $langs->trans(
"Percentage"),
403 $_SERVER[
"PHP_SELF"],
412 $langs->trans(
'AmountHT'),
413 $_SERVER[
"PHP_SELF"],
422 $langs->trans(
"AmountTTC"),
423 $_SERVER[
"PHP_SELF"],
432 $langs->trans(
"Percentage"),
433 $_SERVER[
"PHP_SELF"],
444 foreach ($name as $key => $value) {
445 print
'<tr class="oddeven">';
449 $fullname = $name[$key];
451 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
453 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
459 print
'<td class="right">';
464 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
467 print
'<td class="right">';
468 print
price($amount_ht[$key]);
473 print
'<td class="right">';
474 print
price($amount[$key]);
479 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
488 print
'<tr class="liste_total">';
489 print
'<td>'.$langs->trans(
"Total").
'</td>';
490 print
'<td class="right">'.$qtytotal.
'</td>';
491 print
'<td class="right">100%</td>';
492 print
'<td class="right">'.price($catotal_ht).
'</td>';
493 print
'<td class="right">'.price($catotal).
'</td>';
494 print
'<td class="right">100%</td>';
508 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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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 informations (by default a local PHP server timestamp) Re...
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
img_next($titlealt='default', $moreatt='')
Show next logo.
isModEnabled($module)
Is Dolibarr module enabled.
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.
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.