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