PHPackages                             rip-byrokrat/accounting - 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. rip-byrokrat/accounting

ActiveLibrary

rip-byrokrat/accounting
=======================

Analysis and generation of bookkeeping data according to Swedish standards

01PHP

Since May 24Pushed 2y agoCompare

[ Source](https://github.com/tarreislam/accounting)[ Packagist](https://packagist.org/packages/rip-byrokrat/accounting)[ RSS](/packages/rip-byrokrat-accounting/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![byrokrat](res/logo.svg)](res/logo.svg)

Accounting
==========

[](#accounting)

[![Packagist Version](https://camo.githubusercontent.com/d59f225e907913060249b9fa6d0e85a034d8d3f942e06b6048de87e8531025a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6279726f6b7261742f6163636f756e74696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/byrokrat/accounting)[![Build Status](https://camo.githubusercontent.com/58706f46a591b82a033241298dc6190ac28890c6d1f7c5d43d6e50bc48ab267c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6279726f6b7261742f6163636f756e74696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/byrokrat/accounting)

Analysis and generation of bookkeeping data according to Swedish standards.

Installation
------------

[](#installation)

```
composer require byrokrat/accounting
```

Why?
----

[](#why)

Although it would be possible to build a general bookkeeping application on top of Accounting this was never the primary concern. The motivation for creating Accounting was to provide solutions for two scenarios:

1. The need to generate bookkeeping data using templates (and possibly import to general bookkeeping).
2. The need to analyze accounting data (possibly exported from general bookkeeping).

To enable import and export of bookkeeping data Accounting supports parsing and generating files in the [SIE4](http://www.sie.se/) file format.

Usage
-----

[](#usage)

1. [Generating accounting data using templates](#generating-accounting-data-using-templates)
2. [Handling monetary amounts](#handling-monetary-amounts)
3. [Writing SIE4 files](#writing-sie4-files)
4. [Parsing SIE4 files](#parsing-sie4-files)
5. [Querying accounting data](#querying-accounting-data)
6. [Writing macros](#writing-macros)

### Handling monetary amounts

[](#handling-monetary-amounts)

*Accounting* uses [Moneyphp](https://moneyphp.org) to hande monetary amounts. More information on the money api can be found on their website. In these examples we need to format amounts, wich we do using the simple `DecimalMoneyFormatter`.

```
use Money\Formatter\DecimalMoneyFormatter;
use Money\Currencies\ISOCurrencies;

$moneyFormatter = new DecimalMoneyFormatter(new ISOCurrencies());
```

### Generating accounting data using templates

[](#generating-accounting-data-using-templates)

First we create an accounting template. Values enclosed in curly braces `{}`are placeholders for values supplied at render time.

```
use byrokrat\accounting\Template\TransactionTemplate;
use byrokrat\accounting\Template\VerificationTemplate;

$template = new VerificationTemplate(
    description: '{description}',
    transactionDate: '{date}',
    transactions: [
        new TransactionTemplate(
            account: '1920',
            amount: '{bank_amount}'
        ),
        new TransactionTemplate(
            account: '{income_account}',
            amount: '{income_amount}'
        )
    ]
);
```

Create an account plan, a set of accounts.

```
use byrokrat\accounting\Container;
use byrokrat\accounting\Dimension\Account;

$accounts = new Container(
    new Account(id: '1920', description: 'Bank'),
    new Account(id: '3000', description: 'Incomes'),
    new Account(id: '3010', description: 'Sales'),
);
```

And to render verifications we supply a list of translation values and the account plan.

```
use byrokrat\accounting\Template\TemplateRendererFactory;
use byrokrat\accounting\Template\Translator;

$renderer = (new TemplateRendererFactory)->createRenderer($accounts);

$verifications = new Container(
    $renderer->render(
        $template,
        new Translator([
            'description' => 'Some donation...',
            'date' => '2021-01-12',
            'bank_amount' => '999',
            'income_amount' => '-999',
            'income_account' => '3000'
        ])
    ),
    $renderer->render(
        $template,
        new Translator([
            'description' => 'Daily cash register',
            'date' => '2021-01-12',
            'bank_amount' => '333',
            'income_amount' => '-333',
            'income_account' => '3010'
        ])
    )
);
```

### Writing SIE4 files

[](#writing-sie4-files)

```
use byrokrat\accounting\Sie4\Writer\Sie4iWriter;

$sie = (new Sie4iWriter)->generateSie($verifications);
```

### Parsing SIE4 files

[](#parsing-sie4-files)

```
use byrokrat\accounting\Sie4\Parser\Sie4Parser;

$parser = new Sie4Parser();

$container = $parser->parse($sie);

echo $container->select()->verifications()->first()->getDescription();
```

### Querying accounting data

[](#querying-accounting-data)

#### Listing accounts

[](#listing-accounts)

```
$orderedAccounts = $verifications->select()->accounts()->orderById()->asArray();
```

#### Calculate book magnitude

[](#calculate-book-magnitude)

```
echo $moneyFormatter->format(
    $verifications->select()->verifications()->asSummary()->getMagnitude()
);
```

#### Sorting transactions into a ledger (huvudbok)

[](#sorting-transactions-into-a-ledger-huvudbok)

An example of how Accounting may be used to sort transactions inte a ledger (or *huvudbok* as it is known in swedish).

```
$verifications->select()->accounts()->orderById()->each(function ($account) use ($moneyFormatter) {
    printf(
        "%s %s\nIncoming balance %s\n",
        $account->getId(),
        $account->getDescription(),
        $moneyFormatter->format($account->getSummary()->getIncomingBalance())
    );

    foreach ($account->getTransactions() as $trans) {
        printf(
            "%s\t%s\t%s\n",
            $trans->getVerificationId(),
            $account->getDescription(),
            $moneyFormatter->format($trans->getAmount()),
        );
    }

    printf(
        "Outgoing balance %s\n\n",
        $moneyFormatter->format($account->getSummary()->getOutgoingBalance())
    );
});
```

### Writing macros

[](#writing-macros)

Macros expose the posibility to extend the query api on the fly, without having to subclass the Query class itself. It is suitable for adding project specific order and filter methods. If we for example whant to filter on description we can define a macro for this:

```
use byrokrat\accounting\Query;

Query::macro('filterOnDescription', function (string $desc) {
    return $this->filter(
        fn($item) => str_contains($item->getDescription(), $desc)
    );
});
```

And then use it to query accounting data:

```
echo $verifications->select()->filterOnDescription('donation')->first()->getDescription();
```

Hacking
-------

[](#hacking)

With [composer](https://getcomposer.org/) installed as `composer` and [phive](https://phar.io/) installed as `phive`

```
make
```

Or use something like

```
make COMPOSER_CMD=./composer.phar PHIVE_CMD=./phive.phar
```

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 99.5% 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.

### Community

Maintainers

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

---

Top Contributors

[![hanneskod](https://avatars.githubusercontent.com/u/1369274?v=4)](https://github.com/hanneskod "hanneskod (193 commits)")[![tarreislam](https://avatars.githubusercontent.com/u/9095570?v=4)](https://github.com/tarreislam "tarreislam (1 commits)")

### Embed Badge

![Health badge](/badges/rip-byrokrat-accounting/health.svg)

```
[![Health](https://phpackages.com/badges/rip-byrokrat-accounting/health.svg)](https://phpackages.com/packages/rip-byrokrat-accounting)
```

PHPackages © 2026

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