|
if (type == "available") { |
|
let previous_months_count = 0; |
|
|
|
entry.forEach((element) => { |
|
let search_month = new Date(element.date).toLocaleDateString() |
|
let start_month_modified = new Date(new Date(start_date).getFullYear(), new Date(start_date).getMonth(), 1).toLocaleDateString() |
|
let end_month_modified = new Date(new Date(end_date).getFullYear(), new Date(end_date).getMonth() + 1, 0).toLocaleDateString() |
|
|
|
if ( |
|
new Date(search_month) >= new Date(start_month_modified) && |
|
new Date(search_month) <= new Date(end_month_modified) && |
|
element.type == type |
|
) { |
|
filter_data.push(month[new Date(element.date).getMonth()]); |
|
} |
|
|
|
if ( |
|
new Date(search_month) < new Date(start_month_modified) && |
|
element.type == type |
|
) { |
|
previous_months_count += 1; |
|
} |
|
}); |
|
|
|
let data = {}; |
|
|
|
filter_data.forEach((element) => { |
|
data[element] = (data[element] || 0) + 1; |
|
}); |
|
|
|
let result = Object.keys(data).sort(function (a, b) { |
|
return month.indexOf(a) > month.indexOf(b); |
|
}).map((key, index, array) => { |
|
previous_months_count += (data[array[index - 1]] || 0) |
|
return [key, data[key] + previous_months_count]; |
|
}); |
|
|
|
return result; |
|
} else { |