Skip to content

Commit

Permalink
Debug II
Browse files Browse the repository at this point in the history
  • Loading branch information
aspangaro committed Mar 28, 2016
1 parent cbecb37 commit 2be9795
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 64 deletions.
93 changes: 46 additions & 47 deletions htdocs/accountancy/admin/card.php
Expand Up @@ -46,7 +46,7 @@
if (! $user->admin)
accessforbidden();

$accounting = new AccountingAccount($db);
$object = new AccountingAccount($db);

// Action
if ($action == 'add') {
Expand All @@ -57,16 +57,16 @@
$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 {
Expand All @@ -83,23 +83,23 @@
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;

dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
$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);
Expand All @@ -112,18 +112,18 @@
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");
}
}

if ($result < 0) {
setEventMessages($accounting->error, $accounting->errors, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
}
}

Expand All @@ -150,34 +150,34 @@

// 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>';
Expand All @@ -192,13 +192,12 @@

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') {
Expand All @@ -218,34 +217,34 @@

// 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>';
Expand All @@ -270,37 +269,37 @@

// 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');
Expand Down
31 changes: 17 additions & 14 deletions htdocs/accountancy/class/accountingaccount.class.php
Expand Up @@ -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
*/

/**
Expand Down Expand Up @@ -64,21 +64,22 @@ function __construct($db) {
* @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);
Expand All @@ -97,8 +98,8 @@ function fetch($rowid = null, $account_number = null, $limittocurentchart = 0) {
$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;
Expand Down Expand Up @@ -140,6 +141,8 @@ function create($user, $notrigger = 0) {
$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))
Expand All @@ -159,7 +162,7 @@ function create($user, $notrigger = 0) {
$sql .= ", account_number";
$sql .= ", account_parent";
$sql .= ", label";
$sql .= ", fk_accounting_account";
$sql .= ", fk_accounting_category";
$sql .= ", fk_user_author";
$sql .= ", active";

Expand Down
6 changes: 3 additions & 3 deletions htdocs/core/class/html.formaccounting.class.php
Expand Up @@ -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
*/

Expand Down Expand Up @@ -93,8 +93,8 @@ function select_accounting_category($selected='',$htmlname='account_category', $
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++;
Expand Down

0 comments on commit 2be9795

Please sign in to comment.