PHP code example of jomweb / ringgit

1. Go to this page and download the library: Download jomweb/ringgit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jomweb / ringgit example snippets


use Duit\MYR;

$money = new MYR(540);
$money = MYR::given(540);
$money = MYR::withoutGst(540);
$money = MYR::withoutTax(540);

use Duit\MYR;
use Duit\Taxable\Gst\ZeroRate;
use Duit\Taxable\Gst\StandardRate;

$money = MYR::beforeGst(540);

$money = MYR::beforeTax(540, new StandardRate());
$money = MYR::beforeTax(540, new ZeroRate());

$money = MYR::given(540)->useGstStandardRate(); // 6%
$money = MYR::given(540)->useGstZeroRate(); // 0%

$money = MYR::given(540)->enableTax(new StandardRate());
$money = MYR::given(540)->enableTax(new ZeroRate());

use Duit\MYR;
use Duit\Taxable\Gst\ZeroRate;
use Duit\Taxable\Gst\StandardRate;

$money = MYR::afterGst(530); // always going to use 6%

$money = MYR::afterTax(540, new StandardRate());
$money = MYR::afterTax(540, new ZeroRate());

use Duit\MYR;

$money = new MYR(540);
$money = MYR::given(540);
$money = MYR::withoutTax(540);

use Duit\MYR;
use Duit\Taxable\Sst;

$money = MYR::beforeTax(530, new Sst());

$money = MYR::given(530)->enableTax(new Sst());

use Duit\MYR;
use Duit\Taxable\Sst;

$money = MYR::afterTax(530, new Sst());
 php


use Duit\MYR;

$fiveMyr = MYR::given(500);
$tenMyr = $fiveMyr->add($fiveMyr);

list($part1, $part2, $part3) = $tenMyr->allocate(array(1, 1, 1));
assert($part1->equals(MYR::given(334)));
assert($part2->equals(MYR::given(333)));
assert($part3->equals(MYR::given(333)));