|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
|
|
|
|
|
const { Tanker, Tankerbooking,Bore,GovtPipeLine,UserSupplierAccounts } = require('../models/tankers')
|
|
|
|
|
const { User,Counter, generateBookingId,resetCounter,generateCustomerId } = require('../models/User')
|
|
|
|
|
|
|
|
|
|
const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
|
|
|
|
@ -674,3 +674,96 @@ exports.deleteBookingInfo = async (req, reply) => {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.distrubanceStatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const bookingid = req.params.bookingid;
|
|
|
|
|
const action = req.body.action
|
|
|
|
|
const booking = await Tankerbooking.findOne({ bookingid:bookingid });
|
|
|
|
|
const distrubance_price = parseInt(booking.distrubance_price .replace(/,/g, ''), 10)
|
|
|
|
|
const actual_price = parseInt(booking.actual_price.replace(/,/g, ''), 10)
|
|
|
|
|
const amount_due = parseInt(booking.amount_due .replace(/,/g, ''), 10)
|
|
|
|
|
const price_variation = actual_price-distrubance_price
|
|
|
|
|
if (action === "accept") {
|
|
|
|
|
await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: actual_price,amount_difference:"0" } });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (action === "reject") {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: distrubance_price,amount_difference:"0" } });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: booking});
|
|
|
|
|
// return tank;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.UserSupplierAccounts = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
const supplierId = req.body.supplierId
|
|
|
|
|
const booking = await Tankerbooking.find({ customerId:customerId,supplierId:supplierId,orderStatus:"delivered"});
|
|
|
|
|
const delivered_tankers = booking.length
|
|
|
|
|
console.log(delivered_tankers, booking.length)
|
|
|
|
|
let amount_due = 0
|
|
|
|
|
let amount_advance = 0
|
|
|
|
|
let TotalAmountPaid = 0
|
|
|
|
|
for (let i = 0; i < booking.length; i++) {
|
|
|
|
|
let order = booking[i];
|
|
|
|
|
|
|
|
|
|
TotalAmountPaid += parseInt(order.amount_paid.replace(/,/g, ''), 10)
|
|
|
|
|
amount_due += parseInt(order.amount_due.replace(/,/g, ''), 10)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log("TotalAmountPaid:", TotalAmountPaid);
|
|
|
|
|
console.log("amount_due:", amount_due);
|
|
|
|
|
|
|
|
|
|
const user_accounts = await UserSupplierAccounts.findOne({ customerId:customerId,supplierId:supplierId });
|
|
|
|
|
if (user_accounts) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await UserSupplierAccounts.findOneAndUpdate({ customerId:customerId,supplierId:supplierId }, { $set: { amount_due: amount_due,amount_paid:TotalAmountPaid,delivered_tankers:delivered_tankers } });
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
|
|
UserSupplierData = {
|
|
|
|
|
customerId:customerId,
|
|
|
|
|
supplierId: supplierId,
|
|
|
|
|
amount_due: amount_due,
|
|
|
|
|
amount_paid: TotalAmountPaid,
|
|
|
|
|
amount_advance: amount_advance,
|
|
|
|
|
delivered_tankers:delivered_tankers
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var user_supplier_accounts = new UserSupplierAccounts(UserSupplierData);
|
|
|
|
|
|
|
|
|
|
checkFormEncoding = isUserFormUrlEncoded(req);
|
|
|
|
|
if (checkFormEncoding.isUserFormUrlEncoded) {
|
|
|
|
|
|
|
|
|
|
user_supplier_accounts.customerId = customerId
|
|
|
|
|
user_supplier_accounts.supplierId = supplierId;
|
|
|
|
|
user_supplier_accounts.amount_due = amount_due;
|
|
|
|
|
user_supplier_accounts.amount_paid = TotalAmountPaid;
|
|
|
|
|
user_supplier_accounts.amount_advance = amount_advance;
|
|
|
|
|
user_supplier_accounts.delivered_tankers = delivered_tankers;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const inserteduser_supplier_accounts_data = await user_supplier_accounts.save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
reply.send({ status_code: 200, count: booking.length, data: booking,TotalAmountPaid:TotalAmountPaid,amount_due:amount_due });
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|