24require
'../../main.inc.php';
25require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
26require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
32$langs->loadLangs(array(
"products",
"categories",
"errors",
'accountancy'));
37 $modecompta =
GETPOST(
"modecompta");
41$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
42$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
54if (
GETPOST(
'subcat',
'alpha') ===
'yes') {
58$selected_type =
GETPOST(
'search_type',
"intcomma");
59if ($selected_type ==
'') {
64$hookmanager->initHooks(array(
'supplierturnoverbyprodservlist'));
67$date_startmonth =
GETPOSTINT(
"date_startmonth");
81 $year_start = $year_current - ($nbofyear - 1);
83 $year_current = $year;
85 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
87$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
88$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
91if (empty($date_start) || empty($date_end)) {
95 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
98 if (!$year && $month_start > $month_current) {
102 $month_end = $month_start - 1;
103 if ($month_end < 1) {
107 $month_end = $month_start;
132$year_start = $tmps[
'year'];
134$year_end = $tmpe[
'year'];
135$nbofyear = ($year_end - $year_start) + 1;
137$commonparams = array();
138if (!empty($modecompta)) {
139 $commonparams[
'modecompta'] = $modecompta;
141if (!empty($sortorder)) {
142 $commonparams[
'sortorder'] = $sortorder;
144if (!empty($sortfield)) {
145 $commonparams[
'sortfield'] = $sortfield;
148$headerparams = array();
149if (!empty($date_startyear)) {
150 $headerparams[
'date_startyear'] = $date_startyear;
152if (!empty($date_startmonth)) {
153 $headerparams[
'date_startmonth'] = $date_startmonth;
155if (!empty($date_startday)) {
156 $headerparams[
'date_startday'] = $date_startday;
158if (!empty($date_endyear)) {
159 $headerparams[
'date_endyear'] = $date_endyear;
161if (!empty($date_endmonth)) {
162 $headerparams[
'date_endmonth'] = $date_endmonth;
164if (!empty($date_endday)) {
165 $headerparams[
'date_endday'] = $date_endday;
168 $headerparams[
'year'] = $year;
171 $headerparams[
'month'] = $month;
173$headerparams[
'q'] = $q;
175$tableparams = array();
176if (!empty($selected_cat)) {
177 $tableparams[
'search_categ'] = $selected_cat;
179if (!empty($selected_soc)) {
180 $tableparams[
'search_soc'] = $selected_soc;
182if (!empty($selected_type)) {
183 $tableparams[
'search_type'] = $selected_type;
185$tableparams[
'subcat'] = ($subcat ===
true) ?
'yes' :
'';
188$allparams = array_merge($commonparams, $headerparams, $tableparams);
189$headerparams = array_merge($commonparams, $headerparams);
190$tableparams = array_merge($commonparams, $tableparams);
193foreach ($allparams as $key => $value) {
194 $paramslink .=
'&'.$key.
'='.$value;
200if ($user->socid > 0) {
201 $socid = $user->socid;
203if (isModEnabled(
'comptabilite')) {
206if (isModEnabled(
'accounting')) {
207 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
217$form =
new Form($db);
221if ($modecompta ==
"BOOKKEEPING") {
222 $modecompta =
"CREANCES-DETTES";
224if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
225 $modecompta =
"RECETTES-DEPENSES";
229if ($modecompta ==
"CREANCES-DETTES") {
230 $name = $langs->trans(
"PurchaseTurnover").
', '.$langs->trans(
"ByProductsAndServices");
231 $calcmode = $langs->trans(
"CalcModeDebt");
234 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
235} elseif ($modecompta ==
"RECETTES-DEPENSES") {
236 $name = $langs->trans(
"PurchaseTurnoverCollected").
', '.$langs->trans(
"ByProductsAndServices");
237 $calcmode = $langs->trans(
"CalcModePayment");
239 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
240} elseif ($modecompta ==
"BOOKKEEPING") {
242} elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
247$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
249$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
251 $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>';
258report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $tableparams, $calcmode);
260if (isModEnabled(
'accounting')) {
261 if ($modecompta !=
'BOOKKEEPING') {
262 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
266 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
267 if (empty($pcgvercode)) {
268 $pcgvercode = $pcgverid;
271 $sql =
"SELECT b.rowid ";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
273 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
274 $sql .=
" WHERE b.entity = ".$conf->entity;
275 $sql .=
" AND b.numero_compte = aa.account_number";
276 $sql .=
" AND aa.entity = ".$conf->entity;
277 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
278 $sql .= $db->plimit(1);
280 $resql = $db->query($sql);
281 $nb = $db->num_rows($resql);
283 $langs->load(
"errors");
284 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0, 1);
301if ($modecompta ==
'CREANCES-DETTES') {
302 $sql =
"SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
303 $sql .=
" SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
304 $sql .=
" SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
306 if ($selected_soc > 0) {
307 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as soc ON (soc.rowid = f.fk_soc)";
309 $sql .=
",".MAIN_DB_PREFIX.
"facture_fourn_det as l";
310 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON l.fk_product = p.rowid";
311 if ($selected_cat === -2) {
312 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON p.rowid = cp.fk_product";
313 } elseif ($selected_cat) {
314 $sql .=
", ".MAIN_DB_PREFIX.
"categorie as c, ".MAIN_DB_PREFIX.
"categorie_product as cp";
316 $sql .=
" WHERE l.fk_facture_fourn = f.rowid";
317 $sql .=
" AND f.fk_statut in (1,2)";
318 $sql .=
" AND f.type IN (0,2)";
320 if ($date_start && $date_end) {
321 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
323 if ($selected_type >= 0) {
324 $sql .=
" AND l.product_type = ".((int) $selected_type);
326 if ($selected_cat === -2) {
327 $sql .=
" AND cp.fk_product is null";
328 } elseif ($selected_cat) {
329 $sql .=
" AND (c.rowid = ".((int) $selected_cat);
331 $sql .=
" OR c.fk_parent = ".((int) $selected_cat);
334 $sql .=
" AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
336 if ($selected_soc > 0) {
337 $sql .=
" AND soc.rowid=".((int) $selected_soc);
339 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
340 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
341 $sql .= $db->order($sortfield, $sortorder);
343 dol_syslog(
"supplier_turnover_by_prodserv", LOG_DEBUG);
344 $resql = $db->query($sql);
346 $num = $db->num_rows($resql);
349 $obj = $db->fetch_object($resql);
351 $amount_ht[$obj->rowid] = $obj->amount;
352 $amount[$obj->rowid] = $obj->amount_ttc;
353 $qty[$obj->rowid] = $obj->qty;
354 $name[$obj->rowid] = $obj->ref.
' - '.$obj->label;
355 $type[$obj->rowid] = $obj->product_type;
357 $catotal_ht += $obj->amount;
358 $catotal += $obj->amount_ttc;
359 $qtytotal += $obj->qty;
369 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
370 print
'<input type="hidden" name="token" value="'.newToken().
'">'.
"\n";
372 foreach ($headerparams as $key => $value) {
373 print
'<input type="hidden" name="'.$key.
'" value="'.$value.
'">';
378 print
'<div class="div-table-responsive">';
379 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
382 print
'<tr class="liste_titre">';
384 print
img_picto(
'',
'category',
'class="paddingrightonly"');
385 print $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat,
'search_categ', 0, $langs->trans(
"Category"),
'maxwidth300');
387 print
'<label for="subcat" class="marginleftonly">'.$langs->trans(
"SubCats").
'?</label> ';
388 print
'<input type="checkbox" id="subcat" name="subcat" value="yes"';
395 $form->select_type_of_lines(isset($selected_type) ? $selected_type : -1,
'search_type', $langs->trans(
"Type"), 1, 1);
399 print
img_picto(
'',
'company',
'class="paddingrightonly"');
400 print $form->select_thirdparty_list($selected_soc,
'search_soc',
'', $langs->trans(
"ThirdParty"), 0, 0, [],
'', 0, 0,
'maxwidth250');
403 print
'<td colspan="5" class="right">';
404 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")).
'">';
408 print
'<tr class="liste_titre">';
410 $langs->trans(
"Product"),
411 $_SERVER[
"PHP_SELF"],
420 $langs->trans(
'Quantity'),
421 $_SERVER[
"PHP_SELF"],
430 $langs->trans(
"Percentage"),
431 $_SERVER[
"PHP_SELF"],
440 $langs->trans(
'AmountHT'),
441 $_SERVER[
"PHP_SELF"],
450 $langs->trans(
"AmountTTC"),
451 $_SERVER[
"PHP_SELF"],
460 $langs->trans(
"Percentage"),
461 $_SERVER[
"PHP_SELF"],
472 foreach ($name as $key => $value) {
473 print
'<tr class="oddeven">';
477 $fullname = $name[$key];
479 $linkname =
'<a href="'.DOL_URL_ROOT.
'/product/card.php?id='.$key.
'">'.
img_object($langs->trans(
"ShowProduct"), $type[$key] == 0 ?
'product' :
'service').
' '.$fullname.
'</a>';
481 $linkname = $langs->trans(
"PaymentsNotLinkedToProduct");
487 print
'<td class="right">';
492 print
'<td class="right">'.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).
'%' :
' ').
'</td>';
495 print
'<td class="right">';
496 print
price($amount_ht[$key]);
500 print
'<td class="right">';
501 print
price($amount[$key]);
505 print
'<td class="right">'.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).
'%' :
' ').
'</td>';
514 print
'<tr class="liste_total">';
515 print
'<td>'.$langs->trans(
"Total").
'</td>';
516 print
'<td class="right">'.$qtytotal.
'</td>';
517 print
'<td class="right">100%</td>';
518 print
'<td class="right">'.price($catotal_ht).
'</td>';
519 print
'<td class="right">'.price($catotal).
'</td>';
520 print
'<td class="right">100%</td>';
525 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
536 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.
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 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.