27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
33 $langs->loadLangs(array(
"compta",
"bills",
"other",
"main",
"accountancy"));
36 if (empty($conf->accounting->enabled)) {
41 if (!$user->rights->accounting->bind->write)
44 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
50 $year_end = $year_start + 1;
51 $month_end = $month_start - 1;
57 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
59 $year_current = $year_start;
62 $action =
GETPOST(
'action',
'aZ09');
70 if ($action ==
'clean' || $action ==
'validatehistory')
74 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport_det as erd";
75 $sql1 .=
" SET fk_code_ventilation = 0";
76 $sql1 .=
' WHERE erd.fk_code_ventilation NOT IN';
77 $sql1 .=
' (SELECT accnt.rowid ';
78 $sql1 .=
' FROM '.MAIN_DB_PREFIX.
'accounting_account as accnt';
79 $sql1 .=
' INNER JOIN '.MAIN_DB_PREFIX.
'accounting_system as syst';
80 $sql1 .=
' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.$conf->global->CHARTOFACCOUNTS.
' AND accnt.entity = '.$conf->entity.
')';
81 $sql1 .=
' AND erd.fk_expensereport IN (SELECT rowid FROM '.MAIN_DB_PREFIX.
'expensereport WHERE entity = '.$conf->entity.
')';
82 $sql1 .=
' AND fk_code_ventilation <> 0';
83 dol_syslog(
"htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
84 $resql1 = $db->query($sql1);
95 if ($action ==
'validatehistory') {
100 if ($db->type ==
'pgsql') {
101 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport_det";
102 $sql1 .=
" SET fk_code_ventilation = accnt.rowid";
103 $sql1 .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t, ".MAIN_DB_PREFIX.
"accounting_account as accnt , ".MAIN_DB_PREFIX.
"accounting_system as syst";
104 $sql1 .=
" WHERE ".MAIN_DB_PREFIX.
"expensereport_det.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=".$conf->global->CHARTOFACCOUNTS.
' AND accnt.entity = '.$conf->entity;
105 $sql1 .=
" AND accnt.active = 1 AND t.accountancy_code = accnt.account_number";
106 $sql1 .=
" AND ".MAIN_DB_PREFIX.
"expensereport_det.fk_code_ventilation = 0";
108 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport_det as erd, ".MAIN_DB_PREFIX.
"c_type_fees as t, ".MAIN_DB_PREFIX.
"accounting_account as accnt , ".MAIN_DB_PREFIX.
"accounting_system as syst";
109 $sql1 .=
" SET erd.fk_code_ventilation = accnt.rowid";
110 $sql1 .=
" WHERE erd.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=".$conf->global->CHARTOFACCOUNTS.
' AND accnt.entity = '.$conf->entity;
111 $sql1 .=
" AND accnt.active = 1 AND t.accountancy_code=accnt.account_number";
112 $sql1 .=
" AND erd.fk_code_ventilation = 0";
115 dol_syslog(
'htdocs/accountancy/expensereport/index.php');
117 $resql1 = $db->query($sql1);
133 llxHeader(
'', $langs->trans(
"ExpenseReportsVentilation"));
135 $textprevyear =
'<a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current - 1).
'">'.
img_previous().
'</a>';
136 $textnextyear =
' <a href="'.$_SERVER[
"PHP_SELF"].
'?year='.($year_current + 1).
'">'.
img_next().
'</a>';
138 print load_fiche_titre($langs->trans(
"ExpenseReportsVentilation").
" ".$textprevyear.
" ".$langs->trans(
"Year").
" ".$year_start.
" ".$textnextyear,
'',
'title_accountancy');
140 print '<span class="opacitymedium">'.$langs->trans(
"DescVentilExpenseReport").
'</span><br>';
141 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"DescVentilExpenseReportMore", $langs->transnoentitiesnoconv(
"ValidateHistory"), $langs->transnoentitiesnoconv(
"ToBind")).
'<br>';
147 $buttonbind =
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?year='.$year_current.
'&action=validatehistory">'.$langs->trans(
"ValidateHistory").
'</a>';
150 print_barre_liste($langs->trans(
"OverviewOfAmountOfLinesNotBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0, $buttonbind,
'', 0, 1, 1);
153 print '<div class="div-table-responsive-no-min">';
154 print
'<table class="noborder centpercent">';
155 print
'<tr class="liste_titre"><td width="200">'.$langs->trans(
"Account").
'</td>';
156 print
'<td width="200" class="left">'.$langs->trans(
"Label").
'</td>';
157 for ($i = 1; $i <= 12; $i++) {
158 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
159 if ($j > 12) $j -= 12;
160 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
162 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
164 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
165 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
166 for ($i = 1; $i <= 12; $i++) {
167 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
168 if ($j > 12) $j -= 12;
169 $sql .=
" SUM(".$db->ifsql(
'MONTH(er.date_debut)='.$j,
'erd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
171 $sql .=
" SUM(erd.total_ht) as total";
172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
173 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
174 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
175 $sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
176 $sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
178 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
179 $sql .=
" AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
182 $sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
183 $sql .=
" AND aa.account_number IS NULL";
184 $sql .=
" GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
186 dol_syslog(
'/accountancy/expensereport/index.php:: sql='.$sql);
187 $resql = $db->query($sql);
189 $num = $db->num_rows(
$resql);
191 while ($row = $db->fetch_row(
$resql)) {
192 print
'<tr class="oddeven"><td>';
193 if ($row[0] ==
'tobind')
195 print $langs->trans(
"Unknown");
198 print
'<td class="left">';
199 if ($row[0] ==
'tobind')
201 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/expensereport/list.php?search_year='.$y, $langs->transnoentitiesnoconv(
"ToBind"));
202 }
else print $row[1];
204 for ($i = 2; $i <= 12; $i++) {
205 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
207 print
'<td class="nowrap right">'.price($row[13]).
'</td>';
208 print
'<td class="nowrap right"><b>'.price($row[14]).
'</b></td>';
213 print $db->lasterror();
222 print_barre_liste($langs->trans(
"OverviewOfAmountOfLinesBound"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
226 print
'<div class="div-table-responsive-no-min">';
227 print
'<table class="noborder centpercent">';
228 print
'<tr class="liste_titre"><td width="200">'.$langs->trans(
"Account").
'</td>';
229 print
'<td width="200" class="left">'.$langs->trans(
"Label").
'</td>';
230 for ($i = 1; $i <= 12; $i++) {
231 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
232 if ($j > 12) $j -= 12;
233 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
235 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
237 $sql =
"SELECT ".$db->ifsql(
'aa.account_number IS NULL',
"'tobind'",
'aa.account_number').
" AS codecomptable,";
238 $sql .=
" ".$db->ifsql(
'aa.label IS NULL',
"'tobind'",
'aa.label').
" AS intitule,";
239 for ($i = 1; $i <= 12; $i++) {
240 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
241 if ($j > 12) $j -= 12;
242 $sql .=
" SUM(".$db->ifsql(
'MONTH(er.date_debut)='.$j,
'erd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
244 $sql .=
" ROUND(SUM(erd.total_ht),2) as total";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
246 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
247 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
248 $sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
249 $sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
251 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
252 $sql .=
" AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
255 $sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
256 $sql .=
" AND aa.account_number IS NOT NULL";
257 $sql .=
" GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label";
259 dol_syslog(
'htdocs/accountancy/expensereport/index.php');
260 $resql = $db->query($sql);
262 $num = $db->num_rows(
$resql);
264 while ($row = $db->fetch_row(
$resql)) {
265 print
'<tr class="oddeven"><td>';
266 if ($row[0] ==
'tobind')
268 print $langs->trans(
"Unknown");
272 print
'<td class="left">';
273 if ($row[0] ==
'tobind')
275 print $langs->trans(
"UseMenuToSetBindindManualy", DOL_URL_ROOT.
'/accountancy/expensereport/list.php?search_year='.$y, $langs->transnoentitiesnoconv(
"ToBind"));
276 }
else print $row[1];
278 for ($i = 2; $i <= 12; $i++) {
279 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
281 print
'<td class="nowrap right">'.price($row[13]).
'</td>';
282 print
'<td class="nowrap right"><b>'.price($row[14]).
'</b></td>';
287 print $db->lasterror();
294 if ($conf->global->MAIN_FEATURES_LEVEL > 0)
299 print_barre_liste($langs->trans(
"OtherInfo"),
'',
'',
'',
'',
'',
'', -1,
'',
'', 0,
'',
'', 0, 1, 1);
302 print
'<div class="div-table-responsive-no-min">';
303 print
'<table class="noborder centpercent">';
304 print
'<tr class="liste_titre"><td width="400" class="left">'.$langs->trans(
"Total").
'</td>';
305 for ($i = 1; $i <= 12; $i++) {
306 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
307 if ($j > 12) $j -= 12;
308 print
'<td width="60" class="right">'.$langs->trans(
'MonthShort'.str_pad($j, 2,
'0', STR_PAD_LEFT)).
'</td>';
310 print
'<td width="60" class="right"><b>'.$langs->trans(
"Total").
'</b></td></tr>';
312 $sql =
"SELECT '".$db->escape($langs->trans(
"TotalExpenseReport")).
"' AS label,";
313 for ($i = 1; $i <= 12; $i++) {
314 $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
315 if ($j > 12) $j -= 12;
316 $sql .=
" SUM(".$db->ifsql(
'MONTH(er.date_create)='.$j,
'erd.total_ht',
'0').
") AS month".str_pad($j, 2,
'0', STR_PAD_LEFT).
",";
318 $sql .=
" SUM(erd.total_ht) as total";
319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as erd";
320 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport as er ON er.rowid = erd.fk_expensereport";
321 $sql .=
" WHERE er.date_debut >= '".$db->idate($search_date_start).
"'";
322 $sql .=
" AND er.date_debut <= '".$db->idate($search_date_end).
"'";
324 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
325 $sql .=
" AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
328 $sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
330 dol_syslog(
'htdocs/accountancy/expensereport/index.php');
331 $resql = $db->query($sql);
333 $num = $db->num_rows(
$resql);
335 while ($row = $db->fetch_row(
$resql)) {
336 print
'<tr><td>'.$row[0].
'</td>';
337 for ($i = 1; $i <= 12; $i++) {
338 print
'<td class="nowrap right">'.price($row[$i]).
'</td>';
340 print
'<td class="nowrap right"><b>'.price($row[13]).
'</b></td>';
346 print $db->lasterror();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
const STATUS_CLOSED
Classified paid.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
img_next($titlealt= 'default', $moreatt= '')
Show next logo.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
img_previous($titlealt= 'default', $moreatt= '')
Show previous logo.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...