dolibarr  9.0.0
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@zendsi.com>
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 <http://www.gnu.org/licenses/>.
20  */
21 
27 require '../../main.inc.php';
28 
29 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
30 require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("compta","bills","other","accountancy","trips","productbatch"));
38 
39 $account_parent = GETPOST('account_parent','int');
40 $changeaccount = GETPOST('changeaccount');
41 // Search Getpost
42 $search_expensereport = GETPOST('search_expensereport', 'alpha');
43 $search_label = GETPOST('search_label', 'alpha');
44 $search_desc = GETPOST('search_desc', 'alpha');
45 $search_amount = GETPOST('search_amount', 'alpha');
46 $search_account = GETPOST('search_account', 'alpha');
47 $search_vat = GETPOST('search_vat', 'alpha');
48 $search_day=GETPOST("search_day","int");
49 $search_month=GETPOST("search_month","int");
50 $search_year=GETPOST("search_year","int");
51 
52 // Load variable for pagination
53 $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
54 $sortfield = GETPOST('sortfield', 'alpha');
55 $sortorder = GETPOST('sortorder', 'alpha');
56 $page = GETPOST('page', 'int');
57 if (empty($page) || $page < 0) $page = 0;
58 $pageprev = $page - 1;
59 $pagenext = $page + 1;
60 $offset = $limit * $page;
61 if (! $sortfield)
62  $sortfield = "erd.date, erd.rowid";
63 if (! $sortorder) {
64  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
65  $sortorder = "DESC";
66  }
67 }
68 
69 // Security check
70 if ($user->societe_id > 0)
72 if (! $user->rights->accounting->bind->write)
74 
75 $formaccounting = new FormAccounting($db);
76 
77 
78 /*
79  * Actions
80  */
81 
82 // Purge search criteria
83 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
84 {
85  $search_expensereport = '';
86  $search_label = '';
87  $search_desc = '';
88  $search_amount = '';
89  $search_account = '';
90  $search_vat = '';
91  $search_day = '';
92  $search_month = '';
93  $search_year = '';
94 }
95 
96 if (is_array($changeaccount) && count($changeaccount) > 0) {
97  $error = 0;
98 
99  if (! (GETPOST('account_parent','int') >= 0))
100  {
101  $error++;
102  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Account")), null, 'errors');
103  }
104 
105  if (! $error)
106  {
107  $db->begin();
108 
109  $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
110  $sql1 .= " SET erd.fk_code_ventilation=" . (GETPOST('account_parent','int') > 0 ? GETPOST('account_parent','int') : '0');
111  $sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
112 
113  dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
114  $resql1 = $db->query($sql1);
115  if (! $resql1) {
116  $error ++;
117  setEventMessages($db->lasterror(), null, 'errors');
118  }
119  if (! $error) {
120  $db->commit();
121  setEventMessages($langs->trans('Save'), null, 'mesgs');
122  } else {
123  $db->rollback();
124  setEventMessages($db->lasterror(), null, 'errors');
125  }
126 
127  $account_parent = ''; // Protection to avoid to mass apply it a second time
128  }
129 }
130 
131 
132 /*
133  * View
134  */
135 
136 $form = new Form($db);
137 $formother = new FormOther($db);
138 
139 llxHeader('', $langs->trans("ExpenseReportsVentilation") . ' - ' . $langs->trans("Dispatched"));
140 
141 print '<script type="text/javascript">
142  $(function () {
143  $(\'#select-all\').click(function(event) {
144  // Iterate each checkbox
145  $(\':checkbox\').each(function() {
146  this.checked = true;
147  });
148  });
149  $(\'#unselect-all\').click(function(event) {
150  // Iterate each checkbox
151  $(\':checkbox\').each(function() {
152  this.checked = false;
153  });
154  });
155  });
156  </script>';
157 
158 /*
159  * Expense reports lines
160  */
161 $sql = "SELECT er.ref, er.rowid as erid,";
162 $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,";
163 $sql .= " aa.label, aa.account_number,";
164 $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label";
165 $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
166 $sql .= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
167 $sql .= " , " . MAIN_DB_PREFIX . "expensereport_det as erd";
168 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
169 $sql .= " WHERE er.rowid = erd.fk_expensereport and er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <> 0 ";
170 $sql .= " AND aa.rowid = erd.fk_code_ventilation";
171 if (strlen(trim($search_expensereport))) {
172  $sql .= natural_search("er.ref", $search_expensereport);
173 }
174 if (strlen(trim($search_label))) {
175  $sql .= natural_search("f.label", $search_label);
176 }
177 if (strlen(trim($search_desc))) {
178  $sql .= natural_search("er.comments", $search_desc);
179 }
180 if (strlen(trim($search_amount))) {
181  $sql .= natural_search("erd.total_ht", $search_amount, 1);
182 }
183 if (strlen(trim($search_account))) {
184  $sql .= natural_search("aa.account_number", $search_account);
185 }
186 if (strlen(trim($search_vat))) {
187  $sql .= natural_search("erd.tva_tx", price2num($search_vat), 1);
188 }
189 if ($search_month > 0)
190 {
191  if ($search_year > 0 && empty($search_day))
192  $sql.= " AND erd.date BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
193  else if ($search_year > 0 && ! empty($search_day))
194  $sql.= " AND erd.date BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
195  else
196  $sql.= " AND date_format(erd.date, '%m') = '".$db->escape($search_month)."'";
197 }
198 else if ($search_year > 0)
199 {
200  $sql.= " AND erd.date BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
201 }
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_expensereport) $param .= "&search_expensereport=" . urlencode($search_expensereport);
232  if ($search_label) $param .= "&search_label=" . urlencode($search_label);
233  if ($search_desc) $param .= "&search_desc=" . urlencode($search_desc);
234  if ($search_account) $param .= "&search_account=" . urlencode($search_account);
235  if ($search_vat) $param .= "&search_vat=" . urlencode($search_vat);
236  if ($search_day) $param .= '&search_day='.urlencode($search_day);
237  if ($search_month) $param .= '&search_month='.urlencode($search_month);
238  if ($search_year) $param .= '&search_year='.urlencode($search_year);
239 
240  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
241  print '<input type="hidden" name="action" value="ventil">';
242  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
243  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
244  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
245  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
246  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
247  print '<input type="hidden" name="page" value="'.$page.'">';
248 
249  print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
250 
251  print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
252 
253  print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
254  print $formaccounting->select_account($account_parent, 'account_parent', 2, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone valignmiddle');
255  print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
256 
257  $moreforfilter = '';
258 
259  print '<div class="div-table-responsive">';
260  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
261 
262  print '<tr class="liste_titre_filter">';
263  print '<td class="liste_titre"></td>';
264  print '<td><input type="text" class="flat maxwidth50" name="search_expensereport" value="' . dol_escape_htmltag($search_expensereport) . '"></td>';
265  print '<td class="liste_titre center">';
266  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
267  print '<input class="flat" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
268  $formother->select_year($search_year,'search_year',1, 20, 5);
269  print '</td>';
270  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
271  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
272  print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
273  print '<td class="liste_titre" align="center"><input type="text" class="flat maxwidth50" name="search_vat" size="1" placeholder="%" value="' . dol_escape_htmltag($search_vat) . '"></td>';
274  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
275  print '<td class="liste_titre" align="right"></td>';
276  print '<td class="liste_titre" align="right">';
277  $searchpicto=$form->showFilterButtons();
278  print $searchpicto;
279  print '</td>';
280  print "</tr>\n";
281 
282  print '<tr class="liste_titre">';
283  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
284  print_liste_field_titre("ExpenseReport", $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
285  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
286  print_liste_field_titre("TypeFees", $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
287  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
288  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
289  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
290  print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
292  $checkpicto=$form->showCheckAddButtons();
293  print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
294  print "</tr>\n";
295 
296  $expensereport_static = new ExpenseReport($db);
297 
298  while ( $i < min($num_lines, $limit) ) {
299  $objp = $db->fetch_object($result);
300  $codeCompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
301 
302  $expensereport_static->ref = $objp->ref;
303  $expensereport_static->id = $objp->erid;
304 
305  print '<tr class="oddeven">';
306 
307  print '<td>' . $objp->rowid . '</td>';
308 
309  // Ref Invoice
310  print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
311 
312  print '<td align="center">' . dol_print_date($db->jdate($objp->date), 'day') . '</td>';
313 
314  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>';
315 
316  print '<td>';
317  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
318  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
319  print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
320  print '</td>';
321 
322  print '<td align="right">' . price($objp->total_ht) . '</td>';
323 
324  print '<td align="center">' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . '</td>';
325 
326  print '<td>' . $codeCompta . '</td>';
327 
328  print '<td align="left"><a href="./card.php?id=' . $objp->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].($param?'?'.$param:'')). '">';
329  print img_edit();
330  print '</a></td>';
331 
332  print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
333 
334  print "</tr>";
335  $i ++;
336  }
337 
338  print "</table>";
339  print "</div>";
340 
341  if ($nbtotalofrecords > $limit) {
342  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
343  }
344 
345  print '</form>';
346 } else {
347  print $db->lasterror();
348 }
349 
350 // End of page
351 llxFooter();
352 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
const STATUS_CLOSED
Classified paid.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
dolGetFirstLineOfText($text, $nboflines=1)
Return first line of text.
Class to manage Trips and Expenses.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
Class to manage generation of HTML components for accounting management.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...