byrokrat / 会计
根据瑞典标准分析和生成会计数据
1.0.1
2019-01-23 14:25 UTC
Requires
- php: ^7.1
- byrokrat/amount: ^2
This package is auto-updated.
Last update: 2024-09-19 21:19:07 UTC
README
会计
根据瑞典标准分析和生成会计数据。
安装
composer require byrokrat/accounting
为什么?
尽管可以在会计之上构建一个通用的会计应用程序,但这从来不是主要关注点。创建会计的动机是为了提供两个场景的解决方案
- 需要使用模板(可能导入到通用会计)生成会计数据。
- 需要分析会计数据(可能从通用会计导出)。
为了实现会计数据的导入和导出,会计支持解析和生成SIE4文件格式的文件。
使用方法
处理货币金额
会计使用Moneyphp来处理货币金额。更多关于money api的信息可以在他们的网站上找到。在这些示例中,我们需要格式化金额,我们使用简单的DecimalMoneyFormatter
来做到这一点。
use Money\Formatter\DecimalMoneyFormatter; use Money\Currencies\ISOCurrencies; $moneyFormatter = new DecimalMoneyFormatter(new ISOCurrencies());
使用模板生成会计数据
首先,我们创建一个会计模板。花括号{}
内的值是渲染时提供的值的占位符。
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}' ) ] );
创建一个账户计划,一组账户。
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'), );
为了渲染验证,我们提供一组翻译值和账户计划。
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' ]) ) );
编写SIE4文件
use byrokrat\accounting\Sie4\Writer\Sie4iWriter; $sie = (new Sie4iWriter)->generateSie($verifications);
解析SIE4文件
use byrokrat\accounting\Sie4\Parser\Sie4Parser; $parser = new Sie4Parser(); $container = $parser->parse($sie); echo $container->select()->verifications()->first()->getDescription();
查询会计数据
列出账户
$orderedAccounts = $verifications->select()->accounts()->orderById()->asArray();
计算账本规模
echo $moneyFormatter->format( $verifications->select()->verifications()->asSummary()->getMagnitude() );
将交易分类到账簿(主账簿)中
会计如何用于将交易分类到账簿(或瑞典语中的huvudbok)的示例。
$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()) ); });
编写宏
宏允许在运行时动态扩展查询API,而无需直接子类化Query类。它适用于添加特定于项目的排序和过滤方法。例如,如果我们想根据描述进行过滤,我们可以为这个定义一个宏
use byrokrat\accounting\Query; Query::macro('filterOnDescription', function (string $desc) { return $this->filter( fn($item) => str_contains($item->getDescription(), $desc) ); });
然后使用它来查询会计数据
echo $verifications->select()->filterOnDescription('donation')->first()->getDescription();
黑客攻击
安装了composer
作为composer
和phive
作为phive
make
或者使用类似的东西
make COMPOSER_CMD=./composer.phar PHIVE_CMD=./phive.phar