24 require
'../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
26 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 $langs->loadLangs(array(
'compta',
'bills'));
31 $date_startday =
GETPOST(
'date_startday',
'int');
32 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
33 $date_startyear =
GETPOST(
'date_startyear',
'int');
34 $date_endday =
GETPOST(
'date_endday',
'int');
35 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
36 $date_endyear =
GETPOST(
'date_endyear',
'int');
45 $year_start = $year_current - ($nbofyear - 1);
47 $year_current = $year;
49 $year_start = $year - ($nbofyear - 1);
51 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
52 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
55 if (empty($date_start) || empty($date_end)) {
59 $year_end = $year_start + ($nbofyear - 1);
60 $month_start =
GETPOSTISSET(
"month") ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
62 if (!
GETPOST(
"year") && $month_start > $month_current) {
66 $month_end = $month_start - 1;
73 $month_end = $month_start;
96 $userid =
GETPOST(
'userid',
'int');
97 $socid =
GETPOST(
'socid',
'int');
100 $year_start = $tmps[
'year'];
102 $year_end = $tmpe[
'year'];
103 $nbofyear = ($year_end - $year_start) + 1;
106 $modecompta = $conf->global->ACCOUNTING_MODE;
108 $modecompta =
'BOOKKEEPING';
111 $modecompta =
GETPOST(
"modecompta",
'alpha');
115 if ($user->socid > 0) {
116 $socid = $user->socid;
122 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
135 if ($modecompta ==
"BOOKKEEPING") {
136 $modecompta =
"CREANCES-DETTES";
138 if ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
139 $modecompta =
"RECETTES-DEPENSES";
143 if ($modecompta ==
"CREANCES-DETTES") {
144 $name = $langs->trans(
"PurchaseTurnover");
145 $calcmode = $langs->trans(
"CalcModeDebt");
147 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{link1}',
'{link2}').
')';
148 $calcmode = str_replace(
'{link1}',
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=BOOKKEEPING">', $calcmode);
149 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
151 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
152 $description = $langs->trans(
"RulesPurchaseTurnoverDue");
154 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
155 $name = $langs->trans(
"PurchaseTurnoverCollected");
156 $calcmode = $langs->trans(
"CalcModeEngagement");
157 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
158 $description = $langs->trans(
"RulesPurchaseTurnoverIn");
160 } elseif ($modecompta ==
"BOOKKEEPING") {
161 $name = $langs->trans(
"PurchaseTurnover");
162 $calcmode = $langs->trans(
"CalcModeBookkeeping");
163 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{link1}',
'{link2}').
')';
164 $calcmode = str_replace(
'{link1}',
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=CREANCES-DETTES">', $calcmode);
165 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
166 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
167 $description = $langs->trans(
"RulesPurchaseTurnoverOfExpenseAccounts");
169 } elseif ($modecompta ==
"BOOKKEEPINGCOLLECTED") {
170 $name = $langs->trans(
"PurchaseTurnoverCollected");
171 $calcmode = $langs->trans(
"CalcModeBookkeeping");
172 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{link1}',
'{link2}').
')';
173 $calcmode = str_replace(
'{link1}',
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=RECETTES-DEPENSES">', $calcmode);
174 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
175 $periodlink = ($year_start ?
"<a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear - 2).
"&modecompta=".$modecompta.
"'>".
img_previous().
"</a> <a href='".$_SERVER[
"PHP_SELF"].
"?year=".($year_start + $nbofyear).
"&modecompta=".$modecompta.
"'>".
img_next().
"</a>" :
"");
176 $description = $langs->trans(
"RulesPurchaseTurnoverCollectedOfExpenseAccounts");
181 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
183 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
185 $moreparam = array();
186 if (!empty($modecompta)) {
187 $moreparam[
'modecompta'] = $modecompta;
192 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
194 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
195 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
199 if ($modecompta ==
'CREANCES-DETTES') {
200 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
202 $sql .=
" WHERE f.fk_statut in (1,2)";
203 $sql .=
" AND f.type IN (0,2)";
204 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
206 $sql .=
" AND f.fk_soc = ".((int) $socid);
208 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
209 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
210 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
211 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
212 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn as p";
213 $sql .=
" WHERE p.rowid = pf.fk_paiementfourn";
214 $sql .=
" AND pf.fk_facturefourn = f.rowid";
215 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
217 $sql .=
" AND f.fk_soc = ".((int) $socid);
219 } elseif ($modecompta ==
"BOOKKEEPING") {
220 $pcgverid = $conf->global->CHARTOFACCOUNTS;
221 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
222 if (empty($pcgvercode)) {
223 $pcgvercode = $pcgverid;
226 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit - b.credit) as amount_ttc";
227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
228 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
229 $sql .=
" WHERE b.entity = ".$conf->entity;
230 $sql .=
" AND b.doc_type = 'supplier_invoice'";
231 $sql .=
" AND b.numero_compte = aa.account_number";
232 $sql .=
" AND aa.entity = ".$conf->entity;
233 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
234 $sql .=
" AND aa.pcg_type = 'EXPENSE'";
238 $sql .=
" GROUP BY dm";
239 $sql .=
" ORDER BY dm";
243 $minyearmonth = $maxyearmonth = 0;
245 $result = $db->query($sql);
247 $num = $db->num_rows($result);
250 $obj = $db->fetch_object($result);
251 $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
252 $cum[$obj->dm] = $obj->amount_ttc;
253 if ($obj->amount_ttc) {
254 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
255 $maxyearmonth = max($maxyearmonth, $obj->dm);
266 print
'<div class="div-table-responsive">';
267 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
269 print
'<tr class="liste_titre"><td> </td>';
271 for ($annee = $year_start; $annee <= $year_end; $annee++) {
272 if ($modecompta ==
'CREANCES-DETTES') {
273 print
'<td align="center" width="10%" colspan="3">';
275 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
277 if ($modecompta !=
'BOOKKEEPING') {
278 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
281 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
282 print
'-'.($annee + 1);
284 if ($modecompta !=
'BOOKKEEPING') {
288 if ($annee != $year_end) {
289 print
'<td width="15"> </td>';
294 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
295 for ($annee = $year_start; $annee <= $year_end; $annee++) {
296 if ($modecompta ==
'CREANCES-DETTES') {
297 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
299 print
'<td class="liste_titre right">';
300 if ($modecompta ==
"BOOKKEEPING") {
301 print $langs->trans(
"Amount");
303 print $langs->trans(
"AmountTTC");
306 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
307 if ($annee != $year_end) {
308 print
'<td class="liste_titre" width="15"> </td>';
314 $minyear = substr($minyearmonth, 0, 4);
315 $maxyear = substr($maxyearmonth, 0, 4);
317 $nowyearmonth = strftime(
"%Y-%m",
dol_now());
318 $maxyearmonth = max($maxyearmonth, $nowyearmonth);
323 $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
324 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
325 $mois_modulo = $mois;
327 $mois_modulo = $mois - 12;
330 if ($year_start == $year_end) {
331 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
336 print
'<tr class="oddeven">';
339 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
341 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
342 $annee_decalage = $annee;
344 $annee_decalage = $annee + 1;
349 if ($annee >= $year_start) {
350 if ($modecompta ==
'CREANCES-DETTES') {
352 print
'<td class="right">';
353 if (!empty($cum_ht[$case])) {
355 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cum_ht[$case], 1).
'</a>';
357 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
367 print
'<td class="right">';
368 if (!empty($cum[$case])) {
370 if ($modecompta !=
'BOOKKEEPING') {
371 print
'<a href="supplier_turnover_by_thirdparty.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
373 print
price($cum[$case], 1);
374 if ($modecompta !=
'BOOKKEEPING') {
378 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
387 if ($annee_decalage > $minyear && $case <= $casenow) {
388 if (!empty($cum[$caseprev]) && !empty($cum[$case])) {
389 $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
391 print
'<td class="borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
393 if (!empty($cum[$caseprev]) && empty($cum[$case])) {
394 print
'<td class="borderrightlight right">-100%</td>';
396 if (empty($cum[$caseprev]) && !empty($cum[$case])) {
398 print
'<td class="borderrightlight right">-</td>';
400 if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
401 print
'<td class="borderrightlight right">+0%</td>';
403 if (!isset($cum[$caseprev]) && empty($cum[$case])) {
404 print
'<td class="borderrightlight right">-</td>';
407 print
'<td class="borderrightlight right">';
408 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
416 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
417 print
'<td width="15"> </td>';
421 if (empty($total_ht[$annee])) {
422 $total_ht[$annee] = ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
424 $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
426 if (empty($total[$annee])) {
427 $total[$annee] = (empty($cum[$case]) ? 0 : $cum[$case]);
429 $total[$annee] += (empty($cum[$case]) ? 0 : $cum[$case]);
437 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
438 for ($annee = $year_start; $annee <= $year_end; $annee++) {
439 if ($modecompta ==
'CREANCES-DETTES') {
441 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
442 print
'<td class="nowrap right">'.($total_ht[$annee] ?
price($total_ht[$annee]) :
"0").
"</td>";
444 print
'<td> </td>';
449 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
450 print
'<td class="nowrap right">'.($total[$annee] ?
price($total[$annee]) :
"0").
"</td>";
452 print
'<td> </td>';
456 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
457 if ($total[$annee - 1] && $total[$annee]) {
458 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
459 print
'<td class="nowrap borderrightlight right">'.($percent >= 0 ?
"+$percent" :
"$percent").
'%</td>';
461 if ($total[$annee - 1] && !$total[$annee]) {
462 print
'<td class="borderrightlight right">-100%</td>';
464 if (!$total[$annee - 1] && $total[$annee]) {
465 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
467 if (!$total[$annee - 1] && !$total[$annee]) {
468 print
'<td class="borderrightlight right">+0%</td>';
471 print
'<td class="borderrightlight right">';
472 if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
480 if ($annee != $year_end) {
481 print
'<td width="15"> </td>';
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
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_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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
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.