Skip to content

Commit

Permalink
Merge pull request #65 from TEAM-7-SAD/SPD-151-SPD-153-SPD-154
Browse files Browse the repository at this point in the history
 Add the delete button in account page, fix the bugs in add and edit …
  • Loading branch information
F-Seannnnnn authored Jul 19, 2024
2 parents 79f12ff + 6adc6c9 commit 667cad6
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 153 deletions.
8 changes: 5 additions & 3 deletions src/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
</svg>
<span class="font-13">Add Account</span>
</button>
<!-- <div class="mx-2"></div>
<div class="mx-2"></div>
<button class="btn btn-danger fw-semibold delete-account" data-account-id=">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5m-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5M4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06m6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528M8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5"/>
</svg>
<span>Delete</span>
</button> -->
</button>
</div>
</div>
</div>
Expand All @@ -99,6 +99,7 @@
<table id="example" class="table table-hover table-striped table-borderless mt-4">
<thead>
<tr>
<th class="text-medium-brown fw-semibold font-15"></th>
<th class="text-medium-brown fw-semibold font-15">Last Name</th>
<th class="text-medium-brown fw-semibold font-15">First Name</th>
<th class="text-medium-brown fw-semibold font-15">Middle Name</th>
Expand All @@ -120,7 +121,8 @@
// </tr>
// ';
echo '
<tr>
<tr data-id="'.$row['id'].'" class="selectable">
<td><input type="checkbox" class="account-checkbox" data-account-id="'.$row['id'].'"></td>
<td class="text-carbon-grey fw-medium font-14">'.$row['last_name'].'</td>
<td class="text-carbon-grey fw-medium font-14">'.$row["first_name"].'</td>
<td class="text-carbon-grey fw-medium font-14">'.$row['middle_name'].'</td>
Expand Down
4 changes: 3 additions & 1 deletion src/add_to_order_cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$flavorOrSize = $_POST['flavor_or_size'];
$quantity = $_POST['quantity'];
$price = $_POST['price'];
$discount = $_POST['discount']; // Add discount field

// Exclude default and none variations
$servingOrType = ($servingOrType === 'Default' || $servingOrType === 'None') ? '' : $servingOrType;
Expand All @@ -22,7 +23,8 @@
'serving_or_type' => $servingOrType,
'flavor_or_size' => $flavorOrSize,
'quantity' => $quantity,
'price' => $price
'price' => $price,
'discount' => $discount // Include discount in the order item
];

if (!isset($_SESSION['order_cart'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/billing-section.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
<td>Subtotal:</td>
<td class="text-carbon-grey fw-bold text-end pe-2" id="orderSubtotalReview"></td>
</tr>
<!--Discount-->
<!--Discount
<tr>
<td>Discount (%):</td>
<td><input class="form-control text-carbon-grey shadow-sm" type="number" id="discountInput" min="0" max="100" step="0.01" placeholder="Enter discount" oninput="calculateGrandTotal()"></td>
</tr>
</tr>-->
<!--Grand Total-->
<tr class="fw-bolder h5 text-capitalize">
<td class="text-carbon-grey">Grand Total:</td>
Expand Down
31 changes: 25 additions & 6 deletions src/get-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@
</button>
</div>
</div>
<div class="mb-1">
<label for="discountSelect" class="col-form-label fw-medium text-carbon-grey">Discount:</label>
<div class="input-group mt-2 mb-3">
<select id="discountSelect" class="form-control text-center border border-carbon-grey bg-white text-carbon-grey fw-medium py-3 shadow-sm">
<option value="0">0%</option>
<option value="20">20%</option>
</select>
</div>
</div>
<div class="col-md mb-2">
<div class="form-floating py-3">
<input type="text" readonly class="form-control fw-bold fs-5 text-carbon-grey border border-carbon-grey bg-white shadow-sm" id="priceDisplay" name="price">
Expand Down Expand Up @@ -250,6 +259,7 @@
$('#flavorOrSizeGroup').empty();
$('#priceDisplay').val('');
$('#quantityInput').val(1);
$('#discountSelect').val(0); // Initialize discount select

var defaultServingOrType = 'Default';
var defaultFlavorOrSize = 'Default';
Expand Down Expand Up @@ -366,6 +376,10 @@
}
});

$('#discountSelect').change(function() { // Add event listener for discount selection change
updatePrice();
});

function validateQuantity() {
let input = $('#quantityInput');
let currentValue = parseInt(input.val(), 10);
Expand All @@ -378,22 +392,25 @@ function updatePrice() {
var selectedServingOrType = $('#servingOrTypeGroup .btn.active').text() || $('#defaultServingOrType').val() || $('#noneServingOrType').val();
var selectedFlavorOrSize = $('#flavorOrSizeGroup .btn.active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
var quantity = parseInt($('#quantityInput').val(), 10);
var discount = parseInt($('#discountSelect').val(), 10); // Get the selected discount

var selectedVariation = productData.find(function(variation) {
return variation.servingOrType === selectedServingOrType && variation.flavorOrSize === selectedFlavorOrSize;
});

if (selectedVariation) {
var price = selectedVariation.price * quantity;
$('#priceDisplay').val(price.toFixed(2));
$('#product_price').val(price.toFixed(2));
var discountedPrice = price - (price * discount / 100); // Apply discount
$('#priceDisplay').val(discountedPrice.toFixed(2));
$('#product_price').val(discountedPrice.toFixed(2));
$('#serving_or_type').val(selectedServingOrType);
$('#flavor_or_size').val(selectedFlavorOrSize);
} else {
var defaultPrice = productData[0].price;
var totalPrice = defaultPrice * quantity;
$('#priceDisplay').val(totalPrice.toFixed(2));
$('#product_price').val(totalPrice.toFixed(2));
var discountedTotalPrice = totalPrice - (totalPrice * discount / 100); // Apply discount
$('#priceDisplay').val(discountedTotalPrice.toFixed(2));
$('#product_price').val(discountedTotalPrice.toFixed(2));
}
}

Expand All @@ -405,6 +422,7 @@ function addToCart() {
let flavorOrSize = $('#flavorOrSizeGroup .active').text() || $('#defaultFlavorOrSize').val() || $('#noneFlavorOrSize').val();
let quantity = $('#quantityInput').val();
let price = $('#priceDisplay').val();
let discount = $('#discountSelect').val(); // Get the discount percentage

if (servingOrType === 'Default' || servingOrType === 'None') servingOrType = '';
if (flavorOrSize === 'Default' || flavorOrSize === 'None') flavorOrSize = '';
Expand All @@ -419,7 +437,8 @@ function addToCart() {
serving_or_type: servingOrType,
flavor_or_size: flavorOrSize,
quantity: quantity,
price: price
price: price,
discount: discount // Pass the discount to the backend
},
success: function(response) {
let data = JSON.parse(response);
Expand Down Expand Up @@ -470,8 +489,8 @@ function calculateSubtotal() {
});
}


});
</script>



14 changes: 7 additions & 7 deletions src/javascript/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ $(document).ready(function () {
form.classList.add("was-validated");
});

// Disable delete button by default
// Disable delete button by default
$(".delete-account").prop("disabled", true);

// Add event listener to table rows for row selection
$(".selectable").click(function () {
// Toggle checkbox when clicking anywhere on the row
$(this)
.find(".account-checkbox")
.prop("checked", !$(this).find(".account-checkbox").prop("checked"));
// Add event listener to checkboxes for row selection
$(".account-checkbox").click(function (event) {
// Prevent the click from affecting the row
event.stopPropagation();

// Check if at least one checkbox is checked
var anyChecked = $(".account-checkbox:checked").length > 0;

// Enable or disable the delete button based on checkbox status
$(".delete-account").prop("disabled", !anyChecked);
});
Expand Down
Loading

0 comments on commit 667cad6

Please sign in to comment.