feat: improve code readability by standardizing spacing and formatting in TransactionService
This commit is contained in:
parent
0a6a441ec4
commit
8399de9d2e
@ -53,16 +53,16 @@ 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['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))
|
||||
->orderBy($sort, $direction)
|
||||
->paginate($perPage);
|
||||
|
||||
@ -105,9 +105,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,
|
||||
]),
|
||||
@ -123,6 +123,7 @@ public function getForCreate(): array
|
||||
'productVariants:id,product_id,name,stock,reject_stock',
|
||||
'productVariants.productPrices:id,variant_id,type,price',
|
||||
])
|
||||
->active()
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->each(function (Product $product) {
|
||||
@ -132,7 +133,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;
|
||||
});
|
||||
}),
|
||||
@ -146,11 +147,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(),
|
||||
];
|
||||
}
|
||||
|
||||
@ -180,7 +181,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,
|
||||
@ -240,7 +241,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'),
|
||||
);
|
||||
|
||||
@ -342,14 +343,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];
|
||||
});
|
||||
@ -392,6 +393,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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user