Display monthly product consumption
Create a list of all the products purchased per month and the amount that has being purchased of each product. This should be a new page available to every member in the Almacen menu.
We can use /api/transaction?type=purchase
and aggregate them in the javascript side, this call returns a json list like:
[
{
"ID": 42,
"member": {
"num": 900,
"login": "admin",
"name": "Administradora"
},
"date": "2021-03-22T12:55:35.753991252+01:00",
"total": -1129,
"type": "purchase",
"purchase": [
{
"code": 135,
"product": {
"code": 135,
"name": "tomates",
"price": 1129,
"stock": 20
},
"price": 1129,
"amount": 1
}
]
},
{
"ID": 39,
"member": {
"num": 900,
"login": "admin",
"name": "Administradora"
},
"date": "2021-03-16T22:14:10.210364833+01:00",
"total": -1243,
"type": "purchase",
"purchase": [
{
"code": 135,
"product": {
"code": 135,
"name": "tomates"
},
"price": 1129,
"amount": 1
},
{
"code": 112,
"product": {
"code": 112,
"name": "arroz"
},
"price": 114,
"amount": 1
}
]
}
]
Prices are in cents, so 114 means 1.14 euros. See that there is a conversion function in src/util.js.
Edited by meskio