From 79622d4f22b02381535924b2480fade02dabd7c0 Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Wed, 26 Apr 2023 15:29:10 +0530 Subject: [PATCH] order - delivered,cancel,pending apis --- src/controllers/supplierOrderController.js | 134 +++++++++++ src/routes/supplierOrdersRoutes.js | 247 +++++++++++++++++++++ 2 files changed, 381 insertions(+) diff --git a/src/controllers/supplierOrderController.js b/src/controllers/supplierOrderController.js index e7d77c18..e848a2d2 100644 --- a/src/controllers/supplierOrderController.js +++ b/src/controllers/supplierOrderController.js @@ -392,6 +392,49 @@ exports.userAccounts = async (req, reply) => { +exports.userAccountsofparticularSupplier = async (req, reply) => { + try { + + const booking = await Tankerbooking.find({customerId: req.params.customerId,supplierId: req.body.supplierId,}) + 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); + } +}; + + + exports.supplierAccounts = async (req, reply) => { @@ -478,3 +521,94 @@ exports.tankerAccounts = async (req, reply) => { } }; + +exports.getAllOrderaccepted = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["accepted"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getAllOrderdelivered = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["delivered"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + + +exports.getAllOrderreject = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["rejected"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getAllOrderpending = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const customerId = req.params.customerId + try { + await Tankerbooking.find({ customerId: customerId, orderStatus: ["pending"]}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; + +exports.getBillingInfo = async (req, reply) => { + const limit = parseInt(req.query.limit) || 100; + const page = parseInt(req.query.page) || 1; + const startindex = (page - 1) * limit; + const bookingId = req.params.bookingId; + try { + await Tankerbooking.findOne({ bookingid: bookingId}) + .limit(limit) + .skip(startindex) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + } catch (err) { + reply.status(400).send({ message: err.message }); + } +}; \ No newline at end of file diff --git a/src/routes/supplierOrdersRoutes.js b/src/routes/supplierOrdersRoutes.js index 029906a8..76e59002 100644 --- a/src/routes/supplierOrdersRoutes.js +++ b/src/routes/supplierOrdersRoutes.js @@ -326,6 +326,42 @@ module.exports = function (fastify, opts, next) { + + // fastify.get("/api/userAccountsofparticularSupplier/:customerId", { + // schema: { + // tags: ["Supplier-Order"], + // description: "This is for Get accounts of user for particular supplier", + // summary: "This is for to Get accounts of user for particular supplier", + // params: { + // required: ["customerId"], + // type: "object", + // properties: { + // customerId: { + // type: "string", + // description: "customerId", + // }, + // }, + // }, + // body: { + // type: "object", + // properties: { + + // supplierId:{type:"string"} + // }, + // }, + // security: [ + // { + // basicAuth: [], + // }, + // ], + // }, + // preHandler: fastify.auth([fastify.authenticate]), + // handler: supplierOrderController.userAccountsofparticularSupplier, + // }); + + + + fastify.get("/api/supplierAccounts/:supplierId", { schema: { tags: ["Supplier"], @@ -393,6 +429,217 @@ module.exports = function (fastify, opts, next) { }); + fastify.route({ + method: "GET", + url: "/api/accepted/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order pending for delivery", + summary: "This is for Get All order pending for delivery", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderaccepted, + + }); + fastify.route({ + method: "GET", + url: "/api/rejected/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order cancelled", + summary: "This is for Get All order cancelled", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderreject, + + }); + + fastify.route({ + method: "GET", + url: "/api/delivered/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order Delivered", + summary: "This is for Get All order Delivered", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderdelivered, + + }); + fastify.route({ + method: "GET", + url: "/api/pendingconformation/:customerId", + schema: { + tags: ["Supplier-Order"], + description:"This is for Get All order Pending for confirmation", + summary: "This is for Get All order pending for confirmation", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.getAllOrderpending, + + }); + + // fastify.route({ + // method: "GET", + // url: "/api/billing/:bookingId", + // schema: { + // tags: ["Supplier-Order"], + // description:"This is for Get Billing Information", + // summary: "This is for Get Billing Information", + // params: { + // required: ["bookingId"], + // type: "object", + // properties: { + // bookingId: { + // type: "string", + // description: "bookingId", + // }, + // }, + // }, + + // security: [ + // { + // basicAuth: [], + // }, + // ], + + // }, + // handler:supplierOrderController.getBillingInfo, + + // }); + + fastify.route({ + method: "GET", + url: "/api/billinginfo/:bookingId", + schema: { + tags: ["Supplier-Order"], + description:"This is for giving booking data billing information", + summary: "This is for giving booking data billing information", + params: { + required: ["bookingId"], + type: "object", + properties: { + bookingId: { + type: "string", + description: "bookingId", + }, + }, + }, + + security: [ + { + basicAuth: [], + }, + ], + + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler:supplierOrderController.getBillingInfo, + // onResponse: (request, reply) => { + // validationHandler.sendPhoneVerificationCode(request, reply); + // }, + //onResponse: validationHandler.sendPhoneVerificationCode, + }); + + fastify.route({ + method: "GET", + url: "/api/userAccountsofparticularSupplier/:customerId", + schema: { + tags: ["Supplier-Order"], + description: "This is for Get accounts of user for particular supplier", + summary: "This is for to Get accounts of user for particular supplier", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + body: { + type: "object", + //required: ["customerId"], + properties: { + supplierId : { type : "string"} + }, + }, + security: [ + { + basicAuth: [], + }, + ], + + }, + handler:supplierOrderController.userAccountsofparticularSupplier, + + }); + next(); }