Clean code

This commit is contained in:
Laurent Destailleur 2018-03-15 11:27:39 +01:00
parent b379a2f83c
commit db18db9488
7 changed files with 36 additions and 23 deletions

View File

@ -53,6 +53,11 @@ if (empty($user->rights->accounting->chartofaccount))
$accountingcategory = new AccountancyCategory($db); $accountingcategory = new AccountancyCategory($db);
/*
* Actions
*/
// si ajout de comptes // si ajout de comptes
if (! empty($selectcpt)) { if (! empty($selectcpt)) {
$cpts = array (); $cpts = array ();
@ -83,6 +88,7 @@ if ($action == 'delete') {
/* /*
* View * View
*/ */
$form = new Form($db); $form = new Form($db);
$formaccounting = new FormAccounting($db); $formaccounting = new FormAccounting($db);
@ -99,13 +105,15 @@ print '<input type="hidden" name="action" value="display">';
dol_fiche_head(); dol_fiche_head();
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Category
// Select the category
print '<tr><td class="titlefield">' . $langs->trans("AccountingCategory") . '</td>'; print '<tr><td class="titlefield">' . $langs->trans("AccountingCategory") . '</td>';
print '<td>'; print '<td>';
$formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1); $formaccounting->select_accounting_category($cat_id, 'account_category', 1, 0, 0, 1);
print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">'; print '<input class="button" type="submit" value="' . $langs->trans("Select") . '">';
print '</td></tr>'; print '</td></tr>';
// Select the accounts
if (! empty($cat_id)) if (! empty($cat_id))
{ {
$return = $accountingcategory->getAccountsWithNoCategory($cat_id); $return = $accountingcategory->getAccountsWithNoCategory($cat_id);
@ -153,7 +161,7 @@ if ($action == 'display' || $action == 'delete') {
print "</tr>\n"; print "</tr>\n";
if (! empty($cat_id)) { if (! empty($cat_id)) {
$return = $accountingcategory->display($cat_id); $return = $accountingcategory->display($cat_id); // This load ->lines_display
if ($return < 0) { if ($return < 0) {
setEventMessages(null, $accountingcategory->errors, 'errors'); setEventMessages(null, $accountingcategory->errors, 'errors');
} }

View File

@ -357,7 +357,6 @@ class AccountancyCategory // extends CommonObject
* Function to select all accounting accounts from an accounting category * Function to select all accounting accounts from an accounting category
* *
* @param int $id Id * @param int $id Id
*
* @return int <0 if KO, 0 if not found, >0 if OK * @return int <0 if KO, 0 if not found, >0 if OK
*/ */
public function display($id) { public function display($id) {
@ -365,7 +364,7 @@ class AccountancyCategory // extends CommonObject
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
$sql .= " WHERE t.fk_accounting_category = " . $id; $sql .= " WHERE t.fk_accounting_category = " . $id;
$this->lines_display = array (); $this->lines_display = array());
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);

View File

@ -17,8 +17,8 @@
-- --
-- Group of accounting account for French result. This is a minimal default setup. -- Group of accounting account for French reports. This is a minimal default setup.
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'VENTES', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 1, 1); INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1, 'INCOME', 'Income of products/services', 'Example: 7xxxxx', 0, 0, '', '10', 1, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'DEPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 1, 1); INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2, 'EXPENSES', 'Expenses of products/services', 'Example: 6xxxxx', 0, 0, '', '20', 1, 1);
INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'VENTES+DEPENSES', '30', 1, 1); INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3, 'PROFIT', 'Balance', '', 0, 1, 'VENTES+DEPENSES', '30', 1, 1);

View File

@ -705,3 +705,6 @@ ALTER TABLE llx_facture_rec_extrafields ADD INDEX idx_facture_rec_extrafields (f
-- VMYSQL4.1 ALTER TABLE llx_product_association ADD COLUMN rowid integer AUTO_INCREMENT PRIMARY KEY; -- VMYSQL4.1 ALTER TABLE llx_product_association ADD COLUMN rowid integer AUTO_INCREMENT PRIMARY KEY;
DROP TABLE llx_c_accountancy_category;

View File

@ -36,6 +36,7 @@ ALTER TABLE llx_website_page ADD COLUMN fk_user_create integer;
ALTER TABLE llx_website_page ADD COLUMN fk_user_modif integer; ALTER TABLE llx_website_page ADD COLUMN fk_user_modif integer;
ALTER TABLE llx_website_page ADD COLUMN type_container varchar(16) NOT NULL DEFAULT 'page'; ALTER TABLE llx_website_page ADD COLUMN type_container varchar(16) NOT NULL DEFAULT 'page';
DROP TABLE llx_c_accountancy_category;
-- For 8.0 -- For 8.0

View File

@ -25,13 +25,13 @@ create table llx_accounting_account
entity integer DEFAULT 1 NOT NULL, entity integer DEFAULT 1 NOT NULL,
datec datetime, datec datetime,
tms timestamp, tms timestamp,
fk_pcg_version varchar(32) NOT NULL, fk_pcg_version varchar(32) NOT NULL, -- Chart system
pcg_type varchar(20) NOT NULL, pcg_type varchar(20) NOT NULL, -- First part of Key for predefined groups
pcg_subtype varchar(20) NOT NULL, pcg_subtype varchar(20) NOT NULL, -- Second part of Key for predefined groups
account_number varchar(32) NOT NULL, account_number varchar(32) NOT NULL,
account_parent varchar(32) DEFAULT '0', -- Hierarchic parent TODO Move this as integer, it is a foreign key of llx_accounting_account.rowid account_parent varchar(32) DEFAULT '0', -- Hierarchic parent. TODO Move this as integer, it is a foreign key of llx_accounting_account.rowid
label varchar(255) NOT NULL, label varchar(255) NOT NULL,
fk_accounting_category integer DEFAULT 0, fk_accounting_category integer DEFAULT 0, -- ID of personalized group for report
fk_user_author integer DEFAULT NULL, fk_user_author integer DEFAULT NULL,
fk_user_modif integer DEFAULT NULL, fk_user_modif integer DEFAULT NULL,
active tinyint DEFAULT 1 NOT NULL, active tinyint DEFAULT 1 NOT NULL,

View File

@ -15,14 +15,16 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- --
-- Table with category for accounting account -- Table with category for accounting account.
-- Note: Each accounting account is inside one chart system, so we can have
-- a different dispatching of account in a category for each chart system.
-- =================================================================== -- ===================================================================
CREATE TABLE llx_c_accounting_category ( CREATE TABLE llx_c_accounting_category (
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY, rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
code varchar(16) NOT NULL, code varchar(16) NOT NULL,
label varchar(255) NOT NULL, label varchar(255) NOT NULL,
range_account varchar(255) NOT NULL, range_account varchar(255) NOT NULL, -- Comment
sens tinyint NOT NULL DEFAULT '0', -- For international accounting 0 : credit - debit / 1 : debit - credit sens tinyint NOT NULL DEFAULT '0', -- For international accounting 0 : credit - debit / 1 : debit - credit
category_type tinyint NOT NULL DEFAULT '0', -- Field calculated or not category_type tinyint NOT NULL DEFAULT '0', -- Field calculated or not
formula varchar(255) NOT NULL, -- Example : 1 + 2 (rowid of the category) formula varchar(255) NOT NULL, -- Example : 1 + 2 (rowid of the category)