diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 50116b94b23..f3e70ac837a 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -732,17 +732,16 @@ class AccountingAccount extends CommonObject /** * Return Suggest accounting accounts to bind * - * @param Societe $buyer Societe Object Buyers - * @param $seller Company Object seller - * @param Product $product Product object sell or buy - * @param Facture $facture Facture - * @param FactureLigne $factureDet Facture Det - * @param array $accountingAccount array of Account account - * @param string $type Customer / Supplier - * - * @return array Accounting accounts suggested + * @param Societe $buyer Object buyer + * @param Societe $seller Object seller + * @param Product $product Product object sell or buy + * @param Facture $facture Facture + * @param FactureLigne $factureDet Facture Det + * @param array $accountingAccount Array of Account account + * @param string $type Customer / Supplier + * @return array Accounting accounts suggested */ - public function getAccountingCodeToBind(Societe $buyer, $seller, Product $product, Facture $facture, FactureLigne $factureDet, $accountingAccount = array(), $type = '') + public function getAccountingCodeToBind(Societe $buyer, Societe $seller, Product $product, Facture $facture, FactureLigne $factureDet, $accountingAccount = array(), $type = '') { global $conf; global $hookmanager; @@ -755,21 +754,21 @@ class AccountingAccount extends CommonObject $reshook = $hookmanager->executeHooks('accoutancyBindingCalculation', $parameters); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { - if ($type=='customer') { + if ($type == 'customer') { $const_name = "SOLD"; - } elseif ($type=='supplier') { + } elseif ($type == 'supplier') { $const_name = "BUY"; } require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; $isBuyerInEEC = isInEEC($buyer); $isSellerInEEC = isInEEC($seller); - $code_l = ''; - $code_p = ''; - $code_t = ''; + $code_l = ''; // Default value for generic product/service + $code_p = ''; // Value for the product/service in parameter ($product) + $code_t = ''; // Default value of product account for the thirdparty $suggestedid = ''; - // Level 1: Search suggested default account for product/service + // Level 1 (define $code_l): Search suggested default account for product/service $suggestedaccountingaccountbydefaultfor = ''; if ($factureDet->product_type == 1) { if ($buyer->country_code == $seller->country_code || empty($buyer->country_code)) { // If buyer in same country than seller (if not defined, we assume it is same country) @@ -814,7 +813,7 @@ class AccountingAccount extends CommonObject $code_l = ''; } - // Level 2: Search suggested account for product/service (similar code exists in page index.php to make automatic binding) + // Level 2 (define $code_p): Search suggested account for product/service (similar code exists in page index.php to make automatic binding) $suggestedaccountingaccountfor = ''; if ((($buyer->country_code == $seller->country_code) || empty($buyer->country_code))) { // If buyer in same country than seller (if not defined, we assume it is same country) @@ -866,7 +865,7 @@ class AccountingAccount extends CommonObject } } - // Level 3: Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) + // Level 3 (define $code_t): 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($buyer->code_compta)) { $code_t = $buyer->code_compta; @@ -888,6 +887,7 @@ class AccountingAccount extends CommonObject $suggestedaccountingaccountfor = 'deposit'; } + // If $suggestedid could not be guessed yet, we set it from the generic default accounting code $code_l if (empty($suggestedid) && empty($code_p) && !empty($code_l) && empty($conf->global->ACCOUNTANCY_DO_NOT_AUTOFILL_ACCOUNT_WITH_GENERIC)) { if (empty($this->accountingaccount_codetotid_cache[$code_l])) { $tmpaccount = new self($this->db); diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 908079356a3..23df93ec7d5 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -586,9 +586,9 @@ if ($result) { $suggestedid=$return['suggestedid']; $suggestedaccountingaccountfor=$return['suggestedaccountingaccountfor']; $suggestedaccountingaccountbydefaultfor=$return['suggestedaccountingaccountbydefaultfor']; - $code_sell_l=$return['code_sell_l']; - $code_sell_p=$return['code_sell_p']; - $code_sell_t=$return['code_sell_t']; + $code_sell_l=$return['code_l']; + $code_sell_p=$return['code_p']; + $code_sell_t=$return['code_t']; } //var_dump($return); diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 7ed451d1951..b8fdfc6e0c5 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -595,9 +595,9 @@ if ($result) { $suggestedid=$return['suggestedid']; $suggestedaccountingaccountfor=$return['suggestedaccountingaccountfor']; $suggestedaccountingaccountbydefaultfor=$return['suggestedaccountingaccountbydefaultfor']; - $code_buy_l=$return['code_buy_l']; - $code_buy_p=$return['code_buy_p']; - $code_buy_t=$return['code_buy_t']; + $code_buy_l=$return['code_l']; + $code_buy_p=$return['code_p']; + $code_buy_t=$return['code_t']; } //var_dump($return);