louie_branch #92
|
@ -17,6 +17,11 @@ if ($_SESSION["user_type"] != "admin") {
|
|||
$products = productList();
|
||||
|
||||
$vendorSearchResult = $_SESSION["vendorSearchResult"];
|
||||
|
||||
$payoutResponse = getAllPayout($_SESSION["token"]);
|
||||
|
||||
$payoutData = json_decode($payoutResponse, true);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
|
@ -103,16 +108,16 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card card-default p-4 ec-card-space">
|
||||
<div class="col-lg-6 col-md-12">
|
||||
<form style="display:flex; margin-bottom:50px;" method="POST" action="vendor-card-action.php">
|
||||
<input type="text" name="search" class="form-control" id="searchProduct" placeholder="search with vendor name..">
|
||||
<button class="submit" type="submit" id="search-btn" class="btn btn-flat">
|
||||
<i class="mdi mdi-magnify" style="font-size:20px; color:gray; margin-left:-40px;"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12">
|
||||
<form style="display:flex; margin-bottom:50px;" method="POST" action="vendor-card-action.php">
|
||||
<input type="text" name="search" class="form-control" id="searchProduct" placeholder="search with vendor name..">
|
||||
<button class="submit" type="submit" id="search-btn" class="btn btn-flat">
|
||||
<i class="mdi mdi-magnify" style="font-size:20px; color:gray; margin-left:-40px;"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="ec-vendor-card mt-m-24px row">
|
||||
|
||||
<?php
|
||||
|
@ -126,16 +131,16 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
$end = $start + $vendorsPerPage - 1;
|
||||
|
||||
$vendorsCopy = $vendors;
|
||||
|
||||
if (!empty($_GET['search']) ) {
|
||||
$filteredProducts=[];
|
||||
|
||||
if (!empty($_GET['search'])) {
|
||||
$filteredProducts = [];
|
||||
foreach ($vendorsCopy as $result) {
|
||||
$vendorName = strtolower($result['user_login']);
|
||||
$vendorName = strtolower($result['user_login']);
|
||||
if (
|
||||
strpos($vendorName,strtolower($_GET['search']))!==false
|
||||
strpos($vendorName, strtolower($_GET['search'])) !== false
|
||||
) {
|
||||
$filteredProducts[] = $result;
|
||||
} else{
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +154,19 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
// $vendors = vendorList();
|
||||
for ($x = $start; $x <= $end && $x < $totalVendors; $x++) {
|
||||
$vendor = $vendors[$x];
|
||||
|
||||
$vendorId = $vendor['_id'];
|
||||
$totalPayoutAmount = 0; // Initialize the total net amount for the current vendor
|
||||
|
||||
// Loop through the payout data and sum up the net amounts
|
||||
foreach ($payoutData as $payout) {
|
||||
if ($payout['vendor_details'][0]['vendor_id'] == $vendorId) {
|
||||
$totalPayoutAmount += $payout['net_amount'];
|
||||
}
|
||||
}
|
||||
|
||||
$totalPayoutAmount = number_format($totalPayoutAmount, 2, '.', ',');
|
||||
|
||||
?>
|
||||
<div class="col-lg-6 col-xl-4 col-xxl-3">
|
||||
<div class="card card-default mt-24px">
|
||||
|
@ -177,7 +195,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
<i class="mdi mdi-cellphone-basic mr-1"></i>
|
||||
<span style="font-size:13px;">
|
||||
<?php
|
||||
echo isset($vendor['phone']) && !empty($vendor['phone']) ? $vendor['phone']: 'No Number yet';
|
||||
echo isset($vendor['phone']) && !empty($vendor['phone']) ? $vendor['phone'] : 'No Number yet';
|
||||
?>
|
||||
</span>
|
||||
</li>
|
||||
|
@ -192,7 +210,7 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
</ul>
|
||||
</a>
|
||||
<div class="row justify-content-center ec-vendor-detail">
|
||||
<div class="col-4">
|
||||
<div class="col-3">
|
||||
<h6 class="text-uppercase">Items</h6>
|
||||
<?php
|
||||
$vendorId = $vendor['_id'];
|
||||
|
@ -202,13 +220,13 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
?>
|
||||
<h5><?php echo count($product); ?></h5>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="col-3">
|
||||
<h6 class="text-uppercase">Sell</h6>
|
||||
<h5>1908</h5>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="col-6">
|
||||
<h6 class="text-uppercase">Payout</h6>
|
||||
<h5>$2691</h5>
|
||||
<h5 style="font-size: 15px;">₱ <?php echo $totalPayoutAmount; ?></h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -231,11 +249,12 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
<!-- 02-28-2024 Stacy modified this block of code -->
|
||||
<div class="modal-body pt-0">
|
||||
<div style="text-align: center; display: column; justify-content: center; align-items: center;" class="col-md-6">
|
||||
<!-- <input type="file" id="fileInput<?php #echo $vendor['_id']; ?>" accept=".png, .jpg, .jpeg" /> -->
|
||||
<!-- <input type="file" id="fileInput<?php #echo $vendor['_id'];
|
||||
?>" accept=".png, .jpg, .jpeg" /> -->
|
||||
<div class="thumb-edit" style="padding-left:120px; margin-bottom:-40px;">
|
||||
<input style="display:none;" type='file' id="fileInput<?php echo $vendor['_id']; ?>" class="ec-image-upload" accept=".png, .jpg, .jpeg" onchange="previewImage('<?php echo $vendor['_id']; ?>')"/>
|
||||
<input style="display:none;" type='file' id="fileInput<?php echo $vendor['_id']; ?>" class="ec-image-upload" accept=".png, .jpg, .jpeg" onchange="previewImage('<?php echo $vendor['_id']; ?>')" />
|
||||
<label><i class="fa-solid fa-file-import" style="cursor:pointer;" onclick="document.getElementById('fileInput<?php echo $vendor['_id']; ?>').click()"></i></label>
|
||||
|
||||
|
||||
</div>
|
||||
<div class="vendor-image" style="padding-top:20px; ">
|
||||
<?php
|
||||
|
@ -248,30 +267,29 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
</div>
|
||||
|
||||
<script>
|
||||
function updateButtonText(input){
|
||||
function updateButtonText(input) {
|
||||
var label = document.getElementById('fileInputLabel');
|
||||
if (input.files.length > 0) {
|
||||
label.innerHTML = '<i class="fa-solid fa-file-arrow-up"></i> ' + input.files[0].name;
|
||||
}else{
|
||||
} else {
|
||||
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();
|
||||
var fileInput = document.getElementById('fileInput' + vendorId);
|
||||
var file = fileInput.files[0];
|
||||
console.log('clicked hereee');
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = function (e) {
|
||||
const dataUri = e.target.result;
|
||||
document.getElementById('imgPrev' + vendorId).src = dataUri; // Fixed concatenation here
|
||||
};
|
||||
reader.onload = function(e) {
|
||||
const dataUri = e.target.result;
|
||||
document.getElementById('imgPrev' + vendorId).src = dataUri; // Fixed concatenation here
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
// 03-14-2024 Jun Jihad modified this block of code to show preview of the image to be uploaded
|
||||
|
||||
</script>
|
||||
</div>
|
||||
<form>
|
||||
|
@ -378,296 +396,293 @@ $vendorSearchResult = $_SESSION["vendorSearchResult"];
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function deleteVendor(vendorId){
|
||||
function deleteVendor(vendorId) {
|
||||
let text = "Please confirm delete action!\nClick OK or Cancel button.";
|
||||
if (confirm(text) == true) {
|
||||
window.open("vendor-delete-action.php?id=" + vendorId, "_self");
|
||||
}
|
||||
}
|
||||
|
||||
function uploadFile(vendorId) {
|
||||
const originalEmail = document.getElementById('email-' + vendorId).defaultValue;
|
||||
const updatedEmail = document.getElementById('email-' + vendorId).value;
|
||||
const isEmailModified = originalEmail !== updatedEmail;
|
||||
const originalEmail = document.getElementById('email-' + vendorId).defaultValue;
|
||||
const updatedEmail = document.getElementById('email-' + vendorId).value;
|
||||
const isEmailModified = originalEmail !== updatedEmail;
|
||||
|
||||
if (isEmailModified) {
|
||||
validateEmail(vendorId).then(isEmailAvailable => {
|
||||
if (!isEmailAvailable) {
|
||||
$('#email-error-message-' + vendorId).text('Email is already in use').show();
|
||||
} else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
if (isEmailModified) {
|
||||
validateEmail(vendorId).then(isEmailAvailable => {
|
||||
if (!isEmailAvailable) {
|
||||
$('#email-error-message-' + vendorId).text('Email is already in use').show();
|
||||
} else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
|
||||
var fileInput = document.getElementById('fileInput' + vendorId);
|
||||
var file = fileInput.files[0];
|
||||
|
||||
|
||||
|
||||
const updatedUser = document.getElementById('user_login-' + vendorId).value;
|
||||
const firstName = document.getElementById('firstName-' + vendorId).value;
|
||||
const lastName = document.getElementById('lastName-' + vendorId).value;
|
||||
const phone = document.getElementById('phone-' + vendorId).value;
|
||||
const description = document.getElementById('description-' + vendorId).value;
|
||||
const status = document.getElementById('status-' + vendorId).value;
|
||||
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
|
||||
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
|
||||
const barangay = document.getElementById('barangay-' + vendorId).value;
|
||||
const city = document.getElementById('city-' + vendorId).value;
|
||||
const province = document.getElementById('province-' + vendorId).value;
|
||||
const country = document.getElementById('country-' + vendorId).value;
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('image_id', vendorId);
|
||||
formData.append('category', 'vendor');
|
||||
formData.append('image', file); // Include the file data in the form data
|
||||
|
||||
if(file){
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/upload_image', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('File upload failed');
|
||||
throw new Error('File upload failed');
|
||||
}
|
||||
})
|
||||
.then(result => {
|
||||
const filename = result.filename;
|
||||
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
})
|
||||
.then(secondResponse => {
|
||||
if (secondResponse.ok) {
|
||||
console.log('Second request successful');
|
||||
location.reload();
|
||||
} else {
|
||||
console.error('Second request failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during fetch:', error);
|
||||
});
|
||||
|
||||
}else{
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('vendor Update failed');
|
||||
throw new Error('vendor Update failed');
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
|
||||
const updatedUser = document.getElementById('user_login-' + vendorId).value;
|
||||
const firstName = document.getElementById('firstName-' + vendorId).value;
|
||||
const lastName = document.getElementById('lastName-' + vendorId).value;
|
||||
const updatedEmail = document.getElementById('email-' + vendorId).value;
|
||||
const phone = document.getElementById('phone-' + vendorId).value;
|
||||
const description = document.getElementById('description-' + vendorId).value;
|
||||
const status = document.getElementById('status-' + vendorId).value;
|
||||
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
|
||||
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
|
||||
const barangay = document.getElementById('barangay-' + vendorId).value;
|
||||
const city = document.getElementById('city-' + vendorId).value;
|
||||
const province = document.getElementById('province-' + vendorId).value;
|
||||
const country = document.getElementById('country-' + vendorId).value;
|
||||
|
||||
var fileInput = document.getElementById('fileInput' + vendorId);
|
||||
var file = fileInput.files[0];
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('image_id', vendorId);
|
||||
formData.append('category', 'vendor');
|
||||
formData.append('image', file);
|
||||
|
||||
if (file){
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/upload_image', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('File upload failed');
|
||||
throw new Error('File upload failed');
|
||||
}
|
||||
})
|
||||
.then(result => {
|
||||
const filename = result.filename;
|
||||
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
// Make API request using the extracted filename
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
})
|
||||
.then(secondResponse => {
|
||||
if (secondResponse.ok) {
|
||||
console.log('Second request successful');
|
||||
location.reload();
|
||||
} else {
|
||||
console.error('Second request failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during fetch:', error);
|
||||
});
|
||||
}else{
|
||||
|
||||
const payload = {
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('vendor Update failed');
|
||||
throw new Error('vendor Update failed');
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function validateEmail(vendorId) {
|
||||
var emailInput = document.getElementById('email-' + vendorId);
|
||||
var email = emailInput.value;
|
||||
|
||||
if (email.trim() !== '') {
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/search?q=' + email)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw new Error('Failed to check email availability');
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
const isEmailAvailable = parseInt(data.results.length) === 0;
|
||||
$('#email-error-message-' + vendorId).text(isEmailAvailable ? '' : 'Email is already in use').show();
|
||||
return isEmailAvailable;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during email validation:', error);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
var fileInput = document.getElementById('fileInput' + vendorId);
|
||||
var file = fileInput.files[0];
|
||||
|
||||
|
||||
|
||||
const updatedUser = document.getElementById('user_login-' + vendorId).value;
|
||||
const firstName = document.getElementById('firstName-' + vendorId).value;
|
||||
const lastName = document.getElementById('lastName-' + vendorId).value;
|
||||
const phone = document.getElementById('phone-' + vendorId).value;
|
||||
const description = document.getElementById('description-' + vendorId).value;
|
||||
const status = document.getElementById('status-' + vendorId).value;
|
||||
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
|
||||
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
|
||||
const barangay = document.getElementById('barangay-' + vendorId).value;
|
||||
const city = document.getElementById('city-' + vendorId).value;
|
||||
const province = document.getElementById('province-' + vendorId).value;
|
||||
const country = document.getElementById('country-' + vendorId).value;
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('image_id', vendorId);
|
||||
formData.append('category', 'vendor');
|
||||
formData.append('image', file); // Include the file data in the form data
|
||||
|
||||
if (file) {
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/upload_image', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('File upload failed');
|
||||
throw new Error('File upload failed');
|
||||
}
|
||||
})
|
||||
.then(result => {
|
||||
const filename = result.filename;
|
||||
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
})
|
||||
.then(secondResponse => {
|
||||
if (secondResponse.ok) {
|
||||
console.log('Second request successful');
|
||||
location.reload();
|
||||
} else {
|
||||
console.error('Second request failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during fetch:', error);
|
||||
});
|
||||
|
||||
} else {
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('vendor Update failed');
|
||||
throw new Error('vendor Update failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
|
||||
const updatedUser = document.getElementById('user_login-' + vendorId).value;
|
||||
const firstName = document.getElementById('firstName-' + vendorId).value;
|
||||
const lastName = document.getElementById('lastName-' + vendorId).value;
|
||||
const updatedEmail = document.getElementById('email-' + vendorId).value;
|
||||
const phone = document.getElementById('phone-' + vendorId).value;
|
||||
const description = document.getElementById('description-' + vendorId).value;
|
||||
const status = document.getElementById('status-' + vendorId).value;
|
||||
const updatedAddress1 = document.getElementById('address_1-' + vendorId).value;
|
||||
const updatedAddress2 = document.getElementById('address_2-' + vendorId).value;
|
||||
const barangay = document.getElementById('barangay-' + vendorId).value;
|
||||
const city = document.getElementById('city-' + vendorId).value;
|
||||
const province = document.getElementById('province-' + vendorId).value;
|
||||
const country = document.getElementById('country-' + vendorId).value;
|
||||
|
||||
var fileInput = document.getElementById('fileInput' + vendorId);
|
||||
var file = fileInput.files[0];
|
||||
|
||||
var formData = new FormData();
|
||||
formData.append('image_id', vendorId);
|
||||
formData.append('category', 'vendor');
|
||||
formData.append('image', file);
|
||||
|
||||
if (file) {
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/upload_image', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('File upload failed');
|
||||
throw new Error('File upload failed');
|
||||
}
|
||||
})
|
||||
.then(result => {
|
||||
const filename = result.filename;
|
||||
|
||||
const payload = {
|
||||
vendor_image: `https://<?php echo $_SESSION["data_endpoint"]; ?>/images/storage/vendor_uploads/${filename}`,
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
// Make API request using the extracted filename
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
})
|
||||
.then(secondResponse => {
|
||||
if (secondResponse.ok) {
|
||||
console.log('Second request successful');
|
||||
location.reload();
|
||||
} else {
|
||||
console.error('Second request failed');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during fetch:', error);
|
||||
});
|
||||
} else {
|
||||
|
||||
const payload = {
|
||||
user_login: updatedUser,
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
user_email: updatedEmail,
|
||||
phone: phone,
|
||||
vendor_description: description,
|
||||
status: status,
|
||||
address: [{
|
||||
address_1: updatedAddress1,
|
||||
address_2: updatedAddress2,
|
||||
barangay: barangay,
|
||||
city: city,
|
||||
province: province,
|
||||
country: country,
|
||||
}]
|
||||
};
|
||||
|
||||
fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/' + vendorId, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
location.reload();
|
||||
return response.json();
|
||||
} else {
|
||||
console.error('vendor Update failed');
|
||||
throw new Error('vendor Update failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function validateEmail(vendorId) {
|
||||
var emailInput = document.getElementById('email-' + vendorId);
|
||||
var email = emailInput.value;
|
||||
|
||||
if (email.trim() !== '') {
|
||||
return fetch('https://<?php echo $_SESSION["data_endpoint"]; ?>/api/v1/vendors/search?q=' + email)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
throw new Error('Failed to check email availability');
|
||||
}
|
||||
})
|
||||
.then(data => {
|
||||
const isEmailAvailable = parseInt(data.results.length) === 0;
|
||||
$('#email-error-message-' + vendorId).text(isEmailAvailable ? '' : 'Email is already in use').show();
|
||||
return isEmailAvailable;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during email validation:', error);
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
$('#email-error-message-' + vendorId).text('').hide();
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- <script>
|
||||
|
@ -821,27 +836,27 @@ function validateEmail(vendorId) {
|
|||
} */
|
||||
|
||||
$start = max(1, $currentpage - 2);
|
||||
$end = min($totalPages, $start + 4);
|
||||
$end = min($totalPages, $start + 4);
|
||||
|
||||
if ($start > 1) {
|
||||
echo "<a href='?page=1'>1</a>";
|
||||
if ($start > 2) {
|
||||
echo "<span> ... </span>";
|
||||
}
|
||||
if ($start > 1) {
|
||||
echo "<a href='?page=1'>1</a>";
|
||||
if ($start > 2) {
|
||||
echo "<span> ... </span>";
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a> ";
|
||||
}
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
echo "<a href='?page=$i' class='" . ($currentpage == $i ? 'active' : '') . "'>$i</a> ";
|
||||
}
|
||||
|
||||
if ($end < $totalPages) {
|
||||
if ($end < $totalPages - 1) {
|
||||
echo "<span> ... </span>";
|
||||
}
|
||||
echo "<a href='?page=$totalPages'>$totalPages</a>";
|
||||
if ($end < $totalPages) {
|
||||
if ($end < $totalPages - 1) {
|
||||
echo "<span> ... </span>";
|
||||
}
|
||||
echo "<a href='?page=$totalPages'>$totalPages</a>";
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
</div>
|
||||
<!-- Ec Pagination End -->
|
||||
|
||||
|
@ -858,35 +873,35 @@ function validateEmail(vendorId) {
|
|||
<form action="add_vendor_action.php" method="post">
|
||||
<div class="ec-vendor-block-img space-bottom-30">
|
||||
<!-- <div class="ec-vendor-block-bg cover-upload">
|
||||
<div class="thumb-upload">
|
||||
<div class="thumb-edit">
|
||||
<input type='file' id="thumbUpload01" class="ec-image-upload"
|
||||
accept=".png, .jpg, .jpeg" />
|
||||
<label><i class="fi-rr-edit"></i></label>
|
||||
</div>
|
||||
<div class="thumb-preview ec-preview">
|
||||
<div class="image-thumb-preview">
|
||||
<img loading="lazy" class="image-thumb-preview ec-image-preview v-img"
|
||||
src="assets/images/banner/7.jpg" alt="edit" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- <div class="ec-vendor-block-detail">
|
||||
<div class="thumb-upload">
|
||||
<div class="thumb-edit">
|
||||
<input type='file' id="thumbUpload02" class="ec-image-upload"
|
||||
accept=".png, .jpg, .jpeg" />
|
||||
<label><i class="fi-rr-edit"></i></label>
|
||||
</div>
|
||||
<div class="thumb-preview ec-preview">
|
||||
<div class="image-thumb-preview">
|
||||
<img loading="lazy" class="image-thumb-preview ec-image-preview v-img"
|
||||
src="assets/images/vendor/5.jpg" alt="edit" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="thumb-upload">
|
||||
<div class="thumb-edit">
|
||||
<input type='file' id="thumbUpload01" class="ec-image-upload"
|
||||
accept=".png, .jpg, .jpeg" />
|
||||
<label><i class="fi-rr-edit"></i></label>
|
||||
</div>
|
||||
<div class="thumb-preview ec-preview">
|
||||
<div class="image-thumb-preview">
|
||||
<img loading="lazy" class="image-thumb-preview ec-image-preview v-img"
|
||||
src="assets/images/banner/7.jpg" alt="edit" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- <div class="ec-vendor-block-detail">
|
||||
<div class="thumb-upload">
|
||||
<div class="thumb-edit">
|
||||
<input type='file' id="thumbUpload02" class="ec-image-upload"
|
||||
accept=".png, .jpg, .jpeg" />
|
||||
<label><i class="fi-rr-edit"></i></label>
|
||||
</div>
|
||||
<div class="thumb-preview ec-preview">
|
||||
<div class="image-thumb-preview">
|
||||
<img loading="lazy" class="image-thumb-preview ec-image-preview v-img"
|
||||
src="assets/images/vendor/5.jpg" alt="edit" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="ec-vendor-upload-detail">
|
||||
<form class="row g-3">
|
||||
<div class="col-md-12 space-t-15">
|
||||
|
|
|
@ -360,147 +360,111 @@ $filteredProducts = [];
|
|||
}
|
||||
|
||||
function loadVendors(page, isFilter) {
|
||||
document.querySelector(".vendor-list").innerHTML = "";
|
||||
document.querySelector(".vendor-list").innerHTML = "";
|
||||
|
||||
// Create a new XMLHttpRequest object for fetching vendors
|
||||
let xhrVendors = new XMLHttpRequest();
|
||||
// Create a new XMLHttpRequest object for fetching vendors
|
||||
let xhrVendors = new XMLHttpRequest();
|
||||
|
||||
// Define the endpoint URL for fetching vendors
|
||||
let vendorsEndpointURL =
|
||||
`https://<?php echo htmlspecialchars($_SESSION["data_endpoint"]); ?>/api/v1/vendors/search?q=<?php echo $_GET['search'] ?>`;
|
||||
// Define the endpoint URL for fetching vendors
|
||||
let vendorsEndpointURL = `https://<?php echo htmlspecialchars($_SESSION["data_endpoint"]); ?>/api/v1/vendors/search?q=<?php echo $_GET['search'] ?>`;
|
||||
|
||||
// Open a GET request to fetch vendors
|
||||
xhrVendors.open("GET", vendorsEndpointURL, true);
|
||||
// Open a GET request to fetch vendors
|
||||
xhrVendors.open("GET", vendorsEndpointURL, true);
|
||||
|
||||
// Set up a callback function to handle the vendors response
|
||||
xhrVendors.onreadystatechange = function() {
|
||||
if (xhrVendors.readyState === 4 && xhrVendors.status === 200) {
|
||||
// Parse the response JSON for vendors
|
||||
let vendorsResponse = JSON.parse(xhrVendors.responseText);
|
||||
// Set up a callback function to handle the vendors response
|
||||
xhrVendors.onreadystatechange = function() {
|
||||
if (xhrVendors.readyState === 4 && xhrVendors.status === 200) {
|
||||
// Parse the response JSON for vendors
|
||||
let vendorsResponse = JSON.parse(xhrVendors.responseText);
|
||||
|
||||
// Create an array to store vendor IDs
|
||||
let vendorIds = vendorsResponse.results.map(vendor => vendor._id);
|
||||
// Create an array to store vendor IDs
|
||||
let vendorIds = vendorsResponse.results.map(vendor => vendor._id);
|
||||
|
||||
// Create a new XMLHttpRequest object for fetching products
|
||||
let xhrProducts = new XMLHttpRequest();
|
||||
// Create a new XMLHttpRequest object for fetching products
|
||||
let xhrProducts = new XMLHttpRequest();
|
||||
|
||||
// Define the endpoint URL for fetching products
|
||||
let productsEndpointURL =
|
||||
`https://<?php echo htmlspecialchars($_SESSION["data_endpoint"]); ?>/api/v1/products`;
|
||||
// Define the endpoint URL for fetching products
|
||||
let productsEndpointURL = `https://<?php echo htmlspecialchars($_SESSION["data_endpoint"]); ?>/api/v1/products`;
|
||||
|
||||
// Open a GET request to fetch products
|
||||
xhrProducts.open("GET", productsEndpointURL, true);
|
||||
// Open a GET request to fetch products
|
||||
xhrProducts.open("GET", productsEndpointURL, true);
|
||||
|
||||
// Set up a callback function to handle the products response
|
||||
xhrProducts.onreadystatechange = function() {
|
||||
if (xhrProducts.readyState === 4 && xhrProducts.status === 200) {
|
||||
// Parse the response JSON for products
|
||||
let productsResponse = JSON.parse(xhrProducts.responseText);
|
||||
console.log(productsResponse)
|
||||
// Create an object to store vendor-wise product counts
|
||||
let vendorProductCounts = {};
|
||||
// Set up a callback function to handle the products response
|
||||
xhrProducts.onreadystatechange = function() {
|
||||
if (xhrProducts.readyState === 4 && xhrProducts.status === 200) {
|
||||
// Parse the response JSON for products
|
||||
let productsResponse = JSON.parse(xhrProducts.responseText);
|
||||
console.log(productsResponse);
|
||||
|
||||
// Iterate through each product and count the products associated with each vendor
|
||||
productsResponse.forEach(function(product) {
|
||||
// Increment product count for the vendor
|
||||
if (!vendorProductCounts[product.vendor_api_id]) {
|
||||
vendorProductCounts[product.vendor_api_id] = 1;
|
||||
} else {
|
||||
vendorProductCounts[product.vendor_api_id]++;
|
||||
}
|
||||
});
|
||||
// Create an object to store vendor-wise product counts
|
||||
let vendorProductCounts = {};
|
||||
|
||||
// Now, we have vendor-wise product counts, we can use it to display the counts for each vendor
|
||||
if (vendorsResponse.results.length > 0) {
|
||||
// Iterate through each product and count the products associated with each vendor
|
||||
productsResponse.forEach(function(product) {
|
||||
// Increment product count for the vendor
|
||||
if (!vendorProductCounts[product.vendor_api_id]) {
|
||||
vendorProductCounts[product.vendor_api_id] = 1;
|
||||
} else {
|
||||
vendorProductCounts[product.vendor_api_id]++;
|
||||
}
|
||||
});
|
||||
|
||||
vendorsResponse.results.slice(0, 6).forEach(function(
|
||||
vendor) {
|
||||
let vendorId = vendor._id;
|
||||
let productCount = vendorProductCounts[
|
||||
vendorId] || 0;
|
||||
let vendorDateRegistered = new Date(vendor
|
||||
.date_registered);
|
||||
vendorsResponse.results.slice(0, 6).forEach(
|
||||
function(vendor) {
|
||||
let vendorDateRegistered = "";
|
||||
let vendorId = vendor._id;
|
||||
let productCount =
|
||||
vendorProductCounts[vendorId] ||
|
||||
0;
|
||||
if (vendor.date_registered) {
|
||||
vendorDateRegistered = new Date(
|
||||
vendor.date_registered);
|
||||
} else {
|
||||
vendorDateRegistered =
|
||||
"Not yet registered";
|
||||
}
|
||||
// Now, we have vendor-wise product counts, we can use it to display the counts for each vendor
|
||||
if (vendorsResponse.results.length > 0) {
|
||||
vendorsResponse.results.slice(0, 6).forEach(function(vendor) {
|
||||
let vendorId = vendor._id;
|
||||
let productCount = vendorProductCounts[vendorId] || 0;
|
||||
let vendorDateRegistered = vendor.date_registered ? new Date(vendor.date_registered) : "Not yet registered";
|
||||
|
||||
// Format the date as "Month DD, YYYY"
|
||||
let options = {
|
||||
month: 'long',
|
||||
day: '2-digit',
|
||||
year: 'numeric'
|
||||
};
|
||||
let formattedDate = "";
|
||||
if (vendorDateRegistered !==
|
||||
"Not yet registered") {
|
||||
formattedDate =
|
||||
vendorDateRegistered
|
||||
.toLocaleDateString('en-US',
|
||||
options);
|
||||
} else {
|
||||
formattedDate =
|
||||
"Not yet registered";
|
||||
}
|
||||
// Create a product card element
|
||||
let card = document.createElement(
|
||||
"div");
|
||||
card.classList.add("col-md-12");
|
||||
card.innerHTML = `
|
||||
<div class="card" style="margin:5px">
|
||||
<div class="card-body">
|
||||
<div class="vendor-info" style="display: flex; align-items: center; flex-wrap:wrap; justify-content:center">
|
||||
<div class="ec-catalog-vendor" style="display: inline-block; margin-bottom:10px">
|
||||
<a href="catalog-single-vendor.php?id=${vendorId}">
|
||||
// Format the date as "Month DD, YYYY"
|
||||
let options = {
|
||||
month: 'long',
|
||||
day: '2-digit',
|
||||
year: 'numeric'
|
||||
};
|
||||
let formattedDate = vendorDateRegistered !== "Not yet registered" ? vendorDateRegistered.toLocaleDateString('en-US', options) : "Not yet registered";
|
||||
|
||||
<img loading="lazy" src="${vendor.vendor_image ? vendor.vendor_image : 'https://api.obanana.com/images/storage/web_images/1708588564876-viber_image_2024-02-22_15-54-42-498.png'}" alt="${vendor.user_login}" class="vendor-image" style="max-width: 100px; max-height: 100px;">
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div class="vendor-details" style="display:inline-block; max-width:300px">
|
||||
<a href="catalog-single-vendor.php?id=${vendorId}">
|
||||
<h6 class="ec-pro-title" style="padding:0 30px;font-family: Poppins, sans-serif; text-decoration: none; color: #777;white-space: nowrap;text-overflow: ellipsis;display: block;font-size: 16px;font-weight: 400;">
|
||||
${vendor.user_login}
|
||||
</h6>
|
||||
</a>
|
||||
</div>
|
||||
<div class="card text-center" style="margin-left: auto; margin-right: 5px;">
|
||||
<div class="card-body">
|
||||
<h6>Seller Products</h6>
|
||||
<p>${productCount}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card text-center" style="margin-left: 5px; margin-right: 5px; min-width:180px">
|
||||
<div class="card-body">
|
||||
<h6>Seller since</h6>
|
||||
<p>${formattedDate}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
// Append the product card to the container
|
||||
document.querySelector(
|
||||
".vendor-list")
|
||||
.appendChild(card);
|
||||
});
|
||||
// Create a product card element
|
||||
let card = document.createElement("div");
|
||||
card.classList.add("col-md-12");
|
||||
card.innerHTML = `
|
||||
<div class="card" style="margin:5px">
|
||||
<div class="card-body">
|
||||
<div class="vendor-info" style="display: flex; align-items: center; flex-wrap:wrap; justify-content:center">
|
||||
<div class="ec-catalog-vendor" style="display: inline-block; margin-bottom:10px">
|
||||
<a href="catalog-single-vendor.php?id=${vendorId}">
|
||||
<img loading="lazy" src="${vendor.vendor_image ? vendor.vendor_image : 'https://api.obanana.com/images/storage/web_images/1708588564876-viber_image_2024-02-22_15-54-42-498.png'}" alt="${vendor.user_login}" class="vendor-image" style="max-width: 100px; max-height: 100px;">
|
||||
</a>
|
||||
</div>
|
||||
<div class="vendor-details" style="display:inline-block; max-width:300px">
|
||||
<a href="catalog-single-vendor.php?id=${vendorId}">
|
||||
<h6 class="ec-pro-title" style="padding:0 30px;font-family: Poppins, sans-serif; text-decoration: none; color: #777;white-space: nowrap;text-overflow: ellipsis;display: block;font-size: 16px;font-weight: 400;">
|
||||
${vendor.user_login}
|
||||
</h6>
|
||||
</a>
|
||||
</div>
|
||||
<div class="card text-center" style="margin-left: auto; margin-right: 5px;">
|
||||
<div class="card-body">
|
||||
<h6>Seller Products</h6>
|
||||
<p>${productCount}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card text-center" style="margin-left: 5px; margin-right: 5px; min-width:180px">
|
||||
<div class="card-body">
|
||||
<h6>Seller since</h6>
|
||||
<p>${formattedDate}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
// Append the product card to the container
|
||||
document.querySelector(".vendor-list").appendChild(card);
|
||||
});
|
||||
} else {
|
||||
document.querySelector(".vendor-list")
|
||||
.innerHTML = `
|
||||
<h6>No vendors available</h6>
|
||||
|
||||
`;
|
||||
|
||||
document.querySelector(".vendor-list").innerHTML = `
|
||||
<h6>No vendors available</h6>
|
||||
`;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -512,9 +476,9 @@ $filteredProducts = [];
|
|||
|
||||
// Send the request to fetch vendors
|
||||
xhrVendors.send();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function loadProducts(page, isFilter) {
|
||||
// Make AJAX request to fetch products for given page
|
||||
let xhr = new XMLHttpRequest();
|
||||
|
|
Loading…
Reference in New Issue