Bhaskara Kishore 2 years ago
commit 64741326e5

@ -135,6 +135,7 @@ exports.loginDeliveryBoy = async (req) => {
supplier.description = suppliertobeInserted.description supplier.description = suppliertobeInserted.description
} }
console.log("---------checkurl ecnoded string-----------------------"); console.log("---------checkurl ecnoded string-----------------------");
// Store hash in your password DB. // Store hash in your password DB.

@ -3,6 +3,7 @@
const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier") const { Supplier, generateSupplierId, FriendRequest,DeliveryBoy} = require("../models/supplier")
const { Tank } = require('../models/tanks') const { Tank } = require('../models/tanks')
const http = require('https');
const boom = require("boom"); const boom = require("boom");
const fastify = require("fastify")({ const fastify = require("fastify")({
@ -10,6 +11,54 @@ const fastify = require("fastify")({
}); });
const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers') const { Tanker, Tankerbooking,Bore,GovtPipeLine } = require('../models/tankers')
exports.orderStartedSms = async (request, reply) => {
//console.log(bookingId,supplierContact,deliveryAgentContact,mobile)
const bookingId = request.params.bookingId;
const booking_data = await Tankerbooking.findOne({ bookingid: bookingId})
console.log(booking_data)
const supplierContact = booking_data.supplierPhone
const deliveryAgentContact = booking_data.delivery_agent_mobile
const user_name = booking_data.customerName
const mobile = booking_data.customerPhone
const username = 'Arminta';
const apiKey = '2068323bea61494d315b';
const senderId = 'ARMNTA';
const message = `Hello ${user_name}, We are pleased to inform you that your booking with bookingId ${bookingId} has been started,you can track the current location of tanker here {#var#}. Please note that the supplier's contact number is ${supplierContact} and deliver agent contact number is ${deliveryAgentContact} Thank you for choosing our services. If you have any further questions or concerns, please do not hesitate to contact us. Best regards, Arminta Water Services`;
const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`;
const options = {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
const req = http.request(apiUrl, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
console.log(req)
res.on('end', () => {
reply.send(data);
});
});
req.on('error', (error) => {
console.error(error);
reply.send({ error: 'Failed to send SMS' });
});
req.end();
}
exports.orderNow = async (req, reply) => { exports.orderNow = async (req, reply) => {
@ -18,6 +67,7 @@ exports.orderNow = async (req, reply) => {
const bookingId = req.params.bookingId; const bookingId = req.params.bookingId;
const tankerName = req.body.tankerName; const tankerName = req.body.tankerName;
const booking_info = await Tankerbooking.findOne({ bookingid: bookingId}) const booking_info = await Tankerbooking.findOne({ bookingid: bookingId})
const action = req.body.action const action = req.body.action
const typeofwater = req.body.typeofwater const typeofwater = req.body.typeofwater
const expectedDateOfDelivery = req.body.expectedDateOfDelivery; const expectedDateOfDelivery = req.body.expectedDateOfDelivery;
@ -27,6 +77,11 @@ exports.orderNow = async (req, reply) => {
const delivery_agent = req.body.delivery_agent const delivery_agent = req.body.delivery_agent
const agent_mobile = req.body.agent_mobile const agent_mobile = req.body.agent_mobile
const agent_alternative_mobile = req.body.agent_alternative_mobile const agent_alternative_mobile = req.body.agent_alternative_mobile
const booking_data = await Tankerbooking.findOne({ bookingid: bookingId})
const supplierContact = booking_data.supplierPhone
const deliveryAgentContact = agent_mobile
const mobile = booking_data.customerPhone
// hash = await orderStartedSms(bookingId,supplierContact,deliveryAgentContact,mobile);
booking_info.orderStatus = "accepted" booking_info.orderStatus = "accepted"
booking_info.delivery_agent = delivery_agent booking_info.delivery_agent = delivery_agent
booking_info.delivery_agent_mobile = agent_mobile booking_info.delivery_agent_mobile = agent_mobile
@ -203,6 +258,9 @@ exports.deliveryboystartandstop = async (req, reply) => {
//let start_time,stop_time //let start_time,stop_time
const bookingId = req.params.bookingId const bookingId = req.params.bookingId
const bookingdata = await Tankerbooking.findOne({bookingid: bookingId}) const bookingdata = await Tankerbooking.findOne({bookingid: bookingId})
const ordered_quantity = parseInt((bookingdata.capacity).replace(/,/g, ''), 10)
const price = parseInt((bookingdata.price).replace(/,/g, ''), 10)
const price_per_liter = ordered_quantity/price
// console.log(bookingdata.supplierId,"6") // console.log(bookingdata.supplierId,"6")
@ -297,8 +355,9 @@ exports.deliveryboystartandstop = async (req, reply) => {
const start_water_level = parseInt(booking_data.initial_water_level.replace(/,/g, ''), 10) const start_water_level = parseInt(booking_data.initial_water_level.replace(/,/g, ''), 10)
const quantity_delivered = final_receiver_waterlevel-start_water_level const quantity_delivered = final_receiver_waterlevel-start_water_level
const distrubance_price = parseInt(quantity_delivered.replace(/,/g, ''), 10)*price_per_liter
await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { final_water_level: final_receiver_waterlevel ,stop_time:stop_time,quantityDelivered:quantity_delivered,tankerRunningStatus:"0"} }); const amount_difference = price - distrubance_price
await Tankerbooking.findOneAndUpdate({bookingid:bookingId}, { $set: { final_water_level: final_receiver_waterlevel ,stop_time:stop_time,quantityDelivered:quantity_delivered,distrubance_price:distrubance_price,amount_difference:amount_difference,tankerRunningStatus:"0"} });
reply.send({ status_code: 200, "stop time": stop_time,"final water level":final_receiver_waterlevel}); reply.send({ status_code: 200, "stop time": stop_time,"final water level":final_receiver_waterlevel});
} else { } else {
throw new Error("Invalid action"); throw new Error("Invalid action");

@ -681,11 +681,11 @@ exports.distrubanceStatus = async (req, reply) => {
const action = req.body.action const action = req.body.action
const booking = await Tankerbooking.findOne({ bookingid:bookingid }); const booking = await Tankerbooking.findOne({ bookingid:bookingid });
const distrubance_price = parseInt(booking.distrubance_price .replace(/,/g, ''), 10) const distrubance_price = parseInt(booking.distrubance_price .replace(/,/g, ''), 10)
const actual_price = parseInt(booking.actual_price.replace(/,/g, ''), 10) const price = parseInt(booking.price.replace(/,/g, ''), 10)
const amount_due = parseInt(booking.amount_due .replace(/,/g, ''), 10) const amount_due = parseInt(booking.amount_due .replace(/,/g, ''), 10)
const price_variation = actual_price-distrubance_price const price_variation = price-distrubance_price
if (action === "accept") { if (action === "accept") {
await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: actual_price,amount_difference:"0" } }); await Tankerbooking.findOneAndUpdate({ bookingid:bookingid }, { $set: { amount_due: price,amount_difference:"0" } });
} }
if (action === "reject") { if (action === "reject") {
@ -695,6 +695,7 @@ exports.distrubanceStatus = async (req, reply) => {
} }
reply.send({ status_code: 200, data: booking}); reply.send({ status_code: 200, data: booking});
// return tank; // return tank;
} catch (err) { } catch (err) {

@ -331,6 +331,7 @@ exports.motorAction = async (req, reply) => {
// } // }
if(supplier_tank_type==="bore" && receiver_type === "sump"){ if(supplier_tank_type==="bore" && receiver_type === "sump"){
const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10) const receiver_capacity = parseInt(receiver_tank_info.capacity.replace(/,/g, ''), 10)
// console.log(receiver_capacity,"0",receiver_tank_info.tankName) // console.log(receiver_capacity,"0",receiver_tank_info.tankName)
@ -474,7 +475,7 @@ exports.calculateCapacity = async (req, reply) => {
return { message: 'success' }; return { message: 'success' };
} }
if(shape==="horizontalcylinder"){ if(shape==="cylinder"){
console.log("hii1") console.log("hii1")
const { length,diameter } = req.body const { length,diameter } = req.body
@ -495,28 +496,8 @@ exports.calculateCapacity = async (req, reply) => {
return { message: 'success' }; return { message: 'success' };
} }
if(shape==="verticalcylinder"){
console.log("hii2") if(shape==="oval"){
const { height,diameter } = req.body
// Ensure all parameters are valid numbers
if (isNaN(height) || isNaN(diameter)) {
reply.code(400).send('Invalid input parameters')
return
}
// Calculate the capacity of the water tank in liters
const radius = diameter / 2
const volume = Math.PI * Math.pow(radius, 2) * height
const capacity = volume * 1000
reply.send({ status_code: 200, capacity: capacity});
return { message: 'success' };
}
if(shape==="horizontaloval"){
console.log("hii3") console.log("hii3")
const { length, width, height } = req.body const { length, width, height } = req.body
@ -543,32 +524,6 @@ exports.calculateCapacity = async (req, reply) => {
} }
if(shape=== "verticaloval"){
console.log("hii4")
const { length, width, height } = req.body
// Ensure all parameters are valid numbers
if (isNaN(length) || isNaN(width) || isNaN(height)) {
reply.code(400).send('Invalid input parameters')
return
}
// Calculate the capacity of the water tank in liters
const radius = width / 2
const a = height - width
const area = Math.PI * radius * radius + 2 * radius * a
const volume = area * length
const capacity = volume * 1000
// Format the result with two decimal places and comma-separated thousands
const formattedCapacity = capacity.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
reply.send({ status_code: 200, capacity: formattedCapacity});
return { message: 'success' };
}
if(shape==="horizontalellipse"){ if(shape==="horizontalellipse"){
const { length, width, height } = req.body const { length, width, height } = req.body

@ -424,6 +424,7 @@ exports.sendSms = async (request, reply) => {
const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`; const apiUrl = `https://smslogin.co/v3/api.php?username=${username}&apikey=${apiKey}&senderid=${senderId}&mobile=${mobile}&message=${encodeURIComponent(message)}`;
const options = { const options = {
method: 'GET', method: 'GET',
headers: { headers: {

@ -29,6 +29,7 @@ const tankersSchema = new mongoose.Schema({
}); });
const tankersbookingSchema = new mongoose.Schema({ const tankersbookingSchema = new mongoose.Schema({
customerId: { type: String, default: null }, customerId: { type: String, default: null },
@ -44,7 +45,7 @@ const tankersbookingSchema = new mongoose.Schema({
typeofwater: { type: String, default: null }, typeofwater: { type: String, default: null },
capacity: { type: String, default: null }, capacity: { type: String, default: null },
address: { type: String, default: null }, address: { type: String, default: null },
actual_price: { type: String, default: "750" }, price: { type: String, default: null },
payment_status : { type: String, default: "due" }, payment_status : { type: String, default: "due" },
orderStatus: { type: String, default: "pending" }, orderStatus: { type: String, default: "pending" },
delivery_agent : { type: String, default: "null" }, delivery_agent : { type: String, default: "null" },

@ -57,6 +57,45 @@ module.exports = function (fastify, opts, next) {
//onResponse: validationHandler.sendPhoneVerificationCode, //onResponse: validationHandler.sendPhoneVerificationCode,
}); });
fastify.route({
method: "POST",
url: "/api/orderStartedSms/:bookingId",
schema: {
tags: ["Supplier-Order"],
description:"This is for giving booking data to user through sms",
summary: "This is for giving booking data to user through sms",
params: {
required: ["bookingId"],
type: "object",
properties: {
bookingId: {
type: "string",
description: "bookingId",
},
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: fastify.auth([fastify.authenticate]),
handler:supplierOrderController.orderStartedSms,
// onResponse: (request, reply) => {
// validationHandler.sendPhoneVerificationCode(request, reply);
// },
//onResponse: validationHandler.sendPhoneVerificationCode,
});
fastify.route({ fastify.route({
method: "POST", method: "POST",
url: "/api/addDeliveryboys/:supplierId", url: "/api/addDeliveryboys/:supplierId",
@ -110,6 +149,7 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/getsupplierbookings/:supplierId", { fastify.get("/api/getsupplierbookings/:supplierId", {
schema: { schema: {
tags: ["Supplier"], tags: ["Supplier"],

@ -382,6 +382,7 @@ module.exports = function (fastify, opts, next) {
handler: validationHandler.deleteDeliveryBoy, handler: validationHandler.deleteDeliveryBoy,
}); });
fastify.route({ fastify.route({
method: "PUT", method: "PUT",

@ -793,6 +793,7 @@ module.exports = function (fastify, opts, next) {
}, },
}, },
security: [ security: [
{ {
basicAuth: [], basicAuth: [],

@ -432,6 +432,7 @@ module.exports = function (fastify, opts, next) {
handler: tanksController.checkStatusofIot, handler: tanksController.checkStatusofIot,
}); });
fastify.route({ fastify.route({
method: 'GET', method: 'GET',
url: '/waterlevel-sum', url: '/waterlevel-sum',

@ -230,6 +230,7 @@ module.exports = function (fastify, opts, next) {
validationHandler.sendPasswordResetCode(request, reply); validationHandler.sendPasswordResetCode(request, reply);
}, },
}); });
fastify.route({ fastify.route({
method: "POST", method: "POST",

Loading…
Cancel
Save