28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
35$date_startday =
GETPOST(
'date_startday',
'int');
36$date_startmonth =
GETPOST(
'date_startmonth',
'int');
37$date_startyear =
GETPOST(
'date_startyear',
'int');
38$date_endday =
GETPOST(
'date_endday',
'int');
39$date_endmonth =
GETPOST(
'date_endmonth',
'int');
40$date_endyear =
GETPOST(
'date_endyear',
'int');
49 $year_start = $year_current - ($nbofyear - 1);
51 $year_current = $year;
53 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
55$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
56$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
59if (empty($date_start) || empty($date_end)) {
63 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
64 $month_start = GETPOSTISSET(
"month") ?
GETPOST(
"month",
'int') :
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1);
66 if (!$year && $month_start > $month_current) {
70 $month_end = $month_start - 1;
75 $month_end = $month_start;
99$mothn_start = $tmps[
'mon'];
100$year_start = $tmps[
'year'];
102$month_end = $tmpe[
'mon'];
103$year_end = $tmpe[
'year'];
104$nbofyear = ($year_end - $year_start) + 1;
107$modecompta = $conf->global->ACCOUNTING_MODE;
108if (isModEnabled(
'accounting')) {
109 $modecompta =
'BOOKKEEPING';
111if (
GETPOST(
"modecompta",
'alpha')) {
112 $modecompta =
GETPOST(
"modecompta",
'alpha');
115$userid =
GETPOST(
'userid',
'int');
118$socid =
GETPOST(
'socid',
'int');
119if ($user->socid > 0) {
120 $socid = $user->socid;
122if (isModEnabled(
'comptabilite')) {
125if (isModEnabled(
'accounting')) {
126 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
137if ($date_startday && $date_startmonth && $date_startyear) {
138 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
140if ($date_endday && $date_endmonth && $date_endyear) {
141 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
146$form =
new Form($db);
153if ($modecompta ==
"CREANCES-DETTES") {
154 $name = $langs->trans(
"Turnover");
155 $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>" :
"");
156 $description = $langs->trans(
"RulesCADue");
158 $description .= $langs->trans(
"DepositsAreNotIncluded");
160 $description .= $langs->trans(
"DepositsAreIncluded");
163} elseif ($modecompta ==
"RECETTES-DEPENSES") {
164 $name = $langs->trans(
"TurnoverCollected");
165 $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>" :
"");
166 $description = $langs->trans(
"RulesCAIn");
167 $description .= $langs->trans(
"DepositsAreIncluded");
169} elseif ($modecompta ==
"BOOKKEEPING") {
170 $name = $langs->trans(
"Turnover");
171 $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>" :
"");
172 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
175$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
177$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
180if (!empty($modecompta)) {
181 $moreparam[
'modecompta'] = $modecompta;
186if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEINGCOLLECTED") {
191 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeEngagement");
192 if (isModEnabled(
'accounting')) {
193 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
195 $calcmode .=
'</label>';
197 if (isModEnabled(
'accounting')) {
198 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
201 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
202 if (isModEnabled(
'accounting')) {
203 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
205 $calcmode .=
'</label>';
208report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
210if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
211 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
215if ($modecompta ==
'CREANCES-DETTES') {
216 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
217 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
218 $sql .=
" WHERE f.fk_statut in (1,2)";
220 $sql .=
" AND f.type IN (0,1,2,5)";
222 $sql .=
" AND f.type IN (0,1,2,3,5)";
224 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
226 $sql .=
" AND f.fk_soc = ".((int) $socid);
228} elseif ($modecompta ==
"RECETTES-DEPENSES") {
233 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
235 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
236 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
237 $sql .=
" WHERE p.rowid = pf.fk_paiement";
238 $sql .=
" AND pf.fk_facture = f.rowid";
239 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
241 $sql .=
" AND f.fk_soc = ".((int) $socid);
243} elseif ($modecompta ==
"BOOKKEEPING") {
245 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
246 if (empty($pcgvercode)) {
247 $pcgvercode = $pcgverid;
250 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
252 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
253 $sql .=
" WHERE b.entity = ".$conf->entity;
254 $sql .=
" AND b.numero_compte = aa.account_number";
255 $sql .=
" AND b.doc_type = 'customer_invoice'";
256 $sql .=
" AND aa.entity = ".$conf->entity;
257 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
258 $sql .=
" AND aa.pcg_type = 'INCOME'";
260$sql .=
" GROUP BY dm";
261$sql .=
" ORDER BY dm";
265$minyearmonth = $maxyearmonth = 0;
272$result = $db->query($sql);
274 $num = $db->num_rows($result);
277 $obj = $db->fetch_object($result);
278 $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
279 $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
280 if ($obj->amount_ttc) {
281 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
282 $maxyearmonth = max($maxyearmonth, $obj->dm);
292if ($modecompta ==
'RECETTES-DEPENSES') {
293 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
294 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
295 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
296 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
297 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
298 $sql .=
" WHERE pf.rowid IS NULL";
299 $sql .=
" AND p.fk_bank = b.rowid";
300 $sql .=
" AND b.fk_account = ba.rowid";
301 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
302 $sql .=
" GROUP BY dm";
303 $sql .=
" ORDER BY dm";
305 $result = $db->query($sql);
307 $num = $db->num_rows($result);
310 $obj = $db->fetch_object($result);
311 if (empty($cum[$obj->dm])) {
312 $cum[$obj->dm] = $obj->amount_ttc;
314 $cum[$obj->dm] += $obj->amount_ttc;
316 if ($obj->amount_ttc) {
317 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
318 $maxyearmonth = max($maxyearmonth, $obj->dm);
329print
'<div class="div-table-responsive">';
330print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
332print
'<tr class="liste_titre"><td> </td>';
334for ($annee = $year_start; $annee <= $year_end; $annee++) {
335 if ($modecompta ==
'CREANCES-DETTES') {
336 print
'<td align="center" width="10%" colspan="3">';
338 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
340 if ($modecompta !=
'BOOKKEEPING') {
341 print
'<a href="casoc.php?year='.$annee.
'">';
345 print
'-'.($annee + 1);
347 if ($modecompta !=
'BOOKKEEPING') {
351 if ($annee != $year_end) {
352 print
'<td width="15"> </td>';
357print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
358for ($annee = $year_start; $annee <= $year_end; $annee++) {
359 if ($modecompta ==
'CREANCES-DETTES') {
360 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
362 print
'<td class="liste_titre right">';
363 if ($modecompta ==
"BOOKKEEPING") {
364 print $langs->trans(
"Amount");
366 print $langs->trans(
"AmountTTC");
369 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
370 if ($annee != $year_end) {
371 print
'<td class="liste_titre" width="15"> </td>';
377$minyear = substr($minyearmonth, 0, 4);
378$maxyear = substr($maxyearmonth, 0, 4);
382$maxyearmonth = max($maxyearmonth, $nowyearmonth);
387$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOST(
'date_startmonth',
'int') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : ($conf->global->SOCIETE_FISCAL_MONTH_START - 1));
388for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
389 $mois_modulo = $mois;
391 $mois_modulo = $mois - 12;
394 if ($year_start == $year_end) {
396 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
400 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
405 print
'<tr class="oddeven">';
408 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
410 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
411 $annee_decalage = $annee;
413 $annee_decalage = $annee + 1;
418 if ($annee >= $year_start) {
419 if ($modecompta ==
'CREANCES-DETTES') {
421 print
'<td class="right">';
422 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
423 if (!empty($cum_ht[$case])) {
425 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cum_ht[$case], 1).
'</a>';
427 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
438 print
'<td class="right">';
439 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
440 if (!empty($cum[$case])) {
442 if ($modecompta !=
'BOOKKEEPING') {
443 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
445 print
price($cum[$case], 1);
446 if ($modecompta !=
'BOOKKEEPING') {
450 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
460 print
'<td class="borderrightlight right"><span class="opacitymedium">';
462 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
463 if ($annee_decalage > $minyear && $case <= $casenow) {
464 if (!empty($cum[$caseprev]) && !empty($cum[$case]) && $cum[$caseprev] != 0) {
465 $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
467 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
469 if (!empty($cum[$caseprev]) && empty($cum[$case])) {
472 if (empty($cum[$caseprev]) && !empty($cum[$case])) {
476 if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
479 if (!isset($cum[$caseprev]) && empty($cum[$case])) {
483 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
490 print
'</span></td>';
492 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
493 print
'<td width="15"> </td>';
497 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
498 if (empty($total_ht[$annee])) {
499 $total_ht[$annee] = (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
501 $total_ht[$annee] += (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
503 if (empty($total[$annee])) {
504 $total[$annee] = empty($cum[$case]) ? 0 : $cum[$case];
506 $total[$annee] += empty($cum[$case]) ? 0 : $cum[$case];
580print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
581for ($annee = $year_start; $annee <= $year_end; $annee++) {
582 if ($modecompta ==
'CREANCES-DETTES') {
584 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
585 print
'<td class="nowrap right">';
586 print(empty($total_ht[$annee]) ?
'0' :
price($total_ht[$annee]));
589 print
'<td> </td>';
594 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
595 print
'<td class="nowrap right">';
596 print(empty($total[$annee]) ?
'0' :
price($total[$annee]));
599 print
'<td> </td>';
603 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
604 if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
605 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
606 print
'<td class="nowrap borderrightlight right">';
607 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
610 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
611 print
'<td class="borderrightlight right">-100%</td>';
613 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
614 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
616 if (empty($total[$annee - 1]) && empty($total[$annee])) {
617 print
'<td class="borderrightlight right">+0%</td>';
620 print
'<td class="borderrightlight right">';
621 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
629 if ($annee != $year_end) {
630 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.
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.
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.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.