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>
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.'/compta/facture/class/facture.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39 
40 // Load translation files required by the page
41 $langs->loadLangs(array("bills", "companies", "compta", "accountancy", "other", "productbatch", "products"));
42 
43 $action = GETPOST('action', 'aZ09');
44 $massaction = GETPOST('massaction', 'alpha');
45 $show_files = GETPOST('show_files', 'int');
46 $confirm = GETPOST('confirm', 'alpha');
47 $toselect = GETPOST('toselect', 'array');
48 
49 // Select Box
50 $mesCasesCochees = GETPOST('toselect', 'array');
51 
52 // Search Getpost
53 $search_societe = GETPOST('search_societe', 'alpha');
54 $search_lineid = GETPOST('search_lineid', 'int');
55 $search_ref = GETPOST('search_ref', 'alpha');
56 $search_invoice = GETPOST('search_invoice', 'alpha');
57 $search_label = GETPOST('search_label', 'alpha');
58 $search_desc = GETPOST('search_desc', 'alpha');
59 $search_amount = GETPOST('search_amount', 'alpha');
60 $search_account = GETPOST('search_account', 'alpha');
61 $search_vat = GETPOST('search_vat', 'alpha');
62 $search_day = GETPOST("search_day", "int");
63 $search_month = GETPOST("search_month", "int");
64 $search_year = GETPOST("search_year", "int");
65 $search_country = GETPOST('search_country', 'alpha');
66 $search_tvaintra = GETPOST('search_tvaintra', 'alpha');
67 
68 $btn_ventil = GETPOST('ventil', 'alpha');
69 
70 // Load variable for pagination
71 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
72 $sortfield = GETPOST('sortfield', 'aZ09comma');
73 $sortorder = GETPOST('sortorder', 'aZ09comma');
74 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
75 if (empty($page) || $page < 0) { $page = 0; }
76 $offset = $limit * $page;
77 $pageprev = $page - 1;
78 $pagenext = $page + 1;
79 if (!$sortfield)
80  $sortfield = "f.datef, f.ref, l.rowid";
81 if (!$sortorder) {
82  if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO > 0) {
83  $sortorder = "DESC";
84  }
85 }
86 
87 // Security check
88 if ($user->socid > 0)
90 if (!$user->rights->accounting->bind->write)
92 
93 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
94 $hookmanager->initHooks(array('accountancycustomerlist'));
95 
96 $formaccounting = new FormAccounting($db);
97 
98 $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
99 
100 
101 /*
102  * Actions
103  */
104 
105 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
106 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
107 
108 $parameters = array();
109 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
110 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
111 
112 if (empty($reshook))
113 {
114  // Purge search criteria
115  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
116  {
117  $search_societe = '';
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  $permissiontoread = $user->rights->accounting->read;
136  $permissiontodelete = $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><span style="color:red">' . $langs->trans("Processing") . '...</span></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><span style="color:red">'.$langs->trans("Lineofinvoice", $monId).' - '.$langs->trans("NoAccountSelected").'</span></div>';
161  $ko++;
162  } else {
163  $sql = " UPDATE ".MAIN_DB_PREFIX."facturedet";
164  $sql .= " SET fk_code_ventilation = ".((int) $monCompte);
165  $sql .= " WHERE rowid = ".((int) $monId);
166 
167  $accountventilated = new AccountingAccount($db);
168  $accountventilated->fetch($monCompte, '', 1);
169 
170  dol_syslog("accountancy/customer/list.php sql=".$sql, LOG_DEBUG);
171  if ($db->query($sql)) {
172  $msg .= '<div><span style="color:green">'.$langs->trans("Lineofinvoice", $monId).' - '.$langs->trans("VentilatedinAccount").' : '.length_accountg($accountventilated->account_number).'</span></div>';
173  $ok++;
174  } else {
175  $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>';
176  $ko++;
177  }
178  }
179 
180  $cpt++;
181  }
182  $msg .= '</div>';
183  $msg .= '<div>'.$langs->trans("EndProcessing").'</div>';
184  }
185 }
186 
187 
188 
189 /*
190  * View
191  */
192 
193 $form = new Form($db);
194 $formother = new FormOther($db);
195 
196 llxHeader('', $langs->trans("Ventilation"));
197 
198 if (empty($chartaccountcode))
199 {
200  print $langs->trans("ErrorChartOfAccountSystemNotSelected");
201  // End of page
202  llxFooter();
203  $db->close();
204  exit;
205 }
206 
207 // Customer Invoice lines
208 $sql = "SELECT f.rowid as facid, f.ref as ref, f.datef, f.type as ftype,";
209 $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,";
210 $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,";
211 $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,";
212 $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,";
213 $sql .= " p.tosell as status, p.tobuy as status_buy,";
214 $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export,";
215 $sql .= " co.code as country_code, co.label as country_label,";
216 $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";
217 $parameters = array();
218 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
219 $sql .= $hookmanager->resPrint;
220 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
221 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
222 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
223 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture";
224 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
225 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON p.accountancy_code_sell = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
226 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON p.accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
227 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON p.accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
228 $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
229 $sql .= " AND l.product_type <= 2";
230 // Define begin binding date
231 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
232  $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
233 }
234 // Add search filter like
235 if ($search_societe) {
236  $sql .= natural_search('s.nom', $search_societe);
237 }
238 if ($search_lineid) {
239  $sql .= natural_search("l.rowid", $search_lineid, 1);
240 }
241 if (strlen(trim($search_invoice))) {
242  $sql .= natural_search("f.ref", $search_invoice);
243 }
244 if (strlen(trim($search_ref))) {
245  $sql .= natural_search("p.ref", $search_ref);
246 }
247 if (strlen(trim($search_label))) {
248  $sql .= natural_search("p.label", $search_label);
249 }
250 if (strlen(trim($search_desc))) {
251  $sql .= natural_search("l.description", $search_desc);
252 }
253 if (strlen(trim($search_amount))) {
254  $sql .= natural_search("l.total_ht", $search_amount, 1);
255 }
256 if (strlen(trim($search_account))) {
257  $sql .= natural_search("aa.account_number", $search_account);
258 }
259 if (strlen(trim($search_vat))) {
260  $sql .= natural_search("l.tva_tx", price2num($search_vat), 1);
261 }
262 $sql .= dolSqlDateFilter('f.datef', $search_day, $search_month, $search_year);
263 if (strlen(trim($search_country))) {
264  $arrayofcode = getCountriesInEEC();
265  $country_code_in_EEC = $country_code_in_EEC_without_me = '';
266  foreach ($arrayofcode as $key => $value)
267  {
268  $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
269  if ($value != $mysoc->country_code) $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
270  }
271  if ($search_country == 'special_allnotme') $sql .= " AND co.code <> '".$db->escape($mysoc->country_code)."'";
272  elseif ($search_country == 'special_eec') $sql .= " AND co.code IN (".$country_code_in_EEC.")";
273  elseif ($search_country == 'special_eecnotme') $sql .= " AND co.code IN (".$country_code_in_EEC_without_me.")";
274  elseif ($search_country == 'special_noteec') $sql .= " AND co.code NOT IN (".$country_code_in_EEC.")";
275  else $sql .= natural_search("co.code", $search_country);
276 }
277 if (strlen(trim($search_tvaintra))) {
278  $sql .= natural_search("s.tva_intra", $search_tvaintra);
279 }
280 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
281  $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_SITUATION.")";
282 } else {
283  $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.",".Facture::TYPE_REPLACEMENT.",".Facture::TYPE_CREDIT_NOTE.",".Facture::TYPE_DEPOSIT.",".Facture::TYPE_SITUATION.")";
284 }
285 $sql .= " AND f.entity IN (".getEntity('invoice', 0).")"; // We don't share object for accountancy
286 
287 // Add where from hooks
288 $parameters = array();
289 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
290 $sql .= $hookmanager->resPrint;
291 
292 $sql .= $db->order($sortfield, $sortorder);
293 
294 // Count total nb of records
295 $nbtotalofrecords = '';
296 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
297 {
298  $result = $db->query($sql);
299  $nbtotalofrecords = $db->num_rows($result);
300  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
301  {
302  $page = 0;
303  $offset = 0;
304  }
305 }
306 
307 $sql .= $db->plimit($limit + 1, $offset);
308 
309 dol_syslog("accountancy/customer/list.php", LOG_DEBUG);
310 // MAX_JOIN_SIZE can be very low (ex: 300000) on some limited configurations (ex: https://www.online.net/fr/hosting/online-perso)
311 // This big SELECT command may exceed the MAX_JOIN_SIZE limit => Therefore we use SQL_BIG_SELECTS=1 to disable the MAX_JOIN_SIZE security
312 if ($db->type == 'mysqli') {
313  $db->query("SET SQL_BIG_SELECTS=1");
314 }
315 $result = $db->query($sql);
316 if ($result) {
317  $num_lines = $db->num_rows($result);
318  $i = 0;
319 
320  $arrayofselected = is_array($toselect) ? $toselect : array();
321 
322  $param = '';
323  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
324  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
325  if ($search_societe) $param .= '&search_societe='.urlencode($search_societe);
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']='<span class="fa fa-trash paddingrightonly"></span>'.$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="'.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 '<span class="opacitymedium">'.$langs->trans("DescVentilTodoCustomer").'</span></br><br>';
359 
360  if ($msg) print $msg.'<br>';
361 
362  $moreforfilter = '';
363 
364  print '<div class="div-table-responsive">';
365  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
366 
367  // We add search filter
368  print '<tr class="liste_titre_filter">';
369  print '<td class="liste_titre"><input type="text" class="flat maxwidth25" name="search_lineid" value="'.dol_escape_htmltag($search_lineid).'"></td>';
370  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_invoice" value="'.dol_escape_htmltag($search_invoice).'"></td>';
371  print '<td class="liste_titre center nowraponall minwidth100imp">';
372  if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) {
373  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_day" value="'.$search_day.'">';
374  }
375  print '<input class="flat valignmiddle maxwidth25" type="text" maxlength="2" name="search_month" value="'.$search_month.'">';
376  $formother->select_year($search_year, 'search_year', 1, 20, 5);
377  print '</td>';
378  print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
379  //print '<td class="liste_titre"><input type="text" class="flat maxwidth50" name="search_label" value="' . dol_escape_htmltag($search_label) . '"></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="flat maxwidth50 right" name="search_amount" value="'.dol_escape_htmltag($search_amount).'"></td>';
382  print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" 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>';
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("Date", $_SERVER["PHP_SELF"], "f.datef, f.ref, l.rowid", "", $param, '', $sortfield, $sortorder, 'center ');
401  print_liste_field_titre("ProductRef", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
402  //print_liste_field_titre("ProductLabel", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
403  print_liste_field_titre("ProductDescription", $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
404  print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "l.total_ht", "", $param, '', $sortfield, $sortorder, 'right maxwidth50 ');
405  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
406  print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
407  print_liste_field_titre("Country", $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
408  print_liste_field_titre("VATIntraShort", $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
409  print_liste_field_titre("AccountAccountingSuggest", '', '', '', '', '', '', '', 'nowraponall ');
410  print_liste_field_titre("IntoAccount", '', '', '', '', '', '', '', 'center ');
411  $checkpicto = '';
412  if ($massactionbutton) $checkpicto = $form->showCheckAddButtons('checkforselect', 1);
413  print_liste_field_titre($checkpicto, '', '', '', '', '', '', '', 'center ');
414  print "</tr>\n";
415 
416  $thirdpartystatic = new Societe($db);
417  $facture_static = new Facture($db);
418  $product_static = new Product($db);
419 
420  $isSellerInEEC = isInEEC($mysoc);
421 
422  $accountingaccount_codetotid_cache = array();
423 
424  while ($i < min($num_lines, $limit)) {
425  $objp = $db->fetch_object($result);
426 
427  $objp->code_sell_l = '';
428  $objp->code_sell_p = '';
429 
430  $thirdpartystatic->id = $objp->socid;
431  $thirdpartystatic->name = $objp->name;
432  $thirdpartystatic->client = $objp->client;
433  $thirdpartystatic->fournisseur = $objp->fournisseur;
434  $thirdpartystatic->code_client = $objp->code_client;
435  $thirdpartystatic->code_compta_client = $objp->code_compta_client;
436  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
437  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
438  $thirdpartystatic->email = $objp->email;
439  $thirdpartystatic->country_code = $objp->country_code;
440 
441  $product_static->ref = $objp->product_ref;
442  $product_static->id = $objp->product_id;
443  $product_static->type = $objp->type;
444  $product_static->label = $objp->product_label;
445  $product_static->status = $objp->status;
446  $product_static->status_buy = $objp->status_buy;
447  $product_static->accountancy_code_sell = $objp->code_sell;
448  $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
449  $product_static->accountancy_code_sell_export = $objp->code_sell_export;
450  $product_static->accountancy_code_buy = $objp->code_buy;
451  $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
452  $product_static->accountancy_code_buy_export = $objp->code_buy_export;
453 
454  $facture_static->ref = $objp->ref;
455  $facture_static->id = $objp->facid;
456  $facture_static->type = $objp->ftype;
457 
458  $code_sell_p_notset = '';
459  $objp->aarowid_suggest = ''; // Will be set later
460 
461  $isBuyerInEEC = isInEEC($objp);
462 
463  // Search suggested default account for product/service
464  $suggestedaccountingaccountbydefaultfor = '';
465  if ($objp->type_l == 1) {
466  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)
467  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
468  $suggestedaccountingaccountbydefaultfor = '';
469  } else {
470  if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with a VAT
471  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
472  $suggestedaccountingaccountbydefaultfor = 'eecwithvat';
473  } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
474  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : '');
475  $suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
476  } elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
477  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : '');
478  $suggestedaccountingaccountbydefaultfor = 'eec';
479  } else { // Foreign sale
480  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : '');
481  $suggestedaccountingaccountbydefaultfor = 'export';
482  }
483  }
484  } elseif ($objp->type_l == 0) {
485  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)
486  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
487  $suggestedaccountingaccountbydefaultfor = '';
488  } else {
489  if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with a VAT
490  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
491  $suggestedaccountingaccountbydefaultfor = 'eecwithvat';
492  } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
493  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : '');
494  $suggestedaccountingaccountbydefaultfor = 'eecwithoutvatnumber';
495  } elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
496  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : '');
497  $suggestedaccountingaccountbydefaultfor = 'eec';
498  } else {
499  $objp->code_sell_l = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : '');
500  $suggestedaccountingaccountbydefaultfor = 'export';
501  }
502  }
503  }
504  if ($objp->code_sell_l == -1) $objp->code_sell_l = '';
505 
506  // Search suggested account for product/service (similar code exists in page index.php to make automatic binding)
507  $suggestedaccountingaccountfor = '';
508  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)
509  $objp->code_sell_p = $objp->code_sell;
510  $objp->aarowid_suggest = $objp->aarowid;
511  $suggestedaccountingaccountfor = '';
512  } else {
513  if ($isSellerInEEC && $isBuyerInEEC && $objp->tva_tx_line != 0) { // European intravat sale, but with VAT
514  $objp->code_sell_p = $objp->code_sell;
515  $objp->aarowid_suggest = $objp->aarowid;
516  $suggestedaccountingaccountfor = 'eecwithvat';
517  } elseif ($isSellerInEEC && $isBuyerInEEC && empty($objp->tva_intra)) { // European intravat sale, without VAT intra community number
518  $objp->code_sell_p = $objp->code_sell;
519  $objp->aarowid_suggest = $objp->aarowid; // There is a doubt for this case. Is it an error on vat or we just forgot to fill vat number ?
520  $suggestedaccountingaccountfor = 'eecwithoutvatnumber';
521  } elseif ($isSellerInEEC && $isBuyerInEEC) { // European intravat sale
522  $objp->code_sell_p = $objp->code_sell_intra;
523  $objp->aarowid_suggest = $objp->aarowid_intra;
524  $suggestedaccountingaccountfor = 'eec';
525  } else { // Foreign sale
526  $objp->code_sell_p = $objp->code_sell_export;
527  $objp->aarowid_suggest = $objp->aarowid_export;
528  $suggestedaccountingaccountfor = 'export';
529  }
530  }
531 
532  // Manage Deposit
533  if ($objp->description == "(DEPOSIT)") {
534  $accountdeposittoventilated = new AccountingAccount($db);
535  $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1);
536  $objp->code_sell_l = $accountdeposittoventilated->ref;
537  $objp->aarowid_suggest = $accountdeposittoventilated->rowid;
538  }
539 
540  if (!empty($objp->code_sell_p)) {
541  // Value was defined previously
542  } else {
543  $code_sell_p_notset = 'color:orange';
544  }
545  if (empty($objp->code_sell_l) && empty($objp->code_sell_p)) $code_sell_p_notset = 'color:red';
546  if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber' && empty($code_sell_p_notset)) $code_sell_p_notset = 'color:orange';
547 
548  // $objp->code_sell_l is now default code of product/service
549  // $objp->code_sell_p is now code of product/service
550 
551  print '<tr class="oddeven">';
552 
553  // Line id
554  print '<td>'.$objp->rowid.'</td>';
555 
556  // Ref Invoice
557  print '<td class="nowraponall">'.$facture_static->getNomUrl(1).'</td>';
558 
559  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day').'</td>';
560 
561  // Ref Product
562  print '<td class="tdoverflowmax150">';
563  if ($product_static->id > 0) {
564  print $product_static->getNomUrl(1);
565  }
566  if ($objp->product_label) print '<br><span class="opacitymedium small">'.$objp->product_label.'</span>';
567  print '</td>';
568 
569  print '<td class="tdoverflowonsmartphone small">';
570  $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
571  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
572  print $form->textwithtooltip(dol_trunc($text, $trunclength), $objp->description);
573  print '</td>';
574 
575  print '<td class="nowrap right">';
576  print price($objp->total_ht);
577  print '</td>';
578 
579  // Vat rate
580  if ($objp->vat_tx_l != $objp->vat_tx_p)
581  $code_vat_differ = 'font-weight:bold; text-decoration:blink; color:red';
582  print '<td style="'.$code_vat_differ.'" class="right">';
583  print vatrate($objp->tva_tx_line.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : ''));
584  print '</td>';
585 
586  // Thirdparty
587  print '<td class="tdoverflowmax100">'.$thirdpartystatic->getNomUrl(1, 'customer').'</td>';
588 
589  // Country
590  print '<td>';
591  $labelcountry = ($objp->country_code && ($langs->trans("Country".$objp->country_code) != "Country".$objp->country_code)) ? $langs->trans("Country".$objp->country_code) : $objp->country_label;
592  print $labelcountry;
593  print '</td>';
594 
595  print '<td>'.$objp->tva_intra.'</td>';
596 
597  // Found accounts
598  print '<td>';
599  $s = '<span class="small">'.(($objp->type_l == 1) ? $langs->trans("DefaultForService") : $langs->trans("DefaultForProduct")).': </span>';
600  $shelp = '';
601  if ($suggestedaccountingaccountbydefaultfor == 'eec') $shelp .= $langs->trans("SaleEEC");
602  elseif ($suggestedaccountingaccountbydefaultfor == 'export') $shelp .= $langs->trans("SaleExport");
603  $s .= ($objp->code_sell_l > 0 ? length_accountg($objp->code_sell_l) : '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>');
604  print $form->textwithpicto($s, $shelp, 1, 'help', '', 0, 2, '', 1);
605  if ($objp->product_id > 0)
606  {
607  print '<br>';
608  $s = '<span class="small">'.(($objp->type_l == 1) ? $langs->trans("ThisService") : $langs->trans("ThisProduct")).': </span>';
609  $shelp = ''; $ttype = 'help';
610  if ($suggestedaccountingaccountfor == 'eec') $shelp = $langs->trans("SaleEEC");
611  elseif ($suggestedaccountingaccountfor == 'eecwithvat') $shelp = $langs->trans("SaleEECWithVAT");
612  elseif ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') {
613  $shelp = $langs->trans("SaleEECWithoutVATNumber");
614  $ttype = 'warning';
615  }
616  elseif ($suggestedaccountingaccountfor == 'export') $shelp = $langs->trans("SaleExport");
617  $s .= (empty($objp->code_sell_p) ? '<span style="'.$code_sell_p_notset.'">'.$langs->trans("NotDefined").'</span>' : length_accountg($objp->code_sell_p));
618  print $form->textwithpicto($s, $shelp, 1, $ttype, '', 0, 2, '', 1);
619  }
620  print '</td>';
621 
622  // Suggested accounting account
623  // $objp->code_sell_l = default (it takes the country into consideration), $objp->code_sell_p is value for product (it takes the country into consideration too)
624  print '<td>';
625  $suggestedid = $objp->aarowid_suggest;
626  /*var_dump($suggestedid);
627  var_dump($objp->code_sell_p);
628  var_dump($objp->code_sell_l);*/
629  if (empty($suggestedid) && empty($objp->code_sell_p) && !empty($objp->code_sell_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC))
630  {
631  if (empty($accountingaccount_codetotid_cache[$objp->code_sell_l]))
632  {
633  $tmpaccount = new AccountingAccount($db);
634  $tmpaccount->fetch(0, $objp->code_sell_l, 1);
635  if ($tmpaccount->id > 0) {
636  $suggestedid = $tmpaccount->id;
637  }
638  $accountingaccount_codetotid_cache[$objp->code_sell_l] = $tmpaccount->id;
639  } else {
640  $suggestedid = $accountingaccount_codetotid_cache[$objp->code_sell_l];
641  }
642  }
643  print $formaccounting->select_account($suggestedid, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone');
644  print '</td>';
645 
646  // Column with checkbox
647  print '<td class="center">';
648  //var_dump($objp->aarowid);var_dump($objp->aarowid_intra);var_dump($objp->aarowid_export);var_dump($objp->aarowid_suggest);
649  $ischecked = $objp->aarowid_suggest;
650  if ($suggestedaccountingaccountfor == 'eecwithoutvatnumber') $ischecked = 0;
651  print '<input type="checkbox" class="flat checkforselect checkforselect'.$objp->rowid.'" name="toselect[]" value="'.$objp->rowid."_".$i.'"'.($ischecked ? "checked" : "").'/>';
652  print '</td>';
653 
654  print '</tr>';
655  $i++;
656  }
657  print '</table>';
658  print "</div>";
659 
660  print '</form>';
661 } else {
662  print $db->error();
663 }
664 if ($db->type == 'mysqli') {
665  $db->query("SET SQL_BIG_SELECTS=0"); // Enable MAX_JOIN_SIZE limitation
666 }
667 
668 // Add code to auto check the box when we select an account
669 print '<script type="text/javascript" language="javascript">
670 jQuery(document).ready(function() {
671  jQuery(".codeventil").change(function() {
672  var s=$(this).attr("id").replace("codeventil", "")
673  console.log(s+" "+$(this).val());
674  if ($(this).val() == -1) jQuery(".checkforselect"+s).prop("checked", false);
675  else jQuery(".checkforselect"+s).prop("checked", true);
676  });
677 });
678 </script>';
679 
680 // End of page
681 llxFooter();
682 $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.
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.
const TYPE_SITUATION
Situation invoice.
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...
const TYPE_CREDIT_NOTE
Credit note invoice.
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.
const TYPE_DEPOSIT
Deposit invoice.
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.
print
Draft customers invoices.
Definition: index.php:89
Class to manage generation of HTML components for accounting management.
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.
Class to manage invoices.
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)