accounts of user

master
varun 3 years ago
parent ba972d0135
commit 15389802d8

@ -313,7 +313,8 @@ exports.amountUpdateByDeliveryBoy = async (req, reply) => {
const booking = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}); const booking = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId});
const tanker_price = parseInt(booking.price.replace(/,/g, ''), 10) const tanker_price = parseInt(booking.price.replace(/,/g, ''), 10)
const amount_due = tanker_price-amount_paid const amount_due = tanker_price-amount_paid
await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}, { $set: { amount_paid: amount_paid,amount_due:amount_due,payment_mode:payment_mode} }); const orderStatus = req.body.orderStatus
await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}, { $set: { amount_paid: amount_paid,amount_due:amount_due,payment_mode:payment_mode,orderStatus:orderStatus} });
const booking_data = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId}); const booking_data = await Tankerbooking.findOneAndUpdate({bookingid:req.params.bookingId});
const final_amount_due = parseInt(booking_data.amount_due.replace(/,/g, ''), 10) const final_amount_due = parseInt(booking_data.amount_due.replace(/,/g, ''), 10)
if(final_amount_due === 0){ if(final_amount_due === 0){
@ -326,3 +327,44 @@ exports.amountUpdateByDeliveryBoy = async (req, reply) => {
}; };
exports.userAccounts = async (req, reply) => {
try {
const booking = await Tankerbooking.find({customerId: req.params.customerId})
// console.log(booking)
let acceptedCount = 0;
let pendingRejectedCount = 0;
let deliveredCount = 0;
let deliveredTotalPrice = 0;
let deliveredTotalAmountPaid = 0;
let deliveredTotalAmountDue = 0;
for (let i = 0; i < booking.length; i++) {
let order = booking[i];
if (order.orderStatus === "accepted") {
acceptedCount++;
} else if (order.orderStatus === "pending" || order.orderStatus === "rejected") {
pendingRejectedCount++;
} else if (order.orderStatus === "delivered") {
deliveredCount++;
deliveredTotalPrice += parseInt(order.price.replace(/,/g, ''), 10)
deliveredTotalAmountPaid += parseInt(order.amount_paid.replace(/,/g, ''), 10)
deliveredTotalAmountDue += parseInt(order.amount_due.replace(/,/g, ''), 10)
}
}
console.log("Accepted orders count:", acceptedCount);
console.log("Pending or rejected orders count:", pendingRejectedCount);
console.log("Delivered orders count:", deliveredCount);
console.log("Delivered orders total price:", deliveredTotalPrice);
console.log("Delivered orders total amount paid:", deliveredTotalAmountPaid);
console.log("Delivered orders total amount due:", deliveredTotalAmountDue);
reply.send({ status_code: 200, count: booking.length, data: booking,acceptedCount:acceptedCount,pendingRejectedCount:pendingRejectedCount,deliveredCount:deliveredCount,deliveredTotalPrice:deliveredTotalPrice,deliveredTotalAmountPaid:deliveredTotalAmountPaid,deliveredTotalAmountDue:deliveredTotalAmountDue });
} catch (err) {
throw boom.boomify(err);
}
};

@ -279,7 +279,7 @@ module.exports = function (fastify, opts, next) {
amount_paid: { type: "string" }, amount_paid: { type: "string" },
payment_mode: { type: "string" }, payment_mode: { type: "string" },
orderStatus:{type:"string"}
}, },
}, },
security: [ security: [
@ -295,6 +295,35 @@ module.exports = function (fastify, opts, next) {
preHandler: fastify.auth([fastify.authenticate]), preHandler: fastify.auth([fastify.authenticate]),
handler: supplierOrderController.amountUpdateByDeliveryBoy, handler: supplierOrderController.amountUpdateByDeliveryBoy,
}); });
fastify.get("/api/userAccounts/:customerId", {
schema: {
tags: ["Supplier"],
description: "This is for Get accounts of user",
summary: "This is for to Get accounts of user",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
handler: supplierOrderController.userAccounts,
});
next(); next();
} }

Loading…
Cancel
Save