29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
34$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
37$date_startmonth =
GETPOSTINT(
'date_startmonth');
50 $year_start = $year_current - ($nbofyear - 1);
52 $year_current = $year;
54 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
56$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
57$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
60if (empty($date_start) || empty($date_end)) {
64 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
67 if (!$year && $month_start > $month_current) {
71 $month_end = $month_start - 1;
76 $month_end = $month_start;
103$month_start = $tmps[
'mon'];
104$year_start = $tmps[
'year'];
106$month_end = $tmpe[
'mon'];
107$year_end = $tmpe[
'year'];
108$nbofyear = ($year_end - $year_start) + 1;
112if (isModEnabled(
'accounting')) {
113 $modecompta =
'BOOKKEEPING';
115if (
GETPOST(
"modecompta",
'alpha')) {
116 $modecompta =
GETPOST(
"modecompta",
'alpha');
120if ($user->socid > 0) {
121 $socid = $user->socid;
123if (isModEnabled(
'comptabilite')) {
126if (isModEnabled(
'accounting')) {
127 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
138if ($date_startday && $date_startmonth && $date_startyear) {
139 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
141if ($date_endday && $date_endmonth && $date_endyear) {
142 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
147$form =
new Form($db);
154if ($modecompta ==
"CREANCES-DETTES") {
155 $name = $langs->trans(
"Turnover");
156 $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>" :
"");
157 $description = $langs->trans(
"RulesCADue");
159 $description .= $langs->trans(
"DepositsAreNotIncluded");
161 $description .= $langs->trans(
"DepositsAreIncluded");
164} elseif ($modecompta ==
"RECETTES-DEPENSES") {
165 $name = $langs->trans(
"TurnoverCollected");
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(
"RulesCAIn");
168 $description .= $langs->trans(
"DepositsAreIncluded");
170} elseif ($modecompta ==
"BOOKKEEPING") {
171 $name = $langs->trans(
"Turnover");
172 $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>" :
"");
173 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
176$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
178$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
181if (!empty($modecompta)) {
182 $moreparam[
'modecompta'] = $modecompta;
187if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
192 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
193 if (isModEnabled(
'accounting')) {
194 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
196 $calcmode .=
'</label>';
198 if (isModEnabled(
'accounting')) {
199 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
200 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
203 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
204 if (isModEnabled(
'accounting')) {
205 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
207 $calcmode .=
'</label>';
210report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
212if (isModEnabled(
'accounting')) {
213 if ($modecompta !=
'BOOKKEEPING') {
214 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
218 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
219 if (empty($pcgvercode)) {
220 $pcgvercode = $pcgverid;
223 $sql =
"SELECT b.rowid ";
224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
225 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
226 $sql .=
" WHERE b.entity = ".$conf->entity;
227 $sql .=
" AND b.numero_compte = aa.account_number";
228 $sql .=
" AND aa.entity = ".$conf->entity;
229 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
230 $sql .= $db->plimit(1);
232 $resql = $db->query($sql);
233 $nb = $db->num_rows($resql);
235 $langs->load(
"errors");
236 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0, 1);
242if ($modecompta ==
'CREANCES-DETTES') {
243 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
244 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
245 $sql .=
" WHERE f.fk_statut in (1,2)";
247 $sql .=
" AND f.type IN (0,1,2,5)";
249 $sql .=
" AND f.type IN (0,1,2,3,5)";
251 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
253 $sql .=
" AND f.fk_soc = ".((int) $socid);
255} elseif ($modecompta ==
"RECETTES-DEPENSES") {
260 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
261 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
262 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
263 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
264 $sql .=
" WHERE p.rowid = pf.fk_paiement";
265 $sql .=
" AND pf.fk_facture = f.rowid";
266 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
268 $sql .=
" AND f.fk_soc = ".((int) $socid);
270} elseif ($modecompta ==
"BOOKKEEPING") {
272 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
273 if (empty($pcgvercode)) {
274 $pcgvercode = $pcgverid;
277 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
278 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
279 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
280 $sql .=
" WHERE b.entity = ".$conf->entity;
281 $sql .=
" AND b.numero_compte = aa.account_number";
282 $sql .=
" AND b.doc_type = 'customer_invoice'";
283 $sql .=
" AND aa.entity = ".$conf->entity;
284 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
285 $sql .=
" AND aa.pcg_type = 'INCOME'";
287$sql .=
" GROUP BY dm";
288$sql .=
" ORDER BY dm";
292$minyearmonth = $maxyearmonth = 0;
294$cumulative = array();
295$cumulative_ht = array();
299$result = $db->query($sql);
301 $num = $db->num_rows($result);
304 $obj = $db->fetch_object($result);
305 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
306 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
307 if ($obj->amount_ttc) {
308 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
309 $maxyearmonth = max($maxyearmonth, $obj->dm);
319if ($modecompta ==
'RECETTES-DEPENSES') {
320 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
322 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
323 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
324 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
325 $sql .=
" WHERE pf.rowid IS NULL";
326 $sql .=
" AND p.fk_bank = b.rowid";
327 $sql .=
" AND b.fk_account = ba.rowid";
328 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
329 $sql .=
" GROUP BY dm";
330 $sql .=
" ORDER BY dm";
332 $result = $db->query($sql);
334 $num = $db->num_rows($result);
337 $obj = $db->fetch_object($result);
338 if (empty($cumulative[$obj->dm])) {
339 $cumulative[$obj->dm] = $obj->amount_ttc;
341 $cumulative[$obj->dm] += $obj->amount_ttc;
343 if ($obj->amount_ttc) {
344 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
345 $maxyearmonth = max($maxyearmonth, $obj->dm);
356print
'<div class="div-table-responsive">';
357print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
359print
'<tr class="liste_titre"><td> </td>';
361for ($annee = $year_start; $annee <= $year_end; $annee++) {
362 if ($modecompta ==
'CREANCES-DETTES') {
363 print
'<td align="center" width="10%" colspan="3">';
365 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
367 if ($modecompta !=
'BOOKKEEPING') {
368 print
'<a href="casoc.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
372 print
'-'.($annee + 1);
374 if ($modecompta !=
'BOOKKEEPING') {
378 if ($annee != $year_end) {
379 print
'<td width="15"> </td>';
384print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
385for ($annee = $year_start; $annee <= $year_end; $annee++) {
386 if ($modecompta ==
'CREANCES-DETTES') {
387 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
389 print
'<td class="liste_titre right">';
390 if ($modecompta ==
"BOOKKEEPING") {
391 print $langs->trans(
"Amount");
393 print $langs->trans(
"AmountTTC");
396 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
397 if ($annee != $year_end) {
398 print
'<td class="liste_titre" width="15"> </td>';
404$minyear = substr($minyearmonth, 0, 4);
405$maxyear = substr($maxyearmonth, 0, 4);
408$maxyearmonth = max($maxyearmonth, $nowyearmonth);
413$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
414for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
415 $mois_modulo = $mois;
417 $mois_modulo = $mois - 12;
420 if ($year_start == $year_end) {
422 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
426 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
431 print
'<tr class="oddeven">';
434 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
436 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
437 $annee_decalage = $annee;
439 $annee_decalage = $annee + 1;
444 if ($annee >= $year_start) {
445 if ($modecompta ==
'CREANCES-DETTES') {
447 print
'<td class="right">';
448 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
449 if (!empty($cumulative_ht[$case])) {
451 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
453 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
464 print
'<td class="right">';
465 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
466 if (!empty($cumulative[$case])) {
468 if ($modecompta !=
'BOOKKEEPING') {
469 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
471 print
price($cumulative[$case], 1);
472 if ($modecompta !=
'BOOKKEEPING') {
476 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
486 print
'<td class="borderrightlight right"><span class="opacitymedium">';
488 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
489 if ($annee_decalage > $minyear && $case <= $casenow) {
490 if (!empty($cumulative_ht[$caseprev]) && !empty($cumulative_ht[$case])) {
491 $percent = (round(($cumulative_ht[$case] - $cumulative_ht[$caseprev]) / $cumulative_ht[$caseprev], 4) * 100);
493 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
495 if (!empty($cumulative_ht[$caseprev]) && empty($cumulative_ht[$case])) {
498 if (empty($cumulative_ht[$caseprev]) && !empty($cumulative_ht[$case])) {
502 if (isset($cumulative_ht[$caseprev]) && empty($cumulative_ht[$caseprev]) && empty($cumulative_ht[$case])) {
505 if (!isset($cumulative_ht[$caseprev]) && empty($cumulative_ht[$case])) {
509 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
516 print
'</span></td>';
518 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
519 print
'<td width="15"> </td>';
523 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
524 if (empty($total_ht[$annee])) {
525 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
527 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
529 if (empty($total[$annee])) {
530 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
532 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
606print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
607for ($annee = $year_start; $annee <= $year_end; $annee++) {
608 if ($modecompta ==
'CREANCES-DETTES') {
610 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
611 print
'<td class="nowrap right">';
612 print(empty($total_ht[$annee]) ?
'0' :
price($total_ht[$annee]));
615 print
'<td> </td>';
620 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
621 print
'<td class="nowrap right">';
622 print(empty($total[$annee]) ?
'0' :
price($total[$annee]));
625 print
'<td> </td>';
629 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
630 if (!empty($total_ht[$annee - 1]) && !empty($total_ht[$annee])) {
631 $percent = (round(($total_ht[$annee] - $total_ht[$annee - 1]) / $total_ht[$annee - 1], 4) * 100);
632 print
'<td class="nowrap borderrightlight right">';
633 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
636 if (!empty($total_ht[$annee - 1]) && empty($total_ht[$annee])) {
637 print
'<td class="borderrightlight right">-100%</td>';
639 if (empty($total_ht[$annee - 1]) && !empty($total_ht[$annee])) {
640 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
642 if (empty($total_ht[$annee - 1]) && empty($total_ht[$annee])) {
643 print
'<td class="borderrightlight right">+0%</td>';
646 print
'<td class="borderrightlight right">';
647 if (!empty($total_ht[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
655 if ($annee != $year_end) {
656 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 information (by default a local PHP server timestamp) Rep...
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).
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_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.