32 require
'../../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
37 $langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
39 $date_startmonth =
GETPOST(
'date_startmonth',
'int');
40 $date_startday =
GETPOST(
'date_startday',
'int');
41 $date_startyear =
GETPOST(
'date_startyear',
'int');
42 $date_endmonth =
GETPOST(
'date_endmonth',
'int');
43 $date_endday =
GETPOST(
'date_endday',
'int');
44 $date_endyear =
GETPOST(
'date_endyear',
'int');
53 $year_start = $year_current - ($nbofyear - 1);
55 $year_current = $year;
57 $year_start = $year - ($nbofyear - 1);
59 $date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
60 $date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
63 if (empty($date_start) || empty($date_end)) {
67 $year_end = $year_start + ($nbofyear - 1);
68 $month_start =
GETPOST(
"month") ?
GETPOST(
"month",
'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
70 if (!
GETPOST(
"year") && $month_start > $month_current) {
74 $month_end = $month_start - 1;
81 $month_end = $month_start;
106 $year_start = $tmps[
'year'];
108 $year_end = $tmpe[
'year'];
109 $nbofyear = ($year_end - $year_start) + 1;
113 $modecompta = $conf->global->ACCOUNTING_MODE;
115 $modecompta =
'BOOKKEEPING';
117 if (
GETPOST(
"modecompta",
'alpha')) {
118 $modecompta =
GETPOST(
"modecompta",
'alpha');
122 $socid =
GETPOST(
'socid',
'int');
123 if ($user->socid > 0) {
124 $socid = $user->socid;
130 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
145 $encaiss_ttc = array();
147 $decaiss_ttc = array();
150 if ($modecompta ==
'CREANCES-DETTES') {
151 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
152 $calcmode = $langs->trans(
"CalcModeDebt");
153 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
154 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
156 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
157 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
159 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
160 $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>" :
"");
161 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
162 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
163 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
164 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
166 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
168 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
169 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
173 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
174 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
175 $calcmode = $langs->trans(
"CalcModeEngagement");
176 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
177 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
179 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInBookkeepingMode",
'{s1}',
'{s2}').
')';
180 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=BOOKKEEPING">',
'</a>'), $calcmode);
182 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
183 $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>" :
"");
184 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
185 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
188 } elseif ($modecompta ==
"BOOKKEEPING") {
189 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
190 $calcmode = $langs->trans(
"CalcModeBookkeeping");
191 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInInputOutputMode",
'{s1}',
'{s2}').
')';
192 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=RECETTES-DEPENSES">',
'</a>'), $calcmode);
193 $calcmode .=
'<br>('.$langs->trans(
"SeeReportInDueDebtMode",
'{s1}',
'{s2}').
')';
194 $calcmode = str_replace(array(
'{s1}',
'{s2}'), array(
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year_start='.$year_start.
'&modecompta=CREANCES-DETTES">',
'</a>'), $calcmode);
195 $period =
$form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.
$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
196 $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>" :
"");
197 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
198 $description .=
' ('.$langs->trans(
"SeePageForSetup", DOL_URL_ROOT.
'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv(
"Accountancy").
' / '.$langs->transnoentitiesnoconv(
"Setup").
' / '.$langs->trans(
"Chartofaccounts")).
')';
203 $hselected =
'report';
205 report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(
'modecompta'=>$modecompta), $calcmode);
207 if (
isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
208 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0, 1);
219 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
220 if ($modecompta ==
'CREANCES-DETTES') {
221 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
223 $sql .=
", ".MAIN_DB_PREFIX.
"facture as f";
224 $sql .=
" WHERE f.fk_soc = s.rowid";
225 $sql .=
" AND f.fk_statut IN (1,2)";
226 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
227 $sql .=
" AND f.type IN (0,1,2,5)";
229 $sql .=
" AND f.type IN (0,1,2,3,5)";
231 if (!empty($date_start) && !empty($date_end)) {
232 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
234 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
239 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
241 $sql .=
", ".MAIN_DB_PREFIX.
"paiement_facture as pf";
242 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
243 $sql .=
" WHERE p.rowid = pf.fk_paiement";
244 $sql .=
" AND pf.fk_facture = f.rowid";
245 if (!empty($date_start) && !empty($date_end)) {
246 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
249 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
251 $sql .=
" AND f.fk_soc = ".((int) $socid);
253 $sql .=
" GROUP BY dm";
254 $sql .=
" ORDER BY dm";
257 dol_syslog(
"get customers invoices", LOG_DEBUG);
258 $result = $db->query($sql);
260 $num = $db->num_rows($result);
263 $row = $db->fetch_object($result);
264 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
265 $encaiss_ttc[$row->dm] = $row->amount_ttc;
272 } elseif ($modecompta ==
"BOOKKEEPING") {
276 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
278 if ($modecompta !=
'CREANCES-DETTES') {
279 $sql =
"SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as b";
281 $sql .=
", ".MAIN_DB_PREFIX.
"bank_account as ba";
282 $sql .=
", ".MAIN_DB_PREFIX.
"paiement as p";
283 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON p.rowid = pf.fk_paiement";
284 $sql .=
" WHERE pf.rowid IS NULL";
285 $sql .=
" AND p.fk_bank = b.rowid";
286 $sql .=
" AND b.fk_account = ba.rowid";
287 $sql .=
" AND ba.entity IN (".getEntity(
'bank_account').
")";
288 if (!empty($date_start) && !empty($date_end)) {
289 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
291 $sql .=
" GROUP BY dm";
292 $sql .=
" ORDER BY dm";
294 dol_syslog(
"get old customers payments not linked to invoices", LOG_DEBUG);
295 $result = $db->query($sql);
297 $num = $db->num_rows($result);
300 $row = $db->fetch_object($result);
302 if (!isset($encaiss[$row->dm])) {
303 $encaiss[$row->dm] = 0;
305 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
307 if (!isset($encaiss_ttc[$row->dm])) {
308 $encaiss_ttc[$row->dm] = 0;
310 $encaiss_ttc[$row->dm] += $row->amount_ttc;
317 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
320 } elseif ($modecompta ==
"BOOKKEEPING") {
331 if (
isModEnabled(
'facture') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
332 if ($modecompta ==
'CREANCES-DETTES') {
333 $sql =
"SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
335 $sql .=
" WHERE f.fk_statut IN (1,2)";
336 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
337 $sql .=
" AND f.type IN (0,1,2)";
339 $sql .=
" AND f.type IN (0,1,2,3)";
341 if (!empty($date_start) && !empty($date_end)) {
342 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
344 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
345 $sql =
"SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
346 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
347 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn as f";
348 $sql .=
", ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf";
349 $sql .=
" WHERE f.rowid = pf.fk_facturefourn";
350 $sql .=
" AND p.rowid = pf.fk_paiementfourn";
351 if (!empty($date_start) && !empty($date_end)) {
352 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
355 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
358 $sql .=
" AND f.fk_soc = ".((int) $socid);
360 $sql .=
" GROUP BY dm";
362 dol_syslog(
"get suppliers invoices", LOG_DEBUG);
363 $result = $db->query($sql);
365 $num = $db->num_rows($result);
368 $row = $db->fetch_object($result);
370 if (!isset($decaiss[$row->dm])) {
371 $decaiss[$row->dm] = 0;
373 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
375 if (!isset($decaiss_ttc[$row->dm])) {
376 $decaiss_ttc[$row->dm] = 0;
378 $decaiss_ttc[$row->dm] = $row->amount_ttc;
386 } elseif ($modecompta ==
"BOOKKEEPING") {
398 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
399 if ($modecompta ==
'CREANCES-DETTES') {
401 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
402 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
403 $sql .=
" WHERE f.fk_statut IN (1,2)";
404 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
405 $sql .=
" AND f.type IN (0,1,2,5)";
407 $sql .=
" AND f.type IN (0,1,2,3,5)";
409 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
410 if (!empty($date_start) && !empty($date_end)) {
411 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
413 $sql .=
" GROUP BY dm";
416 $result = $db->query($sql);
418 $num = $db->num_rows($result);
422 $obj = $db->fetch_object($result);
429 if (!isset($decaiss_ttc[$obj->dm])) {
430 $decaiss_ttc[$obj->dm] = 0;
432 $decaiss_ttc[$obj->dm] += $obj->amount;
441 $sql =
"SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
442 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
443 $sql .=
" WHERE f.fk_statut IN (1,2)";
444 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
445 $sql .=
" AND f.type IN (0,1,2)";
447 $sql .=
" AND f.type IN (0,1,2,3)";
449 $sql .=
" AND f.entity IN (".getEntity(
'supplier_invoice').
")";
450 if (!empty($date_start) && !empty($date_end)) {
451 $sql .=
" AND f.datef >= '".$db->idate($date_start).
"' AND f.datef <= '".$db->idate($date_end).
"'";
453 $sql .=
" GROUP BY dm";
455 dol_syslog(
"get vat to receive back", LOG_DEBUG);
456 $result = $db->query($sql);
458 $num = $db->num_rows($result);
462 $obj = $db->fetch_object($result);
469 if (!isset($encaiss_ttc[$obj->dm])) {
470 $encaiss_ttc[$obj->dm] = 0;
472 $encaiss_ttc[$obj->dm] += $obj->amount;
480 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
482 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
483 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
484 $sql .=
" WHERE amount > 0";
485 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
486 if (!empty($date_start) && !empty($date_end)) {
487 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
489 $sql .=
" GROUP BY dm";
492 $result = $db->query($sql);
494 $num = $db->num_rows($result);
498 $obj = $db->fetch_object($result);
505 if (!isset($decaiss_ttc[$obj->dm])) {
506 $decaiss_ttc[$obj->dm] = 0;
508 $decaiss_ttc[$obj->dm] += $obj->amount;
517 $sql =
"SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
519 $sql .=
" WHERE amount < 0";
520 $sql .=
" AND t.entity IN (".getEntity(
'vat').
")";
521 if (!empty($date_start) && !empty($date_end)) {
522 $sql .=
" AND t.datev >= '".$db->idate($date_start).
"' AND t.datev <= '".$db->idate($date_end).
"'";
524 $sql .=
" GROUP BY dm";
526 dol_syslog(
"get vat really received back", LOG_DEBUG);
527 $result = $db->query($sql);
529 $num = $db->num_rows($result);
533 $obj = $db->fetch_object($result);
540 if (!isset($encaiss_ttc[$obj->dm])) {
541 $encaiss_ttc[$obj->dm] = 0;
543 $encaiss_ttc[$obj->dm] += -$obj->amount;
552 } elseif ($modecompta ==
"BOOKKEEPING") {
562 if (
isModEnabled(
'tax') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
563 if ($modecompta ==
'CREANCES-DETTES') {
564 $sql =
"SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
565 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
566 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
567 $sql .=
" WHERE cs.fk_type = c.id";
568 if (!empty($date_start) && !empty($date_end)) {
569 $sql .=
" AND cs.date_ech >= '".$db->idate($date_start).
"' AND cs.date_ech <= '".$db->idate($date_end).
"'";
571 } elseif ($modecompta ==
"RECETTES-DEPENSES") {
572 $sql =
"SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
573 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_chargesociales as c";
574 $sql .=
", ".MAIN_DB_PREFIX.
"chargesociales as cs";
575 $sql .=
", ".MAIN_DB_PREFIX.
"paiementcharge as p";
576 $sql .=
" WHERE p.fk_charge = cs.rowid";
577 $sql .=
" AND cs.fk_type = c.id";
578 if (!empty($date_start) && !empty($date_end)) {
579 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
583 $sql .=
" AND cs.entity IN (".getEntity(
'social_contributions').
")";
584 $sql .=
" GROUP BY c.libelle, dm";
586 dol_syslog(
"get social contributions", LOG_DEBUG);
587 $result = $db->query($sql);
589 $num = $db->num_rows($result);
593 $obj = $db->fetch_object($result);
595 if (!isset($decaiss[$obj->dm])) {
596 $decaiss[$obj->dm] = 0;
598 $decaiss[$obj->dm] += $obj->amount;
600 if (!isset($decaiss_ttc[$obj->dm])) {
601 $decaiss_ttc[$obj->dm] = 0;
603 $decaiss_ttc[$obj->dm] += $obj->amount;
611 } elseif ($modecompta ==
"BOOKKEEPING") {
620 if (
isModEnabled(
'salaries') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
621 if ($modecompta ==
'CREANCES-DETTES') {
622 $column =
's.dateep';
624 $sql =
"SELECT s.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(s.amount) as amount";
625 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
626 $sql .=
" WHERE s.entity IN (".getEntity(
'salary').
")";
627 if (!empty($date_start) && !empty($date_end)) {
628 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
630 $sql .=
" GROUP BY s.label, dm";
632 if ($modecompta ==
"RECETTES-DEPENSES") {
635 $sql =
"SELECT p.label as nom, date_format(".$column.
",'%Y-%m') as dm, sum(p.amount) as amount";
636 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_salary as p";
637 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"salary as s ON p.fk_salary = s.rowid";
638 $sql .=
" WHERE p.entity IN (".getEntity(
'payment_salary').
")";
639 if (!empty($date_start) && !empty($date_end)) {
640 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
642 $sql .=
" GROUP BY p.label, dm";
649 $result = $db->query($sql);
651 $num = $db->num_rows($result);
655 $obj = $db->fetch_object($result);
657 if (!isset($decaiss[$obj->dm])) {
658 $decaiss[$obj->dm] = 0;
660 $decaiss[$obj->dm] += $obj->amount;
662 if (!isset($decaiss_ttc[$obj->dm])) {
663 $decaiss_ttc[$obj->dm] = 0;
665 $decaiss_ttc[$obj->dm] += $obj->amount;
673 } elseif ($modecompta ==
"BOOKKEEPING") {
682 if (!
isModEnabled(
'expensereport') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
683 $langs->load(
'trips');
685 if ($modecompta ==
'CREANCES-DETTES') {
686 $sql =
"SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
687 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
688 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
689 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
690 $sql .=
" AND p.fk_statut>=5";
692 $column =
'p.date_valid';
693 if (!empty($date_start) && !empty($date_end)) {
694 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
696 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
697 $sql =
"SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
698 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as p";
699 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid=p.fk_user_author";
700 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
701 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
702 $sql .=
" WHERE p.entity IN (".getEntity(
'expensereport').
")";
703 $sql .=
" AND p.fk_statut>=5";
705 $column =
'pe.datep';
706 if (!empty($date_start) && !empty($date_end)) {
707 $sql .=
" AND ".$column.
" >= '".$db->idate($date_start).
"' AND ".$column.
" <= '".$db->idate($date_end).
"'";
711 $sql .=
" GROUP BY dm";
714 $result = $db->query($sql);
718 $num = $db->num_rows($result);
720 while ($obj = $db->fetch_object($result)) {
721 if (!isset($decaiss[$obj->dm])) {
722 $decaiss[$obj->dm] = 0;
724 $decaiss[$obj->dm] += $obj->amount_ht;
726 if (!isset($decaiss_ttc[$obj->dm])) {
727 $decaiss_ttc[$obj->dm] = 0;
729 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
735 } elseif ($modecompta ==
'BOOKKEEPING') {
744 if (
isModEnabled(
'don') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
748 if ($modecompta ==
'CREANCES-DETTES') {
749 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
750 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
751 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
752 $sql .=
" AND fk_statut in (1,2)";
753 if (!empty($date_start) && !empty($date_end)) {
754 $sql .=
" AND p.datedon >= '".$db->idate($date_start).
"' AND p.datedon <= '".$db->idate($date_end).
"'";
756 } elseif ($modecompta ==
'RECETTES-DEPENSES') {
757 $sql =
"SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
758 $sql .=
" FROM ".MAIN_DB_PREFIX.
"don as p";
759 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"payment_donation as pe ON pe.fk_donation = p.rowid";
760 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as c ON pe.fk_typepayment = c.id";
761 $sql .=
" WHERE p.entity IN (".getEntity(
'donation').
")";
762 $sql .=
" AND fk_statut >= 2";
763 if (!empty($date_start) && !empty($date_end)) {
764 $sql .=
" AND pe.datep >= '".$db->idate($date_start).
"' AND pe.datep <= '".$db->idate($date_end).
"'";
768 $sql .=
" GROUP BY p.societe, p.firstname, p.lastname, dm";
771 $result = $db->query($sql);
773 $num = $db->num_rows($result);
777 $obj = $db->fetch_object($result);
779 if (!isset($encaiss[$obj->dm])) {
780 $encaiss[$obj->dm] = 0;
782 $encaiss[$obj->dm] += $obj->amount;
784 if (!isset($encaiss_ttc[$obj->dm])) {
785 $encaiss_ttc[$obj->dm] = 0;
787 $encaiss_ttc[$obj->dm] += $obj->amount;
795 } elseif ($modecompta ==
'BOOKKEEPING') {
803 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) &&
isModEnabled(
"banque") && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
806 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various as p";
807 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
808 $sql .=
' AND p.sens = 0';
809 if (!empty($date_start) && !empty($date_end)) {
810 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
812 $sql .=
' GROUP BY dm';
815 $result = $db->query($sql);
817 $num = $db->num_rows($result);
821 $obj = $db->fetch_object($result);
822 if (!isset($decaiss_ttc[$obj->dm])) {
823 $decaiss_ttc[$obj->dm] = 0;
825 if (isset($obj->amount)) {
826 $decaiss_ttc[$obj->dm] += $obj->amount;
837 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX.
"payment_various AS p";
838 $sql .=
" WHERE p.entity IN (".getEntity(
'variouspayment').
")";
839 $sql .=
' AND p.sens = 1';
840 if (!empty($date_start) && !empty($date_end)) {
841 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
843 $sql .=
' GROUP BY dm';
846 $result = $db->query($sql);
848 $num = $db->num_rows($result);
852 $obj = $db->fetch_object($result);
853 if (!isset($encaiss_ttc[$obj->dm])) {
854 $encaiss_ttc[$obj->dm] = 0;
856 if (isset($obj->amount)) {
857 $encaiss_ttc[$obj->dm] += $obj->amount;
874 if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) &&
isModEnabled(
'loan') && ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
"RECETTES-DEPENSES")) {
875 $sql =
"SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
876 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan AS p, ".MAIN_DB_PREFIX.
"loan as l";
877 $sql .=
" WHERE l.entity IN (".getEntity(
'variouspayment').
")";
878 $sql .=
" AND p.fk_loan = l.rowid";
879 if (!empty($date_start) && !empty($date_end)) {
880 $sql .=
" AND p.datep >= '".$db->idate($date_start).
"' AND p.datep <= '".$db->idate($date_end).
"'";
882 $sql .=
' GROUP BY dm';
885 $result = $db->query($sql);
887 $num = $db->num_rows($result);
891 $obj = $db->fetch_object($result);
892 if (!isset($decaiss_ttc[$obj->dm])) {
893 $decaiss_ttc[$obj->dm] = 0;
895 if (isset($obj->amount)) {
896 $decaiss_ttc[$obj->dm] += $obj->amount;
914 if (
isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
915 $predefinedgroupwhere =
"(";
916 $predefinedgroupwhere .=
" (aa.pcg_type = 'EXPENSE')";
917 $predefinedgroupwhere .=
" OR ";
918 $predefinedgroupwhere .=
" (aa.pcg_type = 'INCOME')";
919 $predefinedgroupwhere .=
")";
921 $charofaccountstring = $conf->global->CHARTOFACCOUNTS;
922 $charofaccountstring =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
924 $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";
925 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as b, ".MAIN_DB_PREFIX.
"accounting_account as aa";
926 $sql .=
" WHERE b.entity = ".$conf->entity;
927 $sql .=
" AND aa.entity = ".$conf->entity;
928 $sql .=
" AND b.numero_compte = aa.account_number";
929 $sql .=
" AND ".$predefinedgroupwhere;
930 $sql .=
" AND fk_pcg_version = '".$db->escape($charofaccountstring).
"'";
931 if (!empty($date_start) && !empty($date_end)) {
932 $sql .=
" AND b.doc_date >= '".$db->idate($date_start).
"' AND b.doc_date <= '".$db->idate($date_end).
"'";
934 $sql .=
" GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
941 $result = $db->query($sql);
943 $num = $db->num_rows($result);
947 $obj = $db->fetch_object($result);
949 if ($obj->pcg_type ==
'INCOME') {
950 if (!isset($encaiss[$obj->dm])) {
951 $encaiss[$obj->dm] = 0;
953 $encaiss[$obj->dm] += $obj->credit;
954 $encaiss[$obj->dm] -= $obj->debit;
956 if ($obj->pcg_type ==
'EXPENSE') {
957 if (!isset($decaiss[$obj->dm])) {
958 $decaiss[$obj->dm] = 0;
960 $decaiss[$obj->dm] += $obj->debit;
961 $decaiss[$obj->dm] -= $obj->credit;
965 if (!isset($encaiss_ttc[$obj->dm])) {
966 $encaiss_ttc[$obj->dm] = 0;
968 if (!isset($decaiss_ttc[$obj->dm])) {
969 $decaiss_ttc[$obj->dm] = 0;
971 $encaiss_ttc[$obj->dm] += 0;
972 $decaiss_ttc[$obj->dm] += 0;
985 $object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
986 $parameters[
"mode"] = $modecompta;
988 $hookmanager->initHooks(array(
'externalbalance'));
989 $reshook = $hookmanager->executeHooks(
'addReportInfo', $parameters, $object, $action);
997 $totentrees = array();
998 $totsorties = array();
1000 print
'<div class="div-table-responsive">';
1001 print
'<table class="tagtable liste">'.
"\n";
1003 print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1005 for ($annee = $year_start; $annee <= $year_end; $annee++) {
1006 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1007 print
'<a href="clientfourn.php?year='.$annee.
'">';
1009 if ($conf->global->SOCIETE_FISCAL_MONTH_START > 1) {
1010 print
'-'.($annee + 1);
1015 print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1017 for ($annee = $year_start; $annee <= $year_end; $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;
1034 for ($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; $annee++) {
1043 $annee_decalage = $annee;
1045 $annee_decalage = $annee + 1;
1047 $case = strftime(
"%Y-%m",
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
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];
1096 print
'<tr class="liste_total impair"><td>';
1097 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1098 print $langs->trans(
"Total");
1100 print $langs->trans(
"TotalTTC");
1103 for ($annee = $year_start; $annee <= $year_end; $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>';
1111 print
'<tr class="impair"><td> </td>';
1112 print
'<td colspan="'.$nbcols.
'"> </td>';
1117 print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1118 for ($annee = $year_start; $annee <= $year_end; $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($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
img_next($titlealt='default', $moreatt='')
Show next logo.
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.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.