@php
$allowances = json_decode($payslip->allowance ?? '[]');
$commissions = json_decode($payslip->commission ?? '[]');
$overtimes = json_decode($payslip->overtime ?? '[]');
$other_payments = json_decode($payslip->other_payment ?? '[]');
$deductions = json_decode($payslip->saturation_deduction ?? '[]');
$loans = json_decode($payslip->loan ?? '[]');
// Combine all earnings into one array
$all_earnings = [];
foreach ($allowances as $item) {
$full = $item->type == 'percentage' ? ($item->amount * $payslip->basic_salary) / 100 : $item->amount;
$actual = $item->type == 'percentage' ? ($item->actual_amount * $payslip->basic_salary) / 100 : $item->actual_amount;
$all_earnings[] = ['title' => $item->title, 'full' => $full, 'actual' => $actual];
}
foreach ($commissions as $item) {
$amount = $item->type == 'percentage' ? ($item->amount * $payslip->basic_salary) / 100 : $item->amount;
$all_earnings[] = ['title' => $item->title, 'full' => $amount, 'actual' => $amount];
}
foreach ($other_payments as $item) {
$amount = $item->type == 'percentage' ? ($item->amount * $payslip->basic_salary) / 100 : $item->amount;
$all_earnings[] = ['title' => $item->title, 'full' => $amount, 'actual' => $amount];
}
foreach ($overtimes as $ot) {
$amount = ($ot->number_of_days ?? 0) * ($ot->hours ?? 0) * ($ot->rate ?? 0);
$all_earnings[] = ['title' => $ot->title, 'full' => $amount, 'actual' => $amount];
}
// Combine all deductions into one array (excluding LOP with 0 amount)
$all_deductions = [];
foreach ($deductions as $deduct) {
$amount = $deduct->type == 'percentage' ? ($deduct->amount * $payslip->basic_salary) / 100 : $deduct->amount;
if ($amount > 0) {
$all_deductions[] = ['title' => $deduct->title, 'amount' => $amount];
}
}
foreach ($loans as $loan) {
$amount = $loan->amount ?? 0;
if ($amount > 0) {
$all_deductions[] = ['title' => $loan->title ?? 'Loan', 'amount' => $amount];
}
}
$totalFullEarning = 0;
$totalActualEarning = 0;
$totalDeduction = 0;
// Calculate totals for earnings
foreach ($all_earnings as $earning) {
$totalFullEarning += $earning['full'];
$totalActualEarning += $earning['actual'];
}
// Calculate total deductions
foreach ($all_deductions as $deduction) {
$totalDeduction += $deduction['amount'];
}
// Determine the maximum number of rows needed
$maxRows = max(count($all_earnings), count($all_deductions));
@endphp
@for ($i = 0; $i < $maxRows; $i++)
{{-- Earnings Column --}}
@if ($i < count($all_earnings))
@php
$earning = $all_earnings[$i];
@endphp
| {{ $earning['title'] }} |
{{ \Auth::user()->priceFormat($earning['full']) }} |
{{ \Auth::user()->priceFormat($earning['actual']) }} |
@else
| | |
@endif
{{-- Deductions Column --}}
@if ($i < count($all_deductions))
@php
$deduction = $all_deductions[$i];
@endphp
{{ $deduction['title'] }} |
{{ \Auth::user()->priceFormat($deduction['amount']) }} |
@else
| |
@endif
@endfor
| {{ __('Total Earnings') }} |
{{ \Auth::user()->priceFormat($totalFullEarning) }} |
{{ \Auth::user()->priceFormat($totalActualEarning) }} |
{{ __('Total Deduction') }} |
{{ \Auth::user()->priceFormat($totalDeduction) }} |
@php
$netSalary = round($payslip->net_payble);
$netPay = max(0, round($payslip->net_payble));
$fmt = new \NumberFormatter('en_IN', \NumberFormatter::SPELLOUT);
$inWords = ucfirst($fmt->format($netPay)) . ' rupees only';
@endphp
{{ __('Net Pay for the Month (Total Earning - Total Deduction):') }}
{{ \Auth::user()->priceFormat($netSalary) }}
( {{ $inWords }} )
{{ __('THIS IS A SYSTEM GENERATED PAYSLIP AND DOES NOT REQUIRE SIGNATURE') }}