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-2016 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>
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 . '/compta/facture/class/facture.class.php';
31 require_once DOL_DOCUMENT_ROOT . '/product/class/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_ref = GETPOST('search_ref', 'alpha');
54 $search_invoice = GETPOST('search_invoice', '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.facnumber, 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('accountancycustomerlist'));
93 
94 $formaccounting = new FormAccounting($db);
95 $accounting = new AccountingAccount($db);
96 $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT, 1);
97 $aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT, 1);
98 
99 $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
100 
101 
102 /*
103  * Actions
104  */
105 
106 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
107 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
108 
109 $parameters=array();
110 $reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
111 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112 
113 if (empty($reshook))
114 {
115  // Purge search criteria
116  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
117  {
118  $search_lineid = '';
119  $search_ref = '';
120  $search_invoice = '';
121  $search_label = '';
122  $search_desc = '';
123  $search_amount = '';
124  $search_account = '';
125  $search_vat = '';
126  $search_day = '';
127  $search_month = '';
128  $search_year = '';
129  $search_country = '';
130  $search_tvaintra = '';
131  }
132 
133  // Mass actions
134  $objectclass='AccountingAccount';
135  $permtoread = $user->rights->accounting->read;
136  $permtodelete = $user->rights->accounting->delete;
137  $uploaddir = $conf->accounting->dir_output;
138  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
139 }
140 
141 
142 if ($massaction == 'ventil') {
143  $msg='';
144 
145  //print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
146  if (! empty($mesCasesCochees)) {
147  $msg = '<div>' . $langs->trans("SelectedLines") . ': '.count($mesCasesCochees).'</div>';
148  $msg.='<div class="detail">';
149  $cpt = 0;
150  $ok=0;
151  $ko=0;
152 
153  foreach ($mesCasesCochees as $maLigneCochee) {
154  $maLigneCourante = explode("_", $maLigneCochee);
155  $monId = $maLigneCourante[0];
156  $monCompte = GETPOST('codeventil'.$monId);
157 
158  if ($monCompte <= 0)
159  {
160  $msg.= '<div><font color="red">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("NoAccountSelected") . '</font></div>';
161  $ko++;
162  }
163  else
164  {
165  $sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
166  $sql .= " SET fk_code_ventilation = " . $monCompte;
167  $sql .= " WHERE rowid = " . $monId;
168 
169  $accountventilated = new AccountingAccount($db);
170  $accountventilated->fetch($monCompte, '');
171 
172  dol_syslog("accountancy/customer/list.php sql=" . $sql, LOG_DEBUG);
173  if ($db->query($sql)) {
174  $msg.= '<div><font color="green">' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '</font></div>';
175  $ok++;
176  } else {
177  $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>';
178  $ko++;
179  }
180  }
181 
182  $cpt++;
183  }
184  $msg.='</div>';
185  $msg.= '<div>' . $langs->trans("EndProcessing") . '</div>';
186  //} else {
187  // setEventMessages($langs->trans("NoRecordSelected"), null, 'warnings');
188  }
189 }
190 
191 
192 
193 /*
194  * View
195  */
196 
197 $form = new Form($db);
198 $formother = new FormOther($db);
199 
200 llxHeader('', $langs->trans("Ventilation"));
201 
202 if (empty($chartaccountcode))
203 {
204  print $langs->trans("ErrorChartOfAccountSystemNotSelected");
205  // End of page
206  llxFooter();
207  $db->close();
208  exit;
209 }
210 
211 // Customer Invoice lines
212 $sql = "SELECT f.rowid as facid, f.facnumber as ref, f.datef, f.type as ftype,";
213 $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,";
214 $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_sell as code_sell, p.tva_tx as tva_tx_prod,";
215 $sql.= " aa.rowid as aarowid,";
216 $sql.= " co.code as country_code, co.label as country,";
217 $sql.= " s.tva_intra";
218 $parameters=array();
219 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
220 $sql.=$hookmanager->resPrint;
221 $sql.= " FROM " . MAIN_DB_PREFIX . "facture as f";
222 $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
223 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays ";
224 $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_facture";
225 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
226 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $chartaccountcode."' AND aa.entity = " . $conf->entity;
227 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.fk_pcg_version = '" . $chartaccountcode."' AND aa2.entity = " . $conf->entity;
228 $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.fk_pcg_version = '" . $chartaccountcode."' AND aa3.entity = " . $conf->entity;
229 $sql.= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
230 $sql.= " AND l.product_type <= 2";
231 // Add search filter like
232 if ($search_lineid) {
233  $sql .= natural_search("l.rowid", $search_lineid, 1);
234 }
235 if (strlen(trim($search_invoice))) {
236  $sql .= natural_search("f.facnumber", $search_invoice);
237 }
238 if (strlen(trim($search_ref))) {
239  $sql .= natural_search("p.ref", $search_ref);
240 }
241 if (strlen(trim($search_label))) {
242  $sql .= natural_search("p.label", $search_label);
243 }
244 if (strlen(trim($search_desc))) {
245  $sql .= natural_search("l.description", $search_desc);
246 }
247 if (strlen(trim($search_amount))) {
248  $sql .= natural_search("l.total_ht", $search_amount, 1);
249 }
250 if (strlen(trim($search_account))) {
251  $sql .= natural_search("aa.account_number", $search_account);
252 }
253 if (strlen(trim($search_vat))) {
254  $sql .= natural_search("l.tva_tx", $search_vat, 1);
255 }
256 if ($search_month > 0)
257 {
258  if ($search_year > 0 && empty($search_day))
259  $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))."'";
260  else if ($search_year > 0 && ! empty($search_day))
261  $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))."'";
262  else
263  $sql.= " AND date_format(f.datef, '%m') = '".$db->escape($search_month)."'";
264 }
265 else if ($search_year > 0)
266 {
267  $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))."'";
268 }
269 if (strlen(trim($search_country))) {
270  $arrayofcode = getCountriesInEEC();
271  $country_code_in_EEC = $country_code_in_EEC_without_me = '';
272  foreach ($arrayofcode as $key => $value)
273  {
274  $country_code_in_EEC.=($country_code_in_EEC ? "," : "")."'".$value."'";
275  if ($value != $mysoc->country_code) $country_code_in_EEC_without_me.=($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
276  }
277  if ($search_country == 'special_allnotme') $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
278  elseif ($search_country == 'special_eec') $sql .= " AND co.code IN (".$country_code_in_EEC.")";
279  elseif ($search_country == 'special_eecnotme') $sql .= " AND co.code IN (".$country_code_in_EEC_without_me.")";
280  elseif ($search_country == 'special_noteec') $sql .= " AND co.code NOT IN (".$country_code_in_EEC.")";
281  else $sql .= natural_search(array("co.code","co.label"), $search_country);
282 }
283 if (strlen(trim($search_tvaintra))) {
284  $sql .= natural_search("s.tva_intra", $search_tvaintra);
285 }
286 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
287  $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
288 } else {
289  $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
290 }
291 $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy
292 
293 // Add where from hooks
294 $parameters=array();
295 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
296 $sql.=$hookmanager->resPrint;
297 
298 $sql .= $db->order($sortfield, $sortorder);
299 
300 // Count total nb of records
301 $nbtotalofrecords = '';
302 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
303 {
304  $result = $db->query($sql);
305  $nbtotalofrecords = $db->num_rows($result);
306  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
307  {
308  $page = 0;
309  $offset = 0;
310  }
311 }
312 
313 $sql .= $db->plimit($limit + 1, $offset);
314 
315 dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
316 $result = $db->query($sql);
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 center nowraponall">';
378  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.'">';
379  print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_month" value="'.$search_month.'">';
380  $formother->select_year($search_year,'search_year',1, 20, 5);
381  print '</td>';
382  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="' . dol_escape_htmltag($search_ref) . '"></td>';
383  //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></td>';
384  print '<td class="liste_titre"><input type="text" class="flat maxwidthonsmartphone" name="search_desc" value="' . dol_escape_htmltag($search_desc) . '"></td>';
385  print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50 right" name="search_amount" value="' . dol_escape_htmltag($search_amount) . '"></td>';
386  print '<td class="liste_titre" align="right"><input type="text" class="flat maxwidth50 right" name="search_vat" placeholder="%" size="1" value="' . dol_escape_htmltag($search_vat) . '"></td>';
387  print '<td class="liste_titre">';
388  print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth200', 'code2', 1, 0, 1);
389  //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
390  print '</td>';
391  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="' . dol_escape_htmltag($search_tvaintra) . '"></td>';
392  print '<td class="liste_titre"></td>';
393  print '<td class="liste_titre"></td>';
394  print '<td align="center" class="liste_titre">';
395  $searchpicto=$form->showFilterButtons();
396  print $searchpicto;
397  print '</td>';
398  print '</tr>';
399 
400  print '<tr class="liste_titre">';
401  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
402  print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.facnumber", "", $param, '', $sortfield, $sortorder);
403  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.facnumber, l.rowid", "", $param, 'align="center"', $sortfield, $sortorder);
404  print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
405  //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
406  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
407  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
408  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="right"', $sortfield, $sortorder);
409  print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
410  print_liste_field_titre("VATIntra", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
411  print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', 'align="center"');
412  print_liste_field_titre("IntoAccount", '', '', '', '', 'align="center"');
413  $checkpicto='';
414  if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1);
415  print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"');
416  print "</tr>\n";
417 
418  $facture_static = new Facture($db);
419  $product_static = new Product($db);
420 
421  while ( $i < min($num_lines, $limit) ) {
422  $objp = $db->fetch_object($result);
423 
424  $objp->code_sell_l = '';
425  $objp->code_sell_p = '';
426  $objp->aarowid_suggest = '';
427 
428  $product_static->ref = $objp->product_ref;
429  $product_static->id = $objp->product_id;
430  $product_static->type = $objp->type;
431  $product_static->label = $objp->product_label;
432 
433  $facture_static->ref = $objp->ref;
434  $facture_static->id = $objp->facid;
435  $facture_static->type = $objp->ftype;
436 
437  $code_sell_p_notset = '';
438  $objp->aarowid_suggest = $objp->aarowid;
439 
440  if ($objp->type_l == 1) {
441  $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
442  if ($objp->aarowid == '') {
443  $objp->aarowid_suggest = $aarowid_s;
444  }
445  } elseif ($objp->type_l == 0) {
446  $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
447  if ($objp->aarowid == '') {
448  $objp->aarowid_suggest = $aarowid_p;
449  }
450  }
451  if ($objp->code_sell_l == -1) $objp->code_sell_l='';
452 
453  if (! empty($objp->code_sell)) {
454  $objp->code_sell_p = $objp->code_sell; // Code on product
455  } else {
456  $code_sell_p_notset = 'color:orange';
457  }
458  if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) $code_sell_p_notset = 'color:red';
459 
460  // $objp->code_sell_p is now code of product/service
461  // $objp->code_sell_l is now default code of product/service
462 
463  print '<tr class="oddeven">';
464 
465  // Line id
466  print '<td>' . $objp->rowid . '</td>';
467 
468  // Ref Invoice
469  print '<td class="nowraponall">' . $facture_static->getNomUrl(1) . '</td>';
470 
471  print '<td align="center">' . dol_print_date($db->jdate($objp->datef), 'day') . '</td>';
472 
473  // Ref Product
474  print '<td>';
475  if ($product_static->id)
476  print $product_static->getNomUrl(1);
477  if ($objp->product_label) print '<br>'.$objp->product_label;
478  print '</td>';
479 
480  print '<td class="tdoverflowonsmartphone">';
481  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
482  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
483  print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
484  print '</td>';
485 
486  print '<td align="right">';
487  print price($objp->total_ht);
488  print '</td>';
489 
490  // Vat rate
491  if ($objp->vat_tx_l != $objp->vat_tx_p)
492  $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
493  print '<td style="' . $code_vat_differ . '" align="right">';
494  print vatrate($objp->tva_tx_line.($objp->vat_src_code?' ('.$objp->vat_src_code.')':''));
495  print '</td>';
496 
497  print '<td>' . $objp->country .'</td>';
498 
499  print '<td>' . $objp->tva_intra . '</td>';
500 
501  // Current account
502  print '<td align="center" style="' . $code_sell_p_notset . '">';
503  print (($objp->type_l == 1)?$langs->trans("DefaultForService"):$langs->trans("DefaultForProduct")) . ' = ' . ($objp->code_sell_l > 0 ? length_accountg($objp->code_sell_l) : $langs->trans("Unknown"));
504  if ($objp->product_id > 0)
505  {
506  print '<br>';
507  print (($objp->type_l == 1)?$langs->trans("ThisService"):$langs->trans("ThisProduct")) . ' = ' . (empty($objp->code_sell_p) ? $langs->trans("Unknown") : length_accountg($objp->code_sell_p));
508  }
509  print '</td>';
510 
511  // Suggested accounting account
512  print '<td align="center">';
513  print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
514  print '</td>';
515 
516  // Column with checkbox
517  print '<td align="center">';
518  print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="' . $objp->rowid . "_" . $i . '"' . ($objp->aarowid ? "checked" : "") . '/>';
519  print '</td>';
520 
521  print '</tr>';
522  $i ++;
523  }
524  print '</table>';
525  print "</div>";
526 
527  print '</form>';
528 } else {
529  print $db->error();
530 }
531 
532 // Add code to auto check the box when we select an account
533 print '<script type="text/javascript" language="javascript">
534 jQuery(document).ready(function() {
535  jQuery(".codeventil").change(function() {
536  var s=$(this).attr("id").replace("codeventil", "")
537  console.log(s+" "+$(this).val());
538  if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
539  else jQuery(".checkforselect"+s).prop("checked", true);
540  });
541 });
542 </script>';
543 
544 // End of page
545 llxFooter();
546 $db->close();
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
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.
const TYPE_STANDARD
Standard invoice.
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...
Class to manage products or services.
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.
const TYPE_REPLACEMENT
Replacement invoice.
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...
const TYPE_SITUATION
Situation invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
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_DEPOSIT
Deposit 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.
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.
Class to manage invoices.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...