@ -3,6 +3,7 @@
const { Supplier , generateSupplierId , FriendRequest , DeliveryBoy } = require ( "../models/supplier" )
const { Tank } = require ( '../models/tanks' )
const http = require ( 'https' ) ;
const boom = require ( "boom" ) ;
const fastify = require ( "fastify" ) ( {
@ -10,6 +11,53 @@ const fastify = require("fastify")({
} ) ;
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 ) => {
@ -18,6 +66,7 @@ exports.orderNow = async (req, reply) => {
const bookingId = req . params . bookingId ;
const tankerName = req . body . tankerName ;
const booking _info = await Tankerbooking . findOne ( { bookingid : bookingId } )
const action = req . body . action
const typeofwater = req . body . typeofwater
const expectedDateOfDelivery = req . body . expectedDateOfDelivery ;
@ -27,6 +76,11 @@ exports.orderNow = async (req, reply) => {
const delivery _agent = req . body . delivery _agent
const agent _mobile = req . body . agent _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 . delivery _agent = delivery _agent
booking _info . delivery _agent _mobile = agent _mobile
@ -203,6 +257,9 @@ exports.deliveryboystartandstop = async (req, reply) => {
//let start_time,stop_time
const bookingId = req . params . 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")
@ -297,8 +354,9 @@ exports.deliveryboystartandstop = async (req, reply) => {
const start _water _level = parseInt ( booking _data . initial _water _level . replace ( /,/g , '' ) , 10 )
const quantity _delivered = final _receiver _waterlevel - start _water _level
await Tankerbooking . findOneAndUpdate ( { bookingid : bookingId } , { $set : { final _water _level : final _receiver _waterlevel , stop _time : stop _time , quantityDelivered : quantity _delivered , tankerRunningStatus : "0" } } ) ;
const distrubance _price = parseInt ( quantity _delivered . replace ( /,/g , '' ) , 10 ) * price _per _liter
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 } ) ;
} else {
throw new Error ( "Invalid action" ) ;