feat: update CashTransactionType enum and improve transaction labels; refactor EmployeeAdvanceService and PayrollPeriodService for consistency
This commit is contained in:
parent
6ebcbc24c0
commit
42e04673c6
@ -10,16 +10,16 @@ enum CashTransactionType: string
|
||||
|
||||
case DEPOSIT = 'deposit';
|
||||
case EXPENSE = 'expense';
|
||||
case TRANSFER = 'transfer';
|
||||
case WITHDRAWAL = 'withdrawal';
|
||||
case EMPLOYEE_ADVANCE = 'employee_advance';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::DEPOSIT => 'Setoran',
|
||||
self::DEPOSIT => 'Deposit',
|
||||
self::EXPENSE => 'Pengeluaran',
|
||||
self::TRANSFER => 'Transfer',
|
||||
self::WITHDRAWAL => 'Penarikan',
|
||||
self::WITHDRAWAL => 'Withdrawal',
|
||||
self::EMPLOYEE_ADVANCE => 'Kasbon',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,14 +26,14 @@ protected function casts(): array
|
||||
protected function formattedAmount(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => 'Rp ' . number_format($this->amount, 0, ',', '.'),
|
||||
get: fn () => 'Rp '.number_format($this->amount, 0, ',', '.'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function formattedPaidAt(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => $this->paid_at?->translatedFormat('l, d F Y'),
|
||||
get: fn () => $this->paid_at?->translatedFormat('l, d F Y'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -34,14 +34,14 @@ protected function casts(): array
|
||||
protected function formattedName(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => ucfirst($this->name),
|
||||
get: fn () => ucfirst($this->name),
|
||||
);
|
||||
}
|
||||
|
||||
protected function formattedStock(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn() => number_format($this->stock, 0, ',', '.'),
|
||||
get: fn () => number_format($this->stock, 0, ',', '.'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Admin\Finance;
|
||||
|
||||
use App\Enums\CashTransactionType;
|
||||
use App\Enums\EmployeeAdvanceStatus;
|
||||
use App\Models\EmployeeAdvance;
|
||||
use App\Models\EmployeeAdvancePayment;
|
||||
@ -97,8 +98,9 @@ public function delete(EmployeeAdvance $employeeAdvance): bool
|
||||
public function approve(EmployeeAdvance $employeeAdvance): EmployeeAdvance
|
||||
{
|
||||
$cashTransaction = $this->debitCash(
|
||||
amount: $employeeAdvance->amount,
|
||||
description: 'Kasbon: '.$employeeAdvance->description,
|
||||
$employeeAdvance->amount,
|
||||
'Kasbon: '.$employeeAdvance->description,
|
||||
CashTransactionType::EMPLOYEE_ADVANCE
|
||||
);
|
||||
|
||||
$employeeAdvance->update([
|
||||
@ -131,8 +133,9 @@ public function pay(EmployeeAdvance $employeeAdvance, int $amount): EmployeeAdva
|
||||
|
||||
$employeeAdvance = DB::transaction(function () use ($employeeAdvance, $amount) {
|
||||
$cashTransaction = $this->creditCash(
|
||||
amount: $amount,
|
||||
description: 'Pembayaran kasbon: '.$employeeAdvance->description,
|
||||
$amount,
|
||||
'Pembayaran kasbon: '.$employeeAdvance->description,
|
||||
CashTransactionType::EMPLOYEE_ADVANCE
|
||||
);
|
||||
|
||||
EmployeeAdvancePayment::create([
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
use App\Enums\PayrollStatus;
|
||||
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\Collection;
|
||||
@ -15,8 +14,6 @@
|
||||
|
||||
class PayrollPeriodService
|
||||
{
|
||||
use HandlesCashTransactions;
|
||||
|
||||
private function canViewAll(): bool
|
||||
{
|
||||
return auth()->user()->hasAnyRole(['developer', 'owner', 'direktur', 'admin-toko']);
|
||||
|
||||
@ -30,14 +30,14 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
->with([
|
||||
'createdBy:id',
|
||||
'createdBy.userProfile:id,user_id,full_name',
|
||||
'restockItems' => fn($q) => $q
|
||||
'restockItems' => fn ($q) => $q
|
||||
->select(['id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal'])
|
||||
->orderByRaw('(SELECT name FROM product_variants WHERE product_variants.id = restock_items.product_variant_id)'),
|
||||
'restockItems.productVariant:id,product_id,name,stock,reject_stock,retail_stock',
|
||||
'restockItems.productVariant.product:id,name',
|
||||
])
|
||||
->when($search, function ($q) use ($search) {
|
||||
$q->whereHas('restockItems.productVariant.product', fn($sq) => $sq->where('name', 'like', "%{$search}%"))
|
||||
$q->whereHas('restockItems.productVariant.product', fn ($sq) => $sq->where('name', 'like', "%{$search}%"))
|
||||
->orWhere('notes', 'like', "%{$search}%");
|
||||
})
|
||||
->orderBy($sort, $direction)
|
||||
@ -79,11 +79,11 @@ public function getForCreate(): array
|
||||
: null;
|
||||
|
||||
$capitalPrice = $variant->productPrices
|
||||
->first(fn($price) => $price->type === PriceType::CAPITAL);
|
||||
->first(fn ($price) => $price->type === PriceType::CAPITAL);
|
||||
$variant->capital_price = $capitalPrice?->price ?? 0;
|
||||
|
||||
$rejectPrice = $variant->productPrices
|
||||
->first(fn($price) => $price->type === PriceType::REJECT);
|
||||
->first(fn ($price) => $price->type === PriceType::REJECT);
|
||||
$variant->reject_price = $rejectPrice?->price ?? 0;
|
||||
});
|
||||
}),
|
||||
@ -93,7 +93,7 @@ public function getForCreate(): array
|
||||
public function getForEdit(Restock $restock): array
|
||||
{
|
||||
$restock->load([
|
||||
'restockItems' => fn($q) => $q
|
||||
'restockItems' => fn ($q) => $q
|
||||
->orderByRaw('(SELECT name FROM product_variants WHERE product_variants.id = restock_items.product_variant_id)'),
|
||||
'restockItems.productVariant.product',
|
||||
]);
|
||||
@ -108,7 +108,7 @@ public function getForEdit(Restock $restock): array
|
||||
'photo_url' => $media
|
||||
? $this->s3Service->getTemporaryUrl($media->file_name)
|
||||
: null,
|
||||
'items' => $restock->restockItems->map(fn(RestockItem $item) => [
|
||||
'items' => $restock->restockItems->map(fn (RestockItem $item) => [
|
||||
'id' => $item->id,
|
||||
'product_variant_id' => $item->product_variant_id,
|
||||
'quantity' => $item->quantity,
|
||||
@ -145,7 +145,7 @@ public function create(array $data): Restock
|
||||
NotificationService::notify(
|
||||
roles: ['Owner', 'Developer', 'Admin Toko'],
|
||||
title: 'Restock Baru',
|
||||
body: 'Restock ' . ($stockType === ProductStockQuality::GOOD->value ? 'produk' : 'reject') . ' sebesar Rp ' . number_format($subtotal, 0, ',', '.') . ' berhasil dicatat oleh ' . auth()->user()->full_name . '.',
|
||||
body: 'Restock '.($stockType === ProductStockQuality::GOOD->value ? 'produk' : 'reject').' sebesar Rp '.number_format($subtotal, 0, ',', '.').' berhasil dicatat oleh '.auth()->user()->full_name.'.',
|
||||
url: route('admin.manage.restocks.index'),
|
||||
);
|
||||
|
||||
@ -219,7 +219,7 @@ private function buildItemRows(array $items, string $stockType, $now, int &$subt
|
||||
->get()
|
||||
->mapWithKeys(function (ProductVariant $variant) use ($priceType) {
|
||||
$price = $variant->productPrices
|
||||
->first(fn($p) => $p->type === $priceType);
|
||||
->first(fn ($p) => $p->type === $priceType);
|
||||
|
||||
return [$variant->id => $price?->price ?? 0];
|
||||
});
|
||||
|
||||
@ -53,18 +53,18 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
'orderItems.productVariant.product:id,name',
|
||||
])
|
||||
->when($search, function ($q) use ($search) {
|
||||
$q->whereHas('orderItems.productVariant.product', fn($sq) => $sq->where('name', 'like', "%{$search}%"))
|
||||
$q->whereHas('orderItems.productVariant.product', fn ($sq) => $sq->where('name', 'like', "%{$search}%"))
|
||||
->orWhere('order_number', 'like', "%{$search}%")
|
||||
->orWhere('notes', 'like', "%{$search}%");
|
||||
})
|
||||
->when($filters['status'] ?? null, fn($q, $status) => $q->where('status', $status))
|
||||
->when($filters['channel'] ?? null, fn($q, $channel) => $q->where('channel', $channel))
|
||||
->when($filters['payment_type'] ?? null, fn($q, $paymentType) => $q->where('payment_type', $paymentType))
|
||||
->when($filters['customer_id'] ?? null, fn($q, $customerId) => $q->where('customer_id', $customerId))
|
||||
->when($filters['marketing_id'] ?? null, fn($q, $marketingId) => $q->where('marketing_id', $marketingId))
|
||||
->when($filters['created_by_id'] ?? null, fn($q, $createdById) => $q->where('created_by_id', $createdById))
|
||||
->when($filters['date_from'] ?? null, fn($q, $dateFrom) => $q->whereDate('created_at', '>=', $dateFrom))
|
||||
->when($filters['date_to'] ?? null, fn($q, $dateTo) => $q->whereDate('created_at', '<=', $dateTo))
|
||||
->when($filters['status'] ?? null, fn ($q, $status) => $q->where('status', $status))
|
||||
->when($filters['channel'] ?? null, fn ($q, $channel) => $q->where('channel', $channel))
|
||||
->when($filters['payment_type'] ?? null, fn ($q, $paymentType) => $q->where('payment_type', $paymentType))
|
||||
->when($filters['customer_id'] ?? null, fn ($q, $customerId) => $q->where('customer_id', $customerId))
|
||||
->when($filters['marketing_id'] ?? null, fn ($q, $marketingId) => $q->where('marketing_id', $marketingId))
|
||||
->when($filters['created_by_id'] ?? null, fn ($q, $createdById) => $q->where('created_by_id', $createdById))
|
||||
->when($filters['date_from'] ?? null, fn ($q, $dateFrom) => $q->whereDate('created_at', '>=', $dateFrom))
|
||||
->when($filters['date_to'] ?? null, fn ($q, $dateTo) => $q->whereDate('created_at', '<=', $dateTo))
|
||||
->orderBy($sort, $direction)
|
||||
->paginate($perPage);
|
||||
|
||||
@ -99,14 +99,14 @@ public function getSummary(array $filters = []): array
|
||||
->selectRaw('COALESCE(SUM(subtotal) - SUM(COALESCE(nego_price, subtotal)), 0) as total_discount')
|
||||
->selectRaw('COALESCE(SUM(total_amount), 0) as total_amount')
|
||||
->selectRaw('COALESCE(SUM(cogs), 0) as total_cogs')
|
||||
->when($filters['status'] ?? null, fn($q, $status) => $q->where('status', $status))
|
||||
->when($filters['channel'] ?? null, fn($q, $channel) => $q->where('channel', $channel))
|
||||
->when($filters['payment_type'] ?? null, fn($q, $paymentType) => $q->where('payment_type', $paymentType))
|
||||
->when($filters['customer_id'] ?? null, fn($q, $customerId) => $q->where('customer_id', $customerId))
|
||||
->when($filters['marketing_id'] ?? null, fn($q, $marketingId) => $q->where('marketing_id', $marketingId))
|
||||
->when($filters['created_by_id'] ?? null, fn($q, $createdById) => $q->where('created_by_id', $createdById))
|
||||
->when($filters['date_from'] ?? null, fn($q, $dateFrom) => $q->whereDate('created_at', '>=', $dateFrom))
|
||||
->when($filters['date_to'] ?? null, fn($q, $dateTo) => $q->whereDate('created_at', '<=', $dateTo))
|
||||
->when($filters['status'] ?? null, fn ($q, $status) => $q->where('status', $status))
|
||||
->when($filters['channel'] ?? null, fn ($q, $channel) => $q->where('channel', $channel))
|
||||
->when($filters['payment_type'] ?? null, fn ($q, $paymentType) => $q->where('payment_type', $paymentType))
|
||||
->when($filters['customer_id'] ?? null, fn ($q, $customerId) => $q->where('customer_id', $customerId))
|
||||
->when($filters['marketing_id'] ?? null, fn ($q, $marketingId) => $q->where('marketing_id', $marketingId))
|
||||
->when($filters['created_by_id'] ?? null, fn ($q, $createdById) => $q->where('created_by_id', $createdById))
|
||||
->when($filters['date_from'] ?? null, fn ($q, $dateFrom) => $q->whereDate('created_at', '>=', $dateFrom))
|
||||
->when($filters['date_to'] ?? null, fn ($q, $dateTo) => $q->whereDate('created_at', '<=', $dateTo))
|
||||
->first();
|
||||
|
||||
return [
|
||||
@ -134,9 +134,9 @@ public function getFilterOptions(): array
|
||||
->with('userProfile:id,user_id,full_name')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->filter(fn(User $user) => $user->userProfile?->full_name)
|
||||
->filter(fn (User $user) => $user->userProfile?->full_name)
|
||||
->values()
|
||||
->map(fn(User $user) => [
|
||||
->map(fn (User $user) => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->userProfile->full_name,
|
||||
]),
|
||||
@ -162,7 +162,7 @@ public function getForCreate(): array
|
||||
? $this->s3Service->getTemporaryUrl($media->file_name)
|
||||
: null;
|
||||
|
||||
$prices = $variant->productPrices->mapWithKeys(fn($p) => [$p->type->value => $p->price]);
|
||||
$prices = $variant->productPrices->mapWithKeys(fn ($p) => [$p->type->value => $p->price]);
|
||||
$variant->prices = $prices;
|
||||
});
|
||||
}),
|
||||
@ -176,11 +176,11 @@ public function getForCreate(): array
|
||||
->with('userProfile:id,user_id,full_name')
|
||||
->orderBy('id')
|
||||
->get()
|
||||
->filter(fn(User $user) => $user->userProfile?->full_name)
|
||||
->filter(fn (User $user) => $user->userProfile?->full_name)
|
||||
->values(),
|
||||
'channelOptions' => OrderChannel::toSelect(),
|
||||
'paymentTypeOptions' => PaymentType::toSelect(),
|
||||
'priceTypeOptions' => PriceType::toSelect()->filter(fn($p) => $p['value'] !== PriceType::CAPITAL->value)->values(),
|
||||
'priceTypeOptions' => PriceType::toSelect()->filter(fn ($p) => $p['value'] !== PriceType::CAPITAL->value)->values(),
|
||||
];
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ public function getForEdit(Order $order): array
|
||||
'photo_url' => $media
|
||||
? $this->s3Service->getTemporaryUrl($media->file_name)
|
||||
: null,
|
||||
'items' => $order->orderItems->map(fn(OrderItem $item) => [
|
||||
'items' => $order->orderItems->map(fn (OrderItem $item) => [
|
||||
'id' => $item->id,
|
||||
'product_variant_id' => $item->product_variant_id,
|
||||
'quantity' => $item->quantity,
|
||||
@ -270,7 +270,7 @@ public function create(array $data): Order
|
||||
NotificationService::notify(
|
||||
roles: ['Owner', 'Developer', 'Admin Toko'],
|
||||
title: 'Transaksi Baru',
|
||||
body: 'Transaksi ' . $order->order_number . ' sebesar Rp ' . number_format($totalAmount, 0, ',', '.') . ' berhasil dicatat oleh ' . auth()->user()->full_name . '.',
|
||||
body: 'Transaksi '.$order->order_number.' sebesar Rp '.number_format($totalAmount, 0, ',', '.').' berhasil dicatat oleh '.auth()->user()->full_name.'.',
|
||||
url: route('admin.manage.transactions.index'),
|
||||
);
|
||||
|
||||
@ -379,14 +379,14 @@ private function buildItemRows(array $items, string $stockType, string $priceTyp
|
||||
|
||||
$prices = $variants->mapWithKeys(function (ProductVariant $variant) use ($resolvedPriceType) {
|
||||
$price = $variant->productPrices
|
||||
->first(fn($p) => $p->type === $resolvedPriceType);
|
||||
->first(fn ($p) => $p->type === $resolvedPriceType);
|
||||
|
||||
return [$variant->id => $price?->price ?? 0];
|
||||
});
|
||||
|
||||
$capitalPrices = $variants->mapWithKeys(function (ProductVariant $variant) {
|
||||
$price = $variant->productPrices
|
||||
->first(fn($p) => $p->type === PriceType::CAPITAL);
|
||||
->first(fn ($p) => $p->type === PriceType::CAPITAL);
|
||||
|
||||
return [$variant->id => $price?->price ?? 0];
|
||||
});
|
||||
@ -429,6 +429,6 @@ private function generateOrderNumber(): string
|
||||
$sequence = 1;
|
||||
}
|
||||
|
||||
return $prefix . $date . str_pad($sequence, 4, '0', STR_PAD_LEFT);
|
||||
return $prefix.$date.str_pad($sequence, 4, '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,11 +77,6 @@ export function createTransactionColumns(
|
||||
<span className="font-medium">
|
||||
{getTypeLabel(transaction.type)}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{getReferenceLabel(
|
||||
transaction.reference?.type ?? '',
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user