30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
35$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
38$date_startmonth =
GETPOSTINT(
'date_startmonth');
51 $year_start = $year_current - ($nbofyear - 1);
53 $year_current = $year;
55 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
57$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
58$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
61if (empty($date_start) || empty($date_end)) {
65 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
68 if (!$year && $month_start > $month_current) {
72 $month_end = $month_start - 1;
77 $month_end = $month_start;
104$month_start = $tmps[
'mon'];
105$year_start = $tmps[
'year'];
107$month_end = $tmpe[
'mon'];
108$year_end = $tmpe[
'year'];
109$nbofyear = ($year_end - $year_start) + 1;
113if (isModEnabled(
'accounting')) {
114 $modecompta =
'BOOKKEEPING';
116if (
GETPOST(
"modecompta",
'alpha')) {
117 $modecompta =
GETPOST(
"modecompta",
'alpha');
121if ($user->socid > 0) {
122 $socid = $user->socid;
124if (isModEnabled(
'comptabilite')) {
127if (isModEnabled(
'accounting')) {
128 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
139if ($date_startday && $date_startmonth && $date_startyear) {
140 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
142if ($date_endday && $date_endmonth && $date_endyear) {
143 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
148$form =
new Form($db);
155if ($modecompta ==
"CREANCES-DETTES") {
156 $name = $langs->trans(
"Turnover");
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(
"RulesCADue");
160 $description .= $langs->trans(
"DepositsAreNotIncluded");
162 $description .= $langs->trans(
"DepositsAreIncluded");
165} elseif ($modecompta ==
"RECETTES-DEPENSES") {
166 $name = $langs->trans(
"TurnoverCollected");
167 $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>" :
"");
168 $description = $langs->trans(
"RulesCAIn");
169 $description .= $langs->trans(
"DepositsAreIncluded");
171} elseif ($modecompta ==
"BOOKKEEPING") {
172 $name = $langs->trans(
"Turnover");
173 $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>" :
"");
174 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
177$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
179$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
182if (!empty($modecompta)) {
183 $moreparam[
'modecompta'] = $modecompta;
188if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
193 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
194 if (isModEnabled(
'accounting')) {
195 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
197 $calcmode .=
'</label>';
199 if (isModEnabled(
'accounting')) {
200 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
201 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
204 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
205 if (isModEnabled(
'accounting')) {
206 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
208 $calcmode .=
'</label>';
211report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
213if (isModEnabled(
'accounting')) {
214 if ($modecompta !=
'BOOKKEEPING') {
215 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
219 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
220 if (empty($pcgvercode)) {
221 $pcgvercode = $pcgverid;
224 $sql =
"SELECT b.rowid ";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
226 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
227 $sql .=
" WHERE b.entity = ".$conf->entity;
228 $sql .=
" AND b.numero_compte = aa.account_number";
229 $sql .=
" AND aa.entity = ".$conf->entity;
230 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
231 $sql .= $db->plimit(1);
233 $resql = $db->query($sql);
234 $nb = $db->num_rows($resql);
236 $langs->load(
"errors");
237 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
243if ($modecompta ==
'CREANCES-DETTES') {
244 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
246 $sql .=
" WHERE f.fk_statut in (1,2)";
248 $sql .=
" AND f.type IN (0,1,2,5)";
250 $sql .=
" AND f.type IN (0,1,2,3,5)";
252 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
254 $sql .=
" AND f.fk_soc = ".((int) $socid);
256} elseif ($modecompta ==
"RECETTES-DEPENSES") {
261 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
263 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
264 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
265 $sql .=
" WHERE p.rowid = pf.fk_paiement";
266 $sql .=
" AND pf.fk_facture = f.rowid";
267 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
269 $sql .=
" AND f.fk_soc = ".((int) $socid);
271} elseif ($modecompta ==
"BOOKKEEPING") {
273 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
274 if (empty($pcgvercode)) {
275 $pcgvercode = $pcgverid;
278 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
280 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
281 $sql .=
" WHERE b.entity = ".$conf->entity;
282 $sql .=
" AND b.numero_compte = aa.account_number";
283 $sql .=
" AND b.doc_type = 'customer_invoice'";
284 $sql .=
" AND aa.entity = ".$conf->entity;
285 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
286 $sql .=
" AND aa.pcg_type = 'INCOME'";
288$sql .=
" GROUP BY dm";
289$sql .=
" ORDER BY dm";
293$minyearmonth = $maxyearmonth = 0;
295$cumulative = array();
296$cumulative_ht = array();
300$result = $db->query($sql);
302 $num = $db->num_rows($result);
305 $obj = $db->fetch_object($result);
306 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
307 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
308 if ($obj->amount_ttc) {
309 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
310 $maxyearmonth = max($maxyearmonth, $obj->dm);
320if ($modecompta ==
'RECETTES-DEPENSES') {
321 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
322 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
323 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
324 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
325 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
326 $sql .=
" WHERE pf.rowid IS NULL";
327 $sql .=
" AND p.fk_bank = b.rowid";
328 $sql .=
" AND b.fk_account = ba.rowid";
329 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
330 $sql .=
" GROUP BY dm";
331 $sql .=
" ORDER BY dm";
333 $result = $db->query($sql);
335 $num = $db->num_rows($result);
338 $obj = $db->fetch_object($result);
339 if (empty($cumulative[$obj->dm])) {
340 $cumulative[$obj->dm] = $obj->amount_ttc;
342 $cumulative[$obj->dm] += $obj->amount_ttc;
344 if ($obj->amount_ttc) {
345 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
346 $maxyearmonth = max($maxyearmonth, $obj->dm);
357print
'<div class="div-table-responsive">';
358print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
360print
'<tr class="liste_titre"><td> </td>';
362for ($annee = $year_start; $annee <= $year_end; $annee++) {
363 if ($modecompta ==
'CREANCES-DETTES') {
364 print
'<td align="center" width="10%" colspan="3">';
366 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
368 if ($modecompta !=
'BOOKKEEPING') {
369 print
'<a href="casoc.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
373 print
'-'.($annee + 1);
375 if ($modecompta !=
'BOOKKEEPING') {
379 if ($annee != $year_end) {
380 print
'<td width="15"> </td>';
385print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
386for ($annee = $year_start; $annee <= $year_end; $annee++) {
387 if ($modecompta ==
'CREANCES-DETTES') {
388 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
390 print
'<td class="liste_titre right">';
391 if ($modecompta ==
"BOOKKEEPING") {
392 print $langs->trans(
"Amount");
394 print $langs->trans(
"AmountTTC");
397 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
398 if ($annee != $year_end) {
399 print
'<td class="liste_titre" width="15"> </td>';
405$minyear = substr($minyearmonth, 0, 4);
406$maxyear = substr($maxyearmonth, 0, 4);
409$maxyearmonth = max($maxyearmonth, $nowyearmonth);
414$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
415for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
416 $mois_modulo = $mois;
418 $mois_modulo = $mois - 12;
421 if ($year_start == $year_end) {
423 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
427 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
432 print
'<tr class="oddeven">';
435 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
437 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
438 $annee_decalage = $annee;
440 $annee_decalage = $annee + 1;
445 if ($annee >= $year_start) {
446 if ($modecompta ==
'CREANCES-DETTES') {
448 print
'<td class="right">';
449 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
450 if (!empty($cumulative_ht[$case])) {
452 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
454 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
465 print
'<td class="right">';
466 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
467 if (!empty($cumulative[$case])) {
469 if ($modecompta !=
'BOOKKEEPING') {
470 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
472 print
price($cumulative[$case], 1);
473 if ($modecompta !=
'BOOKKEEPING') {
477 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
487 print
'<td class="borderrightlight right"><span class="opacitymedium">';
489 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
490 if ($annee_decalage > $minyear && $case <= $casenow) {
491 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
492 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
494 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
496 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
499 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
503 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
506 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
510 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
517 print
'</span></td>';
519 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
520 print
'<td width="15"> </td>';
524 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
525 if (empty($total_ht[$annee])) {
526 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
528 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
530 if (empty($total[$annee])) {
531 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
533 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
607print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
608for ($annee = $year_start; $annee <= $year_end; $annee++) {
609 if ($modecompta ==
'CREANCES-DETTES') {
611 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
612 print
'<td class="nowrap right">';
613 print(empty($total_ht[$annee]) ?
'0' :
price($total_ht[$annee]));
616 print
'<td> </td>';
621 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
622 print
'<td class="nowrap right">';
623 print(empty($total[$annee]) ?
'0' :
price($total[$annee]));
626 print
'<td> </td>';
630 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
631 if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
632 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
633 print
'<td class="nowrap borderrightlight right">';
634 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
637 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
638 print
'<td class="borderrightlight right">-100%</td>';
640 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
641 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
643 if (empty($total[$annee - 1]) && empty($total[$annee])) {
644 print
'<td class="borderrightlight right">+0%</td>';
647 print
'<td class="borderrightlight right">';
648 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
656 if ($annee != $year_end) {
657 print
'<td width="15"> </td>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
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 a 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.