mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Add multicurrency support for product buy price for supplier propales, orders and invoices
This commit is contained in:
parent
420fe3a07a
commit
54dba24ab5
|
|
@ -1533,13 +1533,17 @@ class CommandeFournisseur extends CommonOrder
|
|||
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
||||
}
|
||||
|
||||
if ($conf->multicurrency->enabled && $pu_ht_devise > 0) {
|
||||
$pu = 0;
|
||||
}
|
||||
|
||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx,$pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu_ht = $tabprice[3];
|
||||
$pu = $pu_ht = $tabprice[3];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
|
|
|
|||
|
|
@ -1387,7 +1387,7 @@ class FactureFournisseur extends CommonInvoice
|
|||
{
|
||||
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG);
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
||||
global $mysoc;
|
||||
global $mysoc, $conf;
|
||||
|
||||
// Clean parameters
|
||||
if (empty($remise_percent)) $remise_percent=0;
|
||||
|
|
@ -1416,6 +1416,10 @@ class FactureFournisseur extends CommonInvoice
|
|||
$txlocaltax1=price2num($txlocaltax1);
|
||||
$txlocaltax2=price2num($txlocaltax2);
|
||||
|
||||
if ($conf->multicurrency->enabled && $pu_ht_devise > 0) {
|
||||
$pu = 0;
|
||||
}
|
||||
|
||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
|
|
|
|||
|
|
@ -73,6 +73,13 @@ class ProductFournisseur extends Product
|
|||
var $supplier_reputation; // reputation of supplier
|
||||
var $reputations=array(); // list of available supplier reputations
|
||||
|
||||
// Multicurreny
|
||||
var $fourn_multicurrency_id;
|
||||
var $fourn_multicurrency_code;
|
||||
var $fourn_multicurrency_tx;
|
||||
var $fourn_multicurrency_price;
|
||||
var $fourn_multicurrency_unitprice;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
|
@ -173,25 +180,29 @@ class ProductFournisseur extends Product
|
|||
/**
|
||||
* Modify the purchase price for a supplier
|
||||
*
|
||||
* @param int $qty Min quantity for which price is valid
|
||||
* @param float $buyprice Purchase price for the quantity min
|
||||
* @param User $user Object user user made changes
|
||||
* @param string $price_base_type HT or TTC
|
||||
* @param Societe $fourn Supplier
|
||||
* @param int $availability Product availability
|
||||
* @param string $ref_fourn Supplier ref
|
||||
* @param float $tva_tx New VAT Rate (For example 8.5. Should not be a string)
|
||||
* @param string $charges costs affering to product
|
||||
* @param float $remise_percent Discount regarding qty (percent)
|
||||
* @param float $remise Discount regarding qty (amount)
|
||||
* @param int $newnpr Set NPR or not
|
||||
* @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined.
|
||||
* @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER)
|
||||
* @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function).
|
||||
* @param string $newdefaultvatcode Default vat code
|
||||
* @param int $qty Min quantity for which price is valid
|
||||
* @param float $buyprice Purchase price for the quantity min
|
||||
* @param User $user Object user user made changes
|
||||
* @param string $price_base_type HT or TTC
|
||||
* @param Societe $fourn Supplier
|
||||
* @param int $availability Product availability
|
||||
* @param string $ref_fourn Supplier ref
|
||||
* @param float $tva_tx New VAT Rate (For example 8.5. Should not be a string)
|
||||
* @param string $charges costs affering to product
|
||||
* @param float $remise_percent Discount regarding qty (percent)
|
||||
* @param float $remise Discount regarding qty (amount)
|
||||
* @param int $newnpr Set NPR or not
|
||||
* @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined.
|
||||
* @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER)
|
||||
* @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function).
|
||||
* @param string $newdefaultvatcode Default vat code
|
||||
* @param float $multicurrency_buyprice Purchase price for the quantity min in currency
|
||||
* @param string $multicurrency_price_base_type HT or TTC in currency
|
||||
* @param float $multicurrency_tx Rate currency
|
||||
* @param string $multicurrency_code Currency code
|
||||
* @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, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='', $localtaxes_array=array(), $newdefaultvatcode='')
|
||||
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='', $localtaxes_array=array(), $newdefaultvatcode='', $multicurrency_buyprice=0, $multicurrency_price_base_type='HT',$multicurrency_tx=1,$multicurrency_code='')
|
||||
{
|
||||
global $conf, $langs;
|
||||
//global $mysoc;
|
||||
|
|
@ -209,6 +220,25 @@ class ProductFournisseur extends Product
|
|||
$ttx = $tva_tx;
|
||||
$buyprice = $buyprice/(1+($ttx/100));
|
||||
}
|
||||
|
||||
// Multicurrency
|
||||
if ($conf->multicurrency->enabled) {
|
||||
if (empty($multicurrency_tx)) $multicurrency_tx=1;
|
||||
if (empty($multicurrency_buyprice)) $multicurrency_buyprice=0;
|
||||
|
||||
if (empty($multicurrency_buyprice)) $multicurrency_buyprice=0;
|
||||
if ($multicurrency_price_base_type == 'TTC')
|
||||
{
|
||||
$ttx = $tva_tx;
|
||||
$multicurrency_buyprice = $multicurrency_buyprice/(1+($ttx/100));
|
||||
}
|
||||
$multicurrency_buyprice=price2num($multicurrency_buyprice,'MU');
|
||||
$multicurrency_unitBuyPrice=price2num($multicurrency_buyprice/$qty,'MU');
|
||||
|
||||
$buyprice=$multicurrency_buyprice/$multicurrency_tx;
|
||||
$fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $multicurrency_code);
|
||||
}
|
||||
|
||||
$buyprice=price2num($buyprice,'MU');
|
||||
$charges=price2num($charges,'MU');
|
||||
$qty=price2num($qty);
|
||||
|
|
@ -252,6 +282,11 @@ class ProductFournisseur extends Product
|
|||
$sql.= " unitprice = ".$unitBuyPrice.",";
|
||||
$sql.= " unitcharges = ".$unitCharges.","; // deprecated
|
||||
$sql.= " fk_availability = ".$availability.",";
|
||||
$sql.= " multicurrency_price = ".(isset($multicurrency_buyprice)?"'".$this->db->escape(price2num($multicurrency_buyprice))."'":'null').",";
|
||||
$sql.= " multicurrency_unitprice = ".(isset($multicurrency_unitBuyPrice)?"'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'":'null').",";
|
||||
$sql.= " multicurrency_tx = ".(isset($multicurrency_tx)?"'".$this->db->escape($multicurrency_tx)."'":'1').",";
|
||||
$sql.= " fk_multicurrency = ".(isset($fk_multicurrency)?"'".$this->db->escape($fk_multicurrency)."'":'null').",";
|
||||
$sql.= " multicurrency_code = ".(isset($multicurrency_code)?"'".$this->db->escape($multicurrency_code)."'":'null').",";
|
||||
$sql.= " entity = ".$conf->entity.",";
|
||||
$sql.= " tva_tx = ".price2num($tva_tx).",";
|
||||
// TODO Add localtax1 and localtax2
|
||||
|
|
@ -306,8 +341,15 @@ class ProductFournisseur extends Product
|
|||
if ($resql) {
|
||||
// Add price for this quantity to supplier
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price(";
|
||||
$sql.= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
|
||||
$sql .= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation)";
|
||||
$sql .= " values('" . $this->db->idate($now) . "',";
|
||||
$sql .= " values(";
|
||||
$sql.= (isset($multicurrency_buyprice)?"'".$this->db->escape(price2num($multicurrency_buyprice))."'":'null').",";
|
||||
$sql.= (isset($multicurrency_unitBuyPrice)?"'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'":'null').",";
|
||||
$sql.= (isset($multicurrency_tx)?"'".$this->db->escape($multicurrency_tx)."'":'1').",";
|
||||
$sql.= (isset($fk_multicurrency)?"'".$this->db->escape($fk_multicurrency)."'":'null').",";
|
||||
$sql.= (isset($multicurrency_code)?"'".$this->db->escape($multicurrency_code)."'":'null').",";
|
||||
$sql .= " '" . $this->db->idate($now) . "',";
|
||||
$sql .= " " . $this->id . ",";
|
||||
$sql .= " " . $fourn->id . ",";
|
||||
$sql .= " '" . $this->db->escape($ref_fourn) . "',";
|
||||
|
|
@ -341,8 +383,15 @@ class ProductFournisseur extends Product
|
|||
if (! $error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
|
||||
// Add record into log table
|
||||
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price_log(";
|
||||
$sql.= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,";
|
||||
$sql .= "datec, fk_product_fournisseur,fk_user,price,quantity)";
|
||||
$sql .= "values('" . $this->db->idate($now) . "',";
|
||||
$sql .= "values(";
|
||||
$sql.= (isset($multicurrency_buyprice)?"'".$this->db->escape(price2num($multicurrency_buyprice))."'":'null').",";
|
||||
$sql.= (isset($multicurrency_unitBuyPrice)?"'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'":'null').",";
|
||||
$sql.= (isset($multicurrency_tx)?"'".$this->db->escape($multicurrency_tx)."'":'1').",";
|
||||
$sql.= (isset($fk_multicurrency)?"'".$this->db->escape($fk_multicurrency)."'":'null').",";
|
||||
$sql.= (isset($multicurrency_code)?"'".$this->db->escape($multicurrency_code)."'":'null').",";
|
||||
$sql .= " '" . $this->db->idate($now) . "',";
|
||||
$sql .= " " . $this->product_fourn_id . ",";
|
||||
$sql .= " " . $user->id . ",";
|
||||
$sql .= " " . price2num($buyprice) . ",";
|
||||
|
|
@ -395,6 +444,7 @@ class ProductFournisseur extends Product
|
|||
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.fk_availability,";
|
||||
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price
|
||||
$sql.= " pfp.supplier_reputation";
|
||||
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||
|
||||
|
|
@ -429,6 +479,12 @@ class ProductFournisseur extends Product
|
|||
$this->supplier_reputation = $obj->supplier_reputation;
|
||||
$this->default_vat_code = $obj->default_vat_code;
|
||||
|
||||
$this->fourn_multicurrency_price = $obj->multicurrency_price;
|
||||
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
||||
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
||||
$this->fourn_multicurrency_id = $obj->fk_multicurrency;
|
||||
$this->fourn_multicurrency_code = $obj->multicurrency_code;
|
||||
|
||||
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression))
|
||||
{
|
||||
$priceparser = new PriceParser($this->db);
|
||||
|
|
@ -479,6 +535,7 @@ class ProductFournisseur extends Product
|
|||
$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, pfp.fk_supplier_price_expression,";
|
||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.unitcharges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation";
|
||||
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE pfp.entity IN (".getEntity('productprice').")";
|
||||
|
|
@ -521,6 +578,12 @@ class ProductFournisseur extends Product
|
|||
$prodfourn->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
|
||||
$prodfourn->supplier_reputation = $record["supplier_reputation"];
|
||||
|
||||
$prodfourn->fourn_multicurrency_price = $record["multicurrency_price"];
|
||||
$prodfourn->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
|
||||
$prodfourn->fourn_multicurrency_tx = $record["multicurrency_tx"];
|
||||
$prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"];
|
||||
$prodfourn->fourn_multicurrency_code = $record["multicurrency_code"];
|
||||
|
||||
if (!empty($conf->dynamicprices->enabled) && !empty($prodfourn->fk_supplier_price_expression)) {
|
||||
$priceparser = new PriceParser($this->db);
|
||||
$price_result = $priceparser->parseProductSupplier($prodfourn);
|
||||
|
|
@ -586,10 +649,17 @@ class ProductFournisseur extends Product
|
|||
$this->delivery_time_days = '';
|
||||
$this->id = '';
|
||||
|
||||
$this->fourn_multicurrency_price = '';
|
||||
$this->fourn_multicurrency_unitprice = '';
|
||||
$this->fourn_multicurrency_tx = '';
|
||||
$this->fourn_multicurrency_id = '';
|
||||
$this->fourn_multicurrency_code = '';
|
||||
|
||||
$sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
|
||||
$sql.= " pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
|
||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges, pfp.unitcharges, ";
|
||||
$sql.= " pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days";
|
||||
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " WHERE s.entity IN (".getEntity('societe').")";
|
||||
$sql.= " AND pfp.fk_product = ".$prodid;
|
||||
|
|
@ -664,6 +734,11 @@ class ProductFournisseur extends Product
|
|||
$this->delivery_time_days = $record["delivery_time_days"];
|
||||
$this->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
|
||||
$this->id = $prodid;
|
||||
$this->fourn_multicurrency_price = $record["multicurrency_price"];
|
||||
$this->fourn_multicurrency_unitprice = $record["multicurrency_unitprice"];
|
||||
$this->fourn_multicurrency_tx = $record["multicurrency_tx"];
|
||||
$this->fourn_multicurrency_id = $record["fk_multicurrency"];
|
||||
$this->fourn_multicurrency_code = $record["multicurrency_code"];
|
||||
$min = $fourn_unitprice;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -419,7 +419,8 @@ if (empty($reshook))
|
|||
$date_start,
|
||||
$date_end,
|
||||
$array_options,
|
||||
$productsupplier->fk_unit
|
||||
$productsupplier->fk_unit,
|
||||
$productsupplier->fourn_multicurrency_unitprice
|
||||
);
|
||||
}
|
||||
if ($idprod == -99 || $idprod == 0)
|
||||
|
|
|
|||
|
|
@ -1018,7 +1018,9 @@ if (empty($reshook))
|
|||
0,
|
||||
$array_options,
|
||||
$productsupplier->fk_unit,
|
||||
$productsupplier->fourn_ref
|
||||
0,
|
||||
$productsupplier->fourn_multicurrency_unitprice,
|
||||
$productsupplier->fourn_ref
|
||||
);
|
||||
}
|
||||
if ($idprod == -99 || $idprod == 0)
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ insert into llx_c_type_container (code,label,module,active) values ('banner',
|
|||
insert into llx_c_type_container (code,label,module,active) values ('blogpost', 'BlogPost', 'system', 1);
|
||||
insert into llx_c_type_container (code,label,module,active) values ('other', 'Other', 'system', 1);
|
||||
|
||||
-- For supplier product buy price in multicurency
|
||||
ALTER TABLE `llx_product_fournisseur_price` CHANGE `multicurrency_price_ttc` `multicurrency_unitprice` DOUBLE(24,8) NULL DEFAULT NULL;
|
||||
ALTER TABLE `llx_product_fournisseur_price_log` CHANGE `multicurrency_price_ttc` `multicurrency_unitprice` DOUBLE(24,8) NULL DEFAULT NULL;
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -325,8 +325,10 @@ Default=Default
|
|||
DefaultValue=Default value
|
||||
DefaultValues=Default values
|
||||
Price=Price
|
||||
PriceCurrency=Price (currency)
|
||||
UnitPrice=Unit price
|
||||
UnitPriceHT=Unit price (net)
|
||||
UnitPriceHTCurrency=Unit price (net) (currency)
|
||||
UnitPriceTTC=Unit price
|
||||
PriceU=U.P.
|
||||
PriceUHT=U.P. (net)
|
||||
|
|
@ -353,6 +355,7 @@ AmountLT2ES=Amount IRPF
|
|||
AmountTotal=Total amount
|
||||
AmountAverage=Average amount
|
||||
PriceQtyMinHT=Price quantity min. (net of tax)
|
||||
PriceQtyMinHTCurrency=Price quantity min. (net of tax) (currency)
|
||||
Percentage=Percentage
|
||||
Total=Total
|
||||
SubTotal=Subtotal
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ ConfirmDeleteProductLine=Are you sure you want to delete this product line?
|
|||
ProductSpecial=Special
|
||||
QtyMin=Minimum Qty
|
||||
PriceQtyMin=Price for this min. qty (w/o discount)
|
||||
PriceQtyMinCurrency=Price for this min. qty (w/o discount) (currency)
|
||||
VATRateForSupplierProduct=VAT Rate (for this supplier/product)
|
||||
DiscountQtyMin=Default discount for qty
|
||||
NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product
|
||||
|
|
|
|||
|
|
@ -325,8 +325,10 @@ Default=Défaut
|
|||
DefaultValue=Valeur par défaut
|
||||
DefaultValues=Valeurs par défaut
|
||||
Price=Prix
|
||||
PriceCurrency=Prix (devise)
|
||||
UnitPrice=Prix unitaire
|
||||
UnitPriceHT=Prix unitaire HT
|
||||
UnitPriceHTCurrency=Prix unitaire HT (devise)
|
||||
UnitPriceTTC=Prix unitaire TTC
|
||||
PriceU=P.U.
|
||||
PriceUHT=P.U. HT
|
||||
|
|
@ -353,6 +355,7 @@ AmountLT2ES=Montant IRPF
|
|||
AmountTotal=Montant total
|
||||
AmountAverage=Montant moyen
|
||||
PriceQtyMinHT=Prix quantité min. HT
|
||||
PriceQtyMinHTCurrency=Prix quantité min. HT (devise)
|
||||
Percentage=Pourcentage
|
||||
Total=Total
|
||||
SubTotal=Sous-total
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ ConfirmDeleteProductLine=Êtes-vous sûr de vouloir effacer cette ligne produit
|
|||
ProductSpecial=Special
|
||||
QtyMin=Quantité minimum
|
||||
PriceQtyMin=Prix quantité min. (sans remise)
|
||||
PriceQtyMinCurrency=Prix quantité min. (sans remise) (devise)
|
||||
VATRateForSupplierProduct=Taux TVA (pour ce produit/fournisseur)
|
||||
DiscountQtyMin=Remise par défaut quantité min.
|
||||
NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit
|
||||
|
|
|
|||
|
|
@ -1525,6 +1525,7 @@ class Product extends CommonObject
|
|||
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent,";
|
||||
$sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc, pfp.tva_tx, pfp.fk_supplier_price_expression";
|
||||
$sql.= " ,pfp.default_vat_code";
|
||||
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " WHERE pfp.rowid = ".$prodfournprice;
|
||||
if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty;
|
||||
|
|
@ -1561,6 +1562,11 @@ class Product extends CommonObject
|
|||
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
||||
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
|
||||
$this->default_vat_code = $obj->default_vat_code; // Vat code supplier
|
||||
$this->fourn_multicurrency_price = $obj->multicurrency_price;
|
||||
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
||||
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
||||
$this->fourn_multicurrency_id = $obj->fk_multicurrency;
|
||||
$this->fourn_multicurrency_code = $obj->multicurrency_code;
|
||||
$result=$obj->fk_product;
|
||||
return $result;
|
||||
}
|
||||
|
|
@ -1570,6 +1576,7 @@ class Product extends CommonObject
|
|||
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,";
|
||||
$sql.= " pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.tva_tx, pfp.fk_supplier_price_expression";
|
||||
$sql.= " ,pfp.default_vat_code";
|
||||
$sql.= " ,pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " WHERE pfp.fk_product = ".$product_id;
|
||||
if ($fourn_ref != 'none') $sql.= " AND pfp.ref_fourn = '".$fourn_ref."'";
|
||||
|
|
@ -1610,6 +1617,11 @@ class Product extends CommonObject
|
|||
$this->remise_percent = $obj->remise_percent; // remise percent if present and not typed
|
||||
$this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier
|
||||
$this->default_vat_code = $obj->default_vat_code; // Vat code supplier
|
||||
$this->fourn_multicurrency_price = $obj->multicurrency_price;
|
||||
$this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
|
||||
$this->fourn_multicurrency_tx = $obj->multicurrency_tx;
|
||||
$this->fourn_multicurrency_id = $obj->fk_multicurrency;
|
||||
$this->fourn_multicurrency_code = $obj->multicurrency_code;
|
||||
$result=$obj->fk_product;
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php';
|
||||
|
|
@ -201,6 +202,23 @@ if (empty($reshook))
|
|||
$_POST["price"] = 0;
|
||||
}
|
||||
}
|
||||
if ($conf->multicurrency->enabled) {
|
||||
if (empty($_POST["multicurrency_code"])) {
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Currency")), null, 'errors');
|
||||
}
|
||||
if ($_POST["multicurrency_tx"] <= 0 || $_POST["multicurrency_tx"] == '') {
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("CurrencyRate")), null, 'errors');
|
||||
}
|
||||
if ($_POST["multicurrency_price"] < 0 || $_POST["multicurrency_price"] == '') {
|
||||
$error++;
|
||||
$langs->load("errors");
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PriceCurrency")), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
|
|
@ -232,7 +250,11 @@ if (empty($reshook))
|
|||
if (isset($_POST['ref_fourn_price_id']))
|
||||
$object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
|
||||
|
||||
$ret=$object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation);
|
||||
if ($conf->multicurrency->enabled) {
|
||||
$ret = $object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $_POST["multicurrency_price"], $_POST["multicurrency_price_base_type"], $_POST["multicurrency_tx"], $_POST["multicurrency_code"]);
|
||||
} else {
|
||||
$ret = $object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation);
|
||||
}
|
||||
if ($ret < 0)
|
||||
{
|
||||
|
||||
|
|
@ -526,12 +548,98 @@ if ($id > 0 || $ref)
|
|||
</script>';
|
||||
}
|
||||
|
||||
// Price qty min
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMin").'</td>';
|
||||
print '<td><input class="flat" name="price" size="8" value="'.(GETPOST('price')?price(GETPOST('price')):(isset($object->fourn_price)?price($object->fourn_price):'')).'">';
|
||||
print ' ';
|
||||
print $form->selectPriceBaseType((GETPOST('price_base_type')?GETPOST('price_base_type'):'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices
|
||||
print '</td></tr>';
|
||||
if ($conf->multicurrency->enabled) {
|
||||
// Currency
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
|
||||
print '<td>';
|
||||
print $form->selectMultiCurrency(GETPOST('multicurrency_code')?GETPOST('multicurrency_code'):(isset($object->fourn_multicurrency_code)?$object->fourn_multicurrency_code:''), "multicurrency_code", 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Currency tx
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("CurrencyRate").'</td>';
|
||||
print '<td><input class="flat" name="multicurrency_tx" size="4" value="'.(GETPOST('multicurrency_tx')?GETPOST('multicurrency_tx'):(isset($object->fourn_multicurrency_tx)?$object->fourn_multicurrency_tx:'')).'">';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Currency price qty min
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMinCurrency").'</td>';
|
||||
print '<td><input class="flat" name="multicurrency_price" size="8" value="'.(GETPOST('multicurrency_price')?GETPOST('multicurrency_price'):(isset($object->fourn_multicurrency_price)?$object->fourn_multicurrency_price:'')).'">';
|
||||
print ' ';
|
||||
print $form->selectPriceBaseType((GETPOST('multicurrency_price_base_type')?GETPOST('multicurrency_price_base_type'):'HT'), "multicurrency_price_base_type"); // We keep 'HT' here, multicurrency_price_base_type is not yet supported for supplier prices
|
||||
print '</td></tr>';
|
||||
|
||||
// Price qty min
|
||||
print '<tr><td class="fieldrequired">' . $langs->trans("PriceQtyMin") . '</td>';
|
||||
print '<td><input class="flat" name="disabled_price" size="8" value="">';
|
||||
print '<input type="hidden" name="price" value="">';
|
||||
print '<input type="hidden" name="price_base_type" value="">';
|
||||
print ' ';
|
||||
print $form->selectPriceBaseType('', "disabled_price_base_type");
|
||||
print '</td></tr>';
|
||||
|
||||
$currencies = array();
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE entity = '.$conf->entity;
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$currency = new MultiCurrency($db);
|
||||
while ($obj = $db->fetch_object($resql)) {
|
||||
$currency->fetch($obj->rowid);
|
||||
$currencies[$currency->code] = $currency->rate->rate;
|
||||
}
|
||||
}
|
||||
$currencies = json_encode($currencies);
|
||||
|
||||
print <<<SCRIPT
|
||||
<script type="text/javascript">
|
||||
function update_price_from_multicurrency() {
|
||||
var multicurrency_price = $('input[name="multicurrency_price"]').val();
|
||||
var multicurrency_tx = $('input[name="multicurrency_tx"]').val();
|
||||
$('input[name="price"]').val(multicurrency_price / multicurrency_tx);
|
||||
$('input[name="disabled_price"]').val(multicurrency_price / multicurrency_tx);
|
||||
}
|
||||
jQuery(document).ready(function () {
|
||||
$('input[name="disabled_price"]').prop('disabled', true);
|
||||
$('select[name="disabled_price_base_type"]').prop('disabled', true);
|
||||
update_price_from_multicurrency();
|
||||
|
||||
$('input[name="multicurrency_price"]').keyup(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).change(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).on('paste', function () {
|
||||
update_price_from_multicurrency();
|
||||
});
|
||||
|
||||
$('input[name="multicurrency_tx"]').keyup(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).change(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).on('paste', function () {
|
||||
update_price_from_multicurrency();
|
||||
});
|
||||
|
||||
$('select[name="multicurrency_price_base_type"]').change(function () {
|
||||
$('input[name="price_base_type"]').val($(this).val());
|
||||
$('select[name="disabled_price_base_type"]').val($(this).val());
|
||||
});
|
||||
|
||||
var currencies_array = $currencies;
|
||||
$('select[name="multicurrency_code"]').change(function () {
|
||||
$('input[name="multicurrency_tx"]').val(currencies_array[$(this).val()]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
SCRIPT;
|
||||
} else {
|
||||
// Price qty min
|
||||
print '<tr><td class="fieldrequired">' . $langs->trans("PriceQtyMin") . '</td>';
|
||||
print '<td><input class="flat" name="price" size="8" value="' . (GETPOST('price') ? price(GETPOST('price')) : (isset($object->fourn_price) ? price($object->fourn_price) : '')) . '">';
|
||||
print ' ';
|
||||
print $form->selectPriceBaseType((GETPOST('price_base_type') ? GETPOST('price_base_type') : 'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
// Discount qty min
|
||||
print '<tr><td>'.$langs->trans("DiscountQtyMin").'</td>';
|
||||
|
|
@ -634,7 +742,14 @@ if ($id > 0 || $ref)
|
|||
print_liste_field_titre("QtyMin",$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre("VATRate",$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre("PriceQtyMinHT",$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre("UnitPriceHT",$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
||||
if ($conf->multicurrency->enabled) {
|
||||
print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, 'align="right"', $sortfield, $sortorder);
|
||||
}
|
||||
print_liste_field_titre("UnitPriceHT",$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
||||
if ($conf->multicurrency->enabled) {
|
||||
print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, 'align="right"', $sortfield, $sortorder);
|
||||
print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, 'align="right"', $sortfield, $sortorder);
|
||||
}
|
||||
print_liste_field_titre("DiscountQtyMin",$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre("NbDaysToDelivery",$_SERVER["PHP_SELF"],"pfp.delivery_time_days","",$param,'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre("ReputationForThisProduct",$_SERVER["PHP_SELF"],"pfp.supplier_reputation","",$param,'align="center"',$sortfield,$sortorder);
|
||||
|
|
@ -685,12 +800,31 @@ if ($id > 0 || $ref)
|
|||
print $productfourn->fourn_price?price($productfourn->fourn_price):"";
|
||||
print '</td>';
|
||||
|
||||
if ($conf->multicurrency->enabled) {
|
||||
// Price for the quantity in currency
|
||||
print '<td align="right">';
|
||||
print $productfourn->fourn_multicurrency_price ? price($productfourn->fourn_multicurrency_price) : "";
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Unit price
|
||||
print '<td align="right">';
|
||||
print price($productfourn->fourn_unitprice);
|
||||
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" ");
|
||||
print '</td>';
|
||||
|
||||
if ($conf->multicurrency->enabled) {
|
||||
// Unit price in currency
|
||||
print '<td align="right">';
|
||||
print price($productfourn->fourn_multicurrency_unitprice);
|
||||
print '</td>';
|
||||
|
||||
// Currency
|
||||
print '<td align="right">';
|
||||
print $productfourn->fourn_multicurrency_code ? currency_name($productfourn->fourn_multicurrency_code) : '';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Discount
|
||||
print '<td align="right">';
|
||||
print price2num($productfourn->fourn_remise_percent).'%';
|
||||
|
|
|
|||
|
|
@ -643,8 +643,11 @@ if (empty($reshook))
|
|||
$label,
|
||||
$array_options,
|
||||
$ref_supplier,
|
||||
$fk_unit
|
||||
);
|
||||
$fk_unit,
|
||||
'',
|
||||
0,
|
||||
$productsupplier->fourn_multicurrency_unitprice
|
||||
);
|
||||
//var_dump($tva_tx);var_dump($productsupplier->fourn_pu);var_dump($price_base_type);exit;
|
||||
}
|
||||
if ($idprod == -99 || $idprod == 0)
|
||||
|
|
|
|||
|
|
@ -367,13 +367,14 @@ class SupplierProposal extends CommonObject
|
|||
* @param int $fk_unit Id of the unit to use.
|
||||
* @param string $origin 'order', 'supplier_proposal', ...
|
||||
* @param int $origin_id Id of origin line
|
||||
* @param double $pu_ht_devise Amount in currency
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*
|
||||
* @see add_product
|
||||
*/
|
||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0)
|
||||
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$array_option=0, $ref_fourn='', $fk_unit='', $origin='', $origin_id=0, $pu_ht_devise=0)
|
||||
{
|
||||
global $mysoc;
|
||||
global $mysoc, $conf;
|
||||
|
||||
dol_syslog(get_class($this)."::addline supplier_proposalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type");
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
|
||||
|
|
@ -417,17 +418,23 @@ class SupplierProposal extends CommonObject
|
|||
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc);
|
||||
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
|
||||
|
||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
|
||||
if ($conf->multicurrency->enabled && $pu_ht_devise > 0) {
|
||||
$pu = 0;
|
||||
}
|
||||
|
||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu = $pu_ht = $tabprice[3];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
// Rang to use
|
||||
$rangtouse = $rang;
|
||||
|
|
@ -492,7 +499,7 @@ class SupplierProposal extends CommonObject
|
|||
// Multicurrency
|
||||
$this->line->fk_multicurrency = $this->fk_multicurrency;
|
||||
$this->line->multicurrency_code = $this->multicurrency_code;
|
||||
$this->line->multicurrency_subprice = price2num($pu_ht * $this->multicurrency_tx);
|
||||
$this->line->multicurrency_subprice = $pu_ht_devise;
|
||||
$this->line->multicurrency_total_ht = $multicurrency_total_ht;
|
||||
$this->line->multicurrency_total_tva = $multicurrency_total_tva;
|
||||
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user