PHPackages                             sirprize/invoiced - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sirprize/invoiced

ActiveLibrary

sirprize/invoiced
=================

Totals, subtotals, linetotals, VAT-calculations and proper rounding for invoices.

2.0.0(3y ago)3114↓100%1MITPHPPHP ^7.2 || ^8.0

Since Sep 2Pushed 1w ago1 watchersCompare

[ Source](https://github.com/sirprize/invoiced)[ Packagist](https://packagist.org/packages/sirprize/invoiced)[ Docs](https://github.com/sirprize/invoiced)[ RSS](/packages/sirprize-invoiced/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

Invoiced
========

[](#invoiced)

Totals, subtotals, linetotals, VAT-calculations and proper rounding for invoices.

Thanks
------

[](#thanks)

See [Invoices: How to properly round and calculate totals](https://makandracards.com/makandra/1505-invoices-how-to-properly-round-and-calculate-totals)

Usage
-----

[](#usage)

Invoiced handles money amounts in cents.

### Discount Resolver

[](#discount-resolver)

Discount resolver runs a set of custom rules in charge of figuring out an amount to subtract from a given product price.

#### Defining a custom rule

[](#defining-a-custom-rule)

```
class TwentyPercentRule implements RuleInterface
{
    protected $product = null;

    public function __construct(\Product $product)
    {
        $this->product = $product;
    }

    public function getAmount()
    {
        return $this->product->getPrice() * 0.2;
    }
}

```

#### Running the rules

[](#running-the-rules)

```
use Sirprize\Invoiced\BasePrice\Discount\Resolver;
use Sirprize\Invoiced\BasePrice\Discount\RuleInterface;

$product = new \Product(); // this can be anything really...
$resolver = new Resolver(Resolver::BEST); // the rule returning the biggest amount wins
$resolver->addRule(new TwentyPercentRule($product));
$discountAmount = $resolver->getAmount($product->getPrice());
$finalPrice = $product->getPrice() - $discountAmount;

```

### Invoice

[](#invoice)

#### Invoice Line Item

[](#invoice-line-item)

```
use Sirprize\Invoiced\VatPrice\LineItem;

$lineItem = new LineItem(780, 19, true, 1); // $amount, $vatRate, $priceIncludesVat, $quantity

// line item totals
$lineItemGrossTotal = $lineItem->getPrice()->getGrossAmount();
$lineItemVatTotal = $lineItem->getPrice()->getVatAmount();
$lineItemNetTotal = $lineItem->getPrice()->getNetAmount();

// unit
$unitGrossAmount = $lineItem->getUnitPrice()->getGrossAmount();
$unitVatAmount = $lineItem->getUnitPrice()->getVatAmount();
$unitNetAmount = $lineItem->getUnitPrice()->getNetAmount();

```

#### Invoice Sum

[](#invoice-sum)

```
use Sirprize\Invoiced\VatPrice\LineItem;
use Sirprize\Invoiced\VatPrice\Sum;

$sum = new Sum();

$sum
    ->addLineItem(new LineItem(780, 19, true, 1))
    ->addLineItem(new LineItem(2500, 7, true, 1))
;

$grossTotalAmount = $sum->getPrice()->getGrossAmount();
$vatTotalAmount = $sum->getPrice()->getVatAmount();
$netTotalAmount = $sum->getPrice()->getNetAmount();

```

### Subtotals

[](#subtotals)

Invoices often feature all kinds of subtotals such as discounts, items total, shipping and handling etc.

#### Base Price

[](#base-price)

A base price is just a simple object holding the baseprice, the discount amount and the final price of a product:

```
use Sirprize\Invoiced\BasePrice\Price;

$price = new Price(1000, 220); // $baseAmount, $discountAmount

$baseAmount = $price->getBaseAmount();
$discountAmount = $price->getDiscountAmount();
$finalAmount = $price->getFinalAmount();

```

#### Base Price Line Item

[](#base-price-line-item)

```
use Sirprize\Invoiced\BasePrice\LineItem;

$lineItem = new LineItem($price, 3); // $price, $quantity

// line item totals
$lineItemBaseAmount = $lineItem->getPrice()->getBaseAmount();
$lineItemDiscountAmount = $lineItem->getPrice()->getDiscountAmount();
$lineItemFinalAmount = $lineItem->getPrice()->getFinalAmount();

// unit
$unitBaseAmount = $lineItem->getUnitPrice()->getBaseAmount();
$unitDiscountAmount = $lineItem->getUnitPrice()->getDiscountAmount();
$unitFinalAmount = $lineItem->getUnitPrice()->getFinalAmount();

```

#### Base Price Sum

[](#base-price-sum)

Base prices are then added to line items and summed up:

```
use Sirprize\Invoiced\BasePrice\LineItem;
use Sirprize\Invoiced\BasePrice\Sum;
use Sirprize\Invoiced\BasePrice\Price;

$sum = new Sum();

$sum
    ->addLineItem(new LineItem(new Price(1000, 220), 3))
    ->addLineItem(new LineItem(new Price(3000, 500), 10))
;

$baseTotalAmount = $sum->getPrice()->getBaseAmount();
$discountTotalAmount = $sum->getPrice()->getDiscountAmount();
$finalTotalAmount = $sum->getPrice()->getFinalAmount();

```

License
-------

[](#license)

See LICENSE.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance64

Regular maintenance activity

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1629 days

Total

2

Last Release

1129d ago

Major Versions

1.0.0 → 2.0.02023-02-18

PHP version history (2 changes)1.0.0PHP &gt;=5.3.2

2.0.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2aa6b6ece804d8a151ee35b0be09d68fda456edea22a53986bb49ece0a86782?d=identicon)[sirprize](/maintainers/sirprize)

---

Top Contributors

[![sirprize](https://avatars.githubusercontent.com/u/81617?v=4)](https://github.com/sirprize "sirprize (15 commits)")

---

Tags

roundinginvoicesvat

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirprize-invoiced/health.svg)

```
[![Health](https://phpackages.com/badges/sirprize-invoiced/health.svg)](https://phpackages.com/packages/sirprize-invoiced)
```

###  Alternatives

[mpociot/vat-calculator

EU VAT calculation, the way it should be.

1.3k3.8M16](/packages/mpociot-vat-calculator)[laraveldaily/laravel-invoices

Missing invoices for Laravel

1.5k1.2M4](/packages/laraveldaily-laravel-invoices)[ronanguilloux/isocodes

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book and Music Industries, Phone numbers &amp; Zipcodes for many countries

8103.3M23](/packages/ronanguilloux-isocodes)[ibericode/vat

PHP library for dealing with EU VAT

4453.1M7](/packages/ibericode-vat)[dragonbe/vies

EU VAT numbers validation using the VIES Service of the European Commission

2793.9M13](/packages/dragonbe-vies)[commerceguys/tax

Tax library with a flexible data model, predefined tax rates, powerful resolving logic.

284757.1k](/packages/commerceguys-tax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
