PHP code example of riod94 / payroll-calculator-indonesia
1. Go to this page and download the library: Download riod94/payroll-calculator-indonesia library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
riod94 / payroll-calculator-indonesia example snippets
ayrollCalculator\PayrollCalculator;
use PayrollCalculator\Constants\CalculationConstants;
// Create employee
$employee = new PayrollCalculator\DataStructures\Employee(
name: 'John Doe',
earnings: new PayrollCalculator\DataStructures\Earnings(
base: 10000000, // Basic salary
fixedAllowance: 2000000 // Fixed allowance
),
taxable: true,
hasNPWP: true
);
// Initialize calculator
$calculator = new PayrollCalculator($employee);
// Calculate with GROSS method
$result = $calculator->getCalculation();
// Get results
echo "Take Home Pay: " . number_format($result->takeHomePay, 2) . "\n";
echo "Monthly Gross: " . number_format($result->earnings->monthly->gross, 2) . "\n";
echo "Monthly Nett: " . number_format($result->earnings->monthly->nett, 2) . "\n";
echo "PPh21 Tax: " . number_format($result->taxable->pph->liability->monthly, 2) . "\n";
// init employee
$calculator->employee->name = "Tuan A";
$calculator->employee->ptkpStatus = "K/0";
$calculator->employee->hasNPWP = true;
$calculator->employee->permanentStatus = true;
$calculator->employee->yearPeriod = 2024;
$calculator->employee->monthPeriod = $month;
$calculator->employee->earnings->base = 10000000;
$calculator->employee->earnings->baseBeforeProrate = 10000000;
$calculator->employee->components->allowances->set("Tunjangan Jabatan", 20000000);
if (in_array($month, [2, 5])) {
$calculator->employee->components->allowances->set("Uang Lembur", 5000000);
}
if ($month === 7) {
$calculator->employee->onetime->bonus = 20000000;
}
if ($month === $monthPeriod) {
$calculator->employee->onetime->holidayAllowance = 60000000;
// Set Last Tax Period
$calculator->employee->lastTaxPeriod->annualGross = $annually->gross;
$calculator->employee->lastTaxPeriod->annualBonus = $annually->bonus;
$calculator->employee->lastTaxPeriod->annualHolidayAllowance = $annually->THR;
$calculator->employee->lastTaxPeriod->annualPPh21Paid = $annually->pph21Paid;
$calculator->employee->lastTaxPeriod->annualJIPEmployee = 1200000; // dibayar sendiri
$calculator->employee->lastTaxPeriod->annualZakat = 2400000; // dibayar sendiri
}
$result = $calculator->getCalculation();
if ($result) {
$items = (object) [
'month' => date("F", mktime(0, 0, 0, $month, 1, 2024)),
'base' => $result->earnings->base,
'allowance' => $calculator->employee->components->allowances->sum(),
'holidayAllowance' => $calculator->employee->onetime->holidayAllowance,
'bonus' => $calculator->employee->onetime->bonus,
'premi' => (object) [
'JKK' => $result->company->jkk ?? 0,
'JKM' => $result->company->jkm ?? 0
],
'gross' => $result->earnings->monthly->gross,
'terCategory' => $result->taxable->pph->ter->category,
'pph21' => $result->taxable->pph->liability->monthly,
];
$yearIncomes[] = $items;
$annually->gross += $items->base + $items->allowance + $items->premi->JKK + $items->premi->JKM;
$annually->jkk += $result->company->jkk;
$annually->jkm += $result->company->jkm;
$annually->bonus += $calculator->employee->onetime->bonus;
$annually->THR += $calculator->employee->onetime->holidayAllowance;
$annually->pph21Paid += $result->taxable->pph->liability->monthly;
}
}
echo "yearIncomes Tuan A Pada PT.Z\n";
print_r($yearIncomes);
$calculator = new PayrollCalculator();
// Configure company provisions
$calculator->Provisions->company->calculateBPJSKesehatan = true;
$calculator->Provisions->company->calculateOvertime = true;
$calculator->Provisions->company->JKK = true;
$calculator->Provisions->company->JKM = true;
$calculator->Provisions->company->JHT = true;
$calculator->Provisions->company->JIP = true;
// Configure employee
$calculator->Employee->name = "Employee Name";
$calculator->Employee->ptkpStatus = "K/0";
$calculator->Employee->hasNPWP = true;
$calculator->Employee->permanentStatus = true;
$calculator->Employee->earnings->base = 10000000;
// Set calculation method
$calculator->method = PayrollCalculator::GROSS; // or NETT, GROSS_UP