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