Début ajout gestion du HT et TTC avec l'option multiprix
Optimisation de la fonction update_price
This commit is contained in:
parent
a4c3e07689
commit
0852a31f36
@ -125,10 +125,10 @@ class Product
|
|||||||
* \return void
|
* \return void
|
||||||
*/
|
*/
|
||||||
function SetSellPrice($price, $base_type='HT')
|
function SetSellPrice($price, $base_type='HT')
|
||||||
{
|
{
|
||||||
$price = ereg_replace(" ","", $price);
|
$price = ereg_replace(" ","", $price);
|
||||||
$price = ereg_replace(",",".", $price);
|
$price = ereg_replace(",",".", $price);
|
||||||
|
|
||||||
$this->price = $price;
|
$this->price = $price;
|
||||||
|
|
||||||
$this->price_base_type = $base_type;
|
$this->price_base_type = $base_type;
|
||||||
@ -514,26 +514,28 @@ class Product
|
|||||||
global $conf;
|
global $conf;
|
||||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$queryError = false;
|
$queryError = false;
|
||||||
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
||||||
{
|
|
||||||
if($this->multiprices["$i"] != "")
|
|
||||||
{
|
{
|
||||||
// On supprimme ligne existante au cas ou
|
if($this->multiprices["$i"] != "")
|
||||||
$sql_multiprix = "DELETE FROM ".MAIN_DB_PREFIX."product_price ";
|
{
|
||||||
$sql_multiprix .= "WHERE date_price = now()";
|
// On supprimme ligne existante au cas ou
|
||||||
$sql_multiprix .= " and fk_product = ".$this->id;
|
$sql_multiprix = "DELETE FROM ".MAIN_DB_PREFIX."product_price ";
|
||||||
$sql_multiprix .= " and fk_user_author = ".$user->id;
|
$sql_multiprix .= "WHERE date_price = now()";
|
||||||
$sql_multiprix .= " and price = ".price2num($this->multiprices["$i"]);
|
$sql_multiprix .= " and fk_product = ".$this->id;
|
||||||
|
$sql_multiprix .= " and fk_user_author = ".$user->id;
|
||||||
|
$sql_multiprix .= " and price = ".price2num($this->multiprices["$i"]);
|
||||||
|
|
||||||
$this->db->query($sql_multiprix);
|
$this->db->query($sql_multiprix);
|
||||||
|
|
||||||
// On ajoute nouveau tarif
|
// On ajoute nouveau tarif
|
||||||
$sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price) ";
|
$sql_multiprix = "INSERT INTO ".MAIN_DB_PREFIX."product_price(date_price,fk_product,fk_user_author,price_level,price,price_base_type) ";
|
||||||
$sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]);
|
$sql_multiprix .= " VALUES(now(),".$this->id.",".$user->id.",".$i.",".price2num($this->multiprices["$i"]).",'".$this->price_base_type["$i"]."'";
|
||||||
$sql_multiprix .= ")";
|
$sql_multiprix .= ")";
|
||||||
if (! $this->db->query($sql_multiprix) )
|
if (! $this->db->query($sql_multiprix) )
|
||||||
$queryError = true;
|
{
|
||||||
|
$queryError = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strlen(trim($this->price)) > 0 )
|
if (strlen(trim($this->price)) > 0 )
|
||||||
@ -746,76 +748,47 @@ class Product
|
|||||||
{
|
{
|
||||||
//multiprix
|
//multiprix
|
||||||
global $conf;
|
global $conf;
|
||||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
|
||||||
{
|
|
||||||
if (strlen(trim($this->price)) > 0 )
|
|
||||||
{
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
|
||||||
$sql .= " SET price = " . price2num($this->price);
|
|
||||||
$sql .= " WHERE rowid = " . $id;
|
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
if (strlen(trim($this->price)) > 0 )
|
||||||
|
{
|
||||||
|
if ($this->price_base_type == 'TTC')
|
||||||
{
|
{
|
||||||
$this->_log_price($user);
|
$price_ttc = $this->price;
|
||||||
return 1;
|
$this->price = $this->price / (1 + ($this->tva_tx / 100));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
$price_ttc = $this->price * (1 + ($this->tva_tx / 100));
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(count($this->multiprices) > 0)
|
|
||||||
{
|
|
||||||
$this->_log_price($user);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error = "Prix saisi invalide.";
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (strlen(trim($this->price)) > 0 )
|
|
||||||
{
|
|
||||||
if ($this->price_base_type == 'TTC')
|
|
||||||
{
|
|
||||||
$price_ttc = $this->price;
|
|
||||||
$this->price = $this->price / (1 + ($this->tva_tx / 100));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$price_ttc = $this->price * (1 + ($this->tva_tx / 100));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
||||||
|
$sql .= " SET price = " . price2num($this->price);
|
||||||
|
$sql .= " , price_base_type='".$this->price_base_type."'";
|
||||||
|
$sql .= " , price_ttc='".$price_ttc."'";
|
||||||
|
$sql .= " WHERE rowid = " . $id;
|
||||||
|
|
||||||
|
if ( $this->db->query($sql) )
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
|
||||||
$sql .= " SET price = " . price2num($this->price);
|
|
||||||
$sql .= " , price_base_type='".$this->price_base_type."'";
|
|
||||||
$sql .= " , price_ttc='".$price_ttc."'";
|
|
||||||
|
|
||||||
$sql .= " WHERE rowid = " . $id;
|
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
{
|
{
|
||||||
$this->_log_price($user);
|
$this->_log_price($user);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if(($conf->global->PRODUIT_MULTIPRICES == 1) && (count($this->multiprices) > 0))
|
||||||
{
|
{
|
||||||
$this->error = "Prix saisi invalide.";
|
$this->_log_price($user);
|
||||||
return -2;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
|
$this->error = "Prix saisi invalide.";
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -62,15 +62,20 @@ if ($_POST["action"] == 'update_price' &&
|
|||||||
|
|
||||||
// MultiPrix
|
// MultiPrix
|
||||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
||||||
{
|
{
|
||||||
if($_POST["price_".$i])
|
if($_POST["price_".$i])
|
||||||
$product->multiprices["$i"]=ereg_replace(" ","",$_POST["price_".$i]);
|
{
|
||||||
else
|
//$product->SetSellprice($_POST["price_".$i], $_POST["price_base_type_".$i]);
|
||||||
$product->multiprices["$i"] = "";
|
$product->multiprices["$i"] = $product->SetSellprice($_POST["price_".$i], $_POST["price_base_type_".$i]);
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
$product->multiprices["$i"] = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( $product->update_price($product->id, $user) > 0 )
|
if ( $product->update_price($product->id, $user) > 0 )
|
||||||
{
|
{
|
||||||
@ -187,7 +192,9 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
|
|||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
print '<tr><td width="15%">'.$langs->trans('SellingPrice').' 1</td><td><input name="price" size="10" value="'.price($product->price).'"></td></tr>';
|
print '<tr><td width="15%">'.$langs->trans('SellingPrice').' 1</td><td><input name="price" size="10" value="'.price($product->price).'">';
|
||||||
|
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
|
||||||
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -216,8 +223,9 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
|
|||||||
print '<input type="hidden" name="action" value="update_price">';
|
print '<input type="hidden" name="action" value="update_price">';
|
||||||
print '<input type="hidden" name="id" value="'.$product->id.'">';
|
print '<input type="hidden" name="id" value="'.$product->id.'">';
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
print '<tr><td width="15%">'.$langs->trans("SellingPrice").' '.$i.'</td><td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'"></td>';
|
print '<tr><td width="15%">'.$langs->trans("SellingPrice").' '.$i.'</td><td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'">';
|
||||||
print '</tr>';
|
print $html->select_PriceBaseType($product->price_base_type, "price_base_type_".$i);
|
||||||
|
print '</td></tr>';
|
||||||
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"> ';
|
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"> ';
|
||||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
|
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user