30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
40$langs->loadLangs(array(
"bills",
"companies",
"compta",
"accountancy",
"other",
"trips",
"productbatch",
"hrm"));
42$action =
GETPOST(
'action',
'aZ09');
43$massaction =
GETPOST(
'massaction',
'alpha');
44$confirm =
GETPOST(
'confirm',
'alpha');
45$toselect =
GETPOST(
'toselect',
'array');
46$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountancyexpensereportlist';
47$optioncss =
GETPOST(
'optioncss',
'aZ');
51$mesCasesCochees =
GETPOST(
'toselect',
'array');
54$search_login =
GETPOST(
'search_login',
'alpha');
55$search_lineid =
GETPOST(
'search_lineid',
'alpha');
56$search_expensereport =
GETPOST(
'search_expensereport',
'alpha');
57$search_label =
GETPOST(
'search_label',
'alpha');
58$search_desc =
GETPOST(
'search_desc',
'alpha');
59$search_amount =
GETPOST(
'search_amount',
'alpha');
60$search_account =
GETPOST(
'search_account',
'alpha');
61$search_vat =
GETPOST(
'search_vat',
'alpha');
62$search_date_startday =
GETPOSTINT(
'search_date_startday');
63$search_date_startmonth =
GETPOSTINT(
'search_date_startmonth');
64$search_date_startyear =
GETPOSTINT(
'search_date_startyear');
65$search_date_endday =
GETPOSTINT(
'search_date_endday');
66$search_date_endmonth =
GETPOSTINT(
'search_date_endmonth');
67$search_date_endyear =
GETPOSTINT(
'search_date_endyear');
68$search_date_start =
dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);
69$search_date_end =
dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
78$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
79$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
81if (empty($page) || $page < 0) {
84$offset = $limit * $page;
88 $sortfield =
"erd.date, erd.rowid";
99$hookmanager->initHooks(array(
'accountancyexpensereportlist'));
107if (!isModEnabled(
'accounting')) {
110if ($user->socid > 0) {
113if (!$user->hasRight(
'accounting',
'bind',
'write')) {
122if (
GETPOST(
'cancel',
'alpha')) {
126if (!
GETPOST(
'confirmmassaction',
'alpha') && $massaction !=
'presend' && $massaction !=
'confirm_presend') {
130$parameters = array();
131$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
136if (empty($reshook)) {
138 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
141 $search_expensereport =
'';
145 $search_account =
'';
147 $search_date_startday =
'';
148 $search_date_startmonth =
'';
149 $search_date_startyear =
'';
150 $search_date_endday =
'';
151 $search_date_endmonth =
'';
152 $search_date_endyear =
'';
153 $search_date_start =
'';
154 $search_date_end =
'';
155 $search_country =
'';
156 $search_tvaintra =
'';
160 $objectclass =
'ExpenseReport';
161 $objectlabel =
'ExpenseReport';
162 $permissiontoread = $user->hasRight(
'accounting',
'read');
163 $permissiontodelete = $user->hasRight(
'accounting',
'delete');
164 $uploaddir = $conf->expensereport->dir_output;
165 include DOL_DOCUMENT_ROOT .
'/core/actions_massactions.inc.php';
169if ($massaction ==
'ventil' && $user->hasRight(
'accounting',
'bind',
'write')) {
172 if (!empty($mesCasesCochees)) {
173 $msg =
'<div>'.$langs->trans(
"SelectedLines").
': '.count($mesCasesCochees).
'</div>';
174 $msg .=
'<div class="detail">';
179 foreach ($mesCasesCochees as $maLigneCochee) {
180 $maLigneCourante = explode(
"_", $maLigneCochee);
181 $monId = $maLigneCourante[0];
182 $monCompte =
GETPOST(
'codeventil'.$monId);
184 if ($monCompte <= 0) {
185 $msg .=
'<div><span class="error">'.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NoAccountSelected").
'</span></div>';
188 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"expensereport_det";
189 $sql .=
" SET fk_code_ventilation = ".((int) $monCompte);
190 $sql .=
" WHERE rowid = ".((int) $monId);
193 $accountventilated->fetch($monCompte,
'', 1);
195 dol_syslog(
'accountancy/expensereport/list.php:: sql='.$sql, LOG_DEBUG);
196 if ($db->query($sql)) {
197 $msg .=
'<div><span class="green">'.$langs->trans(
"LineOfExpenseReport").
' '.$monId.
' - '.$langs->trans(
"VentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'</span></div>';
200 $msg .=
'<div><span class="error">'.$langs->trans(
"ErrorDB").
' : '.$langs->trans(
"Lineofinvoice").
' '.$monId.
' - '.$langs->trans(
"NotVentilatedinAccount").
' : '.
length_accountg($accountventilated->account_number).
'<br> <pre>'.$sql.
'</pre></span></div>';
208 $msg .=
'<div>'.$langs->trans(
"EndProcessing").
'</div>';
212if (
GETPOST(
'sortfield') ==
'erd.date, erd.rowid') {
213 $value = (
GETPOST(
'sortorder') ==
'asc,asc' ? 0 : 1);
214 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
215 $res =
dolibarr_set_const($db,
"ACCOUNTING_LIST_SORT_VENTILATION_TODO", $value,
'yesno', 0,
'', $conf->entity);
223$form =
new Form($db);
226$help_url =
'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilité_en_Partie_Double#Liaisons_comptables';
228llxHeader(
'', $langs->trans(
"ExpenseReportsVentilation"), $help_url,
'', 0, 0,
'',
'',
'',
'bodyforlist mod-accountancy accountancy-expensereport page-list');
230if (empty($chartaccountcode)) {
231 print $langs->trans(
"ErrorChartOfAccountSystemNotSelected");
239$sql =
"SELECT er.ref, er.rowid as erid, er.date_debut, er.date_valid,";
240$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,";
241$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,";
242$sql .=
" u.rowid as userid, u.login, u.lastname, u.firstname, u.email, u.gender, u.employee, u.photo, u.statut,";
243$sql .=
" aa.rowid as aarowid";
244$parameters = array();
245$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters);
246$sql .= $hookmanager->resPrint;
247$sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as er";
248$sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport_det as erd ON er.rowid = erd.fk_expensereport";
249$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees as f ON f.id = erd.fk_c_type_fees";
250$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON u.rowid = er.fk_user_author";
251$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;
252$sql .=
" WHERE er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.
", ".
ExpenseReport::STATUS_CLOSED.
") AND erd.fk_code_ventilation <= 0";
254if (strlen($search_lineid)) {
257if (strlen(trim($search_login))) {
260if (strlen(trim($search_expensereport))) {
263if (strlen(trim($search_label))) {
266if (strlen(trim($search_desc))) {
269if (strlen(trim($search_amount))) {
272if (strlen(trim($search_account))) {
275if (strlen(trim($search_vat))) {
278if ($search_date_start) {
279 $sql .=
" AND erd.date >= '".$db->idate($search_date_start).
"'";
281if ($search_date_end) {
282 $sql .=
" AND erd.date <= '".$db->idate($search_date_end).
"'";
284$sql .=
" AND er.entity IN (".getEntity(
'expensereport', 0).
")";
287$parameters = array();
288$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
289$sql .= $hookmanager->resPrint;
291$sql .= $db->order($sortfield, $sortorder);
294$nbtotalofrecords =
'';
296 $result = $db->query($sql);
297 $nbtotalofrecords = $db->num_rows($result);
298 if (($page * $limit) > $nbtotalofrecords) {
305$sql .= $db->plimit($limit + 1, $offset);
307dol_syslog(
"accountancy/expensereport/list.php", LOG_DEBUG);
310if ($db->type ==
'mysqli') {
311 $db->query(
"SET SQL_BIG_SELECTS=1");
314$result = $db->query($sql);
316 $num_lines = $db->num_rows($result);
319 $arrayofselected = is_array($toselect) ? $toselect : array();
322 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
323 $param .=
'&contextpage='.urlencode($contextpage);
325 if ($limit > 0 && $limit != $conf->liste_limit) {
326 $param .=
'&limit='.((int) $limit);
328 if ($search_lineid) {
329 $param .=
'&search_lineid='.urlencode($search_lineid);
332 $param .=
'&search_login='.urlencode($search_login);
334 if ($search_date_startday) {
335 $param .=
'&search_date_startday='.urlencode((
string) ($search_date_startday));
337 if ($search_date_startmonth) {
338 $param .=
'&search_date_startmonth='.urlencode((
string) ($search_date_startmonth));
340 if ($search_date_startyear) {
341 $param .=
'&search_date_startyear='.urlencode((
string) ($search_date_startyear));
343 if ($search_date_endday) {
344 $param .=
'&search_date_endday='.urlencode((
string) ($search_date_endday));
346 if ($search_date_endmonth) {
347 $param .=
'&search_date_endmonth='.urlencode((
string) ($search_date_endmonth));
349 if ($search_date_endyear) {
350 $param .=
'&search_date_endyear='.urlencode((
string) ($search_date_endyear));
352 if ($search_expensereport) {
353 $param .=
'&search_expensereport='.urlencode($search_expensereport);
356 $param .=
'&search_label='.urlencode($search_label);
359 $param .=
'&search_desc='.urlencode($search_desc);
361 if ($search_amount) {
362 $param .=
'&search_amount='.urlencode($search_amount);
365 $param .=
'&search_vat='.urlencode($search_vat);
368 $arrayofmassactions = array(
369 'ventil' =>
img_picto(
'',
'check',
'class="pictofixedwidth"').$langs->trans(
"Ventilate")
371 $massactionbutton =
'';
372 if ($massaction !==
'set_default_account') {
373 $massactionbutton = $form->selectMassAction(
'ventil', $arrayofmassactions, 1);
376 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post">'.
"\n";
377 print
'<input type="hidden" name="action" value="ventil">';
378 if ($optioncss !=
'') {
379 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
381 print
'<input type="hidden" name="token" value="'.newToken().
'">';
382 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
383 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
384 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
385 print
'<input type="hidden" name="page" value="'.$page.
'">';
388 print_barre_liste($langs->trans(
"ExpenseReportLines").
'<br><span class="opacitymedium small">'.$langs->trans(
"DescVentilTodoExpenseReport").
'</span>', $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit, 0, 0, 1);
396 print
'<div class="div-table-responsive">';
397 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
400 print
'<tr class="liste_titre_filter">';
401 print
'<td class="liste_titre"><input type="text" class="flat maxwidth40" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).
'"></td>';
402 print
'<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.dol_escape_htmltag($search_login).
'"></td>';
403 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_expensereport" value="'.dol_escape_htmltag($search_expensereport).
'"></td>';
405 print
'<td class="liste_titre"></td>';
407 print
'<td class="liste_titre center">';
408 print
'<div class="nowrapfordate">';
409 print $form->selectDate($search_date_start ? $search_date_start : -1,
'search_date_start', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'From'));
411 print
'<div class="nowrapfordate">';
412 print $form->selectDate($search_date_end ? $search_date_end : -1,
'search_date_end', 0, 0, 1,
'', 1, 0, 0,
'',
'',
'',
'', 1,
'', $langs->trans(
'to'));
415 print
'<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).
'"></td>';
416 print
'<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="'.dol_escape_htmltag($search_desc).
'"></td>';
417 print
'<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).
'"></td>';
418 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>';
419 print
'<td class="liste_titre"></td>';
420 print
'<td class="liste_titre"></td>';
421 print
'<td class="center liste_titre">';
422 $searchpicto = $form->showFilterButtons();
427 print
'<tr class="liste_titre">';
430 print_liste_field_titre(
"ExpenseReport", $_SERVER[
"PHP_SELF"],
"er.ref",
"", $param,
'', $sortfield, $sortorder);
432 print_liste_field_titre(
"DateValidation", $_SERVER[
"PHP_SELF"],
"er.date_valid",
"", $param,
'', $sortfield, $sortorder,
'center ');
434 print_liste_field_titre(
"DateOfLine", $_SERVER[
"PHP_SELF"],
"erd.date, erd.rowid",
"", $param,
'', $sortfield, $sortorder,
'center ');
436 print_liste_field_titre(
"Description", $_SERVER[
"PHP_SELF"],
"erd.comments",
"", $param,
'', $sortfield, $sortorder);
437 print_liste_field_titre(
"Amount", $_SERVER[
"PHP_SELF"],
"erd.total_ht",
"", $param,
'', $sortfield, $sortorder,
'right maxwidth50 ');
438 print_liste_field_titre(
"VATRate", $_SERVER[
"PHP_SELF"],
"erd.tva_tx",
"", $param,
'', $sortfield, $sortorder,
'right ');
442 if ($massactionbutton) {
443 $checkpicto = $form->showCheckAddButtons(
'checkforselect', 1);
450 $userstatic =
new User($db);
451 $form =
new Form($db);
453 while ($i < min($num_lines, $limit)) {
454 $objp = $db->fetch_object($result);
456 $objp->aarowid_suggest =
'';
457 $objp->aarowid_suggest = $objp->aarowid;
459 $expensereport_static->ref = $objp->ref;
460 $expensereport_static->id = $objp->erid;
462 $userstatic->id = $objp->userid;
463 $userstatic->login = $objp->login;
464 $userstatic->status = $objp->statut;
465 $userstatic->email = $objp->email;
466 $userstatic->gender = $objp->gender;
467 $userstatic->firstname = $objp->firstname;
468 $userstatic->lastname = $objp->lastname;
469 $userstatic->employee = $objp->employee;
470 $userstatic->photo = $objp->photo;
472 print
'<tr class="oddeven">';
475 print
'<td>'.$objp->rowid.
'</td>';
478 print
'<td class="nowraponall">';
479 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 1,
'login',
'', 1);
483 print
'<td class="tdoverflowmax150">'.$expensereport_static->getNomUrl(1).
'</td>';
487 print
'<td class="center">'.dol_print_date($db->jdate($objp->date_valid),
'day').
'</td>';
491 print
'<td class="center">'.dol_print_date($db->jdate($objp->date),
'day').
'</td>';
495 print($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code)));
502 print $form->textwithtooltip(
dol_trunc($text, $trunclength), $objp->comments);
506 print
'<td class="right nowraponall amount">';
507 print
price($objp->price);
511 print
'<td class="right">';
512 print
vatrate($objp->tva_tx_line.($objp->vat_src_code ?
' ('.$objp->vat_src_code.
')' :
''));
522 print $formaccounting->select_account($objp->aarowid_suggest,
'codeventil'.$objp->rowid, 1, array(), 0, 0,
'codeventil maxwidth200 maxwidthonsmartphone',
'cachewithshowemptyone');
525 print
'<td class="center">';
526 print
'<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.
'" name="toselect[]" value="'.$objp->rowid.
"_".$i.
'"'.($objp->aarowid ?
"checked" :
"").
'/>';
532 if ($num_lines == 0) {
533 print
'<tr><td colspan="13"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
543if ($db->type ==
'mysqli') {
544 $db->query(
"SET SQL_BIG_SELECTS=0");
548print
'<script type="text/javascript">
549jQuery(document).ready(function() {
550 jQuery(".codeventil").change(function() {
551 var s=$(this).attr("id").replace("codeventil", "")
552 console.log(s+" "+$(this).val());
553 if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
554 else jQuery(".checkforselect"+s).prop("checked", true);
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
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.
Class to manage accounting accounts.
Class to manage Trips and Expenses.
const STATUS_CLOSED
Classified paid.
Class to manage Dolibarr users.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
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)
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.
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...
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.
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.
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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.