Search by

blueprintau / finance

jackharrispeninsulainteractive

Financial arithmetic, Money value objects, tax extraction, and allocation engine for PHP.

Package info

github.com/blueprintau/Finance

pkg:composer/blueprintau/finance

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-master 2026-08-19 23:18 UTC

This package is auto-updated.

Last update: 2026-09-20 01:23:59 UTC


README

Financial arithmetic, Money value objects, tax extraction, and an allocation engine for PHP.

Requires PHP 8.4+.

Installation

composer require blueprintau/finance

Usage

Money

Money stores amounts as integer cents to avoid floating-point rounding errors.

use BlueprintAU\Finance\Values\Money;
use BlueprintAU\Finance\Enums\Currency;

$price = Money::fromDollars('19.99', Currency::AUD);
$tax   = Money::fromCents(200, Currency::AUD);

$total = $price->add($tax);
echo $total->toDollars(); // "21.99"

// Split a total evenly across N targets without losing a cent
[$a, $b, $c] = Money::fromDollars('10.00', Currency::AUD)->allocate(3);

TaxRate & Tax

Extract tax from a tax-inclusive total, or add tax on top of a net subtotal.

use BlueprintAU\Finance\Values\{Money, TaxRate};
use BlueprintAU\Finance\Enums\Currency;

$gst = TaxRate::percentage(10, 'GST');

$fromGross = $gst->fromInclusive(Money::fromDollars('125.25', Currency::AUD));
// $fromGross->subtotal, $fromGross->taxAmount, $fromGross->gross

$fromNet = $gst->fromExclusive(Money::fromDollars('125.25', Currency::AUD));

Margin

Compute gross profit, margin, and markup between revenue and cost.

use BlueprintAU\Finance\Accounting\Margin;
use BlueprintAU\Finance\Values\Money;
use BlueprintAU\Finance\Enums\Currency;

$margin = new Margin(
    revenue: Money::fromDollars('150.00', Currency::AUD),
    cost: Money::fromDollars('100.00', Currency::AUD),
);

$margin->getProfit();            // Money: $50.00
$margin->getMarginPercentage();  // float: 33.33
$margin->getMarkupPercentage();  // float: 50.0

Testing

composer install
vendor/bin/phpunit

License

MIT © Blueprint AU