30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
43$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
46$date_startmonth =
GETPOSTINT(
'date_startmonth');
59 $year_start = $year_current - ($nbofyear - 1);
61 $year_current = $year;
63 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
65$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
66$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
69if (empty($date_start) || empty($date_end)) {
73 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
76 if (!$year && $month_start > $month_current) {
80 $month_end = $month_start - 1;
85 $month_end = $month_start;
112$month_start = $tmps[
'mon'];
113$year_start = $tmps[
'year'];
115$month_end = $tmpe[
'mon'];
116$year_end = $tmpe[
'year'];
117$nbofyear = ($year_end - $year_start) + 1;
121if (isModEnabled(
'accounting')) {
122 $modecompta =
'BOOKKEEPING';
124if (
GETPOST(
"modecompta",
'alpha')) {
125 $modecompta =
GETPOST(
"modecompta",
'alpha');
129if ($user->socid > 0) {
130 $socid = $user->socid;
132if (isModEnabled(
'comptabilite')) {
135if (isModEnabled(
'accounting')) {
136 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
147if ($date_startday && $date_startmonth && $date_startyear) {
148 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
150if ($date_endday && $date_endmonth && $date_endyear) {
151 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
156$form =
new Form($db);
165if ($modecompta ==
"CREANCES-DETTES") {
166 $name = $langs->trans(
"Turnover");
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(
"RulesCADue");
170 $description .= $langs->trans(
"DepositsAreNotIncluded");
172 $description .= $langs->trans(
"DepositsAreIncluded");
175} elseif ($modecompta ==
"RECETTES-DEPENSES") {
176 $name = $langs->trans(
"TurnoverCollected");
177 $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>" :
"");
178 $description = $langs->trans(
"RulesCAIn");
179 $description .= $langs->trans(
"DepositsAreIncluded");
181} elseif ($modecompta ==
"BOOKKEEPING") {
182 $name = $langs->trans(
"Turnover");
183 $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>" :
"");
184 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
187$period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
189$period .= $form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
192if (!empty($modecompta)) {
193 $moreparam[
'modecompta'] = $modecompta;
198if ($modecompta ==
"RECETTES-DEPENSES" || $modecompta ==
"BOOKKEEPINGCOLLECTED") {
203 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModePayment");
204 if (isModEnabled(
'accounting')) {
205 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
207 $calcmode .=
'</label>';
209 if (isModEnabled(
'accounting')) {
210 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
211 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"DataMustHaveBeenTransferredInAccounting").
')</span>';
214 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
215 if (isModEnabled(
'accounting')) {
216 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
218 $calcmode .=
'</label>';
221report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
223if (isModEnabled(
'accounting')) {
224 if ($modecompta !=
'BOOKKEEPING') {
225 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
229 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
230 if (empty($pcgvercode)) {
231 $pcgvercode = $pcgverid;
234 $sql =
"SELECT b.rowid ";
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
236 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
237 $sql .=
" WHERE b.entity = ".$conf->entity;
238 $sql .=
" AND b.numero_compte = aa.account_number";
239 $sql .=
" AND aa.entity = ".$conf->entity;
240 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
241 $sql .= $db->plimit(1);
243 $resql = $db->query($sql);
244 $nb = $db->num_rows($resql);
246 $langs->load(
"errors");
247 print
info_admin($langs->trans(
"WarningNoDataTransferedInAccountancyYet"), 0, 0,
'1');
253if ($modecompta ==
'CREANCES-DETTES') {
254 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
256 $sql .=
" WHERE f.fk_statut in (1,2)";
258 $sql .=
" AND f.type IN (0,1,2,5)";
260 $sql .=
" AND f.type IN (0,1,2,3,5)";
262 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
264 $sql .=
" AND f.fk_soc = ".((int) $socid);
266} elseif ($modecompta ==
"RECETTES-DEPENSES") {
271 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
273 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
274 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
275 $sql .=
" WHERE p.rowid = pf.fk_paiement";
276 $sql .=
" AND pf.fk_facture = f.rowid";
277 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
279 $sql .=
" AND f.fk_soc = ".((int) $socid);
281} elseif ($modecompta ==
"BOOKKEEPING") {
283 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
284 if (empty($pcgvercode)) {
285 $pcgvercode = $pcgverid;
288 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
290 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
291 $sql .=
" WHERE b.entity = ".$conf->entity;
292 $sql .=
" AND b.numero_compte = aa.account_number";
293 $sql .=
" AND b.doc_type = 'customer_invoice'";
294 $sql .=
" AND aa.entity = ".$conf->entity;
295 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
296 $sql .=
" AND aa.pcg_type = 'INCOME'";
298$sql .=
" GROUP BY dm";
299$sql .=
" ORDER BY dm";
303$minyearmonth = $maxyearmonth = 0;
305$cumulative = array();
306$cumulative_ht = array();
310$result = $db->query($sql);
312 $num = $db->num_rows($result);
315 $obj = $db->fetch_object($result);
316 $cumulative_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
317 $cumulative[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
318 if ($obj->amount_ttc) {
319 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
320 $maxyearmonth = max($maxyearmonth, $obj->dm);
330if ($modecompta ==
'RECETTES-DEPENSES') {
331 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
333 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
334 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
335 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
336 $sql .=
" WHERE pf.rowid IS NULL";
337 $sql .=
" AND p.fk_bank = b.rowid";
338 $sql .=
" AND b.fk_account = ba.rowid";
339 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
340 $sql .=
" GROUP BY dm";
341 $sql .=
" ORDER BY dm";
343 $result = $db->query($sql);
345 $num = $db->num_rows($result);
348 $obj = $db->fetch_object($result);
349 if (empty($cumulative[$obj->dm])) {
350 $cumulative[$obj->dm] = $obj->amount_ttc;
352 $cumulative[$obj->dm] += $obj->amount_ttc;
354 if ($obj->amount_ttc) {
355 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
356 $maxyearmonth = max($maxyearmonth, $obj->dm);
367print
'<div class="div-table-responsive">';
368print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
370print
'<tr class="liste_titre"><td> </td>';
372for ($annee = $year_start; $annee <= $year_end; $annee++) {
373 if ($modecompta ==
'CREANCES-DETTES') {
374 print
'<td align="center" width="10%" colspan="3">';
376 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
378 if ($modecompta !=
'BOOKKEEPING') {
379 print
'<a href="casoc.php?year='.$annee.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
383 print
'-'.($annee + 1);
385 if ($modecompta !=
'BOOKKEEPING') {
389 if ($annee != $year_end) {
390 print
'<td width="15"> </td>';
395print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
396for ($annee = $year_start; $annee <= $year_end; $annee++) {
397 if ($modecompta ==
'CREANCES-DETTES') {
398 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
400 print
'<td class="liste_titre right">';
401 if ($modecompta ==
"BOOKKEEPING") {
402 print $langs->trans(
"Amount");
404 print $langs->trans(
"AmountTTC");
407 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
408 if ($annee != $year_end) {
409 print
'<td class="liste_titre" width="15"> </td>';
415$minyear = substr($minyearmonth, 0, 4);
416$maxyear = substr($maxyearmonth, 0, 4);
419$maxyearmonth = max($maxyearmonth, $nowyearmonth);
424$nb_mois_decalage = GETPOSTISSET(
'date_startmonth') ? (
GETPOSTINT(
'date_startmonth') - 1) : (!
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') ? 0 : (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') - 1));
425for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
426 $mois_modulo = $mois;
428 $mois_modulo = $mois - 12;
431 if ($year_start == $year_end) {
433 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
437 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
442 print
'<tr class="oddeven">';
445 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
447 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
448 $annee_decalage = $annee;
450 $annee_decalage = $annee + 1;
455 if ($annee >= $year_start) {
456 if ($modecompta ==
'CREANCES-DETTES') {
458 print
'<td class="right">';
459 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
460 if (!empty($cumulative_ht[$case])) {
462 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cumulative_ht[$case], 1).
'</a>';
464 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
475 print
'<td class="right">';
476 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
477 if (!empty($cumulative[$case])) {
479 if ($modecompta !=
'BOOKKEEPING') {
480 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
482 print
price($cumulative[$case], 1);
483 if ($modecompta !=
'BOOKKEEPING') {
487 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
497 print
'<td class="borderrightlight right"><span class="opacitymedium">';
499 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
500 if ($annee_decalage > $minyear && $case <= $casenow) {
501 if (!empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
502 $percent = (round(($cumulative[$case] - $cumulative[$caseprev]) / $cumulative[$caseprev], 4) * 100);
504 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
506 if (!empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
509 if (empty($cumulative[$caseprev]) && !empty($cumulative[$case])) {
513 if (isset($cumulative[$caseprev]) && empty($cumulative[$caseprev]) && empty($cumulative[$case])) {
516 if (!isset($cumulative[$caseprev]) && empty($cumulative[$case])) {
520 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
527 print
'</span></td>';
529 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
530 print
'<td width="15"> </td>';
534 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
535 if (empty($total_ht[$annee])) {
536 $total_ht[$annee] = (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
538 $total_ht[$annee] += (empty($cumulative_ht[$case]) ? 0 : $cumulative_ht[$case]);
540 if (empty($total[$annee])) {
541 $total[$annee] = empty($cumulative[$case]) ? 0 : $cumulative[$case];
543 $total[$annee] += empty($cumulative[$case]) ? 0 : $cumulative[$case];
617print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
618for ($annee = $year_start; $annee <= $year_end; $annee++) {
619 if ($modecompta ==
'CREANCES-DETTES') {
621 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
622 print
'<td class="nowrap right">';
623 print(empty($total_ht[$annee]) ?
'0' :
price($total_ht[$annee]));
626 print
'<td> </td>';
631 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
632 print
'<td class="nowrap right">';
633 print(empty($total[$annee]) ?
'0' :
price($total[$annee]));
636 print
'<td> </td>';
640 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
641 if (!empty($total[$annee - 1]) && !empty($total[$annee])) {
642 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
643 print
'<td class="nowrap borderrightlight right">';
644 print($percent >= 0 ?
"+$percent" :
"$percent").
'%';
647 if (!empty($total[$annee - 1]) && empty($total[$annee])) {
648 print
'<td class="borderrightlight right">-100%</td>';
650 if (empty($total[$annee - 1]) && !empty($total[$annee])) {
651 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
653 if (empty($total[$annee - 1]) && empty($total[$annee])) {
654 print
'<td class="borderrightlight right">+0%</td>';
657 print
'<td class="borderrightlight right">';
658 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
666 if ($annee != $year_end) {
667 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.