PHP Classes

PHP Price Calculator: Calculate prices using arbitrary precision math

Recommend this page to a friend!
  Info   View files Example   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 67%Total: 279 All time: 7,616 This week: 560Up
Version License PHP version Categories
price-calculator 1.0.0BSD License5.3.0PHP 5, E-Commerce
Description 

Author

This package can calculate prices using arbitrary precision math.

It can calculate the prices of goods using different strategies to compute the final price.

Currently it implements strategies to calculate the sales prices based on a value set manually, adding percentage or a fixed value over the original price.

The calculations of the prices are done using arbitrary precision math to avoid losing precision over multiple operations.

Innovation Award
PHP Programming Innovation award nominee
June 2014
Number 6


Prize: One subscription to the PDF edition of the PHP Architect magazine
When dealing with money operations it is important to preserve the precision of the operation results as much as possible, so rounding errors do not result in serious financial losses.

This class uses arbitrary precision math to avoid rounding errors when performing operations on prices.

Manuel Lemos
Picture of Sergii Pryz
  Performance   Level  
Name: Sergii Pryz <contact>
Classes: 10 packages by
Country: Ukraine Ukraine
Age: 39
All time rank: 134121 in Ukraine Ukraine
Week rank: 109 Up1 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 4x

Example

<?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"
                    //}


Details

PriceCalculator ============== Introduction ------------ Library helps calculate products sales price components such as net, gross, vat with using BCMath (http://www.php.net/manual/en/book.bc.php) for all arithmetics operations. Moreover PriceCalculator offers several algorithms to build price net: * Fixed price over purchase price * Fixed percent over purchase price * Manually set net without any margin Additionally it is possible extend library by adding own net price strategy. ### The areas of usage * Calculation product sales price * Form price that's includes several fees like delivery, insurance etc. * Build price that vary from region * Simply calculate VAT, gross, net ### Examples Example can be found here: `/Example.php`

  Files folder image Files  
File Role Description
Files folder imagedocs (1 directory)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file CHANGELOG.md Data Documentation
Accessible without login Plain text file Example.php Example Example script
Accessible without login Plain text file LICENSE.txt Lic. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  docs  
File Role Description
Files folder imageuml (1 file)

  Files folder image Files  /  docs  /  uml  
File Role Description
  Accessible without login Image file class.diagram.png Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imagePriceCalculator (4 files, 1 directory)
  Accessible without login Plain text file Autoload.php Aux. Class source

  Files folder image Files  /  src  /  PriceCalculator  
File Role Description
Files folder imageStrategy (2 files, 1 directory)
  Plain text file AbstractPriceCalculator.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file PriceCalculator.php Class Class source
  Plain text file PriceCalculatorInterface.php Class Class source

  Files folder image Files  /  src  /  PriceCalculator  /  Strategy  
File Role Description
Files folder imagePriceNet (3 files)
  Plain text file AbstractPriceNet.php Class Class source
  Plain text file PriceNetInterface.php Class Class source

  Files folder image Files  /  src  /  PriceCalculator  /  Strategy  /  PriceNet  
File Role Description
  Plain text file Manual.php Class Class source
  Plain text file PercentOver.php Class Class source
  Plain text file PriceOver.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagesrc (1 directory)
  Accessible without login Plain text file bootstrap.php Aux. Class source
  Accessible without login Plain text file phpunit.xml Data Auxiliary data

  Files folder image Files  /  tests  /  src  
File Role Description
Files folder imagePriceCalculator (2 files)

  Files folder image Files  /  tests  /  src  /  PriceCalculator  
File Role Description
  Accessible without login Plain text file BaseTest.php Test Class source
  Accessible without login Plain text file CalculatorTest.php Test Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:279
This week:0
All time:7,616
This week:560Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:75%StarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:75%StarStarStarStar
Tests:66%StarStarStarStar
Videos:-
Overall:67%StarStarStarStar
Rank:454