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 . '/fourn/class/fournisseur.facture.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
35 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
37 
38 // Langs
39 $langs->load("compta");
40 $langs->load("bills");
41 $langs->load("other");
42 $langs->load("main");
43 $langs->load("accountancy");
44 $langs->load("productbatch");
45 
46 $account_parent = GETPOST('account_parent');
47 $changeaccount = GETPOST('changeaccount');
48 // Search Getpost
49 $search_lineid = GETPOST('search_lineid', 'int');
50 $search_ref = GETPOST('search_ref', 'alpha');
51 $search_invoice = GETPOST('search_invoice', 'alpha');
52 $search_label = GETPOST('search_label', 'alpha');
53 $search_desc = GETPOST('search_desc', 'alpha');
54 $search_amount = GETPOST('search_amount', 'alpha');
55 $search_account = GETPOST('search_account', 'alpha');
56 $search_vat = GETPOST('search_vat', 'alpha');
57 $search_day=GETPOST("search_day","int");
58 $search_month=GETPOST("search_month","int");
59 $search_year=GETPOST("search_year","int");
60 $search_country = GETPOST('search_country', 'alpha');
61 $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
62 
63 // Load variable for pagination
64 $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
65 $sortfield = GETPOST('sortfield', 'alpha');
66 $sortorder = GETPOST('sortorder', 'alpha');
67 $page = GETPOST('page', 'int');
68 if ($page < 0) $page = 0;
69 $offset = $conf->liste_limit * $page;
70 $pageprev = $page - 1;
71 $pagenext = $page + 1;
72 if (! $sortfield)
73  $sortfield = "f.datef, f.ref, l.rowid";
74 if (! $sortorder) {
75  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
76  $sortorder = "DESC";
77  }
78 }
79 
80 // Security check
81 if ($user->societe_id > 0)
83 if (! $user->rights->accounting->bind->write)
85 
86 $formaccounting = new FormAccounting($db);
87 
88 
89 /*
90  * Actions
91  */
92 
93 // Purge search criteria
94 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
95 {
96  $search_lineid = '';
97  $search_ref = '';
98  $search_invoice = '';
99  $search_label = '';
100  $search_desc = '';
101  $search_amount = '';
102  $search_account = '';
103  $search_vat = '';
104  $search_day = '';
105  $search_month = '';
106  $search_year = '';
107  $search_country = '';
108  $search_tvaintra = '';
109 }
110 
111 if (is_array($changeaccount) && count($changeaccount) > 0) {
112  $error = 0;
113 
114  $db->begin();
115 
116  $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as l";
117  $sql1 .= " SET l.fk_code_ventilation=" . GETPOST('account_parent','int');
118  $sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')';
119 
120  dol_syslog('accountancy/supplier/lines.php::changeaccount sql= ' . $sql1);
121  $resql1 = $db->query($sql1);
122  if (! $resql1) {
123  $error ++;
124  setEventMessages($db->lasterror(), null, 'errors');
125  }
126  if (! $error) {
127  $db->commit();
128  setEventMessages($langs->trans('Save'), null, 'mesgs');
129  } else {
130  $db->rollback();
131  setEventMessages($db->lasterror(), null, 'errors');
132  }
133 
134  $account_parent = ''; // Protection to avoid to mass apply it a second time
135 }
136 
137 
138 /*
139  * View
140  */
141 
142 $form = new Form($db);
143 $formother = new FormOther($db);
144 
145 llxHeader('', $langs->trans("SuppliersVentilation") . ' - ' . $langs->trans("Dispatched"));
146 
147 print '<script type="text/javascript">
148  $(function () {
149  $(\'#select-all\').click(function(event) {
150  // Iterate each checkbox
151  $(\':checkbox\').each(function() {
152  this.checked = true;
153  });
154  });
155  $(\'#unselect-all\').click(function(event) {
156  // Iterate each checkbox
157  $(\':checkbox\').each(function() {
158  this.checked = false;
159  });
160  });
161  });
162  </script>';
163 
164 /*
165  * Supplier Invoice lines
166  */
167 $sql = "SELECT f.rowid as facid, f.ref as facnumber, f.ref_supplier, f.libelle as invoice_label, f.datef, f.fk_soc,";
168 $sql.= " l.rowid, l.fk_product, l.description, l.total_ht , l.qty, l.tva_tx, l.vat_src_code,";
169 $sql.= " aa.label, aa.account_number, ";
170 $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, co.label as country, s.tva_intra";
171 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as l";
172 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
173 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = l.fk_code_ventilation";
174 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn";
175 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
176 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays ";
177 $sql.= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
178 $sql.= " AND aa.rowid = l.fk_code_ventilation";
179 if ($search_lineid) {
180  $sql .= natural_search("l.rowid", $search_lineid, 1);
181 }
182 if (strlen(trim($search_invoice))) {
183  $sql .= natural_search("f.ref", $search_invoice);
184 }
185 if (strlen(trim($search_ref))) {
186  $sql .= natural_search("p.ref", $search_ref);
187 }
188 if (strlen(trim($search_label))) {
189  $sql .= natural_search("p.label", $search_label);
190 }
191 if (strlen(trim($search_desc))) {
192  $sql .= natural_search("l.description", $search_desc);
193 }
194 if (strlen(trim($search_amount))) {
195  $sql .= natural_search("l.total_ht", $search_amount, 1);
196 }
197 if (strlen(trim($search_account))) {
198  $sql .= natural_search("aa.account_number", $search_account, 1);
199 }
200 if (strlen(trim($search_vat))) {
201  $sql .= natural_search("l.tva_tx", $search_vat, 1);
202 }
203 if ($search_month > 0)
204 {
205  if ($search_year > 0 && empty($search_day))
206  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
207  else if ($search_year > 0 && ! empty($search_day))
208  $sql.= " AND f.datef 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))."'";
209  else
210  $sql.= " AND date_format(f.datef, '%m') = '".$db->escape($search_month)."'";
211 }
212 else if ($search_year > 0)
213 {
214  $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
215 }
216 if (strlen(trim($search_country))) {
217  $sql .= " AND (co.label like'" . $search_country . "%')";
218 }
219 if (strlen(trim($search_tvaintra))) {
220  $sql .= " AND (s.tva_intra like'" . $search_tvaintra . "%')";
221 }
222 $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
223 
224 $sql .= $db->order($sortfield, $sortorder);
225 
226 // Count total nb of records
227 $nbtotalofrecords = '';
228 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
229 {
230  $result = $db->query($sql);
231  $nbtotalofrecords = $db->num_rows($result);
232 }
233 
234 $sql .= $db->plimit($limit + 1, $offset);
235 
236 dol_syslog('accountancy/supplier/lines.php::list');
237 $result = $db->query($sql);
238 
239 if ($result) {
240  $num_lines = $db->num_rows($result);
241  $i = 0;
242 
243  $param='';
244  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
245  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
246  if ($search_invoice)
247  $param .= "&search_invoice=" . $search_invoice;
248  if ($search_ref)
249  $param .= "&search_ref=" . $search_ref;
250  if ($search_label)
251  $param .= "&search_label=" . $search_label;
252  if ($search_desc)
253  $param .= "&search_desc=" . $search_desc;
254  if ($search_account)
255  $param .= "&search_account=" . $search_account;
256  if ($search_vat)
257  $param .= "&search_vat=" . $search_vat;
258  if ($search_day) $param.='&search_day='.urlencode($search_day);
259  if ($search_month) $param.='&search_month='.urlencode($search_month);
260  if ($search_year) $param.='&search_year='.urlencode($search_year);
261  if ($search_country)
262  $param .= "&search_country=" . $search_country;
263  if ($search_tvaintra)
264  $param .= "&search_tvaintra=" . $search_tvaintra;
265 
266  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
267  print '<input type="hidden" name="action" value="ventil">';
268  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
269  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
270  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
271  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
272  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
273  print '<input type="hidden" name="page" value="'.$page.'">';
274 
275  print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
276 
277  print $langs->trans("DescVentilDoneSupplier") . '<br>';
278 
279  print '<br><div class="inline-block divButAction">' . $langs->trans("ChangeAccount") . '<br>';
280  print $formaccounting->select_account(GETPOST('account_parent'), 'account_parent', 1);
281  print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("ChangeBinding") . '" /></div>';
282 
283  $moreforfilter = '';
284 
285  print '<div class="div-table-responsive">';
286  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
287 
288  print '<tr class="liste_titre_filter">';
289  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
290  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
291  print '<td class="liste_titre"></td>';
292  print '<td class="liste_titre center">';
293  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.'">';
294  print '<input class="flat" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
295  $formother->select_year($search_year,'search_year',1, 20, 5);
296  print '</td>';
297  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
298  //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
299  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
300  print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
301  print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>';
302  print '<td class="liste_titre" align="center"><input type="text" class="flat maxwidth50" name="search_account" value="' . dol_escape_htmltag($search_account) . '"></td>';
303  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '"></td>';
304  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tavintra" value="' . dol_escape_htmltag($search_tavintra) . '"></td>';
305  print '<td class="liste_titre" align="center">';
306  $searchpicto=$form->showFilterButtons();
307  print $searchpicto;
308  print '</td>';
309  print "</tr>\n";
310 
311  print '<tr class="liste_titre">';
312  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
313  print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
314  print_liste_field_titre("InvoiceLabel", $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
315  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
316  print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
317  //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
318  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
319  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
320  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="right"', $sortfield, $sortorder);
321  print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "aa.account_number", "", $param, 'align="center"', $sortfield, $sortorder);
322  print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
323  print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
324  $checkpicto=$form->showCheckAddButtons();
325  print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
326  print "</tr>\n";
327 
328  $facturefournisseur_static = new FactureFournisseur($db);
329  $product_static = new Product($db);
330 
331  while ($i < min($num_lines, $limit)) {
332  $objp = $db->fetch_object($result);
333 
334  $codecompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
335 
336  $facturefournisseur_static->ref = $objp->facnumber;
337  $facturefournisseur_static->id = $objp->facid;
338 
339  $product_static->ref = $objp->product_ref;
340  $product_static->id = $objp->product_id;
341  $product_static->type = $objp->type;
342  $product_static->label = $objp->product_label;
343 
344  print '<tr class="oddeven">';
345 
346  print '<td>' . $objp->rowid . '</td>';
347 
348  // Ref Invoice
349  print '<td>' . $facturefournisseur_static->getNomUrl(1) . '</td>';
350 
351  print '<td>';
352  print $objp->invoice_label;
353  print '</td>';
354 
355  print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
356 
357  // Ref Product
358  print '<td>';
359  if ($product_static->id)
360  print $product_static->getNomUrl(1);
361  if ($objp->product_label) print '<br>'.$objp->product_label;
362  print '</td>';
363 
364  print '<td>';
365  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
366  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
367  print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
368  print '</td>';
369 
370  print '<td align="right">' . price($objp->total_ht) . '</td>';
371  print '<td align="right">' . vatrate($objp->tva_tx.($objp->vat_src_code?' ('.$objp->vat_src_code.')':'')) . '</td>';
372  print '<td align="center">';
373  print $codecompta . ' <a href="./card.php?id=' . $objp->rowid . '&backtopage='.urlencode($_SERVER["PHP_SELF"].($param?'?'.$param:'')) . '">';
374  print img_edit();
375  print '</a></td>';
376  print '<td>' . $objp->country .'</td>';
377  print '<td>' . $objp->tva_intra . '</td>';
378  print '<td class="center"><input type="checkbox" class="checkforaction" name="changeaccount[]" value="' . $objp->rowid . '"/></td>';
379 
380  print "</tr>";
381  $i ++;
382  }
383  print "</table>";
384  print "</div>";
385 
386  if ($nbtotalofrecords > $limit) {
387  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1);
388  }
389 
390  print '</form>';
391 } else {
392  print $db->error();
393 }
394 
395 
396 
397 llxFooter();
398 $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...
Class to manage products or services.
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
Class to manage suppliers invoices.
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.
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.
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.