From a5056fe8dc0916434ef7ff7f032fa3aafccc6075 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Thu, 1 Sep 2011 16:47:37 +0000 Subject: [PATCH] Uniformize code --- htdocs/admin/taxes.php | 67 ++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/htdocs/admin/taxes.php b/htdocs/admin/taxes.php index f41f3c3dd79..9091ddf12eb 100644 --- a/htdocs/admin/taxes.php +++ b/htdocs/admin/taxes.php @@ -2,6 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2011 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,22 +28,17 @@ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); $langs->load('admin'); -$langs->load('compta'); -$langs->load('taxes'); if (!$user->admin) accessforbidden(); +$action = GETPOST("action"); /* - * View + * Actions */ -llxHeader(); - - // 0=normal, 1=option vat for services is on debit -$tax_mode = empty($conf->global->TAX_MODE)?0:$conf->global->TAX_MODE; // TAX_MODE=0 (most cases): // Buy Sell @@ -54,29 +50,44 @@ $tax_mode = empty($conf->global->TAX_MODE)?0:$conf->global->TAX_MODE; // Product On delivery On delivery // Service On invoice On invoice +$tax_mode = empty($conf->global->TAX_MODE)?0:$conf->global->TAX_MODE; -if ($_POST['action'] == 'settaxmode') +if ($action == 'settaxmode') { - $tax_mode = $_POST['tax_mode']; - if (! dolibarr_set_const($db, 'TAX_MODE', $tax_mode,'chaine',0,'',$conf->entity)) { print $db->error(); } - - if ($tax_mode == 0) - { - if (! dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', 'payment','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', 'payment','chaine',0,'',$conf->entity)) { print $db->error(); } - } - if ($tax_mode == 1) - { - if (! dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - if (! dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', 'invoice','chaine',0,'',$conf->entity)) { print $db->error(); } - } + $tax_mode = GETPOST("tax_mode"); + + $res = dolibarr_set_const($db, 'TAX_MODE', $tax_mode,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + + switch ($tax_mode) + { + case 0: + $value = 'payment'; + break; + case 1: + $value = 'invoice'; + break; + } + + $res = dolibarr_set_const($db, 'TAX_MODE_SELL_PRODUCT', 'invoice','chaine',0,'',$conf->entity); + $res = dolibarr_set_const($db, 'TAX_MODE_BUY_PRODUCT', 'invoice','chaine',0,'',$conf->entity); + $res = dolibarr_set_const($db, 'TAX_MODE_SELL_SERVICE', $value,'chaine',0,'',$conf->entity); + $res = dolibarr_set_const($db, 'TAX_MODE_BUY_SERVICE', $value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + + if (! $error) + { + $mesg = "".$langs->trans("SetupSaved").""; + } + else + { + $mesg = "".$langs->trans("Error").""; + } + } +/* if ($_POST['action'] == 'update' || $_POST['action'] == 'add') { if (! dolibarr_set_const($db, $_POST['constname'], $_POST['constvalue'], $typeconst[$_POST['consttype']], 0, isset($_POST['constnote']) ? $_POST['constnote'] : '',$conf->entity)); @@ -92,12 +103,14 @@ if ($_GET['action'] == 'delete') print $db->error(); } } +*/ /* - * Affichage page + * View */ +llxHeader(); $html=new Form($db); $linkback=''.$langs->trans("BackToModuleList").''; @@ -178,6 +191,8 @@ else print ''; } +dol_htmloutput_mesg($mesg); + $db->close(); llxFooter();