32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
40$date_startmonth =
GETPOSTINT(
'date_startmonth');
57 $year_start = $year_current - ($nbofyear - 1);
59 $year_current = $year;
61 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
63$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
64$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
67if (empty($date_start) || empty($date_end)) {
71 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
74 if (!$year && $month_start > $month_current) {
78 $month_end = $month_start - 1;
83 $month_end = $month_start;
108$year_start = $tmps[
'year'];
110$year_end = $tmpe[
'year'];
111$nbofyear = ($year_end - $year_start) + 1;
116if (isModEnabled(
'accounting')) {
117 $modecompta =
'BOOKKEEPING';
119if (
GETPOST(
"modecompta",
'alpha')) {
120 $modecompta =
GETPOST(
"modecompta",
'alpha');
125if ($user->socid > 0) {
126 $socid = $user->socid;
128if (isModEnabled(
'comptabilite')) {
131if (isModEnabled(
'accounting')) {
132 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
142$form =
new Form($db);
147$encaiss_ttc = array();
149$decaiss_ttc = array();
152if ($modecompta ==
'CREANCES-DETTES') {
153 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
154 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
155 $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>" :
"");
156 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
157 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
159 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
161 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
164 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
168} elseif ($modecompta ==
"RECETTES-DEPENSES") {
169 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
170 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
171 $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>" :
"");
172 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
173 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
176} elseif ($modecompta ==
"BOOKKEEPING") {
177 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
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(
"RulesAmountOnInOutBookkeepingRecord");
181 $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")).
')';
188if (isModEnabled(
'accounting')) {
189 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
192$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
193if (isModEnabled(
'accounting')) {
194 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
196$calcmode .=
'</label>';
197$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
198if (isModEnabled(
'accounting')) {
199 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
201$calcmode .=
'</label>';
204report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
206if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
207 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
218if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
219 if ($modecompta ==
'CREANCES-DETTES') {
220 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
222 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
223 $sql .=
" WHERE f.fk_soc = s.rowid";
224 $sql .=
" AND f.fk_statut IN (1,2)";
226 $sql .=
" AND f.type IN (0,1,2,5)";
228 $sql .=
" AND f.type IN (0,1,2,3,5)";
230 if (!empty($date_start) && !empty($date_end)) {
231 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
233 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
238 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
239 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
240 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
241 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
242 $sql .=
" WHERE p.rowid = pf.fk_paiement";
243 $sql .=
" AND pf.fk_facture = f.rowid";
244 if (!empty($date_start) && !empty($date_end)) {
245 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
248 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
250 $sql .=
" AND f.fk_soc = ".((int) $socid);
252 $sql .=
" GROUP BY dm";
253 $sql .=
" ORDER BY dm";
256 dol_syslog(
"get customers invoices", LOG_DEBUG);
257 $result = $db->query($sql);
259 $num = $db->num_rows($result);
262 $row = $db->fetch_object($result);
263 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
264 $encaiss_ttc[$row->dm] = $row->amount_ttc;
271} elseif ($modecompta ==
"BOOKKEEPING") {
275if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
277 if ($modecompta !=
'CREANCES-DETTES') {
278 $sql =
"SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
280 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
281 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
282 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
283 $sql .=
" WHERE pf.rowid IS NULL";
284 $sql .=
" AND p.fk_bank = b.rowid";
285 $sql .=
" AND b.fk_account = ba.rowid";
286 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
287 if (!empty($date_start) && !empty($date_end)) {
288 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
290 $sql .=
" GROUP BY dm";
291 $sql .=
" ORDER BY dm";
293 dol_syslog(
"get old customers payments not linked to invoices", LOG_DEBUG);
294 $result = $db->query($sql);
296 $num = $db->num_rows($result);
299 $row = $db->fetch_object($result);
301 if (!isset($encaiss[$row->dm])) {
302 $encaiss[$row->dm] = 0;
304 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
306 if (!isset($encaiss_ttc[$row->dm])) {
307 $encaiss_ttc[$row->dm] = 0;
309 $encaiss_ttc[$row->dm] += $row->amount_ttc;
316 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
319} elseif ($modecompta ==
"BOOKKEEPING") {
330if (isModEnabled(
'invoice') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
331 if ($modecompta ==
'CREANCES-DETTES') {
332 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
333 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
334 $sql .=
" WHERE f.fk_statut IN (1,2)";
336 $sql .=
" AND f.type IN (0,1,2)";
338 $sql .=
" AND f.type IN (0,1,2,3)";
340 if (!empty($date_start) && !empty($date_end)) {
341 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
343 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
344 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
346 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
347 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
348 $sql .=
" WHERE f.rowid = pf.fk_facturefourn";
349 $sql .=
" AND p.rowid = pf.fk_paiementfourn";
350 if (!empty($date_start) && !empty($date_end)) {
351 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
354 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
357 $sql .=
" AND f.fk_soc = ".((int) $socid);
359 $sql .=
" GROUP BY dm";
361 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
362 $result = $db->query($sql);
364 $num = $db->num_rows($result);
367 $row = $db->fetch_object($result);
369 if (!isset($decaiss[$row->dm])) {
370 $decaiss[$row->dm] = 0;
372 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
374 if (!isset($decaiss_ttc[$row->dm])) {
375 $decaiss_ttc[$row->dm] = 0;
377 $decaiss_ttc[$row->dm] = $row->amount_ttc;
385} elseif ($modecompta ==
"BOOKKEEPING") {
397if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
398 if ($modecompta ==
'CREANCES-DETTES') {
400 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
401 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
402 $sql .=
" WHERE f.fk_statut IN (1,2)";
404 $sql .=
" AND f.type IN (0,1,2,5)";
406 $sql .=
" AND f.type IN (0,1,2,3,5)";
408 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
409 if (!empty($date_start) && !empty($date_end)) {
410 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
412 $sql .=
" GROUP BY dm";
415 $result = $db->query($sql);
417 $num = $db->num_rows($result);
421 $obj = $db->fetch_object($result);
428 if (!isset($decaiss_ttc[$obj->dm])) {
429 $decaiss_ttc[$obj->dm] = 0;
431 $decaiss_ttc[$obj->dm] += $obj->amount;
440 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
441 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
442 $sql .=
" WHERE f.fk_statut IN (1,2)";
444 $sql .=
" AND f.type IN (0,1,2)";
446 $sql .=
" AND f.type IN (0,1,2,3)";
448 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
449 if (!empty($date_start) && !empty($date_end)) {
450 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
452 $sql .=
" GROUP BY dm";
454 dol_syslog(
"get vat to receive back", LOG_DEBUG);
455 $result = $db->query($sql);
457 $num = $db->num_rows($result);
461 $obj = $db->fetch_object($result);
468 if (!isset($encaiss_ttc[$obj->dm])) {
469 $encaiss_ttc[$obj->dm] = 0;
471 $encaiss_ttc[$obj->dm] += $obj->amount;
479 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
481 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
482 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
483 $sql .=
" WHERE amount > 0";
484 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
485 if (!empty($date_start) && !empty($date_end)) {
486 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
488 $sql .=
" GROUP BY dm";
491 $result = $db->query($sql);
493 $num = $db->num_rows($result);
497 $obj = $db->fetch_object($result);
504 if (!isset($decaiss_ttc[$obj->dm])) {
505 $decaiss_ttc[$obj->dm] = 0;
507 $decaiss_ttc[$obj->dm] += $obj->amount;
516 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
517 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
518 $sql .=
" WHERE amount < 0";
519 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
520 if (!empty($date_start) && !empty($date_end)) {
521 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
523 $sql .=
" GROUP BY dm";
525 dol_syslog(
"get vat really received back", LOG_DEBUG);
526 $result = $db->query($sql);
528 $num = $db->num_rows($result);
532 $obj = $db->fetch_object($result);
539 if (!isset($encaiss_ttc[$obj->dm])) {
540 $encaiss_ttc[$obj->dm] = 0;
542 $encaiss_ttc[$obj->dm] += -$obj->amount;
551} elseif ($modecompta ==
"BOOKKEEPING") {
561if (isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
562 if ($modecompta ==
'CREANCES-DETTES') {
563 $sql =
"SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
564 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
565 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
566 $sql .=
" WHERE cs.fk_type = c.id";
567 if (!empty($date_start) && !empty($date_end)) {
568 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
570 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
571 $sql =
"SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
572 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
573 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
574 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
575 $sql .=
" WHERE p.fk_charge = cs.rowid";
576 $sql .=
" AND cs.fk_type = c.id";
577 if (!empty($date_start) && !empty($date_end)) {
578 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
582 $sql .=
" AND cs.entity IN (".getEntity(
'social_contributions').
")";
583 $sql .=
" GROUP BY c.libelle, dm";
585 dol_syslog(
"get social contributions", LOG_DEBUG);
586 $result = $db->query($sql);
588 $num = $db->num_rows($result);
592 $obj = $db->fetch_object($result);
594 if (!isset($decaiss[$obj->dm])) {
595 $decaiss[$obj->dm] = 0;
597 $decaiss[$obj->dm] += $obj->amount;
599 if (!isset($decaiss_ttc[$obj->dm])) {
600 $decaiss_ttc[$obj->dm] = 0;
602 $decaiss_ttc[$obj->dm] += $obj->amount;
610} elseif ($modecompta ==
"BOOKKEEPING") {
619if (isModEnabled(
'salaries') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
620 if ($modecompta ==
'CREANCES-DETTES') {
621 $column =
's.dateep';
623 $sql =
"SELECT s.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(s.amount) as amount";
624 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
625 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
626 if (!empty($date_start) && !empty($date_end)) {
627 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
629 $sql .=
" GROUP BY s.label, dm";
631 if ($modecompta ==
"RECETTES-DEPENSES") {
634 $sql =
"SELECT p.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(p.amount) as amount";
635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
636 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON p.fk_salary = s.rowid";
637 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
638 if (!empty($date_start) && !empty($date_end)) {
639 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
641 $sql .=
" GROUP BY p.label, dm";
648 $result = $db->query($sql);
650 $num = $db->num_rows($result);
654 $obj = $db->fetch_object($result);
656 if (!isset($decaiss[$obj->dm])) {
657 $decaiss[$obj->dm] = 0;
659 $decaiss[$obj->dm] += $obj->amount;
661 if (!isset($decaiss_ttc[$obj->dm])) {
662 $decaiss_ttc[$obj->dm] = 0;
664 $decaiss_ttc[$obj->dm] += $obj->amount;
672} elseif ($modecompta ==
"BOOKKEEPING") {
681if (isModEnabled(
'expensereport') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
682 $langs->load(
'trips');
684 if ($modecompta ==
'CREANCES-DETTES') {
685 $sql =
"SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
686 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
687 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
688 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
689 $sql .=
" AND p.fk_statut>=5";
691 $column =
'p.date_valid';
692 if (!empty($date_start) && !empty($date_end)) {
693 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
695 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
696 $sql =
"SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
697 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
698 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
699 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
700 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
701 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
702 $sql .=
" AND p.fk_statut>=5";
704 $column =
'pe.datep';
705 if (!empty($date_start) && !empty($date_end)) {
706 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
710 $sql .=
" GROUP BY dm";
713 $result = $db->query($sql);
717 $num = $db->num_rows($result);
719 while ($obj = $db->fetch_object($result)) {
720 if (!isset($decaiss[$obj->dm])) {
721 $decaiss[$obj->dm] = 0;
723 $decaiss[$obj->dm] += $obj->amount_ht;
725 if (!isset($decaiss_ttc[$obj->dm])) {
726 $decaiss_ttc[$obj->dm] = 0;
728 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
734} elseif ($modecompta ==
'BOOKKEEPING') {
743if (isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
747 if ($modecompta ==
'CREANCES-DETTES') {
748 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
749 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
750 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
751 $sql .=
" AND fk_statut in (1,2)";
752 if (!empty($date_start) && !empty($date_end)) {
753 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
755 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
756 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
757 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
758 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
759 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
760 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
761 $sql .=
" AND fk_statut >= 2";
762 if (!empty($date_start) && !empty($date_end)) {
763 $sql .=
" AND pe.datep >= '".$db->idate($date_start).
"' AND pe.datep <= '".$db->idate($date_end).
"'";
767 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
770 $result = $db->query($sql);
772 $num = $db->num_rows($result);
776 $obj = $db->fetch_object($result);
778 if (!isset($encaiss[$obj->dm])) {
779 $encaiss[$obj->dm] = 0;
781 $encaiss[$obj->dm] += $obj->amount;
783 if (!isset($encaiss_ttc[$obj->dm])) {
784 $encaiss_ttc[$obj->dm] = 0;
786 $encaiss_ttc[$obj->dm] += $obj->amount;
794} elseif ($modecompta ==
'BOOKKEEPING') {
802if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
805 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
806 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
807 $sql .=
' AND p.sens = 0';
808 if (!empty($date_start) && !empty($date_end)) {
809 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
811 $sql .=
' GROUP BY dm';
814 $result = $db->query($sql);
816 $num = $db->num_rows($result);
820 $obj = $db->fetch_object($result);
821 if (!isset($decaiss_ttc[$obj->dm])) {
822 $decaiss_ttc[$obj->dm] = 0;
824 if (isset($obj->amount)) {
825 $decaiss_ttc[$obj->dm] += $obj->amount;
836 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various AS p";
837 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
838 $sql .=
' AND p.sens = 1';
839 if (!empty($date_start) && !empty($date_end)) {
840 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
842 $sql .=
' GROUP BY dm';
845 $result = $db->query($sql);
847 $num = $db->num_rows($result);
851 $obj = $db->fetch_object($result);
852 if (!isset($encaiss_ttc[$obj->dm])) {
853 $encaiss_ttc[$obj->dm] = 0;
855 if (isset($obj->amount)) {
856 $encaiss_ttc[$obj->dm] += $obj->amount;
873if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled(
'loan') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
874 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
875 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan AS p, ".MAIN_DB_PREFIX.
"loan as l";
876 $sql .=
" WHERE l.entity IN (".getEntity(
'variouspayment').
")";
877 $sql .=
" AND p.fk_loan = l.rowid";
878 if (!empty($date_start) && !empty($date_end)) {
879 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
881 $sql .=
' GROUP BY dm';
884 $result = $db->query($sql);
886 $num = $db->num_rows($result);
890 $obj = $db->fetch_object($result);
891 if (!isset($decaiss_ttc[$obj->dm])) {
892 $decaiss_ttc[$obj->dm] = 0;
894 if (isset($obj->amount)) {
895 $decaiss_ttc[$obj->dm] += $obj->amount;
913if (isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
914 $predefinedgroupwhere =
"(";
915 $predefinedgroupwhere .=
" (aa.pcg_type = 'EXPENSE')";
916 $predefinedgroupwhere .=
" OR ";
917 $predefinedgroupwhere .=
" (aa.pcg_type = 'INCOME')";
918 $predefinedgroupwhere .=
")";
923 $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";
924 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_account as aa";
925 $sql .=
" WHERE b.entity = ".$conf->entity;
926 $sql .=
" AND aa.entity = ".$conf->entity;
927 $sql .=
" AND b.numero_compte = aa.account_number";
928 $sql .=
" AND ".$predefinedgroupwhere;
929 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
930 if (!empty($date_start) && !empty($date_end)) {
931 $sql .=
" AND b.doc_date >= '".$db->idate($date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
933 $sql .=
" GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
940 $result = $db->query($sql);
942 $num = $db->num_rows($result);
946 $obj = $db->fetch_object($result);
948 if ($obj->pcg_type ==
'INCOME') {
949 if (!isset($encaiss[$obj->dm])) {
950 $encaiss[$obj->dm] = 0;
952 $encaiss[$obj->dm] += $obj->credit;
953 $encaiss[$obj->dm] -= $obj->debit;
955 if ($obj->pcg_type ==
'EXPENSE') {
956 if (!isset($decaiss[$obj->dm])) {
957 $decaiss[$obj->dm] = 0;
959 $decaiss[$obj->dm] += $obj->debit;
960 $decaiss[$obj->dm] -= $obj->credit;
964 if (!isset($encaiss_ttc[$obj->dm])) {
965 $encaiss_ttc[$obj->dm] = 0;
967 if (!isset($decaiss_ttc[$obj->dm])) {
968 $decaiss_ttc[$obj->dm] = 0;
970 $encaiss_ttc[$obj->dm] += 0;
971 $decaiss_ttc[$obj->dm] += 0;
984$object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
985$parameters[
"mode"] = $modecompta;
987$hookmanager->initHooks(array(
'externalbalance'));
988$reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
996$totentrees = array();
997$totsorties = array();
998$year_end_for_table = ($year_end - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1000print
'<div class="div-table-responsive">';
1001print
'<table class="tagtable liste">'.
"\n";
1003print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1005for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1006 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1007 print
'<a href="clientfourn.php?year='.((int) $annee).
'">';
1010 print
'-'.($annee + 1);
1015print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1017for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1018 print
'<td class="liste_titre" align="center">';
1021 print $form->textwithpicto($langs->trans(
"Outcome"), $htmlhelp);
1023 print
'<td class="liste_titre" align="center" class="borderrightlight">';
1026 print $form->textwithpicto($langs->trans(
"Income"), $htmlhelp);
1033$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1034for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1035 $mois_modulo = $mois;
1037 $mois_modulo = $mois - 12;
1040 print
'<tr class="oddeven">';
1041 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee),
"%B").
"</td>";
1042 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1043 $annee_decalage = $annee;
1045 $annee_decalage = $annee + 1;
1049 print
'<td class="right">';
1050 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1051 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1052 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss[$case],
'MT')).
'</a>';
1053 if (!isset($totsorties[$annee])) {
1054 $totsorties[$annee] = 0;
1056 $totsorties[$annee] += $decaiss[$case];
1059 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1060 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss_ttc[$case],
'MT')).
'</a>';
1061 if (!isset($totsorties[$annee])) {
1062 $totsorties[$annee] = 0;
1064 $totsorties[$annee] += $decaiss_ttc[$case];
1069 print
'<td class="borderrightlight nowrap right">';
1070 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1071 if (isset($encaiss[$case])) {
1072 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss[$case],
'MT')).
'</a>';
1073 if (!isset($totentrees[$annee])) {
1074 $totentrees[$annee] = 0;
1076 $totentrees[$annee] += $encaiss[$case];
1079 if (isset($encaiss_ttc[$case])) {
1080 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss_ttc[$case],
'MT')).
'</a>';
1081 if (!isset($totentrees[$annee])) {
1082 $totentrees[$annee] = 0;
1084 $totentrees[$annee] += $encaiss_ttc[$case];
1096print
'<tr class="liste_total impair"><td>';
1097if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1098 print $langs->trans(
"Total");
1100 print $langs->trans(
"TotalTTC");
1103for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1105 print
'<td class="nowrap right">'.(isset($totsorties[$annee]) ?
price(
price2num($totsorties[$annee],
'MT')) :
' ').
'</td>';
1106 print
'<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?
price(
price2num($totentrees[$annee],
'MT')) :
' ').
'</td>';
1111print
'<tr class="impair"><td> </td>';
1112print
'<td colspan="'.$nbcols.
'"> </td>';
1117print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1118for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1119 print
'<td colspan="2" class="borderrightlight right"> ';
1120 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1121 $in = (isset($totentrees[$annee]) ?
price2num($totentrees[$annee],
'MT') : 0);
1122 $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()
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 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.
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.