dolibarr  13.0.2
lines.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
5  * Copyright (C) 2013-2016 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("compta", "bills", "other", "accountancy", "trips", "productbatch", "hrm"));
39 
40 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
41 
42 $account_parent = GETPOST('account_parent', 'int');
43 $changeaccount = GETPOST('changeaccount');
44 // Search Getpost
45 $search_login = GETPOST('search_login', 'alpha');
46 $search_expensereport = GETPOST('search_expensereport', 'alpha');
47 $search_label = GETPOST('search_label', 'alpha');
48 $search_desc = GETPOST('search_desc', 'alpha');
49 $search_amount = GETPOST('search_amount', 'alpha');
50 $search_account = GETPOST('search_account', 'alpha');
51 $search_vat = GETPOST('search_vat', 'alpha');
52 $search_day = GETPOST("search_day", "int");
53 $search_month = GETPOST("search_month", "int");
54 $search_year = GETPOST("search_year", "int");
55 
56 // Load variable for pagination
57 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
58 $sortfield = GETPOST('sortfield', 'aZ09comma');
59 $sortorder = GETPOST('sortorder', 'aZ09comma');
60 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61 if (empty($page) || $page < 0) $page = 0;
62 $pageprev = $page - 1;
63 $pagenext = $page + 1;
64 $offset = $limit * $page;
65 if (!$sortfield)
66  $sortfield = "erd.date, erd.rowid";
67 if (!$sortorder) {
68  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
69  $sortorder = "DESC";
70  }
71 }
72 
73 // Security check
74 if ($user->socid > 0)
76 if (!$user->rights->accounting->bind->write)
78 
79 $formaccounting = new FormAccounting($db);
80 
81 
82 /*
83  * Actions
84  */
85 
86 // Purge search criteria
87 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers
88 {
89  $search_login = '';
90  $search_expensereport = '';
91  $search_label = '';
92  $search_desc = '';
93  $search_amount = '';
94  $search_account = '';
95  $search_vat = '';
96  $search_day = '';
97  $search_month = '';
98  $search_year = '';
99 }
100 
101 if (is_array($changeaccount) && count($changeaccount) > 0) {
102  $error = 0;
103 
104  if (!(GETPOST('account_parent', 'int') >= 0))
105  {
106  $error++;
107  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
108  }
109 
110  if (!$error)
111  {
112  $db->begin();
113 
114  $sql1 = "UPDATE ".MAIN_DB_PREFIX."expensereport_det as erd";
115  $sql1 .= " SET erd.fk_code_ventilation=".(GETPOST('account_parent', 'int') > 0 ? GETPOST('account_parent', 'int') : '0');
116  $sql1 .= ' WHERE erd.rowid IN ('.implode(',', $changeaccount).')';
117 
118  dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= '.$sql1);
119  $resql1 = $db->query($sql1);
120  if (!$resql1) {
121  $error++;
122  setEventMessages($db->lasterror(), null, 'errors');
123  }
124  if (!$error) {
125  $db->commit();
126  setEventMessages($langs->trans("Save"), null, 'mesgs');
127  } else {
128  $db->rollback();
129  setEventMessages($db->lasterror(), null, 'errors');
130  }
131 
132  $account_parent = ''; // Protection to avoid to mass apply it a second time
133  }
134 }
135 
136 
137 /*
138  * View
139  */
140 
141 $form = new Form($db);
142 $formother = new FormOther($db);
143 
144 llxHeader('', $langs->trans("ExpenseReportsVentilation").' - '.$langs->trans("Dispatched"));
145 
146 print '<script type="text/javascript">
147  $(function () {
148  $(\'#select-all\').click(function(event) {
149  // Iterate each checkbox
150  $(\':checkbox\').each(function() {
151  this.checked = true;
152  });
153  });
154  $(\'#unselect-all\').click(function(event) {
155  // Iterate each checkbox
156  $(\':checkbox\').each(function() {
157  this.checked = false;
158  });
159  });
160  });
161  </script>';
162 
163 /*
164  * Expense reports lines
165  */
166 $sql = "SELECT er.ref, er.rowid as erid,";
167 $sql .= " erd.rowid, erd.fk_c_type_fees, erd.comments, erd.total_ht, erd.fk_code_ventilation, erd.tva_tx, erd.vat_src_code, erd.date,";
168 $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label,";
169 $sql .= " u.rowid as userid, u.login, u.lastname, u.firstname, u.email, u.gender, u.employee, u.photo, u.statut,";
170 $sql .= " aa.label, aa.labelshort, aa.account_number";
171 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as er";
172 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expensereport_det as erd ON er.rowid = erd.fk_expensereport";
173 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = erd.fk_code_ventilation";
174 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as f ON f.id = erd.fk_c_type_fees";
175 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = er.fk_user_author";
176 $sql .= " WHERE erd.fk_code_ventilation > 0";
177 $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
178 $sql .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.")";
179 // Add search filter like
180 if (strlen(trim($search_login))) {
181  $sql .= natural_search("u.login", $search_login);
182 }
183 if (strlen(trim($search_expensereport))) {
184  $sql .= natural_search("er.ref", $search_expensereport);
185 }
186 if (strlen(trim($search_label))) {
187  $sql .= natural_search("f.label", $search_label);
188 }
189 if (strlen(trim($search_desc))) {
190  $sql .= natural_search("er.comments", $search_desc);
191 }
192 if (strlen(trim($search_amount))) {
193  $sql .= natural_search("erd.total_ht", $search_amount, 1);
194 }
195 if (strlen(trim($search_account))) {
196  $sql .= natural_search("aa.account_number", $search_account);
197 }
198 if (strlen(trim($search_vat))) {
199  $sql .= natural_search("erd.tva_tx", price2num($search_vat), 1);
200 }
201 $sql .= dolSqlDateFilter('erd.date', $search_day, $search_month, $search_year);
202 $sql .= " AND er.entity IN (".getEntity('expensereport', 0).")"; // We don't share object for accountancy
203 
204 $sql .= $db->order($sortfield, $sortorder);
205 
206 // Count total nb of records
207 $nbtotalofrecords = '';
208 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
209 {
210  $result = $db->query($sql);
211  $nbtotalofrecords = $db->num_rows($result);
212  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
213  {
214  $page = 0;
215  $offset = 0;
216  }
217 }
218 
219 $sql .= $db->plimit($limit + 1, $offset);
220 
221 dol_syslog('accountancy/expensereport/lines.php::list');
222 $result = $db->query($sql);
223 
224 if ($result) {
225  $num_lines = $db->num_rows($result);
226  $i = 0;
227 
228  $param = '';
229  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
230  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
231  if ($search_login) $param .= '&search_login='.urlencode($search_login);
232  if ($search_expensereport) $param .= "&search_expensereport=".urlencode($search_expensereport);
233  if ($search_label) $param .= "&search_label=".urlencode($search_label);
234  if ($search_desc) $param .= "&search_desc=".urlencode($search_desc);
235  if ($search_account) $param .= "&search_account=".urlencode($search_account);
236  if ($search_vat) $param .= "&search_vat=".urlencode($search_vat);
237  if ($search_day) $param .= '&search_day='.urlencode($search_day);
238  if ($search_month) $param .= '&search_month='.urlencode($search_month);
239  if ($search_year) $param .= '&search_year='.urlencode($search_year);
240 
241  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
242  print '<input type="hidden" name="action" value="ventil">';
243  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
244  print '<input type="hidden" name="token" value="'.newToken().'">';
245  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
246  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
247  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
248  print '<input type="hidden" name="page" value="'.$page.'">';
249 
250  print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
251 
252  print '<span class="opacitymedium">'.$langs->trans("DescVentilDoneExpenseReport").'</span><br>';
253 
254  print '<br><div class="inline-block divButAction">'.$langs->trans("ChangeAccount").'<br>';
255  print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
256  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("ChangeBinding").'" /></div>';
257 
258  $moreforfilter = '';
259 
260  print '<div class="div-table-responsive">';
261  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
262 
263  print '<tr class="liste_titre_filter">';
264  print '<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.$search_login.'"></td>';
265  print '<td class="liste_titre"></td>';
266  print '<td><input type="text" class="flat maxwidth50" name="search_expensereport" value="'.dol_escape_htmltag($search_expensereport).'"></td>';
267  if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
268  print '<td class="liste_titre"></td>';
269  }
270  print '<td class="liste_titre center">';
271  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.$search_day.'">';
272  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month" value="'.$search_month.'">';
273  $formother->select_year($search_year, 'search_year', 1, 20, 5);
274  print '</td>';
275  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
276  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
277  print '<td class="liste_titre right"><input type="text" class="flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
278  print '<td class="liste_titre center"><input type="text" class="flat maxwidth50" name="search_vat" size="1" placeholder="%" value="'.dol_escape_htmltag($search_vat).'"></td>';
279  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="'.dol_escape_htmltag($search_account).'"></td>';
280  print '<td class="liste_titre center">';
281  $searchpicto = $form->showFilterButtons();
282  print $searchpicto;
283  print '</td>';
284  print "</tr>\n";
285 
286  print '<tr class="liste_titre">';
287  print_liste_field_titre("Employees", $_SERVER['PHP_SELF'], "u.login", $param, "", "", $sortfield, $sortorder);
288  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
289  print_liste_field_titre("ExpenseReport", $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
290  if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
291  print_liste_field_titre("DateValidation", $_SERVER["PHP_SELF"], "er.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
292  }
293  print_liste_field_titre("DateOfLine", $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
294  print_liste_field_titre("TypeFees", $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
295  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
296  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
297  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, '', $sortfield, $sortorder, 'center ');
298  print_liste_field_titre("AccountAccounting", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
299  $checkpicto = $form->showCheckAddButtons();
300  print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
301  print "</tr>\n";
302 
303  $expensereportstatic = new ExpenseReport($db);
304  $accountingaccountstatic = new AccountingAccount($db);
305  $userstatic = new User($db);
306 
307  $i = 0;
308  while ($i < min($num_lines, $limit)) {
309  $objp = $db->fetch_object($result);
310 
311  $expensereportstatic->ref = $objp->ref;
312  $expensereportstatic->id = $objp->erid;
313 
314  $userstatic->id = $objp->userid;
315  $userstatic->ref = $objp->label;
316  $userstatic->login = $objp->login;
317  $userstatic->statut = $objp->statut;
318  $userstatic->email = $objp->email;
319  $userstatic->gender = $objp->gender;
320  $userstatic->firstname = $objp->firstname;
321  $userstatic->lastname = $objp->lastname;
322  $userstatic->employee = $objp->employee;
323  $userstatic->photo = $objp->photo;
324 
325  $accountingaccountstatic->rowid = $objp->fk_compte;
326  $accountingaccountstatic->label = $objp->label;
327  $accountingaccountstatic->labelshort = $objp->labelshort;
328  $accountingaccountstatic->account_number = $objp->account_number;
329 
330  print '<tr class="oddeven">';
331 
332  // Login
333  print '<td class="nowraponall">';
334  print $userstatic->getNomUrl(-1, '', 0, 0, 24, 1, 'login', '', 1);
335  print '</td>';
336 
337  // Line id
338  print '<td>'.$objp->rowid.'</td>';
339 
340  // Ref Expense report
341  print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
342 
343  // Date validation
344  if (!empty($conf->global->ACCOUNTANCY_USE_EXPENSE_REPORT_VALIDATION_DATE)) {
345  print '<td class="center">'.dol_print_date($db->jdate($objp->date_valid), 'day').'</td>';
346  }
347 
348  print '<td class="center">'.dol_print_date($db->jdate($objp->date), 'day').'</td>';
349 
350  // Fees label
351  print '<td class="tdoverflow">'.($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))).'</td>';
352 
353  // Fees description -- Can be null
354  print '<td>';
355  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
356  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
357  print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->comments);
358  print '</td>';
359 
360  // Amount without taxes
361  print '<td class="nowrap right">'.price($objp->total_ht).'</td>';
362 
363  // Vat rate
364  print '<td class="center">'.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).'</td>';
365 
366  // Accounting account affected
367  print '<td class="center">';
368  print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1);
369  print ' <a class="editfielda reposition marginleftonly marginrightonly" href="./card.php?id='.$objp->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($param ? '?'.$param : '')).'">';
370  print img_edit();
371  print '</a></td>';
372  print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="'.$objp->rowid.'"/></td>';
373 
374  print "</tr>";
375  $i++;
376  }
377 
378  print "</table>";
379  print "</div>";
380 
381  if ($nbtotalofrecords > $limit) {
382  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
383  }
384 
385  print '</form>';
386 } else {
387  print $db->lasterror();
388 }
389 
390 // End of page
391 llxFooter();
392 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
Class to manage Dolibarr users.
Definition: user.class.php:44
const STATUS_CLOSED
Classified paid.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
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 ...
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
Class to manage Trips and Expenses.
print $_SERVER["PHP_SELF"]
Edit parameters.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
print
Draft customers invoices.
Definition: index.php:89
Class to manage generation of HTML components for accounting management.
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
Class to manage accounting accounts.
llxFooter()
Empty footer.
Definition: wrapper.php:59