dolibarr 22.0.5
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 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
428 if (isModEnabled('don')) {
429 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Donations").'</td></tr>';
430
431 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
432 if ($modecompta == 'CREANCES-DETTES') {
433 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
434 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
435 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON d.fk_projet = p.rowid";
436 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
437 $sql .= " AND d.fk_statut in (1,2)";
438 } else {
439 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(d.amount) as amount";
440 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
441 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = d.rowid";
442 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON d.fk_projet = p.rowid";
443 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id";
444 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
445 $sql .= " AND d.fk_statut >= 2";
446 }
447 if (!empty($date_start)) {
448 $sql .= " AND d.datedon >= '".$db->idate($date_start)."'";
449 }
450 if (!empty($date_end)) {
451 $sql .= " AND d.datedon <= '".$db->idate($date_end)."'";
452 }
453 }
454 $sql .= " GROUP BY p.rowid, p.ref";
455 $newsortfield = $sortfield;
456 if ($newsortfield == 's.nom, s.rowid') {
457 $newsortfield = 'p.ref';
458 }
459 if ($newsortfield == 'amount_ht') {
460 $newsortfield = 'amount';
461 }
462 if ($newsortfield == 'amount_ttc') {
463 $newsortfield = 'amount';
464 }
465 $sql .= $db->order($newsortfield, $sortorder);
466
467 dol_syslog("by project, get dunning");
468 $result = $db->query($sql);
469 $subtotal_ht = 0;
470 $subtotal_ttc = 0;
471 if ($result) {
472 $num = $db->num_rows($result);
473 $i = 0;
474 if ($num) {
475 while ($i < $num) {
476 $obj = $db->fetch_object($result);
477
478 $total_ht += $obj->amount;
479 $total_ttc += $obj->amount;
480 $subtotal_ht += $obj->amount;
481 $subtotal_ttc += $obj->amount;
482
483 echo '<tr class="oddeven">';
484 echo '<td>&nbsp;</td>';
485 $project_ref = empty($obj->project_ref)? $langs->trans("None"): $obj->project_ref;
486 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
487
488 echo '<td class="right">';
489 if ($modecompta == 'CREANCES-DETTES') {
490 echo '<span class="amount">'.price($obj->amount).'</span>';
491 }
492 echo '</td>';
493 echo '<td class="right"><span class="amount">'.price($obj->amount).'</span></td>';
494 echo '</tr>';
495 $i++;
496 }
497 } else {
498 echo '<tr class="oddeven"><td>&nbsp;</td>';
499 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
500 echo '</tr>';
501 }
502 } else {
503 dol_print_error($db);
504 }
505
506 $total_ht_income += $subtotal_ht;
507 $total_ttc_income += $subtotal_ttc;
508
509 echo '<tr class="liste_total">';
510 echo '<td></td>';
511 echo '<td></td>';
512 echo '<td class="right">';
513 if ($modecompta == 'CREANCES-DETTES') {
514 echo price($subtotal_ht);
515 }
516 echo '</td>';
517 echo '<td class="right">'.price($subtotal_ttc).'</td>';
518 echo '</tr>';
519 }
520
521 /*
522 * Suppliers invoices
523 */
524 if ($modecompta == 'CREANCES-DETTES') {
525 $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";
526 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
527 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
528 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON f.fk_projet = p.rowid";
529 $sql .= " WHERE f.fk_soc = s.rowid";
530 $sql .= " AND f.fk_statut IN (1,2)";
531 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
532 $sql .= " AND f.type IN (0,1,2)";
533 } else {
534 $sql .= " AND f.type IN (0,1,2,3)";
535 }
536 if (!empty($date_start)) {
537 $sql .= " AND f.datef >= '".$db->idate($date_start)."'";
538 }
539 if (!empty($date_end)) {
540 $sql .= " AND f.datef <= '".$db->idate($date_end)."'";
541 }
542 } elseif ($modecompta == 'RECETTES-DEPENSES') {
543 $sql = "SELECT pr.rowid as rowid, pr.ref as project_ref, sum(pf.amount) as amount_ttc";
544 $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p";
545 $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf";
546 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f ON pf.fk_facturefourn = f.rowid";
547 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON f.fk_projet = pr.rowid";
548 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
549 $sql .= " WHERE p.rowid = pf.fk_paiementfourn ";
550 if (!empty($date_start)) {
551 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
552 }
553 if (!empty($date_end)) {
554 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
555 }
556 }
557
558 $sql .= " AND f.entity = ".((int) $conf->entity);
559 if ($socid) {
560 $sql .= " AND f.fk_soc = ".((int) $socid);
561 }
562 $sql .= " GROUP BY rowid, project_ref";
563 $sql .= $db->order($sortfield, $sortorder);
564
565 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("SuppliersInvoices").'</td></tr>';
566
567 $subtotal_ht = 0;
568 $subtotal_ttc = 0;
569 dol_syslog("by project, get suppliers invoices", LOG_DEBUG);
570 $result = $db->query($sql);
571 if ($result) {
572 $num = $db->num_rows($result);
573 $i = 0;
574 if ($num > 0) {
575 while ($i < $num) {
576 $objp = $db->fetch_object($result);
577
578 echo '<tr class="oddeven">';
579 echo '<td>&nbsp;</td>';
580
581 echo "<td>".$langs->trans("Project")." ";
582 if (!empty($objp->project_ref)) {
583 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objp->rowid.'">'.$objp->project_ref.'</a>';
584 } else {
585 echo $langs->trans("None");
586 }
587 $detailed_list_url = '';
588 //$detailed_list_url .= '?search_project='.urlencode($search_project_ref);
589 $detailed_list_url .= empty($objp->project_ref)? "?search_project_ref=^$": '?search_project_ref='.urlencode($objp->project_ref);
590 $detailed_list_url .= $search_date_url;
591 echo ' (<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php'.$detailed_list_url.'">'.$langs->trans("DetailedListLowercase")."</a>)\n";
592 echo "</td>\n";
593
594 echo '<td class="right">';
595 if ($modecompta == 'CREANCES-DETTES') {
596 echo '<span class="amount">'.price(-$objp->amount_ht)."</span>";
597 }
598 echo "</td>\n";
599 echo '<td class="right"><span class="amount">'.price(-$objp->amount_ttc)."</span></td>\n";
600
601 $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0);
602 $total_ttc -= $objp->amount_ttc;
603 $subtotal_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0);
604 $subtotal_ttc += $objp->amount_ttc;
605
606 echo "</tr>\n";
607 $i++;
608 }
609 } else {
610 echo '<tr class="oddeven">';
611 echo '<td>&nbsp;</td>';
612 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
613 echo '</tr>';
614 }
615
616 $db->free($result);
617 } else {
618 dol_print_error($db);
619 }
620
621 $total_ht_outcome += $subtotal_ht;
622 $total_ttc_outcome += $subtotal_ttc;
623
624 echo '<tr class="liste_total">';
625 echo '<td></td>';
626 echo '<td></td>';
627 echo '<td class="right">';
628 if ($modecompta == 'CREANCES-DETTES') {
629 echo price(-$subtotal_ht);
630 }
631 echo '</td>';
632 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
633 echo '</tr>';
634
635 /*
636 * Salaries
637 */
638
639 if (isModEnabled('salaries')) {
640 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("Salaries").'</td></tr>';
641
642 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
643 if ($modecompta == 'CREANCES-DETTES') {
644 $column = 's.dateep'; // We use the date of end of period of salary
645
646 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, sum(s.amount) as amount";
647 $sql .= " FROM ".MAIN_DB_PREFIX."salary as s";
648 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
649 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON s.fk_projet = p.rowid";
650 $sql .= " WHERE s.entity IN (".getEntity('salary').")";
651 if (!empty($date_start)) {
652 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
653 }
654 if (!empty($date_end)) {
655 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
656 }
657 } else {
658 $column = 'ps.datep';
659
660 $sql = "SELECT pr.rowid as rowid, pr.ref as project_ref, sum(ps.amount) as amount";
661 $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as ps";
662 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid = ps.fk_salary";
663 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = s.fk_user";
664 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON s.fk_projet = pr.rowid";
665 $sql .= " WHERE ps.entity IN (".getEntity('payment_salary').")";
666 if (!empty($date_start)) {
667 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
668 }
669 if (!empty($date_end)) {
670 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
671 }
672 }
673
674
675 $sql .= " GROUP BY rowid, project_ref";
676 $newsortfield = $sortfield;
677 if ($newsortfield == 's.nom, s.rowid') {
678 $newsortfield = 'project_ref';
679 }
680 if ($newsortfield == 'amount_ht') {
681 $newsortfield = 'amount';
682 }
683 if ($newsortfield == 'amount_ttc') {
684 $newsortfield = 'amount';
685 }
686 $sql .= $db->order($newsortfield, $sortorder);
687 }
688
689 dol_syslog("by project, get salaries");
690 $result = $db->query($sql);
691 $subtotal_ht = 0;
692 $subtotal_ttc = 0;
693 if ($result) {
694 $num = $db->num_rows($result);
695 $i = 0;
696 if ($num) {
697 while ($i < $num) {
698 $obj = $db->fetch_object($result);
699
700 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
701
702 $total_ht -= $obj->amount;
703 $total_ttc -= $obj->amount;
704 $subtotal_ht += $obj->amount;
705 $subtotal_ttc += $obj->amount;
706
707 echo '<tr class="oddeven"><td>&nbsp;</td>';
708 echo "<td>".$langs->trans("Project")." ";
709 if (!empty($objp->project_ref)) {
710 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objp->rowid.'">'.$objp->project_ref.'</a>';
711 } else {
712 echo $langs->trans("None");
713 }
714 echo "</td>\n";
715 echo '<td class="right">';
716 if ($modecompta == 'CREANCES-DETTES') {
717 echo '<span class="amount">'.price(-$obj->amount).'</span>';
718 }
719 echo '</td>';
720 echo '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
721 echo '</tr>';
722 $i++;
723 }
724 } else {
725 echo '<tr class="oddeven">';
726 echo '<td>&nbsp;</td>';
727 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
728 echo '</tr>';
729 }
730 } else {
731 dol_print_error($db);
732 }
733
734 $total_ht_outcome += $subtotal_ht;
735 $total_ttc_outcome += $subtotal_ttc;
736
737 echo '<tr class="liste_total">';
738 echo '<td></td>';
739 echo '<td></td>';
740 echo '<td class="right">';
741 if ($modecompta == 'CREANCES-DETTES') {
742 echo price(-$subtotal_ht);
743 }
744 echo '</td>';
745 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
746 echo '</tr>';
747 }
748
749
750 /*
751 * Expense report
752 */
753
754 if (isModEnabled('expensereport')) {
755 if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') {
756 $langs->load('trips');
757 if ($modecompta == 'CREANCES-DETTES') {
758 $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";
759 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as ed";
760 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport as e ON ed.fk_expensereport = e.rowid";
761 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON ed.fk_projet = p.rowid";
762 $sql .= " WHERE e.entity IN (".getEntity('expensereport').")";
763 $sql .= " AND e.fk_statut >= 5";
764
765 $column = 'e.date_valid';
766 } else {
767 $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";
768 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as ed";
769 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport as e ON ed.fk_expensereport = e.rowid";
770 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = e.rowid";
771 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON ed.fk_projet = p.rowid";
772 $sql .= " WHERE e.entity IN (".getEntity('expensereport').")";
773 $sql .= " AND e.fk_statut >= 5";
774
775 $column = 'pe.datep';
776 }
777 if (!empty($date_start)) {
778 $sql .= " AND ".$db->sanitize($column)." >= '".$db->idate($date_start)."'";
779 }
780 if (!empty($date_end)) {
781 $sql .= " AND ".$db->sanitize($column)." <= '".$db->idate($date_end)."'";
782 }
783
784 $sql .= " GROUP BY ed.rowid, ed.fk_projet, p.rowid, p.ref";
785 $newsortfield = $sortfield;
786 if ($newsortfield == 's.nom, s.rowid') {
787 $newsortfield = 'project_ref';
788 }
789 $sql .= $db->order($newsortfield, $sortorder);
790 }
791
792 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("ExpenseReport").'</td></tr>';
793
794 dol_syslog("by project, get expense report outcome");
795 $result = $db->query($sql);
796 $subtotal_ht = 0;
797 $subtotal_ttc = 0;
798 if ($result) {
799 $num = $db->num_rows($result);
800 if ($num) {
801 while ($obj = $db->fetch_object($result)) {
802 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
803
804 $total_ht -= $obj->amount_ht;
805 $total_ttc -= $obj->amount_ttc;
806 $subtotal_ht += $obj->amount_ht;
807 $subtotal_ttc += $obj->amount_ttc;
808
809 echo '<tr class="oddeven">';
810 echo '<td>&nbsp;</td>';
811
812 echo "<td>".$langs->trans("Project")." ";
813 if (!empty($obj->project_ref)) {
814 echo ' <a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$obj->project_rowid.'">'.$obj->project_ref.'</a>';
815 } else {
816 echo $langs->trans("None");
817 }
818 $detailed_list_url = '?id='.$obj->project_rowid;
819 $detailed_list_url .= $search_date_url;
820 echo ' (<a href="'.DOL_URL_ROOT.'/projet/element.php'.$detailed_list_url.'">'.$langs->trans("DetailedListLowercase")."</a>)\n";
821 echo "</td>\n";
822
823 echo '<td class="right">';
824 if ($modecompta == 'CREANCES-DETTES') {
825 echo '<span class="amount">'.price(-$obj->amount_ht).'</span>';
826 }
827 echo '</td>';
828 echo '<td class="right"><span class="amount">'.price(-$obj->amount_ttc).'</span></td>';
829 echo '</tr>';
830 }
831 } else {
832 echo '<tr class="oddeven">';
833 echo '<td>&nbsp;</td>';
834 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
835 echo '</tr>';
836 }
837 } else {
838 dol_print_error($db);
839 }
840
841 $total_ht_outcome += $subtotal_ht;
842 $total_ttc_outcome += $subtotal_ttc;
843
844 echo '<tr class="liste_total">';
845 echo '<td></td>';
846 echo '<td></td>';
847 echo '<td class="right">';
848 if ($modecompta == 'CREANCES-DETTES') {
849 echo price(-$subtotal_ht);
850 }
851 echo '</td>';
852 echo '<td class="right">'.price(-$subtotal_ttc).'</td>';
853 echo '</tr>';
854 }
855
856
857
858
859 /*
860 * Various Payments
861 */
862 //$conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY = 1;
863
864 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY') && isModEnabled("bank") && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
865 $subtotal_ht = 0;
866 $subtotal_ttc = 0;
867
868 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("VariousPayment").'</td></tr>';
869
870 // Debit
871 $sql = "SELECT p.rowid as rowid, p.ref as project_ref, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p";
872 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pj ON p.fk_projet = pj.rowid";
873 $sql .= ' WHERE 1 = 1';
874 if (!empty($date_start)) {
875 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
876 }
877 if (!empty($date_end)) {
878 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
879 }
880 $sql .= ' GROUP BY p.rowid, project_ref';
881 $sql .= ' ORDER BY project_ref';
882
883 dol_syslog('get various payments', LOG_DEBUG);
884 $result = $db->query($sql);
885 if ($result) {
886 $num = $db->num_rows($result);
887 if ($num) {
888 while ($obj = $db->fetch_object($result)) {
889 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
890
891 // Debit (payment of suppliers for example)
892 if (isset($obj->amount)) {
893 $subtotal_ht += -$obj->amount;
894 $subtotal_ttc += -$obj->amount;
895
896 $total_ht_outcome += $obj->amount;
897 $total_ttc_outcome += $obj->amount;
898 }
899 echo '<tr class="oddeven">';
900 echo '<td>&nbsp;</td>';
901 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
902 echo '<td class="right">';
903 if ($modecompta == 'CREANCES-DETTES') {
904 echo '<span class="amount">'.price(-$obj->amount).'</span>';
905 }
906 echo '</td>';
907 echo '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
908 echo "</tr>\n";
909
910 // Credit (payment received from customer for example)
911 if (isset($obj->amount)) {
912 $subtotal_ht += $obj->amount;
913 $subtotal_ttc += $obj->amount;
914
915 $total_ht_income += $obj->amount;
916 $total_ttc_income += $obj->amount;
917 }
918 echo '<tr class="oddeven"><td>&nbsp;</td>';
919 echo "<td>".$langs->trans("Project")." <a href=\"".DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid)."\">".$project_ref."</a></td>\n";
920 echo '<td class="right">';
921 if ($modecompta == 'CREANCES-DETTES') {
922 echo '<span class="amount">'.price($obj->amount).'</span>';
923 }
924 echo '</td>';
925 echo '<td class="right"><span class="amount">'.price($obj->amount)."</span></td>\n";
926 echo "</tr>\n";
927 }
928 } else {
929 echo '<tr class="oddeven">';
930 echo '<td>&nbsp;</td>';
931 echo '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
932 echo '</tr>';
933 }
934
935 // Total
936 $total_ht += $subtotal_ht;
937 $total_ttc += $subtotal_ttc;
938 echo '<tr class="liste_total">';
939 echo '<td></td>';
940 echo '<td></td>';
941 echo '<td class="right">';
942 if ($modecompta == 'CREANCES-DETTES') {
943 echo price($subtotal_ht);
944 }
945 echo '</td>';
946 echo '<td class="right">'.price($subtotal_ttc).'</td>';
947 echo '</tr>';
948 } else {
949 dol_print_error($db);
950 }
951 }
952
953 /*
954 * Payment Loan
955 */
956
957 if (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN') && isModEnabled('don') && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
958 $subtotal_ht = 0;
959 $subtotal_ttc = 0;
960
961 echo '<tr class="trforbreak"><td colspan="4">'.$langs->trans("PaymentLoan").'</td></tr>';
962
963 $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';
964 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan';
965 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet AS pj ON l.fk_projet = pj.rowid';
966 $sql .= ' WHERE 1 = 1';
967 if (!empty($date_start)) {
968 $sql .= " AND p.datep >= '".$db->idate($date_start)."'";
969 }
970 if (!empty($date_end)) {
971 $sql .= " AND p.datep <= '".$db->idate($date_end)."'";
972 }
973 $sql .= ' GROUP BY pj.rowid, project_ref';
974 $sql .= ' ORDER BY project_ref';
975
976 dol_syslog('get loan payments', LOG_DEBUG);
977 $result = $db->query($sql);
978 if ($result) {
979 require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
980 $loan_static = new Loan($db);
981
982 while ($obj = $db->fetch_object($result)) {
983 $project_ref = !empty($obj->project_ref) ? $obj->project_ref : $langs->trans("None");
984
985 echo '<tr class="oddeven"><td>&nbsp;</td>';
986 echo "<td>".$langs->trans("Project").' <a href="'.DOL_URL_ROOT."/projet/card.php?id=".((int) $obj->rowid).'">'.$project_ref."</a></td>\n";
987 if ($modecompta == 'CREANCES-DETTES') {
988 echo '<td class="right"><span class="amount">'.price(-$obj->amount).'</span></td>';
989 }
990 echo '<td class="right"><span class="amount">'.price(-$obj->amount)."</span></td>\n";
991 echo "</tr>\n";
992 $subtotal_ht -= $obj->amount;
993 $subtotal_ttc -= $obj->amount;
994 }
995 $total_ht += $subtotal_ht;
996 $total_ttc += $subtotal_ttc;
997
998 $total_ht_income += $subtotal_ht;
999 $total_ttc_income += $subtotal_ttc;
1000
1001 echo '<tr class="liste_total">';
1002 echo '<td></td>';
1003 echo '<td></td>';
1004 echo '<td class="right">';
1005 if ($modecompta == 'CREANCES-DETTES') {
1006 echo price($subtotal_ht);
1007 }
1008 echo '</td>';
1009 echo '<td class="right">'.price($subtotal_ttc).'</td>';
1010 echo '</tr>';
1011 } else {
1012 dol_print_error($db);
1013 }
1014 }
1015}
1016
1017$action = "balanceclient";
1018$object = array(&$total_ht, &$total_ttc);
1019$parameters["mode"] = $modecompta;
1020$parameters["date_start"] = $date_start;
1021$parameters["date_end"] = $date_end;
1022// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
1023$hookmanager->initHooks(array('externalbalance'));
1024$reshook = $hookmanager->executeHooks('addReportInfo', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1025echo $hookmanager->resPrint;
1026
1027
1028
1029// Total
1030
1031$nbcols = 0;
1032echo '<tr>';
1033echo '<td colspan="'.($modecompta == 'BOOKKEEPING' ? 3 : 4).'">&nbsp;</td>';
1034echo '</tr>';
1035
1036echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Income").'</td>';
1037if ($modecompta == 'CREANCES-DETTES') {
1038 echo '<td class="liste_total right nowraponall">'.price(price2num($total_ht_income, 'MT')).'</td>';
1039} elseif ($modecompta == 'RECETTES-DEPENSES') {
1040 echo '<td></td>';
1041}
1042echo '<td class="liste_total right nowraponall">'.price(price2num($total_ttc_income, 'MT')).'</td>';
1043echo '</tr>';
1044echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Outcome").'</td>';
1045if ($modecompta == 'CREANCES-DETTES') {
1046 echo '<td class="liste_total right nowraponall">'.price(price2num(-$total_ht_outcome, 'MT')).'</td>';
1047} elseif ($modecompta == 'RECETTES-DEPENSES') {
1048 echo '<td></td>';
1049}
1050echo '<td class="liste_total right nowraponall">'.price(price2num(-$total_ttc_outcome, 'MT')).'</td>';
1051echo '</tr>';
1052echo '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Profit").'</td>';
1053if ($modecompta == 'CREANCES-DETTES') {
1054 echo '<td class="liste_total right nowraponall">'.price(price2num($total_ht, 'MT')).'</td>';
1055} elseif ($modecompta == 'RECETTES-DEPENSES') {
1056 echo '<td></td>';
1057}
1058echo '<td class="liste_total right nowraponall">'.price(price2num($total_ttc, 'MT')).'</td>';
1059echo '</tr>';
1060
1061echo "</table>";
1062echo '<br>';
1063
1064// End of page
1065llxFooter();
1066
1067$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.