jun-branch #38

Merged
MarkHipe merged 2 commits from jun-branch into main 2024-03-20 13:22:48 +08:00
7 changed files with 395 additions and 106 deletions

View File

@ -1130,10 +1130,10 @@ $vendorId = $_SESSION["vendorId"];
promises.push(promise);
}
// 03-14-2024 Jun Jihad modified this block of code to properly upload images with comma in the filename
Promise.all(promises)
.then(filenames => {
const updatedImages = existingImages.concat(filenames.map(filename => `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/product_uploads/${filename}`));
const updatedImages = existingImages.concat(filenames.map(filename => `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/product_uploads/${encodeURIComponent(filename)}`));
if (!Array.isArray(updatedImages)) {
console.error('Updated images is not an array:', updatedImages);
@ -1154,6 +1154,7 @@ $vendorId = $_SESSION["vendorId"];
body: JSON.stringify(payload)
});
})
// 03-14-2024 Jun Jihad modified this block of code to properly upload images with comma in the filename
.then(response => {
if (response.ok) {
console.log('Images uploaded successfully');

View File

@ -4,7 +4,7 @@ include "../functions.php";
$_SESSION["url"] = $_SERVER['REQUEST_URI'];
if ($_SESSION["userId"] <> "") {
$_SESSION["isLoggedIn"] = true;
$customer_data = getCustomerbyLoginId($_SESSION["userId"]);
//$customer_data = getCustomerbyLoginId($_SESSION["userId"]);
} else {
$_SESSION["isLoggedIn"] = false;
header("location: login.php");
@ -14,8 +14,6 @@ if ($_SESSION["user_type"] != "admin") {
header("location: login.php?alert=Only admins allowed here!");
}
$products = productList();
$vendorSearchResult = $_SESSION["vendorSearchResult"];
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
@ -66,8 +64,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
<link id="ekka-css" rel="stylesheet" href="assets/css/ekka.css" />
<!-- FAVICON -->
<!-- <link href="assets/img/favicon.png" rel="shortcut icon" /> -->
<link href="assets/img/favicon/favicon.png" rel="shortcut icon" />
<link href="assets/img/favicon.png" rel="shortcut icon" />
<!-- FONTAWESOME -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
@ -92,22 +89,17 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
<!-- Sidebar toggle button -->
<button id="sidebar-toggler" class="sidebar-toggle"></button>
<!-- search form -->
<!-- 03-07-2024 Stacy & Raymart modified this block of code -->
<div class="search-form d-lg-inline-block">
<form method="POST" action="vendor-card-action.php">
<div class="input-group">
<input type="text" name="search" id="search-input" class="form-control" placeholder="search.." autofocus autocomplete="off" />
<button class="submit" type="submit" id="search-btn" class="btn btn-flat">
<i class="mdi mdi-magnify" style="font-size:20px; color:gray; padding-right:8px;"></i>
</button>
</div>
</form>
<div class="input-group">
<input type="text" name="query" id="search-input" class="form-control" placeholder="search.." autofocus autocomplete="off" />
<button type="button" name="search" id="search-btn" class="btn btn-flat">
<i class="mdi mdi-magnify"></i>
</button>
</div>
<div id="search-results-container">
<ul id="search-results"></ul>
</div>
</div>
<!-- 03-07-2024 Stacy & Raymart modified this block of code -->
<!-- navbar right -->
<div class="navbar-right">
@ -673,49 +665,10 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
$start = ($currentpage - 1) * $vendorsPerPage;
$end = $start + $vendorsPerPage - 1;
$vendorsCopy = $vendors;
// var_dump($vendorsCopy
// );
// 03-07-2024 added searh filter
if (!empty($_GET['search']) ) {
$filteredProducts=[];
foreach ($vendorsCopy as $result) {
$vendorName = strtolower($result['user_login']);
if (
// $result['user_login'] == $_GET['search']
strpos($vendorName,$_GET['search'])!==false
) {
$filteredProducts[] = $result;
// var_dump("herees");
// var_dump($_GET['search']);
} else{
// var_dump("none");
}
}
$vendors = $filteredProducts;
$totalVendors = count($filteredProducts);
$vendorsPerPage = 20;
}
else{
// $vendors=$vendorsCopy;
}
if ($totalVendors == 0) {
echo '<p style="padding-top:30px; padding-left:20px;">No vendor found.</p>';
}
// $vendors = vendorList();
for ($x = $start; $x <= $end && $x < $totalVendors; $x++) {
$vendor = $vendors[$x];
?>
<div class="col-lg-6 col-xl-4 col-xxl-3">
<div class="card card-default mt-24px">
<a href="javascript:0" data-bs-toggle="modal" data-bs-target="#modal-contact-<?php echo $vendor['_id']; ?>" class="view-detail me-auto">
@ -731,7 +684,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
if (isset($vendor['vendor_image']) && !empty($vendor['vendor_image'])) {
echo '<img src="' . $vendor['vendor_image'] . '" class="img-fluid rounded-circle" alt="Avatar Image" style="width: 150px; height: 150px; object-fit: cover; border-radius: 50%;"> ';
} else {
echo '<img src="https://api.obanana.com/images/storage/web_images/1710214273217-no_image.png" class="img-fluid rounded-circle" alt="Placeholder Image">';
echo '<img src="assets/img/vendor/u1.jpg" class="img-fluid rounded-circle" alt="Placeholder Image">';
}
?>
</div>
@ -806,7 +759,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
<div class="vendor-image" style="padding-top:20px; ">
<?php
if (isset($vendor['vendor_image']) && !empty($vendor['vendor_image'])) {
echo '<img src="' . $vendor['vendor_image'] . '" alt="edit" id="imgPrev" class="img-fluid rounded-circle" alt="Avatar Image" style="align-items:left; width:100px; height:100px; object-fit:cover; border-radius:80%;"> ';
echo '<img src="' . $vendor['vendor_image'] . '" alt="edit" id="imgPrev' . $vendor['_id'] . '" class="img-fluid rounded-circle" alt="Avatar Image" style="align-items:left; width:100px; height:100px; object-fit:cover; border-radius:80%;"> ';
} else {
echo '<img src="https://yourteachingmentor.com/wp-content/uploads/2020/12/istockphoto-1223671392-612x612-1.jpg" id="imgPrev" alt="edit" class="img-fluid rounded-circle" alt="Placeholder Image" style="align-items:left; width:80px; height:80px; object-fit:cover; border-radius:50%;">';
}
@ -822,21 +775,22 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
label.innerHTML = '<i class="fa-solid fa-file-arrow-up"></i> Upload file';
}
}
// 03-14-2024 Jun Jihad modified this block of code to show preview of the image to be uploaded
function previewImage(vendorId) {
var fileInput = document.getElementById('fileInput' + vendorId);
var file = fileInput.files[0];
console.log('clicked hereee');
const reader = new FileReader();
// 02-29-2024 Stacy for image preview
function previewImage(vendorId){
var fileInput = document.getElementById('fileInput' + vendorId);
var file = fileInput.files[0];
console.log('clicked hereee')
const reader = new FileReader();
reader.onload = function (e) {
reader.onload = function (e) {
const dataUri = e.target.result;
document.getElementById('imgPrev').src=dataUri
};
document.getElementById('imgPrev' + vendorId).src = dataUri; // Fixed concatenation here
};
reader.readAsDataURL(file);
}
// 03-14-2024 Jun Jihad modified this block of code to show preview of the image to be uploaded
reader.readAsDataURL(file);
}
</script>
</div>
<form>
@ -941,8 +895,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
</div>
</div>
</div>
</div>
</div>
<script>
function deleteVendor(vendorId){
let text = "Please confirm delete action!\nClick OK or Cancel button.";
@ -1376,16 +1329,13 @@ function validateEmail(vendorId) {
<!-- Ec Pagination Start -->
<div class="pagination mt-3">
<?php
if ($totalVendors >= $vendorsPerPage) {
for ($i = 1; $i <= $totalPages; $i++) {
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a>";
}
}
for ($i = 1; $i <= $totalPages; $i++) {
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a>";
}
?>
</div>
<!-- Ec Pagination End -->
</div>
<!-- Contact Modal -->

View File

@ -1552,6 +1552,7 @@ function editProduct(
$color,
$material,
$size,
$priceMatrix,
$token
) {
$curl = curl_init();
@ -1576,6 +1577,9 @@ function editProduct(
'same-day-delivery' => $sdd ,
'free-shipping' => $freeSf
),
'price_matrix' => array(
$priceMatrix
),
'parent_id' => $parentId,
'minimum_order' => $minimumOrder,
// 'variants' => array(

View File

@ -305,7 +305,7 @@ if ($_SESSION["userId"] <> "") {
<td><span><?php echo date("F j, Y", strtotime($order['updatedAt'])); ?></span></td>
<td>
<span class="tbl-btn">
<a class="btn btn-lg btn-primary" onclick="updateCompletedStatus('<?php echo $order['_id']; ?>')">Received</a>
<a class="btn btn-lg btn-primary" onclick="updateCompletedStatus('<?php echo $order['_id']; ?>', '<?php echo htmlspecialchars($order['payment']['reference_number']); ?>')">Received</a>
</span>
</td>
</tr>
@ -360,13 +360,22 @@ if ($_SESSION["userId"] <> "") {
<td><span><?php echo $order['courier_name']; ?></span></td>
<td><span><?php echo date("F j, Y", strtotime($order['updatedAt'])); ?></span></td>
<td>
<?php
<?php
$currentDate = time(); // Current Unix timestamp
if ($order['return_order']['status'] === 'To Approve') {
echo '<span class="tbl-btn">Refund Requested</span>';
} elseif ($order['return_order']['status'] === 'To Ship') {
echo '<span class="tbl-btn">For Refund</span>';
}else {
echo '<a class="btn btn-lg btn-primary" data-bs-toggle="modal" data-bs-target="#modal-refund-' . $order['_id'] . '">Return/Refund</a>';
} else {
$orderDate = strtotime($order['updatedAt']);
$sevenDaysAfterOrder = strtotime('+7 days', $orderDate); // Seven days after the order date
if ($currentDate >= $sevenDaysAfterOrder) {
echo '<span class="tbl-btn" disabled></span>';
} else {
echo '<a class="btn btn-lg btn-primary" data-bs-toggle="modal" data-bs-target="#modal-refund-' . $order['_id'] . '">Return/Refund</a>';
}
}
?>
</td>
@ -580,7 +589,7 @@ if ($_SESSION["userId"] <> "") {
var sessionToken = '<?php echo isset($_SESSION["token"]) ? $_SESSION["token"] : ""; ?>';
var email = '<?php echo isset($_SESSION["email"]) ? $_SESSION["email"] : ""; ?>';
var password = '<?php echo isset($_SESSION["password"]) ? $_SESSION["password"] : ""; ?>';
function login(username, password, callback) {
fetch("https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/login", {
method: "POST",
@ -656,7 +665,7 @@ if ($_SESSION["userId"] <> "") {
localStorage.setItem('activeTab', tabName);
}
function updateCompletedStatus(orderId) {
function updateCompletedStatus(orderId, referenceNumber) {
login(email, password, function(token) {
// const token = '<?php echo $_SESSION["token"] ?>';
fetch(`https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/orders/${orderId}`, {
@ -667,6 +676,10 @@ if ($_SESSION["userId"] <> "") {
},
body: JSON.stringify({
status: 'COMPLETED',
payment: {
status: 'PAID',
reference_number: referenceNumber
}
}),
})
.then(response => response.json())
@ -675,7 +688,7 @@ if ($_SESSION["userId"] <> "") {
if (data && data !== "") {
// Update the status in the table without reloading the page
// document.querySelector(`[data-order-id="${orderId}"] .order-status`).innerText = 'COMPLETED';
// location.reload();
location.reload();
} else {
alert('Failed to update order status');

View File

@ -233,6 +233,34 @@ if ($_SESSION["userId"] <> "") {
</div>
</div>
</div>
<!-- 03-19-24 Jun Jihad Bank Information -->
<div class="col-md-12 col-sm-12" style="display:flex; justify-content: space-between">
<h5>Bank Information </h5>
<button type="button" class="btn btn-primary" id="vendorBankModalBtn" data-bs-toggle="modal" data-bs-target="#vendorBankModal">My Banks</button>
</div>
<div class="row">
<div class="col-md-12 col-sm-12">
<?php foreach ($vendorData['bank_acount_details'] as $bank_acount_details) : ?>
<?php if ($bank_acount_details['bank_payout']) : ?>
<table style="width:100%; border-collapse: collapse;">
<tr>
<td style="border: 1px solid #dddddd; background-color: #f7f7f7; padding: 8px; font-weight: 700;">Bank Name</td>
<td style="border: 1px solid #dddddd; padding: 8px;font-weight: 500;"><?php echo $bank_acount_details["bank_name"] ?></td>
</tr>
<tr>
<td style="border: 1px solid #dddddd; background-color: #f7f7f7; padding: 8px;font-weight: 700;">Account Number</td>
<td style="border: 1px solid #dddddd; padding: 8px;font-weight: 500;"><?php echo $bank_acount_details["bank_account_number"] ?></td>
</tr>
<tr>
<td style="border: 1px solid #dddddd; background-color: #f7f7f7; padding: 8px;font-weight: 700;">Account Name</td>
<td style="border: 1px solid #dddddd; padding: 8px;font-weight: 500;"><?php echo $bank_acount_details["bank_account_name"] ?></td>
</tr>
</table>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
<!-- 03-19-24 Jun Jihad Bank Information -->
</div>
</div>
</div>
@ -350,6 +378,71 @@ if ($_SESSION["userId"] <> "") {
</div>
</div>
</div>
<div class="modal fade" id="vendorBankModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-body" style="overflow-y: auto; max-height: 90vh;">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#secondBankModal">Add New Bank</button>
<!-- Display a list of addresses and let the user choose -->
<form id="BankForm">
<!-- <?php var_dump($vendorData) ?> -->
<?php foreach ($vendorLoginIdjson['results'] as $vendor_index => $vendor) { ?>
<?php foreach ($vendor['bank_acount_details'] as $bank_index => $bank) { ?>
<div class="card mb-3">
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-md-12 mx-auto">
<label class="form-check-label" for="address_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>">
<strong style="font-weight: bold;">Bank Name: </strong><?php echo $bank['bank_name']; ?> <br>
<strong style="font-weight: bold;">Bank Account Number: </strong><?php echo $bank['bank_account_number']; ?> <br>
<strong style="font-weight: bold;">Bank Account Name: </strong><?php echo $bank['bank_account_name']; ?>
<div class="selectWrap" style="display: flex; justify-content: center; align-items: center; width: 50%;">
<input type="radio" name="payout_bank" id="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" value="<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>" onchange="setPayoutBank('<?php echo $vendor['_id']; ?>', <?php echo $bank_index; ?>, true)" <?php echo $bank['bank_payout'] ? 'checked' : ''; ?>>
<label for="payout_bank_<?php echo $vendor_index; ?>_<?php echo $bank_index; ?>">Set as Payout Bank</label>
</div>
</label>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } ?>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="secondBankModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document" style="max-width: 800px;">
<div class="modal-content">
<div class="modal-body" style="overflow-y: auto; max-height: 90vh;">
<form>
<div class="form-group">
<label for="bankName" class="text-dark font-weight-medium pt-3 mb-2">Bank Name</label>
<input type="text" class="form-control" id="bankName">
</div>
<div class="form-group">
<label for="bankAccountNumber" class="text-dark font-weight-medium pt-3 mb-2">Bank Account Number</label>
<input type="text" class="form-control" id="bankAccountNumber">
</div>
<div class="form-group">
<label for="bankAccountName" class="text-dark font-weight-medium pt-3 mb-2">Bank Account Name</label>
<input type="text" class="form-control" id="bankAccountName">
</div>
<button type="button" class="btn btn-primary" id="submitBankBtn">Add Bank</button>
</form>
</div>
</div>
</div>
</div>
<script>
function editUser() {
// var fileInput = document.getElementById('fileInput' + vendorId);
@ -569,6 +662,49 @@ if ($_SESSION["userId"] <> "") {
});
$('#submitBankBtn').on('click', function() {
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid)
.then(response => response.json())
.then(data => {
const existingBanks = data.bank_acount_details || [];
const bankName = $('#bankName').val();
const bankAccountNumber = $('#bankAccountNumber').val();
const bankAccountName = $('#bankAccountName').val();
const newBank = {
bank_name: bankName,
bank_account_number: bankAccountNumber,
bank_account_name: bankAccountName,
};
existingBanks.push(newBank);
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorid, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
bank_acount_details: existingBanks
}),
});
})
.then(response => {
if (response.ok) {
location.reload();
} else {
console.error('Failed to submit data');
alert('Failed to submit data');
}
})
.catch(error => {
console.error('Error:', error);
alert('Error submitting data');
});
});
</script>
<script>
async function updateAddressBilling(vendorid, addressIndex, isBilling) {
@ -697,6 +833,56 @@ if ($_SESSION["userId"] <> "") {
console.error('Error updating address:', error.message);
}
}
async function setPayoutBank(vendorid, bankIndex, isBankPayout) {
try {
const apiUrl = `https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/${vendorid}`;
const response = await fetch(apiUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Failed to fetch vendor data: ${response.status}`);
}
const vendorsData = await response.json();
vendorsData.bank_acount_details.forEach((bank_acount_details, index) => {
if (index === bankIndex) {
if (isBankPayout !== undefined) {
bank_acount_details.bank_payout = isBankPayout;
const radioButtonId = `#payout_bank__${vendorid}_${bankIndex}`;
$(radioButtonId).prop('checked', isBankPayout);
}
} else {
bank_acount_details.bank_payout = false;
}
});
const updateResponse = await fetch(apiUrl, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
bank_acount_details: vendorsData.bank_acount_details
}),
});
if (!updateResponse.ok) {
throw new Error(`Failed to update address: ${updateResponse.status}`);
}
location.reload()
// console.log(`Address updated successfully for customer ${vendorid}`);
} catch (error) {
console.error('Error updating address:', error.message);
}
}
</script>
</section>
<!-- End Vendor setting section -->

View File

@ -40,6 +40,18 @@ $material = $_POST['material'];
//echo '$material: '.$material.'<br>';
$token = $_SESSION["token"];
$quantities = $_POST['quantity'];
$prices = $_POST['price'];
// Constructing the price matrix
$priceMatrix = array();
for ($i = 0; $i < count($quantities); $i++) {
$priceMatrix[] = array(
'quantity' => $quantities[$i],
'price' => $prices[$i]
);
}
$response = editProduct(
$productId,
@ -66,6 +78,7 @@ $response = editProduct(
$color,
$material,
$size,
$priceMatrix,
$token);
$array = json_decode($response,true);
$_SESSION['newProdictId'] = $array['_id'];

View File

@ -118,14 +118,16 @@ $array = json_decode($result, true);
<div class="ec-vendor-block">
<!-- 03-12-2024 Stacy added placeholder for vendor banner -->
<?php
if (!empty($vendorData['vendor_banner'])) { ?>
<div class="ec-vendor-block-bg" style="background-image: url(<?php echo $vendorData['vendor_banner'] ?>) !important;"></div>
<?php } else { ?>
<div class="ec-vendor-block-bg" style="background-color: orange; background-image: url(<?php echo $vendorData['vendor_banner'] ?>) !important;"></div>
if (!empty($vendorData['vendor_banner'])) { ?>
<div class="ec-vendor-block-bg" style="background-image: url(<?php echo $vendorData['vendor_banner'] ?>) !important;"></div>
<?php } else { ?>
<div class="ec-vendor-block-bg" style="background-color: orange; background-image: url(<?php echo $vendorData['vendor_banner'] ?>) !important;"></div>
<?php } ?>
<!-- <div class="ec-vendor-block-bg" style="background-image: url(<?php #echo $vendorData['vendor_banner'] ?>) !important;"></div> -->
<!-- <div class="ec-vendor-block-bg" style="background-image: url(<?php #echo $vendorData['vendor_banner']
?>) !important;"></div> -->
<div class="ec-vendor-block-detail">
<!-- <img class="v-img" src=<?php #echo $vendorData['vendor_image'] ?> alt="vendor image"> -->
<!-- <img class="v-img" src=<?php #echo $vendorData['vendor_image']
?> alt="vendor image"> -->
<!-- 03-12-2024 Stacy added placeholder for vendor profile -->
<?php
if (!empty($vendorData['vendor_image'])) { ?>
@ -134,7 +136,7 @@ $array = json_decode($result, true);
<img class="v-img" src="https://yourteachingmentor.com/wp-content/uploads/2020/12/istockphoto-1223671392-612x612-1.jpg" alt="vendor image">
<?php } ?>
<h5 class="name"><?php echo $vendorData['user_login'] ?></h5>
</div>
</div>
<!-- 2024-02-12 Stacy deleted div with class "ec-vendor-block-items", and inserted vendor-profile-tabs.php -->
<!-- <div class="ec-vendor-block-items">
<ul>
@ -382,26 +384,51 @@ $array = json_decode($result, true);
)</span></label>
<input type="number" class="form-control" id="price2" name="sale_price" value="<?php echo $array['sale_price'] ?>">
</div>
<!-- 03-15-2024 Jun Jihad price_matrix field Product Upload Vendor Page -->
<div class="col-md-12">
<label class="form-label">Price Matrix</label>
<table class="table">
<thead>
<tr>
<th scope="col">Quantity</th>
<th scope="col">Price (PHP)</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="price-matrix-body">
<?php foreach ($array['price_matrix'][0] as $index => $pair) : ?>
<tr data-row-index="<?php echo $index; ?>">
<td><input type="number" class="form-control" name="quantity[]" value="<?php echo $pair['quantity']; ?>"></td>
<td><input type="number" class="form-control" name="price[]" value="<?php echo $pair['price']; ?>"></td>
<td><button type="button" class="btn btn-danger delete-row">Delete</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<button type="button" class="btn btn-secondary" id="add-row">Add Row</button>
</div>
<!-- 03-15-2024 Jun Jihad price_matrix field Product Upload Vendor Page -->
<!-- 02-19-2024 Jun Jihad Promo Field Product Upload Vendor Page -->
<div class="col-md-12" style="margin: 0 0 20px 0;">
<label class="form-label">Promo</label>
<div class="row" justify-content-between>
<div class="col-md-4">
<div class="col-md-4">
<div class="form-check">
<input type="checkbox" id="nextDayDeliveryCheckbox" name="promo[next-day-delivery]" value="Yes" <?php if ($array['promo'][0]['next-day-delivery'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="nextDayDeliveryCheckbox">Next Day Delivery</label>
</div>
</div>
<div class="col-md-4">
<div class="form-check">
<input type="checkbox" id="sameDayDeliveryCheckbox" name="promo[same-day-delivery]" value="Yes" <?php if ($array['promo'][0]['same-day-delivery'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="sameDayDeliveryCheckbox">Same Day Delivery</label>
<input type="checkbox" id="nextDayDeliveryCheckbox" name="promo[next-day-delivery]" value="Yes" <?php if ($array['promo'][0]['next-day-delivery'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="nextDayDeliveryCheckbox">Next Day Delivery</label>
</div>
</div>
<div class="col-md-4">
<div class="form-check">
<input type="checkbox" id="freeShippingCheckbox" name="promo[free-shipping]" value="Yes" <?php if ($array['promo'][0]['free-shipping'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="freeShippingCheckbox">Free Shipping</label>
<input type="checkbox" id="sameDayDeliveryCheckbox" name="promo[same-day-delivery]" value="Yes" <?php if ($array['promo'][0]['same-day-delivery'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="sameDayDeliveryCheckbox">Same Day Delivery</label>
</div>
</div>
<div class="col-md-4">
<div class="form-check">
<input type="checkbox" id="freeShippingCheckbox" name="promo[free-shipping]" value="Yes" <?php if ($array['promo'][0]['free-shipping'] === "Yes") echo "checked"; ?> style="background-color: blue;">
<label class="form-check-label" for="freeShippingCheckbox">Free Shipping</label>
</div>
</div>
</div>
@ -473,7 +500,7 @@ $array = json_decode($result, true);
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
var quill = new Quill('#editor-container', {
theme: 'snow'
theme: 'snow'
});
quill.clipboard.dangerouslyPasteHTML(document.getElementById('hidden-editor').value);
quill.on('text-change', function() {
@ -481,12 +508,107 @@ $array = json_decode($result, true);
});
var newquill = new Quill('#short-editor-container', {
theme: 'snow'
theme: 'snow'
});
newquill.clipboard.dangerouslyPasteHTML(document.getElementById('short-hidden-editor').value);
newquill.on('text-change', function() {
document.getElementById('short-hidden-editor').value = newquill.root.innerHTML;
});
// 03-15-2024 Jun Jihad price_matrix field delete/add row function
document.getElementById("add-row").addEventListener("click", function() {
var newRow = '<tr>' +
'<td><input type="number" class="form-control quantity-input" name="quantity[]"></td>' +
'<td><input type="number" class="form-control" name="price[]"></td>' +
'<td><button type="button" class="btn btn-danger delete-row">Delete</button></td>' +
'</tr>';
document.getElementById("price-matrix-body").insertAdjacentHTML('beforeend', newRow);
var quantityInputs = document.querySelectorAll('.quantity-input');
var lastIndex = quantityInputs.length - 1;
quantityInputs[lastIndex].addEventListener('blur', function(event) {
checkQuantity(event, lastIndex);
});
});
document.getElementById("price-matrix-body").addEventListener("click", function(event) {
if (event.target.classList.contains("delete-row")) {
event.preventDefault();
var rows = document.querySelectorAll("#price-matrix-body tr");
if (rows.length > 1) {
event.target.closest("tr").remove();
} else {
alert("At least one row is required.");
}
}
});
function checkQuantity(event, index) {
var currentInput = event.target;
var previousRow = currentInput.parentNode.parentNode.previousElementSibling;
var nextRow = currentInput.parentNode.parentNode.nextElementSibling;
if (previousRow !== null) {
var previousQuantityInput = previousRow.querySelector('input[name="quantity[]"]');
var currentQuantity = parseInt(currentInput.value);
var previousQuantity = parseInt(previousQuantityInput.value);
if (currentQuantity <= previousQuantity) {
alert("Quantity must be greater than the previous row's quantity.");
currentInput.value = previousQuantity + 1;
}
}
if (nextRow !== null) {
var nextQuantityInput = nextRow.querySelector('input[name="quantity[]"]');
var nextQuantity = parseInt(nextQuantityInput.value);
if (currentQuantity >= nextQuantity) {
alert("Quantity must be less than the next row's quantity.");
currentInput.value = nextQuantity - 1;
}
}
}
function checkExistingQuantity(row) {
var currentInput = row.querySelector('input[name="quantity[]"]');
var allRows = document.querySelectorAll("#price-matrix-body tr");
var currentIndex = Array.from(allRows).indexOf(row);
for (var i = currentIndex - 1; i >= 0; i--) {
var previousRow = allRows[i];
var previousQuantityInput = previousRow.querySelector('input[name="quantity[]"]');
var currentQuantity = parseInt(currentInput.value);
var previousQuantity = parseInt(previousQuantityInput.value);
if (currentQuantity <= previousQuantity) {
alert("Quantity must be greater than the previous row's quantity.");
currentInput.value = previousQuantity + 1;
return;
}
}
var nextRow = allRows[currentIndex + 1];
if (nextRow !== undefined) {
var nextQuantityInput = nextRow.querySelector('input[name="quantity[]"]');
var nextQuantity = parseInt(nextQuantityInput.value);
if (currentQuantity >= nextQuantity) {
alert("Quantity must be less than the next row's quantity.");
currentInput.value = nextQuantity - 1;
return;
}
}
}
document.getElementById("price-matrix-body").addEventListener("blur", function(event) {
if (event.target.tagName === "INPUT" && event.target.name === "quantity[]") {
checkExistingQuantity(event.target.closest("tr"));
}
}, true);
// 03-15-2024 Jun Jihad price_matrix field delete/add row function
</script>
<script>
function onload() {