28 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
39 $langs->loadLangs(array(
"bills",
"companies",
"compta",
"accountancy",
"other",
"trips",
"productbatch",
"hrm"));
41 $action =
GETPOST(
'action',
'aZ09');
42 $massaction =
GETPOST(
'massaction',
'alpha');
43 $confirm =
GETPOST(
'confirm',
'alpha');
44 $toselect =
GETPOST(
'toselect',
'array');
45 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountancyexpensereportlist';
46 $optioncss =
GETPOST(
'optioncss',
'aZ');
50 $mesCasesCochees =
GETPOST(
'toselect',
'array');
53 $search_login =
GETPOST(
'search_login',
'alpha');
54 $search_lineid =
GETPOST(
'search_lineid',
'alpha');
55 $search_expensereport =
GETPOST(
'search_expensereport',
'alpha');
56 $search_label =
GETPOST(
'search_label',
'alpha');
57 $search_desc =
GETPOST(
'search_desc',
'alpha');
58 $search_amount =
GETPOST(
'search_amount',
'alpha');
59 $search_account =
GETPOST(
'search_account',
'alpha');
60 $search_vat =
GETPOST(
'search_vat',
'alpha');
61 $search_date_startday =
GETPOST(
'search_date_startday',
'int');
62 $search_date_startmonth =
GETPOST(
'search_date_startmonth',
'int');
63 $search_date_startyear =
GETPOST(
'search_date_startyear',
'int');
64 $search_date_endday =
GETPOST(
'search_date_endday',
'int');
65 $search_date_endmonth =
GETPOST(
'search_date_endmonth',
'int');
66 $search_date_endyear =
GETPOST(
'search_date_endyear',
'int');
67 $search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
68 $search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
71 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
72 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
73 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
75 if (empty($page) || $page < 0) {
78 $offset = $limit * $page;
79 $pageprev = $page - 1;
80 $pagenext = $page + 1;
82 $sortfield =
"erd.date, erd.rowid";
85 if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
91 $hookmanager->initHooks(array(
'accountancyexpensereportlist'));
96 $chartaccountcode =
dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS,
'accounting_system',
'rowid',
'pcg_version');
102 if ($user->socid > 0) {
105 if (empty($user->rights->accounting->mouvements->lire)) {
114 if (
GETPOST(
'cancel',
'alpha')) {
115 $action =
'list'; $massaction =
'';
117 if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
121 $parameters = array();
122 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
127 if (empty($reshook)) {
129 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
131 $search_expensereport =
'';
135 $search_account =
'';
137 $search_date_startday =
'';
138 $search_date_startmonth =
'';
139 $search_date_startyear =
'';
140 $search_date_endday =
'';
141 $search_date_endmonth =
'';
142 $search_date_endyear =
'';
143 $search_date_start =
'';
144 $search_date_end =
'';
145 $search_country =
'';
146 $search_tvaintra =
'';
150 $objectclass =
'ExpenseReport';
151 $objectlabel =
'ExpenseReport';
152 $permissiontoread = $user->hasRight(
'accounting',
'read');
153 $permissiontodelete = $user->hasRight(
'accounting',
'delete');
154 $uploaddir = $conf->expensereport->dir_output;
155 include DOL_DOCUMENT_ROOT .
'/core/actions_massactions.inc.php';
159 if ($massaction ==
'ventil' && $user->rights->accounting->bind->write) {
163 if (!empty($mesCasesCochees)) {
164 $msg =
'<div>'.$langs->trans(
"SelectedLines").
': '.count($mesCasesCochees).
'</div>';
165 $msg .=
'<div class="detail">';
170 foreach ($mesCasesCochees as $maLigneCochee) {
171 $maLigneCourante = explode(
"_", $maLigneCochee);
172 $monId = $maLigneCourante[0];
173 $monCompte =
GETPOST(
'codeventil'.$monId);
175 if ($monCompte <= 0) {
176 $msg .=
'<div><span style="color:red">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NoAccountSelected").
'</span></div>';
179 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"expensereport_det";
180 $sql .=
" SET fk_code_ventilation = ".((int) $monCompte);
181 $sql .=
" WHERE rowid = ".((int) $monId);
184 $accountventilated->fetch($monCompte,
'', 1);
186 dol_syslog(
'accountancy/expensereport/list.php:: sql='.$sql, LOG_DEBUG);
187 if ($db->query($sql)) {
188 $msg .=
'<div><span style="color:green">'.$langs->trans(
"LineOfExpenseReport").
' '.$monId.
' - '.$langs->trans(
"VentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'</span></div>';
191 $msg .=
'<div><span style="color:red">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NotVentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'<br> <pre>'.$sql.
'</pre></span></div>';
199 $msg .=
'<div>'.$langs->trans(
"EndProcessing").
'</div>';
212 llxHeader(
'', $langs->trans(
"ExpenseReportsVentilation"));
214 if (empty($chartaccountcode)) {
215 print $langs->trans(
"ErrorChartOfAccountSystemNotSelected");
223 $sql =
"SELECT er.ref, er.rowid as erid, er.date_debut, er.date_valid,";
224 $sql .=
" erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht as price, erd.fk_code_ventilation, erd.tva_tx as tva_tx_line, erd.vat_src_code, erd.date,";
225 $sql .=
" f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label, f.accountancy_code as code_buy,";
226 $sql .=
" u.rowid as userid, u.login, u.lastname, u.firstname, u.email, u.gender, u.employee, u.photo, u.statut,";
227 $sql .=
" aa.rowid as aarowid";
228 $parameters = array();
229 $reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
230 $sql .= $hookmanager->resPrint;
231 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as er";
232 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport_det as erd ON er.rowid = erd.fk_expensereport";
233 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
234 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
235 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON f.accountancy_code = aa.account_number AND aa.fk_pcg_version = '".$db->escape($chartaccountcode).
"' AND aa.entity = ".$conf->entity;
236 $sql .=
" WHERE er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.
", ".
ExpenseReport::STATUS_CLOSED.
") AND erd.fk_code_ventilation <= 0";
238 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
239 $sql .=
" AND er.date_debut >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING).
"'";
242 if (strlen(trim($search_login))) {
245 if (strlen(trim($search_expensereport))) {
248 if (strlen(trim($search_label))) {
251 if (strlen(trim($search_desc))) {
254 if (strlen(trim($search_amount))) {
257 if (strlen(trim($search_account))) {
260 if (strlen(trim($search_vat))) {
263 if ($search_date_start) {
264 $sql .=
" AND erd.date >= '".$db->idate($search_date_start).
"'";
266 if ($search_date_end) {
267 $sql .=
" AND erd.date <= '".$db->idate($search_date_end).
"'";
269 $sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
272 $parameters = array();
273 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
274 $sql .= $hookmanager->resPrint;
276 $sql .= $db->order($sortfield, $sortorder);
280 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
281 $result = $db->query($sql);
289 $sql .= $db->plimit($limit + 1, $offset);
291 dol_syslog(
"accountancy/expensereport/list.php", LOG_DEBUG);
294 if ($db->type ==
'mysqli') {
295 $db->query(
"SET SQL_BIG_SELECTS=1");
298 $result = $db->query($sql);
300 $num_lines = $db->num_rows($result);
303 $arrayofselected = is_array($toselect) ? $toselect : array();
306 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
307 $param .=
'&contextpage='.urlencode($contextpage);
309 if ($limit > 0 && $limit != $conf->liste_limit) {
310 $param .=
'&limit='.urlencode($limit);
313 $param .=
'&search_login='.urlencode($search_login);
315 if ($search_lineid) {
316 $param .=
'&search_lineid='.urlencode($search_lineid);
318 if ($search_date_startday) {
319 $param .=
'&search_date_startday='.urlencode($search_date_startday);
321 if ($search_date_startmonth) {
322 $param .=
'&search_date_startmonth='.urlencode($search_date_startmonth);
324 if ($search_date_startyear) {
325 $param .=
'&search_date_startyear='.urlencode($search_date_startyear);
327 if ($search_date_endday) {
328 $param .=
'&search_date_endday='.urlencode($search_date_endday);
330 if ($search_date_endmonth) {
331 $param .=
'&search_date_endmonth='.urlencode($search_date_endmonth);
333 if ($search_date_endyear) {
334 $param .=
'&search_date_endyear='.urlencode($search_date_endyear);
336 if ($search_expensereport) {
337 $param .=
'&search_expensereport='.urlencode($search_expensereport);
340 $param .=
'&search_label='.urlencode($search_label);
343 $param .=
'&search_desc='.urlencode($search_desc);
345 if ($search_amount) {
346 $param .=
'&search_amount='.urlencode($search_amount);
349 $param .=
'&search_vat='.urlencode($search_vat);
352 $arrayofmassactions = array(
353 'ventil' =>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Ventilate")
355 $massactionbutton =
$form->selectMassAction(
'ventil', $arrayofmassactions, 1);
357 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
358 print
'<input type="hidden" name="action" value="ventil">';
359 if ($optioncss !=
'') {
360 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
362 print
'<input type="hidden" name="token" value="'.newToken().
'">';
363 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
364 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
365 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
366 print
'<input type="hidden" name="page" value="'.$page.
'">';
368 print_barre_liste($langs->trans(
"ExpenseReportLines"), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines,
$nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
370 print
'<span class="opacitymedium">'.$langs->trans(
"DescVentilTodoExpenseReport").
'</span></br><br>';
378 print
'<div class="div-table-responsive">';
379 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
382 print
'<tr class="liste_titre_filter">';
383 print
'<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.$search_login.
'"></td>';
384 print
'<td class="liste_titre"></td>';
385 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_expensereport" value="'.dol_escape_htmltag($search_expensereport).
'"></td>';
386 if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
387 print
'<td class="liste_titre"></td>';
389 print
'<td class="liste_titre center">';
390 print
'<div class="nowrap">';
391 print
$form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
393 print
'<div class="nowrap">';
394 print
$form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
397 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
398 print
'<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
399 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
400 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).
'"></td>';
401 print
'<td class="liste_titre"></td>';
402 print
'<td class="liste_titre"></td>';
403 print
'<td class="center liste_titre">';
404 $searchpicto =
$form->showFilterButtons();
409 print
'<tr class="liste_titre">';
412 print_liste_field_titre(
"ExpenseReport", $_SERVER[
"PHP_SELF"],
"er.ref",
"", $param,
'', $sortfield, $sortorder);
413 if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
414 print_liste_field_titre(
"DateValidation", $_SERVER[
"PHP_SELF"],
"er.date_valid",
"", $param,
'', $sortfield, $sortorder,
'center ');
416 print_liste_field_titre(
"DateOfLine", $_SERVER[
"PHP_SELF"],
"erd.date, erd.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
418 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"erd.comments",
"", $param,
'', $sortfield, $sortorder);
419 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"erd.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right maxwidth50 ');
420 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"erd.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
424 if ($massactionbutton) {
425 $checkpicto =
$form->showCheckAddButtons(
'checkforselect', 1);
432 $userstatic =
new User($db);
435 while ($i < min($num_lines, $limit)) {
436 $objp = $db->fetch_object($result);
438 $objp->aarowid_suggest =
'';
439 $objp->aarowid_suggest = $objp->aarowid;
441 $expensereport_static->ref = $objp->ref;
442 $expensereport_static->id = $objp->erid;
444 $userstatic->id = $objp->userid;
445 $userstatic->login = $objp->login;
446 $userstatic->statut = $objp->statut;
447 $userstatic->email = $objp->email;
448 $userstatic->gender = $objp->gender;
449 $userstatic->firstname = $objp->firstname;
450 $userstatic->lastname = $objp->lastname;
451 $userstatic->employee = $objp->employee;
452 $userstatic->photo = $objp->photo;
454 print
'<tr class="oddeven">';
457 print
'<td class="nowraponall">';
458 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 1,
'login',
'', 1);
462 print
'<td>'.$objp->rowid.
'</td>';
465 print
'<td>'.$expensereport_static->getNomUrl(1).
'</td>';
468 if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
469 print
'<td class="center">'.dol_print_date($db->jdate($objp->date_valid),
'day').
'</td>';
473 print
'<td class="center">'.dol_print_date($db->jdate($objp->date),
'day').
'</td>';
477 print ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code)));
483 $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
484 print
$form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->comments);
488 print
'<td class="right nowraponall amount">';
489 print
price($objp->price);
493 print
'<td class="right">';
494 print
vatrate($objp->tva_tx_line.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
''));
504 print $formaccounting->select_account($objp->aarowid_suggest,
'codeventil'.$objp->rowid, 1, array(), 0, 0,
'codeventil maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone');
507 print
'<td class="center">';
508 print
'<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.
'" name="toselect[]" value="'.$objp->rowid.
"_".$i.
'"'.($objp->aarowid ?
"checked" :
"").
'/>';
514 if ($num_lines == 0) {
515 print
'<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
525 if ($db->type ==
'mysqli') {
526 $db->query(
"SET SQL_BIG_SELECTS=0");
530 print
'<script type="text/javascript">
531 jQuery(document).ready(function() {
532 jQuery(".codeventil").change(function() {
533 var s=$(this).attr("id").replace("codeventil", "")
534 console.log(s+" "+$(this).val());
535 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
536 else jQuery(".checkforselect"+s).prop("checked", true);
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage accounting accounts.
Class to manage Trips and Expenses.
const STATUS_CLOSED
Classified paid.
Class to manage Dolibarr users.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$nbtotalofrecords
Count total nb of records.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.