diff --git a/app/Services/Admin/Manage/TransactionService.php b/app/Services/Admin/Manage/TransactionService.php index 16c357c..074c5fa 100644 --- a/app/Services/Admin/Manage/TransactionService.php +++ b/app/Services/Admin/Manage/TransactionService.php @@ -96,7 +96,7 @@ 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(subtotal) - SUM(COALESCE(nego_price, subtotal)), 0) as total_discount') + ->selectRaw('COALESCE(SUM(discount) + SUM(COALESCE(nego_price, 0)), 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)) @@ -158,7 +158,7 @@ public function store(array $data): Order $discount = (int) ($data['discount'] ?? 0); $negoPrice = ! empty($data['nego_price']) ? (int) $data['nego_price'] : null; - $totalAmount = $subtotal - $discount + ($negoPrice ?? 0); + $totalAmount = $subtotal - $discount - ($negoPrice ?? 0); $order = Order::create([ 'created_by_id' => auth()->id(), @@ -225,7 +225,7 @@ public function update(Order $order, array $data): Order $discount = (int) ($data['discount'] ?? 0); $negoPrice = ! empty($data['nego_price']) ? (int) $data['nego_price'] : null; - $totalAmount = $subtotal - $discount + ($negoPrice ?? 0); + $totalAmount = $subtotal - $discount - ($negoPrice ?? 0); foreach ($itemRows as &$row) { $row['order_id'] = $order->id; diff --git a/resources/js/pages/admin/manage/transaction/create.tsx b/resources/js/pages/admin/manage/transaction/create.tsx index 36fb670..beb4c1c 100644 --- a/resources/js/pages/admin/manage/transaction/create.tsx +++ b/resources/js/pages/admin/manage/transaction/create.tsx @@ -225,7 +225,7 @@ export default function TransactionCreate({ 0, ); - const total = subtotal - discount + (negoPrice ?? 0); + const total = subtotal - discount - (negoPrice ?? 0); const updateQuantity = useCallback((variantId: number, value: number) => { setQuantities((prev) => ({ @@ -814,7 +814,7 @@ export default function TransactionCreate({ placeholder="0" /> - Jika diisi, harga nego menjadi total akhir. + Jumlah potongan harga yang dinego customer. { setQuantities((prev) => ({ @@ -793,7 +793,7 @@ export default function TransactionEdit({ placeholder="0" /> - Jika diisi, harga nego menjadi total akhir. + Jumlah potongan harga yang dinego customer.