Hi there,
I have an attribute "totalNet", an attribute "vat" and an attribute "grossInvoiceAmout". Actually very simple I want to caclulate with the system the values. That means when I put in the value for the "totalNet", ESPO should calculate the "grossInvoiceAmount" based on the VAT factor.
I wanted to manage this with the formula an the function ifThen(CONDITION, CONSEQUENT). But it doesnt work!?
Can anyone help me? Is this possible to manage it via such a function and how must the script code be?
Or must I use a separate PHP Script like this? Thanks for your help in advance!
kind regards, Christoph
<?PHP
function calculateVat ( $price, $calculate = 1, $vat = 19) {
if ( $calculate == 1 ) {
// Berechnet den Brutto-Preis, ausgehend von einem Netto-Preis
$newPrice = $price + ( ( $price / 100 ) * $vat );
return round($newPrice, 2);
}
elseif ( $calculate == 2 ) {
// Berechnet den Netto-Preis, ausgehend von einem Brutto-Preis
$newPrice = ( $price * 100 ) / ( 100 + $vat );
return round($newPrice, 2);
}
else {
// Berechnet die eigentlichen MwSt. in EUR, ausgehend von einem Brutto-Preis
$newPrice = ( ( $price * 100 ) / ( 100 + $vat ) ) * ( $vat / 100 );
return round($newPrice, 2);
}
}
/*
* $calculate
* 1 = Berechnet den Brutto-Preis.
* 2 = Berechnet den Netto-Preis.
* 3 = Berechnet die eigentlichen MwSt. in EUR.
*
* Standard = 1
*/
/*
* $vat
* Die Mehrwertsteuer
*
* Standard = 19
*/
// Netto-Preis ist 37,77 EUR
echo calculateVat( '37.77', 1, 19 ) . '<br>';
echo calculateVat( '44.95', 2, 19 ) . '<br>';
echo calculateVat( '44.95', 3, 19 ) . '<br>';
?>
I have an attribute "totalNet", an attribute "vat" and an attribute "grossInvoiceAmout". Actually very simple I want to caclulate with the system the values. That means when I put in the value for the "totalNet", ESPO should calculate the "grossInvoiceAmount" based on the VAT factor.
I wanted to manage this with the formula an the function ifThen(CONDITION, CONSEQUENT). But it doesnt work!?
Can anyone help me? Is this possible to manage it via such a function and how must the script code be?
Or must I use a separate PHP Script like this? Thanks for your help in advance!
kind regards, Christoph
<?PHP
function calculateVat ( $price, $calculate = 1, $vat = 19) {
if ( $calculate == 1 ) {
// Berechnet den Brutto-Preis, ausgehend von einem Netto-Preis
$newPrice = $price + ( ( $price / 100 ) * $vat );
return round($newPrice, 2);
}
elseif ( $calculate == 2 ) {
// Berechnet den Netto-Preis, ausgehend von einem Brutto-Preis
$newPrice = ( $price * 100 ) / ( 100 + $vat );
return round($newPrice, 2);
}
else {
// Berechnet die eigentlichen MwSt. in EUR, ausgehend von einem Brutto-Preis
$newPrice = ( ( $price * 100 ) / ( 100 + $vat ) ) * ( $vat / 100 );
return round($newPrice, 2);
}
}
/*
* $calculate
* 1 = Berechnet den Brutto-Preis.
* 2 = Berechnet den Netto-Preis.
* 3 = Berechnet die eigentlichen MwSt. in EUR.
*
* Standard = 1
*/
/*
* $vat
* Die Mehrwertsteuer
*
* Standard = 19
*/
// Netto-Preis ist 37,77 EUR
echo calculateVat( '37.77', 1, 19 ) . '<br>';
echo calculateVat( '44.95', 2, 19 ) . '<br>';
echo calculateVat( '44.95', 3, 19 ) . '<br>';
?>
Comment