Skip to content

Commit

Permalink
Refactor: Remove discount calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosa89 committed Apr 29, 2021
1 parent 993a1d6 commit 3774059
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions app/Http/Controllers/VoucherController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ public function store(StoreVoucher $request)
}

$quantity = $start->diffInDays($end);
$discount = ($room->price - $selected['price']) * $quantity;
$taxes = ($selected['price'] * $room->tax) * $quantity;
$subvalue = $selected['price'] * $quantity;

$attach[$room->id] = [
'price' => $selected['price'],
'quantity' => $quantity,
'discount' => $discount,
'discount' => 0,
'subvalue' => $subvalue,
'taxes' => $taxes,
'value' => $subvalue + $taxes,
Expand Down Expand Up @@ -500,7 +499,6 @@ public function addRooms(AddRooms $request, $id)
}

$quantity = $start->diffInDays($end);
$discount = ($room->price - $request->price) * $quantity;
$taxes = ($request->price * $room->tax) * $quantity;
$subvalue = $request->price * $quantity;

Expand All @@ -509,7 +507,7 @@ public function addRooms(AddRooms $request, $id)
[
'price' => $request->price,
'quantity' => $quantity,
'discount' => $discount,
'discount' => 0,
'subvalue' => $subvalue,
'taxes' => $taxes,
'value' => $subvalue + $taxes,
Expand All @@ -519,7 +517,6 @@ public function addRooms(AddRooms $request, $id)
]
);

$voucher->discount += $discount;
$voucher->subvalue += $subvalue;
$voucher->taxes += $taxes;
$voucher->value += $subvalue + $taxes;
Expand Down Expand Up @@ -687,7 +684,6 @@ public function changeRoom(ChangeRoom $request, $id, $roomId)
$voucher->rooms()->detach($current->id);

// Calculating the new values
$discount = ($room->price - $request->price) * $current->pivot->quantity;
$taxes = ($request->price * $room->tax) * $current->pivot->quantity;
$subvalue = $request->price * $current->pivot->quantity;

Expand All @@ -696,7 +692,7 @@ public function changeRoom(ChangeRoom $request, $id, $roomId)
[
'price' => $request->price,
'quantity' => $current->pivot->quantity, // This is same that before
'discount' => $discount,
'discount' => 0,
'subvalue' => $subvalue,
'taxes' => $taxes,
'value' => $subvalue + $taxes,
Expand All @@ -707,7 +703,6 @@ public function changeRoom(ChangeRoom $request, $id, $roomId)
);

// Summing the new values
$voucher->discount += $discount;
$voucher->subvalue += $subvalue;
$voucher->taxes += $taxes;
$voucher->value += $subvalue + $taxes;
Expand Down Expand Up @@ -2740,7 +2735,6 @@ public function process(VouchersProcessing $request)
$quantity = $end->diffInDays($newEnd);

// Adding the new values
$discount = ((float) $room->price - (float) $room->pivot->price) * $quantity;
$taxes = ((float) $room->pivot->price * $room->tax) * $quantity;
$subvalue = (float) $room->pivot->price * $quantity;
$value = $subvalue + $taxes;
Expand All @@ -2749,15 +2743,14 @@ public function process(VouchersProcessing $request)
$room,
[
'quantity' => $room->pivot->quantity + $quantity,
'discount' => $room->pivot->discount + $discount,
'discount' => 0,
'subvalue' => $room->pivot->subvalue + $subvalue,
'taxes' => $room->pivot->taxes + $taxes,
'value' => $room->pivot->value + $value,
'end' => $newEnd->toDateString()
]
);

$voucher->discount += $discount;
$voucher->subvalue += $subvalue;
$voucher->taxes += $taxes;
$voucher->value += $value;
Expand Down

0 comments on commit 3774059

Please sign in to comment.