31 require
'../../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
38 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
39 $date_startday =
GETPOST(
'date_startday',
'int');
40 $date_startyear =
GETPOST(
'date_startyear',
'int');
41 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
42 $date_endday =
GETPOST(
'date_endday',
'int');
43 $date_endyear =
GETPOST(
'date_endyear',
'int');
52 $year_start = $year_current - ($nbofyear - 1);
54 $year_current = $year;
56 $year_start = $year - ($nbofyear - 1);
58 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
59 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
62 if (empty($date_start) || empty($date_end)) {
66 $year_end = $year_start + ($nbofyear - 1);
67 $month_start =
GETPOST(
"month") ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
69 if (!
GETPOST(
"year") && $month_start > $month_current) {
73 $month_end = $month_start - 1;
80 $month_end = $month_start;
105 $year_start = $tmps[
'year'];
107 $year_end = $tmpe[
'year'];
108 $nbofyear = ($year_end - $year_start) + 1;
112 $modecompta = $conf->global->ACCOUNTING_MODE;
114 $modecompta =
'BOOKKEEPING';
116 if (
GETPOST(
"modecompta",
'alpha')) {
117 $modecompta =
GETPOST(
"modecompta",
'alpha');
121 $socid =
GETPOST(
'socid',
'int');
122 if ($user->socid > 0) {
123 $socid = $user->socid;
129 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
144 $encaiss_ttc = array();
146 $decaiss_ttc = array();
149 if ($modecompta ==
'CREANCES-DETTES') {
150 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
151 $calcmode = $langs->trans(
"CalcModeDebt");
152 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
153 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
155 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
156 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
158 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
159 $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>" :
"");
160 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
161 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
162 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
163 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
165 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
169 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
170 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
171 $calcmode = $langs->trans(
"CalcModeEngagement");
172 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
173 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
175 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
176 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
178 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
179 $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>" :
"");
180 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
181 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
184 } elseif ($modecompta ==
"BOOKKEEPING") {
185 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
186 $calcmode = $langs->trans(
"CalcModeBookkeeping");
187 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
188 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
189 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
190 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
191 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
192 $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>" :
"");
193 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
194 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->trans(
"Chartofaccounts")).
')';
199 $hselected =
'report';
201 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta), $calcmode);
203 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
204 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
215 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
216 if ($modecompta ==
'CREANCES-DETTES') {
217 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
219 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
220 $sql .=
" WHERE f.fk_soc = s.rowid";
221 $sql .=
" AND f.fk_statut IN (1,2)";
222 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
223 $sql .=
" AND f.type IN (0,1,2,5)";
225 $sql .=
" AND f.type IN (0,1,2,3,5)";
227 if (!empty($date_start) && !empty($date_end)) {
228 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
230 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
235 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
236 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
237 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
238 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
239 $sql .=
" WHERE p.rowid = pf.fk_paiement";
240 $sql .=
" AND pf.fk_facture = f.rowid";
241 if (!empty($date_start) && !empty($date_end)) {
242 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
245 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
247 $sql .=
" AND f.fk_soc = ".((int) $socid);
249 $sql .=
" GROUP BY dm";
250 $sql .=
" ORDER BY dm";
253 dol_syslog(
"get customers invoices", LOG_DEBUG);
254 $result = $db->query($sql);
256 $num = $db->num_rows($result);
259 $row = $db->fetch_object($result);
260 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
261 $encaiss_ttc[$row->dm] = $row->amount_ttc;
268 } elseif ($modecompta ==
"BOOKKEEPING") {
272 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
274 if ($modecompta !=
'CREANCES-DETTES') {
275 $sql =
"SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
276 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
277 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
278 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
279 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
280 $sql .=
" WHERE pf.rowid IS NULL";
281 $sql .=
" AND p.fk_bank = b.rowid";
282 $sql .=
" AND b.fk_account = ba.rowid";
283 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
284 if (!empty($date_start) && !empty($date_end)) {
285 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
287 $sql .=
" GROUP BY dm";
288 $sql .=
" ORDER BY dm";
290 dol_syslog(
"get old customers payments not linked to invoices", LOG_DEBUG);
291 $result = $db->query($sql);
293 $num = $db->num_rows($result);
296 $row = $db->fetch_object($result);
298 if (!isset($encaiss[$row->dm])) {
299 $encaiss[$row->dm] = 0;
301 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
303 if (!isset($encaiss_ttc[$row->dm])) {
304 $encaiss_ttc[$row->dm] = 0;
306 $encaiss_ttc[$row->dm] += $row->amount_ttc;
313 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
316 } elseif ($modecompta ==
"BOOKKEEPING") {
327 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
328 if ($modecompta ==
'CREANCES-DETTES') {
329 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
331 $sql .=
" WHERE f.fk_statut IN (1,2)";
332 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
333 $sql .=
" AND f.type IN (0,1,2)";
335 $sql .=
" AND f.type IN (0,1,2,3)";
337 if (!empty($date_start) && !empty($date_end)) {
338 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
340 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
341 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
342 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
343 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
344 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
345 $sql .=
" WHERE f.rowid = pf.fk_facturefourn";
346 $sql .=
" AND p.rowid = pf.fk_paiementfourn";
347 if (!empty($date_start) && !empty($date_end)) {
348 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
351 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
354 $sql .=
" AND f.fk_soc = ".((int) $socid);
356 $sql .=
" GROUP BY dm";
358 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
359 $result = $db->query($sql);
361 $num = $db->num_rows($result);
364 $row = $db->fetch_object($result);
366 if (!isset($decaiss[$row->dm])) {
367 $decaiss[$row->dm] = 0;
369 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
371 if (!isset($decaiss_ttc[$row->dm])) {
372 $decaiss_ttc[$row->dm] = 0;
374 $decaiss_ttc[$row->dm] = $row->amount_ttc;
382 } elseif ($modecompta ==
"BOOKKEEPING") {
394 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
395 if ($modecompta ==
'CREANCES-DETTES') {
397 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
398 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
399 $sql .=
" WHERE f.fk_statut IN (1,2)";
400 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
401 $sql .=
" AND f.type IN (0,1,2,5)";
403 $sql .=
" AND f.type IN (0,1,2,3,5)";
405 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
406 if (!empty($date_start) && !empty($date_end)) {
407 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
409 $sql .=
" GROUP BY dm";
412 $result = $db->query($sql);
414 $num = $db->num_rows($result);
418 $obj = $db->fetch_object($result);
425 if (!isset($decaiss_ttc[$obj->dm])) {
426 $decaiss_ttc[$obj->dm] = 0;
428 $decaiss_ttc[$obj->dm] += $obj->amount;
437 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
439 $sql .=
" WHERE f.fk_statut IN (1,2)";
440 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
441 $sql .=
" AND f.type IN (0,1,2)";
443 $sql .=
" AND f.type IN (0,1,2,3)";
445 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
446 if (!empty($date_start) && !empty($date_end)) {
447 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
449 $sql .=
" GROUP BY dm";
451 dol_syslog(
"get vat to receive back", LOG_DEBUG);
452 $result = $db->query($sql);
454 $num = $db->num_rows($result);
458 $obj = $db->fetch_object($result);
465 if (!isset($encaiss_ttc[$obj->dm])) {
466 $encaiss_ttc[$obj->dm] = 0;
468 $encaiss_ttc[$obj->dm] += $obj->amount;
476 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
478 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
479 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
480 $sql .=
" WHERE amount > 0";
481 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
482 if (!empty($date_start) && !empty($date_end)) {
483 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
485 $sql .=
" GROUP BY dm";
488 $result = $db->query($sql);
490 $num = $db->num_rows($result);
494 $obj = $db->fetch_object($result);
501 if (!isset($decaiss_ttc[$obj->dm])) {
502 $decaiss_ttc[$obj->dm] = 0;
504 $decaiss_ttc[$obj->dm] += $obj->amount;
513 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
514 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
515 $sql .=
" WHERE amount < 0";
516 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
517 if (!empty($date_start) && !empty($date_end)) {
518 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
520 $sql .=
" GROUP BY dm";
522 dol_syslog(
"get vat really received back", LOG_DEBUG);
523 $result = $db->query($sql);
525 $num = $db->num_rows($result);
529 $obj = $db->fetch_object($result);
536 if (!isset($encaiss_ttc[$obj->dm])) {
537 $encaiss_ttc[$obj->dm] = 0;
539 $encaiss_ttc[$obj->dm] += -$obj->amount;
548 } elseif ($modecompta ==
"BOOKKEEPING") {
558 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
559 if ($modecompta ==
'CREANCES-DETTES') {
560 $sql =
"SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
561 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
562 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
563 $sql .=
" WHERE cs.fk_type = c.id";
564 if (!empty($date_start) && !empty($date_end)) {
565 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
567 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
568 $sql =
"SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
569 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
570 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
571 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
572 $sql .=
" WHERE p.fk_charge = cs.rowid";
573 $sql .=
" AND cs.fk_type = c.id";
574 if (!empty($date_start) && !empty($date_end)) {
575 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
579 $sql .=
" AND cs.entity IN (".getEntity(
'social_contributions').
")";
580 $sql .=
" GROUP BY c.libelle, dm";
582 dol_syslog(
"get social contributions", LOG_DEBUG);
583 $result = $db->query($sql);
585 $num = $db->num_rows($result);
589 $obj = $db->fetch_object($result);
591 if (!isset($decaiss[$obj->dm])) {
592 $decaiss[$obj->dm] = 0;
594 $decaiss[$obj->dm] += $obj->amount;
596 if (!isset($decaiss_ttc[$obj->dm])) {
597 $decaiss_ttc[$obj->dm] = 0;
599 $decaiss_ttc[$obj->dm] += $obj->amount;
607 } elseif ($modecompta ==
"BOOKKEEPING") {
616 if (
isModEnabled(
'salaries') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
617 if ($modecompta ==
'CREANCES-DETTES') {
618 $column =
's.dateep';
620 $sql =
"SELECT s.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(s.amount) as amount";
621 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
622 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
623 if (!empty($date_start) && !empty($date_end)) {
624 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
626 $sql .=
" GROUP BY s.label, dm";
628 if ($modecompta ==
"RECETTES-DEPENSES") {
631 $sql =
"SELECT p.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(p.amount) as amount";
632 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
633 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON p.fk_salary = s.rowid";
634 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
635 if (!empty($date_start) && !empty($date_end)) {
636 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
638 $sql .=
" GROUP BY p.label, dm";
645 $result = $db->query($sql);
647 $num = $db->num_rows($result);
651 $obj = $db->fetch_object($result);
653 if (!isset($decaiss[$obj->dm])) {
654 $decaiss[$obj->dm] = 0;
656 $decaiss[$obj->dm] += $obj->amount;
658 if (!isset($decaiss_ttc[$obj->dm])) {
659 $decaiss_ttc[$obj->dm] = 0;
661 $decaiss_ttc[$obj->dm] += $obj->amount;
669 } elseif ($modecompta ==
"BOOKKEEPING") {
678 if (!
isModEnabled(
'expensereport') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
679 $langs->load(
'trips');
681 if ($modecompta ==
'CREANCES-DETTES') {
682 $sql =
"SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
683 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
684 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
685 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
686 $sql .=
" AND p.fk_statut>=5";
688 $column =
'p.date_valid';
689 if (!empty($date_start) && !empty($date_end)) {
690 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
692 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
693 $sql =
"SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
694 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
695 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
696 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
697 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
698 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
699 $sql .=
" AND p.fk_statut>=5";
701 $column =
'pe.datep';
702 if (!empty($date_start) && !empty($date_end)) {
703 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
707 $sql .=
" GROUP BY dm";
710 $result = $db->query($sql);
714 $num = $db->num_rows($result);
716 while ($obj = $db->fetch_object($result)) {
717 if (!isset($decaiss[$obj->dm])) {
718 $decaiss[$obj->dm] = 0;
720 $decaiss[$obj->dm] += $obj->amount_ht;
722 if (!isset($decaiss_ttc[$obj->dm])) {
723 $decaiss_ttc[$obj->dm] = 0;
725 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
731 } elseif ($modecompta ==
'BOOKKEEPING') {
740 if (
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
744 if ($modecompta ==
'CREANCES-DETTES') {
745 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
746 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
747 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
748 $sql .=
" AND fk_statut in (1,2)";
749 if (!empty($date_start) && !empty($date_end)) {
750 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
752 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
753 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
754 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
755 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
756 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
757 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
758 $sql .=
" AND fk_statut >= 2";
759 if (!empty($date_start) && !empty($date_end)) {
760 $sql .=
" AND pe.datep >= '".$db->idate($date_start).
"' AND pe.datep <= '".$db->idate($date_end).
"'";
764 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
767 $result = $db->query($sql);
769 $num = $db->num_rows($result);
773 $obj = $db->fetch_object($result);
775 if (!isset($encaiss[$obj->dm])) {
776 $encaiss[$obj->dm] = 0;
778 $encaiss[$obj->dm] += $obj->amount;
780 if (!isset($encaiss_ttc[$obj->dm])) {
781 $encaiss_ttc[$obj->dm] = 0;
783 $encaiss_ttc[$obj->dm] += $obj->amount;
791 } elseif ($modecompta ==
'BOOKKEEPING') {
799 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) &&
isModEnabled(
'banque') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
802 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
803 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
804 $sql .=
' AND p.sens = 0';
805 if (!empty($date_start) && !empty($date_end)) {
806 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
808 $sql .=
' GROUP BY dm';
811 $result = $db->query($sql);
813 $num = $db->num_rows($result);
817 $obj = $db->fetch_object($result);
818 if (!isset($decaiss_ttc[$obj->dm])) {
819 $decaiss_ttc[$obj->dm] = 0;
821 if (isset($obj->amount)) {
822 $decaiss_ttc[$obj->dm] += $obj->amount;
833 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various AS p";
834 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
835 $sql .=
' AND p.sens = 1';
836 if (!empty($date_start) && !empty($date_end)) {
837 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
839 $sql .=
' GROUP BY dm';
842 $result = $db->query($sql);
844 $num = $db->num_rows($result);
848 $obj = $db->fetch_object($result);
849 if (!isset($encaiss_ttc[$obj->dm])) {
850 $encaiss_ttc[$obj->dm] = 0;
852 if (isset($obj->amount)) {
853 $encaiss_ttc[$obj->dm] += $obj->amount;
870 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) &&
isModEnabled(
'loan') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
871 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
872 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan AS p, ".MAIN_DB_PREFIX.
"loan as l";
873 $sql .=
" WHERE l.entity IN (".getEntity(
'variouspayment').
")";
874 $sql .=
" AND p.fk_loan = l.rowid";
875 if (!empty($date_start) && !empty($date_end)) {
876 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
878 $sql .=
' GROUP BY dm';
881 $result = $db->query($sql);
883 $num = $db->num_rows($result);
887 $obj = $db->fetch_object($result);
888 if (!isset($decaiss_ttc[$obj->dm])) {
889 $decaiss_ttc[$obj->dm] = 0;
891 if (isset($obj->amount)) {
892 $decaiss_ttc[$obj->dm] += $obj->amount;
910 if (
isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
911 $predefinedgroupwhere =
"(";
912 $predefinedgroupwhere .=
" (aa.pcg_type = 'EXPENSE')";
913 $predefinedgroupwhere .=
" OR ";
914 $predefinedgroupwhere .=
" (aa.pcg_type = 'INCOME')";
915 $predefinedgroupwhere .=
")";
917 $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
918 $charofaccountstring =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
920 $sql =
"SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, aa.pcg_type, date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as debit, sum(b.credit) as credit, sum(b.montant) as amount";
921 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_account as aa";
922 $sql .=
" WHERE b.entity = ".$conf->entity;
923 $sql .=
" AND aa.entity = ".$conf->entity;
924 $sql .=
" AND b.numero_compte = aa.account_number";
925 $sql .=
" AND ".$predefinedgroupwhere;
926 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
927 if (!empty($date_start) && !empty($date_end)) {
928 $sql .=
" AND b.doc_date >= '".$db->idate($date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
930 $sql .=
" GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
937 $result = $db->query($sql);
939 $num = $db->num_rows($result);
943 $obj = $db->fetch_object($result);
945 if ($obj->pcg_type ==
'INCOME') {
946 if (!isset($encaiss[$obj->dm])) {
947 $encaiss[$obj->dm] = 0;
949 $encaiss[$obj->dm] += $obj->credit;
950 $encaiss[$obj->dm] -= $obj->debit;
952 if ($obj->pcg_type ==
'EXPENSE') {
953 if (!isset($decaiss[$obj->dm])) {
954 $decaiss[$obj->dm] = 0;
956 $decaiss[$obj->dm] += $obj->debit;
957 $decaiss[$obj->dm] -= $obj->credit;
961 if (!isset($encaiss_ttc[$obj->dm])) {
962 $encaiss_ttc[$obj->dm] = 0;
964 if (!isset($decaiss_ttc[$obj->dm])) {
965 $decaiss_ttc[$obj->dm] = 0;
967 $encaiss_ttc[$obj->dm] += 0;
968 $decaiss_ttc[$obj->dm] += 0;
981 $object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
982 $parameters[
"mode"] = $modecompta;
984 $hookmanager->initHooks(array(
'externalbalance'));
985 $reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
993 $totentrees = array();
994 $totsorties = array();
996 print
'<div class="div-table-responsive">';
997 print
'<table class="tagtable liste">'.
"\n";
999 print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1001 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1002 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1003 print
'<a href="clientfourn.php?year='.$annee.
'">';
1005 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
1006 print
'-'.($annee + 1);
1011 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1013 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1014 print
'<td class="liste_titre" align="center">';
1017 print
$form->textwithpicto($langs->trans(
"Outcome"), $htmlhelp);
1019 print
'<td class="liste_titre" align="center" class="borderrightlight">';
1022 print
$form->textwithpicto($langs->trans(
"Income"), $htmlhelp);
1029 $nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1030 for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1031 $mois_modulo = $mois;
1033 $mois_modulo = $mois - 12;
1036 print
'<tr class="oddeven">';
1037 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee),
"%B").
"</td>";
1038 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1039 $annee_decalage = $annee;
1041 $annee_decalage = $annee + 1;
1043 $case = strftime(
"%Y-%m",
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
1045 print
'<td class="right">';
1046 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1047 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1048 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss[$case],
'MT')).
'</a>';
1049 if (!isset($totsorties[$annee])) {
1050 $totsorties[$annee] = 0;
1052 $totsorties[$annee] += $decaiss[$case];
1055 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1056 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss_ttc[$case],
'MT')).
'</a>';
1057 if (!isset($totsorties[$annee])) {
1058 $totsorties[$annee] = 0;
1060 $totsorties[$annee] += $decaiss_ttc[$case];
1065 print
'<td class="borderrightlight nowrap right">';
1066 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1067 if (isset($encaiss[$case])) {
1068 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss[$case],
'MT')).
'</a>';
1069 if (!isset($totentrees[$annee])) {
1070 $totentrees[$annee] = 0;
1072 $totentrees[$annee] += $encaiss[$case];
1075 if (isset($encaiss_ttc[$case])) {
1076 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss_ttc[$case],
'MT')).
'</a>';
1077 if (!isset($totentrees[$annee])) {
1078 $totentrees[$annee] = 0;
1080 $totentrees[$annee] += $encaiss_ttc[$case];
1092 print
'<tr class="liste_total impair"><td>';
1093 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1094 print $langs->trans(
"Total");
1096 print $langs->trans(
"TotalTTC");
1099 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1101 print
'<td class="nowrap right">'.(isset($totsorties[$annee]) ?
price(
price2num($totsorties[$annee],
'MT')) :
' ').
'</td>';
1102 print
'<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?
price(
price2num($totentrees[$annee],
'MT')) :
' ').
'</td>';
1107 print
'<tr class="impair"><td> </td>';
1108 print
'<td colspan="'.$nbcols.
'"> </td>';
1113 print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1114 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1115 print
'<td colspan="2" class="borderrightlight right"> ';
1116 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1117 $in = (isset($totentrees[$annee]) ?
price2num($totentrees[$annee],
'MT') : 0);
1118 $out = (isset($totsorties[$annee]) ?
price2num($totsorties[$annee],
'MT') : 0);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a report.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0, $filters= '')
Return an id or code from a code or id.
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...
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=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.
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.