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