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

View File

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

View File

@ -40,7 +40,7 @@ $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSe
<tr> <tr>
<td class="fieldrequired" width="20%"><?php echo $langs->trans("Ref"); ?></td> <td class="fieldrequired" width="20%"><?php echo $langs->trans("Ref"); ?></td>
<td><input name="ref" size="40" maxlength="32" value="<?php echo $object->ref; ?>"> <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> </td></tr>
<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->facture->enabled)) $langs->load("bills");
if (! empty($conf->productbatch->enabled)) $langs->load("productbatch"); 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'); $id=GETPOST('id', 'int');
$ref=GETPOST('ref', 'alpha'); $ref=GETPOST('ref', 'alpha');
@ -468,7 +470,7 @@ if (empty($reshook))
{ {
$db->rollback(); $db->rollback();
$_error++; $refalreadyexists++;
$action = ""; $action = "";
$mesg=$langs->trans("ErrorProductAlreadyExists",$object->ref); $mesg=$langs->trans("ErrorProductAlreadyExists",$object->ref);
@ -477,7 +479,7 @@ if (empty($reshook))
$object->fetch($id); $object->fetch($id);
} }
else else
{ {
$db->rollback(); $db->rollback();
if (count($object->errors)) if (count($object->errors))
{ {
@ -816,7 +818,7 @@ else
$tmpcode=''; $tmpcode='';
if (! empty($modCodeProduct->code_auto)) $tmpcode=$modCodeProduct->getNextValue($object,$type); 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).'">'; 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"); print $langs->trans("RefAlreadyExists");
} }

View File

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