From 1a5ac1dd85ed62383fa47f26b86d21548d896a99 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 6 Aug 2026 14:41:10 +0700 Subject: [PATCH] feat: add date range filters and enhance transaction summary display --- .../Admin/Manage/TransactionController.php | 2 +- .../Admin/Manage/TransactionService.php | 9 +++++-- .../pages/admin/manage/transaction/index.tsx | 24 ++++++++++++++++++- .../manage/transaction/transaction-card.tsx | 8 +++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Admin/Manage/TransactionController.php b/app/Http/Controllers/Admin/Manage/TransactionController.php index 9c2588e..93a3174 100644 --- a/app/Http/Controllers/Admin/Manage/TransactionController.php +++ b/app/Http/Controllers/Admin/Manage/TransactionController.php @@ -19,7 +19,7 @@ public function __construct( public function index(PaginatedRequest $request): Response { - $filters = $request->only(['status', 'channel', 'payment_type', 'customer_id', 'marketing_id', 'created_by_id']); + $filters = $request->only(['status', 'channel', 'payment_type', 'customer_id', 'marketing_id', 'created_by_id', 'date_from', 'date_to']); return Inertia::render('admin/manage/transaction/index', [ 'transactions' => $this->service->paginated( diff --git a/app/Services/Admin/Manage/TransactionService.php b/app/Services/Admin/Manage/TransactionService.php index 737acf4..0f9106c 100644 --- a/app/Services/Admin/Manage/TransactionService.php +++ b/app/Services/Admin/Manage/TransactionService.php @@ -63,6 +63,8 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = ->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); @@ -94,14 +96,17 @@ public function getSummary(array $filters = []): array $query = Order::query() ->selectRaw('COUNT(*) as total_orders') ->selectRaw('COALESCE(SUM(subtotal), 0) as total_subtotal') - ->selectRaw('COALESCE(SUM(discount), 0) as total_discount') + ->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)) ->first(); return [ @@ -109,7 +114,7 @@ public function getSummary(array $filters = []): array 'total_subtotal' => $query->total_subtotal, 'total_discount' => $query->total_discount, 'total_amount' => $query->total_amount, - 'net_total' => $query->total_amount, + 'net_total' => $query->total_amount - $query->total_cogs, ]; } diff --git a/resources/js/pages/admin/manage/transaction/index.tsx b/resources/js/pages/admin/manage/transaction/index.tsx index b463069..1f5fcae 100644 --- a/resources/js/pages/admin/manage/transaction/index.tsx +++ b/resources/js/pages/admin/manage/transaction/index.tsx @@ -1,7 +1,9 @@ import { Head, Link, router } from '@inertiajs/react'; +import { format } from 'date-fns'; import { Plus } from 'lucide-react'; import { useMemo, useState } from 'react'; import { CardTable } from '@/components/card-table'; +import { DatePicker } from '@/components/date-picker'; import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog'; import { FilterPopover } from '@/components/filter-popover'; import { useCardTableExpand } from '@/components/hooks/use-card-table-expand'; @@ -67,6 +69,8 @@ type Props = { customer_id?: string; marketing_id?: string; created_by_id?: string; + date_from?: string; + date_to?: string; }; filterOptions: { statusOptions: StatusOption[]; @@ -154,7 +158,9 @@ export default function TransactionIndex({ Boolean(filters.payment_type) || Boolean(filters.customer_id) || Boolean(filters.marketing_id) || - Boolean(filters.created_by_id) + Boolean(filters.created_by_id) || + Boolean(filters.date_from) || + Boolean(filters.date_to) } onClear={clearFilters} > @@ -320,6 +326,22 @@ export default function TransactionIndex({ +
+ + applyFilter('date_from', date ? format(date, 'yyyy-MM-dd') : '')} + placeholder="Pilih tanggal mulai" + /> +
+
+ + applyFilter('date_to', date ? format(date, 'yyyy-MM-dd') : '')} + placeholder="Pilih tanggal akhir" + /> +
); diff --git a/resources/js/pages/admin/manage/transaction/transaction-card.tsx b/resources/js/pages/admin/manage/transaction/transaction-card.tsx index baa7b3e..47ef428 100644 --- a/resources/js/pages/admin/manage/transaction/transaction-card.tsx +++ b/resources/js/pages/admin/manage/transaction/transaction-card.tsx @@ -152,6 +152,14 @@ export function TransactionCardRow({ {formatCurrency(transaction.discount)} )} + {transaction.nego_price != null && transaction.nego_price > 0 && ( + + + Nego:{' '} + + {formatCurrency(transaction.nego_price)} + + )} Total:{' '}