|
|
@ -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,89 @@ 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.supplierAccounts = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const booking = await Tankerbooking.find({supplierId: req.params.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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|