diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index a11c036dafe..52d0868ae5c 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -46,7 +46,7 @@ $cancel = GETPOST('cancel'); if (! $user->admin) accessforbidden(); -$accounting = new AccountingAccount($db); +$object = new AccountingAccount($db); // Action if ($action == 'add') { @@ -57,16 +57,16 @@ if ($action == 'add') { $result = $db->query($sql); $obj = $db->fetch_object($result); - $accounting->fk_pcg_version = $obj->pcg_version; - $accounting->pcg_type = GETPOST('pcg_type'); - $accounting->pcg_subtype = GETPOST('pcg_subtype'); - $accounting->account_number = GETPOST('account_number'); - $accounting->account_parent = GETPOST('account_parent', 'int'); - $accounting->account_category = GETPOST('account_category', 'int'); - $accounting->label = GETPOST('label', 'alpha'); - $accounting->active = 1; + $object->fk_pcg_version = $obj->pcg_version; + $object->pcg_type = GETPOST('pcg_type'); + $object->pcg_subtype = GETPOST('pcg_subtype'); + $object->account_number = GETPOST('account_number'); + $object->account_parent = GETPOST('account_parent', 'int'); + $object->account_category = GETPOST('account_category'); + $object->label = GETPOST('label', 'alpha'); + $object->active = 1; - $res = $accounting->create($user); + $res = $object->create($user); if ($res == 0) { } else { @@ -83,7 +83,7 @@ if ($action == 'add') { Header("Location: account.php"); } else if ($action == 'edit') { if (! GETPOST('cancel', 'alpha')) { - $result = $accounting->fetch($id); + $result = $object->fetch($id); $sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS; @@ -91,15 +91,15 @@ if ($action == 'add') { $result2 = $db->query($sql); $obj = $db->fetch_object($result2); - $accounting->fk_pcg_version = $obj->pcg_version; - $accounting->pcg_type = GETPOST('pcg_type'); - $accounting->pcg_subtype = GETPOST('pcg_subtype'); - $accounting->account_number = GETPOST('account_number'); - $accounting->account_parent = GETPOST('account_parent', 'int'); - $accounting->account_category = GETPOST('account_category', 'int'); - $accounting->label = GETPOST('label', 'alpha'); + $object->fk_pcg_version = $obj->pcg_version; + $object->pcg_type = GETPOST('pcg_type'); + $object->pcg_subtype = GETPOST('pcg_subtype'); + $object->account_number = GETPOST('account_number'); + $object->account_parent = GETPOST('account_parent', 'int'); + $object->account_category = GETPOST('account_category'); + $object->label = GETPOST('label', 'alpha'); - $result = $accounting->update($user); + $result = $object->update($user); if ($result > 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); @@ -112,10 +112,10 @@ if ($action == 'add') { exit(); } } else if ($action == 'delete') { - $result = $accounting->fetch($id); + $result = $object->fetch($id); - if (! empty($accounting->id)) { - $result = $accounting->delete($user); + if (! empty($object->id)) { + $result = $object->delete($user); if ($result > 0) { Header("Location: account.php"); @@ -123,7 +123,7 @@ if ($action == 'add') { } if ($result < 0) { - setEventMessages($accounting->error, $accounting->errors, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -150,34 +150,34 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print ''; + print ''; // Label print '' . $langs->trans("Label") . ''; - print ''; + print ''; // Account parent print '' . $langs->trans("Accountparent") . ''; print ''; - print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); + print $htmlacc->select_account($object->account_parent, 'account_parent', 1); print ''; // Category print '' . $langs->trans("AccountingCategory") . ''; print ''; - $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); print ''; // Chart of accounts type print '' . $langs->trans("Pcgtype") . ''; print ''; - print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); + print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); print ''; // Chart of acounts subtype print '' . $langs->trans("Pcgsubtype") . ''; print ''; - print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); + print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); print ''; print ''; @@ -192,13 +192,12 @@ if ($action == 'create') { print ''; } else if ($id) { - $rowid = $id; - $account = $accounting->fetch($rowid); + $result = $object->fetch($id); - if ($account > 0) { + if ($result > 0) { dol_htmloutput_mesg($mesg); - $head = accounting_prepare_head($accounting); + $head = accounting_prepare_head($object); // Edit mode if ($action == 'update') { @@ -218,34 +217,34 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print ''; + print ''; // Label print '' . $langs->trans("Label") . ''; - print ''; + print ''; // Account parent print '' . $langs->trans("Accountparent") . ''; print ''; - print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1); + print $htmlacc->select_account($object->account_parent, 'account_parent', 1); print ''; // Category print ''.$langs->trans("AccountingCategory").''; print ''; - $formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1); + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); print ''; // Chart of accounts type print '' . $langs->trans("Pcgtype") . ''; print ''; - print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type'); + print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); print ''; // Chart of accounts subtype print '' . $langs->trans("Pcgsubtype") . ''; print ''; - print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); + print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); print ''; print ''; @@ -270,37 +269,37 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print '' . $accounting->account_number . ''; + print '' . $object->account_number . ''; print '' . $linkback . ''; // Label print '' . $langs->trans("Label") . ''; - print '' . $accounting->label . ''; + print '' . $object->label . ''; // Account parent $accp = new AccountingAccount($db); - if (! empty($accounting->account_parent)) { - $accp->fetch($accounting->account_parent, ''); + if (! empty($object->account_parent)) { + $accp->fetch($object->account_parent, ''); } print '' . $langs->trans("Accountparent") . ''; print '' . $accp->account_number . ' - ' . $accp->label . ''; // Category - print "".$langs->trans("AccountingCategory")."".$accounting->accounting_category_label.""; + print "".$langs->trans("AccountingCategory")."".$object->account_category_label.""; // Chart of accounts type print '' . $langs->trans("Pcgtype") . ''; - print '' . $accounting->pcg_type . ''; + print '' . $object->pcg_type . ''; // Chart of accounts subtype print '' . $langs->trans("Pcgsubtype") . ''; - print '' . $accounting->pcg_subtype . ''; + print '' . $object->pcg_subtype . ''; // Active print '' . $langs->trans("Activated") . ''; print ''; - if (empty($accounting->active)) { + if (empty($object->active)) { print img_picto($langs->trans("Disabled"), 'switch_off'); } else { print img_picto($langs->trans("Activated"), 'switch_on'); diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 2f2cf023db0..7ee43999736 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -20,9 +20,9 @@ */ /** - * \file htdocs/accountancy/class/accountingaccount.class.php - * \ingroup Accounting Expert - * \brief Fichier de la classe des comptes comptable + * \file htdocs/accountancy/class/accountingaccount.class.php + * \ingroup Accounting Expert + * \brief Fichier de la classe des comptes comptable */ /** @@ -64,21 +64,22 @@ class AccountingAccount extends CommonObject * @param int $limittocurentchart 1=Do not load record if it is into another accounting system * @return int <0 if KO, >0 if OK */ - function fetch($rowid = null, $account_number = null, $limittocurentchart = 0) { + function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0) { global $conf; if ($rowid || $account_number) { $sql = "SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.pcg_subtype, a.account_number, a.account_parent, a.label, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active"; - $sql .= ", ac.rowid, ac.label as category_label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a, " . MAIN_DB_PREFIX . "c_accounting_category as ac"; - $sql .= " WHERE a.fk_accounting_category = ac.rowid"; + $sql .= ", ca.label as category_label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as a"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as ca ON a.fk_accounting_category = ca.rowid"; + $sql .= " WHERE"; if ($rowid) { - $sql .= " AND a.rowid = '" . $rowid . "'"; + $sql .= " a.rowid = '" . $rowid . "'"; } elseif ($account_number) { - $sql .= " AND a.account_number = '" . $account_number . "'"; + $sql .= " a.account_number = '" . $account_number . "'"; } - if (! empty($limittocurentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT a.pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system as as WHERE as.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; + if (! empty($limittocurrentchart)) { + $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; } dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); @@ -97,8 +98,8 @@ class AccountingAccount extends CommonObject $this->account_number = $obj->account_number; $this->account_parent = $obj->account_parent; $this->label = $obj->label; - $this->fk_accounting_category = $obj->fk_accounting_category; - $this->accounting_category_label = $obj->category_label; + $this->account_category = $obj->fk_accounting_category; + $this->account_category_label = $obj->category_label; $this->fk_user_author = $obj->fk_user_author; $this->fk_user_modif = $obj->fk_user_modif; $this->active = $obj->active; @@ -140,6 +141,8 @@ class AccountingAccount extends CommonObject $this->account_parent = trim($this->account_parent); if (isset($this->label)) $this->label = trim($this->label); + if (isset($this->account_category)) + $this->account_category = trim($this->account_category); if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author); if (isset($this->active)) @@ -159,7 +162,7 @@ class AccountingAccount extends CommonObject $sql .= ", account_number"; $sql .= ", account_parent"; $sql .= ", label"; - $sql .= ", fk_accounting_account"; + $sql .= ", fk_accounting_category"; $sql .= ", fk_user_author"; $sql .= ", active"; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 8103575d2c9..e8664e3166d 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -17,7 +17,7 @@ /** * \file htdocs/core/class/html.formaccounting.class.php - * \ingroup core + * \ingroup Advanced accountancy * \brief File of class with all html predefined components */ @@ -93,8 +93,8 @@ class FormAccounting while ($i < $num) { $obj = $db->fetch_object($resql); - print '