FIX Edit of personalized groups

This commit is contained in:
Laurent Destailleur
2019-03-14 16:03:37 +01:00
parent 7f23a396a9
commit 3ab5c3e6ab
3 changed files with 19 additions and 10 deletions

View File

@@ -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 '<td>' . $cpt->label . '</td>';
print '<td class="right">';
print "<a href= '".$_SERVER['PHP_SELF']."?action=delete&account_category=" . $cat_id . "&cptid=" . $cpt->rowid."'>";
print img_delete($langs->trans("DeleteFromCat")).' ';
print $langs->trans("DeleteFromCat")."</a>";
print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink');
print "</a>";
print "</td>";
print "</tr>\n";
}

View File

@@ -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;

View File

@@ -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