feat: add salary type to cash transaction enum and update related components
This commit is contained in:
parent
c415493ee1
commit
0947cf3737
@ -12,6 +12,7 @@ enum CashTransactionType: string
|
|||||||
case EXPENSE = 'expense';
|
case EXPENSE = 'expense';
|
||||||
case WITHDRAWAL = 'withdrawal';
|
case WITHDRAWAL = 'withdrawal';
|
||||||
case EMPLOYEE_ADVANCE = 'employee_advance';
|
case EMPLOYEE_ADVANCE = 'employee_advance';
|
||||||
|
case SALARY = 'salary';
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
@ -20,6 +21,7 @@ public function label(): string
|
|||||||
self::EXPENSE => 'Pengeluaran',
|
self::EXPENSE => 'Pengeluaran',
|
||||||
self::WITHDRAWAL => 'Withdrawal',
|
self::WITHDRAWAL => 'Withdrawal',
|
||||||
self::EMPLOYEE_ADVANCE => 'Kasbon',
|
self::EMPLOYEE_ADVANCE => 'Kasbon',
|
||||||
|
self::SALARY => 'Gaji',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public function create(): Response
|
|||||||
'employees' => $this->getEmployees(),
|
'employees' => $this->getEmployees(),
|
||||||
'channelOptions' => OrderChannel::toSelect(),
|
'channelOptions' => OrderChannel::toSelect(),
|
||||||
'paymentTypeOptions' => PaymentType::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(),
|
'employees' => $this->getEmployees(),
|
||||||
'channelOptions' => OrderChannel::toSelect(),
|
'channelOptions' => OrderChannel::toSelect(),
|
||||||
'paymentTypeOptions' => PaymentType::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(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,18 +3,21 @@
|
|||||||
namespace App\Services\Admin\Finance\Payroll;
|
namespace App\Services\Admin\Finance\Payroll;
|
||||||
|
|
||||||
use App\Concerns\HasRoleChecks;
|
use App\Concerns\HasRoleChecks;
|
||||||
|
use App\Enums\CashTransactionType;
|
||||||
use App\Enums\PayrollPeriodStatus;
|
use App\Enums\PayrollPeriodStatus;
|
||||||
use App\Enums\PayrollStatus;
|
use App\Enums\PayrollStatus;
|
||||||
use App\Enums\Role;
|
use App\Enums\Role;
|
||||||
use App\Models\Payroll;
|
use App\Models\Payroll;
|
||||||
use App\Models\PayrollPeriod;
|
use App\Models\PayrollPeriod;
|
||||||
|
use App\Services\Concerns\HandlesCashTransactions;
|
||||||
use App\Services\NotificationService;
|
use App\Services\NotificationService;
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class PayrollPeriodService
|
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
|
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([
|
$payroll = DB::transaction(function () use ($payroll) {
|
||||||
'status' => PayrollStatus::PAID,
|
$cashTransaction = $this->debitCash(
|
||||||
'paid_by_id' => auth()->id(),
|
amount: $payroll->total_amount,
|
||||||
'paid_at' => now(),
|
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;
|
$employeeUser = $payroll->employee->user ?? null;
|
||||||
|
|
||||||
|
|||||||
@ -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'");
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -32,6 +32,7 @@ function getTypeLabel(type: string): string {
|
|||||||
withdrawal: 'Withdrawal',
|
withdrawal: 'Withdrawal',
|
||||||
expense: 'Pengeluaran',
|
expense: 'Pengeluaran',
|
||||||
employee_advance: 'Kasbon',
|
employee_advance: 'Kasbon',
|
||||||
|
salary : 'Gaji'
|
||||||
};
|
};
|
||||||
|
|
||||||
return labels[type] ?? type;
|
return labels[type] ?? type;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user