byrokrat/accounting
Composer 安装命令:
composer require byrokrat/accounting
包简介
Analysis and generation of bookkeeping data according to Swedish standards
关键字:
README 文档
README
Accounting
Analysis and generation of bookkeeping data according to Swedish standards.
Installation
composer require byrokrat/accounting
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:
- The need to generate bookkeeping data using templates (and possibly import to general bookkeeping).
- 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 file format.
Usage
- Generating accounting data using templates
- Handling monetary amounts
- Writing SIE4 files
- Parsing SIE4 files
- Querying accounting data
- Writing macros
Handling monetary amounts
Accounting uses Moneyphp 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
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
use byrokrat\accounting\Sie4\Writer\Sie4iWriter; $sie = (new Sie4iWriter)->generateSie($verifications);
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
Listing accounts
$orderedAccounts = $verifications->select()->accounts()->orderById()->asArray();
Calculate book magnitude
echo $moneyFormatter->format( $verifications->select()->verifications()->asSummary()->getMagnitude() );
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
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
With composer installed as composer and
phive installed as phive
make
Or use something like
make COMPOSER_CMD=./composer.phar PHIVE_CMD=./phive.phar
byrokrat/accounting 适用场景与选型建议
byrokrat/accounting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.64k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2016 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Accounting」 「bookkeeping」 「SIE」 「SIE4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 byrokrat/accounting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byrokrat/accounting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 byrokrat/accounting 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP port of https://github.com/barsoom/sie
Cliente PHP para la API REST del SIE del Banco de México
Moneybird API client for PHP
Access auditing middleware intended for use with Slim Framework applications
Moneybird OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Accounting module for atmosphere and laravel
统计信息
- 总下载量: 1.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2016-04-15