From de77e39e085c976016ae5419f8733ef4d879620c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Nov 2019 11:14:36 +0100 Subject: [PATCH] FIX #12319 Restore feature ACCOUNTANCY_AUTOFILL_ACCOUNT_WITH_GENERIC. Now autofill works, option can be reverted in v11. --- .../class/accountingaccount.class.php | 2 +- htdocs/accountancy/customer/list.php | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index bc25e33484d..55e463a73f6 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -154,7 +154,7 @@ class AccountingAccount extends CommonObject * @param int $rowid Id * @param string $account_number Account number * @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active char of account - * @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC'. + * @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code). * @return int <0 if KO, 0 if not found, Id of record if OK and found */ public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount = '') diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 7826d2b1faf..55d72c79d12 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -420,6 +420,8 @@ if ($result) { $isSellerInEEC = isInEEC($mysoc); + $accountingaccount_codetotid_cache = array(); + while ($i < min($num_lines, $limit)) { $objp = $db->fetch_object($result); @@ -488,8 +490,8 @@ if ($result) { } } - if (! empty($objp->code_sell)) { - //$objp->code_sell_p = $objp->code_sell; // Code on product + if (! empty($objp->code_sell_p)) { + // Value was defined previously } else { $code_sell_p_notset = 'color:orange'; } @@ -561,11 +563,26 @@ if ($result) { print ''; // Suggested accounting account + // $objp->code_sell_l = default (it takes the country into consideration), $objp->code_sell_p is value for product (it takes the country into consideration too) print ''; $suggestedid = $objp->aarowid_suggest; + /*var_dump($suggestedid); + var_dump($objp->code_sell_p); + var_dump($objp->code_sell_l);*/ if (empty($suggestedid) && empty($objp->code_sell_p) && ! empty($objp->code_sell_l) && ! empty($conf->global->ACCOUNTANCY_AUTOFILL_ACCOUNT_WITH_GENERIC)) { - //$suggestedid = // id of $objp->code_sell_l + if (empty($accountingaccount_codetotid_cache[$objp->code_sell_l])) + { + $tmpaccount = new AccountingAccount($db); + $tmpaccount->fetch(0, $objp->code_sell_l, 1); + if ($tmpaccount->id > 0) { + $suggestedid = $tmpaccount->id; + } + $accountingaccount_codetotid_cache[$objp->code_sell_l] = $tmpaccount->id; + } + else { + $suggestedid = $accountingaccount_codetotid_cache[$objp->code_sell_l]; + } } print $formaccounting->select_account($suggestedid, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'codeventil maxwidth200 maxwidthonsmartphone', 'cachewithshowemptyone'); print '';