Skip to content

Commit

Permalink
Program dashboard:sorted the client booking trends chart on filter in…
Browse files Browse the repository at this point in the history
… ASC
  • Loading branch information
Ronald-pro committed Dec 14, 2023
1 parent 32c660f commit 8419ca9
Showing 1 changed file with 69 additions and 46 deletions.
115 changes: 69 additions & 46 deletions resources/views/dashboard/program.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,36 @@ function fetchData2() {
type: 'GET',
data: {
"months": months,
"year":year
"year": year
},
url: "{{ route('program_filter') }}",
success: function(data) {
createChart(data);
createChart2(data);
var listdata = data.program;
var maxMonths = listdata.reduce(function(max, site) {
return site.Months > max ? site.Months : max;
}, '');
// finding the filtered maximum Months value
function parseMonthYear(dateString) {
var parts = dateString.split('-');
if (parts.length === 2) {
var month = parseInt(parts[0], 10);
var year = parseInt(parts[1], 10);
if (!isNaN(month) && !isNaN(year)) {
return new Date(year, month - 1);
}
}
return null;
}
var maxDate = listdata.reduce(function(max, site) {
var currentDate = parseMonthYear(site.Months);
return currentDate > max ? currentDate : max;
}, new Date(0));
var list = listdata.filter(function(site) {
return site.Months === maxMonths;
var currentDate = parseMonthYear(site.Months);
return currentDate && currentDate.getTime() === maxDate.getTime();
});
console.log(list);
var table = $j('#table_client').DataTable();
// Destroy the DataTable instance
Expand Down Expand Up @@ -338,7 +354,13 @@ function fetchData2() {
}
function createChart(jsonData) {
const processedData = jsonData.program.reduce((accumulator, item) => {
const sortedProgramData = jsonData.program.sort((a, b) => {
const dateA = new Date(a.LastDateUsed);
const dateB = new Date(b.LastDateUsed);
return dateA - dateB;
});
const processedData = sortedProgramData.reduce((accumulator, item) => {
if (item.MonthYear && item.num_clients) {
const monthYear = item.MonthYear;
accumulator[monthYear] = (accumulator[monthYear] || 0) + item.num_clients;
Expand All @@ -351,6 +373,7 @@ function createChart(jsonData) {
y: processedData[monthYear]
}));
Highcharts.chart('client_chart', {
chart: {
type: 'column',
Expand Down Expand Up @@ -390,47 +413,47 @@ function createChart(jsonData) {
}
function createChart2(jsonData) {
const monthYearSum = jsonData.active_site.reduce((accumulator, item) => {
if (item.MonthYear) {
accumulator[item.MonthYear] = (accumulator[item.MonthYear] || 0) + item.num_sites;
}
return accumulator;
}, {});
const seriesData = Object.keys(monthYearSum).map(monthYear => ({
name: monthYear,
y: monthYearSum[monthYear]
}));
Highcharts.chart('site-chart', {
chart: {
type: 'column'
},
title: {
text: 'Active Sites the last 6 Months',
style: {
fontFamily: 'Inter',
fontSize: '14px'
const monthYearSum = jsonData.active_site.reduce((accumulator, item) => {
if (item.MonthYear) {
accumulator[item.MonthYear] = (accumulator[item.MonthYear] || 0) + item.num_sites;
}
},
xAxis: {
categories: Object.keys(monthYearSum),
title: {
text: 'MonthYear'
}
},
yAxis: {
return accumulator;
}, {});
const seriesData = Object.keys(monthYearSum).map(monthYear => ({
name: monthYear,
y: monthYearSum[monthYear]
}));
Highcharts.chart('site-chart', {
chart: {
type: 'column'
},
title: {
text: 'No of Sites'
}
},
series: [{
name: 'No of Sites',
color: '#01058A',
data: seriesData
}]
});
}
text: 'Active Sites the last 6 Months',
style: {
fontFamily: 'Inter',
fontSize: '14px'
}
},
xAxis: {
categories: Object.keys(monthYearSum),
title: {
text: 'MonthYear'
}
},
yAxis: {
title: {
text: 'No of Sites'
}
},
series: [{
name: 'No of Sites',
color: '#01058A',
data: seriesData
}]
});
}
// Fetch data when the page loads
fetchData();
Expand Down

0 comments on commit 8419ca9

Please sign in to comment.