dolibarr 23.0.3
projects.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
10 * Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.fr>
12 * Copyright (C) 2021-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
13 * Copyright (C) 2024 Yoan Mollard <ymollard@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
39require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
44require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
45require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
46
55// Load translation files required by the page
56$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy', 'loan'));
57
58$date_startday = GETPOSTINT('date_startday');
59$date_startmonth = GETPOSTINT('date_startmonth');
60$date_startyear = GETPOSTINT('date_startyear');
61$date_endday = GETPOSTINT('date_endday');
62$date_endmonth = GETPOSTINT('date_endmonth');
63$date_endyear = GETPOSTINT('date_endyear');
64$showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ? GETPOST('showaccountdetail', 'aZ09') : 'yes';
65
66$search_project_ref = GETPOST('search_project_ref', 'alpha');
67
68$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
69$sortfield = GETPOST('sortfield', 'aZ09comma');
70$sortorder = GETPOST('sortorder', 'aZ09comma');
71$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
72if (empty($page) || $page == -1) {
73 $page = 0;
74} // If $page is not defined, or '' or -1
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78//if (! $sortfield) $sortfield='s.nom, s.rowid';
79if (!$sortorder) {
80 $sortorder = 'ASC';
81}
82
83// Date range
84$year = GETPOSTINT('year'); // this is used for navigation previous/next. It is the last year to show in filter
85if (empty($year)) {
86 $year_current = (int) dol_print_date(dol_now(), "%Y");
87 $month_current = (int) dol_print_date(dol_now(), "%m");
88 $year_start = $year_current;
89} else {
90 $year_current = $year;
91 $month_current = (int) dol_print_date(dol_now(), "%m");
92 $year_start = $year;
93}
94$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear, 'tzserver');
95$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear, 'tzserver');
96
97// We define date_start and date_end
98if (empty($date_start) || empty($date_end)) { // We define date_start and date_end
99 $q = GETPOST("q") ? GETPOSTINT("q") : 0;
100 if ($q == 0) {
101 // We define date_start and date_end
102 $year_end = $year_start;
103 $month_start = GETPOST("month") ? GETPOSTINT("month") : getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
104 $month_end = "";
105 if (!GETPOST('month')) {
106 if (!$year && $month_start > $month_current) {
107 $year_start--;
108 $year_end--;
109 }
110 $month_end = $month_start - 1;
111 if ($month_end < 1) {
112 $month_end = 12;
113 }
114 } else {
115 $month_end = $month_start;
116 }
117 $date_start = dol_get_first_day($year_start, $month_start, false);
118 $date_end = dol_get_last_day($year_end, $month_end, false);
119 }
120 if ($q == 1) {
121 $date_start = dol_get_first_day($year_start, 1, false);
122 $date_end = dol_get_last_day($year_start, 3, false);
123 }
124 if ($q == 2) {
125 $date_start = dol_get_first_day($year_start, 4, false);
126 $date_end = dol_get_last_day($year_start, 6, false);
127 }
128 if ($q == 3) {
129 $date_start = dol_get_first_day($year_start, 7, false);
130 $date_end = dol_get_last_day($year_start, 9, false);
131 }
132 if ($q == 4) {
133 $date_start = dol_get_first_day($year_start, 10, false);
134 $date_end = dol_get_last_day($year_start, 12, false);
135 }
136}
137
138// $date_start and $date_end are defined. We force $year_start and $nbofyear
139$tmps = dol_getdate($date_start);
140$year_start = $tmps['year'];
141$tmpe = dol_getdate($date_end);
142$year_end = $tmpe['year'];
143$nbofyear = ($year_end - $year_start) + 1;
144//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'));
145
146// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES' or 'BOOKKEEPING')
147$modecompta = getDolGlobalString('ACCOUNTING_MODE', 'CREANCES-DETTES');
148/*if (isModEnabled('accounting')) {
149 $modecompta = 'BOOKKEEPING';
150}*/
151if (GETPOST("modecompta", 'alpha')) {
152 $modecompta = GETPOST("modecompta", 'alpha');
153}
154
155$AccCat = new AccountancyCategory($db);
156
157// Security check
158$socid = GETPOSTINT('socid');
159if ($user->socid > 0) {
160 $socid = $user->socid;
161}
162if (isModEnabled('comptabilite')) {
163 $result = restrictedArea($user, 'compta', '', '', 'resultat');
164}
165if (isModEnabled('accounting')) {
166 $result = restrictedArea($user, 'accounting', '', '', 'comptarapport');
167}
168$hookmanager->initHooks(['customersupplierreportlist']);
169
170
171/*
172 * View
173 */
174
175llxHeader();
176
177$form = new Form($db);
178
179$periodlink = '';
180$exportlink = '';
181
182$total_ht = 0;
183$total_ttc = 0;
184
185$name = $langs->trans("ReportInOut").', '.$langs->trans("ByProjects");
186$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
187$builddate = dol_now();
188$description = '';
189
190// Display report header
191if ($modecompta == "CREANCES-DETTES") {
192 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByProjects");
193 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
194 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
195 $description = $langs->trans("RulesAmountWithTaxExcluded");
196 $description .= '<br>'.$langs->trans("RulesResultDue");
197 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
198 $description .= "<br>".$langs->trans("DepositsAreNotIncluded");
199 } else {
200 $description .= "<br>".$langs->trans("DepositsAreIncluded");
201 }
202 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
203 $description .= $langs->trans("SupplierDepositsAreNotIncluded");
204 }
205 $builddate = dol_now();
206 //$exportlink=$langs->trans("NotYetAvailable");
207} elseif ($modecompta == "RECETTES-DEPENSES") {
208 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByProjects");
209 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
210 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."'>".img_next()."</a>" : "");
211 $description = $langs->trans("RulesAmountWithTaxIncluded");
212 $description .= '<br>'.$langs->trans("RulesResultInOut");
213 $builddate = dol_now();
214 //$exportlink=$langs->trans("NotYetAvailable");
215} elseif ($modecompta == "BOOKKEEPING") {
216 $name = $langs->trans("ReportInOut").', '.$langs->trans("ByProjects");
217 $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
218 $arraylist = array('no'=>$langs->trans("CustomerCode"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All"));
219 $period .= ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("DetailBy").'</span> '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
220 $periodlink = ($year_start ? "<a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] - 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($tmps['year'] + 1)."&modecompta=".$modecompta."&showaccountdetail=".$showaccountdetail."'>".img_next()."</a>" : "");
221 $description = $langs->trans("RulesAmountOnInOutBookkeepingRecord");
222 $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")).')';
223 $builddate = dol_now();
224 //$exportlink=$langs->trans("NotYetAvailable");
225}
226
227// Define $calcmode line
228$calcmode = '';
229/*
230if (isModEnabled('accounting')) {
231 $calcmode .= '<input type="radio" name="modecompta" id="modecompta3" value="BOOKKEEPING"'.($modecompta == 'BOOKKEEPING' ? ' checked="checked"' : '').'><label for="modecompta3"> '.$langs->trans("CalcModeBookkeeping").'</label>';
232 $calcmode .= '<br>';
233}
234*/
235$calcmode .= '<input type="radio" name="modecompta" id="modecompta1" value="RECETTES-DEPENSES"'.($modecompta == 'RECETTES-DEPENSES' ? ' checked="checked"' : '').'><label for="modecompta1"> '.$langs->trans("CalcModePayment");
236if (isModEnabled('accounting')) {
237 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
238}
239$calcmode .= '</label>';
240$calcmode .= '<br><input type="radio" name="modecompta" id="modecompta2" value="CREANCES-DETTES"'.($modecompta == 'CREANCES-DETTES' ? ' checked="checked"' : '').'><label for="modecompta2"> '.$langs->trans("CalcModeDebt");
241if (isModEnabled('accounting')) {
242 $calcmode .= ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("CalcModeNoBookKeeping").')</span>';
243}
244$calcmode .= '</label>';
245
246report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta, 'showaccountdetail'=>$showaccountdetail), $calcmode);
247
248/*
249if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
250 print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, '1');
251}
252*/
253
254// Show report array
255$param = '&modecompta='.urlencode($modecompta).'&showaccountdetail='.urlencode($showaccountdetail);
256$search_date_url = '';
257if ($date_startday) {
258 $param .= '&date_startday='.$date_startday;
259 $search_date_url .= '&search_date_startday='.$date_startday;
260}
261if ($date_startmonth) {
262 $param .= '&date_startmonth='.$date_startmonth;
263 $search_date_url .= '&search_date_startmonth='.$date_startmonth;
264}
265if ($date_startyear) {
266 $param .= '&date_startyear='.$date_startyear;
267 $search_date_url .= '&search_date_startyear='.$date_startyear;
268}
269if ($date_endday) {
270 $param .= '&date_endday='.$date_endday;
271 $search_date_url .= '&search_date_endday='.$date_endday;
272}
273if ($date_endmonth) {
274 $param .= '&date_endmonth='.$date_endmonth;
275 $search_date_url .= '&search_date_endmonth='.$date_endmonth;
276}
277if ($date_endyear) {
278 $param .= '&date_endyear='.$date_endyear;
279 $search_date_url .= '&search_date_endyear='.$date_endyear;
280}
281
282print '<table class="liste noborder centpercent">';
283print '<tr class="liste_titre">';
284
285if ($modecompta == 'BOOKKEEPING') {
286 print_liste_field_titre("ByProjects", $_SERVER["PHP_SELF"], 'f.thirdparty_code,f.rowid', '', $param, '', $sortfield, $sortorder, 'width200 ');
287} else {
288 print_liste_field_titre("", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'width200 ');
289}
291if ($modecompta == 'BOOKKEEPING') {
292 print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], 'amount', '', $param, 'class="right"', $sortfield, $sortorder);
293} else {
294 if ($modecompta == 'CREANCES-DETTES') {
295 print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], 'amount_ht', '', $param, 'class="right"', $sortfield, $sortorder);
296 } else {
297 print_liste_field_titre(''); // Make 4 columns in total whatever $modecompta is
298 }
299 print_liste_field_titre("AmountTTC", $_SERVER["PHP_SELF"], 'amount_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
300}
301print "</tr>\n";
302
303
304$total_ht_outcome = $total_ttc_outcome = $total_ht_income = $total_ttc_income = 0;
305
306if ($modecompta == 'BOOKKEEPING') {
307 echo "<p>BOOKKEEPING mode not implemented for this report type by project.</p>";
308}
309if (isModEnabled('invoice') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
310 /*
311 * Customer invoices
312 */
313 print '<tr class="trforbreak"><td colspan="4">'.$langs->trans("CustomersInvoices").'</td></tr>';
314
315 $sql = '';
316 if ($modecompta == 'CREANCES-DETTES') {
317 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
318 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
319 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
320 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON f.fk_projet = p.rowid";
321 $sql .= " WHERE f.fk_soc = s.rowid";
322 $sql .= " AND f.entity IN (".getEntity('invoice').")";
323 $sql .= " AND f.fk_statut IN (1,2)";
324 if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {
325 $sql .= " AND f.type IN (0,1,2,5)";
326 } else {
327 $sql .= " AND f.type IN (0,1,2,3,5)";
328 }
329 if (!empty($date_start)) {
330 $sql .= " AND f.datef >= '".$db->idate($date_start)."'";
331 }
332 if (!empty($date_end)) {
333 $sql .= " AND f.datef <= '".$db->idate($date_end)."'";
334 }
335 if ($socid) {
336 $sql .= " AND f.fk_soc = ".((int) $socid);
337 }
338 $sql .= " GROUP BY p.rowid, project_ref";
339 $sql .= $db->order($sortfield, $sortorder);
340 } elseif ($modecompta == 'RECETTES-DEPENSES') {
341 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(pf.amount) as amount_ttc";
342 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
343 $sql .= ", ".MAIN_DB_PREFIX."facture as f";
344 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON f.fk_projet = p.rowid";
345 $sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf";
346 $sql .= ", ".MAIN_DB_PREFIX."paiement as pa";
347 $sql .= " WHERE pa.rowid = pf.fk_paiement";
348 $sql .= " AND pf.fk_facture = f.rowid";
349 $sql .= " AND f.fk_soc = s.rowid";
350 $sql .= " AND f.entity IN (".getEntity('invoice').")";
351 if (!empty($date_start)) {
352 $sql .= " AND pa.datep >= '".$db->idate($date_start)."'";
353 }
354 if (!empty($date_start) && !empty($date_end)) {
355 $sql .= " AND pa.datep <= '".$db->idate($date_end)."'";
356 }
357 if ($socid) {
358 $sql .= " AND f.fk_soc = ".((int) $socid);
359 }
360 $sql .= " GROUP BY p.rowid, p.ref";
361 $sql .= $db->order($sortfield, $sortorder);
362 }
363
364 dol_syslog("by project, get customer invoices", LOG_DEBUG);
365 $result = $db->query($sql);
366 if ($result) {
367 $num = $db->num_rows($result);
368 $i = 0;
369 while ($i < $num) {
370 $objp = $db->fetch_object($result);
371 echo '<tr class="oddeven">';
372 echo '<td>&nbsp;</td>';
373 echo "<td>".$langs->trans("Project")." ";
374 if (!empty($objp->project_ref)) {
375 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objp->rowid.'">'.$objp->project_ref.'</a>';
376 } else {
377 echo $langs->trans("None");
378 }
379 if ($modecompta == 'CREANCES-DETTES') { // In mode payment, we can't filter on date of invoice that is different than date of payment.
380 $detailed_list_url = '';
381 $detailed_list_url .= empty($objp->project_ref)? "?search_project_ref=^$": "?search_project_ref=".urlencode($objp->project_ref);
382 $detailed_list_url .= $search_date_url;
383 echo ' (<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.$detailed_list_url.'">'.$langs->trans("DetailedListLowercase")."</a>)\n";
384 }
385 echo "</td>\n";
386 echo '<td class="right">';
387 if ($modecompta == 'CREANCES-DETTES') {
388 echo '<span class="amount">'.price($objp->amount_ht)."</span>";
389 }
390 echo "</td>\n";
391 echo '<td class="right"><span class="amount">'.price($objp->amount_ttc)."</span></td>\n";
392
393 $total_ht += ($objp->amount_ht ?? 0);
394 $total_ttc += $objp->amount_ttc;
395 echo "</tr>\n";
396 $i++;
397 }
398 $db->free($result);
399 } else {
400 dol_print_error($db);
401 }
402
403 if ($total_ttc == 0) {
404 echo '<tr class="oddeven">';
405 echo '<td>&nbsp;</td>';
406 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
407 echo '</tr>';
408 }
409
410 $total_ht_income += $total_ht;
411 $total_ttc_income += $total_ttc;
412
413 echo '<tr class="liste_total">';
414 echo '<td></td>';
415 echo '<td></td>';
416 echo '<td class="right">';
417 if ($modecompta == 'CREANCES-DETTES') {
418 echo price($total_ht);
419 }
420 echo '</td>';
421 echo '<td class="right">'.price($total_ttc).'</td>';
422 echo '</tr>';
423
424 /*
425 * Donations
426 */
427 if (isModEnabled('don')) {
428 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Donations").'</td></tr>';
429
430 if ($modecompta == 'CREANCES-DETTES') {
431 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
432 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
433 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON d.fk_projet = p.rowid";
434 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
435 $sql .= " AND d.fk_statut in (1,2)";
436 } else {
437 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
438 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
439 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = d.rowid";
440 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON d.fk_projet = p.rowid";
441 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
442 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
443 $sql .= " AND d.fk_statut >= 2";
444 }
445 if (!empty($date_start)) {
446 $sql .= " AND d.datedon >= '".$db->idate($date_start)."'";
447 }
448 if (!empty($date_end)) {
449 $sql .= " AND d.datedon <= '".$db->idate($date_end)."'";
450 }
451 $sql .= " GROUP BY p.rowid, p.ref";
452 $newsortfield = $sortfield;
453 if ($newsortfield == 's.nom, s.rowid') {
454 $newsortfield = 'p.ref';
455 }
456 if ($newsortfield == 'amount_ht') {
457 $newsortfield = 'amount';
458 }
459 if ($newsortfield == 'amount_ttc') {
460 $newsortfield = 'amount';
461 }
462 $sql .= $db->order($newsortfield, $sortorder);
463
464 dol_syslog("by project, get dunning");
465 $result = $db->query($sql);
466 $subtotal_ht = 0;
467 $subtotal_ttc = 0;
468 if ($result) {
469 $num = $db->num_rows($result);
470 $i = 0;
471 if ($num) {
472 while ($i < $num) {
473 $obj = $db->fetch_object($result);
474
475 $total_ht += $obj->amount;
476 $total_ttc += $obj->amount;
477 $subtotal_ht += $obj->amount;
478 $subtotal_ttc += $obj->amount;
479
480 echo '<tr class="oddeven">';
481 echo '<td>&nbsp;</td>';
482 $project_ref = empty($obj->project_ref)? $langs->trans("None"): $obj->project_ref;
483 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
484
485 echo '<td class="right">';
486 if ($modecompta == 'CREANCES-DETTES') {
487 echo '<span class="amount">'.price($obj->amount).'</span>';
488 }
489 echo '</td>';
490 echo '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
491 echo '</tr>';
492 $i++;
493 }
494 } else {
495 echo '<tr class="oddeven"><td>&nbsp;</td>';
496 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
497 echo '</tr>';
498 }
499 } else {
500 dol_print_error($db);
501 }
502
503 $total_ht_income += $subtotal_ht;
504 $total_ttc_income += $subtotal_ttc;
505
506 echo '<tr class="liste_total">';
507 echo '<td></td>';
508 echo '<td></td>';
509 echo '<td class="right">';
510 if ($modecompta == 'CREANCES-DETTES') {
511 echo price($subtotal_ht);
512 }
513 echo '</td>';
514 echo '<td class="right">'.price($subtotal_ttc).'</td>';
515 echo '</tr>';
516 }
517
518 /*
519 * Suppliers invoices
520 */
521 if ($modecompta == 'CREANCES-DETTES') {
522 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc";
523 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
524 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
525 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON f.fk_projet = p.rowid";
526 $sql .= " WHERE f.fk_soc = s.rowid";
527 $sql .= " AND f.fk_statut IN (1,2)";
528 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
529 $sql .= " AND f.type IN (0,1,2)";
530 } else {
531 $sql .= " AND f.type IN (0,1,2,3)";
532 }
533 if (!empty($date_start)) {
534 $sql .= " AND f.datef >= '".$db->idate($date_start)."'";
535 }
536 if (!empty($date_end)) {
537 $sql .= " AND f.datef <= '".$db->idate($date_end)."'";
538 }
539 } elseif ($modecompta == 'RECETTES-DEPENSES') {
540 $sql = "SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
541 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
542 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
543 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON pf.fk_facturefourn = f.rowid";
544 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON f.fk_projet = pr.rowid";
545 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
546 $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
547 if (!empty($date_start)) {
548 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
549 }
550 if (!empty($date_end)) {
551 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
552 }
553 }
554
555 $sql .= " AND f.entity = ".((int) $conf->entity);
556 if ($socid) {
557 $sql .= " AND f.fk_soc = ".((int) $socid);
558 }
559 $sql .= " GROUP BY rowid, project_ref";
560 $sql .= $db->order($sortfield, $sortorder);
561
562 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
563
564 $subtotal_ht = 0;
565 $subtotal_ttc = 0;
566 dol_syslog("by project, get suppliers invoices", LOG_DEBUG);
567 $result = $db->query($sql);
568 if ($result) {
569 $num = $db->num_rows($result);
570 $i = 0;
571 if ($num > 0) {
572 while ($i < $num) {
573 $objp = $db->fetch_object($result);
574
575 echo '<tr class="oddeven">';
576 echo '<td>&nbsp;</td>';
577
578 echo "<td>".$langs->trans("Project")." ";
579 if (!empty($objp->project_ref)) {
580 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objp->rowid.'">'.$objp->project_ref.'</a>';
581 } else {
582 echo $langs->trans("None");
583 }
584 $detailed_list_url = '';
585 //$detailed_list_url .= '?search_project='.urlencode($search_project_ref);
586 $detailed_list_url .= empty($objp->project_ref)? "?search_project_ref=^$": '?search_project_ref='.urlencode($objp->project_ref);
587 $detailed_list_url .= $search_date_url;
588 echo ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php'.$detailed_list_url.'">'.$langs->trans("DetailedListLowercase")."</a>)\n";
589 echo "</td>\n";
590
591 echo '<td class="right">';
592 if ($modecompta == 'CREANCES-DETTES') {
593 echo '<span class="amount">'.price(-$objp->amount_ht)."</span>";
594 }
595 echo "</td>\n";
596 echo '<td class="right"><span class="amount">'.price(-$objp->amount_ttc)."</span></td>\n";
597
598 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
599 $total_ttc -= $objp->amount_ttc;
600 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
601 $subtotal_ttc += $objp->amount_ttc;
602
603 echo "</tr>\n";
604 $i++;
605 }
606 } else {
607 echo '<tr class="oddeven">';
608 echo '<td>&nbsp;</td>';
609 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
610 echo '</tr>';
611 }
612
613 $db->free($result);
614 } else {
615 dol_print_error($db);
616 }
617
618 $total_ht_outcome += $subtotal_ht;
619 $total_ttc_outcome += $subtotal_ttc;
620
621 echo '<tr class="liste_total">';
622 echo '<td></td>';
623 echo '<td></td>';
624 echo '<td class="right">';
625 if ($modecompta == 'CREANCES-DETTES') {
626 echo price(-$subtotal_ht);
627 }
628 echo '</td>';
629 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
630 echo '</tr>';
631
632 /*
633 * Salaries
634 */
635 if (isModEnabled('salaries')) {
636 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';
637
638 if ($modecompta == 'CREANCES-DETTES') {
639 $column = 's.dateep'; // We use the date of end of period of salary
640
641 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
642 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
643 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
644 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON s.fk_projet = p.rowid";
645 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
646 if (!empty($date_start)) {
647 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
648 }
649 if (!empty($date_end)) {
650 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
651 }
652 } else {
653 $column = 'ps.datep';
654
655 $sql = "SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
656 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as ps";
657 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid = ps.fk_salary";
658 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
659 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON s.fk_projet = pr.rowid";
660 $sql .= " WHERE ps.entity IN (".getEntity('payment_salary').")";
661 if (!empty($date_start)) {
662 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
663 }
664 if (!empty($date_end)) {
665 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
666 }
667 }
668
669
670 $sql .= " GROUP BY rowid, project_ref";
671 $newsortfield = $sortfield;
672 if ($newsortfield == 's.nom, s.rowid') {
673 $newsortfield = 'project_ref';
674 }
675 if ($newsortfield == 'amount_ht') {
676 $newsortfield = 'amount';
677 }
678 if ($newsortfield == 'amount_ttc') {
679 $newsortfield = 'amount';
680 }
681 $sql .= $db->order($newsortfield, $sortorder);
682
683 dol_syslog("by project, get salaries");
684 $result = $db->query($sql);
685 $subtotal_ht = 0;
686 $subtotal_ttc = 0;
687 if ($result) {
688 $num = $db->num_rows($result);
689 $i = 0;
690 if ($num) {
691 while ($i < $num) {
692 $obj = $db->fetch_object($result);
693
694 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
695
696 $total_ht -= $obj->amount;
697 $total_ttc -= $obj->amount;
698 $subtotal_ht += $obj->amount;
699 $subtotal_ttc += $obj->amount;
700
701 echo '<tr class="oddeven"><td>&nbsp;</td>';
702 echo "<td>".$langs->trans("Project")." ";
703 if (!empty($objp->project_ref)) {
704 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objp->rowid.'">'.$objp->project_ref.'</a>';
705 } else {
706 echo $langs->trans("None");
707 }
708 echo "</td>\n";
709 echo '<td class="right">';
710 if ($modecompta == 'CREANCES-DETTES') {
711 echo '<span class="amount">'.price(-$obj->amount).'</span>';
712 }
713 echo '</td>';
714 echo '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
715 echo '</tr>';
716 $i++;
717 }
718 } else {
719 echo '<tr class="oddeven">';
720 echo '<td>&nbsp;</td>';
721 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
722 echo '</tr>';
723 }
724 } else {
725 dol_print_error($db);
726 }
727
728 $total_ht_outcome += $subtotal_ht;
729 $total_ttc_outcome += $subtotal_ttc;
730
731 echo '<tr class="liste_total">';
732 echo '<td></td>';
733 echo '<td></td>';
734 echo '<td class="right">';
735 if ($modecompta == 'CREANCES-DETTES') {
736 echo price(-$subtotal_ht);
737 }
738 echo '</td>';
739 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
740 echo '</tr>';
741 }
742
743
744 /*
745 * Expense report
746 */
747 if (isModEnabled('expensereport')) {
748 $langs->load('trips');
749 if ($modecompta == 'CREANCES-DETTES') {
750 $sql = "SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_ref, sum(ed.total_ht) as amount_ht, sum(ed.total_ttc) as amount_ttc";
751 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as ed";
752 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport as e ON ed.fk_expensereport = e.rowid";
753 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON ed.fk_projet = p.rowid";
754 $sql .= " WHERE e.entity IN (".getEntity('expensereport').")";
755 $sql .= " AND e.fk_statut >= 5";
756
757 $column = 'e.date_valid';
758 } else {
759 $sql = "SELECT ed.rowid as rowid, ed.fk_projet, p.rowid as project_rowid, p.ref as project_ref, sum(DISTINCT pe.amount) as amount_ht, sum(DISTINCT pe.amount) as amount_ttc";
760 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as ed";
761 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport as e ON ed.fk_expensereport = e.rowid";
762 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
763 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON ed.fk_projet = p.rowid";
764 $sql .= " WHERE e.entity IN (".getEntity('expensereport').")";
765 $sql .= " AND e.fk_statut >= 5";
766
767 $column = 'pe.datep';
768 }
769 if (!empty($date_start)) {
770 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
771 }
772 if (!empty($date_end)) {
773 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
774 }
775
776 $sql .= " GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
777 $newsortfield = $sortfield;
778 if ($newsortfield == 's.nom, s.rowid') {
779 $newsortfield = 'project_ref';
780 }
781 $sql .= $db->order($newsortfield, $sortorder);
782
783 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
784
785 dol_syslog("by project, get expense report outcome");
786 $result = $db->query($sql);
787 $subtotal_ht = 0;
788 $subtotal_ttc = 0;
789 if ($result) {
790 $num = $db->num_rows($result);
791 if ($num) {
792 while ($obj = $db->fetch_object($result)) {
793 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
794
795 $total_ht -= $obj->amount_ht;
796 $total_ttc -= $obj->amount_ttc;
797 $subtotal_ht += $obj->amount_ht;
798 $subtotal_ttc += $obj->amount_ttc;
799
800 echo '<tr class="oddeven">';
801 echo '<td>&nbsp;</td>';
802
803 echo "<td>".$langs->trans("Project")." ";
804 if (!empty($obj->project_ref)) {
805 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$obj->project_rowid.'">'.$obj->project_ref.'</a>';
806 } else {
807 echo $langs->trans("None");
808 }
809 $detailed_list_url = '?id='.$obj->project_rowid;
810 $detailed_list_url .= $search_date_url;
811 echo ' (<a href="'.DOL_URL_ROOT.'/projet/element.php'.$detailed_list_url.'">'.$langs->trans("DetailedListLowercase")."</a>)\n";
812 echo "</td>\n";
813
814 echo '<td class="right">';
815 if ($modecompta == 'CREANCES-DETTES') {
816 echo '<span class="amount">'.price(-$obj->amount_ht).'</span>';
817 }
818 echo '</td>';
819 echo '<td class="right"><span class="amount">'.price(-$obj->amount_ttc).'</span></td>';
820 echo '</tr>';
821 }
822 } else {
823 echo '<tr class="oddeven">';
824 echo '<td>&nbsp;</td>';
825 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
826 echo '</tr>';
827 }
828 } else {
829 dol_print_error($db);
830 }
831
832 $total_ht_outcome += $subtotal_ht;
833 $total_ttc_outcome += $subtotal_ttc;
834
835 echo '<tr class="liste_total">';
836 echo '<td></td>';
837 echo '<td></td>';
838 echo '<td class="right">';
839 if ($modecompta == 'CREANCES-DETTES') {
840 echo price(-$subtotal_ht);
841 }
842 echo '</td>';
843 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
844 echo '</tr>';
845 }
846
847
848
849
850 /*
851 * Various Payments
852 */
853 //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
854 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank")) {
855 $subtotal_ht = 0;
856 $subtotal_ttc = 0;
857
858 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VariousPayment").'</td></tr>';
859
860 // Debit
861 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
862 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pj ON p.fk_projet = pj.rowid";
863 $sql .= ' WHERE 1 = 1';
864 if (!empty($date_start)) {
865 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
866 }
867 if (!empty($date_end)) {
868 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
869 }
870 $sql .= ' GROUP BY p.rowid, project_ref';
871 $sql .= ' ORDER BY project_ref';
872
873 dol_syslog('get various payments', LOG_DEBUG);
874 $result = $db->query($sql);
875 if ($result) {
876 $num = $db->num_rows($result);
877 if ($num) {
878 while ($obj = $db->fetch_object($result)) {
879 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
880
881 // Debit (payment of suppliers for example)
882 if (isset($obj->amount)) {
883 $subtotal_ht += -$obj->amount;
884 $subtotal_ttc += -$obj->amount;
885
886 $total_ht_outcome += $obj->amount;
887 $total_ttc_outcome += $obj->amount;
888 }
889 echo '<tr class="oddeven">';
890 echo '<td>&nbsp;</td>';
891 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
892 echo '<td class="right">';
893 if ($modecompta == 'CREANCES-DETTES') {
894 echo '<span class="amount">'.price(-$obj->amount).'</span>';
895 }
896 echo '</td>';
897 echo '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
898 echo "</tr>\n";
899
900 // Credit (payment received from customer for example)
901 if (isset($obj->amount)) {
902 $subtotal_ht += $obj->amount;
903 $subtotal_ttc += $obj->amount;
904
905 $total_ht_income += $obj->amount;
906 $total_ttc_income += $obj->amount;
907 }
908 echo '<tr class="oddeven"><td>&nbsp;</td>';
909 echo "<td>".$langs->trans("Project")." <a href=\"".DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid)."\">".$project_ref."</a></td>\n";
910 echo '<td class="right">';
911 if ($modecompta == 'CREANCES-DETTES') {
912 echo '<span class="amount">'.price($obj->amount).'</span>';
913 }
914 echo '</td>';
915 echo '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
916 echo "</tr>\n";
917 }
918 } else {
919 echo '<tr class="oddeven">';
920 echo '<td>&nbsp;</td>';
921 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
922 echo '</tr>';
923 }
924
925 // Total
926 $total_ht += $subtotal_ht;
927 $total_ttc += $subtotal_ttc;
928 echo '<tr class="liste_total">';
929 echo '<td></td>';
930 echo '<td></td>';
931 echo '<td class="right">';
932 if ($modecompta == 'CREANCES-DETTES') {
933 echo price($subtotal_ht);
934 }
935 echo '</td>';
936 echo '<td class="right">'.price($subtotal_ttc).'</td>';
937 echo '</tr>';
938 } else {
939 dol_print_error($db);
940 }
941 }
942
943 /*
944 * Payment Loan
945 */
946 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('don')) {
947 $subtotal_ht = 0;
948 $subtotal_ttc = 0;
949
950 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("PaymentLoan").'</td></tr>';
951
952 $sql = 'SELECT pj.rowid as rowid, pj.ref as project_ref, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.'payment_loan as p';
953 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan';
954 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet AS pj ON l.fk_projet = pj.rowid';
955 $sql .= ' WHERE 1 = 1';
956 if (!empty($date_start)) {
957 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
958 }
959 if (!empty($date_end)) {
960 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
961 }
962 $sql .= ' GROUP BY pj.rowid, project_ref';
963 $sql .= ' ORDER BY project_ref';
964
965 dol_syslog('get loan payments', LOG_DEBUG);
966 $result = $db->query($sql);
967 if ($result) {
968 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
969 $loan_static = new Loan($db);
970
971 while ($obj = $db->fetch_object($result)) {
972 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
973
974 echo '<tr class="oddeven"><td>&nbsp;</td>';
975 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
976 if ($modecompta == 'CREANCES-DETTES') {
977 echo '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
978 }
979 echo '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
980 echo "</tr>\n";
981 $subtotal_ht -= $obj->amount;
982 $subtotal_ttc -= $obj->amount;
983 }
984 $total_ht += $subtotal_ht;
985 $total_ttc += $subtotal_ttc;
986
987 $total_ht_income += $subtotal_ht;
988 $total_ttc_income += $subtotal_ttc;
989
990 echo '<tr class="liste_total">';
991 echo '<td></td>';
992 echo '<td></td>';
993 echo '<td class="right">';
994 if ($modecompta == 'CREANCES-DETTES') {
995 echo price($subtotal_ht);
996 }
997 echo '</td>';
998 echo '<td class="right">'.price($subtotal_ttc).'</td>';
999 echo '</tr>';
1000 } else {
1001 dol_print_error($db);
1002 }
1003 }
1004}
1005
1006$action = "balanceclient";
1007$object = array(&$total_ht, &$total_ttc);
1008$parameters["mode"] = $modecompta;
1009$parameters["date_start"] = $date_start;
1010$parameters["date_end"] = $date_end;
1011// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1012$hookmanager->initHooks(array('externalbalance'));
1013$reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1014echo $hookmanager->resPrint;
1015
1016
1017
1018// Total
1019
1020$nbcols = 0;
1021echo '<tr>';
1022echo '<td colspan="'.($modecompta == 'BOOKKEEPING' ? 3 : 4).'">&nbsp;</td>';
1023echo '</tr>';
1024
1025echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Income").'</td>';
1026if ($modecompta == 'CREANCES-DETTES') {
1027 echo '<td class="liste_total right nowraponall">'.price(price2num($total_ht_income, 'MT')).'</td>';
1028} elseif ($modecompta == 'RECETTES-DEPENSES') {
1029 echo '<td></td>';
1030}
1031echo '<td class="liste_total right nowraponall">'.price(price2num($total_ttc_income, 'MT')).'</td>';
1032echo '</tr>';
1033echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Outcome").'</td>';
1034if ($modecompta == 'CREANCES-DETTES') {
1035 echo '<td class="liste_total right nowraponall">'.price(price2num(-$total_ht_outcome, 'MT')).'</td>';
1036} elseif ($modecompta == 'RECETTES-DEPENSES') {
1037 echo '<td></td>';
1038}
1039echo '<td class="liste_total right nowraponall">'.price(price2num(-$total_ttc_outcome, 'MT')).'</td>';
1040echo '</tr>';
1041echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Profit").'</td>';
1042if ($modecompta == 'CREANCES-DETTES') {
1043 echo '<td class="liste_total right nowraponall">'.price(price2num($total_ht, 'MT')).'</td>';
1044} elseif ($modecompta == 'RECETTES-DEPENSES') {
1045 echo '<td></td>';
1046}
1047echo '<td class="liste_total right nowraponall">'.price(price2num($total_ttc, 'MT')).'</td>';
1048echo '</tr>';
1049
1050echo "</table>";
1051echo '<br>';
1052
1053// End of page
1054llxFooter();
1055
1056$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage categories of an accounting account.
Class to manage generation of HTML components Only common components must be here.
Loan.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:603
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:622
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.