dolibarr 21.0.0-beta
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) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
6 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
10 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('compta', 'bills', 'donation', '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
160$encaiss = array();
161$encaiss_ttc = array();
162$decaiss = array();
163$decaiss_ttc = array();
164
165// Affiche en-tete du rapport
166if ($modecompta == 'CREANCES-DETTES') {
167 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
168 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
169 $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>" : "");
170 $description = $langs->trans("RulesAmountWithTaxExcluded");
171 $description .= '<br>'.$langs->trans("RulesResultDue");
172 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
173 $description .= "<br>".$langs->trans("DepositsAreNotIncluded");
174 } else {
175 $description .= "<br>".$langs->trans("DepositsAreIncluded");
176 }
177 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
178 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
179 }
180 $builddate = dol_now();
181 //$exportlink=$langs->trans("NotYetAvailable");
182} elseif ($modecompta == "RECETTES-DEPENSES") {
183 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
184 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
185 $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>" : "");
186 $description = $langs->trans("RulesAmountWithTaxIncluded");
187 $description .= '<br>'.$langs->trans("RulesResultInOut");
188 $builddate = dol_now();
189 //$exportlink=$langs->trans("NotYetAvailable");
190} elseif ($modecompta == "BOOKKEEPING") {
191 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
192 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
193 $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>" : "");
194 $description = $langs->trans("RulesAmountOnInOutBookkeepingRecord");
195 $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")).')';
196 $builddate = dol_now();
197 //$exportlink=$langs->trans("NotYetAvailable");
198}
199
200// Define $calcmode line
201$calcmode = '';
202if (isModEnabled('accounting')) {
203 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
204 $calcmode .= '<br>';
205}
206$calcmode .= '<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta1"> '.$langs->trans("CalcModePayment");
207if (isModEnabled('accounting')) {
208 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
209}
210$calcmode .= '</label>';
211$calcmode .= '<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
212if (isModEnabled('accounting')) {
213 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
214}
215$calcmode .= '</label>';
216
217report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
218
219if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
220 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
221}
222
223
224
225/*
226 * Factures clients
227 */
228
229$subtotal_ht = 0;
230$subtotal_ttc = 0;
231if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
232 if ($modecompta == 'CREANCES-DETTES') {
233 $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
234 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
235 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
236 $sql .= " WHERE f.fk_soc = s.rowid";
237 $sql .= " AND f.fk_statut IN (1,2)";
238 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
239 $sql .= " AND f.type IN (0,1,2,5)";
240 } else {
241 $sql .= " AND f.type IN (0,1,2,3,5)";
242 }
243 if (!empty($date_start) && !empty($date_end)) {
244 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
245 }
246 } elseif ($modecompta == "RECETTES-DEPENSES") {
247 /*
248 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les
249 * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin)
250 */
251 $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
252 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
253 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
254 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
255 $sql .= " WHERE p.rowid = pf.fk_paiement";
256 $sql .= " AND pf.fk_facture = f.rowid";
257 if (!empty($date_start) && !empty($date_end)) {
258 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
259 }
260 }
261 $sql .= " AND f.entity IN (".getEntity('invoice').")";
262 if ($socid) {
263 $sql .= " AND f.fk_soc = ".((int) $socid);
264 }
265 $sql .= " GROUP BY dm";
266 $sql .= " ORDER BY dm";
267
268 //print $sql;
269 dol_syslog("get customers invoices", LOG_DEBUG);
270 $result = $db->query($sql);
271 if ($result) {
272 $num = $db->num_rows($result);
273 $i = 0;
274 while ($i < $num) {
275 $row = $db->fetch_object($result);
276 $encaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
277 $encaiss_ttc[$row->dm] = $row->amount_ttc;
278 $i++;
279 }
280 $db->free($result);
281 } else {
282 dol_print_error($db);
283 }
284} // elseif ($modecompta == "BOOKKEEPING") {
285// Nothing from this table
286//}
287
288if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
289 // On ajoute les paiements clients anciennes version, non lies par paiement_facture
290 if ($modecompta != 'CREANCES-DETTES') {
291 $sql = "SELECT sum(p.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
292 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
293 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
294 $sql .= ", ".MAIN_DB_PREFIX."paiement as p";
295 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
296 $sql .= " WHERE pf.rowid IS NULL";
297 $sql .= " AND p.fk_bank = b.rowid";
298 $sql .= " AND b.fk_account = ba.rowid";
299 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
300 if (!empty($date_start) && !empty($date_end)) {
301 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
302 }
303 $sql .= " GROUP BY dm";
304 $sql .= " ORDER BY dm";
305
306 dol_syslog("get old customers payments not linked to invoices", LOG_DEBUG);
307 $result = $db->query($sql);
308 if ($result) {
309 $num = $db->num_rows($result);
310 $i = 0;
311 while ($i < $num) {
312 $row = $db->fetch_object($result);
313
314 if (!isset($encaiss[$row->dm])) {
315 $encaiss[$row->dm] = 0;
316 }
317 $encaiss[$row->dm] += (isset($row->amount_ht) ? $row->amount_ht : 0);
318
319 if (!isset($encaiss_ttc[$row->dm])) {
320 $encaiss_ttc[$row->dm] = 0;
321 }
322 $encaiss_ttc[$row->dm] += $row->amount_ttc;
323
324 $i++;
325 }
326 } else {
327 dol_print_error($db);
328 }
329 } //elseif ($modecompta == "RECETTES-DEPENSES") {
330 // Nothing from this table
331 //}
332} //elseif ($modecompta == "BOOKKEEPING") {
333// Nothing from this table
334//}
335
336
337/*
338 * Frais, factures fournisseurs.
339 */
340$subtotal_ht = 0;
341$subtotal_ttc = 0;
342
343if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
344 if ($modecompta == 'CREANCES-DETTES') {
345 $sql = "SELECT sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc, date_format(f.datef,'%Y-%m') as dm";
346 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
347 $sql .= " WHERE f.fk_statut IN (1,2)";
348 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
349 $sql .= " AND f.type IN (0,1,2)";
350 } else {
351 $sql .= " AND f.type IN (0,1,2,3)";
352 }
353 if (!empty($date_start) && !empty($date_end)) {
354 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
355 }
356 } elseif ($modecompta == "RECETTES-DEPENSES") {
357 $sql = "SELECT sum(pf.amount) as amount_ttc, date_format(p.datep,'%Y-%m') as dm";
358 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
359 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
360 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
361 $sql .= " WHERE f.rowid = pf.fk_facturefourn";
362 $sql .= " AND p.rowid = pf.fk_paiementfourn";
363 if (!empty($date_start) && !empty($date_end)) {
364 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
365 }
366 }
367 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
368
369 if ($socid) {
370 $sql .= " AND f.fk_soc = ".((int) $socid);
371 }
372 $sql .= " GROUP BY dm";
373
374 dol_syslog("get suppliers invoices", LOG_DEBUG);
375 $result = $db->query($sql);
376 if ($result) {
377 $num = $db->num_rows($result);
378 $i = 0;
379 while ($i < $num) {
380 $row = $db->fetch_object($result);
381
382 if (!isset($decaiss[$row->dm])) {
383 $decaiss[$row->dm] = 0;
384 }
385 $decaiss[$row->dm] = (isset($row->amount_ht) ? $row->amount_ht : 0);
386
387 if (!isset($decaiss_ttc[$row->dm])) {
388 $decaiss_ttc[$row->dm] = 0;
389 }
390 $decaiss_ttc[$row->dm] = $row->amount_ttc;
391
392 $i++;
393 }
394 $db->free($result);
395 } else {
396 dol_print_error($db);
397 }
398} //elseif ($modecompta == "BOOKKEEPING") {
399// Nothing from this table
400//}
401
402
403
404/*
405 * TVA
406 */
407
408$subtotal_ht = 0;
409$subtotal_ttc = 0;
410if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
411 if ($modecompta == 'CREANCES-DETTES') {
412 // TVA collected to pay
413 $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
414 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
415 $sql .= " WHERE f.fk_statut IN (1,2)";
416 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
417 $sql .= " AND f.type IN (0,1,2,5)";
418 } else {
419 $sql .= " AND f.type IN (0,1,2,3,5)";
420 }
421 $sql .= " AND f.entity IN (".getEntity('invoice').")";
422 if (!empty($date_start) && !empty($date_end)) {
423 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
424 }
425 $sql .= " GROUP BY dm";
426
427 dol_syslog("get vat to pay", LOG_DEBUG);
428 $result = $db->query($sql);
429 if ($result) {
430 $num = $db->num_rows($result);
431 $i = 0;
432 if ($num) {
433 while ($i < $num) {
434 $obj = $db->fetch_object($result);
435
436 /*if (!isset($decaiss[$obj->dm])) {
437 $decaiss[$obj->dm] = 0;
438 }
439 $decaiss[$obj->dm] += $obj->amount;*/
440
441 if (!isset($decaiss_ttc[$obj->dm])) {
442 $decaiss_ttc[$obj->dm] = 0;
443 }
444 $decaiss_ttc[$obj->dm] += $obj->amount;
445
446 $i++;
447 }
448 }
449 } else {
450 dol_print_error($db);
451 }
452 // TVA paid to get
453 $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm";
454 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
455 $sql .= " WHERE f.fk_statut IN (1,2)";
456 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
457 $sql .= " AND f.type IN (0,1,2)";
458 } else {
459 $sql .= " AND f.type IN (0,1,2,3)";
460 }
461 $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
462 if (!empty($date_start) && !empty($date_end)) {
463 $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
464 }
465 $sql .= " GROUP BY dm";
466
467 dol_syslog("get vat to receive back", LOG_DEBUG);
468 $result = $db->query($sql);
469 if ($result) {
470 $num = $db->num_rows($result);
471 $i = 0;
472 if ($num) {
473 while ($i < $num) {
474 $obj = $db->fetch_object($result);
475
476 /*if (!isset($encaiss[$obj->dm])) {
477 $encaiss[$obj->dm] = 0;
478 }
479 $encaiss[$obj->dm] += $obj->amount;*/
480
481 if (!isset($encaiss_ttc[$obj->dm])) {
482 $encaiss_ttc[$obj->dm] = 0;
483 }
484 $encaiss_ttc[$obj->dm] += $obj->amount;
485
486 $i++;
487 }
488 }
489 } else {
490 dol_print_error($db);
491 }
492 } elseif ($modecompta == "RECETTES-DEPENSES") {
493 // TVA really already paid
494 $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
495 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
496 $sql .= " WHERE amount > 0";
497 $sql .= " AND t.entity IN (".getEntity('vat').")";
498 if (!empty($date_start) && !empty($date_end)) {
499 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
500 }
501 $sql .= " GROUP BY dm";
502
503 dol_syslog("get vat really paid", LOG_DEBUG);
504 $result = $db->query($sql);
505 if ($result) {
506 $num = $db->num_rows($result);
507 $i = 0;
508 if ($num) {
509 while ($i < $num) {
510 $obj = $db->fetch_object($result);
511
512 /*if (!isset($decaiss[$obj->dm])) {
513 $decaiss[$obj->dm] = 0;
514 }
515 $decaiss[$obj->dm] += $obj->amount;*/
516
517 if (!isset($decaiss_ttc[$obj->dm])) {
518 $decaiss_ttc[$obj->dm] = 0;
519 }
520 $decaiss_ttc[$obj->dm] += $obj->amount;
521
522 $i++;
523 }
524 }
525 } else {
526 dol_print_error($db);
527 }
528 // TVA retrieved
529 $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
530 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
531 $sql .= " WHERE amount < 0";
532 $sql .= " AND t.entity IN (".getEntity('vat').")";
533 if (!empty($date_start) && !empty($date_end)) {
534 $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
535 }
536 $sql .= " GROUP BY dm";
537
538 dol_syslog("get vat really received back", LOG_DEBUG);
539 $result = $db->query($sql);
540 if ($result) {
541 $num = $db->num_rows($result);
542 $i = 0;
543 if ($num) {
544 while ($i < $num) {
545 $obj = $db->fetch_object($result);
546
547 /*if (!isset($encaiss[$obj->dm])) {
548 $encaiss[$obj->dm] = 0;
549 }
550 $encaiss[$obj->dm] += -$obj->amount;*/
551
552 if (!isset($encaiss_ttc[$obj->dm])) {
553 $encaiss_ttc[$obj->dm] = 0;
554 }
555 $encaiss_ttc[$obj->dm] += -$obj->amount;
556
557 $i++;
558 }
559 }
560 } else {
561 dol_print_error($db);
562 }
563 }
564}// elseif ($modecompta == "BOOKKEEPING") {
565// Nothing from this table
566//}
567
568/*
569 * Social contributions
570 */
571
572$subtotal_ht = 0;
573$subtotal_ttc = 0;
574if (isModEnabled('tax') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
575 if ($modecompta == 'CREANCES-DETTES') {
576 $sql = "SELECT c.libelle as nom, date_format(cs.date_ech,'%Y-%m') as dm, sum(cs.amount) as amount";
577 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
578 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
579 $sql .= " WHERE cs.fk_type = c.id";
580 if (!empty($date_start) && !empty($date_end)) {
581 $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'";
582 }
583 } elseif ($modecompta == "RECETTES-DEPENSES") {
584 $sql = "SELECT c.libelle as nom, date_format(p.datep,'%Y-%m') as dm, sum(p.amount) as amount";
585 $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
586 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
587 $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p";
588 $sql .= " WHERE p.fk_charge = cs.rowid";
589 $sql .= " AND cs.fk_type = c.id";
590 if (!empty($date_start) && !empty($date_end)) {
591 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
592 }
593 }
594
595 $sql .= " AND cs.entity IN (".getEntity('social_contributions').")";
596 $sql .= " GROUP BY c.libelle, dm";
597
598 dol_syslog("get social contributions", LOG_DEBUG);
599 $result = $db->query($sql);
600 if ($result) {
601 $num = $db->num_rows($result);
602 $i = 0;
603 if ($num) {
604 while ($i < $num) {
605 $obj = $db->fetch_object($result);
606
607 if (!isset($decaiss[$obj->dm])) {
608 $decaiss[$obj->dm] = 0;
609 }
610 $decaiss[$obj->dm] += $obj->amount;
611
612 if (!isset($decaiss_ttc[$obj->dm])) {
613 $decaiss_ttc[$obj->dm] = 0;
614 }
615 $decaiss_ttc[$obj->dm] += $obj->amount;
616
617 $i++;
618 }
619 }
620 } else {
621 dol_print_error($db);
622 }
623} //elseif ($modecompta == "BOOKKEEPING") {
624// Nothing from this table
625//}
626
627
628/*
629 * Salaries
630 */
631
632if (isModEnabled('salaries') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
633 $sql = '';
634 if ($modecompta == 'CREANCES-DETTES') {
635 $column = 's.dateep'; // we use the date of end of period of salary
636
637 $sql = "SELECT s.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(s.amount) as amount";
638 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
639 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
640 if (!empty($date_start) && !empty($date_end)) {
641 $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
642 }
643 $sql .= " GROUP BY s.label, dm";
644 }
645 if ($modecompta == "RECETTES-DEPENSES") {
646 $column = 'p.datep';
647
648 $sql = "SELECT p.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(p.amount) as amount";
649 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
650 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON p.fk_salary = s.rowid";
651 $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
652 if (!empty($date_start) && !empty($date_end)) {
653 $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
654 }
655 $sql .= " GROUP BY p.label, dm";
656 }
657
658 $subtotal_ht = 0;
659 $subtotal_ttc = 0;
660
661 dol_syslog("get social salaries payments");
662 $result = $db->query($sql);
663 if ($result) {
664 $num = $db->num_rows($result);
665 $i = 0;
666 if ($num) {
667 while ($i < $num) {
668 $obj = $db->fetch_object($result);
669
670 if (!isset($decaiss[$obj->dm])) {
671 $decaiss[$obj->dm] = 0;
672 }
673 $decaiss[$obj->dm] += $obj->amount;
674
675 if (!isset($decaiss_ttc[$obj->dm])) {
676 $decaiss_ttc[$obj->dm] = 0;
677 }
678 $decaiss_ttc[$obj->dm] += $obj->amount;
679
680 $i++;
681 }
682 }
683 } else {
684 dol_print_error($db);
685 }
686} //elseif ($modecompta == "BOOKKEEPING") {
687// Nothing from this table
688//}
689
690
691/*
692 * Expense reports
693 */
694
695if (isModEnabled('expensereport') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
696 $langs->load('trips');
697
698 if ($modecompta == 'CREANCES-DETTES') {
699 $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
700 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
701 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
702 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
703 $sql .= " AND p.fk_statut>=5";
704
705 $column = 'p.date_valid';
706 if (!empty($date_start) && !empty($date_end)) {
707 $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
708 }
709 } elseif ($modecompta == 'RECETTES-DEPENSES') {
710 $sql = "SELECT date_format(pe.datep,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc";
711 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as p";
712 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author";
713 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid";
714 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
715 $sql .= " WHERE p.entity IN (".getEntity('expensereport').")";
716 $sql .= " AND p.fk_statut>=5";
717
718 $column = 'pe.datep';
719 if (!empty($date_start) && !empty($date_end)) {
720 $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
721 }
722 }
723
724 $sql .= " GROUP BY dm";
725
726 dol_syslog("get expense report outcome");
727 $result = $db->query($sql);
728 $subtotal_ht = 0;
729 $subtotal_ttc = 0;
730 if ($result) {
731 $num = $db->num_rows($result);
732 if ($num) {
733 while ($obj = $db->fetch_object($result)) {
734 if (!isset($decaiss[$obj->dm])) {
735 $decaiss[$obj->dm] = 0;
736 }
737 $decaiss[$obj->dm] += $obj->amount_ht;
738
739 if (!isset($decaiss_ttc[$obj->dm])) {
740 $decaiss_ttc[$obj->dm] = 0;
741 }
742 $decaiss_ttc[$obj->dm] += $obj->amount_ttc;
743 }
744 }
745 } else {
746 dol_print_error($db);
747 }
748} //elseif ($modecompta == 'BOOKKEEPING') {
749// Nothing from this table
750//}
751
752
753/*
754 * Donation get dunning payments
755 */
756
757if (isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
758 $subtotal_ht = 0;
759 $subtotal_ttc = 0;
760
761 if ($modecompta == 'CREANCES-DETTES') {
762 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount";
763 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
764 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
765 $sql .= " AND fk_statut in (1,2)";
766 if (!empty($date_start) && !empty($date_end)) {
767 $sql .= " AND p.datedon >= '".$db->idate($date_start)."' AND p.datedon <= '".$db->idate($date_end)."'";
768 }
769 } elseif ($modecompta == 'RECETTES-DEPENSES') {
770 $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(pe.datep,'%Y-%m') as dm, sum(p.amount) as amount";
771 $sql .= " FROM ".MAIN_DB_PREFIX."don as p";
772 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid";
773 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
774 $sql .= " WHERE p.entity IN (".getEntity('donation').")";
775 $sql .= " AND fk_statut >= 2";
776 if (!empty($date_start) && !empty($date_end)) {
777 $sql .= " AND pe.datep >= '".$db->idate($date_start)."' AND pe.datep <= '".$db->idate($date_end)."'";
778 }
779 }
780
781 $sql .= " GROUP BY p.societe, p.firstname, p.lastname, dm";
782
783 dol_syslog("get donation payments");
784 $result = $db->query($sql);
785 if ($result) {
786 $num = $db->num_rows($result);
787 $i = 0;
788 if ($num) {
789 while ($i < $num) {
790 $obj = $db->fetch_object($result);
791
792 if (!isset($encaiss[$obj->dm])) {
793 $encaiss[$obj->dm] = 0;
794 }
795 $encaiss[$obj->dm] += $obj->amount;
796
797 if (!isset($encaiss_ttc[$obj->dm])) {
798 $encaiss_ttc[$obj->dm] = 0;
799 }
800 $encaiss_ttc[$obj->dm] += $obj->amount;
801
802 $i++;
803 }
804 }
805 } else {
806 dol_print_error($db);
807 }
808} //elseif ($modecompta == 'BOOKKEEPING') {
809// Nothing from this table
810//}
811
812/*
813 * Various Payments
814 */
815
816if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank") && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
817 // decaiss
818
819 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
820 $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
821 $sql .= ' AND p.sens = 0';
822 if (!empty($date_start) && !empty($date_end)) {
823 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
824 }
825 $sql .= ' GROUP BY dm';
826
827 dol_syslog("get various payments");
828 $result = $db->query($sql);
829 if ($result) {
830 $num = $db->num_rows($result);
831 $i = 0;
832 if ($num) {
833 while ($i < $num) {
834 $obj = $db->fetch_object($result);
835 if (!isset($decaiss_ttc[$obj->dm])) {
836 $decaiss_ttc[$obj->dm] = 0;
837 }
838 if (isset($obj->amount)) {
839 $decaiss_ttc[$obj->dm] += $obj->amount;
840 }
841 $i++;
842 }
843 }
844 } else {
845 dol_print_error($db);
846 }
847
848 // encaiss
849
850 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various AS p";
851 $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
852 $sql .= ' AND p.sens = 1';
853 if (!empty($date_start) && !empty($date_end)) {
854 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
855 }
856 $sql .= ' GROUP BY dm';
857
858 dol_syslog("get various payments");
859 $result = $db->query($sql);
860 if ($result) {
861 $num = $db->num_rows($result);
862 $i = 0;
863 if ($num) {
864 while ($i < $num) {
865 $obj = $db->fetch_object($result);
866 if (!isset($encaiss_ttc[$obj->dm])) {
867 $encaiss_ttc[$obj->dm] = 0;
868 }
869 if (isset($obj->amount)) {
870 $encaiss_ttc[$obj->dm] += $obj->amount;
871 }
872 $i++;
873 }
874 }
875 } else {
876 dol_print_error($db);
877 }
878}
879// Useless with BOOKKEEPING
880//elseif ($modecompta == 'BOOKKEEPING') {
881//}
882
883/*
884 * Payment Loan
885 */
886
887if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('loan') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
888 $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
889 $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan AS p, ".MAIN_DB_PREFIX."loan as l";
890 $sql .= " WHERE l.entity IN (".getEntity('variouspayment').")";
891 $sql .= " AND p.fk_loan = l.rowid";
892 if (!empty($date_start) && !empty($date_end)) {
893 $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
894 }
895 $sql .= ' GROUP BY dm';
896
897 dol_syslog("get loan payments");
898 $result = $db->query($sql);
899 if ($result) {
900 $num = $db->num_rows($result);
901 $i = 0;
902 if ($num) {
903 while ($i < $num) {
904 $obj = $db->fetch_object($result);
905 if (!isset($decaiss_ttc[$obj->dm])) {
906 $decaiss_ttc[$obj->dm] = 0;
907 }
908 if (isset($obj->amount)) {
909 $decaiss_ttc[$obj->dm] += $obj->amount;
910 }
911 $i++;
912 }
913 }
914 } else {
915 dol_print_error($db);
916 }
917}
918// Useless with BOOKKEEPING
919//elseif ($modecompta == 'BOOKKEEPING') {
920//}
921
922
923/*
924 * Request in mode BOOKKEEPING
925 */
926
927if (isModEnabled('accounting') && ($modecompta == 'BOOKKEEPING')) {
928 $predefinedgroupwhere = "(";
929 $predefinedgroupwhere .= " (aa.pcg_type = 'EXPENSE')";
930 $predefinedgroupwhere .= " OR ";
931 $predefinedgroupwhere .= " (aa.pcg_type = 'INCOME')";
932 $predefinedgroupwhere .= ")";
933
934 $charofaccountstring = getDolGlobalInt('CHARTOFACCOUNTS');
935 $charofaccountstring = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
936
937 $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";
938 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_account as aa";
939 $sql .= " WHERE b.entity = ".$conf->entity;
940 $sql .= " AND aa.entity = ".$conf->entity;
941 $sql .= " AND b.numero_compte = aa.account_number";
942 $sql .= " AND ".$predefinedgroupwhere;
943 $sql .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'";
944 if (!empty($date_start) && !empty($date_end)) {
945 $sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
946 }
947 $sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
948 //print $sql;
949
950 $subtotal_ht = 0;
951 $subtotal_ttc = 0;
952
953 dol_syslog("get bookkeeping record");
954 $result = $db->query($sql);
955 if ($result) {
956 $num = $db->num_rows($result);
957 $i = 0;
958 if ($num) {
959 while ($i < $num) {
960 $obj = $db->fetch_object($result);
961
962 if ($obj->pcg_type == 'INCOME') {
963 if (!isset($encaiss[$obj->dm])) {
964 $encaiss[$obj->dm] = 0; // To avoid warning of var not defined
965 }
966 $encaiss[$obj->dm] += $obj->credit;
967 $encaiss[$obj->dm] -= $obj->debit;
968 }
969 if ($obj->pcg_type == 'EXPENSE') {
970 if (!isset($decaiss[$obj->dm])) {
971 $decaiss[$obj->dm] = 0; // To avoid warning of var not defined
972 }
973 $decaiss[$obj->dm] += $obj->debit;
974 $decaiss[$obj->dm] -= $obj->credit;
975 }
976
977 // ???
978 if (!isset($encaiss_ttc[$obj->dm])) {
979 $encaiss_ttc[$obj->dm] = 0;
980 }
981 if (!isset($decaiss_ttc[$obj->dm])) {
982 $decaiss_ttc[$obj->dm] = 0;
983 }
984 $encaiss_ttc[$obj->dm] += 0;
985 $decaiss_ttc[$obj->dm] += 0;
986
987 $i++;
988 }
989 }
990 } else {
991 dol_print_error($db);
992 }
993}
994
995
996
997$action = "balance";
998$object = array(&$encaiss, &$encaiss_ttc, &$decaiss, &$decaiss_ttc);
999$parameters["mode"] = $modecompta;
1000// Initialize a technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1001$hookmanager->initHooks(array('externalbalance'));
1002$reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1003
1004
1005
1006/*
1007 * Show result array
1008 */
1009
1010$totentrees = array();
1011$totsorties = array();
1012$year_end_for_table = ($year_end - (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1 ? 1 : 0));
1013
1014print '<div class="div-table-responsive">';
1015print '<table class="tagtable liste">'."\n";
1016
1017print '<tr class="liste_titre"><td class="liste_titre">&nbsp;</td>';
1018
1019for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1020 print '<td align="center" colspan="2" class="liste_titre borderrightlight">';
1021 print '<a href="clientfourn.php?year='.((int) $annee).'">';
1022 print $annee;
1023 if (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START') > 1) {
1024 print '-'.($annee + 1);
1025 }
1026 print '</a></td>';
1027}
1028print '</tr>';
1029print '<tr class="liste_titre"><td class="liste_titre">'.$langs->trans("Month").'</td>';
1030// Loop on each year to output
1031for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1032 print '<td class="liste_titre" align="center">';
1033 $htmlhelp = '';
1034 // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("PurchasesPlusVATEarnedAndDue");
1035 print $form->textwithpicto($langs->trans("Outcome"), $htmlhelp);
1036 print '</td>';
1037 print '<td class="liste_titre" align="center" class="borderrightlight">';
1038 $htmlhelp = '';
1039 // if ($modecompta == 'RECETTES-DEPENSES') $htmlhelp=$langs->trans("SalesPlusVATToRetrieve");
1040 print $form->textwithpicto($langs->trans("Income"), $htmlhelp);
1041 print '</td>';
1042}
1043print '</tr>';
1044
1045
1046// Loop on each month
1047$nb_mois_decalage = $conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START - 1) : 0;
1048for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
1049 $mois_modulo = $mois;
1050 if ($mois > 12) {
1051 $mois_modulo = $mois - 12;
1052 }
1053
1054 print '<tr class="oddeven">';
1055 print "<td>".dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $annee), "%B")."</td>";
1056 for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1057 $annee_decalage = $annee;
1058 if ($mois > 12) {
1059 $annee_decalage = $annee + 1;
1060 }
1061 //$case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
1062 $case = dol_print_date(dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage), "%Y-%m");
1063 print '<td class="right">';
1064 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1065 if (isset($decaiss[$case]) && $decaiss[$case] != 0) {
1066 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($decaiss[$case], 'MT')).'</a>';
1067 if (!isset($totsorties[$annee])) {
1068 $totsorties[$annee] = 0;
1069 }
1070 $totsorties[$annee] += $decaiss[$case];
1071 }
1072 } else {
1073 if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) {
1074 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($decaiss_ttc[$case], 'MT')).'</a>';
1075 if (!isset($totsorties[$annee])) {
1076 $totsorties[$annee] = 0;
1077 }
1078 $totsorties[$annee] += $decaiss_ttc[$case];
1079 }
1080 }
1081 print "</td>";
1082
1083 print '<td class="borderrightlight nowrap right">';
1084 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1085 if (isset($encaiss[$case])) {
1086 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($encaiss[$case], 'MT')).'</a>';
1087 if (!isset($totentrees[$annee])) {
1088 $totentrees[$annee] = 0;
1089 }
1090 $totentrees[$annee] += $encaiss[$case];
1091 }
1092 } else {
1093 if (isset($encaiss_ttc[$case])) {
1094 print '<a href="clientfourn.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta ? '&modecompta='.$modecompta : '').'">'.price(price2num($encaiss_ttc[$case], 'MT')).'</a>';
1095 if (!isset($totentrees[$annee])) {
1096 $totentrees[$annee] = 0;
1097 }
1098 $totentrees[$annee] += $encaiss_ttc[$case];
1099 }
1100 }
1101 print "</td>";
1102 }
1103
1104 print '</tr>';
1105}
1106
1107// Total
1108
1109$nbcols = 0;
1110print '<tr class="liste_total impair"><td>';
1111if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') {
1112 print $langs->trans("Total");
1113} else {
1114 print $langs->trans("TotalTTC");
1115}
1116print '</td>';
1117for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1118 $nbcols += 2;
1119 print '<td class="nowrap right">'.(isset($totsorties[$annee]) ? price(price2num($totsorties[$annee], 'MT')) : '&nbsp;').'</td>';
1120 print '<td class="nowrap right" style="border-right: 1px solid #DDD">'.(isset($totentrees[$annee]) ? price(price2num($totentrees[$annee], 'MT')) : '&nbsp;').'</td>';
1121}
1122print "</tr>\n";
1123
1124// Empty line
1125print '<tr class="impair"><td>&nbsp;</td>';
1126print '<td colspan="'.$nbcols.'">&nbsp;</td>';
1127print "</tr>\n";
1128
1129// Balance
1130
1131print '<tr class="liste_total"><td>'.$langs->trans("AccountingResult").'</td>';
1132for ($annee = $year_start; $annee <= $year_end_for_table; $annee++) {
1133 print '<td colspan="2" class="borderrightlight right"> ';
1134 if (isset($totentrees[$annee]) || isset($totsorties[$annee])) {
1135 $in = (isset($totentrees[$annee]) ? price2num($totentrees[$annee], 'MT') : 0);
1136 $out = (isset($totsorties[$annee]) ? price2num($totsorties[$annee], 'MT') : 0);
1137 print price(price2num($in - $out, 'MT')).'</td>';
1138 // print '<td>&nbsp;</td>';
1139 }
1140}
1141print "</tr>\n";
1142
1143print "</table>";
1144print '</div>';
1145
1146// End of page
1147llxFooter();
1148$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
llxFooter()
Footer empty.
Definition document.php:107
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.