dolibarr  16.0.5
productaccount.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
7  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
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/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
37 if (isModEnabled('categorie')) {
38  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
39 }
40 
41 // Load translation files required by the page
42 $langs->loadLangs(array("companies", "compta", "accountancy", "products"));
43 
44 // Security check
45 if (!isModEnabled('accounting')) {
47 }
48 if (empty($user->rights->accounting->bind->write)) {
50 }
51 
52 // search & action GETPOST
53 $action = GETPOST('action', 'aZ09');
54 $massaction = GETPOST('massaction', 'alpha');
55 $codeventil_buy = GETPOST('codeventil_buy', 'array');
56 $codeventil_sell = GETPOST('codeventil_sell', 'array');
57 $chk_prod = GETPOST('chk_prod', 'array');
58 $default_account = GETPOST('default_account', 'int');
59 $confirm = GETPOST('confirm', 'alpha');
60 $account_number_buy = GETPOST('account_number_buy');
61 $account_number_sell = GETPOST('account_number_sell');
62 $changeaccount = GETPOST('changeaccount', 'array');
63 $changeaccount_buy = GETPOST('changeaccount_buy', 'array');
64 $changeaccount_sell = GETPOST('changeaccount_sell', 'array');
65 $searchCategoryProductOperator = (GETPOST('search_category_product_operator', 'int') ? GETPOST('search_category_product_operator', 'int') : 0);
66 $searchCategoryProductList = GETPOST('search_category_product_list', 'array');
67 $search_ref = GETPOST('search_ref', 'alpha');
68 $search_label = GETPOST('search_label', 'alpha');
69 $search_desc = GETPOST('search_desc', 'alpha');
70 $search_vat = GETPOST('search_vat', 'alpha');
71 $search_current_account = GETPOST('search_current_account', 'alpha');
72 $search_current_account_valid = GETPOST('search_current_account_valid', 'alpha');
73 if ($search_current_account_valid == '') {
74  $search_current_account_valid = 'withoutvalidaccount';
75 }
76 $search_onsell = GETPOST('search_onsell', 'alpha');
77 $search_onpurchase = GETPOST('search_onpurchase', 'alpha');
78 
79 $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha');
80 $btn_changetype = GETPOST('changetype', 'alpha');
81 $optioncss = GETPOST('optioncss', 'alpha');
82 
83 if (empty($accounting_product_mode)) {
84  $accounting_product_mode = 'ACCOUNTANCY_SELL';
85 }
86 
87 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION);
88 $sortfield = GETPOST('sortfield', 'aZ09comma');
89 $sortorder = GETPOST('sortorder', 'aZ09comma');
90 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
91 if (empty($page) || $page == -1) {
92  $page = 0;
93 } // If $page is not defined, or '' or -1
94 $offset = $limit * $page;
95 $pageprev = $page - 1;
96 $pagenext = $page + 1;
97 if (!$sortfield) {
98  $sortfield = "p.ref";
99 }
100 if (!$sortorder) {
101  $sortorder = "ASC";
102 }
103 
104 if (empty($action)) {
105  $action = 'list';
106 }
107 
108 $arrayfields = array();
109 
110 $accounting_product_modes = array(
111  'ACCOUNTANCY_SELL',
112  'ACCOUNTANCY_SELL_INTRA',
113  'ACCOUNTANCY_SELL_EXPORT',
114  'ACCOUNTANCY_BUY',
115  'ACCOUNTANCY_BUY_INTRA',
116  'ACCOUNTANCY_BUY_EXPORT'
117 );
118 
119 if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
120  $accountancy_field_name = "accountancy_code_buy";
121 } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
122  $accountancy_field_name = "accountancy_code_buy_intra";
123 } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
124  $accountancy_field_name = "accountancy_code_buy_export";
125 } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
126  $accountancy_field_name = "accountancy_code_sell";
127 } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
128  $accountancy_field_name = "accountancy_code_sell_intra";
129 } else { // $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT'
130  $accountancy_field_name = "accountancy_code_sell_export";
131 }
132 
133 /*
134  * Actions
135  */
136 
137 if (GETPOST('cancel', 'alpha')) {
138  $action = 'list'; $massaction = '';
139 }
140 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
141  $massaction = '';
142 }
143 
144 $parameters = array();
145 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
146 if ($reshook < 0) {
147  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
148 }
149 
150 // Purge search criteria
151 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
152  $searchCategoryProductOperator = 0;
153  $searchCategoryProductList = array();
154  $search_ref = '';
155  $search_label = '';
156  $search_desc = '';
157  $search_vat = '';
158  $search_onsell = '';
159  $search_onpurchase = '';
160  $search_current_account = '';
161  $search_current_account_valid = '-1';
162 }
163 
164 // Sales or Purchase mode ?
165 if ($action == 'update') {
166  if (!empty($btn_changetype)) {
167  $error = 0;
168 
169  if (in_array($accounting_product_mode, $accounting_product_modes)) {
170  if (!dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) {
171  $error++;
172  }
173  } else {
174  $error++;
175  }
176  }
177 
178  if (!empty($chk_prod) && $massaction === 'changeaccount') {
179  //$msg = '<div><span class="accountingprocessing">' . $langs->trans("Processing") . '...</span></div>';
180  if (!empty($chk_prod) && in_array($accounting_product_mode, $accounting_product_modes)) {
181  $accounting = new AccountingAccount($db);
182 
183  //$msg .= '<div><span class="accountingprocessing">' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '</span></div>';
184  $arrayofdifferentselectedvalues = array();
185 
186  $cpt = 0; $ok = 0; $ko = 0;
187  foreach ($chk_prod as $productid) {
188  $accounting_account_id = GETPOST('codeventil_'.$productid);
189 
190  $result = 0;
191  if ($accounting_account_id > 0) {
192  $arrayofdifferentselectedvalues[$accounting_account_id] = $accounting_account_id;
193  $result = $accounting->fetch($accounting_account_id, null, 1);
194  }
195  if ($result <= 0) {
196  // setEventMessages(null, $accounting->errors, 'errors');
197  $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Product").' '.$productid.' '.$langs->trans("NotVentilatedinAccount").' : id='.$accounting_account_id.'<br> <pre>'.$sql.'</pre></span></div>';
198  $ko++;
199  } else {
200  $sql = '';
201  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
202  $sql_exists = "SELECT rowid FROM " . MAIN_DB_PREFIX . "product_perentity";
203  $sql_exists .= " WHERE fk_product = " . ((int) $productid) . " AND entity = " . ((int) $conf->entity);
204  $resql_exists = $db->query($sql_exists);
205  if (!$resql_exists) {
206  $msg .= '<div><span style="color:red">'.$langs->trans("ErrorDB").' : '.$langs->trans("Product").' '.$productid.' '.$langs->trans("NotVentilatedinAccount").' : id='.$accounting_account_id.'<br> <pre>'.$resql_exists.'</pre></span></div>';
207  $ko++;
208  } else {
209  $nb_exists = $db->num_rows($resql_exists);
210  if ($nb_exists <= 0) {
211  // insert
212  $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity (fk_product, entity, " . $db->escape($accountancy_field_name) . ")";
213  $sql .= " VALUES (" . ((int) $productid) . ", " . ((int) $conf->entity) . ", '" . $db->escape($accounting->account_number) . "')";
214  } else {
215  $obj_exists = $db->fetch_object($resql_exists);
216  // update
217  $sql = "UPDATE " . MAIN_DB_PREFIX . "product_perentity";
218  $sql .= " SET " . $accountancy_field_name . " = '" . $db->escape($accounting->account_number) . "'";
219  $sql .= " WHERE rowid = " . ((int) $obj_exists->rowid);
220  }
221  }
222  } else {
223  $sql = " UPDATE ".MAIN_DB_PREFIX."product";
224  $sql .= " SET ".$accountancy_field_name." = '".$db->escape($accounting->account_number)."'";
225  $sql .= " WHERE rowid = ".((int) $productid);
226  }
227 
228  dol_syslog("/accountancy/admin/productaccount.php", LOG_DEBUG);
229 
230  $db->begin();
231 
232  if ($db->query($sql)) {
233  $ok++;
234  $db->commit();
235  } else {
236  $ko++;
237  $db->rollback();
238  }
239  }
240 
241  $cpt++;
242  }
243  }
244 
245  if ($ko) {
246  setEventMessages($langs->trans("XLineFailedToBeBinded", $ko), null, 'errors');
247  }
248  if ($ok) {
249  setEventMessages($langs->trans("XLineSuccessfullyBinded", $ok), null, 'mesgs');
250  }
251  }
252 }
253 
254 
255 
256 /*
257  * View
258  */
259 
260 $form = new FormAccounting($db);
261 
262 // Default AccountingAccount RowId Product / Service
263 // at this time ACCOUNTING_SERVICE_SOLD_ACCOUNT & ACCOUNTING_PRODUCT_SOLD_ACCOUNT are account number not accountingacount rowid
264 // so we need to get those the rowid of those default value first
265 $accounting = new AccountingAccount($db);
266 // TODO: we should need to check if result is already exists accountaccount rowid.....
267 $aarowid_servbuy = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT'), 1);
268 $aarowid_servbuy_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT'), 1);
269 $aarowid_servbuy_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT'), 1);
270 $aarowid_prodbuy = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT'), 1);
271 $aarowid_prodbuy_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT'), 1);
272 $aarowid_prodbuy_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT'), 1);
273 $aarowid_servsell = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT'), 1);
274 $aarowid_servsell_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT'), 1);
275 $aarowid_servsell_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT'), 1);
276 $aarowid_prodsell = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT'), 1);
277 $aarowid_prodsell_intra = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT'), 1);
278 $aarowid_prodsell_export = $accounting->fetch('', getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT'), 1);
279 
280 $aacompta_servbuy = getDolGlobalString('ACCOUNTING_SERVICE_BUY_ACCOUNT', $langs->trans("CodeNotDef"));
281 $aacompta_servbuy_intra = getDolGlobalString('ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
282 $aacompta_servbuy_export = getDolGlobalString('ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
283 $aacompta_prodbuy = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_ACCOUNT', $langs->trans("CodeNotDef"));
284 $aacompta_prodbuy_intra = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
285 $aacompta_prodbuy_export = getDolGlobalString('ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
286 $aacompta_servsell = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_ACCOUNT', $langs->trans("CodeNotDef"));
287 $aacompta_servsell_intra = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
288 $aacompta_servsell_export = getDolGlobalString('ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
289 $aacompta_prodsell = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_ACCOUNT', $langs->trans("CodeNotDef"));
290 $aacompta_prodsell_intra = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT', $langs->trans("CodeNotDef"));
291 $aacompta_prodsell_export = getDolGlobalString('ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT', $langs->trans("CodeNotDef"));
292 
293 
294 $title = $langs->trans("ProductsBinding");
295 $helpurl = '';
296 
297 $paramsCat = '';
298 foreach ($searchCategoryProductList as $searchCategoryProduct) {
299  $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
300 }
301 
302 llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, '');
303 
304 $pcgverid = getDolGlobalString('CHARTOFACCOUNTS');
305 $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
306 if (empty($pcgvercode)) {
307  $pcgvercode = $pcgverid;
308 }
309 
310 $sql = "SELECT p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
311 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
312  $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
313  $sql .= " ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
314 } else {
315  $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
316  $sql .= " p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
317 }
318 $sql .= " p.tms, p.fk_product_type as product_type,";
319 $sql .= " aa.rowid as aaid";
320 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
321 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
322  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
323  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ppe." . $accountancy_field_name . " AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) . "'";
324 } else {
325  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = p." . $accountancy_field_name . " AND aa.fk_pcg_version = '" . $db->escape($pcgvercode) . "'";
326 }
327 if (!empty($searchCategoryProductList)) {
328  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
329 }
330 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
331 if (strlen(trim($search_current_account))) {
332  $sql .= natural_search((empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p." : "ppe.") . $accountancy_field_name, $search_current_account);
333 }
334 if ($search_current_account_valid == 'withoutvalidaccount') {
335  $sql .= " AND aa.account_number IS NULL";
336 }
337 if ($search_current_account_valid == 'withvalidaccount') {
338  $sql .= " AND aa.account_number IS NOT NULL";
339 }
340 $searchCategoryProductSqlList = array();
341 if ($searchCategoryProductOperator == 1) {
342  foreach ($searchCategoryProductList as $searchCategoryProduct) {
343  if (intval($searchCategoryProduct) == -2) {
344  $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
345  } elseif (intval($searchCategoryProduct) > 0) {
346  $searchCategoryProductSqlList[] = "cp.fk_categorie = ".$db->escape($searchCategoryProduct);
347  }
348  }
349  if (!empty($searchCategoryProductSqlList)) {
350  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
351  }
352 } else {
353  foreach ($searchCategoryProductList as $searchCategoryProduct) {
354  if (intval($searchCategoryProduct) == -2) {
355  $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
356  } elseif (intval($searchCategoryProduct) > 0) {
357  $searchCategoryProductSqlList[] = "p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).")";
358  }
359  }
360  if (!empty($searchCategoryProductSqlList)) {
361  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
362  }
363 }
364 // Add search filter like
365 if (strlen(trim($search_ref))) {
366  $sql .= natural_search("p.ref", $search_ref);
367 }
368 if (strlen(trim($search_label))) {
369  $sql .= natural_search("p.label", $search_label);
370 }
371 if (strlen(trim($search_desc))) {
372  $sql .= natural_search("p.description", $search_desc);
373 }
374 if (strlen(trim($search_vat))) {
375  $sql .= natural_search("p.tva_tx", price2num($search_vat), 1);
376 }
377 if ($search_onsell != '' && $search_onsell != '-1') {
378  $sql .= natural_search('p.tosell', $search_onsell, 1);
379 }
380 if ($search_onpurchase != '' && $search_onpurchase != '-1') {
381  $sql .= natural_search('p.tobuy', $search_onpurchase, 1);
382 }
383 
384 $sql .= " GROUP BY p.rowid, p.ref, p.label, p.description, p.tosell, p.tobuy, p.tva_tx,";
385 $sql .= " p.fk_product_type,";
386 $sql .= ' p.tms,';
387 $sql .= ' aa.rowid,';
388 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
389  $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export";
390 } else {
391  $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export";
392 }
393 
394 $sql .= $db->order($sortfield, $sortorder);
395 
396 $nbtotalofrecords = '';
397 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
398  $resql = $db->query($sql);
399  $nbtotalofrecords = $db->num_rows($resql);
400  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
401  $page = 0;
402  $offset = 0;
403  }
404 }
405 
406 $sql .= $db->plimit($limit + 1, $offset);
407 
408 dol_syslog("/accountancy/admin/productaccount.php", LOG_DEBUG);
409 $resql = $db->query($sql);
410 if ($resql) {
411  $num = $db->num_rows($resql);
412  $i = 0;
413 
414  $param = '';
415  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
416  $param .= '&contextpage='.urlencode($contextpage);
417  }
418  if ($limit > 0 && $limit != $conf->liste_limit) {
419  $param .= '&limit='.urlencode($limit);
420  }
421  if ($searchCategoryProductOperator == 1) {
422  $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator);
423  }
424  foreach ($searchCategoryProductList as $searchCategoryProduct) {
425  $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
426  }
427  if ($search_ref > 0) {
428  $param .= "&search_ref=".urlencode($search_ref);
429  }
430  if ($search_label > 0) {
431  $param .= "&search_label=".urlencode($search_label);
432  }
433  if ($search_desc > 0) {
434  $param .= "&search_desc=".urlencode($search_desc);
435  }
436  if ($search_vat > 0) {
437  $param .= '&search_vat='.urlencode($search_vat);
438  }
439  if ($search_current_account > 0) {
440  $param .= "&search_current_account=".urlencode($search_current_account);
441  }
442  if ($search_current_account_valid && $search_current_account_valid != '-1') {
443  $param .= "&search_current_account_valid=".urlencode($search_current_account_valid);
444  }
445  if ($accounting_product_mode) {
446  $param .= '&accounting_product_mode='.urlencode($accounting_product_mode);
447  }
448 
449  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
450  if ($optioncss != '') {
451  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
452  }
453  print '<input type="hidden" name="token" value="'.newToken().'">';
454  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
455  print '<input type="hidden" name="action" value="update">';
456  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
457  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
458 
459  print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy');
460  print '<br>';
461 
462  print '<span class="opacitymedium">'.$langs->trans("InitAccountancyDesc").'</span><br>';
463  print '<br>';
464 
465  // Select mode
466  print '<table class="noborder centpercent">';
467  print '<tr class="liste_titre">';
468  print '<td>'.$langs->trans('Options').'</td><td>'.$langs->trans('Description').'</td>';
469  print "</tr>\n";
470  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL"'.($accounting_product_mode == 'ACCOUNTANCY_SELL' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSell').'</td>';
471  print '<td>'.$langs->trans('OptionModeProductSellDesc');
472  print "</td></tr>\n";
473  if ($mysoc->isInEEC()) {
474  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_INTRA"'.($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSellIntra').'</td>';
475  print '<td>'.$langs->trans('OptionModeProductSellIntraDesc');
476  print "</td></tr>\n";
477  }
478  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_SELL_EXPORT"'.($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT' ? ' checked' : '').'> '.$langs->trans('OptionModeProductSellExport').'</td>';
479  print '<td>'.$langs->trans('OptionModeProductSellExportDesc');
480  print "</td></tr>\n";
481  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY"'.($accounting_product_mode == 'ACCOUNTANCY_BUY' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuy').'</td>';
482  print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
483  if ($mysoc->isInEEC()) {
484  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_INTRA"'.($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuyIntra').'</td>';
485  print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
486  }
487  print '<tr class="oddeven"><td><input type="radio" name="accounting_product_mode" value="ACCOUNTANCY_BUY_EXPORT"'.($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT' ? ' checked' : '').'> '.$langs->trans('OptionModeProductBuyExport').'</td>';
488  print '<td>'.$langs->trans('OptionModeProductBuyDesc')."</td></tr>\n";
489  print "</table>\n";
490 
491  print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Refresh').'" name="changetype"></div>';
492 
493  print "<br>\n";
494 
495 
496  // Filter on categories
497  $moreforfilter = '';
498  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
499  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
500 
501  if ($massaction !== 'set_default_account') {
502  $arrayofmassactions = array(
503  'changeaccount'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Save")
504  ,'set_default_account'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount")
505  );
506  $massactionbutton = $form->selectMassAction('', $arrayofmassactions, 1);
507  }
508 
509  $buttonsave = '<input type="submit" class="button button-save" id="changeaccount" name="changeaccount" value="'.$langs->trans("Save").'">';
510  //print '<br><div class="center">'.$buttonsave.'</div>';
511 
512  $texte = $langs->trans("ListOfProductsServices");
513  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1);
514 
515  if ($massaction == 'set_default_account') {
516  $formquestion[]=array('type' => 'other',
517  'name' => 'set_default_account',
518  'label' => $langs->trans("AccountancyCode"),
519  'value' => $form->select_account('', 'default_account', 1, array(), 0, 0, 'maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'));
520  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmPreselectAccount"), $langs->trans("ConfirmPreselectAccountQuestion", count($chk_prod)), "confirm_set_default_account", $formquestion, 1, 0, 200, 500, 1);
521  }
522 
523  // Filter on categories
524  $moreforfilter = '';
525  if (isModEnabled('categorie') && $user->rights->categorie->lire) {
526  $moreforfilter .= '<div class="divsearchfield">';
527  $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
528  $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1);
529  $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -';
530  $moreforfilter .= Form::multiselectarray('search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0, 'minwidth300');
531  $moreforfilter .= ' <input type="checkbox" class="valignmiddle" name="search_category_product_operator" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/> <span class="none">'.$langs->trans('UseOrOperatorForCategories').'</span>';
532  $moreforfilter .= '</div>';
533  }
534 
535  //Show/hide child products. Hidden by default
536  if (isModEnabled('variants') && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
537  $moreforfilter .= '<div class="divsearchfield">';
538  $moreforfilter .= '<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ? 'checked="checked"' : '').'>';
539  $moreforfilter .= ' <label for="search_show_childproducts">'.$langs->trans('ShowChildProducts').'</label>';
540  $moreforfilter .= '</div>';
541  }
542 
543  $parameters = array();
544  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
545  if (empty($reshook)) {
546  $moreforfilter .= $hookmanager->resPrint;
547  } else {
548  $moreforfilter = $hookmanager->resPrint;
549  }
550 
551  if ($moreforfilter) {
552  print '<div class="liste_titre liste_titre_bydiv centpercent">';
553  print $moreforfilter;
554  print '</div>';
555  }
556 
557  print '<div class="div-table-responsive">';
558  print '<table class="liste '.($moreforfilter ? "listwithfilterbefore" : "").'">';
559 
560  print '<tr class="liste_titre_filter">';
561  print '<td class="liste_titre"><input type="text" class="flat" size="8" name="search_ref" value="'.dol_escape_htmltag($search_ref).'"></td>';
562  print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
563  print '<td class="liste_titre right"><input type="text" class="flat maxwidth50 right" size="5" name="search_vat" placeholder="%" value="'.dol_escape_htmltag($search_vat).'"></td>';
564 
565  if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
566  print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="'.dol_escape_htmltag($search_desc).'"></td>';
567  }
568  // On sell
569  if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
570  print '<td class="liste_titre center">'.$form->selectyesno('search_onsell', $search_onsell, 1, false, 1).'</td>';
571  } else {
572  // On buy
573  print '<td class="liste_titre center">'.$form->selectyesno('search_onpurchase', $search_onpurchase, 1, false, 1).'</td>';
574  }
575  // Current account
576  print '<td class="liste_titre">';
577  print '<input type="text" class="flat" size="6" name="search_current_account" id="search_current_account" value="'.dol_escape_htmltag($search_current_account).'">';
578  $listofvals = array('withoutvalidaccount'=>$langs->trans("WithoutValidAccount"), 'withvalidaccount'=>$langs->trans("WithValidAccount"));
579  print ' '.$langs->trans("or").' '.$form->selectarray('search_current_account_valid', $listofvals, $search_current_account_valid, 1);
580  print '</td>';
581  print '<td class="liste_titre">&nbsp;</td>';
582  print '<td class="center liste_titre">';
583  $searchpicto = $form->showFilterButtons();
584  print $searchpicto;
585  print '</td>';
586  print '</tr>';
587 
588  print '<tr class="liste_titre">';
589  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
590  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder);
591  if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
592  print_liste_field_titre("Description", $_SERVER["PHP_SELF"], "p.description", "", $param, '', $sortfield, $sortorder);
593  }
594  print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], "p.tva_tx", "", $param, '', $sortfield, $sortorder, 'right ');
595  // On sell / On purchase
596  if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
597  print_liste_field_titre("OnSell", $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
598  } else {
599  print_liste_field_titre("OnBuy", $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
600  }
601  print_liste_field_titre("CurrentDedicatedAccountingAccount", $_SERVER["PHP_SELF"], (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p." : "ppe.") . $accountancy_field_name, "", $param, '', $sortfield, $sortorder);
602  print_liste_field_titre("AssignDedicatedAccountingAccount");
603  $clickpitco = $form->showCheckAddButtons('checkforselect', 1);
604  print_liste_field_titre($clickpitco, '', '', '', '', '', '', '', 'center ');
605  print '</tr>';
606 
607  $product_static = new Product($db);
608 
609  $i = 0;
610  while ($i < min($num, $limit)) {
611  $obj = $db->fetch_object($resql);
612 
613  // Ref produit as link
614  $product_static->ref = $obj->ref;
615  $product_static->id = $obj->rowid;
616  $product_static->type = $obj->product_type;
617  $product_static->label = $obj->label;
618  $product_static->description = $obj->description;
619  $product_static->status = $obj->tosell;
620  $product_static->status_buy = $obj->tobuy;
621 
622  // Sales
623  if ($obj->product_type == 0) {
624  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
625  $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
626  $compta_prodsell_id = $aarowid_prodsell;
627  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
628  $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
629  $compta_prodsell_id = $aarowid_prodsell_intra;
630  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
631  $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
632  $compta_prodsell_id = $aarowid_prodsell_export;
633  } else {
634  $compta_prodsell = (!empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
635  $compta_prodsell_id = $aarowid_prodsell;
636  }
637  } else {
638  if ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
639  $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
640  $compta_prodsell_id = $aarowid_servsell;
641  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
642  $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
643  $compta_prodsell_id = $aarowid_servsell_intra;
644  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
645  $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
646  $compta_prodsell_id = $aarowid_servsell_export;
647  } else {
648  $compta_prodsell = (!empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"));
649  $compta_prodsell_id = $aarowid_servsell;
650  }
651  }
652 
653  // Purchases
654  if ($obj->product_type == 0) {
655  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
656  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
657  $compta_prodbuy_id = $aarowid_prodbuy;
658  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
659  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
660  $compta_prodbuy_id = $aarowid_prodbuy_intra;
661  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
662  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
663  $compta_prodbuy_id = $aarowid_prodbuy_export;
664  } else {
665  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
666  $compta_prodbuy_id = $aarowid_prodbuy;
667  }
668  } else {
669  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
670  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
671  $compta_prodbuy_id = $aarowid_servbuy;
672  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
673  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT : $langs->trans("CodeNotDef"));
674  $compta_prodbuy_id = $aarowid_servbuy_intra;
675  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
676  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT : $langs->trans("CodeNotDef"));
677  $compta_prodbuy_id = $aarowid_servbuy_export;
678  } else {
679  $compta_prodbuy = (!empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
680  $compta_prodbuy_id = $aarowid_servbuy;
681  }
682  }
683 
684  print '<tr class="oddeven">';
685 
686  print '<td>';
687  print $product_static->getNomUrl(1);
688  print '</td>';
689 
690  print '<td class="left">'.$obj->label.'</td>';
691 
692  if (!empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) {
693  // TODO ADJUST DESCRIPTION SIZE
694  // print '<td class="left">' . $obj->description . '</td>';
695  // TODO: we should set a user defined value to adjust user square / wide screen size
696  $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION;
697  print '<td>'.nl2br(dol_trunc($obj->description, $trunclength)).'</td>';
698  }
699 
700  // VAT
701  print '<td class="right">';
702  print vatrate($obj->tva_tx);
703  print '</td>';
704 
705  // On sell / On purchase
706  if ($accounting_product_mode == 'ACCOUNTANCY_SELL' || $accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA' || $accounting_product_mode == 'ACCOUNTANCY_SELL_EXPORT') {
707  print '<td class="center">'.$product_static->getLibStatut(3, 0).'</td>';
708  } else {
709  print '<td class="center">'.$product_static->getLibStatut(3, 1).'</td>';
710  }
711 
712  // Current accounting account
713  print '<td class="left">';
714  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
715  print length_accountg($obj->accountancy_code_buy);
716  if ($obj->accountancy_code_buy && empty($obj->aaid)) {
717  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
718  }
719  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
720  print length_accountg($obj->accountancy_code_buy_intra);
721  if ($obj->accountancy_code_buy_intra && empty($obj->aaid)) {
722  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
723  }
724  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
725  print length_accountg($obj->accountancy_code_buy_export);
726  if ($obj->accountancy_code_buy_export && empty($obj->aaid)) {
727  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
728  }
729  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
730  print length_accountg($obj->accountancy_code_sell);
731  if ($obj->accountancy_code_sell && empty($obj->aaid)) {
732  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
733  }
734  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
735  print length_accountg($obj->accountancy_code_sell_intra);
736  if ($obj->accountancy_code_sell_intra && empty($obj->aaid)) {
737  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
738  }
739  } else {
740  print length_accountg($obj->accountancy_code_sell_export);
741  if ($obj->accountancy_code_sell_export && empty($obj->aaid)) {
742  print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount"));
743  }
744  }
745  print '</td>';
746 
747  // New account to set
748  $defaultvalue = '';
749  if ($accounting_product_mode == 'ACCOUNTANCY_BUY') {
750  // Accounting account buy
751  print '<td class="left">';
752  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
753  if (empty($defaultvalue)) {
754  $defaultvalue = $compta_prodbuy;
755  }
756  $codesell = length_accountg($obj->accountancy_code_buy);
757  if (!empty($obj->aaid)) {
758  $defaultvalue = ''; // Do not suggest default new value is code is already valid
759  }
760  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
761  print '</td>';
762  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_INTRA') {
763  // Accounting account buy intra (In EEC)
764  print '<td class="left">';
765  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
766  if (empty($defaultvalue)) {
767  $defaultvalue = $compta_prodbuy;
768  }
769  $codesell = length_accountg($obj->accountancy_code_buy_intra);
770  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
771  if (!empty($obj->aaid)) {
772  $defaultvalue = ''; // Do not suggest default new value is code is already valid
773  }
774  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
775  print '</td>';
776  } elseif ($accounting_product_mode == 'ACCOUNTANCY_BUY_EXPORT') {
777  // Accounting account buy export (Out of EEC)
778  print '<td class="left">';
779  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
780  if (empty($defaultvalue)) {
781  $defaultvalue = $compta_prodbuy;
782  }
783  $codesell = length_accountg($obj->accountancy_code_buy_export);
784  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
785  if (!empty($obj->aaid)) {
786  $defaultvalue = ''; // Do not suggest default new value is code is already valid
787  }
788  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
789  print '</td>';
790  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL') {
791  // Accounting account sell
792  print '<td class="left">';
793  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
794  if (empty($defaultvalue)) {
795  $defaultvalue = $compta_prodsell;
796  }
797  $codesell = length_accountg($obj->accountancy_code_sell);
798  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
799  if (!empty($obj->aaid)) {
800  $defaultvalue = ''; // Do not suggest default new value is code is already valid
801  }
802  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
803  print '</td>';
804  } elseif ($accounting_product_mode == 'ACCOUNTANCY_SELL_INTRA') {
805  // Accounting account sell intra (In EEC)
806  print '<td class="left">';
807  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
808  if (empty($defaultvalue)) {
809  $defaultvalue = $compta_prodsell;
810  }
811  $codesell = length_accountg($obj->accountancy_code_sell_intra);
812  //var_dump($defaultvalue.' - '.$codesell.' - '.$compta_prodsell);
813  if (!empty($obj->aaid)) {
814  $defaultvalue = ''; // Do not suggest default new value is code is already valid
815  }
816  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
817  print '</td>';
818  } else {
819  // Accounting account sell export (Out of EEC)
820  print '<td class="left">';
821  //$defaultvalue=GETPOST('codeventil_' . $product_static->id,'alpha'); This is id and we need a code
822  if (empty($defaultvalue)) {
823  $defaultvalue = $compta_prodsell;
824  }
825  $codesell = length_accountg($obj->accountancy_code_sell_export);
826  if (!empty($obj->aaid)) {
827  $defaultvalue = ''; // Do not suggest default new value is code is already valid
828  }
829  print $form->select_account(($default_account > 0 && $confirm === 'yes' && in_array($product_static->id, $chk_prod)) ? $default_account : $defaultvalue, 'codeventil_'.$product_static->id, 1, array(), 1, 0, 'maxwidth300 maxwidthonsmartphone productforselect');
830  print '</td>';
831  }
832 
833  if (!empty($chk_prod)) {
834  $ischecked = 0;
835  if (in_array($product_static->id, $chk_prod)) {
836  $ischecked=true;
837  }
838  }
839 
840  // Checkbox select
841  print '<td class="center">';
842  print '<input type="checkbox" class="checkforselect productforselectcodeventil_'.$product_static->id.'" name="chk_prod[]" '.($ischecked ? "checked" : "").' value="'.$obj->rowid.'"/></td>';
843  print "</tr>";
844  $i++;
845  }
846  print '</table>';
847  print '</div>';
848 
849  print '<script type="text/javascript">
850  jQuery(document).ready(function() {
851  function init_savebutton()
852  {
853  console.log("We check if at least one line is checked")
854 
855  atleastoneselected=0;
856  jQuery(".checkforselect").each(function( index ) {
857  /* console.log( index + ": " + $( this ).text() ); */
858  if ($(this).is(\':checked\')) atleastoneselected++;
859  });
860 
861  if (atleastoneselected) jQuery("#changeaccount").removeAttr(\'disabled\');
862  else jQuery("#changeaccount").attr(\'disabled\',\'disabled\');
863  if (atleastoneselected) jQuery("#changeaccount").attr(\'class\',\'button\');
864  else jQuery("#changeaccount").attr(\'class\',\'button\');
865  }
866 
867  jQuery(".checkforselect").change(function() {
868  init_savebutton();
869  });
870  jQuery(".productforselect").change(function() {
871  console.log($(this).attr("id")+" "+$(this).val());
872  if ($(this).val() && $(this).val() != -1) {
873  $(".productforselect"+$(this).attr("id")).prop(\'checked\', true);
874  } else {
875  $(".productforselect"+$(this).attr("id")).prop(\'checked\', false);
876  }
877  init_savebutton();
878  });
879 
880  init_savebutton();
881 
882  jQuery("#search_current_account").keyup(function() {
883  if (jQuery("#search_current_account").val() != \'\')
884  {
885  console.log("We set a value of account to search "+jQuery("#search_current_account").val()+", so we disable the other search criteria on account");
886  jQuery("#search_current_account_valid").val(-1);
887  }
888  });
889  });
890  </script>';
891 
892  print '</form>';
893 
894  $db->free($resql);
895 } else {
896  dol_print_error($db);
897 }
898 
899 // End of page
900 llxFooter();
901 $db->close();
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3805
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8535
length_accountg
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Definition: accounting.lib.php:94
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
print_barre_liste
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.
Definition: functions.lib.php:5257
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
Form\multiselectarray
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Definition: html.form.class.php:8256
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolibarr_set_const
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:627
AccountingAccount
Class to manage accounting accounts.
Definition: accountingaccount.class.php:36
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
Product
Class to manage products or services.
Definition: product.class.php:46
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5492