33require
'../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38$langs->loadLangs(array(
'compta',
'bills',
'donation',
'salaries'));
41$date_startmonth =
GETPOSTINT(
'date_startmonth');
58 $year_start = $year_current - ($nbofyear - 1);
60 $year_current = $year;
62 $year_start = $year - $nbofyear + (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
64$date_start =
dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear,
'tzserver');
65$date_end =
dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear,
'tzserver');
68if (empty($date_start) || empty($date_end)) {
72 $year_end = $year_start + $nbofyear - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
75 if (!$year && $month_start > $month_current) {
79 $month_end = $month_start - 1;
84 $month_end = $month_start;
109$year_start = $tmps[
'year'];
111$year_end = $tmpe[
'year'];
112$nbofyear = ($year_end - $year_start) + 1;
117if (isModEnabled(
'accounting')) {
118 $modecompta =
'BOOKKEEPING';
120if (
GETPOST(
"modecompta",
'alpha')) {
121 $modecompta =
GETPOST(
"modecompta",
'alpha');
126if ($user->socid > 0) {
127 $socid = $user->socid;
129if (isModEnabled(
'comptabilite')) {
132if (isModEnabled(
'accounting')) {
133 $result =
restrictedArea($user,
'accounting',
'',
'',
'comptarapport');
143$form =
new Form($db);
148$encaiss_ttc = array();
150$decaiss_ttc = array();
153if ($modecompta ==
'CREANCES-DETTES') {
154 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
155 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
156 $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>" :
"");
157 $description = $langs->trans(
"RulesAmountWithTaxExcluded");
158 $description .=
'<br>'.$langs->trans(
"RulesResultDue");
160 $description .=
"<br>".$langs->trans(
"DepositsAreNotIncluded");
162 $description .=
"<br>".$langs->trans(
"DepositsAreIncluded");
165 $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
169} elseif ($modecompta ==
"RECETTES-DEPENSES") {
170 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
171 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
172 $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>" :
"");
173 $description = $langs->trans(
"RulesAmountWithTaxIncluded");
174 $description .=
'<br>'.$langs->trans(
"RulesResultInOut");
177} elseif ($modecompta ==
"BOOKKEEPING") {
178 $name = $langs->trans(
"ReportInOut").
', '.$langs->trans(
"ByYear");
179 $period = $form->selectDate($date_start,
'date_start', 0, 0, 0,
'', 1, 0).
' - '.$form->selectDate($date_end,
'date_end', 0, 0, 0,
'', 1, 0);
180 $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>" :
"");
181 $description = $langs->trans(
"RulesAmountOnInOutBookkeepingRecord");
182 $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")).
')';
189if (isModEnabled(
'accounting')) {
190 $calcmode .=
'<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta ==
'BOOKKEEPING' ?
' checked="checked"' :
'').
'><label for="modecompta3"> '.$langs->trans(
"CalcModeBookkeeping").
'</label>';
193$calcmode .=
'<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta ==
'RECETTES-DEPENSES' ?
' checked="checked"' :
'').
'><label for="modecompta1"> '.$langs->trans(
"CalcModePayment");
194if (isModEnabled(
'accounting')) {
195 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
197$calcmode .=
'</label>';
198$calcmode .=
'<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta ==
'CREANCES-DETTES' ?
' checked="checked"' :
'').
'><label for="modecompta2"> '.$langs->trans(
"CalcModeDebt");
199if (isModEnabled(
'accounting')) {
200 $calcmode .=
' <span class="opacitymedium hideonsmartphone">('.$langs->trans(
"CalcModeNoBookKeeping").
')</span>';
202$calcmode .=
'</label>';
205report_header($name,
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
207if (isModEnabled(
'accounting') && $modecompta !=
'BOOKKEEPING') {
208 print
info_admin($langs->trans(
"WarningReportNotReliable"), 0, 0,
'1');
219if (isModEnabled(
'invoice') && ($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)";
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") {
276if (isModEnabled(
'invoice') && ($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") {
331if (isModEnabled(
'invoice') && ($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)";
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") {
398if (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)";
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)";
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") {
562if (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") {
620if (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") {
682if (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') {
744if (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') {
803if (
getDolGlobalString(
'ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled(
"bank") && ($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;
874if (
getDolGlobalString(
'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;
914if (isModEnabled(
'accounting') && ($modecompta ==
'BOOKKEEPING')) {
915 $predefinedgroupwhere =
"(";
916 $predefinedgroupwhere .=
" (aa.pcg_type = 'EXPENSE')";
917 $predefinedgroupwhere .=
" OR ";
918 $predefinedgroupwhere .=
" (aa.pcg_type = 'INCOME')";
919 $predefinedgroupwhere .=
")";
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();
999$year_end_for_table = ($year_end - (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1001print
'<div class="div-table-responsive">';
1002print
'<table class="tagtable liste">'.
"\n";
1004print
'<tr class="liste_titre"><td class="liste_titre"> </td>';
1006for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1007 print
'<td align="center" colspan="2" class="liste_titre borderrightlight">';
1008 print
'<a href="clientfourn.php?year='.((int) $annee).
'">';
1011 print
'-'.($annee + 1);
1016print
'<tr class="liste_titre"><td class="liste_titre">'.$langs->trans(
"Month").
'</td>';
1018for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1019 print
'<td class="liste_titre" align="center">';
1022 print $form->textwithpicto($langs->trans(
"Outcome"), $htmlhelp);
1024 print
'<td class="liste_titre" align="center" class="borderrightlight">';
1027 print $form->textwithpicto($langs->trans(
"Income"), $htmlhelp);
1034$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1035for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1036 $mois_modulo = $mois;
1038 $mois_modulo = $mois - 12;
1041 print
'<tr class="oddeven">';
1042 print
"<td>".dol_print_date(
dol_mktime(12, 0, 0, $mois_modulo, 1, $annee),
"%B").
"</td>";
1043 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1044 $annee_decalage = $annee;
1046 $annee_decalage = $annee + 1;
1050 print
'<td class="right">';
1051 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1052 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1053 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss[$case],
'MT')).
'</a>';
1054 if (!isset($totsorties[$annee])) {
1055 $totsorties[$annee] = 0;
1057 $totsorties[$annee] += $decaiss[$case];
1060 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1061 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($decaiss_ttc[$case],
'MT')).
'</a>';
1062 if (!isset($totsorties[$annee])) {
1063 $totsorties[$annee] = 0;
1065 $totsorties[$annee] += $decaiss_ttc[$case];
1070 print
'<td class="borderrightlight nowrap right">';
1071 if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1072 if (isset($encaiss[$case])) {
1073 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss[$case],
'MT')).
'</a>';
1074 if (!isset($totentrees[$annee])) {
1075 $totentrees[$annee] = 0;
1077 $totentrees[$annee] += $encaiss[$case];
1080 if (isset($encaiss_ttc[$case])) {
1081 print
'<a href="clientfourn.php?year='.$annee_decalage.
'&month='.$mois_modulo.($modecompta ?
'&modecompta='.$modecompta :
'').
'">'.
price(
price2num($encaiss_ttc[$case],
'MT')).
'</a>';
1082 if (!isset($totentrees[$annee])) {
1083 $totentrees[$annee] = 0;
1085 $totentrees[$annee] += $encaiss_ttc[$case];
1097print
'<tr class="liste_total impair"><td>';
1098if ($modecompta ==
'CREANCES-DETTES' || $modecompta ==
'BOOKKEEPING') {
1099 print $langs->trans(
"Total");
1101 print $langs->trans(
"TotalTTC");
1104for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1106 print
'<td class="nowrap right">'.(isset($totsorties[$annee]) ?
price(
price2num($totsorties[$annee],
'MT')) :
' ').
'</td>';
1107 print
'<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ?
price(
price2num($totentrees[$annee],
'MT')) :
' ').
'</td>';
1112print
'<tr class="impair"><td> </td>';
1113print
'<td colspan="'.$nbcols.
'"> </td>';
1118print
'<tr class="liste_total"><td>'.$langs->trans(
"AccountingResult").
'</td>';
1119for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1120 print
'<td colspan="2" class="borderrightlight right"> ';
1121 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1122 $in = (isset($totentrees[$annee]) ?
price2num($totentrees[$annee],
'MT') : 0);
1123 $out = (isset($totsorties[$annee]) ?
price2num($totsorties[$annee],
'MT') : 0);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.