CHANGE_DASHBOARD_COMPLETE_PUSH : AADHAVAN

This commit is contained in:
aadhavan valli 2024-07-30 11:20:35 +05:30
parent b5a3988644
commit a8f0a34762

View File

@ -9,6 +9,8 @@
<!-- Bootstrap JS (ensure this is included) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
<!-- Remove one of these -->
<style>
.carousel-control-next {
@ -339,10 +341,20 @@ $(document).ready(function() {
// Attach click handlers to carousel controls
$('.carousel-control-next').on('click', function() {
navigateCarousel('next');
$('.carousel-item').each(function(index, element) {
if ($.trim($(element).html()) === '') {
$(element).remove();
}
});
});
$('.carousel-control-prev').on('click', function() {
navigateCarousel('prev');
$('.carousel-item').each(function(index, element) {
if ($.trim($(element).html()) === '') {
$(element).remove();
}
});
});
// Check the carousel item when the slide changes
@ -373,9 +385,286 @@ function enrollment_list(current_element, type) {
}
$('#enrollment_status_open_close').change(function () {
if ($(this).val() === 'open') {
var enrollment_data = '<?php echo addslashes($_SESSION['enrollment_data']); ?>';
try {
// Parse JSON data
var data = JSON.parse(enrollment_data);
console.log('Parsed data:', data);
// Ensure data is an object and client_branch_emp_list is treated as an array
if (data && typeof data === 'object') {
if (Array.isArray(data.client_branch_emp_list)) {
console.log('client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data, 1);
} else {
// Convert client_branch_emp_list to an array if it's not already
if (data.client_branch_emp_list && typeof data.client_branch_emp_list === 'object') {
// If it's an object but not an array, wrap it in an array
data.client_branch_emp_list = [data.client_branch_emp_list];
} else {
// Handle the case where it's neither an array nor an object
console.error('client_branch_emp_list is not an array or object:', data.client_branch_emp_list);
data.client_branch_emp_list = []; // Ensure it is at least an empty array
}
console.log('Converted client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data, 1);
}
} else {
console.error('Parsed data is not an object:', data);
}
} catch (e) {
console.error('Error parsing JSON:', e);
}
} else {
// Fetch the session data from PHP
var enrollment_data = '<?php echo addslashes($_SESSION['enrollment_data']); ?>';
try {
// Parse JSON data
var data = JSON.parse(enrollment_data);
console.log('Parsed data:', data);
// Ensure data is an object and client_branch_emp_list is treated as an array
if (data && typeof data === 'object') {
if (Array.isArray(data.client_branch_emp_list)) {
console.log('client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data, 2);
} else {
// Convert client_branch_emp_list to an array if it's not already
if (data.client_branch_emp_list && typeof data.client_branch_emp_list === 'object') {
// If it's an object but not an array, wrap it in an array
data.client_branch_emp_list = [data.client_branch_emp_list];
} else {
// Handle the case where it's neither an array nor an object
console.error('client_branch_emp_list is not an array or object:', data.client_branch_emp_list);
data.client_branch_emp_list = []; // Ensure it is at least an empty array
}
console.log('Converted client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data, 2);
}
} else {
console.error('Parsed data is not an object:', data);
}
} catch (e) {
console.error('Error parsing JSON:', e);
}
}
});
function updateCarouselWithData(data, open_close) {
var itemsPerSlide = 3; // Number of items per slide
var currentItem = 0; // Counter for items
var isActive = true; // Variable to set the first item as active
var carouselInner = $('.carousel-inner');
// Clear existing carousel items
carouselInner.empty();
// Check if data.client_branch_emp_list is valid
if (Array.isArray(data.client_branch_emp_list) && data.client_branch_emp_list.length > 0) {
console.log("Processing array...");
// Handle the case where data.client_branch_emp_list is an array
var items = data.client_branch_emp_list[0];
console.log("Items data:", items);
// Convert items object to an array
var client_list = Object.values(items);
// Validate if client_list is an array
if (Array.isArray(client_list)) {
console.log(client_list);
for (var i = 0; i < client_list.length; i++) {
var client = client_list[i];
// console.log(item.branches);
var branch_list = client.branches;
for (var j = 0; j < branch_list.length; j++) {
var branch = branch_list[j];
console.log(branch);
if(open_close == 1){
if(branch.client_policies.length > 0){
if (currentItem % itemsPerSlide === 0) {
if (!isActive) carouselInner.append('</div>'); // Close previous carousel item
carouselInner.append('<div class="carousel-item' + (isActive ? ' active' : '') + '">');
isActive = false;
}
// Generate HTML for each item
var itemHtml = `
<div class="col-xl-3 col-md-6 d-inline-block scroll-item carousel-slide-item" data-client="${client.short_name}" data-branch="${branch.branch_name }">
<div class="card" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);">
<div class="card-header add_card_background_random" >
<div class="row">
<div class="col-8 emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 " >
<h3 class="my-2 py-1" ><span data-plugin="counterup" style="font-size: 2.0rem;background-color: white;border-radius: 6px;height: 30;padding: 4px 11px 4px 11px;" onclick="enrollment_list(this, 'emp_count_view_click')">${branch.employees.length}</span></h3>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100" >
<h5 class="mt-0 text-truncate" title="Branch Info" style="font-weight: 400 !important;font-size: 20px !important;line-height: 36px;color: black !important;">${client.short_name} - ${branch.branch_name} </h5>
</div>
</div>
</div>
<!-- <div class="col-3 center_text emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 text-center" >
<p class="mb-0 text-muted">
<span class="text-success mr-2"></span>
<span class="text-nowrap">Emp Count</span>
</p>
</div>
</div>
</div> -->
</div>
</div>
<div class="card-body" >
<input type="text" class="client_id" value="${client.client_id}" hidden>
<input type="text" class="client_branch_id" value="${branch.client_branch_id}" hidden>
<div class="row emp-status" style="margin-top: -9px;">
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_logged_in_view_click')">${branch.emp_login}</span><br>
<span class="text-nowrap " style="color: currentColor;font-size: 15px;">Logged-In</span>
</div>
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_logged_in_view_click')"> ${branch.employees.length - (branch.emp_login || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;margin-left: -13px;">Not Logged-In</span>
</div>
</div>
<div class="row emp-status" style="margin-top: 5px;">
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_enrolled_view_click')">${branch.employees.length - (branch.emp_enroll || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Draft</span>
</div>
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_enrolled_view_click')">${(branch.emp_enroll || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Enrolled</span>
</div>
</div>
</div>
</div>
</div>
`;
carouselInner.find('.carousel-item').last().append(itemHtml);
currentItem++;
}
}else{
if(branch.client_policies.length == 0){
if (currentItem % itemsPerSlide === 0) {
if (!isActive) carouselInner.append('</div>'); // Close previous carousel item
carouselInner.append('<div class="carousel-item' + (isActive ? ' active' : '') + '">');
isActive = false;
}
// Generate HTML for each item
var itemHtml = `
<div class="col-xl-3 col-md-6 d-inline-block scroll-item carousel-slide-item" data-client="${client.short_name}" data-branch="${branch.branch_name }">
<div class="card" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);">
<div class="card-header add_card_background_random" >
<div class="row">
<div class="col-8 emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 " >
<h3 class="my-2 py-1" ><span data-plugin="counterup" style="font-size: 2.0rem;background-color: white;border-radius: 6px;height: 30;padding: 4px 11px 4px 11px;" onclick="enrollment_list(this, 'emp_count_view_click')">${branch.employees.length}</span></h3>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100" >
<h5 class="mt-0 text-truncate" title="Branch Info" style="font-weight: 400 !important;font-size: 20px !important;line-height: 36px;color: black !important;">${client.short_name} - ${branch.branch_name} </h5>
</div>
</div>
</div>
<!-- <div class="col-3 center_text emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 text-center" >
<p class="mb-0 text-muted">
<span class="text-success mr-2"></span>
<span class="text-nowrap">Emp Count</span>
</p>
</div>
</div>
</div> -->
</div>
</div>
<div class="card-body" >
<input type="text" class="client_id" value="${client.client_id}" hidden>
<input type="text" class="client_branch_id" value="${branch.client_branch_id}" hidden>
<div class="row emp-status" style="margin-top: -9px;">
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_logged_in_view_click')">${branch.emp_login}</span><br>
<span class="text-nowrap " style="color: currentColor;font-size: 15px;">Logged-In</span>
</div>
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_logged_in_view_click')"> ${branch.employees.length - (branch.emp_login || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;margin-left: -13px;">Not Logged-In</span>
</div>
</div>
<div class="row emp-status" style="margin-top: 5px;">
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_enrolled_view_click')">${branch.employees.length - (branch.emp_enroll || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Draft</span>
</div>
<div class="col-6 emp-count-view-click" >
<span style="font-size: large;color: black !important;" class="number_css" onclick="enrollment_list(this, 'emp_enrolled_view_click')">${(branch.emp_enroll || 0)}</span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Enrolled</span>
</div>
</div>
</div>
</div>
</div>
`;
carouselInner.find('.carousel-item').last().append(itemHtml);
currentItem++;
}
}
}
// Create a new carousel item every `itemsPerSlide` items
}
// Close the last carousel item if it was opened
if (currentItem % itemsPerSlide !== 0) carouselInner.append('</div>');
} else {
console.error('Expected an array for items, but got:', client_list);
}
} else if (typeof data.client_branch_emp_list === 'object') {
console.error('client_branch_emp_list is an object, not an array:', data.client_branch_emp_list);
} else {
console.error('client_branch_emp_list is missing or not in the expected format:', data.client_branch_emp_list);
}
random_color_set();
// Initialize or refresh carousel if needed
$('#carouselExampleControls').carousel('dispose').carousel();
}
document.addEventListener('DOMContentLoaded', function() {
// Array of predefined colors
var colors = ['#EBE8FF', '#FFECE5', '#FFE8F5'];
random_color_set();
});
function remove_empty_carousel() {
}
function random_color_set() {
// Array of predefined colors
var colors = ['#EBE8FF', '#FFECE5', '#FFE8F5'];
// '#6ADBE3'
// Array of predefined background images
var images = [
@ -399,135 +688,6 @@ document.addEventListener('DOMContentLoaded', function() {
header.style.backgroundPosition = 'center'; // Center the image within the div
index++;
});
});
$('#enrollment_status_open_close').change(function () {
if ($(this).val() == 'open') {
console.log("open");
} else {
console.log("close");
// Fetch the session data from PHP
var enrollment_data = '<?php echo $_SESSION['enrollment_data']; ?>';
try {
// Parse JSON data
var data = JSON.parse(enrollment_data);
console.log('Parsed data:', data);
// Ensure data is an object and client_branch_emp_list is treated as an array
if (data && typeof data === 'object') {
if (Array.isArray(data.client_branch_emp_list)) {
console.log('client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data);
} else {
// Convert client_branch_emp_list to an array if it's not already
if (data.client_branch_emp_list && typeof data.client_branch_emp_list === 'object') {
// If it's an object but not an array, wrap it in an array
data.client_branch_emp_list = [data.client_branch_emp_list];
} else {
// Handle the case where it's neither an array nor an object
console.error('client_branch_emp_list is not an array or object:', data.client_branch_emp_list);
data.client_branch_emp_list = []; // Ensure it is at least an empty array
}
console.log('Converted client_branch_emp_list:', data.client_branch_emp_list);
updateCarouselWithData(data);
}
} else {
console.error('Parsed data is not an object:', data);
}
} catch (e) {
console.error('Error parsing JSON:', e);
}
}
});
function updateCarouselWithData(data) {
console.log(data);
var itemsPerSlide = 3; // Number of items per slide
var currentItem = 0; // Counter for items
var isActive = true; // Variable to set the first item as active
var carouselInner = $('.carousel-inner');
// Clear existing carousel items
carouselInner.empty();
// Check if data.client_branch_emp_list is valid
if (Array.isArray(data.client_branch_emp_list) && data.client_branch_emp_list.length > 0) {
console.log("Processing array...");
// Handle the case where data.client_branch_emp_list is an array
var items = data.client_branch_emp_list[0];
console.log("Items data:", items);
array.forEach(element => {
});
// Validate if items is an array
if (Array.isArray(items)) {
for (var i = 0; i < items.length; i++) {
var item = items[i];
console.log("--------------");
console.log(item);
// Create a new carousel item every `itemsPerSlide` items
if (currentItem % itemsPerSlide === 0) {
if (!isActive) carouselInner.append('</div>'); // Close previous carousel item
carouselInner.append('<div class="carousel-item' + (isActive ? ' active' : '') + '">');
isActive = false;
}
// Generate HTML for each item
var itemHtml = `
<div class="col-xl-3 col-md-6 d-inline-block scroll-item carousel-slide-item" data-client="${item.client_name}" data-branch="${item.branch_name}">
<div class="card" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);">
<div class="card-header add_card_background_random">
<div class="row">
<div class="col-8 emp-count-view-click">
<div class="d-flex justify-content-between">
<div class="w-100">
<h3 class="my-2 py-1">
<span data-plugin="counterup" style="font-size: 2.0rem;background-color: white;border-radius: 6px;height: 30;padding: 4px 11px 4px 11px;">${item.employee_count}</span>
</h3>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 emp-count-view-click">
<div class="d-flex justify-content-between">
<div class="w-100">
<h5 class="mt-0 text-truncate" title="Branch Info" style="font-weight: 400 !important;font-size: 20px !important;line-height: 36px;color: black !important;">${item.client_name} - ${item.branch_name}</h5>
</div>
</div>
</div>
</div>
</div>
<div class="card-body">
<!-- Add more details based on the item data -->
</div>
</div>
</div>
`;
carouselInner.find('.carousel-item.active').append(itemHtml);
currentItem++;
}
// Close the last carousel item if it was opened
if (currentItem % itemsPerSlide !== 0) carouselInner.append('</div>');
} else {
console.error('Expected an array for items, but got:', items);
}
} else if (typeof data.client_branch_emp_list === 'object') {
console.error('client_branch_emp_list is an object, not an array:', data.client_branch_emp_list);
} else {
console.error('client_branch_emp_list is missing or not in the expected format:', data.client_branch_emp_list);
}
// Initialize or refresh carousel if needed
$('#carouselExampleControls').carousel('dispose').carousel();
}
</script>