laudis / fiscal
常见税务操作库
1.4.0
2021-11-20 21:10 UTC
Requires
- ext-json: *
- ext-pdo: *
- laudis/typed-enum: ^1.0
- php-ds/php-ds: ^1.0
Requires (Dev)
- ext-json: *
- cocur/slugify: ^4.0
- fakerphp/faker: ^1.16
- friendsofphp/php-cs-fixer: ^3.3
- phpunit/phpunit: ^9.0
- psalm/plugin-phpunit: ^0.16
- robmorgan/phinx: ^0.12.4
- symfony/uid: ^5.2
- vimeo/psalm: ^4.12
README
安装
通过 composer 安装
composer require laudis/fiscal
通用用法
Laudis fiscal 库本质上是一个客户端,它从数据库中提取税务信息,并提供类来将其转换为业务逻辑。
初始化仓库
一切从仓库开始
$repository = new \Laudis\Fiscal\FiscalRepository(new PDO(getenv('PDO_DSN'), getenv('USERNAME'), getenv('PASSWORD')));
加载索引值
索引值是在一段时间内变化的值。Laudis fiscal 将索引值解释为基本日期范围,其中包含一个值和一些标识信息。
// The date argument can either be a string in the Y-m-d format, an integer representing a timestamp, or an object implementing \DateTimeInterface. $values = $repository->loadIndexedValuesWithSlugs('2010-01-01', ['cpi', 'euribor', 'protected-property-car-amount-AUS']); $euribor = $values->get('euribor'); // Returns the euribor of that day $cpi = $values->get('cpi'); // Throws OutOfBoundsException if it wasn't found for that day $protected = $values->get('protected-property-car-amount-AUS', null); // Will return null instead of throwing when it wasn't found on that day.
加载比例
比例是由规则组成的范围组合,这些规则将应用一个因子在每个规则的价值。
示例
比利时个人税2020年征税年度比例(是的,这是真的)
Laudis fiscal 理解这种逻辑,可以像这样加载
$scale = $repository->loadScaleWithSlugs(DateTime::createFromFormat('Y-m-d', '2020-01-01'), ['personal-tax'])->first(); echo $scale->calculate(50000); // echos 13 250.00 echo $scale->calculate(8000); // echos 2000
比例可以进一步被利用来完全解释它们所执行的逻辑
$explanation = $scale->explain(50000);
税务功能支持
要求
- PHP >= 7.4
- 一个 mariadb/mysql 数据库
- ext-json
- ext-pdo
- ext-pdo_mysql