Skip to content

Commit

Permalink
Fixed minus order qty issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Suvink committed Apr 3, 2021
1 parent 35f1f20 commit b5aad0d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
15 changes: 13 additions & 2 deletions controllers/customer/OnlineOrderSummeryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class OnlineOrderSummeryController extends Controller
private $orderTotal;
private $deliveryFee;
private $itemCounter;
private $vat;

function __construct()
{
Expand Down Expand Up @@ -53,11 +54,21 @@ public function getDeliveryFee()
}
}

public function getTotalOrderFee()
public function getVat()
{
if ($this->deliveryFee && $this->orderTotal) {
//cant keep the order total in double because we are double checking the user's order against DB for any hacks
echo number_format((float)($this->deliveryFee + $this->orderTotal), 2, '.', '');
$vat_amount = number_format((number_format((float)($this->deliveryFee + $this->orderTotal), 2, '.', '') * 0.15), 2, '.', '');
$this->vat = $vat_amount;
return $vat_amount;
}
}

public function getTotalOrderFee()
{
if ($this->deliveryFee && $this->orderTotal && $this->vat) {
//cant keep the order total in double because we are double checking the user's order against DB for any hacks
echo number_format((float)($this->deliveryFee + $this->orderTotal + $this->vat), 2, '.', '');
}
}

Expand Down
8 changes: 7 additions & 1 deletion views/customer/Dinein.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function addToCart(itemId){
</div>
<div class="menu-selected-row-description has-text-left">
<h4 class="mb-0 mt-0">`+document.getElementById(itemName).innerHTML+`</h4>
<input placeholder="qty" value="1" id="item-qty-`+itemId+`" onchange="updateCartQty(`+itemId+`);">
<input type="number" placeholder="qty" min='1' value="1" id="item-qty-`+itemId+`" onchange="updateCartQty(`+itemId+`);">
</div>
<div class="menu-selected-row-price">
<h4 class="mb-0 mt-0" id="item-price-`+itemId+`">`+document.getElementById(ItemPrice).innerHTML+`</h4>
Expand All @@ -198,11 +198,17 @@ function addToOrder(itemId){
}

function updateCartQty(itemId){

let qtyDiv = 'item-qty-'+itemId;
let itemPriceDiv = 'price-'+itemId;
let itemPriceDivCart = 'item-price-'+itemId;
let increasedQty = order[itemId] - document.getElementById(qtyDiv).value;

if(document.getElementById(qtyDiv).value < 0){
artemisAlert.alert('warning', 'Item number has to be positive number');
return;
}

//TODO
//convert everything to positive
let changedAmount = parseInt(document.getElementById(itemPriceDiv).innerHTML.replace(/\D/g,'')) * Math.abs(increasedQty);
Expand Down
1 change: 0 additions & 1 deletion views/customer/DineinLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<script src="../../plugins/ArtemisAlert/ArtemisAlert.js"></script>
<script>



window.onload = function(){
if(!localStorage.getItem("table_number")){
Expand Down
7 changes: 6 additions & 1 deletion views/customer/OnlineOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function addToCart(itemId){
</div>
<div class="menu-selected-row-description has-text-left">
<h4 class="mb-0 mt-0">`+document.getElementById(itemName).innerHTML+`</h4>
<input placeholder="qty" value="1" id="item-qty-`+itemId+`" onchange="updateCartQty(`+itemId+`);">
<input type="number" min="1" placeholder="qty" value="1" id="item-qty-`+itemId+`" onchange="updateCartQty(`+itemId+`);">
</div>
<div class="menu-selected-row-price">
<h4 class="mb-0 mt-0" id="item-price-`+itemId+`">`+document.getElementById(ItemPrice).innerHTML+`</h4>
Expand Down Expand Up @@ -198,6 +198,11 @@ function updateCartQty(itemId){
let itemPriceDivCart = 'item-price-'+itemId;
let increasedQty = order[itemId] - document.getElementById(qtyDiv).value;

if(document.getElementById(qtyDiv).value < 0){
artemisAlert.alert('warning', 'Item number has to be positive number');
return;
}

//TODO
//convert everything to positive
let changedAmount = parseInt(document.getElementById(itemPriceDiv).innerHTML.replace(/\D/g,'')) * Math.abs(increasedQty);
Expand Down
16 changes: 14 additions & 2 deletions views/customer/OnlineOrderSummery.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,28 @@
</div>
<div class="total-box d-flex nobottom">
<div class="title-col">
<h3 class="mt-0 mb-1">Delivery Fee:</h3>
<h3 class="mt-0 mb-0">Delivery Fee:</h3>
</div>
<div class="price-col mr-1">
<h3 class="mt-0 mb-1 has-text-right">
<h3 class="mt-0 mb-0 has-text-right">
<?php
$OnlineOrderSummeryController->getDeliveryFee();
?>
</h3>
</div>
</div>
<div class="total-box d-flex nobottom">
<div class="title-col">
<h3 class="mt-0 mb-1">VAT(15%):</h3>
</div>
<div class="price-col mr-1">
<h3 class="mt-0 mb-1 has-text-right">
<?php
echo $OnlineOrderSummeryController->getVat();
?>
</h3>
</div>
</div>
<div class="total-box d-flex">
<div class="title-col">
<h3 class="mt-0 mb-1">Total Amount:</h3>
Expand Down

0 comments on commit b5aad0d

Please sign in to comment.