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