Clean code

This commit is contained in:
Laurent Destailleur 2015-06-12 13:21:21 +02:00
parent ed0e6753e3
commit 4e5ed08ff8
5 changed files with 56 additions and 52 deletions

View File

@ -23,12 +23,14 @@
* \brief Card accounting account
*/
require '../../main.inc.php';
// Class
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/html.formventilation.class.php';
$error=0;
// Langs
$langs->load("bills");
$langs->load("accountancy");
@ -41,7 +43,7 @@ $rowid = GETPOST('rowid', 'int');
// Security check
if (!$user->admin)
accessforbidden();
$accounting = new AccountingAccount($db);
// Action
@ -49,11 +51,11 @@ if ($action == 'add')
{
if (! GETPOST('cancel', 'alpha')) {
$sql = 'SELECT pcg_version FROM ' . MAIN_DB_PREFIX . 'accounting_system WHERE rowid=' . $conf->global->CHARTOFACCOUNTS;
dol_syslog('accountancy/admin/card.php:: $sql=' . $sql);
$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');
@ -61,17 +63,17 @@ if ($action == 'add')
$accounting->account_parent = GETPOST('account_parent', 'int');
$accounting->label = GETPOST('label', 'alpha');
$accounting->active = 1;
$res = $accounting->create($user);
if ($res == 0) {
} else {
if ($res == - 3) {
$_error = 1;
$error = 1;
$action = "create";
}
if ($res == - 4) {
$_error = 2;
$error = 2;
$action = "create";
}
}
@ -82,22 +84,22 @@ else if ($action == 'edit')
{
if (! GETPOST('cancel', 'alpha')) {
$result = $accounting->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', 'int');
$accounting->account_parent = GETPOST('account_parent', 'int');
$accounting->label = GETPOST('label', 'alpha');
$result = $accounting->update($user);
if ($result > 0) {
header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
exit();
@ -112,15 +114,15 @@ else if ($action == 'edit')
else if ($action == 'delete')
{
$result = $accounting->fetch($id);
if (! empty($accounting->id)) {
$result = $accounting->delete($user);
if ($result > 0) {
Header("Location: account.php");
}
}
if ($result < 0) {
setEventMessage($accounting->error, 'errors');
}
@ -137,7 +139,7 @@ $htmlacc = new FormVentilation($db);
if ($action == 'create')
{
print_fiche_titre($langs->trans('NewAccount'));
print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="add">';
@ -145,7 +147,7 @@ if ($action == 'create')
dol_fiche_head();
print '<table class="border" width="100%">';
print '<tr><td width="25%">' . $langs->trans("AccountNumber") . '</td>';
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
print '<tr><td>' . $langs->trans("Label") . '</td>';
@ -162,7 +164,7 @@ if ($action == 'create')
print '<td>';
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
print '</td></tr>';
print '</table>';
dol_fiche_end();
@ -172,35 +174,35 @@ if ($action == 'create')
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '">';
print '</div>';
print '</form>';
}
else if ($id)
{
$rowid = $id;
$account = $accounting->fetch($rowid);
if ($account > 0) {
dol_htmloutput_mesg($mesg);
$head = accounting_prepare_head($accounting);
if ($action == 'update')
{
$soc = new Societe($db);
if ($object->socid) {
$soc->fetch($object->socid);
}
dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
print '<form name="update" action="' . $_SERVER["PHP_SELF"] . '" method="POST">' . "\n";
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="edit">';
print '<input type="hidden" name="id" value="' . $id . '">';
print '<table class="border" width="100%">';
print '<tr><td width="25%">' . $langs->trans("AccountNumber") . '</td>';
print '<td><input name="account_number" size="30" value="' . $accounting->account_number . '"</td></tr>';
print '<tr><td>' . $langs->trans("Label") . '</td>';
@ -217,7 +219,7 @@ else if ($id)
print '<td>';
print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype');
print '</td></tr>';
print '</table>';
dol_fiche_end();
@ -227,71 +229,71 @@ else if ($id)
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" name="cancel" class="button" value="' . $langs->trans("Cancel") . '">';
print '</div>';
print '</form>';
}
else
{
$linkback = '<a href="../admin/account.php">' . $langs->trans("BackToChartofaccounts") . '</a>';
dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr');
print '<table class="border" width="100%">';
// Account number
print '<tr><td width="25%">' . $langs->trans("AccountNumber") . '</td>';
print '<td>' . $accounting->account_number . '</td>';
print '<td align="right" width="25%">' . $linkback . '</td></tr>';
print '<tr><td>' . $langs->trans("Label") . '</td>';
print '<td colspan="2">' . $accounting->label . '</td></tr>';
$accp = new AccountingAccount($db);
if (! empty($accounting->account_parent)) {
$accp->fetch($accounting->account_parent, '');
}
print '<tr><td>' . $langs->trans("Accountparent") . '</td>';
print '<td colspan="2">' . $accp->account_number . ' - ' . $accp->label . '</td></tr>';
print '<tr><td>' . $langs->trans("Pcgtype") . '</td>';
print '<td colspan="2">' . $accounting->pcg_type . '</td></tr>';
print '<tr><td>' . $langs->trans("Pcgsubtype") . '</td>';
print '<td colspan="2">' . $accounting->pcg_subtype . '</td></tr>';
print '<tr><td>' . $langs->trans("Active") . '</td>';
print '<td colspan="2">';
if (empty($accounting->active)) {
print img_picto($langs->trans("Disabled"), 'switch_off');
} else {
print img_picto($langs->trans("Activated"), 'switch_on');
}
print '</td></tr>';
print '</table>';
dol_fiche_end();
/*
* Barre d'actions
*/
print '<div class="tabsAction">';
if ($user->admin) {
print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $id . '">' . $langs->trans('Modify') . '</a>';
} else {
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Modify') . '</a>';
}
if ($user->admin) {
print '<a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $id . '">' . $langs->trans('Delete') . '</a>';
} else {
print '<a class="butActionRefused" href="#" title="' . dol_escape_htmltag($langs->trans("NotAllowed")) . '">' . $langs->trans('Delete') . '</a>';
}
print '</div>';
}
}

View File

@ -42,7 +42,7 @@ $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSe
<tr>
<td class="fieldrequired" width="20%"><?php echo $langs->trans("Ref"); ?></td>
<td><input name="ref" size="40" maxlength="32" value="<?php echo $object->ref; ?>">
<?php if ($_error == 1) echo $langs->trans("RefAlreadyExists"); ?>
<?php if ($refalreadyexists == 1) echo $langs->trans("RefAlreadyExists"); ?>
</td></tr>
<tr>

View File

@ -40,7 +40,7 @@ $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSe
<tr>
<td class="fieldrequired" width="20%"><?php echo $langs->trans("Ref"); ?></td>
<td><input name="ref" size="40" maxlength="32" value="<?php echo $object->ref; ?>">
<?php if ($_error == 1) echo $langs->trans("RefAlreadyExists"); ?>
<?php if ($refalreadyexists == 1) echo $langs->trans("RefAlreadyExists"); ?>
</td></tr>
<tr>

View File

@ -53,7 +53,9 @@ if (! empty($conf->stock->enabled)) $langs->load("stocks");
if (! empty($conf->facture->enabled)) $langs->load("bills");
if (! empty($conf->productbatch->enabled)) $langs->load("productbatch");
$mesg=''; $error=0; $errors=array(); $_error=0;
$mesg=''; $error=0; $errors=array();
$refalreadyexists=0;
$id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha');
@ -468,7 +470,7 @@ if (empty($reshook))
{
$db->rollback();
$_error++;
$refalreadyexists++;
$action = "";
$mesg=$langs->trans("ErrorProductAlreadyExists",$object->ref);
@ -477,7 +479,7 @@ if (empty($reshook))
$object->fetch($id);
}
else
{
{
$db->rollback();
if (count($object->errors))
{
@ -816,7 +818,7 @@ else
$tmpcode='';
if (! empty($modCodeProduct->code_auto)) $tmpcode=$modCodeProduct->getNextValue($object,$type);
print '<td class="fieldrequired" width="20%">'.$langs->trans("Ref").'</td><td colspan="3"><input name="ref" size="32" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref')?GETPOST('ref'):$tmpcode).'">';
if ($_error)
if ($refalreadyexists)
{
print $langs->trans("RefAlreadyExists");
}

View File

@ -43,7 +43,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
$langs->load("products");
$langs->load("bills");
$mesg=''; $error=0; $errors=array(); $_error=0;
$mesg=''; $error=0; $errors=array();
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');