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';
34$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
39 $modecompta =
GETPOST(
"modecompta");
43$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
44$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
56if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
60$selected_type =
GETPOST(
'search_type',
"intcomma");
61if ($selected_type ==
'') {
66$hookmanager->initHooks(array(
'supplierturnoverbyprodservlist'));
69$date_startmonth =
GETPOSTINT(
"date_startmonth");
83 $year_start = $year_current - ($nbofyear - 1);
85 $year_current = $year;
87 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
89$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
90$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
93if (empty($date_start) || empty($date_end)) {
97 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
100 if (!$year && $month_start > $month_current) {
104 $month_end = $month_start - 1;
105 if ($month_end < 1) {
109 $month_end = $month_start;
134$year_start = $tmps[
'year'];
136$year_end = $tmpe[
'year'];
137$nbofyear = ($year_end - $year_start) + 1;
139$commonparams = array();
140if (!empty($modecompta)) {
141 $commonparams[
'modecompta'] = $modecompta;
143if (!empty($sortorder)) {
144 $commonparams[
'sortorder'] = $sortorder;
146if (!empty($sortfield)) {
147 $commonparams[
'sortfield'] = $sortfield;
150$headerparams = array();
151if (!empty($date_startyear)) {
152 $headerparams[
'date_startyear'] = $date_startyear;
154if (!empty($date_startmonth)) {
155 $headerparams[
'date_startmonth'] = $date_startmonth;
157if (!empty($date_startday)) {
158 $headerparams[
'date_startday'] = $date_startday;
160if (!empty($date_endyear)) {
161 $headerparams[
'date_endyear'] = $date_endyear;
163if (!empty($date_endmonth)) {
164 $headerparams[
'date_endmonth'] = $date_endmonth;
166if (!empty($date_endday)) {
167 $headerparams[
'date_endday'] = $date_endday;
170 $headerparams[
'year'] = $year;
173 $headerparams[
'month'] = $month;
175$headerparams[
'q'] = $q;
177$tableparams = array();
178if (!empty($selected_cat)) {
179 $tableparams[
'search_categ'] = $selected_cat;
181if (!empty($selected_soc)) {
182 $tableparams[
'search_soc'] = $selected_soc;
184if (!empty($selected_type)) {
185 $tableparams[
'search_type'] = $selected_type;
187$tableparams[
'subcat'] = $subcat ?
'yes' :
'';
190$allparams = array_merge($commonparams, $headerparams, $tableparams);
191$headerparams = array_merge($commonparams, $headerparams);
192$tableparams = array_merge($commonparams, $tableparams);
195foreach ($allparams as $key => $value) {
196 $paramslink .=
'&'.$key.
'='.$value;
202if ($user->socid > 0) {
203 $socid = $user->socid;
205if (isModEnabled(
'comptabilite')) {
208if (isModEnabled(
'accounting')) {
209 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
219$form =
new Form($db);
223if ($modecompta ==
"BOOKKEEPING") {
224 $modecompta =
"CREANCES-DETTES";
226if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
227 $modecompta =
"RECETTES-DEPENSES";
231if ($modecompta ==
"CREANCES-DETTES") {
232 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByProductsAndServices");
233 $calcmode = $langs->trans(
"CalcModeDebt");
236 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
237} elseif ($modecompta ==
"RECETTES-DEPENSES") {
238 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
239 $calcmode = $langs->trans(
"CalcModePayment");
241 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
242} elseif ($modecompta ==
"BOOKKEEPING") {
244} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
249$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
251$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
253 $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>';
260report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
262if (isModEnabled(
'accounting')) {
263 if ($modecompta !=
'BOOKKEEPING') {
264 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
268 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
269 if (empty($pcgvercode)) {
270 $pcgvercode = $pcgverid;
273 $sql =
"SELECT b.rowid ";
274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
275 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
276 $sql .=
" WHERE b.entity = ".$conf->entity;
277 $sql .=
" AND b.numero_compte = aa.account_number";
278 $sql .=
" AND aa.entity = ".$conf->entity;
279 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
280 $sql .= $db->plimit(1);
282 $resql = $db->query($sql);
283 $nb = $db->num_rows($resql);
285 $langs->load(
"errors");
286 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
303if ($modecompta ==
'CREANCES-DETTES') {
304 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
305 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
306 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
308 if ($selected_soc > 0) {
309 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
311 $sql .=
",".MAIN_DB_PREFIX.
"facture_fourn_det as l";
312 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
313 if ($selected_cat === -2) {
314 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
315 } elseif ($selected_cat) {
316 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
318 $sql .=
" WHERE l.fk_facture_fourn = f.rowid";
319 $sql .=
" AND f.fk_statut in (1,2)";
320 $sql .=
" AND f.type IN (0,2)";
322 if ($date_start && $date_end) {
323 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
325 if ($selected_type >= 0) {
326 $sql .=
" AND l.product_type = ".((int) $selected_type);
328 if ($selected_cat === -2) {
329 $sql .=
" AND cp.fk_product is null";
330 } elseif ($selected_cat) {
331 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
333 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
336 $sql .=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
338 if ($selected_soc > 0) {
339 $sql .=
" AND soc.rowid=".((int) $selected_soc);
341 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
342 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
343 $sql .= $db->order($sortfield, $sortorder);
345 dol_syslog(
"supplier_turnover_by_prodserv", LOG_DEBUG);
346 $resql = $db->query($sql);
348 $num = $db->num_rows($resql);
351 $obj = $db->fetch_object($resql);
353 $amount_ht[$obj->rowid] = $obj->amount;
354 $amount[$obj->rowid] = $obj->amount_ttc;
355 $qty[$obj->rowid] = $obj->qty;
356 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
357 $type[$obj->rowid] = $obj->product_type;
359 $catotal_ht += $obj->amount;
360 $catotal += $obj->amount_ttc;
361 $qtytotal += $obj->qty;
371 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
372 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
374 foreach ($headerparams as $key => $value) {
375 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
380 print
'<div class="div-table-responsive">';
381 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
384 print
'<tr class="liste_titre">';
386 print
img_picto(
'',
'category',
'class="paddingrightonly"');
387 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"),
'maxwidth300');
389 print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
390 print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
397 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', $langs->trans(
"Type"), 1, 1);
401 print
img_picto(
'',
'company',
'class="paddingrightonly"');
402 print $form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"), 0, 0, [],
'', 0, 0,
'maxwidth250');
405 print
'<td colspan="5" class="right">';
406 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")).
'">';
410 print
'<tr class="liste_titre">';
412 $langs->trans(
"Product"),
413 $_SERVER[
"PHP_SELF"],
422 $langs->trans(
'Quantity'),
423 $_SERVER[
"PHP_SELF"],
432 $langs->trans(
"Percentage"),
433 $_SERVER[
"PHP_SELF"],
442 $langs->trans(
'AmountHT'),
443 $_SERVER[
"PHP_SELF"],
452 $langs->trans(
"AmountTTC"),
453 $_SERVER[
"PHP_SELF"],
462 $langs->trans(
"Percentage"),
463 $_SERVER[
"PHP_SELF"],
474 foreach ($name as $key => $value) {
475 print
'<tr class="oddeven">';
479 $fullname = $name[$key];
481 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
483 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
489 print
'<td class="right">';
494 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
497 print
'<td class="right">';
498 print
price($amount_ht[$key]);
502 print
'<td class="right">';
503 print
price($amount[$key]);
507 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
516 print
'<tr class="liste_total">';
517 print
'<td>'.$langs->trans(
"Total").
'</td>';
518 print
'<td class="right">'.$qtytotal.
'</td>';
519 print
'<td class="right">100%</td>';
520 print
'<td class="right">'.price($catotal_ht).
'</td>';
521 print
'<td class="right">'.price($catotal).
'</td>';
522 print
'<td class="right">100%</td>';
527 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
538 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.