mibo / prices
PHP 价格库
2.0.1
2024-05-04 16:56 UTC
Requires
- php: ^8.2
- mibo/currencies: ^1.0
- mibo/properties: ^1.1
- mibo/taxonomy: ^1.1
- mibo/vat: ^2.0
Requires (Dev)
- jetbrains/phpstorm-attributes: ^1.0
- phpstan/phpstan: ^1.5
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/php-invoker: ^4.0
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^3.6
Suggests
- mibo/laravel-properties: Implementation for Laravel framework and Eloquent ORM
- mibo/taxonomy-cpa: Classification of Products by Activity (CPA) to retrieve VAT rates by category
- mibo/vat-resolver-eu: VAT resolver based on the CPA for EU countries
- mibo/vat-value-resolver-eu: VAT value resolver for EU countries
Provides
README
此库提供了一个Price类,可以用来表示一个可售或具有价值的对象中的价格。
目标
- 计算多个价格;
- 计算不同货币的多个价格;
- 计算不同税率下的多个价格;
- 以上任一或所有组合。
使用此库的用户应主要使用\MiBo\Prices\Price
类,它实现了\MiBo\Prices\Contracts\PriceInterface
,或\MiBo\Properties\Contracts\NumericalProperty
,这意味着,该类遵循本地的add
、subtract
方法。PriceInterface通过添加getValueOfVAT
和getValueWithVAT
方法扩展了NumericalProperty接口,这些方法可以用来获取增值税或两者的值。然后,接口通过forCountry
方法扩展了PropertyInterface,该方法可以在需要更改特定国家的价格增值税时使用。
安装
composer require mibo/prices
用法
$price = new \MiBo\Prices\Price( 10, \MiBo\Prices\Units\Price\Currency::get("EUR"), \MiBo\Prices\Calculators\PriceCalc::getVATManager()->retrieveVAT($classification, 'SVK') ); $price->getValue(); // 10 $price->getValueOfVAT(); // 2 (20% of 10 for the day of writing this) $price->getValueWithVAT(); // 12 (10 + 2) $price->forCountry("CZE"); $price->getValueWithVAT(); // 11.5 (10 + 1.5 for the day of writing this)
注意
- 在使用货币转换之前,必须需要提供汇率转换的库。转换不是此库的一部分!
- 在使用增值税率转换之前,必须需要提供增值税率的库。转换不是此库的一部分!
库的逻辑
此库通过Price扩展了MiBo\Properties库,使用MiBo\VAT获取价格的增值税,并使用MiBo\Currencies获取价格的货币单位。
计算器
PriceCalc类用于计算多个价格,无论是相加还是相减。重点是使此过程在单一位置完成。计算器会检查货币和增值税率。
价格
\MiBo\Prices\Price
类(主要属性)是用户应使用的类。用户不应需要使用其他类。
更改、更新等。
此库不涵盖货币之间的转换,也不涵盖增值税率。如果需要解决这个问题,请查看Composer建议。如果为空,则专注于该领域的库尚未发布,但它们正在开发中,并将很快可用。
备注
请注意,比较价格是复杂的,应该小心处理。目前,此库提供了比较价格的方法,但该方法被标记为已弃用且为实验性,尽管它应该可以正常工作。用户应确保行为符合预期,因为比较包含增值税和货币的价格非常困难。