Skip to content

Repository files navigation

Malaysia Ringgit implementation on top of Money PHP

testsLatest Stable VersionTotal DownloadsLatest Unstable VersionLicenseCoverage Status

PHP 8.0+ library to make working with money safer, easier, and fun for Malaysia Ringgit!

"If I had a dime for every time I've seen someone use FLOAT to store currency, I'd have $999.997634" -- Bill Karwin

In short: You shouldn't represent monetary values by a float. Wherever you need to represent money, use this Money value object.

<?phpuseDuit\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)));

Installation

To install through composer, simply put the following in your composer.json file:

{
"require": {
"jomweb/ringgit": "^2.0"
}
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplify by using the following command:

composer require "jomweb/ringgit"

Usages

Taxes

GST Declaration

Without GST

Declaring Money (MYR) without GST (Zero).

useDuit\MYR;
$money = newMYR(540);
$money = MYR::given(540);
$money = MYR::withoutGst(540);
$money = MYR::withoutTax(540);
Before GST

Declaring Money (MYR) before GST is applied.

useDuit\MYR;
useDuit\Taxable\Gst\ZeroRate;
useDuit\Taxable\Gst\StandardRate;
$money = MYR::beforeGst(540);
$money = MYR::beforeTax(540, newStandardRate());
$money = MYR::beforeTax(540, newZeroRate());
$money = MYR::given(540)->useGstStandardRate(); // 6%$money = MYR::given(540)->useGstZeroRate(); // 0%$money = MYR::given(540)->enableTax(newStandardRate());
$money = MYR::given(540)->enableTax(newZeroRate());
After GST

Declaring Money (MYR) with GST amount.

useDuit\MYR;
useDuit\Taxable\Gst\ZeroRate;
useDuit\Taxable\Gst\StandardRate;
$money = MYR::afterGst(530); // always going to use 6%$money = MYR::afterTax(540, newStandardRate());
$money = MYR::afterTax(540, newZeroRate());

SST Declaration

Without SST

Declaring Money (MYR) without GST (Zero).

useDuit\MYR;
$money = newMYR(540);
$money = MYR::given(540);
$money = MYR::withoutTax(540);
Before SST

Declaring Money (MYR) before SST is applied.

useDuit\MYR;
useDuit\Taxable\Sst;
$money = MYR::beforeTax(530, newSst());
$money = MYR::given(530)->enableTax(newSst());
After SST

Declaring Money (MYR) with SST tax.

useDuit\MYR;
useDuit\Taxable\Sst;
$money = MYR::afterTax(530, newSst());

About

Malaysia Ringgit implementation on top of Money PHP

Topics

Resources

Code of conduct

Contributing

Stars

30 stars

Watchers

5 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages