fix: correct total calculation by adjusting discount and negotiation price handling in transaction create and edit components

This commit is contained in:
Yoga Pangestu 2026-08-09 12:31:01 +07:00
parent eba21d3d3a
commit a1ba9564c7
3 changed files with 7 additions and 7 deletions

View File

@ -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;

View File

@ -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"
/>
<FieldDescription>
Jika diisi, harga nego menjadi total akhir.
Jumlah potongan harga yang dinego customer.
</FieldDescription>
<InputError
message={errors.nego_price}

View File

@ -195,7 +195,7 @@ export default function TransactionEdit({
0,
);
const total = subtotal - discount + (negoPrice ?? 0);
const total = subtotal - discount - (negoPrice ?? 0);
const updateQuantity = useCallback((variantId: number, value: number) => {
setQuantities((prev) => ({
@ -793,7 +793,7 @@ export default function TransactionEdit({
placeholder="0"
/>
<FieldDescription>
Jika diisi, harga nego menjadi total akhir.
Jumlah potongan harga yang dinego customer.
</FieldDescription>
<InputError
message={errors.nego_price}