From 36b86686483112b35b1843b4b275a9ba6387788e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Thu, 10 Nov 2022 02:02:04 +0100 Subject: [PATCH] FIX Accountancy - When origin invoice is deposit, suggest specific account on credit note --- .../class/accountingaccount.class.php | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 254c22c9f95..93e56064196 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -868,43 +868,44 @@ class AccountingAccount extends CommonObject } // Manage Deposit - if ($factureDet->desc == "(DEPOSIT)" || $facture->type == $facture::TYPE_DEPOSIT) { - $accountdeposittoventilated = new self($this->db); - if ($type == 'customer') { - $result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); - } elseif ($type == 'supplier') { - $result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1); - } - if (isset($result) && $result < 0) { - return -1; - } - - $code_l = $accountdeposittoventilated->ref; - $code_p = ''; - $code_t = ''; - $suggestedid = $accountdeposittoventilated->rowid; - $suggestedaccountingaccountfor = 'deposit'; - } - - // For credit note invoice, if origin invoice is a deposit invoice, force also on specific customer/supplier deposit account - dol_syslog("fk_facture_source::".$facture->fk_facture_source, LOG_DEBUG); - if (!empty($facture->fk_facture_source)) { - $invoiceSource = new Facture($this->db); - $invoiceSource->fetch($facture->fk_facture_source); - - if ($facture->type == $facture::TYPE_CREDIT_NOTE && $invoiceSource->type == $facture::TYPE_DEPOSIT) { - $accountdeposittoventilated = new AccountingAccount($this->db); + if (!empty($conf->global->{'ACCOUNTING_ACCOUNT_' . strtoupper($type) . '_DEPOSIT'})) { + if ($factureDet->desc == "(DEPOSIT)" || $facture->type == $facture::TYPE_DEPOSIT) { + $accountdeposittoventilated = new self($this->db); if ($type == 'customer') { - $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); + $result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); } elseif ($type == 'supplier') { - $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1); + $result = $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1); } + if (isset($result) && $result < 0) { + return -1; + } + $code_l = $accountdeposittoventilated->ref; $code_p = ''; $code_t = ''; $suggestedid = $accountdeposittoventilated->rowid; $suggestedaccountingaccountfor = 'deposit'; } + + // For credit note invoice, if origin invoice is a deposit invoice, force also on specific customer/supplier deposit account + if (!empty($facture->fk_facture_source)) { + $invoiceSource = new $facture($this->db); + $invoiceSource->fetch($facture->fk_facture_source); + + if ($facture->type == $facture::TYPE_CREDIT_NOTE && $invoiceSource->type == $facture::TYPE_DEPOSIT) { + $accountdeposittoventilated = new self($this->db); + if ($type == 'customer') { + $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT, 1); + } elseif ($type == 'supplier') { + $accountdeposittoventilated->fetch('', $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT, 1); + } + $code_l = $accountdeposittoventilated->ref; + $code_p = ''; + $code_t = ''; + $suggestedid = $accountdeposittoventilated->rowid; + $suggestedaccountingaccountfor = 'deposit'; + } + } } // If $suggestedid could not be guessed yet, we set it from the generic default accounting code $code_l