承接 rip-byrokrat/accounting 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rip-byrokrat/accounting

Composer 安装命令:

composer require rip-byrokrat/accounting

包简介

Analysis and generation of bookkeeping data according to Swedish standards

README 文档

README

byrokrat

Accounting

Packagist Version Build Status

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:

  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 file format.

Usage

  1. Generating accounting data using templates
  2. Handling monetary amounts
  3. Writing SIE4 files
  4. Parsing SIE4 files
  5. Querying accounting data
  6. 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

rip-byrokrat/accounting 适用场景与选型建议

rip-byrokrat/accounting 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Accounting」 「bookkeeping」 「SIE」 「SIE4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rip-byrokrat/accounting 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rip-byrokrat/accounting 我们能提供哪些服务?
定制开发 / 二次开发

基于 rip-byrokrat/accounting 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-05-24