Skip to content

Instantly share code, notes, and snippets.

@markrowi
Last active September 2, 2022 01:09
Show Gist options
  • Select an option

  • Save markrowi/5595196d2563c549da39cb64acffb0b2 to your computer and use it in GitHub Desktop.

Select an option

Save markrowi/5595196d2563c549da39cb64acffb0b2 to your computer and use it in GitHub Desktop.
Food Panda Monthly Expense
getFoodPandaMonthExpense = (month, year) => {
const temp1 = document.querySelectorAll('.order-item-container')
const fpOrders = []
temp1.forEach(a =>
fpOrders.push([
a.querySelector('.order-date').textContent,
a.querySelector('.item-price').textContent,
a.querySelector('[data-testid=NEXTGEN_CART_SUBTOTAL]').textContent,
a.querySelector('.overlay-text')?.textContent
])
)
const fpO = fpOrders.map(o => [
o[0],
o[1],
o[2],
new Date(o[0]),
parseFloat(o[1].replace('₱ ', '')),
o[3]
])
console.log('================================')
const list = fpO.filter(
o => o[3].getUTCMonth() == month && o[3].getUTCFullYear() == year && !o[5]
)
const total = list.reduce((accumulator, a) => {
return accumulator + a[4]
}, 0)
list.forEach(i => console.log(i[0], ' - ', i[1]))
console.log('================================')
console.log('TOTAL: ', total.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','))
console.log('================================')
return [list, total]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment