Formula to calculate php equivalency surcharge

0

I have to calculate the equivalence surcharge with php and I do not get the correct values.

I have this code:

$dcto0=$DLineasPedido["descuento"] / 100;
$importe=$DLineasPedido["precio"]*$DLineasPedido["cantidad"];
$dcto0=$importe*$dcto0;
$Baselinea=$importe-$dcto0;
$base = $base+$Baselinea;
$iva=$base*$DLineasPedido["iva"] / 100;
$Re=$iva*$Drecargo["Conf2"] / 100;
$Total = $base + $iva + $Re;

looking at this Page , says that if I have 3000 and I add 21% plus 5 , 2% should give me 3786 but it gives me 3662.76 and the equivalence surcharge is 32.76 when it should be 156

What can I be doing wrong?

    
asked by Killpe 11.06.2017 в 01:04
source

2 answers

0

In the end, Carmen's response has stayed that way and it works.

$dcto0=$DLineasPedido["descuento"] / 100;
$importe=$DLineasPedido["precio"]*$DLineasPedido["cantidad"];
$dcto0=$importe*$dcto0;
$Baselinea=$importe-$dcto0;
$base = $base+$Baselinea;
$iva=$base*$DLineasPedido["iva"] / 100;
$Re=$base*$Drecargo["Conf2"] / 100;
$Total = $base + $iva + $Re;
    
answered by 11.06.2017 / 10:40
source
1

It's a conceptual problem, you're calculating the VAT surcharge instead of the tax base, that's why it does not work out correctly.

It would be: 3000 + (3000 * 0.21) + (3000 * 0.052) = 3786

Accommodate your PHP to this operation and it will be fine.

    
answered by 11.06.2017 в 01:45