Hello.
Since years users keep asking a solution to the custom fields price not applied when price override is active.
I wrote a temporary fix, but when this can be integrated in VM?
calculationh.php - line 443
Replace:
"if ($override==1) {
$this->productPrices['salesPrice'] = $product_override_price;
}"
With:
"iif ($override==1) {
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price/1.22 + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice*1.22 ;
}
}"
(this has been done for Italian 22% VAT but can be changed with the rule applied)
It is annoying, I need to manually change it on every update
Quote from: rdcustom on December 09, 2022, 08:10:54 AM
...., but when this can be integrated in VM?
First time that I am aware of this fix. It can be integrated, if someone delivers the code.
Quote from: rdcustom on December 09, 2022, 08:10:54 AM
It is annoying, I need to manually change it on every update
Sadly you posted it one day too late to be part of the core already. If you would have posted the solution earlier, you could be less annoyed :-)
Anyway I can add it
Quote from: Milbo on December 09, 2022, 21:15:35 PM
Quote from: rdcustom on December 09, 2022, 08:10:54 AM
...., but when this can be integrated in VM?
First time that I am aware of this fix. It can be integrated, if someone delivers the code.
Quote from: rdcustom on December 09, 2022, 08:10:54 AM
It is annoying, I need to manually change it on every update
Sadly you posted it one day too late to be part of the core already. If you would have posted the solution earlier, you could be less annoyed :-)
Anyway I can add it
thanks Milbo,
this code is not perfect (as it only works with Italian VAT). It should be modified with the applied TAX variable, but I am not a programmer and honestly I don't know how to manage this.
i will try to find a solution for this unless someone can help
how can I replace 1.22 with the applied tax rule?
which is the variable?
also, I need to transform the (example) 22% into 1.22 but I am not good at PHP and I think this need a calculation
ah,. dam, I forgot to add it, I fear.
The main problem here is, that this "override price" thing was never really meant to be used, it was an old vm1.1 thing.
The override price is currently used for rounding problems. with your fix it can be used as "individual discount by setting fixed price". Good that you mention that with the tax. Yeh but I hope you know that will take maybe an hour or so to get it work.
There are two things left in VM, one is the possibility to set the final prices (not net) and the other is to set a simple discount.
Okay, I think I found the solution:
Line 443:
"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if ($override==1) {
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}"
this should work with all taxes applied
hi
I'm with the VirtueMart 4.0.12 10777
but I can't see anymore the price override option on the price section, is this normal ?
It is now a hidden config. Search the forum or check the docs.
Jörgen
hidden config on the new admin template so, because with the old one it's ok
Turn on "Show expert pricing options" on the Configuration/Pricing/Price Configuration tab.
Thanks jenkinhill...
Quote from: rdcustom on December 22, 2022, 18:59:35 PM
Okay, I think I found the solution:
Line 443:
"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if ($override==1) {
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}"
this should work with all taxes applied
Great :-) How long did it take?
Do you mean it like that?
if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}
I added it to the code like that. Lets see what tests say.
Quote from: Milbo on December 29, 2022, 22:22:19 PM
Quote from: rdcustom on December 22, 2022, 18:59:35 PM
Okay, I think I found the solution:
Line 443:
"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if ($override==1) {
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}"
this should work with all taxes applied
Great :-) How long did it take?
around 15 minutes :D
Quote from: Milbo on December 29, 2022, 22:35:27 PM
Do you mean it like that?
if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}
I added it to the code like that. Lets see what tests say.
thanks! but I am still working on it cause I found a bug.
This works only when the Vat is applied.
In all cases without VAT (when the VAT is 0%) it gives a calculation error (division by zero).
the issue is:
i override the price INCLUDING the vat, this is fine as long as I sell with VAT applied.
but if the customer is in a group without VAT, the rule can't know how much is the VAT applied to override.
Still working on it, I think I have to apply the VAT and then subtract it.
??
if ($override==1) {
//$this->productPrices['salesPrice'] = $product_override_price;
if(!empty($this->rules['VatTax'])){
$vat = 100.0 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}else{
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
}
nothing, I think the only solution for this is to handle the override without VAT and then apply the rule if needed.
this works with and without VAT applied, but needs the override WITHOUT vat
"//OVERRIDE
if ($override==1) {
if(empty($this->rules['VatTax']))
{$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice;}
else
{$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
$this->productPrices['salesPrice'] = $product_override_price/$vat + $salesPrice - $costPrice/$vat ;}
}
//OVERRIDE END"
Quote from: rdcustom on December 30, 2022, 08:56:10 AM
Quote from: Milbo on December 29, 2022, 22:22:19 PM
Quote from: rdcustom on December 22, 2022, 18:59:35 PM
Okay, I think I found the solution:
Line 443:
"$vat = 100 / ($this->roundInternal($this->executeCalculation($this->rules['VatTax'], 100)));
if ($override==1) {
if(empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price*$vat + $salesPrice - $costPrice ;
}
if(!empty($this->rules['VatTax'])){
$this->productPrices['salesPrice'] = $product_override_price + $salesPrice - $costPrice/$vat ;
}
}"
this should work with all taxes applied
Great :-) How long did it take?
around 15 minutes :D
Yes, because you was just in it. Additionally, it often happens that i add something like that and the real work comes later, if people with other configurations get problems. Lets see how it works.
i override the price INCLUDING the vat, this is fine as long as I sell with VAT applied.
but if the customer is in a group without VAT, the rule can't know how much is the VAT applied to override.
Still working on it, I think I have to apply the VAT and then subtract it.
Exactly, but great that you keep on it.
Quote from: rdcustom on December 30, 2022, 10:49:26 AM
this works with and without VAT applied, but needs the override WITHOUT vat
You mean they should set the price as net, as we do normally? And now you see the problems developing VM or ecommerce. Some people use it to remove rounding erros of the final price and most people use it for a fast discount. So the solution must be to enter the final price, the brutto price.
I think it should just look like that
if ($override==1) {
$this->productPrices['salesPrice'] = $product_override_price;
if($variant){
if(!empty($this->rules['VatTax'])){
$variant = $this->roundInternal($this->executeCalculation($this->rules['VatTax'], $variant),'salesPrice');
}
$this->productPrices['salesPrice'] += $variant;
}
}
Quote from: Milbo on January 08, 2023, 22:07:03 PM
Quote from: rdcustom on December 30, 2022, 10:49:26 AM
this works with and without VAT applied, but needs the override WITHOUT vat
You mean they should set the price as net, as we do normally? And now you see the problems developing VM or ecommerce. Some people use it to remove rounding erros of the final price and most people use it for a fast discount. So the solution must be to enter the final price, the brutto price.
this is the issue I found:
with the normal price, there's the "calculate cost price" options that automatically removes VAT if applied.
On the override field there's no option to do this, so we need to put the "new base price" manually and then the system will apply the VAT if needed.
Minor issue, but this can be an idea for future upgrades (placing a "calculate" flag also on override).
Anyway, in this way this option can also be used as a temporary discounted price and I think it can be useful (at least... I use it in this way).
Did you check my code?
You can just set the final price, with tax. People want an easy way to set a discount, with tax. They see the old price with tax for example 49.90 an they want to make it 39.9, thats it. and imho the new code works.
I plan the whole time to enable also the direct input with finalprices. But I think I need a fundraising campaign for that.
Hi all,
I tested Milbo's patch
My results with VM 4.0.12 10777
My VAT is 20%
Override the final price set to 700Results without variant applied
- crossed out price Without VAT 749,00 €
- price Without VAT 583,33 €
- final price with VAT 700 €
Results with variant +50 applied
- crossed out price Without VAT 799,00 €
- price Without VAT 633,33 €
- final price with VAT 760 €
Overcharge the price before VAT set to 700Results without variant applied
- crossed out price Without VAT 749,00 €
- price Without VAT 700,0 €
- final price with VAT 840,00 €
Results with variant +50 applied
- crossed out price Without VAT 799,00 €
- price Without VAT 700,00 € Wrong should be 750,00 €
- final price with VAT 840,00 € Wrong should be 900,00 €
in case of Override of "price without tax":
line 413:
if ($override==-1) {
$this->productPrices['discountedPriceWithoutTax'] = $product_override_price;
if($variant){
$this->productPrices['discountedPriceWithoutTax'] += $variant;
}
}
...just for being sure that my last post was read and implemented in the update
Thank you, just added
So this is adding VAT to the price override.
Max i think that you will break many sites by adding that modification.
For years the price override is the final/sales price