This commit is contained in:
aspangaro 2016-03-28 21:03:47 +02:00
parent cbecb37c59
commit 2be979569d
3 changed files with 66 additions and 64 deletions

View File

@ -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 '<tr><td width="25%"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"</td></tr>';
// Label
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
print '<td><input name="label" size="70" value="' . $accounting->label . '"</td></tr>';
print '<td><input name="label" size="70" value="' . $object->label . '"</td></tr>';
// Account parent
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td>';
print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1);
print $htmlacc->select_account($object->account_parent, 'account_parent', 1);
print '</td></tr>';
// Category
print '<tr><td>' . $langs->trans("AccountingCategory") . '</td>';
print '<td>';
$formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1);
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
print '</td></tr>';
// Chart of accounts type
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type');
print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type');
print '</td></tr>';
// Chart of acounts subtype
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype');
print '</td></tr>';
print '</table>';
@ -192,13 +192,12 @@ if ($action == 'create') {
print '</form>';
} 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 '<tr><td width="25%"><span class="fieldrequired">' . $langs->trans("AccountNumber") . '</span></td>';
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
print '<td><input name="account_number" size="30" value="' . $object->account_number . '"</td></tr>';
// Label
print '<tr><td><span class="fieldrequired">' . $langs->trans("Label") . '</span></td>';
print '<td><input name="label" size="70" value="' . $accounting->label . '"</td></tr>';
print '<td><input name="label" size="70" value="' . $object->label . '"</td></tr>';
// Account parent
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td>';
print $htmlacc->select_account($accounting->account_parent, 'account_parent', 1);
print $htmlacc->select_account($object->account_parent, 'account_parent', 1);
print '</td></tr>';
// Category
print '<tr><td>'.$langs->trans("AccountingCategory").'</td>';
print '<td>';
$formaccounting->select_accounting_category($accounting->fk_accounting_category, 'account_category', 1);
$formaccounting->select_accounting_category($object->account_category, 'account_category', 1);
print '</td></tr>';
// Chart of accounts type
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgtype($accounting->pcg_type, 'pcg_type');
print $htmlacc->select_pcgtype($object->pcg_type, 'pcg_type');
print '</td></tr>';
// Chart of accounts subtype
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td>';
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
print $htmlacc->select_pcgsubtype($object->pcg_subtype, 'pcg_subtype');
print '</td></tr>';
print '</table>';
@ -270,37 +269,37 @@ if ($action == 'create') {
// Account number
print '<tr><td width="25%">' . $langs->trans("AccountNumber") . '</td>';
print '<td>' . $accounting->account_number . '</td>';
print '<td>' . $object->account_number . '</td>';
print '<td align="right" width="25%">' . $linkback . '</td></tr>';
// Label
print '<tr><td>' . $langs->trans("Label") . '</td>';
print '<td colspan="2">' . $accounting->label . '</td></tr>';
print '<td colspan="2">' . $object->label . '</td></tr>';
// 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 '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td colspan="2">' . $accp->account_number . ' - ' . $accp->label . '</td></tr>';
// Category
print "<tr><td>".$langs->trans("AccountingCategory")."</td><td colspan='2'>".$accounting->accounting_category_label."</td>";
print "<tr><td>".$langs->trans("AccountingCategory")."</td><td colspan='2'>".$object->account_category_label."</td>";
// Chart of accounts type
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td colspan="2">' . $accounting->pcg_type . '</td></tr>';
print '<td colspan="2">' . $object->pcg_type . '</td></tr>';
// Chart of accounts subtype
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td colspan="2">' . $accounting->pcg_subtype . '</td></tr>';
print '<td colspan="2">' . $object->pcg_subtype . '</td></tr>';
// Active
print '<tr><td>' . $langs->trans("Activated") . '</td>';
print '<td colspan="2">';
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');

View File

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

View File

@ -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 '<option value="'.$obj->id.'"';
if ($obj->id == $selected) print ' selected';
print '<option value="'.$obj->rowid.'"';
if ($obj->rowid == $selected) print ' selected';
print '>'.dol_trunc($obj->type,$maxlen);
print ' ('.$obj->range.')';
$i++;