34require
'../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
46$langs->loadLangs(array(
'compta',
'bills',
'donation',
'accountancy',
'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);
73$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
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;
126 $modecompta =
'BOOKKEEPING';
128if (
GETPOST(
"modecompta",
'alpha')) {
129 $modecompta =
GETPOST(
"modecompta",
'alpha');
134if ($user->socid > 0) {
135 $socid = $user->socid;
141 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
151$form =
new Form($db);
162$encaiss_ttc = array();
164$decaiss_ttc = array();
167if ($modecompta ==
'CREANCES-DETTES') {
168 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
169 $period = $form->selectDate(
$date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
170 $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>" :
"");
171 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
172 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
174 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
176 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
179 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
183} elseif ($modecompta ==
"RECETTES-DEPENSES") {
184 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
185 $period = $form->selectDate(
$date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
186 $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>" :
"");
187 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
188 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
191} elseif ($modecompta ==
"BOOKKEEPING") {
192 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
193 $period = $form->selectDate(
$date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
194 $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>" :
"");
195 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
196 $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")).
')';
204 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
207$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
209 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
211$calcmode .=
'</label>';
212$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
214 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
216$calcmode .=
'</label>';
218report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
220if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
221 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
232if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
233 if ($modecompta ==
'CREANCES-DETTES') {
234 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
236 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
237 $sql .=
" WHERE f.fk_soc = s.rowid";
238 $sql .=
" AND f.fk_statut IN (1,2)";
240 $sql .=
" AND f.type IN (0,1,2,5)";
242 $sql .=
" AND f.type IN (0,1,2,3,5)";
245 $hookmanager->initHooks(array(
'turnoverreport'));
246 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
247 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
248 $sql .= $hookmanager->resPrint;
250 $sql .=
" AND f.datef >= '".$db->idate(
$date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
252 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
257 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
259 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
260 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
261 $sql .=
" WHERE p.rowid = pf.fk_paiement";
262 $sql .=
" AND pf.fk_facture = f.rowid";
264 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
267 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
269 $sql .=
" AND f.fk_soc = ".((int) $socid);
271 $sql .=
" GROUP BY dm";
272 $sql .=
" ORDER BY dm";
275 dol_syslog(
"get customers invoices", LOG_DEBUG);
276 $result = $db->query($sql);
278 $num = $db->num_rows($result);
281 $row = $db->fetch_object($result);
282 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
283 $encaiss_ttc[$row->dm] = $row->amount_ttc;
288 dol_print_error($db);
294if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
296 if ($modecompta !=
'CREANCES-DETTES') {
297 $sql =
"SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
298 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
299 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
300 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
301 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
302 $sql .=
" WHERE pf.rowid IS NULL";
303 $sql .=
" AND p.fk_bank = b.rowid";
304 $sql .=
" AND b.fk_account = ba.rowid";
305 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
307 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
309 $sql .=
" GROUP BY dm";
310 $sql .=
" ORDER BY dm";
312 dol_syslog(
"get old customers payments not linked to invoices", LOG_DEBUG);
313 $result = $db->query($sql);
315 $num = $db->num_rows($result);
318 $row = $db->fetch_object($result);
320 if (!isset($encaiss[$row->dm])) {
321 $encaiss[$row->dm] = 0;
323 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
325 if (!isset($encaiss_ttc[$row->dm])) {
326 $encaiss_ttc[$row->dm] = 0;
328 $encaiss_ttc[$row->dm] += $row->amount_ttc;
333 dol_print_error($db);
349if (
isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
350 if ($modecompta ==
'CREANCES-DETTES') {
351 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
352 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
353 $sql .=
" WHERE f.fk_statut IN (1,2)";
355 $sql .=
" AND f.type IN (0,1,2)";
357 $sql .=
" AND f.type IN (0,1,2,3)";
360 $hookmanager->initHooks(array(
'turnoverreport'));
361 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 1,
'datefield' =>
'datef');
362 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
363 $sql .= $hookmanager->resPrint;
365 $sql .=
" AND f.datef >= '".$db->idate(
$date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
367 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
368 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
369 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
370 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
371 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
372 $sql .=
" WHERE f.rowid = pf.fk_facturefourn";
373 $sql .=
" AND p.rowid = pf.fk_paiementfourn";
375 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
378 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
381 $sql .=
" AND f.fk_soc = ".((int) $socid);
383 $sql .=
" GROUP BY dm";
385 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
386 $result = $db->query($sql);
388 $num = $db->num_rows($result);
391 $row = $db->fetch_object($result);
393 if (!isset($decaiss[$row->dm])) {
394 $decaiss[$row->dm] = 0;
396 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
398 if (!isset($decaiss_ttc[$row->dm])) {
399 $decaiss_ttc[$row->dm] = 0;
401 $decaiss_ttc[$row->dm] = $row->amount_ttc;
407 dol_print_error($db);
421if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
422 if ($modecompta ==
'CREANCES-DETTES') {
424 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
425 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
426 $sql .=
" WHERE f.fk_statut IN (1,2)";
428 $sql .=
" AND f.type IN (0,1,2,5)";
430 $sql .=
" AND f.type IN (0,1,2,3,5)";
433 $hookmanager->initHooks(array(
'turnoverreport'));
434 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 0,
'datefield' =>
'datef');
435 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
436 $sql .= $hookmanager->resPrint;
437 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
439 $sql .=
" AND f.datef >= '".$db->idate(
$date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
441 $sql .=
" GROUP BY dm";
444 $result = $db->query($sql);
446 $num = $db->num_rows($result);
450 $obj = $db->fetch_object($result);
457 if (!isset($decaiss_ttc[$obj->dm])) {
458 $decaiss_ttc[$obj->dm] = 0;
460 $decaiss_ttc[$obj->dm] += $obj->amount;
466 dol_print_error($db);
469 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
471 $sql .=
" WHERE f.fk_statut IN (1,2)";
473 $sql .=
" AND f.type IN (0,1,2)";
475 $sql .=
" AND f.type IN (0,1,2,3)";
478 $hookmanager->initHooks(array(
'turnoverreport'));
479 $parameters = array(
'invoicealias' =>
'f',
'issupplier' => 1,
'datefield' =>
'datef');
480 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
481 $sql .= $hookmanager->resPrint;
482 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
484 $sql .=
" AND f.datef >= '".$db->idate(
$date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
486 $sql .=
" GROUP BY dm";
488 dol_syslog(
"get vat to receive back", LOG_DEBUG);
489 $result = $db->query($sql);
491 $num = $db->num_rows($result);
495 $obj = $db->fetch_object($result);
502 if (!isset($encaiss_ttc[$obj->dm])) {
503 $encaiss_ttc[$obj->dm] = 0;
505 $encaiss_ttc[$obj->dm] += $obj->amount;
511 dol_print_error($db);
513 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
515 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
516 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
517 $sql .=
" WHERE amount > 0";
518 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
520 $sql .=
" AND t.datev >= '".$db->idate(
$date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
522 $sql .=
" GROUP BY dm";
525 $result = $db->query($sql);
527 $num = $db->num_rows($result);
531 $obj = $db->fetch_object($result);
538 if (!isset($decaiss_ttc[$obj->dm])) {
539 $decaiss_ttc[$obj->dm] = 0;
541 $decaiss_ttc[$obj->dm] += $obj->amount;
547 dol_print_error($db);
550 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
552 $sql .=
" WHERE amount < 0";
553 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
555 $sql .=
" AND t.datev >= '".$db->idate(
$date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
557 $sql .=
" GROUP BY dm";
559 dol_syslog(
"get vat really received back", LOG_DEBUG);
560 $result = $db->query($sql);
562 $num = $db->num_rows($result);
566 $obj = $db->fetch_object($result);
573 if (!isset($encaiss_ttc[$obj->dm])) {
574 $encaiss_ttc[$obj->dm] = 0;
576 $encaiss_ttc[$obj->dm] += -$obj->amount;
582 dol_print_error($db);
595if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
596 if ($modecompta ==
'CREANCES-DETTES') {
597 $sql =
"SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
598 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
599 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
600 $sql .=
" WHERE cs.fk_type = c.id";
602 $sql .=
" AND cs.date_ech >= '".$db->idate(
$date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
604 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
605 $sql =
"SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
606 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
607 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
608 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
609 $sql .=
" WHERE p.fk_charge = cs.rowid";
610 $sql .=
" AND cs.fk_type = c.id";
612 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
616 $sql .=
" AND cs.entity IN (".getEntity(
'social_contributions').
")";
617 $sql .=
" GROUP BY c.libelle, dm";
619 dol_syslog(
"get social contributions", LOG_DEBUG);
620 $result = $db->query($sql);
622 $num = $db->num_rows($result);
626 $obj = $db->fetch_object($result);
628 if (!isset($decaiss[$obj->dm])) {
629 $decaiss[$obj->dm] = 0;
631 $decaiss[$obj->dm] += $obj->amount;
633 if (!isset($decaiss_ttc[$obj->dm])) {
634 $decaiss_ttc[$obj->dm] = 0;
636 $decaiss_ttc[$obj->dm] += $obj->amount;
642 dol_print_error($db);
653if (
isModEnabled(
'salaries') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
655 if ($modecompta ==
'CREANCES-DETTES') {
656 $column =
's.dateep';
658 $sql =
"SELECT s.label as nom, date_format(".$db->sanitize($column).
",'%Y-%m') as dm, sum(s.amount) as amount";
659 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
660 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
662 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate(
$date_start).
"' AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
664 $sql .=
" GROUP BY s.label, dm";
666 if ($modecompta ==
"RECETTES-DEPENSES") {
669 $sql =
"SELECT p.label as nom, date_format(".$db->sanitize($column).
",'%Y-%m') as dm, sum(p.amount) as amount";
670 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
671 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON p.fk_salary = s.rowid";
672 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
674 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate(
$date_start).
"' AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
676 $sql .=
" GROUP BY p.label, dm";
683 $result = $db->query($sql);
685 $num = $db->num_rows($result);
689 $obj = $db->fetch_object($result);
691 if (!isset($decaiss[$obj->dm])) {
692 $decaiss[$obj->dm] = 0;
694 $decaiss[$obj->dm] += $obj->amount;
696 if (!isset($decaiss_ttc[$obj->dm])) {
697 $decaiss_ttc[$obj->dm] = 0;
699 $decaiss_ttc[$obj->dm] += $obj->amount;
705 dol_print_error($db);
716if (
isModEnabled(
'expensereport') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
717 $langs->load(
'trips');
719 if ($modecompta ==
'CREANCES-DETTES') {
720 $sql =
"SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
721 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
722 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
723 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
724 $sql .=
" AND p.fk_statut>=5";
726 $column =
'p.date_valid';
728 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate(
$date_start).
"' AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
730 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
731 $sql =
"SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
732 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
733 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
734 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
735 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
736 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
737 $sql .=
" AND p.fk_statut >= 5";
739 $column =
'pe.datep';
741 $sql .=
" AND ".$db->sanitize($column).
" >= '".$db->idate(
$date_start).
"' AND ".$db->sanitize($column).
" <= '".$db->idate($date_end).
"'";
745 $sql .=
" GROUP BY dm";
748 $result = $db->query($sql);
752 $num = $db->num_rows($result);
754 while ($obj = $db->fetch_object($result)) {
755 if (!isset($decaiss[$obj->dm])) {
756 $decaiss[$obj->dm] = 0;
758 $decaiss[$obj->dm] += $obj->amount_ht;
760 if (!isset($decaiss_ttc[$obj->dm])) {
761 $decaiss_ttc[$obj->dm] = 0;
763 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
767 dol_print_error($db);
778if (
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
782 if ($modecompta ==
'CREANCES-DETTES') {
783 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
784 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
785 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
786 $sql .=
" AND fk_statut in (1,2)";
788 $sql .=
" AND p.datedon >= '".$db->idate(
$date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
790 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
791 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
792 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
793 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
794 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
795 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
796 $sql .=
" AND fk_statut >= 2";
798 $sql .=
" AND pe.datep >= '".$db->idate(
$date_start).
"' AND pe.datep <= '".$db->idate($date_end).
"'";
802 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
805 $result = $db->query($sql);
807 $num = $db->num_rows($result);
811 $obj = $db->fetch_object($result);
813 if (!isset($encaiss[$obj->dm])) {
814 $encaiss[$obj->dm] = 0;
816 $encaiss[$obj->dm] += $obj->amount;
818 if (!isset($encaiss_ttc[$obj->dm])) {
819 $encaiss_ttc[$obj->dm] = 0;
821 $encaiss_ttc[$obj->dm] += $obj->amount;
827 dol_print_error($db);
837if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') &&
isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
840 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
841 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
842 $sql .=
' AND p.sens = 0';
844 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
846 $sql .=
' GROUP BY dm';
849 $result = $db->query($sql);
851 $num = $db->num_rows($result);
855 $obj = $db->fetch_object($result);
856 if (!isset($decaiss_ttc[$obj->dm])) {
857 $decaiss_ttc[$obj->dm] = 0;
859 if (isset($obj->amount)) {
860 $decaiss_ttc[$obj->dm] += $obj->amount;
866 dol_print_error($db);
871 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various AS p";
872 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
873 $sql .=
' AND p.sens = 1';
875 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
877 $sql .=
' GROUP BY dm';
880 $result = $db->query($sql);
882 $num = $db->num_rows($result);
886 $obj = $db->fetch_object($result);
887 if (!isset($encaiss_ttc[$obj->dm])) {
888 $encaiss_ttc[$obj->dm] = 0;
890 if (isset($obj->amount)) {
891 $encaiss_ttc[$obj->dm] += $obj->amount;
897 dol_print_error($db);
908if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') &&
isModEnabled(
'loan') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
909 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
910 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan AS p, ".MAIN_DB_PREFIX.
"loan as l";
911 $sql .=
" WHERE l.entity IN (".getEntity(
'variouspayment').
")";
912 $sql .=
" AND p.fk_loan = l.rowid";
914 $sql .=
" AND p.datep >= '".$db->idate(
$date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
916 $sql .=
' GROUP BY dm';
919 $result = $db->query($sql);
921 $num = $db->num_rows($result);
925 $obj = $db->fetch_object($result);
926 if (!isset($decaiss_ttc[$obj->dm])) {
927 $decaiss_ttc[$obj->dm] = 0;
929 if (isset($obj->amount)) {
930 $decaiss_ttc[$obj->dm] += $obj->amount;
936 dol_print_error($db);
948if (
isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
953 $sanitizedpredefinedgroupwhere =
"(";
954 $sanitizedpredefinedgroupwhere .=
" (aa.pcg_type IN ('EXPENSE', 'COGS', 'OTHER_EXPENSES'))";
955 $sanitizedpredefinedgroupwhere .=
" OR ";
956 $sanitizedpredefinedgroupwhere .=
" (aa.pcg_type IN ('INCOME', 'OTHER_REVENUE'))";
957 $sanitizedpredefinedgroupwhere .=
")";
962 $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";
963 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_account as aa";
964 $sql .=
" WHERE b.entity = ".((int)
$conf->entity);
965 $sql .=
" AND aa.entity = ".((int)
$conf->entity);
966 $sql .=
" AND b.numero_compte = aa.account_number";
967 $sql .=
" AND ".$sanitizedpredefinedgroupwhere;
968 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
970 $sql .=
" AND b.doc_date >= '".$db->idate(
$date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
972 $sql .=
" GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
979 $result = $db->query($sql);
981 $num = $db->num_rows($result);
985 $obj = $db->fetch_object($result);
987 if (in_array($obj->pcg_type, array(
'INCOME',
'OTHER_REVENUE'))) {
988 if (!isset($encaiss[$obj->dm])) {
989 $encaiss[$obj->dm] = 0;
991 $encaiss[$obj->dm] += $obj->credit;
992 $encaiss[$obj->dm] -= $obj->debit;
994 if (in_array($obj->pcg_type, array(
'EXPENSE',
'COGS',
'OTHER_EXPENSES'))) {
995 if (!isset($decaiss[$obj->dm])) {
996 $decaiss[$obj->dm] = 0;
998 $decaiss[$obj->dm] += $obj->debit;
999 $decaiss[$obj->dm] -= $obj->credit;
1003 if (!isset($encaiss_ttc[$obj->dm])) {
1004 $encaiss_ttc[$obj->dm] = 0;
1006 if (!isset($decaiss_ttc[$obj->dm])) {
1007 $decaiss_ttc[$obj->dm] = 0;
1009 $encaiss_ttc[$obj->dm] += 0;
1010 $decaiss_ttc[$obj->dm] += 0;
1016 dol_print_error($db);
1023$object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
1024$parameters = array();
1025$parameters[
"mode"] = $modecompta;
1027$hookmanager->initHooks(array(
'externalbalance'));
1028$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
1036$totentrees = array();
1037$totsorties = array();
1038$year_end_for_table = ($year_end - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1040print
'<div class="div-table-responsive">';
1041print
'<table class="tagtable liste">'.
"\n";
1043print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1045for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1046 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1047 print
'<a href="clientfourn.php?year='.((int) $annee).
'">';
1050 print
'-'.($annee + 1);
1055print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1057for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1058 print
'<td class="liste_titre" align="center">';
1061 print $form->textwithpicto($langs->trans(
"Outcome"), $htmlhelp);
1063 print
'<td class="liste_titre" align="center" class="borderrightlight">';
1066 print $form->textwithpicto($langs->trans(
"Income"), $htmlhelp);
1073$nb_mois_decalage =
$conf->global->SOCIETE_FISCAL_MONTH_START ? (
$conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1074for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1075 $mois_modulo = $mois;
1077 $mois_modulo = $mois - 12;
1080 print
'<tr class="oddeven">';
1081 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, $year_start),
"%B").
"</td>";
1082 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1083 $annee_decalage = $annee;
1085 $annee_decalage = $annee + 1;
1089 print
'<td class="right">';
1090 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1091 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1092 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.
'&modecompta='.$modecompta.
'">'.
price(
price2num($decaiss[$case],
'MT')).
'</a>';
1093 if (!isset($totsorties[$annee])) {
1094 $totsorties[$annee] = 0;
1096 $totsorties[$annee] += $decaiss[$case];
1099 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1100 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss_ttc[$case],
'MT')).
'</a>';
1101 if (!isset($totsorties[$annee])) {
1102 $totsorties[$annee] = 0;
1104 $totsorties[$annee] += $decaiss_ttc[$case];
1109 print
'<td class="borderrightlight nowrap right">';
1110 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1111 if (isset($encaiss[$case])) {
1112 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.
'&modecompta='.$modecompta.
'">'.
price(
price2num($encaiss[$case],
'MT')).
'</a>';
1113 if (!isset($totentrees[$annee])) {
1114 $totentrees[$annee] = 0;
1116 $totentrees[$annee] += $encaiss[$case];
1119 if (isset($encaiss_ttc[$case])) {
1120 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss_ttc[$case],
'MT')).
'</a>';
1121 if (!isset($totentrees[$annee])) {
1122 $totentrees[$annee] = 0;
1124 $totentrees[$annee] += $encaiss_ttc[$case];
1136print
'<tr class="liste_total impair"><td>';
1137if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1138 print $langs->trans(
"Total");
1140 print $langs->trans(
"TotalTTC");
1143for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1145 print
'<td class="nowrap right">'.(isset($totsorties[$annee]) ?
price(
price2num($totsorties[$annee],
'MT')) :
' ').
'</td>';
1146 print
'<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?
price(
price2num($totentrees[$annee],
'MT')) :
' ').
'</td>';
1151print
'<tr class="impair"><td> </td>';
1152print
'<td colspan="'.$nbcols.
'"> </td>';
1157print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1158for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1159 print
'<td colspan="2" class="borderrightlight right"> ';
1160 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1161 $in = (isset($totentrees[$annee]) ?
price2num($totentrees[$annee],
'MT') : 0);
1162 $out = (isset($totsorties[$annee]) ?
price2num($totsorties[$annee],
'MT') : 0);
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
img_next($titlealt='default', $moreatt='')
Show next logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.