From 4e5ed08ff81a482e81f6590a5a55a745e50f0092 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Jun 2015 13:21:21 +0200 Subject: [PATCH] Clean code --- htdocs/accountancy/admin/card.php | 92 ++++++++++--------- .../canvas/product/tpl/card_create.tpl.php | 2 +- .../canvas/service/tpl/card_create.tpl.php | 2 +- htdocs/product/card.php | 10 +- htdocs/product/price.php | 2 +- 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index d555ed46092..51517993bb5 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -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 '
' . "\n"; print ''; print ''; @@ -145,7 +147,7 @@ if ($action == 'create') dol_fiche_head(); print ''; - + print ''; print ''; print ''; @@ -162,7 +164,7 @@ if ($action == 'create') print ''; - + print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); print '
'; dol_fiche_end(); @@ -172,35 +174,35 @@ if ($action == 'create') print '     '; print ''; print ''; - + print '
'; } 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 '
' . "\n"; print ''; print ''; print ''; - + print ''; - + print ''; print ''; print ''; @@ -217,7 +219,7 @@ else if ($id) print ''; - + print '
' . $langs->trans("AccountNumber") . '
' . $langs->trans("Label") . ''; print $htmlacc->select_pcgsubtype($accounting->pcg_subtype, 'pcg_subtype'); print '
'; dol_fiche_end(); @@ -227,71 +229,71 @@ else if ($id) print '     '; print ''; print ''; - + print '
'; } else { $linkback = '' . $langs->trans("BackToChartofaccounts") . ''; - + dol_fiche_head($head, 'card', $langs->trans('AccountAccounting'), 0, 'billr'); - + print ''; - + // Account number print ''; print ''; print ''; - + print ''; print ''; - + $accp = new AccountingAccount($db); if (! empty($accounting->account_parent)) { $accp->fetch($accounting->account_parent, ''); } print ''; print ''; - + print ''; print ''; - + print ''; print ''; - + print ''; print ''; - + print '
' . $langs->trans("AccountNumber") . '' . $accounting->account_number . '' . $linkback . '
' . $langs->trans("Label") . '' . $accounting->label . '
' . $langs->trans("Accountparent") . '' . $accp->account_number . ' - ' . $accp->label . '
' . $langs->trans("Pcgtype") . '' . $accounting->pcg_type . '
' . $langs->trans("Pcgsubtype") . '' . $accounting->pcg_subtype . '
' . $langs->trans("Active") . ''; - + if (empty($accounting->active)) { print img_picto($langs->trans("Disabled"), 'switch_off'); } else { print img_picto($langs->trans("Activated"), 'switch_on'); } - + print '
'; dol_fiche_end(); - + /* * Barre d'actions */ - + print '
'; - + if ($user->admin) { print '' . $langs->trans('Modify') . ''; } else { print '' . $langs->trans('Modify') . ''; } - + if ($user->admin) { print '' . $langs->trans('Delete') . ''; } else { print '' . $langs->trans('Delete') . ''; } - + print '
'; } } diff --git a/htdocs/product/canvas/product/tpl/card_create.tpl.php b/htdocs/product/canvas/product/tpl/card_create.tpl.php index b700764484d..3f5ebdcbc0b 100644 --- a/htdocs/product/canvas/product/tpl/card_create.tpl.php +++ b/htdocs/product/canvas/product/tpl/card_create.tpl.php @@ -42,7 +42,7 @@ $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSe trans("Ref"); ?> -trans("RefAlreadyExists"); ?> +trans("RefAlreadyExists"); ?> diff --git a/htdocs/product/canvas/service/tpl/card_create.tpl.php b/htdocs/product/canvas/service/tpl/card_create.tpl.php index 148b9164ac1..c9bb423d0a2 100644 --- a/htdocs/product/canvas/service/tpl/card_create.tpl.php +++ b/htdocs/product/canvas/service/tpl/card_create.tpl.php @@ -40,7 +40,7 @@ $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSe trans("Ref"); ?> -trans("RefAlreadyExists"); ?> +trans("RefAlreadyExists"); ?> diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 65845a5dd2c..beb01758aad 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -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 ''.$langs->trans("Ref").''; - if ($_error) + if ($refalreadyexists) { print $langs->trans("RefAlreadyExists"); } diff --git a/htdocs/product/price.php b/htdocs/product/price.php index b744d37ea06..d29df98ff31 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -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');