dolibarr  7.0.0-beta
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 // Class
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 . '/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
36 
37 // Langs
38 $langs->load("compta");
39 $langs->load("bills");
40 $langs->load("other");
41 $langs->load("main");
42 $langs->load("accountancy");
43 $langs->load("trips");
44 $langs->load("productbatch");
45 
46 $account_parent = GETPOST('account_parent');
47 $changeaccount = GETPOST('changeaccount');
48 // Search Getpost
49 $search_expensereport = GETPOST('search_expensereport', 'alpha');
50 $search_label = GETPOST('search_label', 'alpha');
51 $search_desc = GETPOST('search_desc', 'alpha');
52 $search_amount = GETPOST('search_amount', 'alpha');
53 $search_account = GETPOST('search_account', 'alpha');
54 $search_vat = GETPOST('search_vat', 'alpha');
55 $search_day=GETPOST("search_day","int");
56 $search_month=GETPOST("search_month","int");
57 $search_year=GETPOST("search_year","int");
58 
59 // Load variable for pagination
60 $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
61 $sortfield = GETPOST('sortfield', 'alpha');
62 $sortorder = GETPOST('sortorder', 'alpha');
63 $page = GETPOST('page', 'int');
64 if ($page < 0) $page = 0;
65 $offset = $conf->liste_limit * $page;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 if (! $sortfield)
69  $sortfield = "erd.date, erd.rowid";
70 if (! $sortorder) {
71  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
72  $sortorder = "DESC";
73  }
74 }
75 
76 // Security check
77 if ($user->societe_id > 0)
79 if (! $user->rights->accounting->bind->write)
81 
82 $formaccounting = new FormAccounting($db);
83 
84 
85 /*
86  * Actions
87  */
88 
89 // Purge search criteria
90 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
91 {
92  $search_expensereport = '';
93  $search_label = '';
94  $search_desc = '';
95  $search_amount = '';
96  $search_account = '';
97  $search_vat = '';
98  $search_day = '';
99  $search_month = '';
100  $search_year = '';
101 }
102 
103 if (is_array($changeaccount) && count($changeaccount) > 0) {
104  $error = 0;
105 
106  $db->begin();
107 
108  $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd";
109  $sql1 .= " SET erd.fk_code_ventilation=" . GETPOST('account_parent','int');
110  $sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')';
111 
112  dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1);
113  $resql1 = $db->query($sql1);
114  if (! $resql1) {
115  $error ++;
116  setEventMessages($db->lasterror(), null, 'errors');
117  }
118  if (! $error) {
119  $db->commit();
120  setEventMessages($langs->trans('Save'), null, 'mesgs');
121  } else {
122  $db->rollback();
123  setEventMessages($db->lasterror(), null, 'errors');
124  }
125 
126  $account_parent = ''; // Protection to avoid to mass apply it a second time
127 }
128 
129 
130 /*
131  * View
132  */
133 
134 $form = new Form($db);
135 $formother = new FormOther($db);
136 
137 llxHeader('', $langs->trans("ExpenseReportsVentilation") . ' - ' . $langs->trans("Dispatched"));
138 
139 print '<script type="text/javascript">
140  $(function () {
141  $(\'#select-all\').click(function(event) {
142  // Iterate each checkbox
143  $(\':checkbox\').each(function() {
144  this.checked = true;
145  });
146  });
147  $(\'#unselect-all\').click(function(event) {
148  // Iterate each checkbox
149  $(\':checkbox\').each(function() {
150  this.checked = false;
151  });
152  });
153  });
154  </script>';
155 
156 /*
157  * Expense reports lines
158  */
159 $sql = "SELECT er.ref, er.rowid as erid,";
160 $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,";
161 $sql .= " aa.label, aa.account_number,";
162 $sql .= " f.id as type_fees_id, f.code as type_fees_code, f.label as type_fees_label";
163 $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport as er";
164 $sql .= " , " . MAIN_DB_PREFIX . "accounting_account as aa";
165 $sql .= " , " . MAIN_DB_PREFIX . "expensereport_det as erd";
166 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees";
167 $sql .= " WHERE er.rowid = erd.fk_expensereport and er.fk_statut >= 5 AND erd.fk_code_ventilation <> 0 ";
168 $sql .= " AND aa.rowid = erd.fk_code_ventilation";
169 if (strlen(trim($search_expensereport))) {
170  $sql .= " AND er.ref like '%" . $search_expensereport . "%'";
171 }
172 if (strlen(trim($search_label))) {
173  $sql .= " AND f.label like '%" . $search_label . "%'";
174 }
175 if (strlen(trim($search_desc))) {
176  $sql .= " AND er.comments like '%" . $search_desc . "%'";
177 }
178 if (strlen(trim($search_amount))) {
179  $sql .= " AND erd.total_ht like '%" . $search_amount . "%'";
180 }
181 if (strlen(trim($search_account))) {
182  $sql .= " AND aa.account_number like '%" . $search_account . "%'";
183 }
184 if (strlen(trim($search_vat))) {
185  $sql .= " AND (erd.tva_tx like '" . $search_vat . "%')";
186 }
187 if ($search_month > 0)
188 {
189  if ($search_year > 0 && empty($search_day))
190  $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))."'";
191  else if ($search_year > 0 && ! empty($search_day))
192  $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))."'";
193  else
194  $sql.= " AND date_format(erd.date, '%m') = '".$db->escape($search_month)."'";
195 }
196 else if ($search_year > 0)
197 {
198  $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))."'";
199 }
200 $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy
201 
202 $sql .= $db->order($sortfield, $sortorder);
203 
204 // Count total nb of records
205 $nbtotalofrecords = '';
206 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
207 {
208  $result = $db->query($sql);
209  $nbtotalofrecords = $db->num_rows($result);
210 }
211 
212 $sql .= $db->plimit($limit + 1, $offset);
213 
214 dol_syslog('accountancy/expensereport/lines.php::list');
215 $result = $db->query($sql);
216 
217 if ($result) {
218  $num_lines = $db->num_rows($result);
219  $i = 0;
220 
221  $param='';
222  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
223  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
224  if ($search_expensereport)
225  $param .= "&search_expensereport=" . $search_expensereport;
226  if ($search_label)
227  $param .= "&search_label=" . $search_label;
228  if ($search_desc)
229  $param .= "&search_desc=" . $search_desc;
230  if ($search_account)
231  $param .= "&search_account=" . $search_account;
232  if ($search_vat)
233  $param .= "&search_vat=" . $search_vat;
234  if ($search_day) $param.='&search_day='.urlencode($search_day);
235  if ($search_month) $param.='&search_month='.urlencode($search_month);
236  if ($search_year) $param.='&search_year='.urlencode($search_year);
237  if ($search_country)
238  $param .= "&search_country=" . $search_country;
239  if ($search_tvaintra)
240  $param .= "&search_tvaintra=" . $search_tvaintra;
241 
242  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
243  print '<input type="hidden" name="action" value="ventil">';
244  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
245  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
246  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
247  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
248  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
249  print '<input type="hidden" name="page" value="'.$page.'">';
250 
251  print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
252 
253  print $langs->trans("DescVentilDoneExpenseReport") . '<br>';
254 
255  print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
256  print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
257  print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
258 
259  $moreforfilter = '';
260 
261  print '<div class="div-table-responsive">';
262  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
263 
264  print '<tr class="liste_titre_filter">';
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  print '<td class="liste_titre center">';
268  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.'">';
269  print '<input class="flat" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
270  $formother->select_year($search_year,'search_year',1, 20, 5);
271  print '</td>';
272  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
273  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
274  print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
275  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>';
276  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
277  print '<td class="liste_titre" align="right"></td>';
278  print '<td class="liste_titre" align="right">';
279  $searchpicto=$form->showFilterButtons();
280  print $searchpicto;
281  print '</td>';
282  print "</tr>\n";
283 
284  print '<tr class="liste_titre">';
285  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "erd.rowid", "", $param, '', $sortfield, $sortorder);
286  print_liste_field_titre("ExpenseReport", $_SERVER["PHP_SELF"], "er.ref", "", $param, '', $sortfield, $sortorder);
287  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "erd.date, erd.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
288  print_liste_field_titre("TypeFees", $_SERVER["PHP_SELF"], "f.label", "", $param, '', $sortfield, $sortorder);
289  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "erd.comments", "", $param, '', $sortfield, $sortorder);
290  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "erd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
291  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "erd.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
292  print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
294  $checkpicto=$form->showCheckAddButtons();
295  print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
296  print "</tr>\n";
297 
298  $expensereport_static = new ExpenseReport($db);
299 
300  $var = True;
301  while ( $i < min($num_lines, $limit) ) {
302  $objp = $db->fetch_object($result);
303  $codeCompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
304 
305  $expensereport_static->ref = $objp->ref;
306  $expensereport_static->id = $objp->erid;
307 
308  print '<tr class="oddeven">';
309 
310  print '<td>' . $objp->rowid . '</td>';
311 
312  // Ref Invoice
313  print '<td>' . $expensereport_static->getNomUrl(1) . '</td>';
314 
315  print '<td align="center">' . dol_print_date($db->jdate($objp->date), 'day') . '</td>';
316 
317  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>';
318 
319  print '<td>';
320  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
321  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
322  print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
323  print '</td>';
324 
325  print '<td align="right">' . price($objp->total_ht) . '</td>';
326 
327  print '<td align="center">' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . '</td>';
328 
329  print '<td>' . $codeCompta . '</td>';
330 
331  print '<td align="left"><a href="./card.php?id=' . $objp->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].($param?'?'.$param:'')). '">';
332  print img_edit();
333  print '</a></td>';
334 
335  print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
336 
337  print "</tr>";
338  $i ++;
339  }
340 
341  print "</table>";
342  print "</div>";
343 
344  if ($nbtotalofrecords > $limit) {
345  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
346  }
347 
348  print '</form>';
349 } else {
350  print $db->error();
351 }
352 
353 
354 llxFooter();
355 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
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 '...' 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...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
if(empty($reshook)) $form
View.
Definition: perms.php:103
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...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
dolGetFirstLineOfText($text, $nboflines=1)
Return first line of text.
Class to manage Trips and Expenses.
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...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8')
Clean a string from all HTML tags and entities.
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:459
print
Draft customers invoices.
Definition: index.php:91
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) ...
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.