feat: add salary type to cash transaction enum and update related components

This commit is contained in:
Yoga Pangestu 2026-08-16 14:26:55 +07:00
parent c415493ee1
commit 0947cf3737
5 changed files with 44 additions and 8 deletions

View File

@ -12,6 +12,7 @@ enum CashTransactionType: string
case EXPENSE = 'expense';
case WITHDRAWAL = 'withdrawal';
case EMPLOYEE_ADVANCE = 'employee_advance';
case SALARY = 'salary';
public function label(): string
{
@ -20,6 +21,7 @@ public function label(): string
self::EXPENSE => 'Pengeluaran',
self::WITHDRAWAL => 'Withdrawal',
self::EMPLOYEE_ADVANCE => 'Kasbon',
self::SALARY => 'Gaji',
};
}
}

View File

@ -51,7 +51,7 @@ public function create(): Response
'employees' => $this->getEmployees(),
'channelOptions' => OrderChannel::toSelect(),
'paymentTypeOptions' => PaymentType::toSelect(),
'priceTypeOptions' => PriceType::toSelect()->filter(fn ($p) => $p['value'] !== PriceType::CAPITAL->value)->values(),
'priceTypeOptions' => PriceType::toSelect()->filter(fn ($p) => ! in_array($p['value'], [PriceType::CAPITAL->value, PriceType::REJECT_CAPITAL->value]))->values(),
]);
}
@ -74,7 +74,7 @@ public function edit(Order $transaction): Response
'employees' => $this->getEmployees(),
'channelOptions' => OrderChannel::toSelect(),
'paymentTypeOptions' => PaymentType::toSelect(),
'priceTypeOptions' => PriceType::toSelect()->filter(fn ($p) => $p['value'] !== PriceType::CAPITAL->value)->values(),
'priceTypeOptions' => PriceType::toSelect()->filter(fn ($p) => ! in_array($p['value'], [PriceType::CAPITAL->value, PriceType::REJECT_CAPITAL->value]))->values(),
]);
}

View File

@ -3,18 +3,21 @@
namespace App\Services\Admin\Finance\Payroll;
use App\Concerns\HasRoleChecks;
use App\Enums\CashTransactionType;
use App\Enums\PayrollPeriodStatus;
use App\Enums\PayrollStatus;
use App\Enums\Role;
use App\Models\Payroll;
use App\Models\PayrollPeriod;
use App\Services\Concerns\HandlesCashTransactions;
use App\Services\NotificationService;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
class PayrollPeriodService
{
use HasRoleChecks;
use HandlesCashTransactions, HasRoleChecks;
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = [], ?int $highlight = null): LengthAwarePaginator
{
@ -123,11 +126,22 @@ public function pay(Payroll $payroll): Payroll
]);
}
$payroll->update([
'status' => PayrollStatus::PAID,
'paid_by_id' => auth()->id(),
'paid_at' => now(),
]);
$payroll = DB::transaction(function () use ($payroll) {
$cashTransaction = $this->debitCash(
amount: $payroll->total_amount,
description: 'Pembayaran gaji karyawan',
type: CashTransactionType::SALARY,
);
$payroll->update([
'status' => PayrollStatus::PAID,
'cash_transaction_id' => $cashTransaction->id,
'paid_by_id' => auth()->id(),
'paid_at' => now(),
]);
return $payroll;
});
$employeeUser = $payroll->employee->user ?? null;

View File

@ -0,0 +1,19 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
DB::statement("ALTER TABLE cash_transactions MODIFY COLUMN type ENUM('deposit', 'expense', 'withdrawal', 'employee_advance', 'salary') NOT NULL DEFAULT 'deposit'");
}
public function down(): void
{
DB::statement("ALTER TABLE cash_transactions MODIFY COLUMN type ENUM('deposit', 'expense', 'withdrawal', 'employee_advance') NOT NULL DEFAULT 'deposit'");
}
};

View File

@ -32,6 +32,7 @@ function getTypeLabel(type: string): string {
withdrawal: 'Withdrawal',
expense: 'Pengeluaran',
employee_advance: 'Kasbon',
salary : 'Gaji'
};
return labels[type] ?? type;