Task # 559 : Modifications to store unitprice as in supplier prices
This commit is contained in:
parent
5586897f70
commit
7035ec42f1
@ -1226,9 +1226,10 @@ class Form
|
||||
$objp = $this->db->fetch_object($result);
|
||||
|
||||
if(!empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product
|
||||
$sql = "SELECT rowid, qty_min, price, price_ttc, remise_percent, remise";
|
||||
$sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
|
||||
$sql.= " WHERE fk_product_price=".$objp->price_rowid;
|
||||
$sql.= " ORDER BY quantity ASC";
|
||||
|
||||
dol_syslog(get_class($this)."::select_produits_do search price by qty sql=".$sql);
|
||||
$result2 = $this->db->query($sql);
|
||||
@ -1239,9 +1240,9 @@ class Form
|
||||
while ($nb_prices && $j < $nb_prices) {
|
||||
$objp2 = $this->db->fetch_object($result2);
|
||||
|
||||
$objp->quantity = $objp2->qty_min;
|
||||
$objp->quantity = $objp2->quantity;
|
||||
$objp->price = $objp2->price;
|
||||
$objp->unitprice = $objp2->price;
|
||||
$objp->unitprice = $objp2->unitprice;
|
||||
$objp->remise_percent = $objp2->remise_percent;
|
||||
$objp->remise = $objp2->remise;
|
||||
$objp->price_by_qty_rowid = $objp2->rowid;
|
||||
@ -1313,14 +1314,8 @@ class Form
|
||||
$opt.= (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0)?' pbq="'.$objp->price_by_qty_rowid.'"':'';
|
||||
if (! empty($conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock))
|
||||
{
|
||||
if ($objp->stock > 0)
|
||||
{
|
||||
$opt.= ' style="background-color:#32CD32; color:#F5F5F5;"';
|
||||
}
|
||||
else if ($objp->stock <= 0)
|
||||
{
|
||||
$opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
|
||||
}
|
||||
if ($objp->stock > 0) $opt.= ' class="product_line_stock_ok"';
|
||||
else if ($objp->stock <= 0) $opt.= ' class="product_line_stock_too_low"';
|
||||
}
|
||||
$opt.= '>';
|
||||
$opt.= $objp->ref.' - '.dol_trunc($label,32).' - ';
|
||||
@ -1382,21 +1377,21 @@ class Form
|
||||
$outdiscount=$objp->remise_percent;
|
||||
if ($objp->quantity == 1)
|
||||
{
|
||||
$opt.= price($objp->price).' '.$currencytext."/";
|
||||
$outval.= price($objp->price).' '.$currencytextnoent."/";
|
||||
$opt.= price($objp->unitprice).' '.$currencytext."/";
|
||||
$outval.= price($objp->unitprice).' '.$currencytextnoent."/";
|
||||
$opt.= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval.=$langs->transnoentities("Unit");
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt.= price($objp->price * $objp->quantity).' '.$currencytext."/".$objp->quantity;
|
||||
$outval.= price($objp->price * $objp->quantity).' '.$currencytextnoent."/".$objp->quantity;
|
||||
$opt.= price($objp->price).' '.$currencytext."/".$objp->quantity;
|
||||
$outval.= price($objp->price).' '.$currencytextnoent."/".$objp->quantity;
|
||||
$opt.= $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
||||
$outval.=$langs->transnoentities("Units");
|
||||
}
|
||||
|
||||
$outprice_ht=price($objp->price);
|
||||
$outprice_ttc=price($objp->price_ttc);
|
||||
$outprice_ht=price($objp->unitprice);
|
||||
$outprice_ttc=price($objp->unitprice * (1 + ($objp->tva_tx / 100)));
|
||||
$outpricebasetype=$objp->price_base_type;
|
||||
$outtva_tx=$objp->tva_tx;
|
||||
}
|
||||
@ -1573,8 +1568,12 @@ class Form
|
||||
$label = $objp->label;
|
||||
if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
|
||||
|
||||
$opt.=$objp->ref.' ('.$objp->ref_fourn.') - ';
|
||||
$outval.=$objRef.' ('.$objRefFourn.') - ';
|
||||
$opt.=$objp->ref;
|
||||
if (! empty($objp->idprodfournprice)) $opt.=' ('.$objp->ref_fourn.')';
|
||||
$opt.=' - ';
|
||||
$outval.=$objRef;
|
||||
if (! empty($objp->idprodfournprice)) $outval.=' ('.$objRefFourn.')';
|
||||
$outval.=' - ';
|
||||
$opt.=dol_trunc($objp->label,18).' - ';
|
||||
$outval.=dol_trunc($label,18).' - ';
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
--
|
||||
-- ============================================================================
|
||||
|
||||
ALTER TABLE llx_product_price_by_qty ADD UNIQUE INDEX uk_product_price_by_qty_level (fk_product_price, qty_min);
|
||||
ALTER TABLE llx_product_price_by_qty ADD UNIQUE INDEX uk_product_price_by_qty_level (fk_product_price, quantity);
|
||||
|
||||
ALTER TABLE llx_product_price_by_qty ADD INDEX idx_product_price_by_qty_fk_product_price (fk_product_price);
|
||||
|
||||
|
||||
@ -21,12 +21,12 @@
|
||||
|
||||
create table llx_product_price_by_qty
|
||||
(
|
||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||
rowid integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
fk_product_price integer NOT NULL,
|
||||
date_price timestamp,
|
||||
price double (24,8) DEFAULT 0,
|
||||
price_ttc double (24,8) DEFAULT 0,
|
||||
date_price timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
price double(24,8) DEFAULT 0,
|
||||
quantity double DEFAULT NULL,
|
||||
remise_percent double NOT NULL DEFAULT 0,
|
||||
remise double NOT NULL DEFAULT 0,
|
||||
qty_min real DEFAULT 1
|
||||
remise double NOT NULL DEFAULT 0,
|
||||
unitprice double(24,8) DEFAULT 0
|
||||
)ENGINE=innodb;
|
||||
|
||||
@ -74,7 +74,7 @@ if (! empty($action) && $action == 'fetch' && ! empty($id))
|
||||
// Price by qty
|
||||
if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1) // If we need a particular price related to qty
|
||||
{
|
||||
$sql = "SELECT price, price_ttc, qty_min, remise_percent";
|
||||
$sql = "SELECT price, unitprice, quantity, remise_percent";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty ";
|
||||
$sql.= " WHERE rowid=".$price_by_qty_rowid."";
|
||||
|
||||
@ -85,11 +85,11 @@ if (! empty($action) && $action == 'fetch' && ! empty($id))
|
||||
if ($objp)
|
||||
{
|
||||
$found=true;
|
||||
$outprice_ht=price($objp->price);
|
||||
$outprice_ttc=price($objp->price_ttc);
|
||||
$outprice_ht=price($objp->unitprice);
|
||||
$outprice_ttc=price($objp->unitprice * (1 + ($object->tva_tx / 100)));
|
||||
$outpricebasetype=$object->price_base_type;
|
||||
$outtva_tx=$object->tva_tx;
|
||||
$outqty=$objp->qty_min;
|
||||
$outqty=$objp->quantity;
|
||||
$outdiscount=$objp->remise_percent;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1203,10 +1203,10 @@ class Product extends CommonObject
|
||||
// Récuperation de la liste des prix selon qty si flag positionné
|
||||
if ($this->prices_by_qty[$i] == 1)
|
||||
{
|
||||
$sql = "SELECT rowid,price, price_ttc, qty_min, remise_percent, remise";
|
||||
$sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
|
||||
$sql.= " WHERE fk_product_price = '".$this->prices_by_qty_id[$i]."'";
|
||||
$sql.= " ORDER BY qty_min ASC";
|
||||
$sql.= " ORDER BY quantity ASC";
|
||||
$resultat=array();
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
@ -1216,8 +1216,8 @@ class Product extends CommonObject
|
||||
$resultat[$ii]=array();
|
||||
$resultat[$ii]["rowid"]=$result["rowid"];
|
||||
$resultat[$ii]["price"]= $result["price"];
|
||||
$resultat[$ii]["price_ttc"]= $result["price_ttc"];
|
||||
$resultat[$ii]["qty_min"]= $result["qty_min"];
|
||||
$resultat[$ii]["unitprice"]= $result["unitprice"];
|
||||
$resultat[$ii]["quantity"]= $result["quantity"];
|
||||
$resultat[$ii]["remise_percent"]= $result["remise_percent"];
|
||||
$resultat[$ii]["remise"]= $result["remise"];
|
||||
$ii++;
|
||||
@ -1256,10 +1256,10 @@ class Product extends CommonObject
|
||||
// Récuperation de la liste des prix selon qty si flag positionné
|
||||
if ($this->prices_by_qty[0] == 1)
|
||||
{
|
||||
$sql = "SELECT rowid,price, price_ttc, qty_min, remise_percent, remise";
|
||||
$sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty";
|
||||
$sql.= " WHERE fk_product_price = '".$this->prices_by_qty_id[0]."'";
|
||||
$sql.= " ORDER BY qty_min ASC";
|
||||
$sql.= " ORDER BY quantity ASC";
|
||||
$resultat=array();
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
@ -1269,8 +1269,8 @@ class Product extends CommonObject
|
||||
$resultat[$ii]=array();
|
||||
$resultat[$ii]["rowid"]=$result["rowid"];
|
||||
$resultat[$ii]["price"]= $result["price"];
|
||||
$resultat[$ii]["price_ttc"]= $result["price_ttc"];
|
||||
$resultat[$ii]["qty_min"]= $result["qty_min"];
|
||||
$resultat[$ii]["unitprice"]= $result["unitprice"];
|
||||
$resultat[$ii]["quantity"]= $result["quantity"];
|
||||
$resultat[$ii]["remise_percent"]= $result["remise_percent"];
|
||||
$resultat[$ii]["remise"]= $result["remise"];
|
||||
$ii++;
|
||||
|
||||
@ -108,6 +108,7 @@ else if ($action == 'delete' && $user->rights->produit->supprimer)
|
||||
/*****************************************************
|
||||
* Price by quantity
|
||||
*****************************************************/
|
||||
$error=0;
|
||||
if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity
|
||||
$result = $object->fetch($id);
|
||||
$level=GETPOST('level');
|
||||
@ -127,68 +128,47 @@ if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par qu
|
||||
$priceid=GETPOST('priceid');
|
||||
$newprice=price2num(GETPOST("price"),'MU');
|
||||
//$newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
|
||||
$qtymin=GETPOST('qty_min');
|
||||
$quantity=GETPOST('quantity');
|
||||
$remise_percent=price2num(GETPOST('remise_percent'));
|
||||
$remise=0; // TODO : allow dicsoun by amount when available on documents
|
||||
$remise=0; // TODO : allow dicsount by amount when available on documents
|
||||
|
||||
// Calcul des prix (HT et TTC)
|
||||
if ($newprice!='' || $newprice==0)
|
||||
if (empty($quantity))
|
||||
{
|
||||
$error++;
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'</div>';
|
||||
}
|
||||
if (empty($newprice))
|
||||
{
|
||||
$error++;
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'</div>';
|
||||
}
|
||||
if(!$error) {
|
||||
// Calcul du prix HT et du prix unitaire
|
||||
if ($object->price_base_type == 'TTC')
|
||||
{
|
||||
$price_ttc = price2num($newprice,'MU');
|
||||
$price = price2num($newprice) / (1 + ($object->tva_tx / 100));
|
||||
$price = price2num($price,'MU');
|
||||
|
||||
/*if ($newminprice!='' || $newminprice==0)
|
||||
{
|
||||
$price_min_ttc = price2num($newminprice,'MU');
|
||||
$price_min = price2num($newminprice) / (1 + ($object->tva_tx / 100));
|
||||
$price_min = price2num($price_min,'MU');
|
||||
}
|
||||
else
|
||||
{
|
||||
$price_min=0;
|
||||
$price_min_ttc=0;
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
$price = price2num($newprice,'MU');
|
||||
$price_ttc = price2num($newprice) * (1 + ($object->tva_tx / 100));
|
||||
$price_ttc = price2num($price_ttc,'MU');
|
||||
|
||||
/*if ($newminprice!='' || $newminprice==0)
|
||||
{
|
||||
$price_min = price2num($newminprice,'MU');
|
||||
$price_min_ttc = price2num($newminprice) * (1 + ($object->tva_tx / 100));
|
||||
$price_min_ttc = price2num($price_min_ttc,'MU');
|
||||
//print 'X'.$newminprice.'-'.$price_min;
|
||||
}
|
||||
else
|
||||
{
|
||||
$price_min=0;
|
||||
$price_min_ttc=0;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout / mise à jour
|
||||
if($rowid > 0) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
|
||||
$sql.= " price='".$price."',";
|
||||
$sql.= " price_ttc=".$price_ttc.",";
|
||||
$sql.= " qty_min=".$qtymin.",";
|
||||
$sql.= " remise_percent=".$remise_percent.",";
|
||||
$sql.= " remise=".$remise;
|
||||
$sql.= " WHERE rowid = ".GETPOST('rowid');
|
||||
|
||||
$result = $db->query($sql);
|
||||
} else {
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,price_ttc,qty_min,remise_percent,remise) values (";
|
||||
$sql.= $priceid.','.$price.','.$price_ttc.','.$qtymin.','.$remise_percent.','.$remise.')';
|
||||
|
||||
$result = $db->query($sql);
|
||||
$price = price2num($newprice,'MU');
|
||||
$unitPrice = price2num($price/$quantity,'MU');
|
||||
|
||||
// Ajout / mise à jour
|
||||
if($rowid > 0) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
|
||||
$sql.= " price='".$price."',";
|
||||
$sql.= " unitprice=".$unitPrice.",";
|
||||
$sql.= " quantity=".$quantity.",";
|
||||
$sql.= " remise_percent=".$remise_percent.",";
|
||||
$sql.= " remise=".$remise;
|
||||
$sql.= " WHERE rowid = ".GETPOST('rowid');
|
||||
|
||||
$result = $db->query($sql);
|
||||
} else {
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
|
||||
$sql.= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')';
|
||||
|
||||
$result = $db->query($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,7 +332,7 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("PriceByQuantityRange").' '.$i.'</td>';
|
||||
print '<td align="right">'.$langs->trans("HT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TTC").'</td>';
|
||||
print '<td align="right">'.$langs->trans("UnitPrice").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Discount").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
@ -363,7 +343,7 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">';
|
||||
print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">';
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td><input size="5" type="text" value="'.$prices['qty_min'].'" name="qty_min"></td>';
|
||||
print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
|
||||
print '<td align="right" colspan="2"><input size="10" type="text" value="'.$prices['price'].'" name="price"> '.$object->price_base_type.'</td>';
|
||||
//print '<td align="right"> </td>';
|
||||
print '<td align="right"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
@ -372,9 +352,9 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
print '</form>';
|
||||
} else {
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td>'.$prices['qty_min'].'</td>';
|
||||
print '<td>'.$prices['quantity'].'</td>';
|
||||
print '<td align="right">'.price($prices['price']).'</td>';
|
||||
print '<td align="right">'.price($prices['price_ttc']).'</td>';
|
||||
print '<td align="right">'.price($prices['unitprice']).'</td>';
|
||||
print '<td align="right">'.price($prices['remise_percent']).' %</td>';
|
||||
print '<td align="center">';
|
||||
if(($user->rights->produit->creer || $user->rights->service->creer)) {
|
||||
@ -395,7 +375,7 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">';
|
||||
print '<input type="hidden" value="0" name="rowid">';
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td><input size="5" type="text" value="1" name="qty_min"></td>';
|
||||
print '<td><input size="5" type="text" value="1" name="quantity"></td>';
|
||||
print '<td align="right" colspan="2"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.'</td>';
|
||||
//print '<td align="right"> </td>';
|
||||
print '<td align="right"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
|
||||
@ -456,7 +436,7 @@ else
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("PriceByQuantityRange").'</td>';
|
||||
print '<td align="right">'.$langs->trans("HT").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TTC").'</td>';
|
||||
print '<td align="right">'.$langs->trans("UnitPrice").'</td>';
|
||||
print '<td align="right">'.$langs->trans("Discount").'</td>';
|
||||
print '<td> </td>';
|
||||
print '</tr>';
|
||||
@ -467,7 +447,7 @@ else
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">';
|
||||
print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">';
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td><input size="5" type="text" value="'.$prices['qty_min'].'" name="qty_min"></td>';
|
||||
print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
|
||||
print '<td align="right" colspan="2"><input size="10" type="text" value="'.$prices['price'].'" name="price"> '.$object->price_base_type.'</td>';
|
||||
//print '<td align="right"> </td>';
|
||||
print '<td align="right"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
@ -476,9 +456,9 @@ else
|
||||
print '</form>';
|
||||
} else {
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td>'.$prices['qty_min'].'</td>';
|
||||
print '<td>'.$prices['quantity'].'</td>';
|
||||
print '<td align="right">'.price($prices['price']).'</td>';
|
||||
print '<td align="right">'.price($prices['price_ttc']).'</td>';
|
||||
print '<td align="right">'.price($prices['unitprice']).'</td>';
|
||||
print '<td align="right">'.price($prices['remise_percent']).' %</td>';
|
||||
print '<td align="center">';
|
||||
if(($user->rights->produit->creer || $user->rights->service->creer)) {
|
||||
@ -499,7 +479,7 @@ else
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">';
|
||||
print '<input type="hidden" value="0" name="rowid">';
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair':'impair').'">';
|
||||
print '<td><input size="5" type="text" value="1" name="qty_min"></td>';
|
||||
print '<td><input size="5" type="text" value="1" name="quantity"></td>';
|
||||
print '<td align="right" colspan="2"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.'</td>';
|
||||
//print '<td align="right"> </td>';
|
||||
print '<td align="right"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user