From 2975d47113323e61ed0405ba12702c90470f2e32 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 22 Nov 2021 04:13:16 +0100 Subject: [PATCH] FIX Debug a lot of regression in accountancy transfer --- .../class/accountingaccount.class.php | 2 +- htdocs/accountancy/customer/index.php | 25 +++-------------- htdocs/accountancy/customer/list.php | 27 ++++--------------- htdocs/accountancy/supplier/index.php | 13 +++------ htdocs/accountancy/supplier/list.php | 12 ++++----- 5 files changed, 18 insertions(+), 61 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 5c5faa837b7..730e52c805a 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -874,7 +874,7 @@ class AccountingAccount extends CommonObject } // Manage Deposit - if ($factureDet->desc == "(DEPOSIT)") { + if ($factureDet->desc == "(DEPOSIT)" || $facture->type == $facture::TYPE_DEPOSIT) { $accountdeposittoventilated = new self($this->db); $result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); if ($result < 0) { diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index f54c81477aa..2a4a18a15ce 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -251,6 +251,8 @@ if ($action == 'validatehistory') { $code_sell_p_notset = ''; $code_sell_t_notset = ''; + $suggestedid = 0; + $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer'); if (!is_array($return) && $return<0) { setEventMessage($accountingAccount->error, 'errors'); @@ -265,28 +267,7 @@ if ($action == 'validatehistory') { } } - if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { - // Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) - if (!empty($objp->company_code_sell)) { - $objp->code_sell_t = $objp->company_code_sell; - $objp->aarowid_suggest = $objp->aarowid_thirdparty; - $suggestedaccountingaccountfor = ''; - } - } - - // Manage Deposit - if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT)) { - if ($objp->description == "(DEPOSIT)" || $objp->ftype == $facture_static::TYPE_DEPOSIT) { - $accountdeposittoventilated = new AccountingAccount($db); - $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); - $objp->code_sell_l = $accountdeposittoventilated->ref; - $objp->code_sell_p = ''; - $objp->code_sell_t = ''; - $objp->aarowid_suggest = $accountdeposittoventilated->rowid; - } - } - - if ($objp->aarowid_suggest > 0) { + if ($suggestedid > 0) { $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."facturedet"; $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid); $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id); diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index b61e2e74ad8..6de33911e74 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -532,6 +532,7 @@ if ($result) { // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB ! $code_sell_l = ''; $code_sell_p = ''; + $code_sell_t = ''; $thirdpartystatic->id = $objp->socid; $thirdpartystatic->name = $objp->name; @@ -581,6 +582,8 @@ if ($result) { $code_sell_p_notset = ''; $code_sell_t_notset = ''; + $suggestedid = 0; + $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer'); if (!is_array($return) && $return<0) { setEventMessage($accountingAccount->error, 'errors'); @@ -594,28 +597,7 @@ if ($result) { } //var_dump($return); - // Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) - if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { - if (!empty($objp->company_code_sell)) { - $objp->code_sell_t = $objp->company_code_sell; - $objp->aarowid_suggest = $objp->aarowid_thirdparty; - $suggestedaccountingaccountfor = ''; - } - } - - // Manage Deposit - if (!empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT)) { - if ($objp->description == "(DEPOSIT)" || $objp->ftype == $facture_static::TYPE_DEPOSIT) { - $accountdeposittoventilated = new AccountingAccount($db); - $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); - $objp->code_sell_l = $accountdeposittoventilated->ref; - $objp->code_sell_p = ''; - $objp->code_sell_t = ''; - $objp->aarowid_suggest = $accountdeposittoventilated->rowid; - } - } - - if (!empty($objp->code_sell_p)) { + if (!empty($code_sell_p)) { // Value was defined previously } else { $code_sell_p_notset = 'color:orange'; @@ -630,6 +612,7 @@ if ($result) { // $code_sell_l is now default code of product/service // $code_sell_p is now code of product/service // $code_sell_t is now code of thirdparty + //var_dump($code_sell_l.' - '.$code_sell_p.' - '.$code_sell_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')'); print ''; diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 55dcec12989..1038fd25e57 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -247,6 +247,8 @@ if ($action == 'validatehistory') { $code_buy_p_notset = ''; $code_buy_t_notset = ''; + $suggestedid = 0; + $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'supplier'); if (!is_array($return) && $return<0) { setEventMessage($accountingAccount->error, 'errors'); @@ -261,16 +263,7 @@ if ($action == 'validatehistory') { } } - if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { - // Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) - if (!empty($objp->company_code_buy)) { - $objp->code_buy_t = $objp->company_code_buy; - $objp->aarowid_suggest = $objp->aarowid_thirdparty; - $suggestedaccountingaccountfor = ''; - } - } - - if ($objp->aarowid_suggest > 0) { + if ($suggestedid > 0) { $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det"; $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid); $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id); diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 18cb15d61a5..2b1260ea0da 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -532,9 +532,9 @@ if ($result) { // product_type: 0 = service, 1 = product // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB ! - $objp->code_buy_l = ''; - $objp->code_buy_p = ''; - $objp->aarowid_suggest = ''; // Will be set later + $code_buy_l = ''; + $code_buy_p = ''; + $code_buy_t = ''; $thirdpartystatic->id = $objp->socid; $thirdpartystatic->name = $objp->name; @@ -585,6 +585,8 @@ if ($result) { $code_buy_p_notset = ''; $code_buy_t_notset = ''; + $suggestedid = 0; + $return=$accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facturefourn_static, $facturefourn_static_det, $accountingAccountArray, 'supplier'); if (!is_array($return) && $return<0) { setEventMessage($accountingAccount->error, 'errors'); @@ -598,9 +600,6 @@ if ($result) { } //var_dump($return); - // Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) - // Not supported for suppliers - if (!empty($code_buy_p)) { // Value was defined previously } else { @@ -616,6 +615,7 @@ if ($result) { // $code_buy_l is now default code of product/service // $code_buy_p is now code of product/service // $code_buy_t is now code of thirdparty + //var_dump($code_buy_l.' - '.$code_buy_p.' - '.$code_buy_t.' -> '.$suggestedid.' ('.$suggestedaccountingaccountbydefaultfor.' '.$suggestedaccountingaccountfor.')'); print '';