rezzza/accounting

会计工具

安装数: 15,319

依赖项: 0

建议者: 0

安全性: 0

星标: 22

关注者: 8

分支: 8

公开问题: 0

类型:独立

v1.0.2 2015-12-15 09:11 UTC

This package is not auto-updated.

Last update: 2024-09-11 12:19:55 UTC


README

会计库是PHP中通用会计的现代化伴侣。

验证器

增值税

该库提供了2个增值税验证器

  • VatValidator:适用于所有已知的增值税号系统。
  • ViesValidator:仅适用于欧洲的增值税号。

格式化器

增值税

待办事项

国际银行账号(IBAN)

待办事项

操作

痛点

会计操作有时会受到错误的影响。为什么?因为它们是由一系列算术计算组成的,但如果它们使用数学,则有自己的规则,例如舍入结果、管理特定货币的小数位数等...这就是为什么你应该使用这个库的原因;)

优点

  • 计算将按照你想要的顺序进行(见鬼,不要在这次操作之前计算这个税!)。
  • 每种货币的小数位数都得到尊重。
  • 每个计算都正确应用了舍入规则。
  • 最后但同样重要的是,你可以开发自己的操作集,并将其作为计算模板应用。你只需在之后装饰你的结果,很简单;)

示例

$resultsSet = new OperationSetResult(array(
    'discount_rate' => new Percentage(10),   // Our special discount rate for that lucky guy
    'vat_rate'      => new Percentage(19.6), // French VAT rate
));

$f  = new Factory();
$os = new OperationSet(
    array(
        'price_discounted' => new Operation(
            new Reference\Reference('price_excl_taxes'),
            Operation::MINORATE,
            new Reference\Reference('discount_rate')
        ),
        'price_incl_taxes' => new Operation(
            $f->value(new Reference\Reference('price_discounted')),
            Operation::MAJORATE,
            new Reference\Reference('vat_rate')
        ),
    ),
    $resultsSet
);

$os
    ->getResultsSet()
    ->add(new Price(100, 'EUR'), 'price_excl_taxes');
$os->compute();

echo sprintf("%s\n", $os->getResultsSet());
discount_rate: 10%
vat_rate: 19.6%
price_excl_taxes: 100€
price_discounted: 100€ minorate by 10% => 90€ \ 10€
price_incl_taxes: 90€ majorate by 19.6% => 107.64€ \ 17.64€

相同的事情,但使用日元(0位小数货币)

[...]

$os
    ->getResultsSet()
    ->add(new Price(100, 'EUR'), 'price_excl_taxes');
$os->compute();

echo sprintf("%s\n", $os->getResultsSet());
discount_rate: 10%
vat_rate: 19.6%
price_excl_taxes: 100¥JP
price_discounted: 100¥JP minorate by 10% => 90¥JP \ 10¥JP
price_incl_taxes: 90¥JP majorate by 19.6% => 108¥JP \ 18¥JP

Twig扩展

你必须将此扩展定义为服务

<service id="rezzza.accounting.twig.extension.iban" class="Rezzza\Accounting\Twig\Extension\IbanExtension" public="false">
    <tag name="twig.extension" />
</service>
{{ "FR1337133713371337133713371"|iban }}
{{ "FR133  7133713371337133713371"|iban }}

{# will output FR13 3713 3713 3713 3713 3713 371 #}