dolibarr 25.0.0-alpha
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
7 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
8 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
9 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
11 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44
45// Load translation files required by the page
46$langs->loadLangs(array('compta', 'bills', 'donation', 'accountancy', 'salaries'));
47
48$date_startday = GETPOSTINT('date_startday');
49$date_startmonth = GETPOSTINT('date_startmonth');
50$date_startyear = GETPOSTINT('date_startyear');
51$date_endday = GETPOSTINT('date_endday');
52$date_endmonth = GETPOSTINT('date_endmonth');
53$date_endyear = GETPOSTINT('date_endyear');
54
55$nbofyear = 4;
56
57// Change this to test different cases of setup.
58//$conf->global->SOCIETE_FISCAL_MONTH_START = 7;
59
60
61// Date range
62$year = GETPOSTINT('year'); // this is used for navigation previous/next. It is the last year to show in filter
63if (empty($year)) {
64 $year_current = (int) dol_print_date(dol_now(), "%Y");
65 $month_current = (int) dol_print_date(dol_now(), "%m");
66 $year_start = $year_current - ($nbofyear - 1);
67} else {
68 $year_current = $year;
69 $month_current = (int) dol_print_date(dol_now(), "%m");
70 $year_start = $year - $nbofyear + (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
71}
72$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver');
73$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver');
74
75// We define date_start and date_end
76if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
77 $q = GETPOST("q") ? GETPOSTINT("q") : 0;
78 if ($q == 0) {
79 // We define date_start and date_end
80 $year_end = $year_start + $nbofyear - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 0 : 1);
81 $month_start = GETPOST("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
82 if (!GETPOST('month')) {
83 if (!$year && $month_start > $month_current) {
84 $year_start--;
85 $year_end--;
86 }
87 $month_end = $month_start - 1;
88 if ($month_end < 1) {
89 $month_end = 12;
90 }
91 } else {
92 $month_end = $month_start;
93 }
94 $date_start = dol_get_first_day($year_start, $month_start, false);
95 $date_end = dol_get_last_day($year_end, $month_end, false);
96 }
97 if ($q == 1) {
98 $date_start = dol_get_first_day($year_start, 1, false);
99 $date_end = dol_get_last_day($year_start, 3, false);
100 }
101 if ($q == 2) {
102 $date_start = dol_get_first_day($year_start, 4, false);
103 $date_end = dol_get_last_day($year_start, 6, false);
104 }
105 if ($q == 3) {
106 $date_start = dol_get_first_day($year_start, 7, false);
107 $date_end = dol_get_last_day($year_start, 9, false);
108 }
109 if ($q == 4) {
110 $date_start = dol_get_first_day($year_start, 10, false);
111 $date_end = dol_get_last_day($year_start, 12, false);
112 }
113}
114
115// $date_start and $date_end are defined. We force $year_start and $nbofyear
116$tmps = dol_getdate($date_start);
117$year_start = $tmps['year'];
118$tmpe = dol_getdate($date_end);
119$year_end = $tmpe['year'];
120$nbofyear = ($year_end - $year_start) + 1;
121//var_dump("year_start=".$year_start." year_end=".$year_end." nbofyear=".$nbofyear." date_start=".dol_print_date($date_start, 'dayhour')." date_end=".dol_print_date($date_end, 'dayhour'));
122
123// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
124$modecompta = getDolGlobalString('ACCOUNTING_MODE');
125if (isModEnabled('accounting')) {
126 $modecompta = 'BOOKKEEPING';
127}
128if (GETPOST("modecompta", 'alpha')) {
129 $modecompta = GETPOST("modecompta", 'alpha');
130}
131
132// Security check
133$socid = GETPOSTINT('socid');
134if ($user->socid > 0) {
135 $socid = $user->socid;
136}
137if (isModEnabled('comptabilite')) {
138 $result = restrictedArea($user, 'compta', '', '', 'resultat');
139}
140if (isModEnabled('accounting')) {
141 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
142}
143
144
145/*
146 * View
147 */
148
149llxHeader();
150
151$form = new Form($db);
152
153
154$builddate = 0;
155$name = '';
156$period = '';
157$periodlink = '';
158$exportlink = '';
159$description = '';
160
161$encaiss = array();
162$encaiss_ttc = array();
163$decaiss = array();
164$decaiss_ttc = array();
165
166// Display report header
167if ($modecompta == 'CREANCES-DETTES') {
168 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
169 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
170 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
171 $description = $langs->trans("RulesAmountWithTaxExcluded");
172 $description .= '<br>'.$langs->trans("RulesResultDue");
173 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
174 $description .= "<br>".$langs->trans("DepositsAreNotIncluded");
175 } else {
176 $description .= "<br>".$langs->trans("DepositsAreIncluded");
177 }
178 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
179 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
180 }
181 $builddate = dol_now();
182 //$exportlink=$langs->trans("NotYetAvailable");
183} elseif ($modecompta == "RECETTES-DEPENSES") {
184 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
185 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
186 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
187 $description = $langs->trans("RulesAmountWithTaxIncluded");
188 $description .= '<br>'.$langs->trans("RulesResultInOut");
189 $builddate = dol_now();
190 //$exportlink=$langs->trans("NotYetAvailable");
191} elseif ($modecompta == "BOOKKEEPING") {
192 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
193 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
194 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear - 2)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start + $nbofyear)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
195 $description = $langs->trans("RulesAmountOnInOutBookkeepingRecord");
196 $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("Chartofaccounts")).')';
197 $builddate = dol_now();
198 //$exportlink=$langs->trans("NotYetAvailable");
199}
200
201// Define $calcmode line
202$calcmode = '';
203if (isModEnabled('accounting')) {
204 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
205 $calcmode .= '<br>';
206}
207$calcmode .= '<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta1"> '.$langs->trans("CalcModePayment");
208if (isModEnabled('accounting')) {
209 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
210}
211$calcmode .= '</label>';
212$calcmode .= '<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
213if (isModEnabled('accounting')) {
214 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
215}
216$calcmode .= '</label>';
217
218report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
219
220if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
221 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
222}
223
224
225
226/*
227 * Customers invoices
228 */
229
230$subtotal_ht = 0;
231$subtotal_ttc = 0;
232if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
233 if ($modecompta == 'CREANCES-DETTES') {
234 $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
235 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
236 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
237 $sql .= " WHERE f.fk_soc = s.rowid";
238 $sql .= " AND f.fk_statut IN (1,2)";
239 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
240 $sql .= " AND f.type IN (0,1,2,5)";
241 } else {
242 $sql .= " AND f.type IN (0,1,2,3,5)";
243 }
244 // Add SQL restrictions from hooks (context turnoverreport), e.g. a deposit pivot date restricting deposits by their date
245 $hookmanager->initHooks(array('turnoverreport'));
246 $parameters = array('invoicealias' => 'f', 'issupplier' => 0, 'datefield' => 'datef');
247 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by some hooks
248 $sql .= $hookmanager->resPrint;
249 if (!empty($date_start) && !empty($date_end)) {
250 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
251 }
252 } elseif ($modecompta == "RECETTES-DEPENSES") {
253 /*
254 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
255 * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
256 */
257 $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
258 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
259 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
260 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
261 $sql .= " WHERE p.rowid = pf.fk_paiement";
262 $sql .= " AND pf.fk_facture = f.rowid";
263 if (!empty($date_start) && !empty($date_end)) {
264 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
265 }
266 }
267 $sql .= " AND f.entity IN (".getEntity('invoice').")";
268 if ($socid) {
269 $sql .= " AND f.fk_soc = ".((int) $socid);
270 }
271 $sql .= " GROUP BY dm";
272 $sql .= " ORDER BY dm";
273
274 //print $sql;
275 dol_syslog("get customers invoices", LOG_DEBUG);
276 $result = $db->query($sql);
277 if ($result) {
278 $num = $db->num_rows($result);
279 $i = 0;
280 while ($i < $num) {
281 $row = $db->fetch_object($result);
282 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
283 $encaiss_ttc[$row->dm] = $row->amount_ttc;
284 $i++;
285 }
286 $db->free($result);
287 } else {
288 dol_print_error($db);
289 }
290} // elseif ($modecompta == "BOOKKEEPING") {
291// Nothing from this table
292//}
293
294if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
295 // Adding legacy client payments not linked via 'paiement_facture'.
296 if ($modecompta != 'CREANCES-DETTES') {
297 $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
298 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
299 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
300 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
301 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
302 $sql .= " WHERE pf.rowid IS NULL";
303 $sql .= " AND p.fk_bank = b.rowid";
304 $sql .= " AND b.fk_account = ba.rowid";
305 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
306 if (!empty($date_start) && !empty($date_end)) {
307 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
308 }
309 $sql .= " GROUP BY dm";
310 $sql .= " ORDER BY dm";
311
312 dol_syslog("get old customers payments not linked to invoices", LOG_DEBUG);
313 $result = $db->query($sql);
314 if ($result) {
315 $num = $db->num_rows($result);
316 $i = 0;
317 while ($i < $num) {
318 $row = $db->fetch_object($result);
319
320 if (!isset($encaiss[$row->dm])) {
321 $encaiss[$row->dm] = 0;
322 }
323 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
324
325 if (!isset($encaiss_ttc[$row->dm])) {
326 $encaiss_ttc[$row->dm] = 0;
327 }
328 $encaiss_ttc[$row->dm] += $row->amount_ttc;
329
330 $i++;
331 }
332 } else {
333 dol_print_error($db);
334 }
335 } //elseif ($modecompta == "RECETTES-DEPENSES") {
336 // Nothing from this table
337 //}
338} //elseif ($modecompta == "BOOKKEEPING") {
339// Nothing from this table
340//}
341
342
343/*
344 * Expenses, supplier invoices.
345 */
346$subtotal_ht = 0;
347$subtotal_ttc = 0;
348
349if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
350 if ($modecompta == 'CREANCES-DETTES') {
351 $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
352 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
353 $sql .= " WHERE f.fk_statut IN (1,2)";
354 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
355 $sql .= " AND f.type IN (0,1,2)";
356 } else {
357 $sql .= " AND f.type IN (0,1,2,3)";
358 }
359 // Add SQL restrictions from hooks (context turnoverreport), e.g. a deposit pivot date restricting deposits by their date
360 $hookmanager->initHooks(array('turnoverreport'));
361 $parameters = array('invoicealias' => 'f', 'issupplier' => 1, 'datefield' => 'datef');
362 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by some hooks
363 $sql .= $hookmanager->resPrint;
364 if (!empty($date_start) && !empty($date_end)) {
365 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
366 }
367 } elseif ($modecompta == "RECETTES-DEPENSES") {
368 $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
369 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
370 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
371 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
372 $sql .= " WHERE f.rowid = pf.fk_facturefourn";
373 $sql .= " AND p.rowid = pf.fk_paiementfourn";
374 if (!empty($date_start) && !empty($date_end)) {
375 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
376 }
377 }
378 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
379
380 if ($socid) {
381 $sql .= " AND f.fk_soc = ".((int) $socid);
382 }
383 $sql .= " GROUP BY dm";
384
385 dol_syslog("get suppliers invoices", LOG_DEBUG);
386 $result = $db->query($sql);
387 if ($result) {
388 $num = $db->num_rows($result);
389 $i = 0;
390 while ($i < $num) {
391 $row = $db->fetch_object($result);
392
393 if (!isset($decaiss[$row->dm])) {
394 $decaiss[$row->dm] = 0;
395 }
396 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
397
398 if (!isset($decaiss_ttc[$row->dm])) {
399 $decaiss_ttc[$row->dm] = 0;
400 }
401 $decaiss_ttc[$row->dm] = $row->amount_ttc;
402
403 $i++;
404 }
405 $db->free($result);
406 } else {
407 dol_print_error($db);
408 }
409} //elseif ($modecompta == "BOOKKEEPING") {
410// Nothing from this table
411//}
412
413
414
415/*
416 * TVA
417 */
418
419$subtotal_ht = 0;
420$subtotal_ttc = 0;
421if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
422 if ($modecompta == 'CREANCES-DETTES') {
423 // TVA collected to pay
424 $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
425 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
426 $sql .= " WHERE f.fk_statut IN (1,2)";
427 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
428 $sql .= " AND f.type IN (0,1,2,5)";
429 } else {
430 $sql .= " AND f.type IN (0,1,2,3,5)";
431 }
432 // Add SQL restrictions from hooks (context turnoverreport), e.g. a deposit pivot date restricting deposits by their date
433 $hookmanager->initHooks(array('turnoverreport'));
434 $parameters = array('invoicealias' => 'f', 'issupplier' => 0, 'datefield' => 'datef');
435 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by some hooks
436 $sql .= $hookmanager->resPrint;
437 $sql .= " AND f.entity IN (".getEntity('invoice').")";
438 if (!empty($date_start) && !empty($date_end)) {
439 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
440 }
441 $sql .= " GROUP BY dm";
442
443 dol_syslog("get vat to pay", LOG_DEBUG);
444 $result = $db->query($sql);
445 if ($result) {
446 $num = $db->num_rows($result);
447 $i = 0;
448 if ($num) {
449 while ($i < $num) {
450 $obj = $db->fetch_object($result);
451
452 /*if (!isset($decaiss[$obj->dm])) {
453 $decaiss[$obj->dm] = 0;
454 }
455 $decaiss[$obj->dm] += $obj->amount;*/
456
457 if (!isset($decaiss_ttc[$obj->dm])) {
458 $decaiss_ttc[$obj->dm] = 0;
459 }
460 $decaiss_ttc[$obj->dm] += $obj->amount;
461
462 $i++;
463 }
464 }
465 } else {
466 dol_print_error($db);
467 }
468 // TVA paid to get
469 $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
470 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
471 $sql .= " WHERE f.fk_statut IN (1,2)";
472 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
473 $sql .= " AND f.type IN (0,1,2)";
474 } else {
475 $sql .= " AND f.type IN (0,1,2,3)";
476 }
477 // Add SQL restrictions from hooks (context turnoverreport), e.g. a deposit pivot date restricting deposits by their date
478 $hookmanager->initHooks(array('turnoverreport'));
479 $parameters = array('invoicealias' => 'f', 'issupplier' => 1, 'datefield' => 'datef');
480 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by some hooks
481 $sql .= $hookmanager->resPrint;
482 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
483 if (!empty($date_start) && !empty($date_end)) {
484 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
485 }
486 $sql .= " GROUP BY dm";
487
488 dol_syslog("get vat to receive back", LOG_DEBUG);
489 $result = $db->query($sql);
490 if ($result) {
491 $num = $db->num_rows($result);
492 $i = 0;
493 if ($num) {
494 while ($i < $num) {
495 $obj = $db->fetch_object($result);
496
497 /*if (!isset($encaiss[$obj->dm])) {
498 $encaiss[$obj->dm] = 0;
499 }
500 $encaiss[$obj->dm] += $obj->amount;*/
501
502 if (!isset($encaiss_ttc[$obj->dm])) {
503 $encaiss_ttc[$obj->dm] = 0;
504 }
505 $encaiss_ttc[$obj->dm] += $obj->amount;
506
507 $i++;
508 }
509 }
510 } else {
511 dol_print_error($db);
512 }
513 } elseif ($modecompta == "RECETTES-DEPENSES") {
514 // TVA really already paid
515 $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
516 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
517 $sql .= " WHERE amount > 0";
518 $sql .= " AND t.entity IN (".getEntity('vat').")";
519 if (!empty($date_start) && !empty($date_end)) {
520 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
521 }
522 $sql .= " GROUP BY dm";
523
524 dol_syslog("get vat really paid", LOG_DEBUG);
525 $result = $db->query($sql);
526 if ($result) {
527 $num = $db->num_rows($result);
528 $i = 0;
529 if ($num) {
530 while ($i < $num) {
531 $obj = $db->fetch_object($result);
532
533 /*if (!isset($decaiss[$obj->dm])) {
534 $decaiss[$obj->dm] = 0;
535 }
536 $decaiss[$obj->dm] += $obj->amount;*/
537
538 if (!isset($decaiss_ttc[$obj->dm])) {
539 $decaiss_ttc[$obj->dm] = 0;
540 }
541 $decaiss_ttc[$obj->dm] += $obj->amount;
542
543 $i++;
544 }
545 }
546 } else {
547 dol_print_error($db);
548 }
549 // TVA retrieved
550 $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
551 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
552 $sql .= " WHERE amount < 0";
553 $sql .= " AND t.entity IN (".getEntity('vat').")";
554 if (!empty($date_start) && !empty($date_end)) {
555 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
556 }
557 $sql .= " GROUP BY dm";
558
559 dol_syslog("get vat really received back", LOG_DEBUG);
560 $result = $db->query($sql);
561 if ($result) {
562 $num = $db->num_rows($result);
563 $i = 0;
564 if ($num) {
565 while ($i < $num) {
566 $obj = $db->fetch_object($result);
567
568 /*if (!isset($encaiss[$obj->dm])) {
569 $encaiss[$obj->dm] = 0;
570 }
571 $encaiss[$obj->dm] += -$obj->amount;*/
572
573 if (!isset($encaiss_ttc[$obj->dm])) {
574 $encaiss_ttc[$obj->dm] = 0;
575 }
576 $encaiss_ttc[$obj->dm] += -$obj->amount;
577
578 $i++;
579 }
580 }
581 } else {
582 dol_print_error($db);
583 }
584 }
585}// elseif ($modecompta == "BOOKKEEPING") {
586// Nothing from this table
587//}
588
589/*
590 * Social contributions
591 */
592
593$subtotal_ht = 0;
594$subtotal_ttc = 0;
595if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
596 if ($modecompta == 'CREANCES-DETTES') {
597 $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
598 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
599 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
600 $sql .= " WHERE cs.fk_type = c.id";
601 if (!empty($date_start) && !empty($date_end)) {
602 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
603 }
604 } elseif ($modecompta == "RECETTES-DEPENSES") {
605 $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
606 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
607 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
608 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
609 $sql .= " WHERE p.fk_charge = cs.rowid";
610 $sql .= " AND cs.fk_type = c.id";
611 if (!empty($date_start) && !empty($date_end)) {
612 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
613 }
614 }
615
616 $sql .= " AND cs.entity IN (".getEntity('social_contributions').")";
617 $sql .= " GROUP BY c.libelle, dm";
618
619 dol_syslog("get social contributions", LOG_DEBUG);
620 $result = $db->query($sql);
621 if ($result) {
622 $num = $db->num_rows($result);
623 $i = 0;
624 if ($num) {
625 while ($i < $num) {
626 $obj = $db->fetch_object($result);
627
628 if (!isset($decaiss[$obj->dm])) {
629 $decaiss[$obj->dm] = 0;
630 }
631 $decaiss[$obj->dm] += $obj->amount;
632
633 if (!isset($decaiss_ttc[$obj->dm])) {
634 $decaiss_ttc[$obj->dm] = 0;
635 }
636 $decaiss_ttc[$obj->dm] += $obj->amount;
637
638 $i++;
639 }
640 }
641 } else {
642 dol_print_error($db);
643 }
644} //elseif ($modecompta == "BOOKKEEPING") {
645// Nothing from this table
646//}
647
648
649/*
650 * Salaries
651 */
652
653if (isModEnabled('salaries') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
654 $sql = '';
655 if ($modecompta == 'CREANCES-DETTES') {
656 $column = 's.dateep'; // we use the date of end of period of salary
657
658 $sql = "SELECT s.label as nom, date_format(".$db->sanitize($column).",'%Y-%m') as dm, sum(s.amount) as amount";
659 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
660 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
661 if (!empty($date_start) && !empty($date_end)) {
662 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."' AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
663 }
664 $sql .= " GROUP BY s.label, dm";
665 }
666 if ($modecompta == "RECETTES-DEPENSES") {
667 $column = 'p.datep';
668
669 $sql = "SELECT p.label as nom, date_format(".$db->sanitize($column).",'%Y-%m') as dm, sum(p.amount) as amount";
670 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
671 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON p.fk_salary = s.rowid";
672 $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
673 if (!empty($date_start) && !empty($date_end)) {
674 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."' AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
675 }
676 $sql .= " GROUP BY p.label, dm";
677 }
678
679 $subtotal_ht = 0;
680 $subtotal_ttc = 0;
681
682 dol_syslog("get social salaries payments");
683 $result = $db->query($sql);
684 if ($result) {
685 $num = $db->num_rows($result);
686 $i = 0;
687 if ($num) {
688 while ($i < $num) {
689 $obj = $db->fetch_object($result);
690
691 if (!isset($decaiss[$obj->dm])) {
692 $decaiss[$obj->dm] = 0;
693 }
694 $decaiss[$obj->dm] += $obj->amount;
695
696 if (!isset($decaiss_ttc[$obj->dm])) {
697 $decaiss_ttc[$obj->dm] = 0;
698 }
699 $decaiss_ttc[$obj->dm] += $obj->amount;
700
701 $i++;
702 }
703 }
704 } else {
705 dol_print_error($db);
706 }
707} //elseif ($modecompta == "BOOKKEEPING") {
708// Nothing from this table
709//}
710
711
712/*
713 * Expense reports
714 */
715
716if (isModEnabled('expensereport') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
717 $langs->load('trips');
718
719 if ($modecompta == 'CREANCES-DETTES') {
720 $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
721 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
722 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
723 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
724 $sql .= " AND p.fk_statut>=5";
725
726 $column = 'p.date_valid';
727 if (!empty($date_start) && !empty($date_end)) {
728 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."' AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
729 }
730 } elseif ($modecompta == 'RECETTES-DEPENSES') {
731 $sql = "SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
732 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
733 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
734 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
735 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
736 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
737 $sql .= " AND p.fk_statut >= 5";
738
739 $column = 'pe.datep';
740 if (!empty($date_start) && !empty($date_end)) {
741 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."' AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
742 }
743 }
744
745 $sql .= " GROUP BY dm";
746
747 dol_syslog("get expense report outcome");
748 $result = $db->query($sql);
749 $subtotal_ht = 0;
750 $subtotal_ttc = 0;
751 if ($result) {
752 $num = $db->num_rows($result);
753 if ($num) {
754 while ($obj = $db->fetch_object($result)) {
755 if (!isset($decaiss[$obj->dm])) {
756 $decaiss[$obj->dm] = 0;
757 }
758 $decaiss[$obj->dm] += $obj->amount_ht;
759
760 if (!isset($decaiss_ttc[$obj->dm])) {
761 $decaiss_ttc[$obj->dm] = 0;
762 }
763 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
764 }
765 }
766 } else {
767 dol_print_error($db);
768 }
769} //elseif ($modecompta == 'BOOKKEEPING') {
770// Nothing from this table
771//}
772
773
774/*
775 * Donation get dunning payments
776 */
777
778if (isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
779 $subtotal_ht = 0;
780 $subtotal_ttc = 0;
781
782 if ($modecompta == 'CREANCES-DETTES') {
783 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
784 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
785 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
786 $sql .= " AND fk_statut in (1,2)";
787 if (!empty($date_start) && !empty($date_end)) {
788 $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
789 }
790 } elseif ($modecompta == 'RECETTES-DEPENSES') {
791 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
792 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
793 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
794 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
795 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
796 $sql .= " AND fk_statut >= 2";
797 if (!empty($date_start) && !empty($date_end)) {
798 $sql .= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'";
799 }
800 }
801
802 $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
803
804 dol_syslog("get donation payments");
805 $result = $db->query($sql);
806 if ($result) {
807 $num = $db->num_rows($result);
808 $i = 0;
809 if ($num) {
810 while ($i < $num) {
811 $obj = $db->fetch_object($result);
812
813 if (!isset($encaiss[$obj->dm])) {
814 $encaiss[$obj->dm] = 0;
815 }
816 $encaiss[$obj->dm] += $obj->amount;
817
818 if (!isset($encaiss_ttc[$obj->dm])) {
819 $encaiss_ttc[$obj->dm] = 0;
820 }
821 $encaiss_ttc[$obj->dm] += $obj->amount;
822
823 $i++;
824 }
825 }
826 } else {
827 dol_print_error($db);
828 }
829} //elseif ($modecompta == 'BOOKKEEPING') {
830// Nothing from this table
831//}
832
833/*
834 * Various Payments
835 */
836
837if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank") && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
838 // decaiss
839
840 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
841 $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
842 $sql .= ' AND p.sens = 0';
843 if (!empty($date_start) && !empty($date_end)) {
844 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
845 }
846 $sql .= ' GROUP BY dm';
847
848 dol_syslog("get various payments");
849 $result = $db->query($sql);
850 if ($result) {
851 $num = $db->num_rows($result);
852 $i = 0;
853 if ($num) {
854 while ($i < $num) {
855 $obj = $db->fetch_object($result);
856 if (!isset($decaiss_ttc[$obj->dm])) {
857 $decaiss_ttc[$obj->dm] = 0;
858 }
859 if (isset($obj->amount)) {
860 $decaiss_ttc[$obj->dm] += $obj->amount;
861 }
862 $i++;
863 }
864 }
865 } else {
866 dol_print_error($db);
867 }
868
869 // encaiss
870
871 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various AS p";
872 $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
873 $sql .= ' AND p.sens = 1';
874 if (!empty($date_start) && !empty($date_end)) {
875 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
876 }
877 $sql .= ' GROUP BY dm';
878
879 dol_syslog("get various payments");
880 $result = $db->query($sql);
881 if ($result) {
882 $num = $db->num_rows($result);
883 $i = 0;
884 if ($num) {
885 while ($i < $num) {
886 $obj = $db->fetch_object($result);
887 if (!isset($encaiss_ttc[$obj->dm])) {
888 $encaiss_ttc[$obj->dm] = 0;
889 }
890 if (isset($obj->amount)) {
891 $encaiss_ttc[$obj->dm] += $obj->amount;
892 }
893 $i++;
894 }
895 }
896 } else {
897 dol_print_error($db);
898 }
899}
900// Useless with BOOKKEEPING
901//elseif ($modecompta == 'BOOKKEEPING') {
902//}
903
904/*
905 * Payment Loan
906 */
907
908if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('loan') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
909 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
910 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan AS p, ".MAIN_DB_PREFIX."loan as l";
911 $sql .= " WHERE l.entity IN (".getEntity('variouspayment').")";
912 $sql .= " AND p.fk_loan = l.rowid";
913 if (!empty($date_start) && !empty($date_end)) {
914 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
915 }
916 $sql .= ' GROUP BY dm';
917
918 dol_syslog("get loan payments");
919 $result = $db->query($sql);
920 if ($result) {
921 $num = $db->num_rows($result);
922 $i = 0;
923 if ($num) {
924 while ($i < $num) {
925 $obj = $db->fetch_object($result);
926 if (!isset($decaiss_ttc[$obj->dm])) {
927 $decaiss_ttc[$obj->dm] = 0;
928 }
929 if (isset($obj->amount)) {
930 $decaiss_ttc[$obj->dm] += $obj->amount;
931 }
932 $i++;
933 }
934 }
935 } else {
936 dol_print_error($db);
937 }
938}
939// Useless with BOOKKEEPING
940//elseif ($modecompta == 'BOOKKEEPING') {
941//}
942
943
944/*
945 * Request in mode BOOKKEEPING
946 */
947
948if (isModEnabled('accounting') && ($modecompta == 'BOOKKEEPING')) {
949 // Some shipped charts of accounts (e.g. US-BASE) split income and expense
950 // accounts across more than one pcg_type value (COGS, OTHER_REVENUE,
951 // OTHER_EXPENSES), unlike FR/GB-style charts which only use INCOME/EXPENSE.
952 // Include those here so this report does not silently omit them.
953 $sanitizedpredefinedgroupwhere = "(";
954 $sanitizedpredefinedgroupwhere .= " (aa.pcg_type IN ('EXPENSE', 'COGS', 'OTHER_EXPENSES'))";
955 $sanitizedpredefinedgroupwhere .= " OR ";
956 $sanitizedpredefinedgroupwhere .= " (aa.pcg_type IN ('INCOME', 'OTHER_REVENUE'))";
957 $sanitizedpredefinedgroupwhere .= ")";
958
959 $charofaccountstring = getDolGlobalInt('CHARTOFACCOUNTS');
960 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
961
962 $sql = "SELECT b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, aa.pcg_type, date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as debit, sum(b.credit) as credit, sum(b.montant) as amount";
963 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa";
964 $sql .= " WHERE b.entity = ".((int) $conf->entity);
965 $sql .= " AND aa.entity = ".((int) $conf->entity);
966 $sql .= " AND b.numero_compte = aa.account_number";
967 $sql .= " AND ".$sanitizedpredefinedgroupwhere;
968 $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
969 if (!empty($date_start) && !empty($date_end)) {
970 $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
971 }
972 $sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
973 //print $sql;
974
975 $subtotal_ht = 0;
976 $subtotal_ttc = 0;
977
978 dol_syslog("get bookkeeping record");
979 $result = $db->query($sql);
980 if ($result) {
981 $num = $db->num_rows($result);
982 $i = 0;
983 if ($num) {
984 while ($i < $num) {
985 $obj = $db->fetch_object($result);
986
987 if (in_array($obj->pcg_type, array('INCOME', 'OTHER_REVENUE'))) {
988 if (!isset($encaiss[$obj->dm])) {
989 $encaiss[$obj->dm] = 0; // To avoid warning of var not defined
990 }
991 $encaiss[$obj->dm] += $obj->credit;
992 $encaiss[$obj->dm] -= $obj->debit;
993 }
994 if (in_array($obj->pcg_type, array('EXPENSE', 'COGS', 'OTHER_EXPENSES'))) {
995 if (!isset($decaiss[$obj->dm])) {
996 $decaiss[$obj->dm] = 0; // To avoid warning of var not defined
997 }
998 $decaiss[$obj->dm] += $obj->debit;
999 $decaiss[$obj->dm] -= $obj->credit;
1000 }
1001
1002 // ???
1003 if (!isset($encaiss_ttc[$obj->dm])) {
1004 $encaiss_ttc[$obj->dm] = 0;
1005 }
1006 if (!isset($decaiss_ttc[$obj->dm])) {
1007 $decaiss_ttc[$obj->dm] = 0;
1008 }
1009 $encaiss_ttc[$obj->dm] += 0;
1010 $decaiss_ttc[$obj->dm] += 0;
1011
1012 $i++;
1013 }
1014 }
1015 } else {
1016 dol_print_error($db);
1017 }
1018}
1019
1020
1021
1022$action = "balance";
1023$object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
1024$parameters = array();
1025$parameters["mode"] = $modecompta;
1026// Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1027$hookmanager->initHooks(array('externalbalance'));
1028$reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1029
1030
1031
1032/*
1033 * Show result array
1034 */
1035
1036$totentrees = array();
1037$totsorties = array();
1038$year_end_for_table = ($year_end - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1039
1040print '<div class="div-table-responsive">';
1041print '<table class="tagtable liste">'."\n";
1042
1043print '<tr class="liste_titre"><td class="liste_titre">&nbsp;</td>';
1044
1045for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1046 print '<td align="center" colspan="2" class="liste_titre borderrightlight">';
1047 print '<a href="clientfourn.php?year='.((int) $annee).'">';
1048 print $annee;
1049 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
1050 print '-'.($annee + 1);
1051 }
1052 print '</a></td>';
1053}
1054print '</tr>';
1055print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
1056// Loop on each year to output
1057for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1058 print '<td class="liste_titre" align="center">';
1059 $htmlhelp = '';
1060 // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("PurchasesPlusVATEarnedAndDue");
1061 print $form->textwithpicto($langs->trans("Outcome"), $htmlhelp);
1062 print '</td>';
1063 print '<td class="liste_titre" align="center" class="borderrightlight">';
1064 $htmlhelp = '';
1065 // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("SalesPlusVATToRetrieve");
1066 print $form->textwithpicto($langs->trans("Income"), $htmlhelp);
1067 print '</td>';
1068}
1069print '</tr>';
1070
1071
1072// Loop on each month
1073$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1074for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1075 $mois_modulo = $mois;
1076 if ($mois > 12) {
1077 $mois_modulo = $mois - 12;
1078 }
1079
1080 print '<tr class="oddeven">';
1081 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $year_start), "%B")."</td>";
1082 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1083 $annee_decalage = $annee;
1084 if ($mois > 12) {
1085 $annee_decalage = $annee + 1;
1086 }
1087 //$case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
1088 $case = dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage), "%Y-%m");
1089 print '<td class="right">';
1090 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1091 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1092 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.'&modecompta='.$modecompta.'">'.price(price2num($decaiss[$case], 'MT')).'</a>';
1093 if (!isset($totsorties[$annee])) {
1094 $totsorties[$annee] = 0;
1095 }
1096 $totsorties[$annee] += $decaiss[$case];
1097 }
1098 } else {
1099 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1100 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($decaiss_ttc[$case], 'MT')).'</a>';
1101 if (!isset($totsorties[$annee])) {
1102 $totsorties[$annee] = 0;
1103 }
1104 $totsorties[$annee] += $decaiss_ttc[$case];
1105 }
1106 }
1107 print "</td>";
1108
1109 print '<td class="borderrightlight nowrap right">';
1110 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1111 if (isset($encaiss[$case])) {
1112 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.'&modecompta='.$modecompta.'">'.price(price2num($encaiss[$case], 'MT')).'</a>';
1113 if (!isset($totentrees[$annee])) {
1114 $totentrees[$annee] = 0;
1115 }
1116 $totentrees[$annee] += $encaiss[$case];
1117 }
1118 } else {
1119 if (isset($encaiss_ttc[$case])) {
1120 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($encaiss_ttc[$case], 'MT')).'</a>';
1121 if (!isset($totentrees[$annee])) {
1122 $totentrees[$annee] = 0;
1123 }
1124 $totentrees[$annee] += $encaiss_ttc[$case];
1125 }
1126 }
1127 print "</td>";
1128 }
1129
1130 print '</tr>';
1131}
1132
1133// Total
1134
1135$nbcols = 0;
1136print '<tr class="liste_total impair"><td>';
1137if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1138 print $langs->trans("Total");
1139} else {
1140 print $langs->trans("TotalTTC");
1141}
1142print '</td>';
1143for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1144 $nbcols += 2;
1145 print '<td class="nowrap right">'.(isset($totsorties[$annee]) ? price(price2num($totsorties[$annee], 'MT')) : '&nbsp;').'</td>';
1146 print '<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ? price(price2num($totentrees[$annee], 'MT')) : '&nbsp;').'</td>';
1147}
1148print "</tr>\n";
1149
1150// Empty line
1151print '<tr class="impair"><td>&nbsp;</td>';
1152print '<td colspan="'.$nbcols.'">&nbsp;</td>';
1153print "</tr>\n";
1154
1155// Balance
1156
1157print '<tr class="liste_total"><td>'.$langs->trans("AccountingResult").'</td>';
1158for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1159 print '<td colspan="2" class="borderrightlight right"> ';
1160 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1161 $in = (isset($totentrees[$annee]) ? price2num($totentrees[$annee], 'MT') : 0);
1162 $out = (isset($totsorties[$annee]) ? price2num($totsorties[$annee], 'MT') : 0);
1163 print price(price2num($in - $out, 'MT')).'</td>';
1164 // print '<td>&nbsp;</td>';
1165 }
1166}
1167print "</tr>\n";
1168
1169print "</table>";
1170print '</div>';
1171
1172// End of page
1173llxFooter();
1174$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:616
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:635
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
img_next($titlealt='default', $moreatt='')
Show next logo.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.