From 3ab5c3e6ab5df33ae2f2ff5ee2f802bb4f489be0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Mar 2019 16:03:37 +0100 Subject: [PATCH] FIX Edit of personalized groups --- htdocs/accountancy/admin/categories.php | 11 ++++++----- .../class/accountancycategory.class.php | 15 +++++++++++---- htdocs/langs/en_US/accountancy.lang | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php index decae324ac5..faba7fb1c62 100644 --- a/htdocs/accountancy/admin/categories.php +++ b/htdocs/accountancy/admin/categories.php @@ -60,7 +60,7 @@ $accountingcategory = new AccountancyCategory($db); // si ajout de comptes if (! empty($selectcpt)) { - $cpts = array (); + $cpts = array(); foreach ($selectcpt as $selectedoption) { if (! array_key_exists($selectedoption, $cpts)) $cpts[$selectedoption] = "'" . $selectedoption . "'"; @@ -71,13 +71,13 @@ if (! empty($selectcpt)) { if ($return<0) { setEventMessages($langs->trans('errors'), $accountingcategory->errors, 'errors'); } else { - setEventMessages($langs->trans('SetupSaved'), null, 'mesgs'); + setEventMessages($langs->trans('RecordModifiedSuccessfully'), null, 'mesgs'); } } if ($action == 'delete') { if ($cpt_id) { if ($accountingcategory->deleteCptCat($cpt_id)) { - setEventMessages($langs->trans('CategoryDeleted'), null, 'mesgs'); + setEventMessages($langs->trans('AccountRemovedFromGroup'), null, 'mesgs'); } else { setEventMessages($langs->trans('errors'), null, 'errors'); } @@ -173,8 +173,9 @@ if ($action == 'display' || $action == 'delete') { print '' . $cpt->label . ''; print ''; print ""; - print img_delete($langs->trans("DeleteFromCat")).' '; - print $langs->trans("DeleteFromCat").""; + print $langs->trans("DeleteFromCat"); + print img_picto($langs->trans("DeleteFromCat"), 'unlink'); + print ""; print ""; print "\n"; } diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 73cccdfd721..ae4b42c8e3c 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -514,7 +514,7 @@ class AccountancyCategory // extends CommonObject /** * Function to select accounting category of an accounting account present in chart of accounts * - * @param int $id Id category + * @param int $id Id of category to know which account to exclude * * @return int <0 if KO, 0 if not found, >0 if OK */ @@ -569,12 +569,13 @@ class AccountancyCategory // extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - $sql = "SELECT aa.rowid,aa.account_number "; + $sql = "SELECT aa.rowid, aa.account_number"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1"; $sql .= " AND aa.entity = " . $conf->entity; + $sql .= " ORDER BY LENGTH(aa.account_number) DESC;"; // LENGTH is ok with mysql and postgresql $this->db->begin(); @@ -587,10 +588,16 @@ class AccountancyCategory // extends CommonObject return -1; } - while ( $obj = $this->db->fetch_object($resql)) + $accountincptsadded=array(); + while ($obj = $this->db->fetch_object($resql)) { - if (array_key_exists(length_accountg($obj->account_number), $cpts)) + $account_number_formated=length_accountg($obj->account_number); + if (! empty($accountincptsadded[$account_number_formated])) continue; + + if (array_key_exists($account_number_formated, $cpts)) { + $accountincptsadded[$account_number_formated]=1; + // We found an account number that is in list $cpts of account to add $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account"; $sql .= " SET fk_accounting_category=" . $id_cat; $sql .= " WHERE rowid=".$obj->rowid; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index fc2cb928903..30d97cc6e3e 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -256,7 +256,7 @@ NotYetAccounted=Not yet accounted in ledger ## Admin ApplyMassCategories=Apply mass categories -AddAccountFromBookKeepingWithNoCategories=Available account not yet in a personalized group +AddAccountFromBookKeepingWithNoCategories=Available account not yet in the personalized group CategoryDeleted=Category for the accounting account has been removed AccountingJournals=Accounting journals AccountingJournal=Accounting journal @@ -308,6 +308,7 @@ PredefinedGroups=Predefined groups WithoutValidAccount=Without valid dedicated account WithValidAccount=With valid dedicated account ValueNotIntoChartOfAccount=This value of accounting account does not exist into chart of account +AccountRemovedFromGroup=Account removed from group ## Dictionary Range=Range of accounting account