28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
30 require_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 - 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');
59 if (empty($date_start) || empty($date_end)) {
63 $year_end = $year_start + ($nbofyear - 1);
64 $month_start =
GETPOSTISSET(
"month") ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1);
66 if (!
GETPOST(
"year") && $month_start > $month_current) {
70 $month_end = $month_start - 1;
77 $month_end = $month_start;
100 $userid =
GETPOST(
'userid',
'int');
101 $socid =
GETPOST(
'socid',
'int');
104 $mothn_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;
112 $modecompta = $conf->global->ACCOUNTING_MODE;
114 $modecompta =
'BOOKKEEPING';
117 $modecompta =
GETPOST(
"modecompta",
'alpha');
121 if ($user->socid > 0) {
122 $socid = $user->socid;
128 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
139 if ($date_startday && $date_startmonth && $date_startyear) {
140 $param .=
'&date_startday='.$date_startday.
'&date_startmonth='.$date_startmonth.
'&date_startyear='.$date_startyear;
142 if ($date_endday && $date_endmonth && $date_endyear) {
143 $param .=
'&date_endday='.$date_endday.
'&date_endmonth='.$date_endmonth.
'&date_endyear='.$date_endyear;
153 if ($modecompta ==
"CREANCES-DETTES") {
154 $name = $langs->trans(
"Turnover");
155 $calcmode = $langs->trans(
"CalcModeDebt");
158 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{link1}',
'{link2}').
')';
159 $calcmode = str_replace(
'{link1}',
'<a class="bold" href="'.$_SERVER[
"PHP_SELF"].
'?'.($param ? $param :
'year_start='.$year_start).
'&modecompta=BOOKKEEPING">', $calcmode);
160 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
162 $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>" :
"");
163 $description = $langs->trans(
"RulesCADue");
164 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
165 $description .= $langs->trans(
"DepositsAreNotIncluded");
167 $description .= $langs->trans(
"DepositsAreIncluded");
171 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
172 $name = $langs->trans(
"TurnoverCollected");
173 $calcmode = $langs->trans(
"CalcModeEngagement");
178 $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>" :
"");
179 $description = $langs->trans(
"RulesCAIn");
180 $description .= $langs->trans(
"DepositsAreIncluded");
183 } elseif ($modecompta ==
"BOOKKEEPING") {
184 $name = $langs->trans(
"Turnover");
185 $calcmode = $langs->trans(
"CalcModeBookkeeping");
186 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{link1}',
'{link2}').
')';
187 $calcmode = str_replace(
'{link1}',
'<a class="bold" href="'.$_SERVER[
"PHP_SELF"].
'?'.($param ? $param :
'year_start='.$year_start).
'&modecompta=CREANCES-DETTES">', $calcmode);
188 $calcmode = str_replace(
'{link2}',
'</a>', $calcmode);
190 $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>" :
"");
191 $description = $langs->trans(
"RulesSalesTurnoverOfIncomeAccounts");
195 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
197 $period .=
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'',
'',
'tzserver');
199 $moreparam = array();
200 if (!empty($modecompta)) {
201 $moreparam[
'modecompta'] = $modecompta;
203 report_header($name, $namelink, $period, $periodlink, $description, $builddate, $exportlink, $moreparam, $calcmode);
205 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
206 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
210 if ($modecompta ==
'CREANCES-DETTES') {
211 $sql =
"SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount, sum(f.total_ttc) as amount_ttc";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
213 $sql .=
" WHERE f.fk_statut in (1,2)";
214 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
215 $sql .=
" AND f.type IN (0,1,2,5)";
217 $sql .=
" AND f.type IN (0,1,2,3,5)";
219 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
221 $sql .=
" AND f.fk_soc = ".((int) $socid);
223 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
228 $sql =
"SELECT date_format(p.datep, '%Y-%m') as dm, sum(pf.amount) as amount_ttc";
229 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
230 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
231 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
232 $sql .=
" WHERE p.rowid = pf.fk_paiement";
233 $sql .=
" AND pf.fk_facture = f.rowid";
234 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
236 $sql .=
" AND f.fk_soc = ".((int) $socid);
238 } elseif ($modecompta ==
"BOOKKEEPING") {
239 $pcgverid = $conf->global->CHARTOFACCOUNTS;
240 $pcgvercode =
dol_getIdFromCode($db, $pcgverid,
'accounting_system',
'rowid',
'pcg_version');
241 if (empty($pcgvercode)) {
242 $pcgvercode = $pcgverid;
245 $sql =
"SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit - b.debit) as amount_ttc";
246 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b,";
247 $sql .=
" ".MAIN_DB_PREFIX.
"accounting_account as aa";
248 $sql .=
" WHERE b.entity = ".$conf->entity;
249 $sql .=
" AND b.numero_compte = aa.account_number";
250 $sql .=
" AND b.doc_type = 'customer_invoice'";
251 $sql .=
" AND aa.entity = ".$conf->entity;
252 $sql .=
" AND aa.fk_pcg_version = '".$db->escape($pcgvercode).
"'";
253 $sql .=
" AND aa.pcg_type = 'INCOME'";
255 $sql .=
" GROUP BY dm";
256 $sql .=
" ORDER BY dm";
260 $minyearmonth = $maxyearmonth = 0;
267 $result = $db->query($sql);
269 $num = $db->num_rows($result);
272 $obj = $db->fetch_object($result);
273 $cum_ht[$obj->dm] = empty($obj->amount) ? 0 : $obj->amount;
274 $cum[$obj->dm] = empty($obj->amount_ttc) ? 0 : $obj->amount_ttc;
275 if ($obj->amount_ttc) {
276 $minyearmonth = ($minyearmonth ? min($minyearmonth, $obj->dm) : $obj->dm);
277 $maxyearmonth = max($maxyearmonth, $obj->dm);
287 if ($modecompta ==
'RECETTES-DEPENSES') {
288 $sql =
"SELECT date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount_ttc";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
290 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
291 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
292 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
293 $sql .=
" WHERE pf.rowid IS NULL";
294 $sql .=
" AND p.fk_bank = b.rowid";
295 $sql .=
" AND b.fk_account = ba.rowid";
296 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
297 $sql .=
" GROUP BY dm";
298 $sql .=
" ORDER BY dm";
300 $result = $db->query($sql);
302 $num = $db->num_rows($result);
305 $obj = $db->fetch_object($result);
306 if (empty($cum[$obj->dm])) {
307 $cum[$obj->dm] = $obj->amount_ttc;
309 $cum[$obj->dm] += $obj->amount_ttc;
311 if ($obj->amount_ttc) {
312 $minyearmonth = ($minyearmonth ?min($minyearmonth, $obj->dm) : $obj->dm);
313 $maxyearmonth = max($maxyearmonth, $obj->dm);
324 print
'<div class="div-table-responsive">';
325 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
327 print
'<tr class="liste_titre"><td> </td>';
329 for ($annee = $year_start; $annee <= $year_end; $annee++) {
330 if ($modecompta ==
'CREANCES-DETTES') {
331 print
'<td align="center" width="10%" colspan="3">';
333 print
'<td align="center" width="10%" colspan="2" class="borderrightlight">';
335 if ($modecompta !=
'BOOKKEEPING') {
336 print
'<a href="casoc.php?year='.$annee.
'">';
339 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
340 print
'-'.($annee + 1);
342 if ($modecompta !=
'BOOKKEEPING') {
346 if ($annee != $year_end) {
347 print
'<td width="15"> </td>';
352 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
353 for ($annee = $year_start; $annee <= $year_end; $annee++) {
354 if ($modecompta ==
'CREANCES-DETTES') {
355 print
'<td class="liste_titre right">'.$langs->trans(
"AmountHT").
'</td>';
357 print
'<td class="liste_titre right">';
358 if ($modecompta ==
"BOOKKEEPING") {
359 print $langs->trans(
"Amount");
361 print $langs->trans(
"AmountTTC");
364 print
'<td class="liste_titre right borderrightlight">'.$langs->trans(
"Delta").
'</td>';
365 if ($annee != $year_end) {
366 print
'<td class="liste_titre" width="15"> </td>';
372 $minyear = substr($minyearmonth, 0, 4);
373 $maxyear = substr($maxyearmonth, 0, 4);
375 $nowyearmonth = strftime(
"%Y-%m",
dol_now());
376 $maxyearmonth = max($maxyearmonth, $nowyearmonth);
381 $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));
382 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
383 $mois_modulo = $mois;
385 $mois_modulo = $mois - 12;
388 if ($year_start == $year_end) {
390 if ($mois < $date_startmonth && $year_start <= $date_startyear) {
394 if ($mois > $date_endmonth && $year_end >= $date_endyear) {
399 print
'<tr class="oddeven">';
402 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, 2000),
"%B").
"</td>";
404 for ($annee = $year_start - 1; $annee <= $year_end; $annee++) {
405 $annee_decalage = $annee;
407 $annee_decalage = $annee + 1;
412 if ($annee >= $year_start) {
413 if ($modecompta ==
'CREANCES-DETTES') {
415 print
'<td class="right">';
416 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
417 if ($cum_ht[$case]) {
419 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price($cum_ht[$case], 1).
'</a>';
421 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
432 print
'<td class="right">';
433 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
434 if (!empty($cum[$case])) {
436 if ($modecompta !=
'BOOKKEEPING') {
437 print
'<a href="casoc.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">';
439 print
price($cum[$case], 1);
440 if ($modecompta !=
'BOOKKEEPING') {
444 if ($minyearmonth < $case && $case <= max($maxyearmonth, $nowyearmonth)) {
454 print
'<td class="borderrightlight right"><span class="opacitymedium">';
456 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
457 if ($annee_decalage > $minyear && $case <= $casenow) {
458 if (!empty($cum[$caseprev]) && !empty($cum[$case])) {
459 $percent = (round(($cum[$case] - $cum[$caseprev]) / $cum[$caseprev], 4) * 100);
461 print ($percent >= 0 ?
"+$percent" :
"$percent").
'%';
463 if (!empty($cum[$caseprev]) && empty($cum[$case])) {
466 if (empty($cum[$caseprev]) && !empty($cum[$case])) {
470 if (isset($cum[$caseprev]) && empty($cum[$caseprev]) && empty($cum[$case])) {
473 if (!isset($cum[$caseprev]) && empty($cum[$case])) {
477 if ($minyearmonth <= $case && $case <= $maxyearmonth) {
484 print
'</span></td>';
486 if ($annee_decalage < $year_end || ($annee_decalage == $year_end && $mois > 12 && $annee < $year_end)) {
487 print
'<td width="15"> </td>';
491 if ($annee < $year_end || ($annee == $year_end && $mois <= $month_end)) {
492 if (empty($total_ht[$annee])) {
493 $total_ht[$annee] = (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
495 $total_ht[$annee] += (empty($cum_ht[$case]) ? 0 : $cum_ht[$case]);
497 if (empty($total[$annee])) {
498 $total[$annee] = empty($cum[$case]) ? 0 : $cum[$case];
500 $total[$annee] += empty($cum[$case]) ? 0 : $cum[$case];
574 print
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td>';
575 for ($annee = $year_start; $annee <= $year_end; $annee++) {
576 if ($modecompta ==
'CREANCES-DETTES') {
578 if ($total_ht[$annee] || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
579 print
'<td class="nowrap right">';
580 print ($total_ht[$annee] ?
price($total_ht[$annee]) :
"0");
583 print
'<td> </td>';
588 if (!empty($total[$annee]) || ($annee >= $minyear && $annee <= max($nowyear, $maxyear))) {
589 print
'<td class="nowrap right">';
590 print ($total[$annee] ?
price($total[$annee]) :
"0");
593 print
'<td> </td>';
597 if ($annee > $minyear && $annee <= max($nowyear, $maxyear)) {
598 if ($total[$annee - 1] && $total[$annee]) {
599 $percent = (round(($total[$annee] - $total[$annee - 1]) / $total[$annee - 1], 4) * 100);
600 print
'<td class="nowrap borderrightlight right">';
601 print ($percent >= 0 ?
"+$percent" :
"$percent").
'%';
604 if ($total[$annee - 1] && !$total[$annee]) {
605 print
'<td class="borderrightlight right">-100%</td>';
607 if (!$total[$annee - 1] && $total[$annee]) {
608 print
'<td class="borderrightlight right">+'.$langs->trans(
'Inf').
'%</td>';
610 if (!$total[$annee - 1] && !$total[$annee]) {
611 print
'<td class="borderrightlight right">+0%</td>';
614 print
'<td class="borderrightlight right">';
615 if (!empty($total[$annee]) || ($minyear <= $annee && $annee <= max($nowyear, $maxyear))) {
623 if ($annee != $year_end) {
624 print
'<td width="15"> </td>';
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
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.