refactor: improve code readability by standardizing spacing and formatting in TransactionService
This commit is contained in:
parent
49841a662c
commit
7976a457f5
@ -53,20 +53,20 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
'orderItems.productVariant:id,product_id,name,stock,reject_stock,retail_stock',
|
||||
'orderItems.productVariant.product:id,name',
|
||||
])
|
||||
->when($user && $this->isMarketingUser($user), fn ($q) => $q->where('marketing_id', $user->id))
|
||||
->when($user && $this->isMarketingUser($user), fn($q) => $q->where('marketing_id', $user->id))
|
||||
->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);
|
||||
|
||||
@ -112,15 +112,15 @@ public function getSummary(array $filters = [], ?User $user = null): array
|
||||
->selectRaw('COALESCE(SUM(discount), 0) as total_discount')
|
||||
->selectRaw('COALESCE(SUM(nego_price), 0) as total_deduction')
|
||||
->selectRaw('COALESCE(SUM(cogs), 0) as total_cogs')
|
||||
->when($user && $this->isMarketingUser($user), fn ($q) => $q->where('marketing_id', $user->id))
|
||||
->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($user && $this->isMarketingUser($user), fn($q) => $q->where('marketing_id', $user->id))
|
||||
->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 [
|
||||
@ -148,9 +148,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,
|
||||
]),
|
||||
@ -213,7 +213,7 @@ public function store(array $data): Order
|
||||
NotificationService::notify(
|
||||
roles: [Role::OWNER, Role::DEVELOPER, Role::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'),
|
||||
);
|
||||
|
||||
@ -324,20 +324,20 @@ private function buildItemRows(array $items, string $stockType, string $priceTyp
|
||||
->with(['productPrices:id,variant_id,type,price', 'product:id,name'])
|
||||
->get();
|
||||
|
||||
$variantLabels = $variants->mapWithKeys(fn (ProductVariant $v) => [
|
||||
$v->id => $v->product->name.' - '.$v->name,
|
||||
$variantLabels = $variants->mapWithKeys(fn(ProductVariant $v) => [
|
||||
$v->id => $v->product->name . ' - ' . $v->name,
|
||||
]);
|
||||
|
||||
$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];
|
||||
});
|
||||
@ -349,7 +349,7 @@ private function buildItemRows(array $items, string $stockType, string $priceTyp
|
||||
|
||||
if ($unitPrice <= 0) {
|
||||
throw ValidationException::withMessages([
|
||||
'items' => 'Harga untuk "'.$label.'" belum diatur.',
|
||||
'items' => 'Harga untuk "' . $label . '" belum diatur.',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ private function buildItemRows(array $items, string $stockType, string $priceTyp
|
||||
|
||||
if ($capitalPrice <= 0) {
|
||||
throw ValidationException::withMessages([
|
||||
'items' => 'Harga modal untuk "'.$label.'" belum diatur.',
|
||||
'items' => 'Harga modal untuk "' . $label . '" belum diatur.',
|
||||
]);
|
||||
}
|
||||
|
||||
@ -384,7 +384,8 @@ private function generateOrderNumber(): string
|
||||
{
|
||||
$prefix = 'TRX';
|
||||
$date = now()->format('ymd');
|
||||
$lastOrder = Order::where('order_number', 'like', "{$prefix}{$date}%")
|
||||
$lastOrder = Order::withTrashed()
|
||||
->where('order_number', 'like', "{$prefix}{$date}%")
|
||||
->orderByDesc('order_number')
|
||||
->first();
|
||||
|
||||
@ -395,7 +396,7 @@ 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);
|
||||
}
|
||||
|
||||
private function isMarketingUser(User $user): bool
|
||||
|
||||
Loading…
Reference in New Issue
Block a user