dgtlinf/salary-calculator
Composer 安装命令:
composer require dgtlinf/salary-calculator
包简介
Multi-country salary calculator for Laravel, with modular country providers
README 文档
README
A modern, extensible Laravel package for standardized salary calculations across multiple countries.
Supports detailed breakdowns for gross, net, contributions, and total employer costs — starting with Serbia (RS).
📦 Installation
Install the package via Composer:
composer require dgtlinf/salary-calculator
⚙️ Usage Example
use Dgtlinf\SalaryCalculator\Facades\SalaryCalculator; use Dgtlinf\SalaryCalculator\Models\{ SalaryContext, EmployeeProfile, EmployerProfile }; $employee = new EmployeeProfile( firstName: 'Milan', lastName: 'Jovanović', address: 'Kralja Petra 10, Beograd', idNumber: '0101990123456', bankAccount: '160-123456789-01', position: 'Software Engineer' ); $employer = new EmployerProfile( name: 'Digital Infinity DOO', taxId: '110217311', registrationNumber: '21318507', address: 'Bulevar Kralja Petra I 89, Novi Sad', bankName: 'Raiffeisen Bank', bankAccount: '265-0001234567890-00' ); $context = new SalaryContext( 2025, 9, 'RS', vacationDays: 0, sickDays: 0, sickLeaveFullPay: false, yearsInService: 2, avgHourlyRateLast12Months: null, employee: $employee, employer: $employer ); // Create the calculator $calc = SalaryCalculator::for($context); // Run calculation from gross $result = $calc->fromGross(790729.64); // Optionally validate output structure before use $calc->validateOutput($result); return response()->json($result);
📊 Example JSON Response
{
"salary": {
"gross": {
"items": {
"regular_work": { "units": 176, "unit": "_hours", "per_unit": 4441.04, "basis": 1, "amount": 781623.59 },
"seniority_allowance": { "units": 176, "unit": "_hours", "per_unit": 4441.04, "basis": 0.008, "amount": 6252.99 },
"meal_allowance": { "units": 22, "unit": "_days", "per_unit": 64.84, "basis": 1, "amount": 1426.53 }
},
"total": 790729.64
},
"contributions_base": 656425,
"income_tax": { "base": 762306.64, "amount": 76230.66 },
"employee_contributions": { "total": 130628.58 },
"net_salary": 583870.4,
"employer_contributions": { "total": 99448.39 },
"total_salary_cost": 890178.03
},
"context": { "employee": { "firstName": "Milan" }, "employer": { "name": "Digital Infinity DOO" }, "country": "RS" },
"tax_table": { "year": 2025, "tax_rate": 0.1, "currency_code": "RSD" }
}
⚙️ Configuration
The package publishes a config file config/salary-calculator.php allowing full control over:
- Country providers and validators
- Default rounding precision
- Validation behavior and output structure
- Optional external tax table directory
php artisan vendor:publish --tag="salary-calculator-config"
🧩 Validation Behavior
SalaryCalculator::validateOutput($result) uses the config-defined validators to ensure data structure integrity.
Behavior can be customized in config/salary-calculator.php:
| Option | Description |
|---|---|
strict_validation |
Throw exception if validator missing |
fallback_to_base_validator |
Use BaseOutputValidator if no country-specific validator |
include_context_in_output |
Whether to include the context block in output |
🧪 Testing
composer test
🧱 Architecture Overview
- SalaryCalculatorManager — Resolves and loads the correct provider based on country and year.
- Country Providers — Contain tax rules and salary logic for each country (e.g.,
RSCountryProvider). - Output Validators — Verify structure of salary data before use (Payslip integration-ready).
- Tax Tables — Organized per country and year under
/SalaryProviders/{Country}/TaxTables/{Year}.php. - Traits — Shared helpers such as
RoundingTraitfor precision and numeric consistency.
🧾 Changelog
All notable changes are automatically documented in CHANGELOG.md.
Changelog updates automatically on each GitHub release.
🪪 License
The MIT License (MIT).
See LICENSE.md for more information.
👤 Author
Digital Infinity DOO
Bulevar Kralja Petra I 89, Novi Sad, Serbia
www.digitalinfinity.rs
dgtlinf/salary-calculator 适用场景与选型建议
dgtlinf/salary-calculator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「net」 「tax」 「laravel」 「calculator」 「payroll」 「salary」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dgtlinf/salary-calculator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dgtlinf/salary-calculator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dgtlinf/salary-calculator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The library provides us with a frame to build a workflow or a business process such as BPMN. Could execute tasks in parallel or delayed tasks
API client for validating Tax Identification Number.
Validate the format of EU vat numbers.
Multishipping support for the Mollie Payment Module for Magento 2
Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment But
Module allowing creation of tax rates and categories in the CMS via SiteConfig
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-05