diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 04cee2215b0..60812cc61f4 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -145,8 +145,6 @@ if ($action == 'delete') { $pcgver = $conf->global->CHARTOFACCOUNTS; - - $sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.pcg_subtype, aa.account_number, aa.account_parent , aa.label, aa.active, "; $sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; @@ -198,10 +196,12 @@ if ($resql) { if ($search_pcgsubtype != "") $params.= '&search_pcgsubtype='.urlencode($search_pcgsubtype); if ($optioncss != '') $param.='&optioncss='.$optioncss; - print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy'); - print '
'; + $htmlbuttonadd = '' . $langs->trans("Addanaccount") . ''; + + print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $htmlbuttonadd); + // Box to select active chart of account $var = ! $var; print $langs->trans("Selectchartofaccounts") . " : "; @@ -229,13 +229,7 @@ if ($resql) { print ""; print ''; print '
'; - print "
\n"; - - print '' . $langs->trans("Addanaccount") . ''; - print '' . $langs->trans("ApplyMassCategories") . ''; - // print '' . $langs->trans("ImportAccount") . ''; - // print '' . $langs->trans("CheckProductAccountancyCode") . ''; - print '

'; + print '
'; print ''; print ''; @@ -307,12 +301,12 @@ if ($resql) { // Action print '
'; - if ($user->admin) { - print ''; + if ($user->rights->accounting->chartofaccount) { + print ''; print img_edit(); print ''; print ' '; - print ''; + print ''; print img_delete(); print ''; } diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 822a4d19bcd..8e77c4a5dab 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -26,6 +26,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancysystem.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; @@ -159,13 +160,15 @@ if ($action == 'add' && $user->rights->accounting->chartofaccount) $result = $object->update($user); if ($result > 0) { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + $urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id); + header("Location: " . $urltogo); exit(); } else { $mesg = $object->error; } } else { - header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + $urltogo=$backtopage?$backtopage:($_SERVER["PHP_SELF"]."?id=".$id); + header("Location: " . $urltogo); exit(); } } else if ($action == 'delete' && $user->rights->accounting->chartofaccount) { @@ -196,6 +199,9 @@ $form = new Form($db); $htmlacc = new FormVentilation($db); $formaccounting = new FormAccounting($db); +$accountsystem = new AccountancySystem($db); +$accountsystem->fetch($conf->global->CHARTOFACCOUNTS); + // Create mode if ($action == 'create') { print load_fiche_titre($langs->trans('NewAccountingAccount')); @@ -208,36 +214,45 @@ if ($action == 'create') { print ''; + // Chart of account + print ''; + print ''; + + // Account number print ''; - print ''; + print ''; // Label print ''; - print ''; + print ''; // Account parent print ''; print ''; // Category print ''; print ''; // Chart of accounts type print ''; print ''; // Chart of acounts subtype print ''; print ''; print '
' . $langs->trans("Chartofaccounts") . ''; + print $accountsystem->ref; + print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . '
' . $langs->trans("Accountparent") . ''; - print $htmlacc->select_account($object->account_parent, 'account_parent', 1); + print $htmlacc->select_account($object->account_parent, 'account_parent', 1, null, 0, 0, 'minwidth200'); print '
' . $langs->trans("AccountingCategory") . ''; - $formaccounting->select_accounting_category($object->account_category, 'account_category', 1); + $formaccounting->select_accounting_category($object->account_category, 'account_category', 1, 0, 1); print '
' . $langs->trans("Pcgtype") . ''; - print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); + print ''; + //print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1); print '
' . $langs->trans("Pcgsubtype") . ''; - print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); + print ''; + //print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1); print '
'; @@ -268,7 +283,8 @@ if ($action == 'create') { print ''; print ''; print ''; - + print ''; + print ''; // Account number @@ -294,13 +310,15 @@ if ($action == 'create') { // Chart of accounts type print ''; print ''; // Chart of accounts subtype print ''; print ''; print '
' . $langs->trans("Pcgtype") . ''; - print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type'); + //print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type', 1); + print ''; print '
' . $langs->trans("Pcgsubtype") . ''; - print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype'); + print ''; + //print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype', 1); print '
'; diff --git a/htdocs/accountancy/class/accountancysystem.class.php b/htdocs/accountancy/class/accountancysystem.class.php index dd7d0c70897..a1c90a97b5b 100644 --- a/htdocs/accountancy/class/accountancysystem.class.php +++ b/htdocs/accountancy/class/accountancysystem.class.php @@ -47,6 +47,55 @@ class AccountancySystem $this->db = $db; } + + /** + * Load record in memory + * + * @param int $rowid Id + * @param string $ref ref + * @return int <0 if KO, Id of record if OK and found + */ + function fetch($rowid = 0, $ref = '') + { + global $conf; + + if ($rowid > 0 || $ref) + { + $sql = "SELECT a.pcg_version, a.label, a.active"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_system as a"; + $sql .= " WHERE"; + if ($rowid) { + $sql .= " a.rowid = '" . $rowid . "'"; + } elseif ($ref) { + $sql .= " a.pcg_version = '" . $ref . "'"; + } + + dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + $obj = $this->db->fetch_object($result); + + if ($obj) { + $this->id = $obj->rowid; + $this->rowid = $obj->rowid; + $this->pcg_version = $obj->pcg_version; + $this->ref = $obj->pcg_version; + $this->label = $obj->label; + $this->active = $obj->active; + + return $this->id; + } else { + return 0; + } + } else { + $this->error = "Error " . $this->db->lasterror(); + $this->errors[] = "Error " . $this->db->lasterror(); + } + } + return - 1; + } + + /** * Insert accountancy system name into database * diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 9749e38007f..aee7d7172c6 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -150,12 +150,19 @@ class AccountingAccount extends CommonObject if (isset($this->active)) $this->active = trim($this->active); - // Check parameters - // Put here code to add control on parameters values + if (empty($this->pcg_type) || $this->pcg_type == '-1') + { + $this->pcg_type = 'XXXXXX'; + } + if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') + { + $this->pcg_subtype = 'XXXXXX'; + } + // Check parameters + // Put here code to add control on parameters values // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_account("; - $sql .= "datec"; $sql .= ", entity"; $sql .= ", fk_pcg_version"; @@ -167,9 +174,7 @@ class AccountingAccount extends CommonObject $sql .= ", fk_accounting_category"; $sql .= ", fk_user_author"; $sql .= ", active"; - $sql .= ") VALUES ("; - $sql .= " '" . $this->db->idate($now) . "'"; $sql .= ", " . $conf->entity; $sql .= ", " . (empty($this->fk_pcg_version) ? 'NULL' : "'" . $this->db->escape($this->fk_pcg_version) . "'"); @@ -225,11 +230,22 @@ class AccountingAccount extends CommonObject /** * Update record * - * @param User $user Use making update - * @return int <0 if KO, >0 if OK + * @param User $user Use making update + * @return int <0 if KO, >0 if OK */ - function update($user) { - $this->db->begin(); + function update($user) + { + // Check parameters + if (empty($this->pcg_type) || $this->pcg_type == '-1') + { + $this->pcg_type = 'XXXXXX'; + } + if (empty($this->pcg_subtype) || $this->pcg_subtype == '-1') + { + $this->pcg_subtype = 'XXXXXX'; + } + + $this->db->begin(); $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account "; $sql .= " SET fk_pcg_version = " . ($this->fk_pcg_version ? "'" . $this->db->escape($this->fk_pcg_version) . "'" : "null"); @@ -241,7 +257,6 @@ class AccountingAccount extends CommonObject $sql .= " , fk_accounting_category = '" . $this->account_category . "'"; $sql .= " , fk_user_modif = " . $user->id; $sql .= " , active = '" . $this->active . "'"; - $sql .= " WHERE rowid = " . $this->id; dol_syslog(get_class($this) . "::update sql=" . $sql, LOG_DEBUG); diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index 376e5b00d56..06c9dcacc71 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -180,11 +180,15 @@ class FormVentilation extends Form $options = array(); $out = ajax_combobox($htmlname, $event); - while ($obj = $this->db->fetch_object($resql)) { - $options[$obj->pcg_type] = $obj->pcg_type; + while ($obj = $this->db->fetch_object($resql)) + { + if ($obj->pcg_type != '-1') + { + $options[$obj->pcg_type] = $obj->pcg_type; + } } - $out .= Form::selectarray($htmlname, $options, $selectid, $showempty); + $out .= Form::selectarray($htmlname, $options, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth200'); $this->db->free($resql); return $out; @@ -200,7 +204,8 @@ class FormVentilation extends Form * * @return string String with HTML select */ - function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) { + function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) + { global $conf; $sql = "SELECT DISTINCT pcg_subtype "; @@ -221,11 +226,15 @@ class FormVentilation extends Form $options = array(); $out = ajax_combobox($htmlname, $event); - while ($obj = $this->db->fetch_object($resql)) { - $options[$obj->pcg_subtype] = $obj->pcg_subtype; + while ($obj = $this->db->fetch_object($resql)) + { + if ($obj->pcg_type != '-1') + { + $options[$obj->pcg_subtype] = $obj->pcg_subtype; + } } - $out .= Form::selectarray($htmlname, $options, $selectid, $showempty); + $out .= Form::selectarray($htmlname, $options, $selectid, $showempty, 0, 0, '', 0, 0, 0, '', 'minwidth200'); $this->db->free($resql); return $out; diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 8c7f6903bb3..36d32436e82 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -90,31 +90,35 @@ class FormAccounting $num = $db->num_rows($resql); if ($num) { - print ''; $i = 0; - if ($useempty) print ''; + if ($useempty) $out.= ''; while ($i < $num) { $obj = $db->fetch_object($resql); - print '