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