Task # 559 : Add possibility to define a discount for min quantity on supplier product prices
This commit is contained in:
parent
c3dd8348fe
commit
1d21f24fa7
@ -44,6 +44,8 @@ class ProductFournisseur extends Product
|
|||||||
var $fourn_ref; // ref supplier
|
var $fourn_ref; // ref supplier
|
||||||
var $fourn_qty; // quantity for price
|
var $fourn_qty; // quantity for price
|
||||||
var $fourn_price; // price for quantity
|
var $fourn_price; // price for quantity
|
||||||
|
var $fourn_remise_percent; // discount for quantity (percent)
|
||||||
|
var $fourn_remise; // discount for quantity (amount)
|
||||||
var $product_fourn_id; // supplier id
|
var $product_fourn_id; // supplier id
|
||||||
var $fk_availability; // availability delay
|
var $fk_availability; // availability delay
|
||||||
var $fourn_unitprice;
|
var $fourn_unitprice;
|
||||||
@ -133,18 +135,20 @@ class ProductFournisseur extends Product
|
|||||||
/**
|
/**
|
||||||
* Modify the purchase price for a supplier
|
* Modify the purchase price for a supplier
|
||||||
*
|
*
|
||||||
* @param int $qty Min quantity for which price is valid
|
* @param int $qty Min quantity for which price is valid
|
||||||
* @param float $buyprice Purchase price for the quantity min
|
* @param float $buyprice Purchase price for the quantity min
|
||||||
* @param User $user Object user user made changes
|
* @param User $user Object user user made changes
|
||||||
* @param string $price_base_type HT or TTC
|
* @param string $price_base_type HT or TTC
|
||||||
* @param Societe $fourn Supplier
|
* @param Societe $fourn Supplier
|
||||||
* @param int $availability Product availability
|
* @param int $availability Product availability
|
||||||
* @param string $ref_fourn Supplier ref
|
* @param string $ref_fourn Supplier ref
|
||||||
* @param float $tva_tx VAT rate
|
* @param float $tva_tx VAT rate
|
||||||
* @param string $charges costs affering to product
|
* @param string $charges costs affering to product
|
||||||
|
* @param float $remise_percent Discount regarding qty (percent)
|
||||||
|
* @param float $remise Discount regarding qty (amount)
|
||||||
* @return int >0 if KO, >0 if OK
|
* @return int >0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0)
|
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0)
|
||||||
{
|
{
|
||||||
global $conf,$mysoc;
|
global $conf,$mysoc;
|
||||||
|
|
||||||
@ -177,6 +181,8 @@ class ProductFournisseur extends Product
|
|||||||
$sql.= " SET fk_user = " . $user->id." ,";
|
$sql.= " SET fk_user = " . $user->id." ,";
|
||||||
$sql.= " price = ".price2num($buyprice).",";
|
$sql.= " price = ".price2num($buyprice).",";
|
||||||
$sql.= " quantity = ".$qty.",";
|
$sql.= " quantity = ".$qty.",";
|
||||||
|
$sql.= " remise_percent = ".$remise_percent.",";
|
||||||
|
$sql.= " remise = ".$remise.",";
|
||||||
$sql.= " unitprice = ".$unitBuyPrice.",";
|
$sql.= " unitprice = ".$unitBuyPrice.",";
|
||||||
$sql.= " unitcharges = ".$unitCharges.",";
|
$sql.= " unitcharges = ".$unitCharges.",";
|
||||||
$sql.= " tva_tx = ".$tva_tx.",";
|
$sql.= " tva_tx = ".$tva_tx.",";
|
||||||
@ -211,7 +217,7 @@ class ProductFournisseur extends Product
|
|||||||
{
|
{
|
||||||
// Add price for this quantity to supplier
|
// Add price for this quantity to supplier
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
||||||
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, unitprice, tva_tx, fk_availability, entity)";
|
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, fk_availability, entity)";
|
||||||
$sql.= " values('".$this->db->idate($now)."',";
|
$sql.= " values('".$this->db->idate($now)."',";
|
||||||
$sql.= " ".$this->id.",";
|
$sql.= " ".$this->id.",";
|
||||||
$sql.= " ".$fourn->id.",";
|
$sql.= " ".$fourn->id.",";
|
||||||
@ -219,6 +225,8 @@ class ProductFournisseur extends Product
|
|||||||
$sql.= " ".$user->id.",";
|
$sql.= " ".$user->id.",";
|
||||||
$sql.= " ".price2num($buyprice).",";
|
$sql.= " ".price2num($buyprice).",";
|
||||||
$sql.= " ".$qty.",";
|
$sql.= " ".$qty.",";
|
||||||
|
$sql.= " ".$remise_percent.",";
|
||||||
|
$sql.= " ".$remise.",";
|
||||||
$sql.= " ".$unitBuyPrice.",";
|
$sql.= " ".$unitBuyPrice.",";
|
||||||
$sql.= " ".$tva_tx.",";
|
$sql.= " ".$tva_tx.",";
|
||||||
$sql.= " ".$availability.",";
|
$sql.= " ".$availability.",";
|
||||||
@ -280,7 +288,7 @@ class ProductFournisseur extends Product
|
|||||||
*/
|
*/
|
||||||
function fetch_product_fournisseur_price($rowid)
|
function fetch_product_fournisseur_price($rowid)
|
||||||
{
|
{
|
||||||
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.fk_availability,";
|
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability,";
|
||||||
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges";
|
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||||
@ -297,6 +305,8 @@ class ProductFournisseur extends Product
|
|||||||
$this->fourn_price = $obj->price;
|
$this->fourn_price = $obj->price;
|
||||||
$this->fourn_charges = $obj->charges;
|
$this->fourn_charges = $obj->charges;
|
||||||
$this->fourn_qty = $obj->quantity;
|
$this->fourn_qty = $obj->quantity;
|
||||||
|
$this->fourn_remise_percent = $obj->remise_percent;
|
||||||
|
$this->fourn_remise = $obj->remise;
|
||||||
$this->fourn_unitprice = $obj->unitprice;
|
$this->fourn_unitprice = $obj->unitprice;
|
||||||
$this->fourn_unitcharges = $obj->unitcharges;
|
$this->fourn_unitcharges = $obj->unitcharges;
|
||||||
$this->tva_tx = $obj->tva_tx;
|
$this->tva_tx = $obj->tva_tx;
|
||||||
@ -331,7 +341,7 @@ class ProductFournisseur extends Product
|
|||||||
|
|
||||||
$sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
|
$sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
|
||||||
$sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn, pfp.fk_product as product_fourn_id,";
|
$sql.= " pfp.rowid as product_fourn_pri_id, pfp.ref_fourn, pfp.fk_product as product_fourn_id,";
|
||||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges";
|
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= " WHERE pfp.entity IN (".getEntity('product', 1).")";
|
$sql.= " WHERE pfp.entity IN (".getEntity('product', 1).")";
|
||||||
@ -356,6 +366,8 @@ class ProductFournisseur extends Product
|
|||||||
$prodfourn->fourn_ref = $record["ref_fourn"];
|
$prodfourn->fourn_ref = $record["ref_fourn"];
|
||||||
$prodfourn->fourn_price = $record["price"];
|
$prodfourn->fourn_price = $record["price"];
|
||||||
$prodfourn->fourn_qty = $record["quantity"];
|
$prodfourn->fourn_qty = $record["quantity"];
|
||||||
|
$prodfourn->fourn_remise_percent = $record["remise_percent"];
|
||||||
|
$prodfourn->fourn_remise = $record["remise"];
|
||||||
$prodfourn->fourn_unitprice = $record["unitprice"];
|
$prodfourn->fourn_unitprice = $record["unitprice"];
|
||||||
$prodfourn->fourn_charges = $record["charges"];
|
$prodfourn->fourn_charges = $record["charges"];
|
||||||
$prodfourn->fourn_unitcharges = $record["unitcharges"];
|
$prodfourn->fourn_unitcharges = $record["unitcharges"];
|
||||||
@ -406,6 +418,8 @@ class ProductFournisseur extends Product
|
|||||||
$this->fourn_ref = '';
|
$this->fourn_ref = '';
|
||||||
$this->fourn_price = '';
|
$this->fourn_price = '';
|
||||||
$this->fourn_qty = '';
|
$this->fourn_qty = '';
|
||||||
|
$this->fourn_remise_percent = '';
|
||||||
|
$this->fourn_remise = '';
|
||||||
$this->fourn_unitprice = '';
|
$this->fourn_unitprice = '';
|
||||||
$this->fourn_id = '';
|
$this->fourn_id = '';
|
||||||
$this->fourn_name = '';
|
$this->fourn_name = '';
|
||||||
@ -431,9 +445,11 @@ class ProductFournisseur extends Product
|
|||||||
$this->fourn_ref = $record["ref_fourn"];
|
$this->fourn_ref = $record["ref_fourn"];
|
||||||
$this->fourn_price = $record["price"];
|
$this->fourn_price = $record["price"];
|
||||||
$this->fourn_qty = $record["quantity"];
|
$this->fourn_qty = $record["quantity"];
|
||||||
|
$this->fourn_remise_percent = $record["remise_percent"];
|
||||||
|
$this->fourn_remise = $record["remise"];
|
||||||
$this->fourn_unitprice = $record["unitprice"];
|
$this->fourn_unitprice = $record["unitprice"];
|
||||||
$this->fourn_charges = $record["charges"];
|
$this->fourn_charges = $record["charges"];
|
||||||
$this->fourn_unitcharges = $record["unitcharges"];
|
$this->fourn_unitcharges = $record["unitcharges"];
|
||||||
$this->fourn_tva_tx = $record["tva_tx"];
|
$this->fourn_tva_tx = $record["tva_tx"];
|
||||||
$this->fourn_id = $record["fourn_id"];
|
$this->fourn_id = $record["fourn_id"];
|
||||||
$this->fourn_name = $record["supplier_name"];
|
$this->fourn_name = $record["supplier_name"];
|
||||||
|
|||||||
@ -742,3 +742,7 @@ insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype,
|
|||||||
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (436,'PCG99-BASE','PROD', 'XXXXXX', '791','79', 'Transferts de charges d''exploitation ', '1');
|
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (436,'PCG99-BASE','PROD', 'XXXXXX', '791','79', 'Transferts de charges d''exploitation ', '1');
|
||||||
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (437,'PCG99-BASE','PROD', 'XXXXXX', '796','79', 'Transferts de charges financières', '1');
|
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (437,'PCG99-BASE','PROD', 'XXXXXX', '796','79', 'Transferts de charges financières', '1');
|
||||||
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (438,'PCG99-BASE','PROD', 'XXXXXX', '797','79', 'Transferts de charges exceptionnelles', '1');
|
insert into llx_accountingaccount (rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number, account_parent, label, active) VALUES (438,'PCG99-BASE','PROD', 'XXXXXX', '797','79', 'Transferts de charges exceptionnelles', '1');
|
||||||
|
|
||||||
|
-- Add discount in product supplier price
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN remise_percent DOUBLE NOT NULL DEFAULT 0 AFTER quantity;
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN remise DOUBLE NOT NULL DEFAULT 0 AFTER remise_percent;
|
||||||
|
|||||||
@ -146,6 +146,7 @@ ProductSpecial=Special
|
|||||||
QtyMin=Quantity minimum
|
QtyMin=Quantity minimum
|
||||||
PriceQty=Price for this quantity
|
PriceQty=Price for this quantity
|
||||||
PriceQtyMin=Price quantity min.
|
PriceQtyMin=Price quantity min.
|
||||||
|
DiscountQtyMin=Discount quantity min.
|
||||||
NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product
|
NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product
|
||||||
NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this product
|
NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this product
|
||||||
RecordedProducts=Products recorded
|
RecordedProducts=Products recorded
|
||||||
|
|||||||
@ -146,6 +146,7 @@ ProductSpecial=Special
|
|||||||
QtyMin=Quantité minimum
|
QtyMin=Quantité minimum
|
||||||
PriceQty=Prix pour la quantité
|
PriceQty=Prix pour la quantité
|
||||||
PriceQtyMin=Prix quantité min.
|
PriceQtyMin=Prix quantité min.
|
||||||
|
DiscountQtyMin=Remise quantité min.
|
||||||
NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit
|
NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit
|
||||||
NoSupplierPriceDefinedForThisProduct=Aucun prix/qté fournisseur défini pour ce produit
|
NoSupplierPriceDefinedForThisProduct=Aucun prix/qté fournisseur défini pour ce produit
|
||||||
RecordedProducts=Produits en vente
|
RecordedProducts=Produits en vente
|
||||||
|
|||||||
@ -94,6 +94,7 @@ if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
|
|||||||
$ref_fourn=GETPOST("ref_fourn");
|
$ref_fourn=GETPOST("ref_fourn");
|
||||||
if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn");
|
if (empty($ref_fourn)) $ref_fourn=GETPOST("search_ref_fourn");
|
||||||
$quantity=GETPOST("qty");
|
$quantity=GETPOST("qty");
|
||||||
|
$remise_percent=price2num(GETPOST('remise_percent','alpha'));
|
||||||
$tva_tx=price2num(GETPOST('tva_tx','alpha'));
|
$tva_tx=price2num(GETPOST('tva_tx','alpha'));
|
||||||
|
|
||||||
if (empty($quantity))
|
if (empty($quantity))
|
||||||
@ -153,10 +154,10 @@ if ($action == 'updateprice' && GETPOST('cancel') <> $langs->trans("Cancel"))
|
|||||||
$supplier=new Fournisseur($db);
|
$supplier=new Fournisseur($db);
|
||||||
$result=$supplier->fetch($id_fourn);
|
$result=$supplier->fetch($id_fourn);
|
||||||
|
|
||||||
if (isset($_POST['ref_fourn_price_id']))
|
if (isset($_POST['ref_fourn_price_id']))
|
||||||
$product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
|
$product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
|
||||||
|
|
||||||
$ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"]);
|
$ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent);
|
||||||
if ($ret < 0)
|
if ($ret < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@ -346,7 +347,12 @@ if ($id || $ref)
|
|||||||
print '<td><input class="flat" name="price" size="8" value="'.(GETPOST('price')?price(GETPOST('price')):(isset($product->fourn_price)?price($product->fourn_price):'')).'">';
|
print '<td><input class="flat" name="price" size="8" value="'.(GETPOST('price')?price(GETPOST('price')):(isset($product->fourn_price)?price($product->fourn_price):'')).'">';
|
||||||
print ' ';
|
print ' ';
|
||||||
print $form->select_PriceBaseType((GETPOST('price_base_type')?GETPOST('price_base_type'):$product->price_base_type), "price_base_type");
|
print $form->select_PriceBaseType((GETPOST('price_base_type')?GETPOST('price_base_type'):$product->price_base_type), "price_base_type");
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
// Discount qty min
|
||||||
|
print '<td>'.$langs->trans("DiscountQtyMin").'</td>';
|
||||||
|
print '<td><input class="flat" name="remise_percent" size="8" value="'.(GETPOST('remise_percent')?vatrate(GETPOST('remise_percent')):(isset($product->fourn_remise_percent)?vatrate($product->fourn_remise_percent):'')).'"> %';
|
||||||
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
// Charges ????
|
// Charges ????
|
||||||
@ -407,6 +413,7 @@ if ($id || $ref)
|
|||||||
// Charges ????
|
// Charges ????
|
||||||
if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("Charges").'</td>';
|
if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("Charges").'</td>';
|
||||||
print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
||||||
|
print '<td class="liste_titre" align="right">'.$langs->trans("DiscountQtyMin").'</td>';
|
||||||
// Charges ????
|
// Charges ????
|
||||||
if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("UnitCharges").'</td>';
|
if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("UnitCharges").'</td>';
|
||||||
print '<td class="liste_titre"></td>';
|
print '<td class="liste_titre"></td>';
|
||||||
@ -466,6 +473,11 @@ if ($id || $ref)
|
|||||||
print price($productfourn->fourn_unitprice);
|
print price($productfourn->fourn_unitprice);
|
||||||
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" ");
|
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" ");
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
// Discount
|
||||||
|
print '<td align="right">';
|
||||||
|
print vatrate($productfourn->fourn_remise_percent, $langs);
|
||||||
|
print '</td>';
|
||||||
|
|
||||||
// Unit Charges ???
|
// Unit Charges ???
|
||||||
if (! empty($conf->margin->enabled))
|
if (! empty($conf->margin->enabled))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user