fix: correct total calculation by adjusting discount and negotiation price handling in transaction create and edit components
This commit is contained in:
parent
eba21d3d3a
commit
a1ba9564c7
@ -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;
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user