30require
'../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
43$langs->loadLangs(array(
"compta",
"bills",
"other",
"accountancy"));
57$year_end = $year_start + 1;
58$month_end = $month_start - 1;
63$search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
65$year_current = $year_start;
68$action =
GETPOST(
'action',
'aZ09');
76if ($user->socid > 0) {
79if (!$user->hasRight(
'accounting',
'bind',
'write')) {
90if (($action ==
'clean' || $action ==
'validatehistory') && $user->hasRight(
'accounting',
'bind',
'write')) {
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);
114if ($action ==
'validatehistory' && $user->hasRight(
'accounting',
'bind',
'write')) {
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) {
133 dol_syslog(
'htdocs/accountancy/expensereport/index.php');
135 $result =
$db->query($sql1);
140 $num_lines =
$db->num_rows($result);
143 while ($i < min($num_lines, 10000)) {
144 $objp =
$db->fetch_object($result);
146 $lineid = $objp->rowid;
147 $suggestedid = $objp->suggestedid;
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);
154 $resqlupdate =
$db->query($sqlupdate);
170 if ($num_lines > 10000) {
171 $notpossible += ($num_lines - 10000);
179 setEventMessages($langs->trans(
'AutomaticBindingDone', $nbbinddone, $notpossible),
null, ($notpossible ?
'warnings' :
'mesgs'));
181 setEventMessages($langs->trans(
'DoManualBindingForFailedRecord', $nbbindfailed),
null,
'warnings');
190$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables';
192llxHeader(
'', $langs->trans(
"ExpenseReportsVentilation"), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy accountancy-expensereport page-list');
194$textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
195$textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
198print
load_fiche_titre($langs->trans(
"ExpenseReportsVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
200print
'<div class="info">';
201print
'<span class="">'.$langs->trans(
"DescVentilExpenseReport").
'</span><br>';
202print
'<span class="hideonsmartphone">'.$langs->trans(
"DescVentilExpenseReportMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
208$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>';
211print_barre_liste(
img_picto(
'',
'unlink',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesNotBound"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1, 0, $buttonbind);
214print
'<div class="div-table-responsive-no-min">';
215print
'<table class="noborder centpercent">';
216print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
217for ($i = 1; $i <= 12; $i++) {
223 if ($cursormonth > 12) {
226 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
229 print
'<td width="60" class="right">';
230 if (!empty($tmp[
'mday'])) {
231 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
232 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
233 $param .=
'&search_month='.$tmp[
'mon'].
'&search_year='.$tmp[
'year'];
234 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/expensereport/list.php?'.$param.
'">';
236 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
237 if (!empty($tmp[
'mday'])) {
242print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
244$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
245$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
246for ($i = 1; $i <= 12; $i++) {
251 $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).
",";
252 $sql .=
" SUM(".$db->ifsql(
"MONTH(er.date_debut) = ".((
string) $j),
"1",
"0").
") AS nbmonth".str_pad((
string) $j, 2,
"0", STR_PAD_LEFT).
",";
254$sql .=
" SUM(erd.total_ht) as total, COUNT(erd.rowid) as nb";
255$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
256$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
257$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
258$sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
259$sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
262 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
265$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
266$sql .=
" AND aa.account_number IS NULL";
267$sql .=
" GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
268$sql .=
' ORDER BY aa.account_number';
270dol_syslog(
'/accountancy/expensereport/index.php', LOG_DEBUG);
271$resql =
$db->query($sql);
273 $num =
$db->num_rows($resql);
275 while ($row =
$db->fetch_row($resql)) {
276 print
'<tr class="oddeven">';
278 if ($row[0] ==
'tobind') {
285 if ($row[0] ==
'tobind') {
287 if ($startmonth > 12) {
290 $startyear = ($startmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
292 if ($endmonth > 12) {
295 $endyear = ($endmonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
296 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"));
301 for ($i = 2; $i <= 13; $i++) {
302 $cursormonth = (
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
303 if ($cursormonth > 12) {
306 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
309 print
'<td class="right nowraponall amount" title="'.price($row[2 * $i - 2]).
' - '.$row[2 * $i - 1].
' lines">';
310 print
price($row[2 * $i - 2]);
312 if (!empty(
price2num($row[2 * $i - 2])) || !empty($row[2 * $i - 1])) {
313 print
'<a href="'.$_SERVER[
'PHP_SELF'].
'?action=validatehistory&year='.$y.
'&validatemonth='.((int) $cursormonth).
'&validateyear='.((int) $cursoryear).
'&token='.newToken().
'">';
314 print
img_picto($langs->trans(
"ValidateHistory").
' ('.$langs->trans(
'Month'.str_pad((
string) $cursormonth, 2,
'0', STR_PAD_LEFT)).
' '.$cursoryear.
')',
'link',
'class="marginleft2"');
319 print
'<td class="right nowraponall amount"><b>'.price($row[26]).
'</b></td>';
325 print
'<tr class="oddeven"><td colspan="15">';
326 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
330 print
$db->lasterror();
339print_barre_liste(
img_picto(
'',
'link',
'class="paddingright fa-color-unset"').$langs->trans(
"OverviewOfAmountOfLinesBound"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
343print
'<div class="div-table-responsive-no-min">';
344print
'<table class="noborder centpercent">';
345print
'<tr class="liste_titre"><td class="minwidth100">'.$langs->trans(
"Account").
'</td>';
346for ($i = 1; $i <= 12; $i++) {
352 if ($cursormonth > 12) {
355 $cursoryear = ($cursormonth <
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
358 print
'<td width="60" class="right">';
359 if (!empty($tmp[
'mday'])) {
360 $param =
'search_date_startday=1&search_date_startmonth='.$cursormonth.
'&search_date_startyear='.$cursoryear;
361 $param .=
'&search_date_endday='.$tmp[
'mday'].
'&search_date_endmonth='.$tmp[
'mon'].
'&search_date_endyear='.$tmp[
'year'];
362 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/expensereport/lines.php?'.$param.
'">';
364 print $langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT));
365 if (!empty($tmp[
'mday'])) {
370print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
372$sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
373$sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
374for ($i = 1; $i <= 12; $i++) {
379 $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).
",";
381$sql .=
" ROUND(SUM(erd.total_ht),2) as total";
382$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
383$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
384$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
385$sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
386$sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
389 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
392$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
393$sql .=
" AND aa.account_number IS NOT NULL";
394$sql .=
" GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
396dol_syslog(
'htdocs/accountancy/expensereport/index.php');
397$resql =
$db->query($sql);
399 $num =
$db->num_rows($resql);
401 while ($row =
$db->fetch_row($resql)) {
402 print
'<tr class="oddeven">';
403 print
'<td class="tdoverflowmax300"'.(empty($row[1]) ?
'' :
' title="'.dol_escape_htmltag($row[1]).
'"').
'>';
404 if ($row[0] ==
'tobind') {
409 if ($row[0] ==
'tobind') {
410 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/expensereport/list.php?search_year='.((
int) $y), $langs->transnoentitiesnoconv(
"ToBind"));
415 for ($i = 2; $i <= 13; $i++) {
416 print
'<td class="right nowraponall amount">';
417 print
price($row[$i]);
420 print
'<td class="right nowraponall amount"><b>'.price($row[14]).
'</b></td>';
426 print
'<tr class="oddeven"><td colspan="15">';
427 print
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
431 print
$db->lasterror();
442 print_barre_liste($langs->trans(
"OtherInfo"), 0,
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
445 print
'<div class="div-table-responsive-no-min">';
446 print
'<table class="noborder centpercent">';
447 print
'<tr class="liste_titre"><td class="left">'.$langs->trans(
"Total").
'</td>';
448 for ($i = 1; $i <= 12; $i++) {
453 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad((
string) $j, 2,
'0', STR_PAD_LEFT)).
'</td>';
455 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
457 $sql =
"SELECT '".$db->escape($langs->trans(
"TotalExpenseReport")).
"' AS label,";
458 for ($i = 1; $i <= 12; $i++) {
463 $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).
",";
465 $sql .=
" SUM(erd.total_ht) as total";
466 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
467 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
468 $sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
469 $sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
472 $sql .=
" AND er.date_debut >= '".$db->idate(
getDolGlobalInt(
'ACCOUNTING_DATE_START_BINDING')).
"'";
475 $sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
477 dol_syslog(
'htdocs/accountancy/expensereport/index.php');
478 $resql =
$db->query($sql);
480 $num =
$db->num_rows($resql);
482 while ($row =
$db->fetch_row($resql)) {
483 print
'<tr><td>'.$row[0].
'</td>';
484 for ($i = 1; $i <= 12; $i++) {
485 print
'<td class="right nowraponall amount">'.price($row[$i]).
'</td>';
487 print
'<td class="right nowraponall amount"><b>'.price($row[13]).
'</b></td>';
493 print
$db->lasterror();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
img_next($titlealt='default', $moreatt='')
Show next logo.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.