dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 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-2014 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>s
7  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
28 require '../../main.inc.php';
29 
30 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
32 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
33 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.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 require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array("bills","compta","accountancy","other","productbatch"));
41 
42 $action=GETPOST('action','alpha');
43 $massaction=GETPOST('massaction','alpha');
44 $show_files=GETPOST('show_files','int');
45 $confirm=GETPOST('confirm','alpha');
46 $toselect = GETPOST('toselect', 'array');
47 
48 // Select Box
49 $mesCasesCochees = GETPOST('toselect', 'array');
50 
51 // Search Getpost
52 $search_lineid = GETPOST('search_lineid', 'int');
53 $search_invoice = GETPOST('search_invoice', 'alpha');
54 $search_ref = GETPOST('search_ref', 'alpha');
55 $search_label = GETPOST('search_label', 'alpha');
56 $search_desc = GETPOST('search_desc', 'alpha');
57 $search_amount = GETPOST('search_amount', 'alpha');
58 $search_account = GETPOST('search_account', 'alpha');
59 $search_vat = GETPOST('search_vat', 'alpha');
60 $search_day=GETPOST("search_day","int");
61 $search_month=GETPOST("search_month","int");
62 $search_year=GETPOST("search_year","int");
63 $search_country = GETPOST('search_country', 'alpha');
64 $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
65 
66 $btn_ventil = GETPOST('ventil', 'alpha');
67 
68 // Load variable for pagination
69 $limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
70 $sortfield = GETPOST('sortfield', 'alpha');
71 $sortorder = GETPOST('sortorder', 'alpha');
72 $page = GETPOST('page','int');
73 if (empty($page) || $page < 0) { $page = 0; }
74 $offset = $limit * $page;
75 $pageprev = $page - 1;
76 $pagenext = $page + 1;
77 if (! $sortfield)
78  $sortfield = "f.datef, f.ref, l.rowid";
79 if (! $sortorder) {
80  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
81  $sortorder = "DESC";
82  }
83 }
84 
85 // Security check
86 if ($user->societe_id > 0)
88 if (! $user->rights->accounting->bind->write)
90 
91 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
92 $hookmanager->initHooks(array('accountancysupplierlist'));
93 
94 $formaccounting = new FormAccounting($db);
95 $accounting = new AccountingAccount($db);
96 // TODO: we should need to check if result is a really exist accountaccount rowid.....
97 $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
98 $aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
99 
100 $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
101 
102 
103 /*
104  * Actions
105  */
106 
107 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
108 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
109 
110 $parameters=array();
111 $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
112 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
113 
114 if (empty($reshook))
115 {
116  // Purge search criteria
117  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers
118  {
119  $search_lineid = '';
120  $search_ref = '';
121  $search_invoice = '';
122  $search_label = '';
123  $search_desc = '';
124  $search_amount = '';
125  $search_account = '';
126  $search_vat = '';
127  $search_day = '';
128  $search_month = '';
129  $search_year = '';
130  $search_country = '';
131  $search_tvaintra = '';
132  }
133 
134  // Mass actions
135  $objectclass='AccountingAccount';
136  $permtoread = $user->rights->accounting->read;
137  $permtodelete = $user->rights->accounting->delete;
138  $uploaddir = $conf->accounting->dir_output;
139  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
140 }
141 
142 
143 if ($massaction == 'ventil') {
144  $msg='';
145 
146  //print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
147  if (! empty($mesCasesCochees)) {
148  $msg = '<div>' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'</div>';
149  $msg.='<div class="detail">';
150  $cpt = 0;
151  $ok=0;
152  $ko=0;
153 
154  foreach ($mesCasesCochees as $maLigneCochee) {
155  $maLigneCourante = explode("_", $maLigneCochee);
156  $monId = $maLigneCourante[0];
157  $monCompte = GETPOST('codeventil'.$monId);
158 
159  if ($monCompte <= 0)
160  {
161  $msg.= '<div><font color="red">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</font></div>';
162  $ko++;
163  }
164  else
165  {
166  $sql = " UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
167  $sql .= " SET fk_code_ventilation = " . $monCompte;
168  $sql .= " WHERE rowid = " . $monId;
169 
170  $accountventilated = new AccountingAccount($db);
171  $accountventilated->fetch($monCompte, '');
172 
173  dol_syslog('accountancy/supplier/list.php:: sql=' . $sql, LOG_DEBUG);
174  if ($db->query($sql)) {
175  $msg.= '<div><font color="green">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</font></div>';
176  $ok++;
177  } else {
178  $msg.= '<div><font color="red">' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '<br/> <pre>' . $sql . '</pre></font></div>';
179  $ko++;
180  }
181  }
182 
183  $cpt++;
184  }
185  $msg.='</div>';
186  $msg.= '<div>' . $langs->trans("EndProcessing") . '</div>';
187  //} else {
188  // setEventMessages($langs->trans("NoRecordSelected"), null, 'warnings');
189  }
190 }
191 
192 
193 
194 /*
195  * View
196  */
197 
198 $form = new Form($db);
199 $formother = new FormOther($db);
200 
201 llxHeader('', $langs->trans("SuppliersVentilation"));
202 
203 if (empty($chartaccountcode))
204 {
205  print $langs->trans("ErrorChartOfAccountSystemNotSelected");
206  // End of page
207  llxFooter();
208  $db->close();
209  exit;
210 }
211 
212 // Supplier Invoice Lines
213 $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype,";
214 $sql.= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
215 $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.accountancy_code_buy as code_buy, p.tva_tx as tva_tx_prod,";
216 $sql.= " aa.rowid as aarowid,";
217 $sql.= " co.code as country_code, co.label as country,";
218 $sql.= " s.tva_intra";
219 $parameters=array();
220 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
221 $sql.=$hookmanager->resPrint;
222 $sql.= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
223 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
224 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays ";
225 $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
226 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
227 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity;
228 $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
229 $sql.= " AND l.product_type <= 2";
230 // Add search filter like
231 if ($search_lineid) {
232  $sql .= natural_search("l.rowid", $search_lineid, 1);
233 }
234 if (strlen(trim($search_invoice))) {
235  $sql .= natural_search("f.ref", $search_invoice);
236 }
237 if (strlen(trim($search_ref))) {
238  $sql .= natural_search("p.ref", $search_ref);
239 }
240 if (strlen(trim($search_label))) {
241  $sql .= natural_search("p.label", $search_label);
242 }
243 if (strlen(trim($search_desc))) {
244  $sql .= natural_search("l.description", $search_desc);
245 }
246 if (strlen(trim($search_amount))) {
247  $sql .= natural_search("l.total_ht", $search_amount, 1);
248 }
249 if (strlen(trim($search_account))) {
250  $sql .= natural_search("aa.account_number", $search_account);
251 }
252 if (strlen(trim($search_vat))) {
253  $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
254 }
255 if ($search_month > 0)
256 {
257  if ($search_year > 0 && empty($search_day))
258  $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))."'";
259  else if ($search_year > 0 && ! empty($search_day))
260  $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))."'";
261  else
262  $sql.= " AND date_format(f.datef, '%m') = '".$db->escape($search_month)."'";
263 }
264 else if ($search_year > 0)
265 {
266  $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))."'";
267 }
268 if (strlen(trim($search_country))) {
269  $arrayofcode = getCountriesInEEC();
270  $country_code_in_EEC = $country_code_in_EEC_without_me = '';
271  foreach ($arrayofcode as $key => $value)
272  {
273  $country_code_in_EEC.=($country_code_in_EEC ? "," : "")."'".$value."'";
274  if ($value != $mysoc->country_code) $country_code_in_EEC_without_me.=($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
275  }
276  if ($search_country == 'special_allnotme') $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
277  elseif ($search_country == 'special_eec') $sql .= " AND co.code IN (".$country_code_in_EEC.")";
278  elseif ($search_country == 'special_eecnotme') $sql .= " AND co.code IN (".$country_code_in_EEC_without_me.")";
279  elseif ($search_country == 'special_noteec') $sql .= " AND co.code NOT IN (".$country_code_in_EEC.")";
280  else $sql .= natural_search(array("co.code","co.label"), $search_country);
281 }
282 if (strlen(trim($search_tvaintra))) {
283  $sql .= natural_search("s.tva_intra", $search_tvaintra);
284 }
285 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
287 } else {
289 }
290 $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy
291 
292 // Add where from hooks
293 $parameters=array();
294 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
295 $sql.=$hookmanager->resPrint;
296 
297 $sql .= $db->order($sortfield, $sortorder);
298 
299 // Count total nb of records
300 $nbtotalofrecords = '';
301 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
302 {
303  $result = $db->query($sql);
304  $nbtotalofrecords = $db->num_rows($result);
305  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
306  {
307  $page = 0;
308  $offset = 0;
309  }
310 }
311 
312 $sql .= $db->plimit($limit + 1, $offset);
313 
314 dol_syslog('accountancy/supplier/list.php');
315 $result = $db->query($sql);
316 
317 if ($result) {
318  $num_lines = $db->num_rows($result);
319  $i = 0;
320 
321  $arrayofselected=is_array($toselect)?$toselect:array();
322 
323  $param='';
324  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
325  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
326  if ($search_lineid) $param.='&search_lineid='.urlencode($search_lineid);
327  if ($search_day) $param.='&search_day='.urlencode($search_day);
328  if ($search_month) $param.='&search_month='.urlencode($search_month);
329  if ($search_year) $param.='&search_year='.urlencode($search_year);
330  if ($search_invoice) $param.='&search_invoice='.urlencode($search_invoice);
331  if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
332  if ($search_desc) $param.='&search_desc='.urlencode($search_desc);
333  if ($search_amount) $param.='&search_amount='.urlencode($search_amount);
334  if ($search_vat) $param.='&search_vat='.urlencode($search_vat);
335  if ($search_country) $param .= "&search_country=" . urlencode($search_country);
336  if ($search_tvaintra) $param .= "&search_tvaintra=" . urlencode($search_tvaintra);
337 
338  $arrayofmassactions = array(
339  'ventil'=>$langs->trans("Ventilate")
340  //'presend'=>$langs->trans("SendByMail"),
341  //'builddoc'=>$langs->trans("PDFMerge"),
342  );
343  //if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
344  //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
345  $massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1);
346 
347  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">' . "\n";
348  print '<input type="hidden" name="action" value="ventil">';
349  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
350  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
351  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
352  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
353  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
354  print '<input type="hidden" name="page" value="'.$page.'">';
355 
356  print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
357 
358  print $langs->trans("DescVentilTodoCustomer") . '</br><br>';
359 
360  /*$topicmail="Information";
361  $modelmail="project";
362  $objecttmp=new Project($db);
363  $trackid='prj'.$object->id;
364  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';*/
365 
366  if ($msg) print $msg.'<br>';
367 
368  $moreforfilter = '';
369 
370  print '<div class="div-table-responsive">';
371  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
372 
373  // We add search filter
374  print '<tr class="liste_titre_filter">';
375  print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="' . dol_escape_htmltag($search_lineid) . '""></td>';
376  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="' . dol_escape_htmltag($search_invoice) . '"></td>';
377  print '<td class="liste_titre"></td>';
378  print '<td class="liste_titre center nowraponall">';
379  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_day" value="'.$search_day.'">';
380  print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
381  $formother->select_year($search_year,'search_year',1, 20, 5);
382  print '</td>';
383  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
384  //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
385  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
386  print '<td class="liste_titre" align="right"><input type="text" class="right flat maxwidth50" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
387  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>';
388  print '<td class="liste_titre">';
389  print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth200', 'code2', 1, 0, 1);
390  //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
391  print '</td>';
392  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="' . dol_escape_htmltag($search_tvaintra) . '"></td>';
393  print '<td class="liste_titre"></td>';
394  print '<td class="liste_titre"></td>';
395  print '<td align="center" class="liste_titre">';
396  $searchpicto=$form->showFilterButtons();
397  print $searchpicto;
398  print '</td>';
399  print "</tr>\n";
400 
401  print '<tr class="liste_titre">';
402  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
403  print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
404  print_liste_field_titre("InvoiceLabel", $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
405  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
406  print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
407  //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
408  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
409  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
410  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="right"', $sortfield, $sortorder);
411  print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
412  print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
413  print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', 'align="center"');
414  print_liste_field_titre("IntoAccount", '', '', '', '', 'align="center"');
415  $checkpicto='';
416  if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
417  print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
418  print "</tr>\n";
419 
420  $facturefourn_static = new FactureFournisseur($db);
421  $productfourn_static = new ProductFournisseur($db);
422 
423  while ($i < min($num_lines, $limit)) {
424  $objp = $db->fetch_object($result);
425 
426  // product_type: 0 = service ? 1 = product
427  // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
428  // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
429  $objp->code_buy_l = '';
430  $objp->code_buy_p = '';
431  $objp->aarowid_suggest = '';
432 
433  $productfourn_static->ref = $objp->product_ref;
434  $productfourn_static->id = $objp->product_id;
435  $productfourn_static->type = $objp->type;
436  $productfourn_static->label = $objp->product_label;
437 
438  $facturefourn_static->ref = $objp->ref;
439  $facturefourn_static->id = $objp->facid;
440  $facturefourn_static->type = $objp->type;
441 
442  $code_buy_p_notset = '';
443  $objp->aarowid_suggest = $objp->aarowid;
444 
445  if ($objp->type_l == 1) {
446  $objp->code_buy_l = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : '');
447  if ($objp->aarowid == '')
448  $objp->aarowid_suggest = $aarowid_s;
449  } elseif ($objp->type_l == 0) {
450  $objp->code_buy_l = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : '');
451  if ($objp->aarowid == '')
452  $objp->aarowid_suggest = $aarowid_p;
453  }
454  if ($objp->code_buy_l == -1) $objp->code_buy_l='';
455 
456  if (! empty($objp->code_buy)) {
457  $objp->code_buy_p = $objp->code_buy; // Code on product
458  } else {
459  $code_buy_p_notset = 'color:orange';
460  }
461  if (empty($objp->code_buy_l) && empty($objp->code_buy_p)) $code_buy_p_notset = 'color:red';
462 
463  // $objp->code_buy_p is now code of product/service
464  // $objp->code_buy_l is now default code of product/service
465 
466  print '<tr class="oddeven">';
467 
468  // Line id
469  print '<td>' . $objp->rowid . '</td>';
470 
471  // Ref Invoice
472  print '<td class="nowraponall">' . $facturefourn_static->getNomUrl(1) . '</td>';
473 
474  print '<td class="tdoverflowonsmartphone">';
475  print $objp->invoice_label;
476  print '</td>';
477 
478  print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
479 
480  // Ref product
481  print '<td>';
482  if ($productfourn_static->id)
483  print $productfourn_static->getNomUrl(1);
484  if ($objp->product_label) print '<br>'.$objp->product_label;
485  print '</td>';
486 
487  // Description
488  print '<td>';
489  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
490  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
491  print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
492  print '</td>';
493 
494  print '<td align="right">';
495  print price($objp->total_ht);
496  print '</td>';
497 
498  // Vat rate
499  if ($objp->vat_tx_l != $objp->vat_tx_p)
500  $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
501  print '<td style="' . $code_vat_differ . '" align="right">';
502  print vatrate($objp->tva_tx_line.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''));
503  print '</td>';
504 
505  print '<td>' . $objp->country .'</td>';
506  print '<td>' . $objp->tva_intra . '</td>';
507 
508  // Current account
509  print '<td align="center" style="' . $code_buy_p_notset . '">';
510  print (($objp->type_l == 1)?$langs->trans("DefaultForService"):$langs->trans("DefaultForProduct")) . ' = ' . ($objp->code_buy_l > 0 ? length_accountg($objp->code_buy_l) : $langs->trans("Unknown"));
511  if ($objp->product_id > 0)
512  {
513  print '<br>';
514  print (($objp->type_l == 1)?$langs->trans("ThisService"):$langs->trans("ThisProduct")) . ' = ' . (empty($objp->code_buy_p) ? $langs->trans("Unknown") : length_accountg($objp->code_buy_p));
515  }
516  print '</td>';
517 
518  // Suggested accounting account
519  print '<td align="center">';
520  print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
521  print '</td>';
522 
523  // Column with checkbox
524  print '<td align="center">';
525  print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';
526  print '</td>';
527 
528  print '</tr>';
529  $i ++;
530  }
531 
532  print '</table>';
533  print "</div>";
534 
535  print '</form>';
536 } else {
537  print $db->error();
538 }
539 
540 // Add code to auto check the box when we select an account
541 print '<script type="text/javascript" language="javascript">
542 jQuery(document).ready(function() {
543  jQuery(".codeventil").change(function() {
544  var s=$(this).attr("id").replace("codeventil", "")
545  console.log(s+" "+$(this).val());
546  if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
547  else jQuery(".checkforselect"+s).prop("checked", true);
548  });
549 });
550 </script>';
551 
552 // End of page
553 llxFooter();
554 $db->close();
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
const TYPE_STANDARD
Standard invoice.
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.
const TYPE_DEPOSIT
Deposit invoice.
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...
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) TODO Add a field into ...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
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
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
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...
if(! GETPOST('transkey', 'alphanohtml') &&! GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:43
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.
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
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).
const TYPE_CREDIT_NOTE
Credit note invoice.
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.
const TYPE_SITUATION
Situation invoice.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage accounting accounts.
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;...
Class to manage predefined suppliers products.