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