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