Fix: code optimization

This commit is contained in:
Regis Houssin 2012-08-31 09:25:27 +02:00
parent 18b7549c52
commit f81b696890
5 changed files with 44 additions and 68 deletions

View File

@ -635,6 +635,7 @@ else if ($action == "addline" && $user->rights->propal->creer)
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):'')));
$price_ht = GETPOST('price_ht');
$tva_tx = GETPOST('tva_tx');
if (empty($idprod) && GETPOST('type') < 0)
{
@ -674,8 +675,9 @@ else if ($action == "addline" && $user->rights->propal->creer)
{
$pu_ht=price2num($price_ht, 'MU');
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$tva_tx=str_replace('*','', GETPOST('tva_tx'));
$tva_npr=preg_match('/\*/', GETPOST('tva_tx'))?1:0;
$tva_npr=(preg_match('/\*/', $tva_tx)?1:0);
$tva_tx=str_replace('*','', $tva_tx);
$desc = $product_desc;
}
else
{
@ -711,13 +713,6 @@ else if ($action == "addline" && $user->rights->propal->creer)
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
}
}
}
if (GETPOST('usenewaddlineform')) {
$desc = $product_desc;
} else {
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
@ -747,19 +742,18 @@ else if ($action == "addline" && $user->rights->propal->creer)
}
else
{
$pu_ht= $price_ht;
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$rate=GETPOST('tva_tx')?GETPOST('tva_tx'):GETPOST('np_tva_tx');
$tva_tx=str_replace('*','',$rate);
$tva_npr=preg_match('/\*/',$rate)?1:0;
$label=(GETPOST('product_label')?GETPOST('product_label'):'');
$desc=$product_desc;
$type=GETPOST('type');
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
$tva_npr = (preg_match('/\*/', $tva_tx)?1:0);
$tva_tx = str_replace('*', '', $tva_tx);
$label = (GETPOST('product_label')?GETPOST('product_label'):'');
$desc = $product_desc;
$type = GETPOST('type');
}
// Margin
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):(GETPOST('np_fournprice')?GETPOST('np_fournprice'):''));
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):(GETPOST('np_buying_price')?GETPOST('np_buying_price'):''));
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
// Local Taxes
$localtax1_tx= get_localtax($tva_tx, 1, $object->client);
@ -832,8 +826,6 @@ else if ($action == "addline" && $user->rights->propal->creer)
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']);
unset($_POST['np_fournprice']);
unset($_POST['np_buying_price']);
}
else
{

View File

@ -527,6 +527,7 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):'')));
$price_ht = GETPOST('price_ht');
$tva_tx = GETPOST('tva_tx');
if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0))
{
@ -574,12 +575,13 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$label = ((GETPOST('product_label') && GETPOST('product_label')!=$prod->label)?GETPOST('product_label'):'');
// Update if prices fields are defined
if (GETPOST('usenewaddlineform') && isset($price_ht))
if (GETPOST('usenewaddlineform'))
{
$pu_ht=price2num($price_ht, 'MU');
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$tva_tx=str_replace('*','', GETPOST('tva_tx'));
$tva_npr=preg_match('/\*/', GETPOST('tva_tx'))?1:0;
$tva_npr=(preg_match('/\*/', $tva_tx)?1:0);
$tva_tx=str_replace('*','', $tva_tx);
$desc = $product_desc;
}
else
{
@ -615,13 +617,6 @@ else if ($action == 'addline' && $user->rights->commande->creer)
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
}
}
}
if (GETPOST('usenewaddlineform')) {
$desc = $product_desc;
} else {
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
@ -651,19 +646,18 @@ else if ($action == 'addline' && $user->rights->commande->creer)
}
else
{
$pu_ht=($price_ht?$price_ht:$np_price);
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$rate=GETPOST('tva_tx')?GETPOST('tva_tx'):GETPOST('np_tva_tx');
$tva_tx=str_replace('*','',$rate);
$tva_npr=preg_match('/\*/',$rate)?1:0;
$label=(GETPOST('product_label')?GETPOST('product_label'):'');
$desc=$product_desc;
$type=GETPOST('type');
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
$tva_npr = (preg_match('/\*/', $tva_tx)?1:0);
$tva_tx = str_replace('*', '', $tva_tx);
$label = (GETPOST('product_label')?GETPOST('product_label'):'');
$desc = $product_desc;
$type = GETPOST('type');
}
// Margin
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):(GETPOST('np_fournprice')?GETPOST('np_fournprice'):''));
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):(GETPOST('np_buying_price')?GETPOST('np_buying_price'):''));
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
// Local Taxes
$localtax1_tx= get_localtax($tva_tx, 1, $object->client);
@ -741,8 +735,6 @@ else if ($action == 'addline' && $user->rights->commande->creer)
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']);
unset($_POST['np_fournprice']);
unset($_POST['np_buying_price']);
}
else
{

View File

@ -950,6 +950,7 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
$idprod=GETPOST('idprod', 'int');
$product_desc = (GETPOST('product_desc')?GETPOST('product_desc'):(GETPOST('np_desc')?GETPOST('np_desc'):(GETPOST('dp_desc')?GETPOST('dp_desc'):'')));
$price_ht = GETPOST('price_ht');
$tva_tx = GETPOST('tva_tx');
if ((empty($idprod) || GETPOST('usenewaddlineform')) && ($price_ht < 0) && (GETPOST('qty') < 0))
{
@ -1009,8 +1010,9 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
{
$pu_ht=price2num($price_ht, 'MU');
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$tva_tx=str_replace('*','', GETPOST('tva_tx'));
$tva_npr=preg_match('/\*/', GETPOST('tva_tx'))?1:0;
$tva_npr=(preg_match('/\*/', $tva_tx))?1:0);
$tva_tx=str_replace('*','', $tva_tx);
$desc = $product_desc;
}
else
{
@ -1046,13 +1048,6 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
}
}
}
if (GETPOST('usenewaddlineform')) {
$desc = $product_desc;
} else {
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
@ -1092,19 +1087,18 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
}
else
{
$pu_ht=($price_ht?$price_ht:$np_price);
$pu_ttc=price2num(GETPOST('price_ttc'), 'MU');
$rate=GETPOST('tva_tx')?GETPOST('tva_tx'):GETPOST('np_tva_tx');
$tva_tx=str_replace('*','',$rate);
$tva_npr=preg_match('/\*/',$rate)?1:0;
$label=(GETPOST('product_label')?GETPOST('product_label'):'');
$desc=$product_desc;
$type=GETPOST('type');
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
$tva_npr = (preg_match('/\*/', $tva_tx)?1:0);
$tva_tx = str_replace('*', '', $tva_tx);
$label = (GETPOST('product_label')?GETPOST('product_label'):'');
$desc = $product_desc;
$type = GETPOST('type');
}
// Margin
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):(GETPOST('np_fournprice')?GETPOST('np_fournprice'):''));
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):(GETPOST('np_buying_price')?GETPOST('np_buying_price'):''));
$fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):'');
$buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):'');
// Local Taxes
$localtax1_tx= get_localtax($tva_tx, 1, $object->client);
@ -1183,8 +1177,6 @@ else if (($action == 'addline' || $action == 'addline_predef') && $user->rights-
// old method
unset($_POST['np_desc']);
unset($_POST['dp_desc']);
unset($_POST['np_fournprice']);
unset($_POST['np_buying_price']);
}
else
{

View File

@ -77,7 +77,7 @@ if (! empty($conf->margin->enabled)) {
<td align="right">
<?php
if ($seller->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0';
else echo $form->load_tva('np_tva_tx', (isset($_POST["np_tva_tx"])?$_POST["np_tva_tx"]:-1), $seller, $buyer);
else echo $form->load_tva('tva_tx', (isset($_POST["tva_tx"])?$_POST["tva_tx"]:-1), $seller, $buyer);
?>
</td>
<td align="right"><input type="text" size="5" name="price_ht" value="<?php echo (isset($_POST["price_ht"])?$_POST["price_ht"]:''); ?>"></td>
@ -87,7 +87,7 @@ if (! empty($conf->margin->enabled)) {
$colspan = 4;
if (! empty($conf->margin->enabled)) {
?>
<td align="right"><input type="text" size="5" name="np_buying_price" value="<?php echo (isset($_POST["np_buying_price"])?$_POST["np_buying_price"]:''); ?>"></td>
<td align="right"><input type="text" size="5" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>"></td>
<?php
if($conf->global->DISPLAY_MARGIN_RATES)
$colspan++;

View File

@ -96,8 +96,8 @@ $colspan = 4;
if (! empty($conf->margin->enabled)) {
?>
<td align="right">
<select id="np_fournprice" name="np_fournprice" style="display: none;"></select>
<input type="text" size="5" id="np_buying_price" name="np_buying_price" value="<?php echo (isset($_POST["np_buying_price"])?$_POST["np_buying_price"]:''); ?>">
<select id="fournprice" name="fournprice" style="display: none;"></select>
<input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td>
<?php
if($conf->global->DISPLAY_MARGIN_RATES)