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