dolibarr  13.0.2
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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 <https://www.gnu.org/licenses/>.
21  */
22 
28 require '../../main.inc.php';
29 
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "productbatch", "products"));
43 
44 $action = GETPOST('action', 'aZ09');
45 $massaction = GETPOST('massaction', 'alpha');
46 $show_files = GETPOST('show_files', 'int');
47 $confirm = GETPOST('confirm', 'alpha');
48 $toselect = GETPOST('toselect', 'array');
49 
50 // Select Box
51 $mesCasesCochees = GETPOST('toselect', 'array');
52 
53 // Search Getpost
54 $search_societe = GETPOST('search_societe', 'alpha');
55 $search_lineid = GETPOST('search_lineid', 'int');
56 $search_invoice = GETPOST('search_invoice', 'alpha');
57 $search_ref = GETPOST('search_ref', 'alpha');
58 $search_label = GETPOST('search_label', 'alpha');
59 $search_desc = GETPOST('search_desc', 'alpha');
60 $search_amount = GETPOST('search_amount', 'alpha');
61 $search_account = GETPOST('search_account', 'alpha');
62 $search_vat = GETPOST('search_vat', 'alpha');
63 $search_day = GETPOST("search_day", "int");
64 $search_month = GETPOST("search_month", "int");
65 $search_year = GETPOST("search_year", "int");
66 $search_country = GETPOST('search_country', 'alpha');
67 $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
68 
69 $btn_ventil = GETPOST('ventil', 'alpha');
70 
71 // Load variable for pagination
72 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
73 $sortfield = GETPOST('sortfield', 'aZ09comma');
74 $sortorder = GETPOST('sortorder', 'aZ09comma');
75 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
76 if (empty($page) || $page < 0) { $page = 0; }
77 $offset = $limit * $page;
78 $pageprev = $page - 1;
79 $pagenext = $page + 1;
80 if (!$sortfield)
81  $sortfield = "f.datef, f.ref, l.rowid";
82 if (!$sortorder) {
83  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
84  $sortorder = "DESC";
85  }
86 }
87 
88 // Security check
89 if ($user->socid > 0)
91 if (!$user->rights->accounting->bind->write)
93 
94 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
95 $hookmanager->initHooks(array('accountancysupplierlist'));
96 
97 $formaccounting = new FormAccounting($db);
98 $accounting = new AccountingAccount($db);
99 // TODO: we should need to check if result is a really exist accountaccount rowid.....
100 $aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT, 1);
101 $aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT, 1);
102 
103 $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
104 
105 
106 /*
107  * Actions
108  */
109 
110 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
111 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
112 
113 $parameters = array();
114 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
115 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116 
117 if (empty($reshook))
118 {
119  // Purge search criteria
120  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
121  {
122  $search_societe = '';
123  $search_lineid = '';
124  $search_ref = '';
125  $search_invoice = '';
126  $search_label = '';
127  $search_desc = '';
128  $search_amount = '';
129  $search_account = '';
130  $search_vat = '';
131  $search_day = '';
132  $search_month = '';
133  $search_year = '';
134  $search_country = '';
135  $search_tvaintra = '';
136  }
137 
138  // Mass actions
139  $objectclass = 'AccountingAccount';
140  $permissiontoread = $user->rights->accounting->read;
141  $permissiontodelete = $user->rights->accounting->delete;
142  $uploaddir = $conf->accounting->dir_output;
143  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
144 }
145 
146 
147 if ($massaction == 'ventil') {
148  $msg = '';
149 
150  //print '<div><span style="color:red">' . $langs->trans("Processing") . '...</span></div>';
151  if (!empty($mesCasesCochees)) {
152  $msg = '<div>'.$langs->trans("SelectedLines").': '.count($mesCasesCochees).'</div>';
153  $msg .= '<div class="detail">';
154  $cpt = 0;
155  $ok = 0;
156  $ko = 0;
157 
158  foreach ($mesCasesCochees as $maLigneCochee) {
159  $maLigneCourante = explode("_", $maLigneCochee);
160  $monId = $maLigneCourante[0];
161  $monCompte = GETPOST('codeventil'.$monId);
162 
163  if ($monCompte <= 0)
164  {
165  $msg .= '<div><span style="color:red">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NoAccountSelected").'</span></div>';
166  $ko++;
167  } else {
168  $sql = " UPDATE ".MAIN_DB_PREFIX."facture_fourn_det";
169  $sql .= " SET fk_code_ventilation = ".$monCompte;
170  $sql .= " WHERE rowid = ".$monId;
171 
172  $accountventilated = new AccountingAccount($db);
173  $accountventilated->fetch($monCompte, '', 1);
174 
175  dol_syslog('accountancy/supplier/list.php:: sql='.$sql, LOG_DEBUG);
176  if ($db->query($sql)) {
177  $msg .= '<div><span style="color:green">'.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
178  $ok++;
179  } else {
180  $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Lineofinvoice").' '.$monId.' - '.$langs->trans("NotVentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'<br/> <pre>'.$sql.'</pre></span></div>';
181  $ko++;
182  }
183  }
184 
185  $cpt++;
186  }
187  $msg .= '</div>';
188  $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
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.tva_tx as tva_tx_prod,";
216 $sql .= " p.accountancy_code_sell as code_sell, p.accountancy_code_sell_intra as code_sell_intra, p.accountancy_code_sell_export as code_sell_export,";
217 $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
218 $sql .= " p.tosell as status, p.tobuy as status_buy,";
219 $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
220 $sql .= " co.code as country_code, co.label as country_label,";
221 $sql .= " s.rowid as socid, s.nom as name, s.tva_intra, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur";
222 $parameters = array();
223 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
224 $sql .= $hookmanager->resPrint;
225 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
226 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
227 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
228 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
229 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
230 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
231 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON p.accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
232 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON p.accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
233 $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
234 $sql .= " AND l.product_type <= 2";
235 // Define begin binding date
236 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
237  $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
238 }
239 // Add search filter like
240 if ($search_societe) {
241  $sql .= natural_search('s.nom', $search_societe);
242 }
243 if ($search_lineid) {
244  $sql .= natural_search("l.rowid", $search_lineid, 1);
245 }
246 if (strlen(trim($search_invoice))) {
247  $sql .= natural_search("f.ref", $search_invoice);
248 }
249 if (strlen(trim($search_label))) {
250  $sql .= natural_search("f.libelle", $search_label);
251 }
252 if (strlen(trim($search_ref))) {
253  $sql .= natural_search("p.ref", $search_ref);
254 }
255 if (strlen(trim($search_desc))) {
256  $sql .= natural_search("l.description", $search_desc);
257 }
258 if (strlen(trim($search_amount))) {
259  $sql .= natural_search("l.total_ht", $search_amount, 1);
260 }
261 if (strlen(trim($search_account))) {
262  $sql .= natural_search("aa.account_number", $search_account);
263 }
264 if (strlen(trim($search_vat))) {
265  $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
266 }
267 $sql .= dolSqlDateFilter('f.datef', $search_day, $search_month, $search_year);
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("co.code", $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)) {
286  $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_SITUATION.")";
287 } else {
288  $sql .= " AND f.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_DEPOSIT.",".FactureFournisseur::TYPE_SITUATION.")";
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='.urlencode($contextpage);
325  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
326  if ($search_societe) $param .= '&search_societe='.urlencode($search_societe);
327  if ($search_lineid) $param .= '&search_lineid='.urlencode($search_lineid);
328  if ($search_day) $param .= '&search_day='.urlencode($search_day);
329  if ($search_month) $param .= '&search_month='.urlencode($search_month);
330  if ($search_year) $param .= '&search_year='.urlencode($search_year);
331  if ($search_invoice) $param .= '&search_invoice='.urlencode($search_invoice);
332  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
333  if ($search_label) $param .= '&search_label='.urlencode($search_label);
334  if ($search_desc) $param .= '&search_desc='.urlencode($search_desc);
335  if ($search_amount) $param .= '&search_amount='.urlencode($search_amount);
336  if ($search_vat) $param .= '&search_vat='.urlencode($search_vat);
337  if ($search_country) $param .= "&search_country=".urlencode($search_country);
338  if ($search_tvaintra) $param .= "&search_tvaintra=".urlencode($search_tvaintra);
339 
340  $arrayofmassactions = array(
341  'ventil'=>$langs->trans("Ventilate")
342  //'presend'=>$langs->trans("SendByMail"),
343  //'builddoc'=>$langs->trans("PDFMerge"),
344  );
345  //if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']='<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
346  //if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
347  $massactionbutton = $form->selectMassAction('ventil', $arrayofmassactions, 1);
348 
349  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'."\n";
350  print '<input type="hidden" name="action" value="ventil">';
351  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
352  print '<input type="hidden" name="token" value="'.newToken().'">';
353  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
354  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
355  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
356  print '<input type="hidden" name="page" value="'.$page.'">';
357 
358  print_barre_liste($langs->trans("InvoiceLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit);
359 
360  print '<span class="opacitymedium">'.$langs->trans("DescVentilTodoCustomer").'</span></br><br>';
361 
362  if ($msg) print $msg.'<br>';
363 
364  $moreforfilter = '';
365 
366  print '<div class="div-table-responsive">';
367  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
368 
369  // We add search filter
370  print '<tr class="liste_titre_filter">';
371  print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'"></td>';
372  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'"></td>';
373  //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
374  print '<td class="liste_titre center nowraponall minwidth100imp">';
375  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.$search_day.'">';
376  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month" value="'.$search_month.'">';
377  $formother->select_year($search_year, 'search_year', 1, 20, 5);
378  print '</td>';
379  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
380  print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
381  print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
382  print '<td class="liste_titre right"><input type="text" class="right flat maxwidth50" name="search_vat" placeholder="%" size="1" value="'.dol_escape_htmltag($search_vat).'"></td>';
383  print '<td class="liste_titre"><input type="text" class="flat maxwidth75imp" name="search_societe" value="'.dol_escape_htmltag($search_societe).'"></td>';
384  print '<td class="liste_titre">';
385  print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth125', 'code2', 1, 0, 1);
386  //print '<input type="text" class="flat maxwidth50" name="search_country" value="' . dol_escape_htmltag($search_country) . '">';
387  print '</td>';
388  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_tvaintra" value="'.dol_escape_htmltag($search_tvaintra).'"></td>';
389  print '<td class="liste_titre"></td>';
390  print '<td class="liste_titre"></td>';
391  print '<td class="center liste_titre">';
392  $searchpicto = $form->showFilterButtons();
393  print $searchpicto;
394  print '</td>';
395  print "</tr>\n";
396 
397  print '<tr class="liste_titre">';
398  print_liste_field_titre("LineId", $_SERVER["PHP_SELF"], "l.rowid", "", $param, '', $sortfield, $sortorder);
399  print_liste_field_titre("Invoice", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
400  //print_liste_field_titre("InvoiceLabel", $_SERVER["PHP_SELF"], "f.libelle", "", $param, '', $sortfield, $sortorder);
401  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
402  print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
403  //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
404  print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
405  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 ');
406  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
407  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
408  print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
409  print_liste_field_titre("VATIntraShort", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
410  print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', 'nowraponall ');
411  print_liste_field_titre("IntoAccount", '', '', '', '', '', '', '', 'center ');
412  $checkpicto = '';
413  if ($massactionbutton) $checkpicto = $form->showCheckAddButtons('checkforselect', 1);
414  print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
415  print "</tr>\n";
416 
417  $thirdpartystatic = new Societe($db);
418  $facturefourn_static = new FactureFournisseur($db);
419  $product_static = new Product($db);
420 
421  $isBuyerInEEC = isInEEC($mysoc);
422 
423  $accountingaccount_codetotid_cache = array();
424 
425  while ($i < min($num_lines, $limit)) {
426  $objp = $db->fetch_object($result);
427 
428  // product_type: 0 = service ? 1 = product
429  // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
430  // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
431  $objp->code_buy_l = '';
432  $objp->code_buy_p = '';
433 
434  $thirdpartystatic->id = $objp->socid;
435  $thirdpartystatic->name = $objp->name;
436  $thirdpartystatic->client = $objp->client;
437  $thirdpartystatic->fournisseur = $objp->fournisseur;
438  $thirdpartystatic->code_client = $objp->code_client;
439  $thirdpartystatic->code_compta_client = $objp->code_compta_client;
440  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
441  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
442  $thirdpartystatic->email = $objp->email;
443  $thirdpartystatic->country_code = $objp->country_code;
444 
445  $product_static->ref = $objp->product_ref;
446  $product_static->id = $objp->product_id;
447  $product_static->type = $objp->type;
448  $product_static->label = $objp->product_label;
449  $product_static->status = $objp->status;
450  $product_static->status_buy = $objp->status_buy;
451  $product_static->accountancy_code_sell = $objp->code_sell;
452  $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
453  $product_static->accountancy_code_sell_export = $objp->code_sell_export;
454  $product_static->accountancy_code_buy = $objp->code_buy;
455  $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
456  $product_static->accountancy_code_buy_export = $objp->code_buy_export;
457 
458  $facturefourn_static->ref = $objp->ref;
459  $facturefourn_static->id = $objp->facid;
460  $facturefourn_static->type = $objp->type;
461  $facturefourn_static->label = $objp->invoice_label;
462 
463  $code_buy_p_notset = '';
464  $objp->aarowid_suggest = ''; // Will be set later
465 
466  $isSellerInEEC = isInEEC($objp);
467 
468  $suggestedaccountingaccountbydefaultfor = '';
469  if ($objp->type_l == 1) {
470  if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
471  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : '');
472  $suggestedaccountingaccountbydefaultfor = '';
473  } else {
474  if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
475  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : '');
476  $suggestedaccountingaccountbydefaultfor = 'eec';
477  } else { // Foreign sale
478  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : '');
479  $suggestedaccountingaccountbydefaultfor = 'export';
480  }
481  }
482  } elseif ($objp->type_l == 0) {
483  if ($objp->country_code == $mysoc->country_code || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
484  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : '');
485  $suggestedaccountingaccountbydefaultfor = '';
486  } else {
487  if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
488  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : '');
489  $suggestedaccountingaccountbydefaultfor = 'eec';
490  } else {
491  $objp->code_buy_l = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : '');
492  $suggestedaccountingaccountbydefaultfor = 'export';
493  }
494  }
495  }
496  if ($objp->code_sell_l == -1) $objp->code_sell_l = '';
497 
498  // Search suggested account for product/service
499  $suggestedaccountingaccountfor = '';
500  if (($objp->country_code == $mysoc->country_code) || empty($objp->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country)
501  $objp->code_buy_p = $objp->code_buy;
502  $objp->aarowid_suggest = $objp->aarowid;
503  $suggestedaccountingaccountfor = '';
504  } else {
505  if ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
506  $objp->code_buy_p = $objp->code_buy_intra;
507  $objp->aarowid_suggest = $objp->aarowid_intra;
508  $suggestedaccountingaccountfor = 'eec';
509  } else { // Foreign sale
510  $objp->code_buy_p = $objp->code_buy_export;
511  $objp->aarowid_suggest = $objp->aarowid_export;
512  $suggestedaccountingaccountfor = 'export';
513  }
514  }
515 
516  if (!empty($objp->code_buy_p)) {
517  // Value was defined previously
518  } else {
519  $code_buy_p_notset = 'color:orange';
520  }
521  if (empty($objp->code_buy_l) && empty($objp->code_buy_p)) $code_buy_p_notset = 'color:red';
522 
523  // $objp->code_buy_l is now default code of product/service
524  // $objp->code_buy_p is now code of product/service
525 
526  print '<tr class="oddeven">';
527 
528  // Line id
529  print '<td>'.$objp->rowid.'</td>';
530 
531  // Ref Invoice
532  print '<td class="nowraponall">'.$facturefourn_static->getNomUrl(1).'</td>';
533 
534  /*print '<td class="tdoverflowonsmartphone">';
535  print $objp->invoice_label;
536  print '</td>';
537  */
538 
539  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
540 
541  // Ref Product
542  print '<td class="tdoverflowmax150">';
543  if ($product_static->id > 0)
544  print $product_static->getNomUrl(1);
545  if ($objp->product_label) print '<br><span class="opacitymedium small">'.$objp->product_label.'</span>';
546  print '</td>';
547 
548  // Description
549  print '<td class="tdoverflowonsmartphone small">';
550  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
551  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
552  print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
553  print '</td>';
554 
555  print '<td class="nowrap right">';
556  print price($objp->total_ht);
557  print '</td>';
558 
559  // Vat rate
560  if ($objp->vat_tx_l != $objp->vat_tx_p)
561  $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
562  print '<td style="'.$code_vat_differ.'" class="right">';
563  print vatrate($objp->tva_tx_line.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : ''));
564  print '</td>';
565 
566  // Thirdparty
567  print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'supplier').'</td>';
568 
569  // Country
570  print '<td>';
571  $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
572  print $labelcountry;
573  print '</td>';
574 
575  // VAT Num
576  print '<td>'.$objp->tva_intra.'</td>';
577 
578  // Found accounts
579  print '<td>';
580  $s = '<span class="small">'.(($objp->type_l == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': </span>';
581  $shelp = '';
582  if ($suggestedaccountingaccountbydefaultfor == 'eec') $shelp .= $langs->trans("SaleEEC");
583  elseif ($suggestedaccountingaccountbydefaultfor == 'export') $shelp .= $langs->trans("SaleExport");
584  $s .= ($objp->code_buy_l > 0 ? length_accountg($objp->code_buy_l) : '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>');
585  print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
586  if ($objp->product_id > 0)
587  {
588  print '<br>';
589  $s = '<span class="small">'.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': </span>';
590  $shelp = '';
591  if ($suggestedaccountingaccountfor == 'eec') $shelp = $langs->trans("SaleEEC");
592  elseif ($suggestedaccountingaccountfor == 'export') $shelp = $langs->trans("SaleExport");
593  $s .= (empty($objp->code_buy_p) ? '<span style="'.$code_buy_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($objp->code_buy_p));
594  print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
595  }
596  print '</td>';
597 
598  // Suggested accounting account
599  print '<td>';
600  $suggestedid = $objp->aarowid_suggest;
601  if (empty($suggestedid) && empty($objp->code_buy_p) && !empty($objp->code_buy_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC))
602  {
603  if (empty($accountingaccount_codetotid_cache[$objp->code_buy_l]))
604  {
605  $tmpaccount = new AccountingAccount($db);
606  $tmpaccount->fetch(0, $objp->code_buy_l, 1);
607  if ($tmpaccount->id > 0) {
608  $suggestedid = $tmpaccount->id;
609  }
610  $accountingaccount_codetotid_cache[$objp->code_buy_l] = $tmpaccount->id;
611  } else {
612  $suggestedid = $accountingaccount_codetotid_cache[$objp->code_buy_l];
613  }
614  }
615  print $formaccounting->select_account($suggestedid, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
616  print '</td>';
617 
618  // Column with checkbox
619  print '<td class="center">';
620  $ischecked = $objp->aarowid_suggest;
621  print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="'.$objp->rowid."_".$i.'"'.($ischecked ? "checked" : "").'/>';
622  print '</td>';
623 
624  print '</tr>';
625  $i++;
626  }
627 
628  print '</table>';
629  print "</div>";
630 
631  print '</form>';
632 } else {
633  print $db->error();
634 }
635 if ($db->type == 'mysqli') {
636  $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
637 }
638 
639 // Add code to auto check the box when we select an account
640 print '<script type="text/javascript" language="javascript">
641 jQuery(document).ready(function() {
642  jQuery(".codeventil").change(function() {
643  var s=$(this).attr("id").replace("codeventil", "")
644  console.log(s+" "+$(this).val());
645  if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
646  else jQuery(".checkforselect"+s).prop("checked", true);
647  });
648 });
649 </script>';
650 
651 // End of page
652 llxFooter();
653 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
const TYPE_DEPOSIT
Deposit invoice.
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
Class to manage products or services.
getCountriesInEEC()
Return list of countries that are inside the EEC (European Economic Community) Note: Try to keep this...
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage suppliers invoices.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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...
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0)
Generate a SQL string to make a filter into a range (for second of date until last second of date) ...
Definition: date.lib.php:281
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...
print $_SERVER["PHP_SELF"]
Edit parameters.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
const TYPE_CREDIT_NOTE
Credit note invoice.
print
Draft customers invoices.
Definition: index.php:89
Class to manage generation of HTML components for accounting management.
const TYPE_SITUATION
Situation invoice.
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.
Class to manage accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)