Filter orders and sandwiches to have those paying
This commit is contained in:
parent
e4981ff5ef
commit
59005d8d6e
5 changed files with 30 additions and 18 deletions
|
@ -8,20 +8,25 @@ router.get("/", sessionCheck(2), async (req, res) => {
|
||||||
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
|
let date = req.query.date ? req.query.date : (new Date()).toISOString().substring(0,10);
|
||||||
|
|
||||||
let orders = {};
|
let orders = {};
|
||||||
for (let i of await models.SandwichOrder.findAll({where: {date: date}})) {
|
for (let o of await models.Order.findAll({
|
||||||
i.Order = await models.Order.findByPk(i.OrderId);
|
where: {paid: true},
|
||||||
i.Sandwich = await models.Sandwich.findByPk(i.SandwichName);
|
include: [{
|
||||||
let name = i.Order.firstName + " " + i.Order.lastName;
|
model: models.Sandwich,
|
||||||
|
through: {
|
||||||
|
where: {date: date}
|
||||||
|
},
|
||||||
|
required: true
|
||||||
|
}]
|
||||||
|
})) {
|
||||||
|
let name = o.firstName + " " + o.lastName;
|
||||||
|
|
||||||
if (!(i.Order.DepartmentName in orders))
|
if (!(o.DepartmentName in orders))
|
||||||
orders[i.Order.DepartmentName] = {};
|
orders[o.DepartmentName] = {};
|
||||||
|
|
||||||
if (!(name in orders[i.Order.DepartmentName]))
|
if (!(name in orders[o.DepartmentName]))
|
||||||
orders[i.Order.DepartmentName][name] = {};
|
orders[o.DepartmentName][name] = {};
|
||||||
|
|
||||||
if (!(i.Order.id in orders[i.Order.DepartmentName][name]))
|
orders[o.DepartmentName][name][o.id] = o.Sandwiches;
|
||||||
orders[i.Order.DepartmentName][name][i.Order.id] = [];
|
|
||||||
orders[i.Order.DepartmentName][name][i.Order.id].push(i);
|
|
||||||
}
|
}
|
||||||
res.render("orders", {title: "SOD - Orders", orders: orders, date: date});
|
res.render("orders", {title: "SOD - Orders", orders: orders, date: date});
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,7 @@ router.get("/", sessionCheck(0), async (req, res) => {
|
||||||
title: "SOD - Profile",
|
title: "SOD - Profile",
|
||||||
departments: await models.Department.findAll(),
|
departments: await models.Department.findAll(),
|
||||||
orders: await models.Order.findAll({
|
orders: await models.Order.findAll({
|
||||||
where: {UserUsername: req.session.user.username},
|
where: {UserUsername: req.session.user.username, paid: true},
|
||||||
include: models.Sandwich,
|
include: models.Sandwich,
|
||||||
order: ["date"]
|
order: ["date"]
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,10 +10,17 @@ router.get("/", sessionCheck(1), async (req, res) => {
|
||||||
|
|
||||||
res.render("sandwiches", {
|
res.render("sandwiches", {
|
||||||
title: "SOD - Sandwiches",
|
title: "SOD - Sandwiches",
|
||||||
sandwiches: await models.SandwichOrder.findAll({
|
sandwiches: await models.Sandwich.findAll({
|
||||||
attributes: ["SandwichName", [sequelize.fn("COUNT", sequelize.col("SandwichName")), "number"]],
|
attributes: ["name", [sequelize.fn("COUNT", sequelize.col("name")), "number"]],
|
||||||
where: {date: date},
|
include: [{
|
||||||
group: "SandwichName"
|
model: models.Order,
|
||||||
|
where: {paid: true},
|
||||||
|
through: {
|
||||||
|
where: {date: date}
|
||||||
|
},
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
group: "name"
|
||||||
}),
|
}),
|
||||||
date: date});
|
date: date});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,6 +17,6 @@ block content
|
||||||
h4 #{__("order")} N°#{id}
|
h4 #{__("order")} N°#{id}
|
||||||
each sandwich in order
|
each sandwich in order
|
||||||
div.sandwich
|
div.sandwich
|
||||||
h4= sandwich.Sandwich.name
|
h4= sandwich.name
|
||||||
|
|
||||||
script(src="/javascripts/orders.js")
|
script(src="/javascripts/orders.js")
|
||||||
|
|
|
@ -8,6 +8,6 @@ block content
|
||||||
h1=__("sandwiches")
|
h1=__("sandwiches")
|
||||||
each sandwich in sandwiches
|
each sandwich in sandwiches
|
||||||
div.sandwich
|
div.sandwich
|
||||||
h2 #{sandwich.SandwichName}: #{sandwich.dataValues.number}
|
h2 #{sandwich.name}: #{sandwich.dataValues.number}
|
||||||
|
|
||||||
script(src="/javascripts/sandwiches.js")
|
script(src="/javascripts/sandwiches.js")
|
||||||
|
|
Reference in a new issue