33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
46$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
49$date_startmonth =
GETPOSTINT(
'date_startmonth');
66 $year_start = $year_current - ($nbofyear - 1);
68 $year_current = $year;
70 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
72$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
73$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
76if (empty($date_start) || empty($date_end)) {
80 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
83 if (!$year && $month_start > $month_current) {
87 $month_end = $month_start - 1;
92 $month_end = $month_start;
117$year_start = $tmps[
'year'];
119$year_end = $tmpe[
'year'];
120$nbofyear = ($year_end - $year_start) + 1;
125if (isModEnabled(
'accounting')) {
126 $modecompta =
'BOOKKEEPING';
128if (
GETPOST(
"modecompta",
'alpha')) {
129 $modecompta =
GETPOST(
"modecompta",
'alpha');
134if ($user->socid > 0) {
135 $socid = $user->socid;
137if (isModEnabled(
'comptabilite')) {
140if (isModEnabled(
'accounting')) {
141 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
151$form =
new Form($db);
161$encaiss_ttc = array();
163$decaiss_ttc = array();
166if ($modecompta ==
'CREANCES-DETTES') {
167 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
168 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
169 $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>" :
"");
170 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
171 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
173 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
175 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
178 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
182} elseif ($modecompta ==
"RECETTES-DEPENSES") {
183 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
184 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
185 $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>" :
"");
186 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
187 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
190} elseif ($modecompta ==
"BOOKKEEPING") {
191 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
192 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
193 $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>" :
"");
194 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
195 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->transnoentitiesnoconv(
"Chartofaccounts")).
')';
202if (isModEnabled(
'accounting')) {
203 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
206$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
207if (isModEnabled(
'accounting')) {
208 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
210$calcmode .=
'</label>';
211$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
212if (isModEnabled(
'accounting')) {
213 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
215$calcmode .=
'</label>';
217report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
219if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
220 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
231if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
232 if ($modecompta ==
'CREANCES-DETTES') {
233 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
235 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
236 $sql .=
" WHERE f.fk_soc = s.rowid";
237 $sql .=
" AND f.fk_statut IN (1,2)";
239 $sql .=
" AND f.type IN (0,1,2,5)";
241 $sql .=
" AND f.type IN (0,1,2,3,5)";
243 if (!empty($date_start) && !empty($date_end)) {
244 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
246 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
251 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
253 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
254 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
255 $sql .=
" WHERE p.rowid = pf.fk_paiement";
256 $sql .=
" AND pf.fk_facture = f.rowid";
257 if (!empty($date_start) && !empty($date_end)) {
258 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
261 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
263 $sql .=
" AND f.fk_soc = ".((int) $socid);
265 $sql .=
" GROUP BY dm";
266 $sql .=
" ORDER BY dm";
269 dol_syslog(
"get customers invoices", LOG_DEBUG);
270 $result = $db->query($sql);
272 $num = $db->num_rows($result);
275 $row = $db->fetch_object($result);
276 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
277 $encaiss_ttc[$row->dm] = $row->amount_ttc;
288if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
290 if ($modecompta !=
'CREANCES-DETTES') {
291 $sql =
"SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
292 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
293 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
294 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
295 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
296 $sql .=
" WHERE pf.rowid IS NULL";
297 $sql .=
" AND p.fk_bank = b.rowid";
298 $sql .=
" AND b.fk_account = ba.rowid";
299 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
300 if (!empty($date_start) && !empty($date_end)) {
301 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
303 $sql .=
" GROUP BY dm";
304 $sql .=
" ORDER BY dm";
306 dol_syslog(
"get old customers payments not linked to invoices", LOG_DEBUG);
307 $result = $db->query($sql);
309 $num = $db->num_rows($result);
312 $row = $db->fetch_object($result);
314 if (!isset($encaiss[$row->dm])) {
315 $encaiss[$row->dm] = 0;
317 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
319 if (!isset($encaiss_ttc[$row->dm])) {
320 $encaiss_ttc[$row->dm] = 0;
322 $encaiss_ttc[$row->dm] += $row->amount_ttc;
343if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
344 if ($modecompta ==
'CREANCES-DETTES') {
345 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
346 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
347 $sql .=
" WHERE f.fk_statut IN (1,2)";
349 $sql .=
" AND f.type IN (0,1,2)";
351 $sql .=
" AND f.type IN (0,1,2,3)";
353 if (!empty($date_start) && !empty($date_end)) {
354 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
356 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
357 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
359 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
360 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
361 $sql .=
" WHERE f.rowid = pf.fk_facturefourn";
362 $sql .=
" AND p.rowid = pf.fk_paiementfourn";
363 if (!empty($date_start) && !empty($date_end)) {
364 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
367 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
370 $sql .=
" AND f.fk_soc = ".((int) $socid);
372 $sql .=
" GROUP BY dm";
374 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
375 $result = $db->query($sql);
377 $num = $db->num_rows($result);
380 $row = $db->fetch_object($result);
382 if (!isset($decaiss[$row->dm])) {
383 $decaiss[$row->dm] = 0;
385 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
387 if (!isset($decaiss_ttc[$row->dm])) {
388 $decaiss_ttc[$row->dm] = 0;
390 $decaiss_ttc[$row->dm] = $row->amount_ttc;
410if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
411 if ($modecompta ==
'CREANCES-DETTES') {
413 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
414 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
415 $sql .=
" WHERE f.fk_statut IN (1,2)";
417 $sql .=
" AND f.type IN (0,1,2,5)";
419 $sql .=
" AND f.type IN (0,1,2,3,5)";
421 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
422 if (!empty($date_start) && !empty($date_end)) {
423 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
425 $sql .=
" GROUP BY dm";
428 $result = $db->query($sql);
430 $num = $db->num_rows($result);
434 $obj = $db->fetch_object($result);
441 if (!isset($decaiss_ttc[$obj->dm])) {
442 $decaiss_ttc[$obj->dm] = 0;
444 $decaiss_ttc[$obj->dm] += $obj->amount;
453 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
454 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
455 $sql .=
" WHERE f.fk_statut IN (1,2)";
457 $sql .=
" AND f.type IN (0,1,2)";
459 $sql .=
" AND f.type IN (0,1,2,3)";
461 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
462 if (!empty($date_start) && !empty($date_end)) {
463 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
465 $sql .=
" GROUP BY dm";
467 dol_syslog(
"get vat to receive back", LOG_DEBUG);
468 $result = $db->query($sql);
470 $num = $db->num_rows($result);
474 $obj = $db->fetch_object($result);
481 if (!isset($encaiss_ttc[$obj->dm])) {
482 $encaiss_ttc[$obj->dm] = 0;
484 $encaiss_ttc[$obj->dm] += $obj->amount;
492 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
494 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
495 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
496 $sql .=
" WHERE amount > 0";
497 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
498 if (!empty($date_start) && !empty($date_end)) {
499 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
501 $sql .=
" GROUP BY dm";
504 $result = $db->query($sql);
506 $num = $db->num_rows($result);
510 $obj = $db->fetch_object($result);
517 if (!isset($decaiss_ttc[$obj->dm])) {
518 $decaiss_ttc[$obj->dm] = 0;
520 $decaiss_ttc[$obj->dm] += $obj->amount;
529 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
530 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
531 $sql .=
" WHERE amount < 0";
532 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
533 if (!empty($date_start) && !empty($date_end)) {
534 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
536 $sql .=
" GROUP BY dm";
538 dol_syslog(
"get vat really received back", LOG_DEBUG);
539 $result = $db->query($sql);
541 $num = $db->num_rows($result);
545 $obj = $db->fetch_object($result);
552 if (!isset($encaiss_ttc[$obj->dm])) {
553 $encaiss_ttc[$obj->dm] = 0;
555 $encaiss_ttc[$obj->dm] += -$obj->amount;
574if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
575 if ($modecompta ==
'CREANCES-DETTES') {
576 $sql =
"SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
577 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
578 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
579 $sql .=
" WHERE cs.fk_type = c.id";
580 if (!empty($date_start) && !empty($date_end)) {
581 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
583 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
584 $sql =
"SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
585 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
586 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
587 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
588 $sql .=
" WHERE p.fk_charge = cs.rowid";
589 $sql .=
" AND cs.fk_type = c.id";
590 if (!empty($date_start) && !empty($date_end)) {
591 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
595 $sql .=
" AND cs.entity IN (".getEntity(
'social_contributions').
")";
596 $sql .=
" GROUP BY c.libelle, dm";
598 dol_syslog(
"get social contributions", LOG_DEBUG);
599 $result = $db->query($sql);
601 $num = $db->num_rows($result);
605 $obj = $db->fetch_object($result);
607 if (!isset($decaiss[$obj->dm])) {
608 $decaiss[$obj->dm] = 0;
610 $decaiss[$obj->dm] += $obj->amount;
612 if (!isset($decaiss_ttc[$obj->dm])) {
613 $decaiss_ttc[$obj->dm] = 0;
615 $decaiss_ttc[$obj->dm] += $obj->amount;
632if (isModEnabled(
'salaries') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
634 if ($modecompta ==
'CREANCES-DETTES') {
635 $column =
's.dateep';
637 $sql =
"SELECT s.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(s.amount) as amount";
638 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
639 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
640 if (!empty($date_start) && !empty($date_end)) {
641 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
643 $sql .=
" GROUP BY s.label, dm";
645 if ($modecompta ==
"RECETTES-DEPENSES") {
648 $sql =
"SELECT p.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(p.amount) as amount";
649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
650 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON p.fk_salary = s.rowid";
651 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
652 if (!empty($date_start) && !empty($date_end)) {
653 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
655 $sql .=
" GROUP BY p.label, dm";
662 $result = $db->query($sql);
664 $num = $db->num_rows($result);
668 $obj = $db->fetch_object($result);
670 if (!isset($decaiss[$obj->dm])) {
671 $decaiss[$obj->dm] = 0;
673 $decaiss[$obj->dm] += $obj->amount;
675 if (!isset($decaiss_ttc[$obj->dm])) {
676 $decaiss_ttc[$obj->dm] = 0;
678 $decaiss_ttc[$obj->dm] += $obj->amount;
695if (isModEnabled(
'expensereport') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
696 $langs->load(
'trips');
698 if ($modecompta ==
'CREANCES-DETTES') {
699 $sql =
"SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
700 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
701 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
702 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
703 $sql .=
" AND p.fk_statut>=5";
705 $column =
'p.date_valid';
706 if (!empty($date_start) && !empty($date_end)) {
707 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
709 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
710 $sql =
"SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
711 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
712 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
713 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
714 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
715 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
716 $sql .=
" AND p.fk_statut>=5";
718 $column =
'pe.datep';
719 if (!empty($date_start) && !empty($date_end)) {
720 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
724 $sql .=
" GROUP BY dm";
727 $result = $db->query($sql);
731 $num = $db->num_rows($result);
733 while ($obj = $db->fetch_object($result)) {
734 if (!isset($decaiss[$obj->dm])) {
735 $decaiss[$obj->dm] = 0;
737 $decaiss[$obj->dm] += $obj->amount_ht;
739 if (!isset($decaiss_ttc[$obj->dm])) {
740 $decaiss_ttc[$obj->dm] = 0;
742 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
757if (isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
761 if ($modecompta ==
'CREANCES-DETTES') {
762 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
763 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
764 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
765 $sql .=
" AND fk_statut in (1,2)";
766 if (!empty($date_start) && !empty($date_end)) {
767 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
769 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
770 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
771 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
772 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
773 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
774 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
775 $sql .=
" AND fk_statut >= 2";
776 if (!empty($date_start) && !empty($date_end)) {
777 $sql .=
" AND pe.datep >= '".$db->idate($date_start).
"' AND pe.datep <= '".$db->idate($date_end).
"'";
781 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
784 $result = $db->query($sql);
786 $num = $db->num_rows($result);
790 $obj = $db->fetch_object($result);
792 if (!isset($encaiss[$obj->dm])) {
793 $encaiss[$obj->dm] = 0;
795 $encaiss[$obj->dm] += $obj->amount;
797 if (!isset($encaiss_ttc[$obj->dm])) {
798 $encaiss_ttc[$obj->dm] = 0;
800 $encaiss_ttc[$obj->dm] += $obj->amount;
816if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
819 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
820 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
821 $sql .=
' AND p.sens = 0';
822 if (!empty($date_start) && !empty($date_end)) {
823 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
825 $sql .=
' GROUP BY dm';
828 $result = $db->query($sql);
830 $num = $db->num_rows($result);
834 $obj = $db->fetch_object($result);
835 if (!isset($decaiss_ttc[$obj->dm])) {
836 $decaiss_ttc[$obj->dm] = 0;
838 if (isset($obj->amount)) {
839 $decaiss_ttc[$obj->dm] += $obj->amount;
850 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various AS p";
851 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
852 $sql .=
' AND p.sens = 1';
853 if (!empty($date_start) && !empty($date_end)) {
854 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
856 $sql .=
' GROUP BY dm';
859 $result = $db->query($sql);
861 $num = $db->num_rows($result);
865 $obj = $db->fetch_object($result);
866 if (!isset($encaiss_ttc[$obj->dm])) {
867 $encaiss_ttc[$obj->dm] = 0;
869 if (isset($obj->amount)) {
870 $encaiss_ttc[$obj->dm] += $obj->amount;
887if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'loan') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
888 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
889 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan AS p, ".MAIN_DB_PREFIX.
"loan as l";
890 $sql .=
" WHERE l.entity IN (".getEntity(
'variouspayment').
")";
891 $sql .=
" AND p.fk_loan = l.rowid";
892 if (!empty($date_start) && !empty($date_end)) {
893 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
895 $sql .=
' GROUP BY dm';
898 $result = $db->query($sql);
900 $num = $db->num_rows($result);
904 $obj = $db->fetch_object($result);
905 if (!isset($decaiss_ttc[$obj->dm])) {
906 $decaiss_ttc[$obj->dm] = 0;
908 if (isset($obj->amount)) {
909 $decaiss_ttc[$obj->dm] += $obj->amount;
927if (isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
928 $predefinedgroupwhere =
"(";
929 $predefinedgroupwhere .=
" (aa.pcg_type = 'EXPENSE')";
930 $predefinedgroupwhere .=
" OR ";
931 $predefinedgroupwhere .=
" (aa.pcg_type = 'INCOME')";
932 $predefinedgroupwhere .=
")";
937 $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";
938 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_account as aa";
939 $sql .=
" WHERE b.entity = ".$conf->entity;
940 $sql .=
" AND aa.entity = ".$conf->entity;
941 $sql .=
" AND b.numero_compte = aa.account_number";
942 $sql .=
" AND ".$predefinedgroupwhere;
943 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
944 if (!empty($date_start) && !empty($date_end)) {
945 $sql .=
" AND b.doc_date >= '".$db->idate($date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
947 $sql .=
" GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
954 $result = $db->query($sql);
956 $num = $db->num_rows($result);
960 $obj = $db->fetch_object($result);
962 if ($obj->pcg_type ==
'INCOME') {
963 if (!isset($encaiss[$obj->dm])) {
964 $encaiss[$obj->dm] = 0;
966 $encaiss[$obj->dm] += $obj->credit;
967 $encaiss[$obj->dm] -= $obj->debit;
969 if ($obj->pcg_type ==
'EXPENSE') {
970 if (!isset($decaiss[$obj->dm])) {
971 $decaiss[$obj->dm] = 0;
973 $decaiss[$obj->dm] += $obj->debit;
974 $decaiss[$obj->dm] -= $obj->credit;
978 if (!isset($encaiss_ttc[$obj->dm])) {
979 $encaiss_ttc[$obj->dm] = 0;
981 if (!isset($decaiss_ttc[$obj->dm])) {
982 $decaiss_ttc[$obj->dm] = 0;
984 $encaiss_ttc[$obj->dm] += 0;
985 $decaiss_ttc[$obj->dm] += 0;
998$object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
999$parameters[
"mode"] = $modecompta;
1001$hookmanager->initHooks(array(
'externalbalance'));
1002$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1010$totentrees = array();
1011$totsorties = array();
1012$year_end_for_table = ($year_end - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1014print
'<div class="div-table-responsive">';
1015print
'<table class="tagtable liste">'.
"\n";
1017print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1019for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1020 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1021 print
'<a href="clientfourn.php?year='.((int) $annee).
'">';
1024 print
'-'.($annee + 1);
1029print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1031for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1032 print
'<td class="liste_titre" align="center">';
1035 print $form->textwithpicto($langs->trans(
"Outcome"), $htmlhelp);
1037 print
'<td class="liste_titre" align="center" class="borderrightlight">';
1040 print $form->textwithpicto($langs->trans(
"Income"), $htmlhelp);
1047$nb_mois_decalage =
$conf->global->SOCIETE_FISCAL_MONTH_START ? (
$conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1048for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1049 $mois_modulo = $mois;
1051 $mois_modulo = $mois - 12;
1054 print
'<tr class="oddeven">';
1055 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee),
"%B").
"</td>";
1056 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1057 $annee_decalage = $annee;
1059 $annee_decalage = $annee + 1;
1063 print
'<td class="right">';
1064 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1065 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1066 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss[$case],
'MT')).
'</a>';
1067 if (!isset($totsorties[$annee])) {
1068 $totsorties[$annee] = 0;
1070 $totsorties[$annee] += $decaiss[$case];
1073 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1074 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss_ttc[$case],
'MT')).
'</a>';
1075 if (!isset($totsorties[$annee])) {
1076 $totsorties[$annee] = 0;
1078 $totsorties[$annee] += $decaiss_ttc[$case];
1083 print
'<td class="borderrightlight nowrap right">';
1084 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1085 if (isset($encaiss[$case])) {
1086 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss[$case],
'MT')).
'</a>';
1087 if (!isset($totentrees[$annee])) {
1088 $totentrees[$annee] = 0;
1090 $totentrees[$annee] += $encaiss[$case];
1093 if (isset($encaiss_ttc[$case])) {
1094 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss_ttc[$case],
'MT')).
'</a>';
1095 if (!isset($totentrees[$annee])) {
1096 $totentrees[$annee] = 0;
1098 $totentrees[$annee] += $encaiss_ttc[$case];
1110print
'<tr class="liste_total impair"><td>';
1111if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1112 print $langs->trans(
"Total");
1114 print $langs->trans(
"TotalTTC");
1117for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1119 print
'<td class="nowrap right">'.(isset($totsorties[$annee]) ?
price(
price2num($totsorties[$annee],
'MT')) :
' ').
'</td>';
1120 print
'<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?
price(
price2num($totentrees[$annee],
'MT')) :
' ').
'</td>';
1125print
'<tr class="impair"><td> </td>';
1126print
'<td colspan="'.$nbcols.
'"> </td>';
1131print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1132for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1133 print
'<td colspan="2" class="borderrightlight right"> ';
1134 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1135 $in = (isset($totentrees[$annee]) ?
price2num($totentrees[$annee],
'MT') : 0);
1136 $out = (isset($totsorties[$annee]) ?
price2num($totsorties[$annee],
'MT') : 0);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.