26require
'../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
42$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
47 $modecompta =
GETPOST(
"modecompta");
51$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
52$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
64if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
68$selected_type =
GETPOST(
'search_type',
"intcomma");
69if ($selected_type ==
'') {
74$hookmanager->initHooks(array(
'supplierturnoverbyprodservlist'));
77$date_startmonth =
GETPOSTINT(
"date_startmonth");
91 $year_start = $year_current - ($nbofyear - 1);
93 $year_current = $year;
95 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
97$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
98$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
102if (empty($date_start) || empty($date_end)) {
106 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
109 if (!$year && $month_start > $month_current) {
113 $month_end = $month_start - 1;
114 if ($month_end < 1) {
118 $month_end = $month_start;
143$year_start = $tmps[
'year'];
145$year_end = $tmpe[
'year'];
146$nbofyear = ($year_end - $year_start) + 1;
148$commonparams = array();
149if (!empty($modecompta)) {
150 $commonparams[
'modecompta'] = $modecompta;
152if (!empty($sortorder)) {
153 $commonparams[
'sortorder'] = $sortorder;
155if (!empty($sortfield)) {
156 $commonparams[
'sortfield'] = $sortfield;
159$headerparams = array();
160if (!empty($date_startyear)) {
161 $headerparams[
'date_startyear'] = $date_startyear;
163if (!empty($date_startmonth)) {
164 $headerparams[
'date_startmonth'] = $date_startmonth;
166if (!empty($date_startday)) {
167 $headerparams[
'date_startday'] = $date_startday;
169if (!empty($date_endyear)) {
170 $headerparams[
'date_endyear'] = $date_endyear;
172if (!empty($date_endmonth)) {
173 $headerparams[
'date_endmonth'] = $date_endmonth;
175if (!empty($date_endday)) {
176 $headerparams[
'date_endday'] = $date_endday;
179 $headerparams[
'year'] = $year;
182 $headerparams[
'month'] = $month;
184$headerparams[
'q'] = $q;
186$tableparams = array();
187if (!empty($selected_cat)) {
188 $tableparams[
'search_categ'] = $selected_cat;
190if (!empty($selected_soc)) {
191 $tableparams[
'search_soc'] = $selected_soc;
193if ($selected_type > 0) {
194 $tableparams[
'search_type'] = $selected_type;
196$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
199$allparams = array_merge($commonparams, $headerparams, $tableparams);
200$headerparams = array_merge($commonparams, $headerparams);
201$tableparams = array_merge($commonparams, $tableparams);
204foreach ($allparams as $key => $value) {
205 $paramslink .=
'&'.$key.
'='.$value;
211if ($user->socid > 0) {
212 $socid = $user->socid;
214if (isModEnabled(
'comptabilite')) {
217if (isModEnabled(
'accounting')) {
218 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
228$form =
new Form($db);
232if ($modecompta ==
"BOOKKEEPING") {
233 $modecompta =
"CREANCES-DETTES";
235if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
236 $modecompta =
"RECETTES-DEPENSES";
245if ($modecompta ==
"CREANCES-DETTES") {
246 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByProductsAndServices");
247 $calcmode = $langs->trans(
"CalcModeDebt");
250 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
251} elseif ($modecompta ==
"RECETTES-DEPENSES") {
252 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
253 $calcmode = $langs->trans(
"CalcModePayment");
255 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
256} elseif ($modecompta ==
"BOOKKEEPING") {
258} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
263$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
265$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
267 $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>';
274report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
276if (isModEnabled(
'accounting')) {
277 if ($modecompta !=
'BOOKKEEPING') {
278 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
282 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
283 if (empty($pcgvercode)) {
284 $pcgvercode = $pcgverid;
287 $sql =
"SELECT b.rowid ";
288 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
289 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
290 $sql .=
" WHERE b.entity = ".$conf->entity;
291 $sql .=
" AND b.numero_compte = aa.account_number";
292 $sql .=
" AND aa.entity = ".$conf->entity;
293 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
294 $sql .= $db->plimit(1);
296 $resql = $db->query($sql);
297 $nb = $db->num_rows($resql);
299 $langs->load(
"errors");
300 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
317if ($modecompta ==
'CREANCES-DETTES') {
318 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
319 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
320 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
322 if ($selected_soc > 0) {
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
325 $sql .=
",".MAIN_DB_PREFIX.
"facture_fourn_det as l";
326 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
327 if ($selected_cat === -2) {
328 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
329 } elseif ($selected_cat) {
330 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
332 $sql .=
" WHERE l.fk_facture_fourn = f.rowid";
333 $sql .=
" AND f.fk_statut in (1,2)";
334 $sql .=
" AND f.type IN (0,2)";
336 if ($date_start && $date_end) {
337 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
339 if ($selected_type >= 0) {
340 $sql .=
" AND l.product_type = ".((int) $selected_type);
342 if ($selected_cat === -2) {
343 $sql .=
" AND cp.fk_product is null";
344 } elseif ($selected_cat) {
345 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
347 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
350 $sql .=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
352 if ($selected_soc > 0) {
353 $sql .=
" AND soc.rowid=".((int) $selected_soc);
355 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
356 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
357 $sql .= $db->order($sortfield, $sortorder);
359 dol_syslog(
"supplier_turnover_by_prodserv", LOG_DEBUG);
360 $resql = $db->query($sql);
362 $num = $db->num_rows($resql);
365 $obj = $db->fetch_object($resql);
367 $amount_ht[$obj->rowid] = $obj->amount;
368 $amount[$obj->rowid] = $obj->amount_ttc;
369 $qty[$obj->rowid] = $obj->qty;
370 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
371 $type[$obj->rowid] = $obj->product_type;
373 $catotal_ht += $obj->amount;
374 $catotal += $obj->amount_ttc;
375 $qtytotal += $obj->qty;
385 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
386 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
388 foreach ($headerparams as $key => $value) {
389 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
394 print
'<div class="div-table-responsive">';
395 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
398 print
'<tr class="liste_titre">';
400 print
img_picto(
'',
'category',
'class="paddingrightonly"');
401 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"),
'maxwidth300');
403 print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
404 print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
411 $form->select_type_of_lines($selected_type,
'search_type', $langs->trans(
"Type"), 1, 1);
415 print
img_picto(
'',
'company',
'class="paddingrightonly"');
416 print $form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"), 0, 0, [],
'', 0, 0,
'maxwidth250');
419 print
'<td colspan="5" class="right">';
420 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")).
'">';
424 print
'<tr class="liste_titre">';
426 $langs->trans(
"Product"),
427 $_SERVER[
"PHP_SELF"],
436 $langs->trans(
'Quantity'),
437 $_SERVER[
"PHP_SELF"],
446 $langs->trans(
"Percentage"),
447 $_SERVER[
"PHP_SELF"],
456 $langs->trans(
'AmountHT'),
457 $_SERVER[
"PHP_SELF"],
466 $langs->trans(
"AmountTTC"),
467 $_SERVER[
"PHP_SELF"],
476 $langs->trans(
"Percentage"),
477 $_SERVER[
"PHP_SELF"],
488 foreach ($name as $key => $value) {
489 print
'<tr class="oddeven">';
493 $fullname = $name[$key];
495 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
497 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
503 print
'<td class="right">';
508 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
511 print
'<td class="right">';
512 print
price($amount_ht[$key]);
516 print
'<td class="right">';
517 print
price($amount[$key]);
521 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
530 print
'<tr class="liste_total">';
531 print
'<td>'.$langs->trans(
"Total").
'</td>';
532 print
'<td class="right">'.$qtytotal.
'</td>';
533 print
'<td class="right">100%</td>';
534 print
'<td class="right">'.price($catotal_ht).
'</td>';
535 print
'<td class="right">'.price($catotal).
'</td>';
536 print
'<td class="right">100%</td>';
541 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
552 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.
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_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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.