I am making a dashboard for online food ordering page. As a functionality I need to show total order sales amount per each day, categorized by payment methods when the user click a particular month. I am able to get the orders of the month and the payment method of each order and the order date but I cannot produce the actual functionality in Vanilla Js or in Vue.
The below images are showing what I tried and what I need to achieve. Please any suggestions.
Vue code
var app = new Vue({
el: '#app',
data: {
orders: [],
},
mounted: function() {
// Call the API the first time
this.refreshData()
},
computed: {
totals: function () {
return this.orders.reduce((acc, item) => {
const date = item.date.split('T')[0]
let dayTotal = acc.find(total => total.date === date)
if (!dayTotal) {
dayTotal = {
date,
}
acc.push(dayTotal)
}
dayTotal[item.method] = dayTotal[item.method] ? dayTotal[item.method] + item.total : item.total
return acc
}, [])
}
},
methods: {
// Extract refresh logic into a method
refreshData () {
axios.get('https://staging.testing/wp-json/wc/v3/orders?status=completed,processing&per_page=100&consumer_key=123&consumer_secret=456', {
params: {
after: convertdate,
before: convertbeforedate,
}
})
.then(response => {
this.orders = response.data;
console.log(response);
});
}
}
});