dolibarr 22.0.5
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
45
46$validatemonth = GETPOSTINT('validatemonth');
47$validateyear = GETPOSTINT('validateyear');
48
49$month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
50if (GETPOSTINT("year")) {
51 $year_start = GETPOSTINT("year");
52} else {
53 $year_start = dol_print_date(dol_now(), '%Y');
54 if (dol_print_date(dol_now(), '%m') < $month_start) {
55 $year_start--; // If current month is lower that starting fiscal month, we start last year
56 }
57}
58$year_end = $year_start + 1;
59$month_end = $month_start - 1;
60if ($month_end < 1) {
61 $month_end = 12;
62 $year_end--;
63}
64$search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
65$search_date_end = dol_get_last_day($year_end, $month_end);
66$year_current = $year_start;
67
68// Validate History
69$action = GETPOST('action', 'aZ09');
70
71$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
72
73// Security check
74if (!isModEnabled('accounting')) {
76}
77if ($user->socid > 0) {
79}
80if (!$user->hasRight('accounting', 'bind', 'write')) {
82}
83
84
85/*
86 * Actions
87 */
88$error = 0;
89
90if (($action == 'clean' || $action == 'validatehistory') && $user->hasRight('accounting', 'bind', 'write')) {
91 // Clean database by removing binding done on non existing or no more existing accounts
92 $db->begin();
93 $sql1 = "UPDATE ".$db->prefix()."expensereport_det as erd";
94 $sql1 .= " SET fk_code_ventilation = 0";
95 $sql1 .= ' WHERE erd.fk_code_ventilation NOT IN';
96 $sql1 .= ' (SELECT accnt.rowid ';
97 $sql1 .= ' FROM '.$db->prefix().'accounting_account as accnt';
98 $sql1 .= ' INNER JOIN '.$db->prefix().'accounting_system as syst';
99 $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.((int) getDolGlobalInt('CHARTOFACCOUNTS')).' AND accnt.entity = '.((int) $conf->entity).')';
100 $sql1 .= ' AND erd.fk_expensereport IN (SELECT rowid FROM '.$db->prefix().'expensereport WHERE entity = '.((int) $conf->entity).')';
101 $sql1 .= " AND fk_code_ventilation <> 0";
102 dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
103 $resql1 = $db->query($sql1);
104 if (!$resql1) {
105 $error++;
106 $db->rollback();
107 setEventMessages($db->lasterror(), null, 'errors');
108 } else {
109 $db->commit();
110 }
111 // End clean database
112}
113
114if ($action == 'validatehistory' && $user->hasRight('accounting', 'bind', 'write')) {
115 $nbbinddone = 0;
116 $nbbindfailed = 0;
117 $notpossible = 0;
118
119 $db->begin();
120
121 // Now make the binding
122 $sql1 = "SELECT erd.rowid, accnt.rowid as suggestedid";
123 $sql1 .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
124 $sql1 .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as t ON erd.fk_c_type_fees = t.id";
125 $sql1 .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as accnt ON t.accountancy_code = accnt.account_number AND accnt.active = 1 AND accnt.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND accnt.entity =".((int) $conf->entity).",";
126 $sql1 .= " ".MAIN_DB_PREFIX."expensereport as er";
127 $sql1 .= " WHERE erd.fk_expensereport = er.rowid AND er.entity = ".((int) $conf->entity);
128 $sql1 .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <= 0";
129 if ($validatemonth && $validateyear) {
130 $sql1 .= dolSqlDateFilter('erd.date', 0, $validatemonth, $validateyear);
131 }
132
133 dol_syslog('htdocs/accountancy/expensereport/index.php');
134
135 $result = $db->query($sql1);
136 if (!$result) {
137 $error++;
138 setEventMessages($db->lasterror(), null, 'errors');
139 } else {
140 $num_lines = $db->num_rows($result);
141
142 $i = 0;
143 while ($i < min($num_lines, 10000)) { // No more than 10000 at once
144 $objp = $db->fetch_object($result);
145
146 $lineid = $objp->rowid;
147 $suggestedid = $objp->suggestedid;
148
149 if ($suggestedid > 0) {
150 $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."expensereport_det";
151 $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid);
152 $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND rowid = ".((int) $lineid);
153
154 $resqlupdate = $db->query($sqlupdate);
155 if (!$resqlupdate) {
156 $error++;
157 setEventMessages($db->lasterror(), null, 'errors');
158 $nbbindfailed++;
159 break;
160 } else {
161 $nbbinddone++;
162 }
163 } else {
164 $notpossible++;
165 $nbbindfailed++;
166 }
167
168 $i++;
169 }
170 if ($num_lines > 10000) {
171 $notpossible += ($num_lines - 10000);
172 }
173 }
174
175 if ($error) {
176 $db->rollback();
177 } else {
178 $db->commit();
179 setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, ($notpossible ? 'warnings' : 'mesgs'));
180 if ($nbbindfailed) {
181 setEventMessages($langs->trans('DoManualBindingForFailedRecord', $nbbindfailed), null, 'warnings');
182 }
183 }
184}
185
186
187/*
188 * View
189 */
190$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
191
192llxHeader('', $langs->trans("ExpenseReportsVentilation"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-expensereport page-list');
193
194$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current - 1).'">'.img_previous().'</a>';
195$textnextyear = '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current + 1).'">'.img_next().'</a>';
196
197
198print load_fiche_titre($langs->trans("ExpenseReportsVentilation")."&nbsp;".$textprevyear."&nbsp;".$langs->trans("Year")."&nbsp;".$year_start."&nbsp;".$textnextyear, '', 'title_accountancy');
199
200print '<span class="opacitymedium">'.$langs->trans("DescVentilExpenseReport").'</span><br>';
201print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("DescVentilExpenseReportMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")).'<br>';
202print '</span><br>';
203
204
205$y = $year_current;
206
207$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
208
209
210print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
211//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
212
213print '<div class="div-table-responsive-no-min">';
214print '<table class="noborder centpercent">';
215print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
216for ($i = 1; $i <= 12; $i++) {
217 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
218 if ($j > 12) {
219 $j -= 12;
220 }
221 $cursormonth = $j;
222 if ($cursormonth > 12) {
223 $cursormonth -= 12;
224 }
225 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
226 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
227
228 print '<td width="60" class="right">';
229 if (!empty($tmp['mday'])) {
230 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
231 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
232 $param .= '&search_month='.$tmp['mon'].'&search_year='.$tmp['year'];
233 print '<a href="'.DOL_URL_ROOT.'/accountancy/expensereport/list.php?'.$param.'">';
234 }
235 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
236 if (!empty($tmp['mday'])) {
237 print '</a>';
238 }
239 print '</td>';
240}
241print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
242
243$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
244$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
245for ($i = 1; $i <= 12; $i++) {
246 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
247 if ($j > 12) {
248 $j -= 12;
249 }
250 $sql .= " SUM(".$db->ifsql("MONTH(er.date_debut) = ".((int) $j), "erd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
251 $sql .= " SUM(".$db->ifsql("MONTH(er.date_debut) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
252}
253$sql .= " SUM(erd.total_ht) as total, COUNT(erd.rowid) as nb";
254$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
255$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
256$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
257$sql .= " WHERE er.date_debut >= '".$db->idate($search_date_start)."'";
258$sql .= " AND er.date_debut <= '".$db->idate($search_date_end)."'";
259// Define begin binding date
260if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
261 $sql .= " AND er.date_debut >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
262}
263$sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")";
264$sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
265$sql .= " AND aa.account_number IS NULL";
266$sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
267$sql .= ' ORDER BY aa.account_number';
268
269dol_syslog('/accountancy/expensereport/index.php', LOG_DEBUG);
270$resql = $db->query($sql);
271if ($resql) {
272 $num = $db->num_rows($resql);
273
274 while ($row = $db->fetch_row($resql)) {
275 print '<tr class="oddeven">';
276 print '<td>';
277 if ($row[0] == 'tobind') {
278 //print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
279 } else {
280 print length_accountg($row[0]).' - ';
281 }
282 //print '</td>';
283 //print '<td>';
284 if ($row[0] == 'tobind') {
285 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
286 if ($startmonth > 12) {
287 $startmonth -= 12;
288 }
289 $startyear = ($startmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
290 $endmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + 11;
291 if ($endmonth > 12) {
292 $endmonth -= 12;
293 }
294 $endyear = ($endmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
295 print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/expensereport/list.php?search_date_startday=1&search_date_startmonth='.((int) $startmonth).'&search_date_startyear='.((int) $startyear).'&search_date_endday=&search_date_endmonth='.((int) $endmonth).'&search_date_endyear='.((int) $endyear), $langs->transnoentitiesnoconv("ToBind"));
296 } else {
297 print $row[1];
298 }
299 print '</td>';
300 for ($i = 2; $i <= 13; $i++) {
301 $cursormonth = (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
302 if ($cursormonth > 12) {
303 $cursormonth -= 12;
304 }
305 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
306 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
307
308 print '<td class="right nowraponall amount" title="'.price($row[2 * $i - 2]).' - '.$row[2 * $i - 1].' lines">';
309 print price($row[2 * $i - 2]);
310 // Add link to make binding
311 if (!empty(price2num($row[2 * $i - 2])) || !empty($row[2 * $i - 1])) {
312 print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
313 print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
314 print '</a>';
315 }
316 print '</td>';
317 }
318 print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
319 print '</tr>';
320 }
321 $db->free($resql);
322
323 if ($num == 0) {
324 print '<tr class="oddeven"><td colspan="15">';
325 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
326 print '</td></tr>';
327 }
328} else {
329 print $db->lasterror(); // Show last sql error
330}
331print "</table>\n";
332print '</div>';
333
334
335print '<br>';
336
337
338print_barre_liste(img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
339//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
340
341
342print '<div class="div-table-responsive-no-min">';
343print '<table class="noborder centpercent">';
344print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
345for ($i = 1; $i <= 12; $i++) {
346 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
347 if ($j > 12) {
348 $j -= 12;
349 }
350 $cursormonth = $j;
351 if ($cursormonth > 12) {
352 $cursormonth -= 12;
353 }
354 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
355 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
356
357 print '<td width="60" class="right">';
358 if (!empty($tmp['mday'])) {
359 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
360 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
361 print '<a href="'.DOL_URL_ROOT.'/accountancy/expensereport/lines.php?'.$param.'">';
362 }
363 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
364 if (!empty($tmp['mday'])) {
365 print '</a>';
366 }
367 print '</td>';
368}
369print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
370
371$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
372$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
373for ($i = 1; $i <= 12; $i++) {
374 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
375 if ($j > 12) {
376 $j -= 12;
377 }
378 $sql .= " SUM(".$db->ifsql("MONTH(er.date_debut) = ".((int) $j), "erd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
379}
380$sql .= " ROUND(SUM(erd.total_ht),2) as total";
381$sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
382$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
383$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
384$sql .= " WHERE er.date_debut >= '".$db->idate($search_date_start)."'";
385$sql .= " AND er.date_debut <= '".$db->idate($search_date_end)."'";
386// Define begin binding date
387if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
388 $sql .= " AND er.date_debut >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
389}
390$sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")";
391$sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
392$sql .= " AND aa.account_number IS NOT NULL";
393$sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
394
395dol_syslog('htdocs/accountancy/expensereport/index.php');
396$resql = $db->query($sql);
397if ($resql) {
398 $num = $db->num_rows($resql);
399
400 while ($row = $db->fetch_row($resql)) {
401 print '<tr class="oddeven">';
402 print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
403 if ($row[0] == 'tobind') {
404 //print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
405 } else {
406 print length_accountg($row[0]).' - ';
407 }
408 if ($row[0] == 'tobind') {
409 print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/expensereport/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
410 } else {
411 print $row[1];
412 }
413 print '</td>';
414 for ($i = 2; $i <= 13; $i++) {
415 print '<td class="right nowraponall amount">';
416 print price($row[$i]);
417 print '</td>';
418 }
419 print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
420 print '</tr>';
421 }
422 $db->free($resql);
423
424 if ($num == 0) {
425 print '<tr class="oddeven"><td colspan="15">';
426 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
427 print '</td></tr>';
428 }
429} else {
430 print $db->lasterror(); // Show last sql error
431}
432print "</table>\n";
433print '</div>';
434
435
436
437if (getDolGlobalString('SHOW_TOTAL_OF_PREVIOUS_LISTS_IN_LIN_PAGE')) { // This part of code looks strange. Why showing a report that should rely on result of this step ?
438 print '<br>';
439 print '<br>';
440
441 print_barre_liste($langs->trans("OtherInfo"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
442 //print load_fiche_titre($langs->trans("OtherInfo"), '', '');
443
444 print '<div class="div-table-responsive-no-min">';
445 print '<table class="noborder centpercent">';
446 print '<tr class="liste_titre"><td class="left">'.$langs->trans("Total").'</td>';
447 for ($i = 1; $i <= 12; $i++) {
448 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
449 if ($j > 12) {
450 $j -= 12;
451 }
452 print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT)).'</td>';
453 }
454 print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
455
456 $sql = "SELECT '".$db->escape($langs->trans("TotalExpenseReport"))."' AS label,";
457 for ($i = 1; $i <= 12; $i++) {
458 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
459 if ($j > 12) {
460 $j -= 12;
461 }
462 $sql .= " SUM(".$db->ifsql("MONTH(er.date_create) = ".((int) $j), "erd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
463 }
464 $sql .= " SUM(erd.total_ht) as total";
465 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd";
466 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport as er ON er.rowid = erd.fk_expensereport";
467 $sql .= " WHERE er.date_debut >= '".$db->idate($search_date_start)."'";
468 $sql .= " AND er.date_debut <= '".$db->idate($search_date_end)."'";
469 // Define begin binding date
470 if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
471 $sql .= " AND er.date_debut >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
472 }
473 $sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")";
474 $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
475
476 dol_syslog('htdocs/accountancy/expensereport/index.php');
477 $resql = $db->query($sql);
478 if ($resql) {
479 $num = $db->num_rows($resql);
480
481 while ($row = $db->fetch_row($resql)) {
482 print '<tr><td>'.$row[0].'</td>';
483 for ($i = 1; $i <= 12; $i++) {
484 print '<td class="right nowraponall amount">'.price($row[$i]).'</td>';
485 }
486 print '<td class="right nowraponall amount"><b>'.price($row[13]).'</b></td>';
487 print '</tr>';
488 }
489
490 $db->free($resql);
491 } else {
492 print $db->lasterror(); // Show last sql error
493 }
494 print "</table>\n";
495 print '</div>';
496}
497
498// End of page
499llxFooter();
500$db->close();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
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
const STATUS_CLOSED
Classified paid.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition date.lib.php:382
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.