From e0f600f226c669575d8cd8f5e3427de33e1441ec Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 2 May 2016 20:21:37 +0200 Subject: [PATCH] FIX: Accountancy - Little fix et add page to assign massively the category --- htdocs/accountancy/admin/account.php | 1 + htdocs/accountancy/admin/categories.php | 157 ++++++++++++++++++ .../class/accountancycategory.class.php | 8 +- htdocs/langs/en_US/accountancy.lang | 2 + 4 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 htdocs/accountancy/admin/categories.php diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 94ce450ff30..5bdaa3c5828 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -147,6 +147,7 @@ if ($result) { print '
'; print '' . $langs->trans("Addanaccount") . ''; + print '' . $langs->trans("ApplyMassCategories") . ''; // print '' . $langs->trans("ImportAccount") . ''; // print '' . $langs->trans("CheckProductAccountancyCode") . ''; print '

'; diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php new file mode 100644 index 00000000000..f0013632b53 --- /dev/null +++ b/htdocs/accountancy/admin/categories.php @@ -0,0 +1,157 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/accountancy/admin/categories.php + * \ingroup Advanced accountancy + * \brief Page to assign mass categories to accounts + */ +require '../../main.inc.php'; + +// Class +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; + +$error = 0; + +// Langs +$langs->load("bills"); +$langs->load("accountancy"); + +$mesg = ''; +$action = GETPOST('action'); +$cat_id = GETPOST('account_category'); +$selectcpt = GETPOST('cpt_bk'); +$cpt_id = GETPOST('cptid'); + +if($cat_id == 0){ + $cat_id = null; +} + +$id = GETPOST('id', 'int'); +$rowid = GETPOST('rowid', 'int'); +$cancel = GETPOST('cancel'); + +// Security check +if (! $user->admin) + accessforbidden(); + +$AccCat = new AccountancyCategory($db); + +// si ajout de comptes +if(!empty($selectcpt)){ + $cpts = array(); + $i = 0; + foreach ($selectcpt as $selectedOption){ + $cpts[$i] = "'".$selectedOption."'"; + $i++; + } + + if($AccCat->updateAccAcc($cat_id, $cpts)){ + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + }else{ + setEventMessages($langs->trans('errors'), null, 'errors'); + } + + +} +if ($action == 'delete') { + if($cpt_id){ + if($AccCat->deleteCptCat($cpt_id)){ + setEventMessages($langs->trans('Deleted'), null, 'mesgs'); + }else{ + setEventMessages($langs->trans('errors'), null, 'errors'); + } + } +} + +/* + * View + */ +llxheader('', $langs->trans('AccountAccounting')); + +$formaccounting = new FormAccounting($db); +$form = new Form($db); + + print load_fiche_titre($langs->trans('Categories')); + + print '
' . "\n"; + print ''; + print ''; + + dol_fiche_head(); + + print ''; + // Category + print ''; + print ''; + + + if(!empty($cat_id)){ + $obj = $AccCat->getCptBK($cat_id); + print ''; + print ''; + } + + print '
' . $langs->trans("AccountingCategory") . ''; + $formaccounting->select_accounting_category($cat_id, 'account_category', 1); + print ''; + print '
' . $langs->trans("AddCompteFromBK") . ''; + if(!empty($obj)){ + print ' - '; + } + print '
'; + + dol_fiche_end(); + + print '
'; + +if ($action == 'display' || $action == 'delete') { + + print ''; + + print ''; + + if(!empty($cat_id)){ + $obj = $AccCat->display($cat_id); + $j=1; + if(!empty($obj)){ + foreach ( $obj as $cpt ) { + $var = ! $var; + print ""; + print ''; + print ''; + print $form->formconfirm($_SERVER["PHP_SELF"]."?account_category=$cat_id&cptid=".$cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete".$j); + print ''; + print "\n"; + $j++; + } + } + } + + print "
'.$langs->trans("Numerocompte").''.$langs->trans("Description").'Action
' . length_accountg($cpt->account_number) . '' . $cpt->label . '
"; +} + +llxFooter(); + +$db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 92ea01660ac..ef880aa8113 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -19,7 +19,7 @@ /** * \file htdocs/accountancy/class/accountancycategory.class.php * \ingroup Advanced accountancy - * \brief File of class to manage categories of an accounting account_category + * \brief File of class to manage categories of an accounting category_type */ // Class @@ -243,7 +243,7 @@ class AccountancyCategory } else { - $sql = "SELECT c.rowid, c.code, c.label, c.account_category "; + $sql = "SELECT c.rowid, c.code, c.label, c.category_type "; $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; $sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid"; $sql.= " AND co.code = '".$mysoc->country_code."'"; @@ -343,7 +343,7 @@ class AccountancyCategory { $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; - $sql.= " WHERE c.active = 1 AND c.account_category = 1 "; + $sql.= " WHERE c.active = 1 AND c.category_type = 1 "; $sql.= " AND c.fk_country = ".$mysoc->country_id; $sql.= " ORDER BY c.position ASC"; } @@ -351,7 +351,7 @@ class AccountancyCategory { $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; - $sql.= " WHERE c.active = 1 AND c.account_category = 1 AND c.fk_country = co.rowid"; + $sql.= " WHERE c.active = 1 AND c.category_type = 1 AND c.fk_country = co.rowid"; $sql.= " AND co.code = '".$mysoc->country_code."'"; $sql.= " ORDER BY c.position ASC"; } diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 64c0d88df48..46375e49ff9 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -149,6 +149,8 @@ FicheVentilation=Breakdown card GeneralLedgerIsWritten=Operations are written in the general ledger MvtNotCorrectlyBalanced=Mouvement not correctly balanced. Credit = %s. Debit = %s +## Admin +ApplyMassCategories=Apply mass categories ## Export Exports=Exports