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