From bb786d5ab95b5211fd304cfd2e02744922bf74ad Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 21 Aug 2022 08:06:04 +0200 Subject: [PATCH 1/2] NEW Accountancy - Manage supplier deposit with specific account --- htdocs/accountancy/admin/defaultaccounts.php | 42 +++++++++++++++++++ .../class/accountingaccount.class.php | 8 +++- .../accountancy/journal/purchasesjournal.php | 21 +++++++++- htdocs/langs/en_US/accountancy.lang | 2 + 4 files changed, 69 insertions(+), 4 deletions(-) diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php index 895437ab58b36..361bc0d6e1596 100644 --- a/htdocs/accountancy/admin/defaultaccounts.php +++ b/htdocs/accountancy/admin/defaultaccounts.php @@ -128,6 +128,7 @@ } $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'; + $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'; $constvalue = GETPOST($constname, 'int'); if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error++; @@ -155,6 +156,20 @@ } } +if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') { + $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOST('value', 'int'); + $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + } + + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'mesgs'); + } +} + /* * View @@ -281,6 +296,33 @@ print ''; } +// Supplier deposit account +print ''; +// Param +print ''; +print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'); +print ''; +// Value +print ''; // Do not force class=right, or it align also the content of the select box +print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts'); +print ''; +print ''; + +if (!empty($conf->societe->enabled) && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') { + print ''; + print '' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . ''; + if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning'); + print ''; + } else { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; + } + print ''; +} + print "\n"; print "\n"; diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 710443c9badf8..bf487d47c2c04 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -863,14 +863,18 @@ public function getAccountingCodeToBind(Societe $buyer, Societe $seller, Product if (!empty($buyer->code_compta_product)) { $code_t = $buyer->code_compta_product; $suggestedid = $accountingAccount['thirdparty']; - $suggestedaccountingaccountfor = 'thridparty'; + $suggestedaccountingaccountfor = 'thirdparty'; } } // Manage 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 ($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 ($result < 0) { return -1; } diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 7c0a8b90f7db3..a7b0760e1f6af 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -405,8 +405,18 @@ $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add $bookkeeping->thirdparty_code = $companystatic->code_fournisseur; - $bookkeeping->subledger_account = ''; - $bookkeeping->subledger_label = ''; + if (!empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT)) { + if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + $bookkeeping->subledger_label = $tabcompany[$key]['name']; + } else { + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + } + } else { + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + } $bookkeeping->numero_compte = $k; $bookkeeping->label_compte = $label_account; @@ -952,6 +962,13 @@ function writebookkeeping() { print ""; // Subledger account print ""; + if (!empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT)) { + if ($k == getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT')) { + print length_accounta($tabcompany[$key]['code_compta']); + } + } elseif (($accountoshow == "") || $accountoshow == 'NotDefined') { + print '' . $langs->trans("ThirdpartyAccountNotDefined") . ''; + } print ''; $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index b059cc9952aec..2fbc48e653efc 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -183,6 +183,8 @@ ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT=Accounting account to register subscript ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT=Accounting account by default to register customer deposit UseAuxiliaryAccountOnCustomerDeposit=Store customer account as individual account in subsidiary ledger for lines of down payments (if disabled, individual account for down payment lines will remain empty) +ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT=Accounting account by default to register supplier deposit +UseAuxiliaryAccountOnSupplierDeposit=Store supplier account as individual account in subsidiary ledger for lines of down payments (if disabled, individual account for down payment lines will remain empty) ACCOUNTING_PRODUCT_BUY_ACCOUNT=Accounting account by default for the bought products (used if not defined in the product sheet) ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT=Accounting account by default for the bought products in EEC (used if not defined in the product sheet) From d652384f3c44bd36cd2db9f5ed10eb11fb8dfad1 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 22 Aug 2022 21:55:00 +0200 Subject: [PATCH 2/2] Fix admin --- htdocs/accountancy/admin/defaultaccounts.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php index 361bc0d6e1596..2af7192525b9d 100644 --- a/htdocs/accountancy/admin/defaultaccounts.php +++ b/htdocs/accountancy/admin/defaultaccounts.php @@ -128,6 +128,11 @@ } $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'; + $constvalue = GETPOST($constname, 'int'); + if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { + $error++; + } + $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'; $constvalue = GETPOST($constname, 'int'); if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {