tawwfik/zakat-calculator
Composer 安装命令:
composer require tawwfik/zakat-calculator
包简介
A Laravel package for calculating zakat on money, gold, and silver.
README 文档
README
A comprehensive Laravel package for calculating zakat on various assets including money, gold, silver, business assets, and agricultural products. This package follows Islamic principles and supports multiple calculation methods.
Features
- Calculate zakat on multiple asset types:
- Cash and bank balances
- Gold (supports multiple karats)
- Silver
- Business assets (inventory, receivables, cash)
- Agricultural products
- Support for different calculation methods (Hanafi, Shafi'i, Maliki, Hanbali)
- Configurable nisab thresholds
- Real-time gold and silver price integration
- Detailed calculation breakdowns
- Caching support for better performance
- Comprehensive validation and error handling
Installation
You can install the package via composer:
composer require tawwfik/zakat-calculator
The package will automatically register its service provider.
Publishing Configuration
You can publish the configuration file using:
php artisan vendor:publish --provider="Tawfik\ZakatCalculator\ZakatServiceProvider" --tag="config"
This will create a config/zakat.php file in your config directory.
Usage
Basic Usage
use Tawfik\ZakatCalculator\ZakatCalculator; class ZakatController extends Controller { protected $calculator; public function __construct(ZakatCalculator $calculator) { $this->calculator = $calculator; } public function calculate(Request $request) { $result = $this->calculator ->setCash($request->cash) ->setGoldItems([ ['weight' => 100, 'karat' => 24], ['weight' => 50, 'karat' => 18] ]) ->setSilverWeight(500) ->setBusinessAssets([ 'inventory' => 5000, 'receivables' => 2000, 'cash_at_bank' => 3000 ]) ->setAgriculturalProducts([ ['value' => 10000, 'irrigated' => true], ['value' => 20000, 'irrigated' => false] ]) ->calculate(); return response()->json($result); } }
Available Methods
Asset Setting Methods
setCash(float $cash): Set cash amountsetGoldItems(array $goldItems): Set gold items with weight and karatsetSilverWeight(float $silverWeight): Set silver weightsetGoldPrice(float $goldPrice): Set gold price per gramsetSilverPrice(float $silverPrice): Set silver price per gramsetBusinessAssets(array $assets): Set business assetssetAgriculturalProducts(array $products): Set agricultural products
Configuration Methods
setCalculationMethod(string $method): Set calculation method (hanafi, shafi, maliki, hanbali)setNisabThreshold(float $threshold): Set custom nisab thresholdsetCacheEnabled(bool $enabled): Enable/disable cachingsetCacheTTL(int $ttl): Set cache time-to-live in seconds
Calculation Methods
calculate(): Calculate total zakatcalculateCashZakat(): Calculate zakat on cash onlycalculateGoldZakat(): Calculate zakat on gold onlycalculateSilverZakat(): Calculate zakat on silver onlycalculateBusinessZakat(): Calculate zakat on business assets onlycalculateAgriculturalZakat(): Calculate zakat on agricultural products only
Calculation Result
The calculate() method returns an array with the following information:
[
'total_assets' => [
'cash' => float,
'gold' => float,
'silver' => float,
'business' => float,
'agricultural' => float
],
'nisab_value' => float,
'is_eligible' => boolean,
'total_zakat' => float,
'details' => [
'cash' => [
'amount' => float,
'zakat' => float
],
'gold' => [
'items' => array,
'total_weight' => float,
'total_value' => float,
'zakat' => float
],
'silver' => [
'weight' => float,
'value' => float,
'zakat' => float
],
'business' => [
'assets' => array,
'total_value' => float,
'zakat' => float
],
'agricultural' => [
'products' => array,
'total_value' => float,
'zakat' => float
]
],
'calculation_method' => string
]
Configuration
After publishing the configuration file, you can customize the following settings in config/zakat.php:
Default Prices
'default_prices' => [ 'gold' => 0.00, // Set your default gold price per gram 'silver' => 0.00, // Set your default silver price per gram ],
Nisab Thresholds
'nisab' => [ 'gold' => 85, // grams of gold 'silver' => 595, // grams of silver ],
Currency Settings
'currency' => [ 'code' => 'SAR', // Currency code 'symbol' => 'ر.س', // Currency symbol 'position' => 'before', // Symbol position: 'before' or 'after' ],
Weight Unit
'weight_unit' => 'gram', // 'gram' or 'ounce'
Calculation Precision
'precision' => 2, // Number of decimal places
Supported Gold Karats
'supported_karats' => [24, 22, 21, 18, 14, 12, 10],
Cache Settings
'cache' => [ 'enabled' => true, 'ttl' => 3600, // Cache time-to-live in seconds ],
Calculation Methods
'calculation_methods' => [ 'default' => 'hanafi', // Available: 'hanafi', 'shafi', 'maliki', 'hanbali' ],
Business Assets
'business' => [ 'inventory' => true, // Include inventory in calculation 'receivables' => true, // Include receivables in calculation 'cash_at_bank' => true, // Include bank cash in calculation 'cash_in_hand' => true, // Include cash in hand in calculation ],
Agricultural Products
'agricultural' => [ 'irrigated_rate' => 0.05, // 5% rate for irrigated crops 'non_irrigated_rate' => 0.1, // 10% rate for non-irrigated crops ],
Advanced Usage Examples
Calculating Zakat for Gold Only
$result = $calculator ->setGoldItems([ ['weight' => 100, 'karat' => 24], ['weight' => 50, 'karat' => 18] ]) ->setGoldPrice(100) // Price per gram ->calculateGoldZakat();
Calculating Business Zakat
$result = $calculator ->setBusinessAssets([ 'inventory' => 5000, 'receivables' => 2000, 'cash_at_bank' => 3000, 'cash_in_hand' => 1000 ]) ->calculateBusinessZakat();
Calculating Agricultural Zakat
$result = $calculator ->setAgriculturalProducts([ ['value' => 10000, 'irrigated' => true], // Irrigated crops (5%) ['value' => 20000, 'irrigated' => false] // Non-irrigated crops (10%) ]) ->calculateAgriculturalZakat();
Using Different Calculation Methods
$result = $calculator ->setCalculationMethod('shafi') ->setCash(10000) ->setGoldItems([['weight' => 100, 'karat' => 24]]) ->calculate();
Error Handling
The package throws specific exceptions for different error cases:
InvalidInputException: Thrown for invalid input valuesInvalidKaratException: Thrown for unsupported gold karatsConfigurationException: Thrown for missing or invalid configuration
Example error handling:
use Tawfik\ZakatCalculator\Exceptions\InvalidInputException; try { $result = $calculator->setCash(-1000)->calculate(); } catch (InvalidInputException $e) { return response()->json(['error' => $e->getMessage()], 400); }
Testing
Run the tests using:
composer test
Contributing
Please see CONTRIBUTING.md for details.
Security
If you discover any security related issues, please email security@tawfik.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
tawwfik/zakat-calculator 适用场景与选型建议
tawwfik/zakat-calculator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 10, 最近一次更新时间为 2025 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「money」 「laravel」 「calculator」 「gold」 「islamic」 「silver」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tawwfik/zakat-calculator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tawwfik/zakat-calculator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tawwfik/zakat-calculator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
The Payum Yandex Money gateway
Yii2 extension help to get the result of the calculating from the aggregated delivery services
Alfabank REST API integration
Handles currency for Laravel 5.8
SDK com regras para cálculo de juros.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-29