27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
34 $date_startday =
GETPOST(
'date_startday',
'int');
35 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
36 $date_startyear =
GETPOST(
'date_startyear',
'int');
37 $date_endday =
GETPOST(
'date_endday',
'int');
38 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
39 $date_endyear =
GETPOST(
'date_endyear',
'int');
49 $year_start = $year_current - ($nbofyear - 1);
51 $year_current = $year;
53 $year_start = $year - ($nbofyear - 1);
55 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
56 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
59 if (empty($date_start) || empty($date_end))
65 $year_end = $year_start + ($nbofyear - 1);
66 $month_start =
GETPOSTISSET(
"month") ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
69 if (!
GETPOST(
"year") && $month_start > $month_current)
74 $month_end = $month_start - 1;
75 if ($month_end < 1) $month_end = 12;
76 }
else $month_end = $month_start;
85 $userid =
GETPOST(
'userid',
'int');
86 $socid =
GETPOST(
'socid',
'int');
89 $mothn_start = $tmps[
'mon'];
90 $year_start = $tmps[
'year'];
92 $month_end = $tmpe[
'mon'];
93 $year_end = $tmpe[
'year'];
94 $nbofyear = ($year_end - $year_start) + 1;
97 $modecompta = $conf->global->ACCOUNTING_MODE;
98 if (!empty($conf->accounting->enabled)) $modecompta =
'BOOKKEEPING';
99 if (
GETPOST(
"modecompta")) $modecompta =
GETPOST(
"modecompta",
'alpha');
102 if ($user->socid > 0) $socid = $user->socid;
103 if (!empty($conf->comptabilite->enabled)) $result =
restrictedArea($user,
'compta',
'',
'',
'resultat');
104 if (!empty($conf->accounting->enabled)) $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
114 if ($date_startday && $date_startmonth && $date_startyear) $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
115 if ($date_endday && $date_endmonth && $date_endyear) $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
119 $form =
new Form($db);
122 if ($modecompta ==
"CREANCES-DETTES")
124 $name = $langs->trans(
"Turnover");
125 $calcmode = $langs->trans(
"CalcModeDebt");
127 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{link1}',
'{link2}').
')';
128 $calcmode = str_replace(
'{link1}',
'<a class="bold" href="'.
$_SERVER[
"PHP_SELF"].
'?'.($param ? $param :
'year_start='.$year_start).
'&modecompta=BOOKKEEPING">', $calcmode);
129 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
130 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
131 $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>" :
"");
132 $description = $langs->trans(
"RulesCADue");
133 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description .= $langs->trans(
"DepositsAreNotIncluded");
134 else $description .= $langs->trans(
"DepositsAreIncluded");
137 } elseif ($modecompta ==
"RECETTES-DEPENSES")
139 $name = $langs->trans(
"TurnoverCollected");
140 $calcmode = $langs->trans(
"CalcModeEngagement");
143 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
144 $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>" :
"");
145 $description = $langs->trans(
"RulesCAIn");
146 $description .= $langs->trans(
"DepositsAreIncluded");
149 } elseif ($modecompta ==
"BOOKKEEPING")
151 $name = $langs->trans(
"Turnover");
152 $calcmode = $langs->trans(
"CalcModeBookkeeping");
153 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{link1}',
'{link2}').
')';
154 $calcmode = str_replace(
'{link1}',
'<a class="bold" href="'.
$_SERVER[
"PHP_SELF"].
'?'.($param ? $param :
'year_start='.$year_start).
'&modecompta=CREANCES-DETTES">', $calcmode);
155 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
157 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
158 $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>" :
"");
159 $description = $langs->trans(
"RulesCATotalSaleJournal");
164 $moreparam = array();
165 if (!empty($modecompta)) $moreparam[
'modecompta'] = $modecompta;
166 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
168 if (!empty($conf->accounting->enabled) && $modecompta !=
'BOOKKEEPING')
174 if ($modecompta ==
'CREANCES-DETTES')
176 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc";
177 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
178 $sql .=
" WHERE f.fk_statut in (1,2)";
179 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .=
" AND f.type IN (0,1,2,5)";
180 else $sql .=
" AND f.type IN (0,1,2,3,5)";
181 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
182 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
183 } elseif ($modecompta ==
"RECETTES-DEPENSES")
189 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc";
190 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
191 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
192 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
193 $sql .=
" WHERE p.rowid = pf.fk_paiement";
194 $sql .=
" AND pf.fk_facture = f.rowid";
195 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
196 if ($socid) $sql .=
" AND f.fk_soc = ".$socid;
197 } elseif ($modecompta ==
"BOOKKEEPING")
199 $sql =
"SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.credit) as amount_ttc";
200 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_journal as aj";
201 $sql .=
" WHERE b.entity = ".$conf->entity;
202 $sql .=
" AND aj.entity = ".$conf->entity;
203 $sql .=
" AND b.code_journal = aj.code AND aj.nature = 2";
206 $sql .=
" GROUP BY dm";
207 $sql .=
" ORDER BY dm";
211 $minyearmonth = $maxyearmonth = 0;
213 $result = $db->query($sql);
216 $num = $db->num_rows($result);
220 $obj = $db->fetch_object($result);
221 $cum_ht[$obj->dm] = !empty($obj->amount) ? $obj->amount : 0;
222 $cum[$obj->dm] = $obj->amount_ttc;
223 if ($obj->amount_ttc)
225 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
226 $maxyearmonth = max($maxyearmonth, $obj->dm);
236 if ($modecompta ==
'RECETTES-DEPENSES')
238 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
239 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
240 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
241 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
242 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
243 $sql .=
" WHERE pf.rowid IS NULL";
244 $sql .=
" AND p.fk_bank = b.rowid";
245 $sql .=
" AND b.fk_account = ba.rowid";
246 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
247 $sql .=
" GROUP BY dm";
248 $sql .=
" ORDER BY dm";
250 $result = $db->query($sql);
253 $num = $db->num_rows($result);
257 $obj = $db->fetch_object($result);
258 $cum[$obj->dm] += $obj->amount_ttc;
259 if ($obj->amount_ttc)
261 $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm);
262 $maxyearmonth = max($maxyearmonth, $obj->dm);
273 print '<div class="div-table-responsive">';
274 print '<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
276 print '<tr class="liste_titre"><td> </td>';
278 for ($annee = $year_start; $annee <= $year_end; $annee++)
280 if ($modecompta ==
'CREANCES-DETTES') print
'<td align="center" width="10%" colspan="3">';
281 else print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
282 if ($modecompta !=
'BOOKKEEPING') print
'<a href="casoc.php?year='.$annee.
'">';
284 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) print
'-'.($annee + 1);
285 if ($modecompta !=
'BOOKKEEPING') print
'</a>';
287 if ($annee != $year_end) print
'<td width="15"> </td>';
291 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
292 for ($annee = $year_start; $annee <= $year_end; $annee++)
294 if ($modecompta ==
'CREANCES-DETTES') print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
295 print
'<td class="liste_titre right">'.$langs->trans(
"AmountTTC").
'</td>';
296 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
297 if ($annee != $year_end) print
'<td class="liste_titre" width="15"> </td>';
302 $minyear = substr($minyearmonth, 0, 4);
303 $maxyear = substr($maxyearmonth, 0, 4);
304 $nowyear = strftime(
"%Y",
dol_now());
305 $nowyearmonth = strftime(
"%Y-%m",
dol_now());
306 $maxyearmonth = max($maxyearmonth, $nowyearmonth);
311 $nb_mois_decalage =
GETPOSTISSET(
'date_startmonth') ? (
GETPOST(
'date_startmonth',
'int') - 1) : (empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1));
312 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++)
314 $mois_modulo = $mois;
315 if ($mois > 12) {$mois_modulo = $mois - 12; }
317 if ($year_start == $year_end) {
319 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
323 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
328 print
'<tr class="oddeven">';
331 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
333 for ($annee = $year_start - 1; $annee <= $year_end; $annee++)
335 $annee_decalage = $annee;
336 if ($mois > 12) {$annee_decalage = $annee + 1; }
340 if ($annee >= $year_start)
342 if ($modecompta ==
'CREANCES-DETTES') {
344 print
'<td class="right">';
345 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
346 if ($cum_ht[$case]) {
348 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cum_ht[$case], 1).
'</a>';
350 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print
'0'; }
else { print
' '; }
357 print
'<td class="right">';
358 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
361 if ($modecompta !=
'BOOKKEEPING') print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
362 print
price($cum[$case], 1);
363 if ($modecompta !=
'BOOKKEEPING') print
'</a>';
365 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) { print
'0'; }
else { print
' '; }
371 print
'<td class="borderrightlight right">';
373 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
374 if ($annee_decalage > $minyear && $case <= $casenow)
376 if ($cum[$caseprev] && $cum[$case])
378 $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
380 print ($percent >= 0 ?
"+$percent" :
"$percent").
'%';
382 if ($cum[$caseprev] && !$cum[$case])
386 if (!$cum[$caseprev] && $cum[$case])
391 if (isset($cum[$caseprev]) && !$cum[$caseprev] && !$cum[$case])
395 if (!isset($cum[$caseprev]) && !$cum[$case])
400 if ($minyearmonth <= $case && $case <= $maxyearmonth) { print
'-'; }
else { print
' '; }
405 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) print
'<td width="15"> </td>';
408 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
409 $total_ht[$annee] += ((!empty($cum_ht[$case])) ? $cum_ht[$case] : 0);
410 $total[$annee] += $cum[$case];
483 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
484 for ($annee = $year_start; $annee <= $year_end; $annee++)
486 if ($modecompta ==
'CREANCES-DETTES') {
488 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
489 print
'<td class="nowrap right">';
490 print ($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
493 print
'<td> </td>';
498 if ($total[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
499 print
'<td class="nowrap right">';
500 print ($total[$annee] ?
price($total[$annee]) :
"0");
503 print
'<td> </td>';
507 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
508 if ($total[$annee - 1] && $total[$annee]) {
509 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
510 print
'<td class="nowrap borderrightlight right">';
511 print ($percent >= 0 ?
"+$percent" :
"$percent").
'%';
514 if ($total[$annee - 1] && !$total[$annee])
516 print
'<td class="borderrightlight right">-100%</td>';
518 if (!$total[$annee - 1] && $total[$annee])
520 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
522 if (!$total[$annee - 1] && !$total[$annee])
524 print
'<td class="borderrightlight right">+0%</td>';
527 print
'<td class="borderrightlight right">';
528 if ($total[$annee] || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) { print
'-'; }
else { print
' '; }
532 if ($annee != $year_end) print
'<td width="15"> </td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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_now($mode= 'auto')
Return date for now.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.