PHP Classes

File: Example.php

Recommend this page to a friend!
  Classes of Sergii Pryz   PHP Price Calculator   Example.php   Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Price Calculator
Calculate prices using arbitrary precision math
Author: By
Last change:
Date: 9 years ago
Size: 961 bytes
 

Contents

Class file image Download
<?php
/**
 * =======================================
 * Example of usage Price Calculator
 * =======================================
 */

namespace PriceCalculator;
use
PriceCalculator\Strategy\PriceNet\PercentOver;

// PriceCalculator Autoload
require_once ('./src/Autoload.php');

// shop buy apples by 10$ from farmer
$price_purchase = 10;

// shop has 3% over purchase price
$strategy = new PercentOver(array('percent_over' => 3));

// vat is 23%
$vat_percent = 23;

// calculate price
$calculator = new PriceCalculator($strategy, $vat_percent);

$price = $calculator->setPricePurchase($price_purchase)
                    ->
getPrice();

var_dump($price); // output: array(3) {
                    // ["price_net"]=>
                    // string(5) "10.30"
                    // ["price_gross"]=>
                    // string(7) "12.6690"
                    // ["vat_value"]=>
                    // string(6) "2.3690"
                    //}