PHP price calculator
This is the first version of a class that will contain methods to be used to calculate taxes, prices, percentage, interest fees and so on.
<?php
/**
* This class could be used for basic price, tax and interest calculations
* @package Sami's price calculator
* @version $Id: samis_price_calculator.php v.1.0 2017-11-10 16:43:00 $
* @author Samuil Banti
* @copyright (C) 2017 - Samuil Banti
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
class samis_price_calculator {
/**
* Calculates the price with VAT.
* @param float $price_without_vat - The price with VAT.
* @param int $vat_percentage - The percent of VAT.
* @return float - The price with VAT.
*/
public function get_price_with_vat($price_without_vat, $vat_percentage)
{
return $price_without_vat + $this->get_vat_amount($price_without_vat, $vat_percentage);
}
/**
* Calculates the price without VAT.
* @param float $price_with_vat - The price with VAT.
* @param int $vat_percentage - The percent of VAT.
* @return float - The price without VAT.
*/
public function get_price_without_vat($price_with_vat, $vat_percentage)
{
return $price_with_vat - $this->get_vat_amount_of_total($price_with_vat, $vat_percentage);
}
/**
* Calculates the VAT amount from price with does NOT included VAT.
* @param float $price_with_vat - The price with VAT.
* @param int $vat_percentage - The percent of VAT.
* @return float - The amount of VAT.
*/
public function get_vat_amount($price_without_vat, $vat_percentage)
{
return ($price_without_vat * $vat_percentage / 100);
}
/**
* Calculates the VAT amount from price with included VAT.
* @param float $price_with_vat - The price with VAT.
* @param int $vat_percentage - The percent of VAT.
* @return float - The amount of VAT.
*/
public function get_vat_amount_of_total($price_with_vat, $vat_percentage)
{
return ($price_with_vat * $vat_percentage) / (100+$vat_percentage);
}
/**
* Get the percent of total number.
* @param float $sub_number - The part of the total number.
* @param float $total_number - The total number.
*/
public function get_percent_of_total($sub_number, $total_number)
{
return $sub_number * 100 / $total_number;
}
}
Download...