Price override and custom fields price - fix for new releases

Started by rdcustom, December 09, 2022, 08:10:54 AM

Previous topic - Next topic

GJC Web Design

??

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 ;
}
}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

rdcustom

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"

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

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;
}
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rdcustom

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).

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sirius

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 700
Results 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 700
Results 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 €
J3.10.12 | PHP 7.4.33 + APC + memcached + Opcode
VM Prod : 3.8.6 | VM Test : 4.0.12.10777

rdcustom

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;
         }
      }

rdcustom

...just for being sure that my last post was read and implemented in the update

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

balai

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