-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `bookingc_cabs`
--

DELIMITER $$
--
-- Procedures
--
CREATE DEFINER=`root`@`localhost` PROCEDURE `accept_booking_status` (IN `booking_id` INT, IN `id` INT)  NO SQL BEGIN
update booking_stack SET booking_stack.`status`='A',last_try = Now() WHERE booking_id=booking_id;
INSERT INTO `booking_register`(`bookingid`,`driverId`,`updateOn`,`status`,`type`) VALUES(booking_id,id,Now(),'A','By Un-Assigned Booking');
UPDATE driver SET `status`=1 WHERE user_id = id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `booking_travel_detail` (IN `booking_id` INT)   BEGIN
SELECT driver_location.booking_id as bookingId,
(SELECT DATE_FORMAT(time,'%Y-%m-%d %H:%i:%s') as time FROM booking_logs WHERE status = 7 AND bookingid = booking_id) as strtTime,
(SELECT DATE_FORMAT(datetime,'%Y-%m-%d %H:%i:%s') as time FROM driver_location WHERE booking_id = booking_id order by booking_id desc limit 0,1 ) as endTime,
(Select distance from driver_location where booking_id = booking_id order by driver_location.id desc limit 0,1) as distance,
driver_location.duration,   
driver_location.pre_Waiting_time,
driver_location.WaitingTime,
driver_location.start_latitude,
driver_location.start_longitude,
TIMEDIFF( DATE_FORMAT(booking_estimation.estimated_time,"%H:%i:%s"),TIMEDIFF(
    (SELECT DATE_FORMAT(time,'%H:%i:%s') as time FROM booking_logs WHERE status = 8 AND bookingid = booking_id),
    (SELECT DATE_FORMAT(time,'%H:%i:%s') as time FROM booking_logs WHERE status = 7 AND bookingid = booking_id)
)) as delay_time,
DATE_FORMAT(booking_pickdrop_details.pickup_date,'%Y-%m-%d') as pickup_date ,
DATE_FORMAT(booking_pickdrop_details.pickup_time,"%H:%i:%s") as pickup_time,
booking_estimation.*
from driver_location
left join booking_estimation ON driver_location.booking_id =booking_estimation.booking_id 
left join booking_pickdrop_details ON booking_estimation.booking_id  = booking_pickdrop_details.booking_id
where driver_location.booking_id = booking_id
order by driver_location.id desc limit 0,1;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_agent_work_history` (IN `user_id` INT, IN `driver_id` INT, IN `mobile` VARCHAR(50), IN `booking_ref` VARCHAR(50), IN `reason_text` VARCHAR(100))   BEGIN
INSERT INTO `agent_work_history`(`AgentID`,`CallerId`,`BookingID`,`ActionType`,`Date`,`ActionDesc`) VALUES(user_id,mobile,booking_ref,'Cancellation',Now(),reason_text);
UPDATE driver SET `status`= 0 WHERE `user_id` = driver_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_assign_booking` (IN `driver` INT, IN `booking` TEXT)   BEGIN
DECLARE dno int;
DECLARE bno int;
DECLARE lno int;
DECLARE tno int;
SELECT COUNT(*) into lno FROM user WHERE id=driver and loginstatus=1;
SELECT COUNT(*) into tno FROM cab_booking WHERE CONCAT(pickupdate,' ',pickuptime)>NOW();
IF dno>0 and bno>0 and lno>0 and tno>0
THEN 
UPDATE cab_booking SET pickup=driver WHERE booking_reference=booking;
END IF;
SELECT dno,bno,lno,tno;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_a_client_booking` (IN `client_id` INT)   BEGIN
SELECT booking_charges.totalBill AS amount,(booking_charges.totalBill*booking_charges.companyshare/100) 
AS cAmount,(booking_charges.totalBill*booking_charges.drivershare/100) AS dAmount,
(booking_charges.totalBill*booking_charges.partnershare/100) AS pAmount,
booking_charges.companyshare AS cshare,booking_charges.drivershare AS dshare,
booking_charges.partnershare AS pshare,complaint.ID as com_id,
complaint.StatusID as com_status, cab_booking.csr_id as emp,
CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.id as id,
booking_charges.totalBill, cab_booking.booking_reference as ref,
master_package.master_package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,
vehicle_type.vehicle_type as vehicle, 
CONCAT(user_info.first_name," ",user_info.last_name) as clientname,
CONCAT(driver.first_name," ",driver.last_name) as driver_name, 
user_info.mobile_no as mob_no,user_info.uid as client_id,driver.uid as driver_id,
CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,
driver.vehicle_reg_no as reg,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
 JOIN master_package ON cab_booking.booking_type=master_package.package_id 
 JOIN user_info ON cab_booking.client_id=user_info.uid
 LEFT JOIN driver ON cab_booking.pickup=driver.uid 
 LEFT JOIN vehicle_type ON driver.vehicle_type=vehicle_type.id 
 LEFT JOIN booking_charges ON cab_booking.id=booking_charges.BookingID 
 LEFT JOIN complaint ON cab_booking.booking_reference=complaint.BookingID 
 WHERE cab_status.`type`='cab' AND cab_booking.client_id=client_id order by cab_booking.id desc;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_a_driver_order_history` (IN `ids` INT, IN `from_i` DATETIME, IN `to_i` DATETIME)   BEGIN
SELECT CONCAT(cab_booking.DropAddress,cab_booking.DropArea) as drop_area,cab_booking.ID as id,cab_booking.booking_reference as book_ref, 
cab_list_mgmt.name,booking_charges.totalBill,
user_info.vehicleimg,master_package.Master_Package as booking_type,CONCAT(cab_booking.PickupDate," ",cab_booking.PickupTime) as ordertime,
concat(client.clientName,'<br>(',appid.`type`,')') as partner,
CONCAT(user_info.FirstName," ",user_info.LastName) as clientname,
CONCAT(cab_booking.PickupAddress,' ',cab_booking.PickupArea) as departure,driver.VehicleRegistrationNo as reg,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` INNER JOIN user_info ON user_info.UID=cab_booking.pickup 
 JOIN master_package ON cab_booking.BookingType=master_package.Package_Id INNER JOIN driver ON cab_booking.pickup=driver.uid 
  JOIN appid ON appid.id=cab_booking.partner INNER JOIN user ON cab_booking.pickup = user.ID
 JOIN client ON appid.clientId=client.id INNER JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID 
 LEFT JOIN complaint ON cab_booking.booking_reference=complaint.BookingID INNER JOIN cab_list_mgmt ON cab_list_mgmt.id = driver.vehicleId
 WHERE  cab_status.`type`='cab' AND user.token = ids AND DATE(cab_booking.BookingDate) BETWEEN from_i and to_i order by cab_booking.ID desc;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_a_user_order_history` (IN `id` INT)   BEGIN
SELECT CONCAT(cab_booking.DropAddress,cab_booking.DropArea) as drop_area,cab_booking.ID as id,cab_booking.booking_reference as book_ref, 
cab_list_mgmt.name as veh_name,master_package.Master_Package as booking_type,CONCAT(cab_booking.PickupDate," ",cab_booking.PickupTime) as ordertime,
concat(client.clientName,'<br>(',appid.`type`,')') as partner,
CONCAT(user_info.FirstName," ",user_info.LastName) as clientname,
CONCAT(cab_booking.PickupAddress,' ',cab_booking.PickupArea) as departure,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
INNER JOIN user_info ON user_info.UID=cab_booking.ClientID
INNER JOIN master_package ON cab_booking.BookingType=master_package.Package_Id 
LEFT JOIN driver ON cab_booking.pickup=driver.uid 
INNER JOIN appid ON appid.id=cab_booking.partner 
LEFT JOIN user ON cab_booking.pickup = user.ID
INNER JOIN client ON appid.clientId=client.id 
LEFT JOIN cab_list_mgmt ON cab_list_mgmt.id = driver.vehicleId
 WHERE cab_status.`type`='cab' AND cab_booking.ClientID = id order by cab_booking.ID desc;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_a_user_total_bill` (IN `booking_id` INT)   BEGIN
SELECT booking_charges.totalBill, cab_booking.actual_distance from booking_charges inner join cab_booking on booking_charges.BookingID = cab_booking.ID where booking_charges.BookingID = booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_booking_action` (IN `booking_id` INT)   BEGIN
SELECT booking.client_id as client,booking.driver_id as pickup,booking.reference_number as ref,booking.status as stat,CONCAT(booking_pickdrop_details.pickup_date,' ',booking_pickdrop_details.pickup_time) as date FROM booking
LEFT JOIN booking_pickdrop_details ON booking_pickdrop_details.booking_id=booking.booking_id
WHERE booking.booking_id=booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_booking_action_old` (IN `booking_id` INT)   BEGIN
SELECT cab_booking.client_id as client,cab_booking.pickup,cab_booking.booking_reference as ref,cab_booking.status as stat,CONCAT(cab_booking.pickup_date,' ',cab_booking.pickup_time) as date FROM cab_booking WHERE id=booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_booking_distance` (IN `user_id` INT, IN `book_id` INT, IN `from_a` VARCHAR(200), IN `to_a` VARCHAR(200), IN `date_time` DATETIME, IN `distance` DOUBLE, IN `waiting_time` VARCHAR(50))   BEGIN
INSERT INTO booking_distance  (user_id,booking_id,`to`,`from`,device_time,distance, WaitingTime)
VALUES (user_id,book_id,to_a,from_a,date_time,distance,waiting_time);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_book_fetch_info` (IN `book_id` INT(4))   BEGIN
SELECT bk.booking_id as id,bk.driver_id,bk.reference_number as ref,us2.id as client_id,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  us.mobile,
  us.email as user_email,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
mp.id as booking_type_id,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.base_vehicle_id,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
bk.master_package_mode_id,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
bpd.pickup_date,
bpd.pickup_time,
bpd.pickup_address,
bpd.pickup_area,
bpd.drop_address,
bpd.drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone,
location.api_time,
location.api_distance,
dispatch.type_of_dispatch,
if(dispatch.type_of_dispatch=1,'Point To Point','Garage To garage') As type_of_dispatch_name,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.city as garage_city,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN base_vehicle_type AS bvt ON bk.base_vehicle_id = bvt.base_vehicle_id
LEFT JOIN dispatch_location AS dispatch ON bvt.base_comb_id = dispatch.base_comb_id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package_fare AS lpf ON bk.package_id = lpf.local_pkg_fare_id
LEFT JOIN local_package as lp ON lpf.local_pkg_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
LEFT JOIN 
	api_call_timeinterval as location ON bk.company_id = location.company_id AND bk.master_package_id = location.package_id
WHERE
   bk.booking_id = book_id AND bk.booking_status = 1
ORDER BY
  bk.booking_id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_book_fetch_info_current_notification` (IN `book_id` INT, IN `bookingType` INT, IN `calculationType` INT, IN `driver_id` INT)   BEGIN
DECLARE currency_n varchar(50);
DECLARE distance_n varchar(50);
SELECT tblcountry.currency ,tblcountry.distance_unit into currency_n,distance_n 
FROM tblcountry 
WHERE tblcountry.CountryName='India';
IF calculationType=1 THEN
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,		 
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON driver.UID = driver_id
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.cabType = cab_booking.CarType AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON driver.UID = driver_id
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
ELSE
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.cabType = cab_booking.CarType AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_book_fetch_info_notification` (IN `book_id` INT, IN `bookingType` VARCHAR(50), IN `calculationType` VARCHAR(50))   BEGIN
DECLARE currency_n varchar(50);
DECLARE distance_n varchar(50);
SELECT tblcountry.currency ,tblcountry.distance_unit into currency_n,distance_n 
FROM tblcountry 
WHERE tblcountry.CountryName='India';
IF calculationType=1 THEN
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price,user.gcm_id,user.Latitude as lat,user.Longtitude1 as lon
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON cab_booking.pickup = driver.UID
JOIN user ON cab_booking.pickup=user.id
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees,user.gcm_id,user.Latitude as lat,user.Longtitude1 as lon
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON cab_booking.pickup = driver.UID
JOIN user ON cab_booking.pickup=user.id
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
ELSE
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price,user.gcm_id,user.Latitude as lat,user.Longtitude1 as lon
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
JOIN user ON cab_booking.pickup=user.id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.cabType = cab_booking.CarType AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName,
		 cab_booking.EmailId,
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees,user.gcm_id,user.Latitude as lat,user.Longtitude1 as lon
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
JOIN user ON cab_booking.pickup=user.id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_book_fetch_info_old` (IN `book_id` INT, IN `bookingType` VARCHAR(50), IN `calculationType` VARCHAR(50))   BEGIN
DECLARE currency_n varchar(50);
DECLARE distance_n varchar(50);
SELECT tblcountry.currency ,tblcountry.distance_unit into currency_n,distance_n 
FROM tblcountry 
WHERE tblcountry.CountryName='India';
IF calculationType=1 THEN
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName, 
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.EmailId,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state AND tbllocalpackage.cabType = cab_booking.CarType 
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		 distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName, 
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.EmailId,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 cab_list_mgmt.Min_Distance,
	    cab_list_mgmt.NightCharges,
		cab_list_mgmt.nightCharge_unit,
	    cab_list_mgmt.waitingfee_upto_minutes,
	    cab_list_mgmt.MinimumCharge, 
	    cab_list_mgmt.night_rate_begins,
	    cab_list_mgmt.night_rate_ends,
	    cab_list_mgmt.basic_tax,
	    cab_list_mgmt.tripCharge_per_minute,
		 cab_list_mgmt.Per_Km_Charge,
		 cab_list_mgmt.rate_per_km_dh,
		 cab_list_mgmt.minimum_fare_dh,
		 cab_list_mgmt.minimum_distance_dh,
		 cab_list_mgmt.rate_per_km_dw,
		 cab_list_mgmt.minimum_fare_dw,
		 cab_list_mgmt.minimum_distance_dw,
		 cab_list_mgmt.rate_per_hour_dh,
		 cab_list_mgmt.CabId,		
		 cab_list_mgmt.waiting_fees,
		 tblcity.state
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
ELSE
IF bookingType=101 THEN
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName, 
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.CabIn,
		 cab_booking.EmailId,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees,
		 tblcity.state,
		 tbllocalpackage.Price
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.cabType = cab_booking.CarType AND tbllocalpackage.Sub_Package_Id = master_package.Sub_Package_Id AND tbllocalpackage.City_ID = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
ELSE
SELECT cab_booking.ID,
		 cab_booking.booking_reference,
		 cab_booking.CarType,
		  distance_n as measure,
		 currency_n as currency, 
		 cab_booking.UserName, 
		 cab_booking.BookingType,
		 master_package.Sub_Package_Id,
		 cab_booking.CabFor,
		 cab_booking.CabFor AS CabForHrs,
		 cab_booking.min_Distance AS CabForKm,
		 cab_booking.PickupArea, 
		 cab_booking.PickupAddress,
		 cab_booking.PickupArea as pickup_location,
		 cab_booking.DropAddress,
		 cab_booking.DropArea as drop_location,
		 cab_booking.PickupLatitude,
		 cab_booking.PickupLongtitude,
		 cab_booking.DestinationLatitude,
		 cab_booking.DestinationLongtitude,
		 cab_booking.PickupDate,
		 cab_booking.PickupTime,
		 cab_booking.approx_distance_charge,
		 cab_booking.MobileNo,
		 cab_booking.EstimatedDistance,
		 cab_booking.estimated_price,
		 cab_booking.EstimatedTime,
		 cab_booking.local_subpackage,
		 cab_booking.CabIn,
		 cab_booking.peakTimePrice,
		 cab_booking.peaktimeFrom,
         cab_booking.peaktimeTo,
         cab_booking.peaktimepercentage,
		 cab_booking.extraPrice,
		 cab_booking.EmailId,
		 cab_booking.charge_type,
		 NOW() as send_time,
		 booking_bill.Min_Distance,
	    booking_bill.NightCharges,
		booking_bill.nightCharge_unit,
	    booking_bill.waitingfee_upto_minutes,
	    booking_bill.MinimumCharge, 
	    booking_bill.night_rate_begins,
	    booking_bill.night_rate_ends,
	    booking_bill.basic_tax,
	    booking_bill.tripCharge_per_minute,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_distance_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.minimum_fare_dw,
		 booking_bill.minimum_distance_dw,
		 booking_bill.rate_per_hour_dh,	
		 booking_bill.waiting_fees,
		 tblcity.state
FROM cab_booking
INNER JOIN master_package ON cab_booking.BookingType = master_package.Package_Id
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType AND booking_bill.CityId = tblcity.state
WHERE cab_booking.ID = book_id
AND cab_booking.BookingStatus = 1;
END IF;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_calculate_point` (IN `id_s` INT, IN `lat` DOUBLE, IN `long1` DOUBLE)   BEGIN
DECLARE time_interval datetime;
DECLARE check_time int;
DECLARE amount int;
DECLARE distance double;
DECLARE last_booking datetime;
DECLARE check_idle int;
DECLARE total_booking int;
DECLARE `point` int;
DECLARE distance_out DOUBLE;
DECLARE time2 int;
SELECT user.loginTime,`driver`.`SecurityAmt`,`user`.`last_booking` INTO time_interval, amount,last_booking FROM user INNER JOIN driver ON user.id=driver.UID WHERE user.userType=3 and user.id=id_s;
SELECT (((acos( sin ( (lat * pi()/180)) * sin((`latitude`*pi()/180))+cos((lat*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((long1- `longtitude1`)*  pi()/180))))*180/pi())*60*1.1515) INTO distance  FROM user WHERE id=id_s;
SET distance_out=distance;
SET check_time=TIMESTAMPDIFF(HOUR,time_interval,NOW());
SET point=5;
IF check_time<=3 THEN 
SET point=1;
ELSEIF check_time<=6 THEN 
SET point =2;
ELSEIF check_time<=9 THEN
SET point=3;
ELSEIF check_time<=12 THEN
SET point=4;
ELSEIF check_time<=15 THEN
SET point=5;
END IF;
IF amount<=1000 THEN
SET point=point+0;
ELSEIF amount<=2000 THEN
SET point=point+1;
ELSEIF amount<=3000 THEN
SET point=point+2;
ELSEIF amount<=4000 THEN
SET point=point+3;
ELSEIF amount<=5000 THEN
SET point=point+4;
ELSEIF amount>5000 THEN
SET point=point+5;
END IF;
IF distance<=1 THEN
SET point=point+5;
ELSEIF distance<=2 THEN
SET point=point+4;
ELSEIF distance<=3 THEN
SET point=point+3;
ELSEIF amount<=4 THEN
SET point=point+2;
ELSEIF amount<=5 THEN
SET point=point+1;
ELSEIF distance>5 THEN
SET point=point+0;
END IF;
IF time_interval>last_booking THEN
SET check_idle=TIMESTAMPDIFF(MiNUTE,time_interval,NOW());
ELSE
SET check_idle=TIMESTAMPDIFF(MiNUTE,last_booking,NOW());
END IF;
IF check_idle<=30 THEN
SET point=point+0;
ELSEIF check_idle<=60 THEN
SET point=point+1;
ELSEIF check_idle<=90 THEN
SET point=point+2;
ELSEIF check_idle<=120 THEN
SET point=point+3;
ELSEIF check_idle<=150 THEN
SET point=point+4;
ELSEIF check_idle>150 THEN
SET point=point+5;
END IF;
SET time2=check_idle;
SELECT count(*) INTO total_booking FROM `cab_booking` WHERE pickup=id_s;
SET point = point + (5-total_booking);
SELECT point;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_check_booking` (IN `bookid` INT, IN `user_id` INT)   BEGIN
DECLARE  checked INT ; 
DECLARE latitude_id INT ; 
DECLARE longitude_id INT ; 
DECLARE update_id INT ; 
DECLARE driver TEXT ; 
DECLARE vehicle TEXT ;
DECLARE cname TEXT ; 
DECLARE ref TEXT ; 
DECLARE pdate TEXT ;
  SELECT
    COUNT(*),
    `lat`,
    `long`
  INTO
    checked,
    latitude_id,
    longitude_id
  FROM
    booking_stack
  JOIN
    booking ON booking_stack.booking_id = booking.booking_id
  WHERE
    booking_stack.booking_id = bookid AND(
      booking_stack.`status` = 'W' OR booking_stack.`status` = ''
    ) ; 
IF checked = 1 THEN
  UPDATE
    booking_stack
  SET
    `status` = 'A'
  WHERE
    booking_id = bookid ;
  UPDATE
    booking
  SET
    driver = user_id,
    `status` = 3,
    is_updation_allow = 'FALSE'
  WHERE
    booking_id = bookid AND is_updation_allow = 'TRUE' ;
  SELECT
    CONCAT(
      driver.first_name,
      ' ',
      driver.last_name,
      ' ',
      driver.mobile
    ),
    vm.registration_number as VehicleRegistrationNo
  INTO
    driver,
    vehicle
  FROM
    user as driver
left join user_vehicle_mapping as vmap ON driver.id = vmap.user_id
left join vehicle_master as vm ON vmap.vehicle_master_id = vm.vehicle_master_id
  WHERE
    driver.id = user_id ;
  SELECT
   CONCAT(
      user.first_name,
      ' ',
      user.last_name,
      ' ',
      driver.mobile
    ) as UserName,
    booking.reference_number as booking_reference,
    CONCAT(
      bpick.pickup_date,
      " ",
      bpick.pickup_time
    )
  INTO
    cname,
    ref,
    pdate
  FROM
    booking
LEFT JOIN user ON booking.user_id = user.id
LEFT JOIN booking_pickdrop_details AS bpick ON booking.booking_id = bpick.booking_id
  WHERE
    booking.booking_id = bookid ;
  SELECT
    booking_register.id
  INTO
    update_id
  FROM
    booking_register
  WHERE
    booking_register.driverId = user_id AND booking_register.bookingid = bookid
  ORDER BY
    id DESC
  LIMIT 0, 1 ;
UPDATE
  booking_register
SET
  `status` = 'A',
  `type` = 'By Notification'
WHERE
  id = update_id ;
UPDATE
  `driver`
SET
  `status` = '1'
WHERE
  `user_id` = user_id ;
INSERT
INTO
  `booking_tracker`(
    `BookingID`,
    `DriverId`,
    `Latitutude`,
    `Logitude`,
    `Date_Time`,
    `CabStatus`
  )
VALUES(
  bookid,
  user_id,
  latitude_id,
  longitude_id,
  NOW(), '3') ;
INSERT
INTO
  `booking_logs`(`bookingid`,
  `status`,
  `message`,
  `time`)
VALUES(bookid, '3', 'Accepted', NOW()) ;
END IF ;
SELECT
  checked,
  driver,
  vehicle,
  cname,
  ref,
  pdate ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_check_booking_old` (IN `bookid` INT, IN `user_id` INT)   BEGIN
  DECLARE checked int;
  DECLARE latitude_id int;
  DECLARE longitude_id int;
  DECLARE update_id INT;
  DECLARE driver TEXT;
  DECLARE vehicle TEXT;
  DECLARE cname TEXT;
  DECLARE ref TEXT;
  DECLARE pdate TEXT;
  SELECT count(*) ,`lat`,`long` INTO checked,latitude_id,longitude_id FROM booking_stack JOIN cab_booking ON booking_stack.booking_id=cab_booking.ID WHERE booking_stack.booking_id=bookid and (booking_stack.`status`='W' or booking_stack.`status`='');
  IF checked=1 THEN
   UPDATE booking_stack SET `status`='A' WHERE booking_id=bookid;
  UPDATE cab_booking SET pickup=user_id,`status`=3,is_updation_allow='FALSE' WHERE id=bookid AND is_updation_allow='TRUE';
  SELECT CONCAT(driver.FirstName,' ',driver.LastName,' ',driver.ContactNo),driver.VehicleRegistrationNo INTO driver,vehicle FROM driver WHERE driver.UID=user_id;
SELECT cab_booking.UserName,cab_booking.booking_reference,CONCAT(cab_booking.PickupDate," ",cab_booking.PickupTime) INTO cname,ref,pdate FROM cab_booking WHERE cab_booking.ID=bookid;
  SELECT booking_register.id into update_id FROM booking_register WHERE booking_register.driverId=user_id and booking_register.bookingid=bookid order by id desc LIMIT 0,1;
  UPDATE booking_register SET `status`='A',`type`='By Notification' WHERE id=update_id ;
   UPDATE `driver` SET `status`='1' WHERE `UID`=user_id;
  INSERT INTO `booking_tracker` (`BookingID`,`DriverId`,`Latitutude`,`Logitude`,`Date_Time`,`CabStatus`) VALUES (bookid,user_id,latitude_id,longitude_id,NOW(),'3');
  INSERT INTO `booking_logs` (`bookingid`,`status`,`message`,`time`) VALUES (bookid,'3','Accepted',NOW());
  END IF;
   SELECT checked,driver,vehicle,cname,ref,pdate;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_customer_care_text` ()  NO SQL Begin
Select text,text_id from region_text where page_title='customer_ca' and lang=2;
end$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_acc_balance` (IN `id` INT, IN `since` DATETIME, IN `to_i` DATETIME)   BEGIN
SELECT driver_transaction.user_id,driver_transaction.amount,driver_transaction.currentbalance,date(driver_transaction.time) as date,
driver_transaction.`status`,driver_transaction.reason, master_package.Master_Package,driver_transaction.booking_ref 
FROM driver_transaction left JOIN cab_booking ON driver_transaction.booking_ref = cab_booking.booking_reference 
left join master_package on cab_booking.BookingType = master_package.Package_Id
where driver_transaction.user_id = id and  DATE(driver_transaction.time) BETWEEN since and to_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_alloc` (IN `book_id` INT)   BEGIN
SELECT
  CONCAT(
    user.first_name,
    ' ',
    user.last_name
  ) AS driver_name,
  mvm.name AS vehicle,
  booking_register.updateOn AS created,
  booking_register.`status`
FROM
  booking_register
JOIN
  driver ON booking_register.driverId = driver.user_id
JOIN
  user ON booking_register.driverId = user.id
LEFT JOIN
  user_vehicle_mapping AS uvm ON driver.user_id = uvm.user_id
LEFT JOIN
 vehicle_master AS vm ON uvm.vehicle_master_id = vm.vehicle_master_id
LEFT JOIN 
 master_vehicle_model AS mvm ON  vm.id = mvm.id
WHERE
  booking_register.bookingid = book_id
ORDER BY
  booking_register.id DESC
LIMIT 0, 7; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_info` (IN `driver_id` INT)   BEGIN
SELECT complaint.CSRID as csre,complaint.ClosureDescription as sub_type, complaint.ComplaintType as com_type,complaint.ID as com_id,complaint.ComplaintDescription as com_desc,complaint.ComplaintDate as com_date,complaint.StatusID as com_status, complaint.CallerName as com_caller,driver.uid, CONCAT(driver.first_name," ",driver.last_name)  as driver_name,driver.contact_no,driver.lang_speak,vendor.vendor_name,vendor.group_name,driver.`status`,driver.account_no,driver.rtgs_neft,driver.operational_company_name,cab_master.CabRegistrationNumber,cab_master.CabName,cab_master.CabColor,driver.vehicle_make as make,cab_master.CabModel as model,driver.vehicle_type as v_type FROM cab_booking JOIN driver ON cab_booking.pickup=driver.uid LEFT JOIN vendor ON driver.vendor_id=vendor.id JOIN cab_master ON driver.vehicle_id=cab_master.CabId LEFT JOIN complaint ON cab_booking.booking_reference = complaint.BookingID WHERE cab_booking.ID=driver_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_on_off` (IN `driver_id` INT)  NO SQL BEGIN
DECLARE is_on int;
SELECT is_active into is_on FROM user WHERE id=driver_id and loginstatus=1;
IF is_on = 1 THEN
UPDATE user SET is_active=0 WHERE id=driver_id;
ELSEIF is_on=0 THEN 
UPDATE user SET is_active=1 WHERE id=driver_id;
END IF;
SELECT is_active FROM user WHERE id=driver_id and loginstatus=0 ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_tracking` ()   BEGIN
DECLARE total_driver int;
DECLARE OnDuty int;
DECLARE available_driver int;
DECLARE hired int;
DECLARE accepted int;
DECLARE log_out int;
DECLARE reported int;
DECLARE free_moving int;
DECLARE logout_moving int;
DECLARE on_call int;
SELECT COUNT(DISTINCT(user.ID)) INTO reported FROM user INNER JOIN user_info ON user.ID = user_info.UID INNER JOIN driver ON user.ID = driver.UID INNER JOIN cab_master ON driver.vehicleId = cab_master.CabId INNER JOIN cab_booking ON user.ID = cab_booking.pickup WHERE cab_booking.`Status`=5 AND user.loginStatus=1 AND user.Latitude != '' AND user.Longtitude1 != '' AND driver.`status`=1;
SELECT COUNT(*) INTO log_out FROM user INNER JOIN user_info ON user.ID = user_info.UID INNER JOIN driver ON user.ID = driver.UID INNER JOIN cab_master ON driver.vehicleId = cab_master.CabId WHERE user.UserType = 3 AND user.isVerified = 1 AND user.Latitude != '' AND user.Longtitude1 != '' AND user.loginStatus=0; 
SELECT hired,free_moving,logout_moving,reported,on_call;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_driver_tracking_list` ()   BEGIN
SELECT DISTINCT(driver.ID),
		 driver.uid,
		 driver.`status`,
		 user.loginStatus,
		 cab_booking.`Status` 
FROM driver 
JOIN cab_master ON driver.vehicleId = cab_master.CabId
WHERE user.isVerified = 1
GROUP BY driver.UID 
ORDER BY driver.ID desc; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_fare_details` (IN `city_id` INT, IN `master_package_id` INT, IN `local_pkg_id` INT, IN `seating_capacity` INT, IN `luggage` INT, IN `pickup_date_time` VARCHAR(50))   BEGIN
IF local_pkg_id>0
THEN
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.category_id as vehicle_category_id,
  mvt.vehicle_type,
GROUP_CONCAT(DISTINCT vmodel.name SEPARATOR ', ') as vehicle_name,
  GROUP_CONCAT(DISTINCT vm.model SEPARATOR ', ') as vehicle_model,
  GROUP_CONCAT(DISTINCT vcolour.colour_name SEPARATOR ', ') as vehicle_color,
    GROUP_CONCAT(DISTINCT fuel.fuel_type SEPARATOR ', ') as ignition_type,  
  mvt.vehicle_image,
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude,
user_rating.Rating as rating
FROM
  base_combination AS bc
INNER JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
INNER JOIN 
 local_package_fare AS lpf ON bvt.base_vehicle_id = lpf.base_vehicle_id
INNER join 
 local_package AS lp ON lpf.local_pkg_id = lp.id
LEFT JOIN
  master_package_mode AS mpm ON lp.booking_mode = mpm.id
LEFT JOIN
  master_package AS mp ON lp.id = mp.id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id 
LEFT JOIN
master_vehicle_model as vmodel ON mvt.id =vmodel.vehicle_type_id
INNER JOIN 
	vehicle_master AS vm ON mvt.id = vm.id
INNER join 
 	master_fuel_type as fuel ON vm.ignition_type_id= fuel.id
INNER JOIN 
	master_colour AS vcolour ON vm.color  = vcolour.colour_id
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
LEFT JOIN 
 user_rating ON bc.vendor_id = user_rating.UserId
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id  AND lpf.local_pkg_id = local_pkg_id
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
AND bc.status = '1'
group by bvt.base_vehicle_id;
ELSE 
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.vehicle_type,
  GROUP_CONCAT(vmodel.name SEPARATOR ', ') as vehicle_name,
     GROUP_CONCAT(DISTINCT vm.model SEPARATOR ', ') as vehicle_model,
  GROUP_CONCAT(DISTINCT vcolour.colour_name SEPARATOR ', ') as vehicle_color,
   GROUP_CONCAT(DISTINCT fuel.fuel_type SEPARATOR ', ') as ignition_type,
  mvt.vehicle_image, 
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude,
user_rating.Rating as rating
FROM
  base_combination AS bc
LEFT JOIN
  master_package_mode AS mpm ON bc.master_package_mode_id = mpm.id
LEFT JOIN
  master_package AS mp ON bc.master_package_id = mp.id
LEFT JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id
LEFT JOIN
master_vehicle_model as vmodel ON mvt.id =vmodel.vehicle_type_id
INNER JOIN 
	vehicle_master AS vm ON mvt.id = vm.id
INNER join 
 	master_fuel_type as fuel ON vm.ignition_type_id= fuel.id
INNER JOIN 
	master_colour AS vcolour ON vm.color  = vcolour.colour_id
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
 LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
	premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id 
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
LEFT JOIN 
 user_rating ON bc.vendor_id = user_rating.UserId
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id 
AND bc.status = '1'
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
group by bvt.base_vehicle_id
;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_fare_details_15-aug-20` (IN `city_id` INT, IN `master_package_id` INT, IN `local_pkg_id` INT, IN `seating_capacity` INT, IN `luggage` INT)   BEGIN
IF local_pkg_id>0
THEN
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.category_id as vehicle_category_id,
  mvt.vehicle_type,
  GROUP_CONCAT(vmodel.name SEPARATOR ', ') as vehicle_name,
  mvt.vehicle_image,
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
FROM
  base_combination AS bc
INNER JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
INNER JOIN 
 local_package_fare AS lpf ON bvt.base_vehicle_id = lpf.base_vehicle_id
INNER join 
 local_package AS lp ON lpf.local_pkg_id = lp.id
LEFT JOIN
  master_package_mode AS mpm ON lp.booking_mode = mpm.id
LEFT JOIN
  master_package AS mp ON lp.id = mp.id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id 
LEFT JOIN
master_vehicle_model as vmodel ON mvt.id =vmodel.vehicle_type_id
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id  AND lpf.local_pkg_id = local_pkg_id
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
AND bc.status = '1'
group by bvt.base_vehicle_id
;
ELSE 
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.vehicle_type,
  GROUP_CONCAT(vmodel.name SEPARATOR ', ') as vehicle_name,
  mvt.vehicle_image, 
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
FROM
  base_combination AS bc
LEFT JOIN
  master_package_mode AS mpm ON bc.master_package_mode_id = mpm.id
LEFT JOIN
  master_package AS mp ON bc.master_package_id = mp.id
LEFT JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id
LEFT JOIN
master_vehicle_model as vmodel ON mvt.id =vmodel.vehicle_type_id
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
 LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
	premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id 
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id 
AND bc.status = '1'
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
group by bvt.base_vehicle_id
;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_fare_details_old_18-feb-20` (IN `city_id` INT, IN `master_package_id` INT, IN `local_pkg_id` INT, IN `seating_capacity` INT, IN `luggage` INT)   BEGIN
IF local_pkg_id>0
THEN
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.vehicle_type,
  mvt.vehicle_image,
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
FROM
  base_combination AS bc
INNER JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
INNER JOIN 
 local_package_fare AS lpf ON bvt.base_vehicle_id = lpf.base_vehicle_id
INNER join 
 local_package AS lp ON lpf.local_pkg_id = lp.id
LEFT JOIN
  master_package_mode AS mpm ON lp.booking_mode = mpm.id
LEFT JOIN
  master_package AS mp ON lp.id = mp.id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id 
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
  LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
	premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id  
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id  AND lpf.local_pkg_id = local_pkg_id
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
AND bc.status = '1'
;
ELSE 
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.vehicle_type,
  mvt.vehicle_image,
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
FROM
  base_combination AS bc
LEFT JOIN
  master_package_mode AS mpm ON bc.master_package_mode_id = mpm.id
LEFT JOIN
  master_package AS mp ON bc.master_package_id = mp.id
LEFT JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id 
LEFT JOIN
  night_charge AS nc ON bvt.base_vehicle_id = nc.base_vehicle_id AND nc.status = "1"
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
 LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
	premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id 
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id 
AND bc.status = '1'
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_all_complaint_by_id` (IN `complaint_id_i` INT)   BEGIN
SELECT * FROM complaint WHERE ID = complaint_id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_all_enquiry_by_id` (IN `enquiry_id` INT)   BEGIN
SELECT * FROM enquiry WHERE id = enquiry_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_booking_filter_new` (IN `CallerID` VARCHAR(50), IN `book_ref` VARCHAR(50), IN `Todate` DATETIME, IN `FromDate` DATETIME, IN `vehicle_number` VARCHAR(50), IN `vehicle_Driver` VARCHAR(50))   BEGIN
SELECT CONCAT(cab_status.`status`,' ',IFNULL(CONCAT("(INR ",booking_charges.totalBill,")"),'')) as `status`,
complaint.ID as com_id,complaint.StatusID as com_status,
 cab_booking.CSR_ID as emp,
 CONCAT(cab_booking.DropAddress,cab_booking.DropArea) as drop_area,
 cab_booking.ID as id,booking_charges.totalBill,
  cab_booking.booking_reference as ref,
  master_package.Master_Package as booking_type,
  CONCAT(cab_booking.PickupDate," ",cab_booking.PickupTime) as ordertime,
  concat(client.clientName," ",appid.`type`)   as partner,
  CONCAT(cab_list_mgmt.name,', ',driver.FirstName,"(",driver.ContactNo,")") as vehicle,
  CONCAT(user_info.FirstName,"(",user_info.MobNo,")") as clientname,
  CONCAT(driver.FirstName," ",driver.ContactNo) as driver_name, 
  cab_booking.MobileNo as mob_no,
  user_info.UID as client_id,
  driver.UID as driver_id,
  CONCAT(cab_booking.PickupAddress,' ',cab_booking.PickupArea) as departure,
  driver.VehicleRegistrationNo as reg 
  FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
  LEFT JOIN driver ON cab_booking.pickup=driver.uid 
  LEFT JOIN cab_list_mgmt ON driver.TypeOfvehicle=cab_list_mgmt.id 
  JOIN appid ON appid.id=cab_booking.partner 
  JOIN client ON appid.clientId=client.id 
  LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID 
  WHERE cab_status.`type`='cab' 
    and cab_booking.Bookingdate >= FromDate 
	 AND cab_booking.Bookingdate <= Todate and cab_booking.MobileNo=IFNULL(CallerID,cab_booking.MobileNo) 
	 and  cab_booking.Booking_reference=IFNULL(book_ref, cab_booking.Booking_reference)  
	 and  driver.VehicleRegistrationNo=IFNULL(vehicle_number, driver.VehicleRegistrationNo) 
	 and  driver.FirstName=IFNULL(vehicle_Driver, driver.FirstName) order by cab_booking.ID desc ;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_land_mark_address` (IN `PiCity` VARCHAR(50), IN `PiZone` VARCHAR(50), IN `PiArea` VARCHAR(50))   BEGIN
select distinct Address from rt_locations where city=PiCity and zone=PiZone and area=PiArea order by id desc limit 1;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_lat_lot_address` (IN `PiCity` INT, IN `PiZone` INT, IN `PiArea` INT, IN `PiAddress` INT)   BEGIN
select lat ,lon  from rt_locations where city=PiCity and zone=PiZone and area=PiArea and Address=PiAddress order by id desc limit 1;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_homepage_text` ()  NO SQL Begin
Select text,text_id from region_text where page_title='home' and lang=2;
end$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_locate_booking` (IN `bookid` VARCHAR(50), IN `driverid` VARCHAR(50), IN `latitide` VARCHAR(50), IN `longitude` VARCHAR(50))   BEGIN
DECLARE lastid INT;
UPDATE booking SET `status`=4 WHERE booking_id=bookid;
INSERT INTO `booking_tracker` (`BookingID`,`DriverId`,`Latitutude`,`Logitude`,`Date_Time`,`CabStatus`) VALUES (bookid,driverid,latitide,longitude,NOW(),'4');
INSERT INTO `booking_logs` (`bookingid`,`user_id`,`status`,`message`,`time`) VALUES (bookid,driverid,'4','Located',NOW());
SELECT LAST_INSERT_ID() INTO lastid;
SELECT lastid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_locate_booking_old` (IN `bookid` VARCHAR(50), IN `driverid` VARCHAR(50), IN `latitide` VARCHAR(50), IN `longitude` VARCHAR(50))   BEGIN
DECLARE lastid INT;
UPDATE booking SET `status`=4 WHERE booking_id=bookid;
INSERT INTO `booking_tracker` (`BookingID`,`DriverId`,`Latitutude`,`Logitude`,`Date_Time`,`CabStatus`) VALUES (bookid,driverid,latitide,longitude,NOW(),'4');
INSERT INTO `booking_logs` (`bookingid`,`status`,`message`,`time`) VALUES (bookid,'4','Located',NOW()); 
SELECT LAST_INSERT_ID() INTO lastid;
SELECT lastid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_login_text` ()  NO SQL Begin
Select text,text_id from region_text where page_title='login' and lang=2;
end$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_logout` (IN `login_id` INT, IN `token` VARCHAR(200), IN `logout_location` VARCHAR(200))  NO SQL BEGIN
UPDATE user SET login_status = 0, gcm_id = '',logout_time = NOW() WHERE `id` = login_id;
UPDATE driver SET `status`=0 WHERE user_id = login_id;
UPDATE log_in_log SET logout_time=NOW(),logout_location =logout_location WHERE userId = login_id and status=token;
UPDATE log_in_log SET `logout_date`= DATE(log_in_log.logout_time), login_diff=TIMEDIFF(log_in_log.logout_time,log_in_log.login_time) where userID=login_id and status=token;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_mohit_logout` (IN `login_id` INT, IN `token` VARCHAR(200))  NO SQL BEGIN
UPDATE user SET loginStatus = 0,
						 gcm_id = '',
						 is_active = 0,
						 logoutTime = NOW()
WHERE `ID` = login_id;
UPDATE driver SET `status`=0 WHERE UID = login_id and status=token;
UPDATE log_in_log SET logout_time=NOW() WHERE userId = login_id and status=token;
UPDATE log_in_log SET `logout_date`= DATE(log_in_log.logout_time), login_diff=TIMEDIFF(log_in_log.logout_time,log_in_log.login_time) where userID=login_id and status=token;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_new_check` (IN `val` INT, IN `initial` TEXT)   BEGIN
DECLARE divide INT;
DECLARE neww VARCHAR(50);
DECLARE next INT;
DECLARE generated_ref TEXT;
IF val>=10000 THEN
SET divide=floor(val/10000);
SET next=val-(divide*10000);
SET neww=CHAR(64+divide);
SELECT neww,lpad(next,4,0), CONCAT(initial,DATE_FORMAT(NOW(), '%y') 
,DATE_FORMAT(NOW(), '%m'),neww,lpad(next,4,0)) into generated_ref;
ELSE
SELECT CONCAT(initial,DATE_FORMAT(NOW(), '%y') ,DATE_FORMAT(NOW(), 
'%m'),lpad(val,4,0)) into generated_ref;
END IF;
UPDATE cab_booking SET booking_reference=xyz WHERE id=val;
SELECT generated_ref;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_new_filter_search` (IN `status_i` INT(10), IN `check_val` INT(10), IN `s_val` VARCHAR(50))  NO SQL BEGIN
DECLARE checklogin VARCHAR(50);
SET checklogin=s_val;
IF  check_val = 0 THEN
SELECT cab_booking.charge_type,cab_booking.pickup_date,complaint.ID as com_id,complaint.StatusID as com_status, cab_booking.CSR_ID as
emp,CONCAT(cab_booking.drop_address,cab_booking.drop_area)
as drop_area,cab_booking.ID as id,booking_charges.totalBill, cab_booking.booking_reference as ref,master_package.master_package
as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as
ordertime,concat(client.clientName,'<br>(',appid.`type`,')') as partner,
REPLACE(cab_master.CabName,'•','') as vehicle,CONCAT(user_info.first_name," ",user_info.last_name) as clientname, user_info.alternate_contact_no as alt_no, CONCAT(driver.first_name," ",driver.last_name) as driver_name, user_info.mobile_no as mob_no,user_info.uid as client_id,driver.UID as driver_id, CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,driver.vehicle_reg_no as reg,cab_status.`status` as `status` FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` JOIN user_info ON user_info.uid=cab_booking.client_id
JOIN master_package ON
cab_booking.booking_type=master_package.package_id LEFT JOIN driver ON cab_booking.pickup=driver.uid
LEFT JOIN cab_master ON
driver.vehicle_id=cab_master.CabId JOIN appid ON appid.id=cab_booking.partner JOIN client ON appid.clientId=client.id LEFT JOIN booking_charges ON cab_booking.id=booking_charges.BookingID
LEFT JOIN complaint ON
cab_booking.booking_reference=complaint.BookingID WHERE cab_status.`type`='cab'  and cab_status.status_id = status_i;
END if;
IF  check_val = 1 THEN
SELECT cab_booking.charge_type,cab_booking.pickup_date,IFNULL ( complaint.ID,'Not Available') as com_id, IFNULL ( complaint.StatusID,'Not Available') as com_status, cab_booking.csr_id as emp,CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.id as id,
IFNULL(booking_charges.totalBill, 0) as totalBill, cab_booking.booking_reference as ref,master_package.master_package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,concat(client.clientName,'<br>(',appid.`type`,')') as partner,
IFNULL (REPLACE(cab_master.CabName,'•','') ,'Not Available') as vehicle,CONCAT(user_info.first_name," ",user_info.last_name) as clientname, user_info.alternate_contact_no as alt_no, IFNULL ( CONCAT(driver.first_name," ",driver.last_name),'Not Available') as driver_name, user_info.mobile_no as mob_no,user_info.uid as client_id, IFNULL ( driver.uid,0) as driver_id, CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,IFNULL ( driver.vehicle_reg_no ,'Not Available') as reg, CONCAT(cab_status.status ," ", "") as status 
FROM cab_booking JOIN cab_status ON cab_booking.status_c=cab_status.`status_id`
JOIN user_info ON user_info.uid=cab_booking.client_id
JOIN master_package ON
cab_booking.booking_type=master_package.package_id LEFT JOIN driver ON cab_booking.pickup=driver.uid
LEFT JOIN cab_master ON
driver.vehicle_id=cab_master.CabId JOIN appid ON appid.id=cab_booking.partner JOIN client ON appid.clientId=client.id LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID
LEFT JOIN complaint ON
cab_booking.booking_reference=complaint.BookingID WHERE cab_status.`type`='cab'  and cab_status.status_id = status_i;
END if;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_oneway_fare_details` (IN `city_id` INT, IN `dropcity_id` INT, IN `master_package_id` INT, IN `local_pkg_id` INT, IN `seating_capacity` INT, IN `luggage` INT, IN `pickup_date` VARCHAR(50))   BEGIN
SELECT
  bc.id AS base_comb_id,
  bc.date_from,
  bc.date_to,
  pat.start_time,
  pat.end_time,
  bc.city_id,
  mp.id AS master_package_id,
  mp.name AS package_name,
  mp.image,
  mpm.id AS master_package_mode_id,
  mpm.package_mode,
  nc.night_rate_begins,
  nc.night_rate_ends,
  nc.night_rate_type,
  nc.night_rate_value,
  bvt.base_vehicle_id,
  mvt.id AS master_vehicle_type_id,
  mvt.vehicle_type,
  GROUP_CONCAT(DISTINCT vmodel.name SEPARATOR ', ') as vehicle_name,
   GROUP_CONCAT(DISTINCT vm.model SEPARATOR ', ') as vehicle_model,
  GROUP_CONCAT(DISTINCT vcolour.colour_name SEPARATOR ', ') as vehicle_color,
   GROUP_CONCAT(DISTINCT fuel.fuel_type SEPARATOR ', ') as ignition_type,
  mvt.vehicle_image, 
  mvt.seating_capacity,
  mvt.amenities,
  mvt.luggage,
  tax.sgst,
  tax.cgst,
  tax.igst,
  bc.vendor_id,
  concat(vendor.first_name,' ',vendor.last_name) as vendor_name,
  vendor.email as vendor_email,
  vendor.mobile as vendor_mobile,
  premium.premiums_type,
  premium.premiums_value,
  dispatch.type_of_dispatch ,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude,
user_rating.Rating as rating,
oneway.city_distance_id,
citylist.source_city as source_city_id,citylist.destination_city as destination_city_id,
sourcecity.name as source_city_name,destinationcity.name as destination_city_name,
nc.night_rate_value as driver_allowance,ctt.toll as toll_tax,ctt.parking as parking_charge,ctt.city_tax as city_tax 
FROM
  base_combination AS bc
LEFT JOIN
  master_package_mode AS mpm ON bc.master_package_mode_id = mpm.id
LEFT JOIN
  master_package AS mp ON bc.master_package_id = mp.id
LEFT JOIN
  base_vehicle_type AS bvt ON bc.id = bvt.base_comb_id 
LEFT JOIN
  master_vehicle_type AS mvt ON bvt.vehicle_type_id = mvt.id
LEFT JOIN
master_vehicle_model as vmodel ON mvt.id =vmodel.vehicle_type_id
INNER JOIN 
	vehicle_master AS vm ON mvt.id = vm.id
INNER join 
 	master_fuel_type as fuel ON vm.ignition_type_id= fuel.id
INNER JOIN 
	master_colour AS vcolour ON vm.color  = vcolour.colour_id
LEFT JOIN
  basic_tax AS tax ON bvt.base_vehicle_id = tax.base_vehicle_id
Left join 
 package_active_timeslot as pat ON bvt.base_vehicle_id = pat.base_vehicle_id
 LEFT JOIN 
 user as vendor ON bc.vendor_id = vendor.id
LEFT JOIN 
	premiums_fare AS premium ON bvt.base_vehicle_id = premium.base_vehicle_id 
LEFT JOIN 
 dispatch_location as dispatch ON bc.id = dispatch.base_comb_id
 LEFT JOIN 
 user_rating ON bc.vendor_id = user_rating.UserId
 LEFT JOIN 
 oneway_city_route_package AS oneway ON bvt.base_vehicle_id = oneway.base_vehicle_id
 LEFT JOIN 
 city_distance_list as citylist ON oneway.city_distance_id = citylist.id AND citylist.source_city = city_id AND citylist.destination_city= dropcity_id
  LEFT JOIN master_city as sourcecity ON  citylist.source_city = sourcecity.id 
LEFT JOIN master_city as destinationcity ON citylist.destination_city = destinationcity.id 
 LEFT JOIN bidding_fare  ON bvt.base_vehicle_id =  bidding_fare.base_vehicle_id 
 LEFT JOIN night_charge as nc ON bvt.base_vehicle_id =  nc.base_vehicle_id 
LEFT JOIN city_toll_tax as ctt ON bvt.base_vehicle_id =  ctt.base_vehicle_id
WHERE
  bc.city_id  = city_id AND bc.master_package_id = master_package_id 

AND bc.status = '1'
AND bc.date_from <= pickup_date AND bc.date_to >=pickup_date 
AND mvt.seating_capacity >= seating_capacity
AND mvt.luggage >=luggage
group by bvt.base_vehicle_id,vm.id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_vehicle_filter` (IN `stauts_id` INT)   BEGIN
SELECT  DISTINCT(driver.id),driver.uid,cab_booking.booking_reference,cab_booking.drop_area,cab_list_mgmt.vehicleNumber,CONCAT(driver.first_name,' ',driver.last_name) as name,driver.contact_no,driver.`status`,user.login_status,cab_booking.`Status` FROM driver JOIN cab_list_mgmt ON driver.vehicle_id=cab_list_mgmt.id JOIN user ON driver.uid=user.id inner join cab_booking ON driver.uid=cab_booking.pickup and cab_booking.`Status`=stauts_id GROUP BY driver.uid ORDER BY cab_booking.`Status` DESC ; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_accept_fetch_job` (IN `bookid` INT, IN `driver_id` INT)   BEGIN
DECLARE is_stack int;
DECLARE BookingTypeVal varchar(50);
DECLARE unsuccess int;
DECLARE vehicleType varchar(50);
SELECT COUNT(*),master_package.name,master_vehicle_type.vehicle_type  into is_stack,BookingTypeVal,vehicleType FROM booking left join master_package ON booking.master_package_id = master_package.id LEFT JOIN master_vehicle_type  ON booking.master_vehicle_type_id =master_vehicle_type.id WHERE booking.booking_id=bookid and booking.driver_id=0 and booking.booking_status='1'; 
IF is_stack=1 THEN
UPDATE booking SET driver_id=driver_id, `status` = '3', is_updation_allow='FALSE'  WHERE booking_id=bookid and booking_status='1' and is_updation_allow='TRUE'; 
   END IF;
   SELECT is_stack,BookingTypeVal,vehicleType;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_accept_fetch_job_old` (IN `bookid` INT, IN `driver_id` INT)   BEGIN
DECLARE is_stack int;
DECLARE BookingTypeVal int;
DECLARE unsuccess int;
SELECT COUNT(*),BookingType into is_stack,BookingTypeVal FROM cab_booking WHERE id=bookid and pickup=0 and BookingStatus='1'; 
IF is_stack=1 THEN
UPDATE cab_booking SET pickup=driver_id, `Status` = '3', is_updation_allow='FALSE'  WHERE id=bookid and BookingStatus='1' and is_updation_allow='TRUE'; 
   END IF;
   SELECT is_stack,BookingTypeVal;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_admin_driver` (IN `state_in` INT)  NO SQL BEGIN
DECLARE taxis_reg INT;
DECLARE taxis_road INT;
DECLARE taxis_logged_in INT;
DECLARE taxis_logged_off INT;
DECLARE driver_blocked INT;
DECLARE taxis_not_functional INT;
DECLARE taxis_available INT;
DECLARE total_jobs INT;
DECLARE delhi_jobs INT;
DECLARE gurgaon_jobs INT;
DECLARE faridabad_jobs INT;
DECLARE noida_jobs INT;
DECLARE state_new text;
DECLARE outstation_jobs INT;
DECLARE railway_jobs INT;
DECLARE cancel_jobs INT;
DECLARE airport_jobs INT;
DECLARE taxis_busy INT;
DECLARE job_1 text;
DECLARE job_2 text;
DECLARE job_3 text;
DECLARE job_4 text;
DECLARE taxis_free INT;
DECLARE job_in_progress INT;
DECLARE job_advance INT;
DECLARE cash_duty_val INT DEFAULT 0;
DECLARE credit_duty_val INT DEFAULT 0;
DECLARE total_revenue_val INT DEFAULT 0;
DECLARE point_val INT DEFAULT 0;
DECLARE air_val INT DEFAULT 0;
DECLARE outstation_val INT DEFAULT 0;
DECLARE local_val INT DEFAULT 0;
DECLARE currency VARCHAR(50);
DECLARE job_completed int;
DECLARE cash_val int;
DECLARE credit_val int;
DECLARE local_book int;
DECLARE point_book int;
DECLARE airport_book int;
DECLARE outstation_book int;
DECLARE railway_book int;
DECLARE web_app int;
declare call_center int;
declare user_app int;
declare company_sh int;
declare driver_sh int;
declare partner_sh int;
SELECT COUNT(*) INTO taxis_free FROM driver JOIN user ON driver.uid=user.id WHERE user.login_status='1' and driver.`status`=0 and `state`=state_in;
SELECT COUNT(*) INTO job_in_progress FROM cab_booking WHERE pickup_date=CURDATE() and `status` >3 and `status`< 8;
SELECT value INTO job_1 FROM admin_text WHERE type=state_in and `field`='jobs_1';
SELECT value INTO job_2 FROM admin_text WHERE type=state_in and `field`='jobs_2';
SELECT value INTO job_3 FROM admin_text WHERE type=state_in and `field`='jobs_3';
SELECT value INTO job_4 FROM admin_text WHERE type=state_in and `field`='jobs_4';
SELECT COUNT(*) INTO taxis_reg FROM driver;
SELECT COUNT(*) INTO taxis_road FROM driver WHERE status='1';
SELECT COUNT(*) INTO taxis_busy FROM driver WHERE status='1';
SELECT COUNT(*) INTO taxis_logged_in FROM driver JOIN user ON driver.uid=user.id WHERE user.login_status='1';
SELECT COUNT(*) INTO taxis_logged_off FROM driver JOIN user ON driver.uid=user.id WHERE user.login_status!='1';
SELECT COUNT(*) INTO driver_blocked FROM driver WHERE is_active=0 and state=state_in;
SELECT COUNT(*) INTO taxis_not_functional FROM driver WHERE is_functional=0 and state=state_in;
SELECT COUNT(*) INTO taxis_available FROM driver JOIN user ON driver.uid=user.id WHERE driver.`status`=0 and user.login_status=1;
SELECT `state` INTO state_new FROM states WHERE id=state_in;
SELECT COUNT(*) INTO total_jobs FROM cab_booking WHERE DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO delhi_jobs FROM cab_booking WHERE cab_booking.pickup_area LIKE CONCAT('%', job_1, '%') AND DATE(pickup_date)=CURDATE() ;
SELECT COUNT(*) INTO noida_jobs FROM cab_booking WHERE cab_booking.pickup_area LIKE CONCAT('%', job_2, '%') AND DATE(pickup_date)=CURDATE() ;
SELECT COUNT(*) INTO faridabad_jobs FROM cab_booking WHERE cab_booking.pickup_area LIKE CONCAT('%', job_3, '%') AND DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO gurgaon_jobs FROM cab_booking WHERE cab_booking.pickup_area LIKE CONCAT('%', job_4, '%') AND DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO outstation_jobs FROM cab_booking WHERE DATE(pickup_date)=CURDATE() AND booking_type=104;
SELECT COUNT(*) INTO railway_jobs FROM cab_booking WHERE drop_area LIKE '%railway%' AND DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO cancel_jobs FROM cab_booking WHERE `status`=10 AND DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO airport_jobs FROM cab_booking WHERE `booking_type`=103 AND DATE(pickup_date)=CURDATE();
SELECT COUNT(*) INTO job_advance FROM cab_booking WHERE pickup_date>CURDATE();
SELECT SUM(booking_charges.totalBill) into cash_duty_val FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE() and payment_type='CASH';
SELECT SUM(booking_charges.totalBill) into credit_duty_val FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE() and payment_type='CREDIT';
SELECT SUM(booking_charges.totalBill) into total_revenue_val FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE();
SELECT SUM(booking_charges.totalBill) into local_val FROM booking_charges JOIN cab_booking ON booking_charges.BookingID=cab_booking.ID WHERE date(booking_charges.AddedTime)=CURDATE() and cab_booking.booking_type=101;
SELECT SUM(booking_charges.totalBill) into point_val FROM booking_charges JOIN cab_booking ON booking_charges.BookingID=cab_booking.ID WHERE date(booking_charges.AddedTime)=CURDATE() and cab_booking.booking_type=102;
SELECT SUM(booking_charges.totalBill) into air_val FROM booking_charges JOIN cab_booking ON booking_charges.BookingID=cab_booking.ID WHERE date(booking_charges.AddedTime)=CURDATE() and cab_booking.booking_type=103;
SELECT SUM(booking_charges.totalBill) into outstation_val FROM booking_charges JOIN cab_booking ON booking_charges.BookingID=cab_booking.ID WHERE date(booking_charges.AddedTime)=CURDATE() and cab_booking.booking_type=104;
SELECT COUNT(*) into job_completed FROM cab_booking WHERE cab_booking.`Status` IN (8,11,12) and pickup_date=CURDATE();
SELECT country.currency into currency fROM country WHERE country.country_name='India';
SELECT COUNT(*) into cash_val FROM cab_booking WHERE cab_booking.`Status`=11 and pickup_date=CURDATE();
SELECT COUNT(*) into credit_val FROM cab_booking WHERE cab_booking.`Status`=12 and pickup_date=CURDATE();
SELECT COUNT(*) into local_book FROM cab_booking WHERE cab_booking.booking_type=101 and pickup_date=CURDATE();
SELECT COUNT(*) into point_book FROM cab_booking WHERE cab_booking.booking_type=102 and pickup_date=CURDATE();
SELECT COUNT(*) into airport_book FROM cab_booking WHERE cab_booking.booking_type=103 and pickup_date=CURDATE();
SELECT COUNT(*) into outstation_book FROM cab_booking WHERE cab_booking.booking_type=104 and pickup_date=CURDATE();
SELECT COUNT(*) into web_app FROM cab_booking WHERE partner=1 and pickup_date=CURDATE();
SELECT COUNT(*) into call_center FROM cab_booking WHERE partner=3 and pickup_date=CURDATE();
SELECT COUNT(*) into user_app FROM cab_booking WHERE partner=2 and pickup_date=CURDATE();
SELECT SUM((booking_charges.totalBill*booking_charges.drivershare)/100) into driver_sh FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE();
SELECT SUM((booking_charges.totalBill*booking_charges.companyshare)/100) into company_sh FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE();
SELECT SUM((booking_charges.totalBill*booking_charges.partnershare)/100) into partner_sh FROM booking_charges WHERE date(booking_charges.AddedTime)=CURDATE();
SELECT partner_sh,company_sh,driver_sh,web_app,call_center,user_app,local_book,point_book,airport_book,outstation_book,cash_val,credit_val,job_completed,CONCAT(currency,' ',local_val) as local_val,CONCAT(currency,' ',point_val) as point_val,CONCAT(currency,' ',air_val) as air_val,CONCAT(currency,' ',total_revenue_val) as total_revenue_val,CONCAT(currency,' ',cash_duty_val) as cash_duty_val, CONCAT(currency,' ',credit_duty_val) as credit_duty_val,taxis_reg,taxis_road,taxis_logged_in,taxis_logged_off,driver_blocked,taxis_not_functional,taxis_available,total_jobs,delhi_jobs,noida_jobs,faridabad_jobs,gurgaon_jobs,outstation_jobs,railway_jobs,cancel_jobs,airport_jobs,taxis_busy,taxis_free,job_in_progress,job_advance;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_admin_login` (IN `username_i` VARCHAR(50), IN `password_i` VARCHAR(100), IN `ipaddress` TEXT)  NO SQL BEGIN
DECLARE check_login INT;
DECLARE id_s INT;

IF check_login>0 THEN
SELECT *,check_login FROM web_admin WHERE `email`=username_i;
INSERT INTO admin_log (adminId,`login_time`,login_date,lat,`log`,ipaddress) VALUES (id_s,NOW(),CURDATE(),'','',ipaddress);
ELSE
SELECT check_login;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_admin_text` (IN `id` INT, IN `type_in` INT)   BEGIN
SELECT * FROM admin_text WHERE page=`id` and (`type`=type_in or `type`='0');
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_admin_text_module` (IN `module_i` VARCHAR(50), IN `type_in` INT)   BEGIN
SELECT * FROM admin_text WHERE admin_text.module = module_i and (`type`=type_in or `type`='0');
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_auth` (IN `api_key` VARCHAR(200))  NO SQL BEGIN
DECLARE check_auth int;
SELECT COUNT(*) INTO check_auth FROM client WHERE clientKey=api_key;
SELECT check_auth;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_a_booking_information` (IN `booking_id` INT)   BEGIN SELECT
  cab_status.status_id,
  cab_status.`status` AS `status`,
  IF(
    booking.`status` IN(10,
    17,
    20,
    21),
    1,
    0
  ) AS `cancel_status`,
  DATE_FORMAT(
    booking_logs.`time`,
    '%Y-%m-%d %H:%i:%s'
  ) AS `time`,
  `message`,
  apitime.api_time,
  apitime.api_distance
FROM
  booking
JOIN
  cab_status ON booking.`status` = cab_status.`status_id`
LEFT JOIN
  booking_logs ON booking_logs.`Status` = cab_status.`status_id` AND booking_logs.bookingid = booking_id
LEFT JOIN 
 api_call_timeinterval AS apitime ON booking.master_package_id = apitime.package_id
WHERE
  booking.booking_id = booking_id AND cab_status.`type` = 'cab';
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_a_booking_information_old` (IN `booking_id` INT, IN `token_val` VARCHAR(50))   BEGIN
SELECT cab_status.`status` as `status`,`time`,`message` FROM booking_logs JOIN cab_status ON booking_logs.`Status`=cab_status.`status_id`
INNER JOIN cab_booking ON booking_logs.bookingid = cab_booking.ID INNER JOIN user ON cab_booking.pickup = user.ID
WHERE booking_logs.bookingid=booking_id and user.token = token_val and cab_status.`type`='cab';
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_a_payment_information` (IN `booking_id` INT, IN `token_val` VARCHAR(50))   BEGIN
SELECT booking_bill.CabName as cab_name,addedtime,cancellation_price,waitingCharge,tripCharge,total_tax_price,totalBill,is_paid,paid_at,currency,invoice_number,payment_type,fees,total_price,total_tax_price,duration_rate,starting_rate,base_price,tax_price,starting_charge,distance_charge,duration_charge,minimum_price,cab_booking.*
FROM cab_booking
LEFT JOIN booking_charges ON cab_booking.id=booking_charges.bookingid
LEFT JOIN booking_bill ON cab_booking.CarType=booking_bill.Id 
INNER JOIN driver ON cab_booking.pickup = driver.UID INNER JOIN user ON  driver.UID = user.ID
WHERE cab_booking.id=booking_id and user.token = token_val; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_details` ()   BEGIN
SELECT bk.booking_id as id,bk.driver_id,bk.reference_number as ref,us2.id as client_id,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
 CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
  CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
  CONCAT(
    bpd.drop_address,
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
   bpd.pickup_date >= CURDATE() AND bk.status <= 8
ORDER BY
  bk.booking_id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_details_date` (IN `date_n` DATE, IN `hour_n` INT)   BEGIN
IF hour_n=0
THEN
SELECT bk.booking_id as id,bk.driver_id,bk.reference_number as ref,us2.id as client_id,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
hour(bpd.pickup_time),
 CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
  CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
  CONCAT(
    bpd.drop_address,
    ' ',
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
   bpd.pickup_date = date_n AND bk.status <= 8   
ORDER BY
  bk.booking_id DESC;
ELSE
SELECT bk.booking_id as id,bk.driver_id,bk.reference_number as ref,us2.id as client_id,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
lp.price as local_package_price,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
hour(bpd.pickup_time),
 CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
  CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
  CONCAT(
    bpd.drop_address,
    ' ',
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
   bpd.pickup_date = date_n AND hour(bpd.pickup_time) = hour_n AND bk.status <= 8   
ORDER BY
  bk.booking_id DESC;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_details_date_bookingtype` (IN `date_n` DATE, IN `btype` INT)   BEGIN
SELECT bk.booking_id as id,bk.driver_id,bk.reference_number as ref,us2.id as client_id,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
hour(bpd.pickup_time),
 CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
  CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
  CONCAT(
    bpd.drop_address,
    ' ',
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
   bpd.pickup_date = date_n AND bk.master_package_id = btype AND bk.status <= 8   
ORDER BY
  bk.booking_id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_details_date_old` (IN `date_n` DATE, IN `hour_n` INT)   BEGIN
IF hour_n=0
THEN
SELECT hour(cab_booking.pickup_time),booking_charges.totalBill AS amount,master_package.icon_image,(booking_charges.totalBill*booking_charges.companyshare/100) 
AS cAmount,(booking_charges.totalBill*booking_charges.drivershare/100) AS dAmount,
(booking_charges.totalBill*booking_charges.partnershare/100) AS pAmount,
booking_charges.companyshare AS cshare,booking_charges.drivershare AS dshare,
booking_charges.partnershare AS pshare,complaint.ID as com_id,
complaint.StatusID as com_status, cab_booking.CSR_ID as emp,
CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.ID as id,
booking_charges.totalBill, cab_booking.booking_reference as ref,
master_package.Master_Package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,
concat(client.clientName,'<br>(',appid.`type`,')') as partner,
REPLACE(cab_master.CabName,'·','') as vehicle,
CONCAT(user_info.first_name," ",user_info.last_name) as clientname,user_info.alternate_contact_no as alt_no,
CONCAT(driver.first_name," ",driver.last_name) as driver_name, 
user_info.mobile_no as mob_no,user_info.uid as client_id,driver.UID as driver_id,
CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,
driver.vehicle_reg_no as reg,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
 JOIN user_info ON user_info.uid=cab_booking.client_id 
 JOIN master_package ON cab_booking.booking_type=master_package.package_id 
 LEFT JOIN driver ON cab_booking.pickup=driver.uid 
 LEFT JOIN cab_master ON driver.vehicle_id=cab_master.CabId 
 JOIN appid ON appid.id=cab_booking.partner 
 JOIN client ON appid.clientId=client.id 
 LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID 
 LEFT JOIN complaint ON cab_booking.booking_reference=complaint.BookingID 
 WHERE cab_status.`type`='cab' and cab_booking.pickup_date=date_n and cab_booking.status<=8 order by cab_booking.ID desc;   
ELSE
SELECT booking_charges.totalBill AS amount,master_package.icon_image,(booking_charges.totalBill*booking_charges.companyshare/100) 
AS cAmount,(booking_charges.totalBill*booking_charges.drivershare/100) AS dAmount,
(booking_charges.totalBill*booking_charges.partnershare/100) AS pAmount,
booking_charges.companyshare AS cshare,booking_charges.drivershare AS dshare,
booking_charges.partnershare AS pshare,complaint.ID as com_id,
complaint.StatusID as com_status, cab_booking.CSR_ID as emp,
CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.ID as id,
booking_charges.totalBill, cab_booking.booking_reference as ref,
master_package.Master_Package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,
concat(client.clientName,'<br>(',appid.`type`,')') as partner,
REPLACE(cab_master.CabName,'·','') as vehicle,
CONCAT(user_info.first_name," ",user_info.last_name) as clientname,user_info.alternate_contact_no as alt_no,
CONCAT(driver.first_name," ",driver.last_name) as driver_name, 
user_info.mobile_no as mob_no,user_info.uid as client_id,driver.UID as driver_id,
CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,
driver.vehicle_reg_no as reg,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
 JOIN user_info ON user_info.uid=cab_booking.client_id 
 JOIN master_package ON cab_booking.booking_type=master_package.package_id 
 LEFT JOIN driver ON cab_booking.pickup=driver.uid 
 LEFT JOIN cab_master ON driver.vehicle_id=cab_master.CabId
 JOIN appid ON appid.id=cab_booking.partner 
 JOIN client ON appid.clientId=client.id 
 LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID 
 LEFT JOIN complaint ON cab_booking.booking_reference=complaint.BookingID 
 WHERE cab_status.`type`='cab' and cab_booking.pickup_date=date_n and hour(cab_booking.pickup_time)=hour_n and cab_booking.status<=8 order by cab_booking.ID desc;   
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_details_old` ()   BEGIN
SELECT master_package.icon_image,booking_charges.totalBill AS amount,(booking_charges.totalBill*booking_charges.companyshare/100) 
AS cAmount,(booking_charges.totalBill*booking_charges.drivershare/100) AS dAmount,
(booking_charges.totalBill*booking_charges.partnershare/100) AS pAmount,
booking_charges.companyshare AS cshare,booking_charges.drivershare AS dshare,
booking_charges.partnershare AS pshare,complaint.ID as com_id,
complaint.StatusID as com_status, cab_booking.csr_id as emp,
CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.id as id,
booking_charges.totalBill, cab_booking.booking_reference as ref,
master_package.master_package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,
concat(client.clientName,'<br>(',appid.`type`,')') as partner,
REPLACE(cab_master.CabName,'·','') as vehicle,
CONCAT(user_info.first_name," ",user_info.last_name) as clientname,user_info.alternate_contact_no as alt_no,
CONCAT(driver.first_name," ",driver.last_name) as driver_name, 
user_info.mobile_no as mob_no,cab_booking.charge_type,user_info.uid as client_id,driver.uid as driver_id,
CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,
driver.vehicle_reg_no as reg,cab_status.`status` as `status`
 FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
 JOIN user_info ON user_info.uid=cab_booking.client_id 
 JOIN master_package ON cab_booking.booking_type=master_package.package_id 
 LEFT JOIN driver ON cab_booking.pickup=driver.uid 
 LEFT JOIN cab_master ON driver.vehicle_id=cab_master.CabId
 JOIN appid ON appid.id=cab_booking.partner 
 JOIN client ON appid.clientId=client.id 
 LEFT JOIN booking_charges ON cab_booking.id=booking_charges.BookingID 
 LEFT JOIN complaint ON cab_booking.booking_reference=complaint.BookingID 
 WHERE cab_status.`type`='cab' and cab_booking.`pickup_date`>=CURDATE() and cab_booking.`status` <=8 order by cab_booking.id desc; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_booking_information` (IN `booking_id` INT)  NO SQL BEGIN
SELECT
bk.booking_id as id,bk.reference_number as ref,
CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as payment_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
CONCAT(
    bpd.drop_address,
    ' ',
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
FROM booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
  bk.booking_id = booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_client_info` (IN `user_id` INT)   BEGIN
SELECT 
user.create_date,
user.id,
user.referral_key,
user.login_name,
user_info.email,
user_info.first_name,
user_info.last_name,
user_info.mobile_no,
user_info.image,
	user_info.alt_email,
	user_info.alternate_contact_no,
	user_info.country,
	user_info.state,
	user_info.city,
	user_info.address1,
	user_info.address2,
	user_info.pincode,
	user_info.bank_account_name,
	user_info.acount_holder,
	user_info.bank_adds,
	user_info.account_no,
	user_info.rtgs_neft,
	user_info.ibn,
user_info.`language`  FROM user JOIN user_info ON user.id=user_info.uid WHERE user.id=user_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_client_information` (IN `client_id` INT)   BEGIN
SELECT * FROM user_info WHERE user_id=client_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_client_list` ()   BEGIN
SELECT user.id,
		 CONCAT(user_info.first_name,' ',user_info.last_name) as name,
		 user.login_name AS Email,
		 user.user_no AS ContactNumber,
		 user.create_date,
		 user.user_type,
		 Count(user.id) as booking 
FROM user 
JOIN user_info ON user.id=user_info.uid 
LEFT JOIN cab_booking ON user.id=cab_booking.client_id 
WHERE user.is_verified=1 and user.user_type IN (1,2) 
GROUP BY (user.id);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_driver_confirm` (IN `driver_id` INT, IN `stat` INT)   BEGIN
IF stat!=3 THEN
SELECT booking.*,vt.vehicle_type,pd.pickup_time,pd.pickup_date,pd.pickup_area,pd.drop_address FROM booking join master_vehicle_type as vt ON booking.master_vehicle_type_id = vt.id JOIN booking_pickdrop_details as pd ON booking.booking_id=pd.booking_id WHERE booking.driver_id=driver_id and booking.`status`=stat order by booking.booking_id desc;
END IF;
IF stat=3 THEN
SELECT booking.*,vt.vehicle_type,pd.pickup_time,pd.pickup_date,pd.pickup_area,pd.drop_address FROM booking JOIN booking_pickdrop_details as pd ON booking.booking_id=pd.booking_id join master_vehicle_type as vt ON booking.master_vehicle_type_id = vt.id  WHERE booking.driver_id=driver_id and booking.`status`<6 and CONCAT(pd.pickup_date,' ',pd.pickup_time)>NOW() order by booking.booking_id desc;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_driver_confirm_old` (IN `driver_id` INT, IN `stat` INT)   BEGIN
IF stat!=3 THEN
SELECT * FROM cab_booking WHERE pickup=driver_id and `status`=stat order by id desc;
END IF;
IF stat=3 THEN
SELECT * FROM cab_booking WHERE pickup=driver_id and `status`<6 and CONCAT(cab_booking.PickupDate,' ',cab_booking.PickupTime)>NOW() order by id desc;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_latest_booking` (IN `lim` INT)  NO SQL BEGIN
SELECT cab_booking.ID as id,cab_booking.bookingdate as ordertime,"dfdfdfd",CONCAT(user_info.FirstName," ",user_info.LastName) as clientname,cab_booking.Departure as departure,booking_status.`status` as `status` FROM cab_booking JOIN booking_status ON cab_booking.`status`=booking_status.`id` JOIN user_info ON user_info.UID=cab_booking.ClientID LEFT JOIN driver ON cab_booking.pickup=driver.uid order by cab_booking.id desc LIMIT 0,lim ;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_list_booking` (IN `datea` DATE)   BEGIN
SELECT
  bk.booking_id as id,
  bk.driver_id,
  CONCAT(
    CLIENT.first_name,
    '(',
    appid.`type`,
    ')'
  ) AS partner,
  bk.reference_number AS ref,
  HOUR(bk.booking_date) AS HOUR,
  mp.name  AS booking_type,
  CONCAT(
    driver.`first_name`,
    " ",
    driver.`last_name`
  ) AS driver,
  CONCAT(
    user_info.`first_name`,
    " ",
    user_info.`last_name`
  ) AS clientname,
  user_info.mobile AS ContactNo,
  cs.`status` AS `status`,
  bk.booking_date,
  bpd.pickup_address as pickup_location,
  bpd.pickup_area
FROM
  booking as bk
JOIN
  user as user_info ON bk.user_id = user_info.id
LEFT JOIN 
  user as driver ON bk.driver_id=driver.id
JOIN 
  master_package as mp ON bk.master_package_id = mp.id
JOIN  
  cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
LEFT join 
  booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
JOIN
  appid ON bk.partner = appid.id
JOIN 
  user as CLIENT ON bk.client_id = CLIENT.id
WHERE
  DATE(bk.booking_date) = datea AND bpd.`pickup_date` >= CURDATE()
ORDER BY
  bk.booking_id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_list_booking_old` (IN `datea` DATE)   BEGIN
SELECT `cab_booking`.id as id,concat(client.clientName,'(',appid.`type`,')') as partner,cab_booking.booking_reference as ref,HOUR(`booking_date`) as hour,cab_booking.booking_type as booking_type,CONCAT(driver.`first_name`," ",driver.`last_name`) as driver,CONCAT(user_info.`first_name`," ",user_info.`last_name`) as clientname, user_info.mobile_no as ContactNo,cab_status.`status` as `status`,`booking_date`,`pickup_location`,`pickup_area` FROM cab_booking JOIN user_info ON cab_booking.client_id=user_info.uid JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` JOIN appid ON cab_booking.partner=appid.id JOIN client ON client.id=appid.clientId LEFT JOIN driver on cab_booking.pickup=driver.UID WHERE date(cab_booking.booking_date)=datea and cab_booking.`pickup_date`>=CURDATE() and cab_status.`type`='cab' order by cab_booking.id desc;    
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_list_hour_booking` (IN `i_date` DATE, IN `i_time` INT)   BEGIN
IF i_time=0 THEN
SELECT COUNT(*) as no_of,HOUR(`pickup_time`) as `hour` FROM booking_pickdrop_details WHERE pickup_date=i_date GROUP BY HOUR(`pickup_time`);
ELSE
SELECT COUNT(*) as no_of,HOUR(`pickup_time`) as `hour` FROM booking_pickdrop_details WHERE pickup_date=i_date and hour(`pickup_time`)=i_time;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_list_hour_booking_old` (IN `i_date` DATE, IN `i_time` INT)   BEGIN
IF i_time=0 THEN
SELECT COUNT(*) as no_of,HOUR(`pickup_time`) as `hour` FROM cab_booking WHERE pickup_date=i_date GROUP BY HOUR(`pickup_time`);
ELSE
SELECT COUNT(*) as no_of,HOUR(`pickup_time`) as `hour` FROM cab_booking WHERE pickup_date=i_date and hour(`pickup_time`)=i_time;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_list_package_wise_booking` (IN `i_date` DATE, IN `i_time` INT)   BEGIN
IF i_time=0 THEN
SELECT COUNT(*) as no,bk.master_package_id AS booking_type FROM booking_pickdrop_details as bpd
join booking AS bk ON bk.booking_id = bpd.booking_id
WHERE bpd.pickup_date=i_date GROUP BY (bk.master_package_id);
ELSE
SELECT COUNT(*) as no,bk.master_package_id AS booking_type FROM booking_pickdrop_details as bpd
join booking AS bk ON bk.booking_id = bpd.booking_id
WHERE bpd.pickup_date=i_date and hour(bpd.`pickup_time`)=i_time GROUP BY (bk.master_package_id);
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_login_logs` (IN `driver_id` INT)  NO SQL BEGIN
SELECT login_time,logout_time,login_diff,DATE(log_in_log.login_time) as `date`,TIMEDIFF(logout_time,login_time) as diff from log_in_log WHERE userid=driver_id ORDER by id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_login_logs_2` (IN `driver_id` INT, IN `log_time` DATE)   BEGIN
SELECT login_time,logout_time,DATE(log_in_log.login_time) as `date`,TIMEDIFF(logout_time,login_time) as diff from log_in_log WHERE userid=driver_id and date(login_time)=log_time ORDER by id desc;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_login_logs_week` (IN `driver_id` INT, IN `since` DATE, IN `too` DATE)   BEGIN
SELECT login_time,logout_time,DATE(log_in_log.login_time) as `date`,TIMESTAMPDIFF(second,login_time,logout_time) as diff from log_in_log 
WHERE userid=driver_id and date(login_time) BETWEEN date(since) AND date(too);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_payment_information` (IN `booking_id` INT)  NO SQL BEGIN
SELECT
bk.booking_id as ID,bk.reference_number as booking_reference,
CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
bk.is_corportate,
bk.is_account,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as payment_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date as BookingDate,
bk.created_date as addedtime,
cs.status,
bkest.*,
bkest.estimateprice_before_discount as total_price,
bkest.discount_price as total_discount,
bkest.estimated_final_price as final_price,
bkest.booking_amt_percentage as paid_amt_percentage,
bkest.booking_amt_paid as paid_amount,
bkest.booking_amt_balance as balance_amount,
bkest.estimated_distance as EstimatedDistance,
bkest.estimated_time as EstimatedTime,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_date as PickupDate,
bpd.pickup_time as PickupTime,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_area as PickupArea,
bpd.pickup_address as PickupAddress,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_address as DropAddress,
bpd.drop_area as DropArea,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
FROM
   booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
WHERE
  bk.booking_id = booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_payment_information_old` (IN `booking_id` INT)  NO SQL BEGIN
SELECT cab_master.CabName as cab_name,driver.vehicle_id,addedtime,cancellation_price,waitingCharge,tripCharge,total_tax_price,totalBill,is_paid,paid_at,currency,invoice_number,payment_type,fees,total_price,total_tax_price,duration_rate,starting_rate,base_price,tax_price,starting_charge,distance_charge,duration_charge,minimum_price,cab_booking.*
FROM cab_booking 
LEFT JOIN booking_charges ON cab_booking.id=booking_charges.bookingid 
LEFT JOIN driver ON cab_booking.pickup=driver.uid
LEFT JOIN cab_master ON driver.vehicle_id=cab_master.CabId
WHERE cab_booking.id=booking_id; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_w_user_edit_profile` (IN `fname` VARCHAR(50), IN `lname` VARCHAR(50), IN `mob` BIGINT, IN `landline` VARCHAR(50), IN `email` VARCHAR(50), IN `altemail` VARCHAR(50), IN `company` VARCHAR(50), IN `address` VARCHAR(50), IN `res_addr` VARCHAR(50), IN `id_i` INT, IN `altMobile` INT)   BEGIN
Declare com_id INT;
SELECT company.ID as com_id from company
 INNER JOIN user_info ON user_info.CompanyID = company.ID
 where user_info.UID = id_i;
UPDATE user SET LoginName = email, UserNo = mob WHERE ID = id_i;
UPDATE user_info SET FirstName = fname, LastName = lname, MobNo = mob, LandNo = landline, Email = email,
AltEmail = altemail,Address1 = address,Address2 = res_addr,AlternateContactNo=altMobile WHERE UID = id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_activation_user` (IN `verify` VARCHAR(210), IN `token` VARCHAR(150))   BEGIN
DECLARE verifyTotal INT;
DECLARE uerrid VARCHAR(50);
SELECT COUNT(*) ,UID INTO verifyTotal,uerrid FROM `tblactivation` WHERE `Verification_code` = verify AND `isUsed`=0 LIMIT 0,1;
IF verifyTotal=1 THEN
UPDATE `tblactivation` SET `isUsed` =  '1' WHERE `UID` = uerrid;
UPDATE `user` SET `isVerified` =  '1' WHERE `ID` = uerrid;
UPDATE `user` SET `token`= token WHERE `ID` = uerrid;
END IF;
SELECT verifyTotal,uerrid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_app_chat_list` (IN `driver_id` INT)   BEGIN
SELECT distinct bookingid,CONCAT (user_info.Firstname," ",user_info.LastName) as name,user_info.UID as userid from booking_msg JOIN cab_booking ON booking_msg.bookingid=cab_booking.ID JOIN user_info ON user_info.UID=cab_booking.ClientID WHERE booking_msg.sender=driver_id or booking_msg.receiver=driver_id order by booking_msg.id desc;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_action_type_info_by_id` (IN `action_Id_i` INT)   BEGIN
SELECT * FROM tblactiontype WHERE id = action_Id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_add_device` (IN `dUnit` INT, IN `dpickDate` VARCHAR(50), IN `dactiveDate` VARCHAR(50), IN `dSim` INT, IN `dPort` INT, IN `taxiId` VARCHAR(50))   BEGIN
DECLARE untid INT;
SELECT COUNT(`unit_no`) INTO untid FROM `device` WHERE `unit_no` = dUnit;
IF untid < 1 THEN  
INSERT INTO `device` (`unit_no`,`purchase_date`,`activation_date`,`sim_no`,`port`,`taxiNoId`,`status`) VALUES (dUnit,dpickDate,dactiveDate,dSim,dPort,taxiId,1);
END IF;
SELECT LAST_INSERT_ID() AS devicesId,untid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_add_vehicle` (IN `cabtype_i` INT(10), IN `vehicle_model_i` VARCHAR(100), IN `external_reference_i` VARCHAR(100), IN `year_i` INT(20), IN `license_plate_i` VARCHAR(100), IN `colour_i` VARCHAR(100), IN `engine_no_i` VARCHAR(100), IN `fueltype_i` VARCHAR(100), IN `capacity_i` INT(10), IN `status_i` INT(10))  NO SQL BEGIN
DECLARE vehicle_exists int;
SELECT COUNT(*) INTO vehicle_exists FROM `cab_list_mgmt` WHERE `Engine_No`  =engine_no_i OR `license_plate`  =license_plate_i;
IF vehicle_exists =0 THEN
INSERT INTO `cab_list_mgmt` (`CabType`,`VehicleModel`,`external_reference`,`year`,`license_plate`,`colour`,`Engine_No`,`fuelType`,`capacity`,`status`) values(cabtype_i,vehicle_model_i,external_reference_i,year_i,license_plate_i,colour_i,engine_no_i,fueltype_i,capacity_i,status_i);
END IF;
SELECT vehicle_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_add_vehicle_type` (IN `cabname_i` TEXT, IN `city_i` TEXT)  NO SQL BEGIN
DECLARE id_s int;
DECLARE cabtype_exists int;
SELECT COUNT(*) INTO cabtype_exists FROM `booking_bill` WHERE `CabName` COLLATE latin1_general_ci =cabname_i AND `CityId`=city_i;
IF cabtype_exists =0 THEN
INSERT INTO `booking_bill` (`CabName`,`cityId`) values(cabname_i,city_i);
SET id_s=LAST_INSERT_ID();
UPDATE `booking_bill` SET `cabType`=id_s WHERE id=id_S;
END IF;
SELECT cabtype_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_bank_update` (IN `dids` INT, IN `bankName` VARCHAR(50), IN `holderName` VARCHAR(50), IN `bAdds` VARCHAR(50), IN `anos` VARCHAR(50), IN `neft` VARCHAR(50), IN `ibnos` VARCHAR(50))   BEGIN
UPDATE `driver` SET `bank_account_name`=bankName,`acount_holder`=holderName,`bank_adds`=bAdds,`account_no`=anos,`rtgs_neft`=neft,`ibn`=ibnos WHERE `UID`=dids;
SELECT ROW_COUNT() AS count;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_booking_complaint_list` ()   BEGIN
SELECT complaint.ID as com_id,complaint.StatusID as com_status, cab_booking.csr_id as emp,CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.id as id,booking_charges.totalBill, cab_booking.booking_reference as ref,master_package.master_package as booking_type,CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,concat(client.clientName,'<br>(',appid.`type`,')') as partner,REPLACE(vehicle_type.vehicle_type,'·','') as vehicle,CONCAT(user_info.first_name," ",user_info.last_name) as clientname,CONCAT(driver.first_name," ",driver.last_name) as driver_name, user_info.mobile_no as mob_no,user_info.uid as client_id,driver.uid as driver_id,CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,driver.vehicle_reg_no as reg,cab_status.`status` as `status` FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` JOIN user_info ON user_info.uid=cab_booking.client_id JOIN master_package ON cab_booking.booking_type=master_package.package_id LEFT JOIN driver ON cab_booking.pickup=driver.uid LEFT JOIN vehicle_type ON driver.vehicle_type=vehicle_type.id JOIN appid ON appid.id=cab_booking.partner JOIN client ON appid.clientId=client.id LEFT JOIN booking_charges ON cab_booking.id = booking_charges.BookingID INNER JOIN complaint ON cab_booking.booking_reference = complaint.BookingID WHERE cab_status.`type`='cab' order by cab_booking.id desc;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_cab_package_calculation` (IN `local_package` VARCHAR(50), IN `point_to_point_package` VARCHAR(50), IN `airport_package` VARCHAR(50), IN `outstation_package` VARCHAR(50))   BEGIN
DECLARE localPackage varchar(50);
DECLARE pointToPointPackage varchar(50);
DECLARE airportPackage varchar(50);
DECLARE outstationPackage varchar(50);
SELECT tblsubpackage.Sub_Package_Id INTO localPackage FROM tblsubpackage WHERE tblsubpackage.Sub_Package_Name = local_package;
SELECT tblsubpackage.Sub_Package_Id INTO pointToPointPackage FROM tblsubpackage WHERE tblsubpackage.Sub_Package_Name = point_to_point_package;
SELECT tblsubpackage.Sub_Package_Id INTO airportPackage FROM tblsubpackage WHERE tblsubpackage.Sub_Package_Name = airport_package;
SELECT tblsubpackage.Sub_Package_Id INTO outstationPackage FROM tblsubpackage WHERE tblsubpackage.Sub_Package_Name = outstation_package;
UPDATE master_package SET master_package.Sub_Package_Id = localPackage where master_package.Master_Package = 'Local';
UPDATE master_package SET master_package.Sub_Package_Id = pointToPointPackage where master_package.Master_Package = 'Point To Point';
UPDATE master_package SET master_package.Sub_Package_Id = airportPackage where master_package.Master_Package = 'Airport Terminal';
UPDATE master_package SET master_package.Sub_Package_Id = outstationPackage where master_package.Master_Package = 'Outstation';
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_client_bank_update` (IN `cids` INT, IN `bankName` VARCHAR(50), IN `holderName` VARCHAR(50), IN `bAdds` VARCHAR(50), IN `anos` VARCHAR(50), IN `neft` VARCHAR(50), IN `ibnos` VARCHAR(50))   BEGIN
UPDATE `user_info` SET `bank_account_name`=bankName,`acount_holder`=holderName,`bank_adds`=bAdds,`account_no`=anos,`rtgs_neft`=neft,`ibn`=ibnos WHERE `uid`=cids;
SELECT ROW_COUNT() AS count;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_client_update_profile` (IN `cids` INT, IN `fname` VARCHAR(50), IN `lname` VARCHAR(50), IN `lang` INT, IN `email` VARCHAR(50), IN `cnt_no` VARCHAR(50), IN `alt_email` VARCHAR(50), IN `alt_cnt_no` VARCHAR(50), IN `country` INT, IN `state` INT, IN `city` INT, IN `address1` TEXT, IN `address2` TEXT, IN `pin_code` VARCHAR(10))   BEGIN
DECLARE tablecount INT;
DECLARE usercount INT;
UPDATE `user_info` SET `first_name`=fname,`last_name`=lname,`alt_email`=alt_email,`country`=country,`state`=state,`city`=city,`address1`=address1,`address2`=address2,`pincode`=pin_code,`mobile_no`=cnt_no,`alternate_contact_no`=alt_cnt_no WHERE `uid`=cids;
SELECT ROW_COUNT() INTO tablecount;
UPDATE `user` SET `login_name`=email WHERE `id`=cids;
SELECT ROW_COUNT() as tablecountuser, tablecount;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_complaint_type_info_by_id` (IN `complaint_id_i` INT)   BEGIN
SELECT sub_complaint.id, enquiry_type.enquiry_type, sub_complaint.sub_complaint FROM enquiry_type INNER JOIN sub_complaint ON enquiry_type.id = sub_complaint.complaint_type WHERE sub_complaint.id = complaint_id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_delete_action_type` (IN `id_i` INT)   BEGIN
DELETE FROM tblactiontype WHERE id = id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_delete_complaint_type` (IN `id_i` INT)   BEGIN
DELETE FROM sub_complaint WHERE id = id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_delete_enquiry_type` (IN `id_i` INT)   BEGIN
DELETE FROM enquiry_type WHERE id = id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_device_delete` (IN `deviceid` INT)   BEGIN
UPDATE `device` SET `status` = 0 WHERE `unit_no` = deviceid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_device_edit` (IN `idDevice` INT)   BEGIN
SELECT a.*,b.vehicleNumber FROM `device` a INNER JOIN `cab_list_mgmt` b ON a.taxiNoId = b.id WHERE a.unit_no=idDevice;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_device_list` ()   BEGIN
SELECT a.unit_no,a.purchase_date,a.activation_date,a.sim_no,a.port,b.vehicleNumber FROM `device` a LEFT JOIN `cab_list_mgmt` b ON a.taxiNoId = b.id WHERE a.status=1;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_device_taxi_nos` (IN `data` VARCHAR(50))   BEGIN
SELECT `id`,`vehicleNumber` FROM `cab_list_mgmt` WHERE `vehicleNumber` LIKE CONCAT('%', data , '%');
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_device_update` (IN `dunit` INT, IN `devicepdate` VARCHAR(50), IN `deviceadate` VARCHAR(50), IN `dsim` INT, IN `dport` INT, IN `taxiNos` VARCHAR(50))   BEGIN
UPDATE `device` SET `purchase_date`=devicepdate,`activation_date`=deviceadate,`sim_no`=dsim,`port`=dport,`taxiNoId`=taxiNos WHERE `unit_no` = dunit;
SELECT ROW_COUNT() AS ids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_a_history` (IN `dids` INT)   BEGIN
SELECT * FROM `booking_register` WHERE driverId=dids; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_b_history` (IN `dids` INT)   BEGIN
SELECT bk.booking_id as id,bk.reference_number as ref,
	CONCAT(
    us.first_name,
    " ",
    us.last_name
  ) AS user_name,
  CONCAT(
    us2.first_name,
    " ",
    us2.last_name
  ) AS clientname,
 CONCAT(
    driver.first_name,
    " ",
    driver.last_name
  ) AS driver_name,
lp.name as local_package_id,
lp.hrs as local_package_hrs,
lp.km as local_package_km,
mpm.package_mode,
mp.name  as booking_type,
payty.pay_type_mode as charge_type,
mvt.vehicle_type as vehicle,
bk.no_of_vehicles,
mcoup.name as coupon_name,
bk.booking_date,
cs.status,
bkest.*,
bkest.estimated_final_price as amount,
 CONCAT(
    bpd.pickup_date,
    " ",
    bpd.pickup_time
  ) AS ordertime,
  CONCAT(
    bpd.pickup_address,
    ' ',
    bpd.pickup_area
  ) AS departure,
  CONCAT(
    bpd.drop_address,
    ' ',
    bpd.drop_area
  ) AS drop_area,
bpd.adults,
bpd.childs,
bpd.luggages,
bpd.pickup_country,
bpd.pickup_state,
bpd.pickup_city,
bpd.pickup_landmark,
bpd.pickup_latitude,
bpd.pickup_longitude,
bpd.pickup_zone,
bpd.drop_date,
bpd.drop_time,
bpd.drop_country,
bpd.drop_state,
bpd.drop_city,
bpd.drop_landmark,
bpd.drop_latitude,
bpd.drop_longitude,
bpd.drop_zone
from booking as bk
JOIN user as us ON bk.user_id=us.id
JOIN user as us2 ON bk.client_id=us2.id
LEFT JOIN user as driver ON bk.driver_id=driver.id
JOIN master_package_mode as mpm ON bk.master_package_mode_id = mpm.id 
JOIN master_package as mp ON bk.master_package_id = mp.id 
JOIN master_vehicle_type as mvt ON bk.master_vehicle_type_id = mvt.id
LEFT JOIN master_coupon as mcoup ON bk.coupon_id = mcoup.id
LEFT JOIN local_package as lp ON bk.package_id = lp.id
JOIN cab_status as cs ON bk.status = cs.status_id AND cs.type = 'cab'
JOIN payment_type as payty ON bk.charge_type = payty.payment_type_id
LEFT join 
	booking_estimation as bkest ON bk.booking_id = bkest.booking_id
LEFT join 
	booking_pickdrop_details as bpd ON bk.booking_id=bpd.booking_id
LEFT JOIN
  booking_tracker ON bk.booking_id = booking_tracker.BookingID AND booking_tracker.CabStatus = 3
WHERE
    bk.driver_id = dids
ORDER BY
  bk.booking_id DESC;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_b_history_old` (IN `dids` INT)   SELECT complaint.ID as com_id,complaint.StatusID as com_status, cab_booking.csr_id as emp,booking_charges.totalBill AS amount,(booking_charges.totalBill*booking_charges.companyshare/100) AS cAmount,(booking_charges.totalBill*booking_charges.drivershare/100) AS dAmount,(booking_charges.totalBill*booking_charges.partnershare/100) AS pAmount,booking_charges.companyshare AS cshare,booking_charges.drivershare AS dshare,booking_charges.partnershare AS pshare,
CONCAT(cab_booking.drop_address,cab_booking.drop_area) as drop_area,cab_booking.id as id,
booking_charges.totalBill, cab_booking.booking_reference as ref,master_package.master_package as booking_type,
CONCAT(cab_booking.pickup_date," ",cab_booking.pickup_time) as ordertime,concat(client.clientName,'<br>(',appid.`type`,')') as partner,
CONCAT(user_info.first_name," ",user_info.last_name) as clientname,
CONCAT(driver.first_name," ",driver.last_name) as driver_name, user_info.mobile_no as mob_no,user_info.uid as client_id,cab_master.CabName,cab_booking.basic_tax_price,
driver.uid as driver_id,CONCAT(cab_booking.pickup_address,' ',cab_booking.pickup_area) as departure,driver.vehicle_reg_no as reg,
cab_status.`status` as `status` 
FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` 
JOIN user_info ON user_info.uid=cab_booking.client_id 
JOIN master_package ON cab_booking.booking_type=master_package.package_id 
LEFT JOIN driver ON cab_booking.pickup=driver.uid 
LEFT JOIN cab_master ON cab_master.CabId=driver.vehicle_id  
JOIN appid ON appid.id=cab_booking.partner 
JOIN client ON appid.clientId=client.id 
LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID 
LEFT JOIN complaint ON cab_booking.ID=complaint.BookingID
INNER JOIN booking_tracker ON cab_booking.id=booking_tracker.BookingID WHERE 
cab_status.`type`='cab' AND booking_tracker.CabStatus =3 AND cab_booking.pickup=dids order by cab_booking.id desc$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_cer_down` (IN `dids` INT)   BEGIN
SELECT mdt.doc_level_name,uud.doc_file_upload,mdt.doc_type_id
from master_document_type AS mdt LEFT JOIN user_upload_document AS uud ON mdt.doc_type_id = uud.document_type_id where mdt.type = 'driverC' AND uud.user_id =dids and uud.status=1;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_cer_down_old` (IN `dids` INT)   BEGIN
SELECT `residential_proof`,`office_proof`,`pancard_proof`,`vehicle_proof`,`license_proof`,`police_proof`,`audit_proof`,`rc_proof` FROM `driver` WHERE `user_id`=dids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_cer_update` (IN `dids` INT, IN `resProof` TEXT, IN `ofcProof` TEXT, IN `panProof` TEXT, IN `vproof` TEXT, IN `badgeProof` TEXT, IN `pProof` TEXT, IN `auditproof` TEXT, IN `rcproof` TEXT)   BEGIN
UPDATE `driver` SET `residential_proof`=resProof,`office_proof`=ofcProof,`pancard_proof`=panProof,`vehicle_proof`=vproof,`license_proof`=badgeProof,`police_proof`=pProof,`audit_proof`=auditproof,`rc_proof`=rcproof WHERE `UID`=dids;
SELECT ROW_COUNT() as count;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_contacts` (IN `dids` INT)   BEGIN
SELECT `ContactNo` FROM `driver` WHERE `UID`=dids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_data` ()   BEGIN
SELECT a.UID,a.FirstName,a.Email,a.status,a.ContactNo,a.VehicleRegistrationNo,a.DrivingLicenceNo,a.is_active,a.created_date,b.name as vehicleName,f.status as approvedStatus,
count(pickup) as booking, e.isVerified FROM `driver` a INNER JOIN `cab_list_mgmt` b ON a.vehicleId = b.id LEFT JOIN `cab_booking` d ON a.UID=d.pickup INNER JOIN `user` e ON a.UID = e.ID INNER JOIN `active` f ON  
 e.isVerified=f.status_id group by(UID) ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_edit_group` (IN `gids` INT, IN `dids` INT)   BEGIN
UPDATE `driver` SET `vendor_id`=gids WHERE `UID`=dids;
SELECT ROW_COUNT() AS gedit;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_edit_profile` (IN `driverId` INT)   BEGIN
SELECT
userInfo.id AS ID_user_info,
driver.*,
driver.id AS uid,
  driver.is_verified AS isVerifY,
  driver.email AS userName,
  driver.password AS loginPass,
  driver2.status AS driverStatus, 
  driver2.pancard_no AS pan_card_no,
  driver2.driving_license_no,
  driver2.total_fleet_no,
  driver2.license_validity AS license_validity,
  driver2.operational_company_name,
  driver2.imei,
  driver2.gps,
  driver2.eye_test,
  driver2.photo_verify,
  driver2.zone,
  driver2.route_know,
  mvm.name AS CabName,
  vm.permit_exp_date AS expiry,
  vm.vehicle_no AS vehicle_reg_no,
  vm.vehicle_owner_type AS vehicle_owned,
  vm.vehicle_owner_name,
  vm.vehicle_owner_mobile AS vehicle_owner_cnt_no,
  vm.model AS CabModel,
  vm.registration_number AS CabRegistrationNumber,
  vm.ignition_type_id AS CabIgnitionTypeId,
  vm.rc_no,
  vm.insurance_validity,
  mvt.vehicle_type,
  licenceState.name AS licence_state,
  ignition_type.fuel_type as CabIgnitionType,
  role.RoleName,
  userInfo.image,
  vm.image AS vehicle_image,
  company.company_name as operational_company_name,
  company.company_address AS office_address,
  company.pincode AS company_pincode,
  city.name AS v_city,
  state.name AS v_state,
  country.name AS v_country,
  userInfo.pincode AS v_pin,
  driver.mobile AS contact_no,
  userInfo.father_name,
  userInfo.dob,
  userInfo.address AS Address,
  city.name AS cn,
  state.name AS sn
FROM
    user AS driver
Left JOIN 
      driver AS driver2 on driver.id =  driver2.user_id
Left JOIN 
      master_state AS licenceState ON driver2.license_state =  licenceState.id
LEFT JOIN
  user_info AS userInfo ON driver.id = userInfo.user_id
LEFT JOIN 
 user_role AS role ON driver.user_type_id = role.Role_ID 
LEFT JOIN 
  master_city AS city ON userInfo.city_id = city.id
LEFT JOIN 
  master_state AS state ON userInfo.state_id = state.id
LEFT JOIN
 master_country AS country ON userInfo.country_id = country.id 
LEFT JOIN
  user_vehicle_mapping AS uvm ON driver.id = uvm.user_id
LEFT JOIN
 vehicle_master AS vm ON uvm.vehicle_master_id = vm.vehicle_master_id
LEFT JOIN 
 master_fuel_type AS ignition_type ON vm.ignition_type_id = ignition_type.id
LEFT JOIN 
 master_vehicle_model AS mvm ON  vm.id = mvm.id
LEFT JOIN 
 master_vehicle_type AS mvt ON  mvm.vehicle_type_id = mvt.id
LEFT JOIN
  booking AS bk ON driver.id = bk.driver_id
LEFT JOIN 
  company ON driver.id = company.user_id
LEFT JOIN
  active ON driver2.is_active = active.status_id
WHERE
  driver.id = driverId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_edit_profile_old` (IN `driverId` INT)   BEGIN
DECLARE isVerifY INT;
DECLARE userName VARCHAR(50);
DECLARE loginPass VARCHAR(50);
DECLARE driverStatus INT;
DECLARE ref_Key VARCHAR(50);
SELECT `is_verified`,`login_name`,`password`,`login_status`,`referral_key` into isVerifY,userName,loginPass,driverStatus,ref_Key FROM `user` WHERE `id`= driverId;
SELECT user_info.id as ID_user_info,driver.*,isVerifY,userName,loginPass,driverStatus,ref_Key,cab_master.CabName,cab_master.CabPermitExpDate as expiry, vehicle_type.vehicle_type,driver.licence_state,cab_master.CabModel,cab_master.CabRegistrationNumber, cab_master.CabIgnitionTypeId,ignition_type.CabIgnitionType,vendor.vendor_name, user_info.image,user_info.vehicle_image, 
user.user_type, vendor.group_name,vendor.UID as v_id, vendor.vendor_name, vendor.vendor_email,user_info.city as v_city, user_info.state as v_state, 
user_info.country as v_country, user_info.pincode as v_pin, user_info.mobile_no as v_mob, user_info.address1 as v_address, cities.city_name as cn, states.state as sn,states.state as licence_state, country.country_name as countryName 
FROM `driver` 
INNER JOIN `cab_master` ON driver.vehicle_id = cab_master.CabId 
INNER JOIN `ignition_type` ON ignition_type.id = cab_master.CabIgnitionTypeId
INNER JOIN `vehicle_type` ON vehicle_type.id = cab_master.CabType
LEFT JOIN  `vendor` ON driver.vendor_id=vendor.id 
INNER JOIN user_info ON driver.uid = user_info.uid
LEFT JOIN `cities` ON driver.city = cities.id
LEFT JOIN `states` ON driver.state = states.id AND driver.licence_state = states.id
LEFT JOIN `country` ON driver.country = country.id
INNER JOIN user ON driver.uid = user.id 
WHERE driver.uid=driverId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_email_history` (IN `did` INT)   BEGIN
SELECT * FROM `email_history` WHERE `uid`=did;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_feature_update` (IN `feat` VARCHAR(50), IN `dids` INT)   BEGIN
UPDATE `driver` SET `driver_feature`=feat WHERE `UID`=dids;
SELECT ROW_COUNT() AS features;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_groups_remove` (IN `groups` VARCHAR(50))   BEGIN
SELECT `id`,`group_name` FROM `vendor` WHERE `group_name` LIKE CONCAT('%', groups , '%') LIMIT 0,10; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_group_list` (IN `vids` INT)   BEGIN
SELECT a.UID,a.FirstName,a.ContactNo,a.Email,a.is_active,c.loginStatus,d.name,e.status FROM `driver` a INNER JOIN `vendor` b ON a.vendor_id=b.id INNER JOIN `user` c ON a.UID=c.ID INNER JOIN `cab_list_mgmt` d ON a.vehicleId=d.id INNER JOIN `cab_status` e ON a.is_active=e.status_id WHERE b.UID = vids AND e.`type`='driverS';
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_group_name` (IN `driverid` INT)   BEGIN
SELECT a.group_name FROM vendor a INNER JOIN driver b ON a.id=b.vendor_id WHERE b.UID=driverid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_image_verf` (IN `image` VARCHAR(50), IN `dids` INT)   BEGIN
UPDATE `driver` SET `photo_verify`=image WHERE `uid`=dids;
SELECT ROW_COUNT() AS img;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_list` ()   BEGIN
SELECT
  (
  SELECT
    AVG(rating)
  FROM
    driver_rating
  WHERE
    driver_rating.DID = driver.id
  GROUP BY
    driver_rating.DID
) AS DriverRating,
driver.login_status AS LoginStatus,
driver.is_active AS IsActive,
driver.email,
driver.id as uid,
driver.first_name,
driver.mobile AS contact_no,
city.name as city_name,
vm.registration_number as vehicle_reg_no, 
driver2.driving_license_no,
ignition_type.fuel_type as CabIgnitionType,
driver2.is_active,
driver2.status, 
active.status AS approvedStatus,
driver2.created_date,
mvm.name AS vehicleName,
company.company_name as CompanyName,
COUNT(bk.driver_id) AS booking
FROM
  user AS driver
Left JOIN 
      driver AS driver2 on driver.id =  driver2.user_id
LEFT JOIN
  user_info AS userInfo ON driver.id = userInfo.user_id
LEFT JOIN 
  master_city AS city ON  userInfo.city_id = city.id
LEFT JOIN
  user_vehicle_mapping AS uvm ON driver.id = uvm.user_id
LEFT JOIN
 vehicle_master AS vm ON uvm.vehicle_master_id = vm.vehicle_master_id
LEFT JOIN 
 master_fuel_type AS ignition_type ON vm.ignition_type_id = ignition_type.id
LEFT JOIN 
 master_vehicle_model AS mvm ON  vm.id = mvm.id
LEFT JOIN
  booking AS bk ON driver.id = bk.driver_id
LEFT JOIN 
  company ON driver.id = company.user_id
LEFT JOIN
  active ON driver2.is_active = active.status_id
where driver.user_type_id = 3
GROUP BY  (driver.id);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_list_old` ()   BEGIN
SELECT (SELECT AVG(rating) FROM driver_rating WHERE driver_rating.DID = driver.UID GROUP BY driver_rating.DID) AS DriverRating, user.login_status as LoginStatus,user.is_active as IsActive,driver.email,driver.uid,driver.first_name,driver.status,driver.contact_no,driver.vehicle_reg_no,driver.driving_license_no,
driver.is_active,active.status AS approvedStatus,driver.created_date,cab_master.CabName AS vehicleName, ignition_type.CabIgnitionType ,
count(pickup) AS booking 
FROM driver  
INNER JOIN cab_master ON driver.vehicle_id = cab_master.cabId 
INNER JOIN ignition_type ON ignition_type.id = cab_master.CabIgnitionTypeId
INNER JOIN vehicle_type ON vehicle_type.Id = cab_master.CabType
LEFT JOIN cab_booking ON driver.uid=cab_booking.pickup 
INNER JOIN user ON driver.uid = user.id 
INNER join active on driver.is_active = active.status_id  group by(uid);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_remove_group` (IN `grName` VARCHAR(50))   BEGIN
DECLARE gid INT;
DECLARE lo INT;
SELECT `id` INTO gid FROM `vendor` WHERE `group_name`=grName;
IF gid > 0 THEN
UPDATE `driver` SET `vendor_id`=0 where vendor_id = gid;
SELECT ROW_COUNT() INTO lo;
END IF;
SELECT lo, gid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_search` (IN `data` TEXT)   BEGIN
SELECT `UID`,driver.VehicleRegistrationNo name FROM `driver` JOIN user ON driver.UID=user.id WHERE driver.`status`=0 and user.loginStatus=1 and driver.VehicleRegistrationNo LIKE CONCAT('%', data , '%');
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_sms` (IN `ids` INT, IN `sms` LONGTEXT, IN `cont` VARCHAR(50))   BEGIN
INSERT INTO `tblsmsstatus` (`UID`,`mesg`,`ContactNo`,`status`,`sent_time`) VALUES (ids,sms,cont,'1',NOW());
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_sms_history` (IN `ids` VARCHAR(50))   BEGIN
SELECT * FROM `sms_status` WHERE `uid`=ids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_tracking` (IN `bookingId` INT)   BEGIN
SELECT user.Latitude, user.Longtitude1 from user inner join cab_booking on user.ID = cab_booking.pickup where user.UserType = '3' and cab_booking.ID = bookingId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_update_profile` (IN `dids` INT, IN `name` VARCHAR(50), IN `lname` VARCHAR(50), IN `father` VARCHAR(50), IN `cityname` VARCHAR(50), IN `emaild` VARCHAR(50), IN `dverifyE` INT, IN `uname` VARCHAR(50), IN `dadds` VARCHAR(50), IN `doffadds` VARCHAR(50), IN `dphone` VARCHAR(50), IN `dverifyP` INT, IN `dpannos` VARCHAR(50), IN `dlicence` VARCHAR(50), IN `dvehicleno` VARCHAR(50), IN `dfleet` VARCHAR(50), IN `dmodel` VARCHAR(50), IN `dlstate` VARCHAR(50), IN `eyesite` VARCHAR(50), IN `d_zone` VARCHAR(50), IN `dsmount` VARCHAR(50), IN `d_route` VARCHAR(50), IN `d_pref` VARCHAR(50), IN `doff` VARCHAR(50), IN `dimei` VARCHAR(50), IN `dgps` VARCHAR(50), IN `dlang_w` TEXT, IN `dlan_s` TEXT, IN `pref_t` TEXT, IN `dactivetion` INT, IN `reci_port` TEXT, IN `dacc_cash` VARCHAR(50), IN `dsigupC` LONGTEXT, IN `dinternalC` LONGTEXT, IN `driveBirth` VARCHAR(100), IN `d_ac_nonac` VARCHAR(10), IN `operational_company_name` VARCHAR(150), IN `vehicle_owned` VARCHAR(100), IN `vehicle_owner_name` VARCHAR(100), IN `vehicle_owner_cnt_no` VARCHAR(100), IN `vehicle_owner_alt_cnt_no` VARCHAR(100), IN `license_validity` VARCHAR(100), IN `insurance_validity` VARCHAR(100), IN `rc_no` VARCHAR(100), IN `com_pincode` VARCHAR(100))   BEGIN
DECLARE tablecount INT;
DECLARE usercount INT;
UPDATE `driver` SET `first_name`=name,`last_name`=lname,`father_name`=father,`city`=cityname,`email`=emaild,`address`=dadds,`office_address`=doffadds,`contact_no`=dphone,`pan_card_no`=dpannos,`driving_license_no`=dlicence,`vehicle_reg_no`=dvehicleno,`total_fleet_no`=dfleet,`vehicle_mode`=dmodel,`licence_state`=dlstate,`eye_test`=eyesite,`zone`=d_zone,`security_amt`=dsmount,`route_know`=d_route,`pref_location`=d_pref,`week_off`=doff,`imei`=dimei,`gps`=dgps,`lang_write`=dlang_w,`lang_speak`=dlan_s,`pref_timing`=pref_t,`is_active`=dactivetion,`receive_airport_trns`=reci_port,`accept_cash`=dacc_cash,`signup_comment`=dsigupC,`internal_comment`=dinternalC, `dob`=driveBirth, `ac_nonac`=d_ac_nonac,`operational_company_name`=operational_company_name,`vehicle_owned`=vehicle_owned,`vehicle_owner_name`=vehicle_owner_name,`vehicle_owner_cnt_no`=vehicle_owner_cnt_no,`vehicle_owner_alt_cnt_no`=vehicle_owner_alt_cnt_no,`license_validity`=license_validity,`insurance_validity`=insurance_validity,`rc_no`=rc_no,`company_pincode`=com_pincode WHERE `UID`=dids;
SELECT ROW_COUNT() INTO tablecount;
UPDATE `user` SET `login_name`=uname,`is_verified`=dverifyE WHERE `id`=dids;
SELECT ROW_COUNT() as tablecountuser, tablecount;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_driver_vehicle` (IN `vids` INT)   BEGIN
SELECT a.license_plate,a.name,a.id FROM `cab_list_mgmt` a INNER JOIN `driver` b ON a.id=b.vehicleId INNER JOIN `vendor` c ON c.id=b.vendor_id WHERE c.UID=vids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_edit_vehicle` (IN `vehicle_type` INT, IN `vehicle_model` VARCHAR(50), IN `vehicle_externalref` VARCHAR(200), IN `vehicle_year` INT, IN `vehicle_licenseplate` VARCHAR(50), IN `vehicle_color` VARCHAR(50), IN `vehicle_engine_no` VARCHAR(50), IN `vehicle_fuel_type` VARCHAR(50), IN `vehicle_capacity` INT, IN `vehicle_is_active` INT, IN `vehicleId` INT)  NO SQL BEGIN
UPDATE cab_list_mgmt SET CabType = vehicle_type,VehicleModel = vehicle_model,external_reference = vehicle_externalref,year = vehicle_year,	license_plate=vehicle_licenseplate,colour = vehicle_color,Engine_No = vehicle_engine_no, fuelType = vehicle_fuel_type,capacity = vehicle_capacity,status = vehicle_is_active WHERE id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_edit_vehicle_type` (IN `cabTypeName` VARCHAR(50), IN `cityId` INT, IN `cabTypeId` INT)  NO SQL BEGIN
Update booking_bill SET CabName = cabTypeName,CityId = cityId where Id = cabTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_enquiry_type_info_by_id` (IN `enquiry_id_i` INT)   BEGIN
SELECT * FROM enquiry_type WHERE id = enquiry_id_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_basic` (IN `taxText` FLOAT, IN `taxType` VARCHAR(50), IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `cabTypeId` INT, IN `BookingTypeId` INT, IN `RecId` INT, IN `CancelFee` VARCHAR(500), IN `hourlyRate` VARCHAR(500), IN `prewaitingRate` VARCHAR(500), IN `krishikalyanText` FLOAT, IN `swachhbharatText` FLOAT)  NO SQL BEGIN
UPDATE booking_bill SET basic_tax = taxText,
								  basic_tax_type = taxType,
								  rounding = rounding,
								  `level` = leveli,
								  direction = Direction,
                                  cancellation_fees = CancelFee,
                                  waitingfee_upto_minutes = hourlyRate,
                                  prewaitingfee_upto_minutes=prewaitingRate,
								  krishikalyan_tax = krishikalyanText,
								  swachhbharat_tax = swachhbharatText
WHERE Id = RecId;
UPDATE cab_list_mgmt SET UpdatedStatus = 0, 
								  basic_tax = taxText,
								  basic_tax_type = taxType,
								  rounding = rounding,
								  `level` = leveli,
								  direction = Direction,
                                  cancellation_fees = CancelFee,
                                  waitingfee_upto_minutes = hourlyRate,
                                  prewaitingfee_upto_minutes=prewaitingRate,
								  krishikalyan_tax = krishikalyanText,
								  swachhbharat_tax = swachhbharatText
WHERE BookingType = BookingTypeId AND CabType = cabTypeId;
SELECT ROW_COUNT() as affectedrow, BookingTypeId, cabTypeId, RecId, taxText, taxType, rounding, leveli, Direction, cancellation_fees;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_basic_status` (IN `taxText` FLOAT, IN `taxType` VARCHAR(50), IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `cabTypeId` INT, IN `BookingTypeId` INT, IN `RecId` INT, IN `CancelFee` VARCHAR(500), IN `hourlyRate` VARCHAR(500), IN `prewaitingRate` VARCHAR(500), IN `krishikalyanText` FLOAT, IN `swachhbharatText` FLOAT)   BEGIN
UPDATE booking_bill SET basic_tax = taxText,
								  basic_tax_type = taxType,
								  rounding = rounding,
								  `level` = leveli,
								  direction = Direction,
                                  cancellation_fees = CancelFee,
                                  waitingfee_upto_minutes = hourlyRate,
                                  prewaitingfee_upto_minutes=prewaitingRate,
								  krishikalyan_tax = krishikalyanText,
								  swachhbharat_tax = swachhbharatText
WHERE Id = RecId;
UPDATE cab_list_mgmt SET basic_tax = taxText,
								  basic_tax_type = taxType,
								  rounding = rounding,
								  `level` = leveli,
								  direction = Direction,
                                  cancellation_fees = CancelFee,
                                  waitingfee_upto_minutes = hourlyRate,
                                  prewaitingfee_upto_minutes=prewaitingRate,
								  krishikalyan_tax = krishikalyanText,
								  swachhbharat_tax = swachhbharatText
WHERE BookingType = BookingTypeId AND CabType = cabTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow, BookingTypeId, cabTypeId, RecId, taxText, taxType, rounding, leveli, Direction;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_basic_vehicle` (IN `taxText` FLOAT, IN `taxType` VARCHAR(50), IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `vehicleId` INT)  NO SQL BEGIN
UPDATE cab_list_mgmt SET basic_tax = taxText,basic_tax_type = taxType,rounding = rounding,level = leveli,direction = Direction WHERE Id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_distance` (IN `rate_per_km` INT, IN `first_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(500), IN `rate_upto_distance` VARCHAR(500), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `roundupkm_i` VARCHAR(50), IN `accum_instance_i` VARCHAR(50), IN `package_info_distance` TEXT)  NO SQL BEGIN
UPDATE booking_bill SET Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,rate_upto_distance= rate_upto_distance, round_up_km = roundupkm_i, accumulated_instance = accum_instance_i,package_info_distance=package_info_distance  
WHERE Id = RecId;
UPDATE cab_list_mgmt SET UpdatedStatus = 0, Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare, rate_upto_distance= rate_upto_distance, round_up_km = roundupkm_i, accumulated_instance = accum_instance_i,package_info_distance=package_info_distance 
WHERE CabType = cabTypeId AND BookingType = BookingTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_distance_status` (IN `rate_per_km` INT, IN `irst_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(500), IN `rate_upto_distance` VARCHAR(500), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `roundupkm_i` VARCHAR(50), IN `accum_instance_i` VARCHAR(50), IN `package_info_distance` TEXT)   BEGIN
UPDATE booking_bill SET Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare, rate_upto_distance= rate_upto_distance, round_up_km = roundupkm_i, accumulated_instance = accum_instance_i,package_info_distance=package_info_distance  
WHERE Id = RecId;
UPDATE cab_list_mgmt SET Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare, rate_upto_distance= rate_upto_distance, round_up_km = roundupkm_i, accumulated_instance = accum_instance_i,package_info_distance=package_info_distance 
WHERE CabType = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_distance_vehicle` (IN `rate_per_km` INT, IN `first_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(500), IN `rate_upto_distance` VARCHAR(500), IN `vehicleId` INT, IN `roundupkm_val_i` VARCHAR(50), IN `accum_instance_val_i` VARCHAR(50))  NO SQL BEGIN
UPDATE cab_list_mgmt SET Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee, rate_upto_distance= rate_upto_distance, round_up_km = roundupkm_val_i, accumulated_instance = accum_instance_val_i  WHERE Id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_fixed_route` (IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(500), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT)  NO SQL BEGIN
	UPDATE booking_bill 
	SET frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr 
	WHERE Id = RecId;
	UPDATE cab_list_mgmt 
	SET UpdatedStatus = 0,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr 
	WHERE CabType = cabTypeId AND BookingType = BookingTypeId;
	SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_fixed_route_status` (IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(500), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT)   BEGIN
	UPDATE booking_bill 
	SET frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr 
	WHERE Id = RecId;
	UPDATE cab_list_mgmt 
	SET frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr 
	WHERE CabType = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
	SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_fixed_route_vehicle` (IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(500), IN `vehicleId` INT)  NO SQL BEGIN
UPDATE cab_list_mgmt SET frequent_location=frequent_location,
								  postcode_to_postcode_fair=postCodeArr,
								  UpdatedStatus = 1 
WHERE Id = vehicleId;
SELECT ROW_COUNT() as affectedrow;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_premium` (IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `extraArray` VARCHAR(500), IN `premiumofVehicle` VARCHAR(50), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `night_charge_unit` VARCHAR(50), IN `premiumofVehicleUnit` VARCHAR(50))  NO SQL BEGIN
UPDATE booking_bill 
SET NightCharges = nightChrge,nightCharge_unit=night_charge_unit,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,extras = extraArray,premiums=premiumofVehicle,premiums_unit=premiumofVehicleUnit
WHERE Id = RecId;
UPDATE cab_list_mgmt 
SET UpdatedStatus = 0, NightCharges = nightChrge,nightCharge_unit=night_charge_unit,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,extras = extraArray,premiums=premiumofVehicle,premiums_unit=premiumofVehicleUnit 
WHERE CabType = cabTypeId AND BookingType = BookingTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_premium_status` (IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `extraArray` VARCHAR(500), IN `premiumofVehicle` VARCHAR(50), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `night_charge_unit` VARCHAR(50), IN `premiumofVehicleUnit` VARCHAR(50))   BEGIN
UPDATE booking_bill 
SET NightCharges = nightChrge,nightCharge_unit=night_charge_unit,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,extras = extraArray,premiums=premiumofVehicle,premiums_unit=premiumofVehicleUnit 
WHERE Id = RecId;
UPDATE cab_list_mgmt 
SET NightCharges = nightChrge,nightCharge_unit=night_charge_unit,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,extras = extraArray,premiums=premiumofVehicle,premiums_unit=premiumofVehicleUnit 
WHERE CabType = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_premium_vehicle` (IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `extraArray` VARCHAR(500), IN `premium` VARCHAR(50), IN `vehicleId` INT, IN `night_charge_unit` VARCHAR(50))  NO SQL BEGIN
UPDATE cab_list_mgmt SET NightCharges = nightChrge,nightCharge_unit=night_charge_unit,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,extras = extraArray,premiums=premium WHERE Id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_vehicle_type` (IN `taxText` FLOAT, IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `rate_per_km` INT, IN `first_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(50), IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `vehicle_rate_hour` INT, IN `rate_upto_distance` VARCHAR(500), IN `extraArray` VARCHAR(500), IN `hourlyRate` VARCHAR(500), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `premium` VARCHAR(50), IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(500), IN `vehicle_ignore_hour` INT, IN `vehicle_hour_minimum_fare` INT, IN `package_info_hourly` TEXT)  NO SQL BEGIN
UPDATE booking_bill SET basic_tax = taxText,rounding = rounding,level = leveli,direction = Direction,	Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee,NightCharges = nightChrge,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,	tripCharge_per_minute = vehicle_rate_hour, rate_upto_distance= rate_upto_distance,extras = extraArray,waitingfee_upto_minutes = hourlyRate,premiums=premium,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr ,ignore_first_hrs = vehicle_ignore_hour,minimum_hourly_Charge = vehicle_hour_minimum_fare,package_info_hourly=package_info_hourly
WHERE Id = RecId;
UPDATE cab_list_mgmt SET UpdatedStatus = 0, basic_tax = taxText,rounding = rounding,level = leveli,direction = Direction,	Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee,NightCharges = nightChrge,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,	tripCharge_per_minute = vehicle_rate_hour, rate_upto_distance= rate_upto_distance,extras = extraArray,waitingfee_upto_minutes = hourlyRate,premiums=premium,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr ,ignore_first_hrs = vehicle_ignore_hour,minimum_hourly_Charge = vehicle_hour_minimum_fare,package_info_hourly=package_info_hourly
WHERE Cabtype = cabTypeId AND BookingType = BookingTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fair_manage_for_vehicle_type_status` (IN `taxText` FLOAT, IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `rate_per_km` INT, IN `first_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(50), IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `vehicle_rate_hour` INT, IN `rate_upto_distance` TEXT, IN `extraArray` TEXT, IN `hourlyRate` TEXT, IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `premium` VARCHAR(50), IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(50), IN `vehicle_ignore_hour` INT, IN `vehicle_hour_minimum_fare` INT, IN `package_info_hourly` TEXT)   BEGIN
UPDATE booking_bill SET basic_tax = taxText,rounding = rounding,level = leveli,direction = Direction,	Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee,NightCharges = nightChrge,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,	tripCharge_per_minute = vehicle_rate_hour, rate_upto_distance= rate_upto_distance,extras = extraArray,waitingfee_upto_minutes = hourlyRate,premiums=premium,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr, ignore_first_hrs = vehicle_ignore_hour, minimum_hourly_Charge = vehicle_hour_minimum_fare,package_info_hourly=package_info_hourly
WHERE Id = RecId;
UPDATE cab_list_mgmt SET basic_tax = taxText,rounding = rounding,level = leveli,direction = Direction,	Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee,NightCharges = nightChrge,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,	tripCharge_per_minute = vehicle_rate_hour, rate_upto_distance= rate_upto_distance,extras = extraArray,waitingfee_upto_minutes = hourlyRate,premiums=premium,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr, ignore_first_hrs = vehicle_ignore_hour, minimum_hourly_Charge = vehicle_hour_minimum_fare,package_info_hourly=package_info_hourly
WHERE Cabtype = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_fetch_cab_package` ()   BEGIN
DECLARE localPackage varchar(50);
DECLARE pointToPointPackage varchar(50);
DECLARE airportPackage varchar(50);
DECLARE outstationPackage varchar(50);
DECLARE driverShare varchar(50);
DECLARE companyShare varchar(50);
DECLARE partnerShare varchar(50);
SELECT tblsubpackage.Sub_Package_Name INTO localPackage FROM tblsubpackage INNER JOIN master_package ON tblsubpackage.Sub_Package_Id = master_package.Sub_Package_Id where master_package.Master_Package = 'Local';
SELECT tblsubpackage.Sub_Package_Name INTO pointToPointPackage FROM tblsubpackage INNER JOIN master_package ON tblsubpackage.Sub_Package_Id = master_package.Sub_Package_Id where master_package.Master_Package = 'Point To Point';
SELECT tblsubpackage.Sub_Package_Name INTO airportPackage FROM tblsubpackage INNER JOIN master_package ON tblsubpackage.Sub_Package_Id = master_package.Sub_Package_Id where master_package.Master_Package = 'Airport Terminal';
SELECT tblsubpackage.Sub_Package_Name INTO outstationPackage FROM tblsubpackage INNER JOIN master_package ON tblsubpackage.Sub_Package_Id = master_package.Sub_Package_Id where master_package.Master_Package = 'Outstation';
SELECT client.driver_share , client.company_share , client.partner_share INTO driverShare,companyShare,partnerShare FROM client where client.clientName = 'Hello42';
SELECT localPackage,pointToPointPackage,airportPackage,outstationPackage,driverShare,companyShare,partnerShare;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_action_type` ()   BEGIN
SELECT * FROM tblactiontype order by id desc;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_cities` (IN `stateId` VARCHAR(50))  NO SQL BEGIN
select cities.id,cities.city_name,states.id as stateId from cities INNER JOIN states ON states.id = cities.state_id where states.state = stateId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_complaint` ()   BEGIN
SELECT sub_complaint.id, enquiry_type.enquiry_type, sub_complaint.sub_complaint, sub_complaint.created_by, sub_complaint.date, sub_complaint.updated_by, sub_complaint.updated_on FROM enquiry_type INNER JOIN sub_complaint ON enquiry_type.id = sub_complaint.complaint_type;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_country` ()  NO SQL BEGIN
select id, country_name from country;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_enquiry` ()   BEGIN
SELECT * FROM enquiry order by Enquirydate desc;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_enquiry_type` ()   BEGIN
SELECT * FROM enquiry_type;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_state` (IN `countryName` VARCHAR(50))  NO SQL BEGIN
select states.state,states.id from states INNER JOIN country ON states.country_code = country.id where country.country_name = countryName;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_all_vehicle_type` (IN `city` VARCHAR(50), IN `state` VARCHAR(50))  NO SQL BEGIN
SELECT booking_bill.Id, 
		 master_package.master_package AS FormName, 
		 master_package.package_id AS BookingTypeId,
       master_package.sub_package_id AS RateCatId, 
       sub_package.sub_package_name AS CalculateBy, 
		 vehicle_type.vehicle_type AS CabName,
		 vehicle_type.id AS CabTypeId,
		 country.country_name,
		 states.state,
		 cities.city_name,
         cities.id AS CityId,
		 booking_bill.Per_Km_Charge,
		 booking_bill.rate_per_km_dh,
		 booking_bill.rate_per_km_dw,
		 booking_bill.tripCharge_per_minute,
		 booking_bill.rate_per_hour_dh, 
		 booking_bill.MinimumCharge,
		 booking_bill.minimum_fare_dh,
		 booking_bill.minimum_fare_dw
FROM booking_bill 
INNER JOIN master_package ON booking_bill.BookingTypeId = master_package.package_id 
INNER JOIN sub_package ON master_package.sub_package_id = sub_package.id 
INNER JOIN cities ON booking_bill.CityId = cities.state_id 
INNER JOIN states ON cities.state_id = states.id 
INNER JOIN country ON country.id = states.country_code 
INNER JOIN vehicle_type ON booking_bill.CabType = vehicle_type.id 
WHERE states.state = state AND cities.city_name = city AND master_package.package_id IN (101,102,103,104,105) 
ORDER BY booking_bill.BookingTypeId, booking_bill.Cabtype ASC ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_status` ()   BEGIN
SELECT * FROM status;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_vehicle_info` (IN `BookingTypeId` INT, IN `cabId` INT, IN `city` VARCHAR(50))  NO SQL BEGIN
select 
cab_list_mgmt.id,
cab_list_mgmt.BookingType AS BookingTypeId,
cab_master.CabName, 
cab_master.CabManufacturer, 
cab_master.CabModel, 
cab_master.CabRegistrationNumber, 
cab_list_mgmt.name,
vehicle_type.CabType,
cab_list_mgmt.capacity,
cab_list_mgmt.no_of_cabs,
cab_list_mgmt.VehicleModel,
cab_list_mgmt.Registration_Date,
cab_list_mgmt.Engine_No,
cab_list_mgmt.vehicleNumber,
cab_list_mgmt.status,
cab_list_mgmt.fuelType,
cab_list_mgmt.Manufacturer,
master_package.Sub_Package_Id AS RateCatId,
cab_list_mgmt.Per_Km_Charge,
cab_list_mgmt.MinimumCharge,
cab_list_mgmt.tripCharge_per_minute,
cab_list_mgmt.rate_per_km_dh,
cab_list_mgmt.rate_per_hour_dh,
cab_list_mgmt.minimum_fare_dh,
cab_list_mgmt.rate_per_km_dw,
cab_list_mgmt.minimum_fare_dw,
driver.UID AS DriverId,
concat(driver.FirstName,' ',driver.LastName) As DriverName 
from cab_list_mgmt 
INNER JOIN cab_master ON cab_list_mgmt.CabId = cab_master.CabId  
INNER JOIN driver ON cab_master.CabId = driver.vehicleId
INNER JOIN tblcity ON cab_list_mgmt.cityId = tblcity.id 
INNER JOIN vehicle_type ON vehicle_type.Id = cab_list_mgmt.CabType 
INNER JOIN master_package ON cab_list_mgmt.BookingType = master_package.Package_Id
WHERE cab_list_mgmt.BookingType = BookingTypeId AND cab_list_mgmt.CabType = cabId AND tblcity.name = city;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_vehicle_info_by_id` (IN `vehicleId` INT)  NO SQL BEGIN 
SELECT * FROM cab_list_mgmt WHERE id = vehicleId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_get_vehicle_type_info_by_id` (IN `RowId` INT)  NO SQL BEGIN 
SELECT booking_bill.*, master_package.Sub_Package_Id FROM booking_bill
INNER JOIN master_package ON booking_bill.BookingTypeId=master_package.Package_Id 
 WHERE booking_bill.Id = RowId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_group` ()   BEGIN
SELECT vendor.UID,
		 vendor.group_name,
		 vendor.vendor_name 
FROM vendor 
INNER JOIN driver ON vendor.id=driver.vendor_id 
WHERE vendor.`status`='1' 
GROUP BY vendor.id ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_group_delete` (IN `groupids` INT)   BEGIN
UPDATE `vendor` SET `status`='0' WHERE `UID`=groupids;
SELECT ROW_COUNT() as del;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_group_edit` (IN `groupId` INT)   BEGIN
SELECT * FROM `vendor` WHERE `UID` = groupId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_group_update` (IN `groupId` INT, IN `groupName` VARCHAR(50), IN `groupBoss` VARCHAR(50))   BEGIN
UPDATE `vendor` SET `group_name`=groupName,`vendor_name`=groupBoss WHERE `UID` = groupId;
SELECT ROW_COUNT() as aftrow;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_insert_action_type` (IN `action_type_i` VARCHAR(50), IN `action_type_status_i` VARCHAR(50), IN `action_type_created_by_i` VARCHAR(50))   BEGIN
DECLARE actionType_exists int;
SELECT COUNT(*) INTO actionType_exists FROM tblactiontype WHERE `action` = action_type_i ;
IF actionType_exists =0 THEN
INSERT INTO tblactiontype (`action`,`created_by`,`created_on`,`status`) values (`action_type_i`,`action_type_created_by_i`,NOW(),`action_type_status_i`);
END IF;
SELECT actionType_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_insert_enquiry_type` (IN `enquiry_type_i` VARCHAR(50), IN `enquiry_type_status` VARCHAR(50), IN `enquiry_type_created_by` VARCHAR(50))   BEGIN
DECLARE enquiryType_exists int;
SELECT COUNT(*) INTO enquiryType_exists FROM enquiry_type WHERE `enquiry_type` = enquiry_type_i ;
IF enquiryType_exists =0 THEN
INSERT INTO enquiry_type (`enquiry_type`,`created_by`,`created_on`,`status`) values (`enquiry_type_i`,`enquiry_type_created_by`,NOW(),`enquiry_type_status`);
END IF;
SELECT enquiryType_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_rate_card` (IN `book_ref` INT)   BEGIN
SELECT cab_booking.CarType, cab_booking.ID, booking_bill.MinimumCharge, booking_bill.Min_Distance, booking_bill.Per_Km_Charge, booking_bill.waitingfee_upto_minutes from cab_booking inner join booking_bill on cab_booking.CarType = booking_bill.CabType where cab_booking.ID = book_ref;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_hour` (IN `dh_rate_per_km` INT, IN `dh_minmum_distance` INT, IN `dh_minmum_fare` INT, IN `dh_rate_per_hour` INT, IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `dh_ignore_first_hrs` INT, IN `package_info_distance_hourly` TEXT)   BEGIN
UPDATE booking_bill SET rate_per_km_dh = dh_rate_per_km, minimum_distance_dh = dh_minmum_distance, minimum_fare_dh = dh_minmum_fare, rate_per_hour_dh = dh_rate_per_hour, ignore_first_hrs_dh=dh_ignore_first_hrs,package_info_distance_hourly=package_info_distance_hourly  
WHERE Id = RecId;
UPDATE cab_list_mgmt SET UpdatedStatus = 0, rate_per_km_dh = dh_rate_per_km, minimum_distance_dh = dh_minmum_distance, minimum_fare_dh = dh_minmum_fare, rate_per_hour_dh = dh_rate_per_hour, ignore_first_hrs_dh=dh_ignore_first_hrs,package_info_distance_hourly=package_info_distance_hourly  
WHERE CabType = cabTypeId AND BookingType = BookingTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_hour_status` (IN `dh_rate_per_km` INT, IN `dh_minmum_distance` INT, IN `dh_minmum_fare` INT, IN `dh_rate_per_hour` INT, IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `dh_ignore_first_hrs` INT, IN `package_info_distance_hourly` TEXT)   BEGIN
UPDATE booking_bill SET rate_per_km_dh = dh_rate_per_km, minimum_distance_dh = dh_minmum_distance, minimum_fare_dh = dh_minmum_fare, rate_per_hour_dh = dh_rate_per_hour,
ignore_first_hrs_dh=dh_ignore_first_hrs,package_info_distance_hourly=package_info_distance_hourly
WHERE Id = RecId;
UPDATE cab_list_mgmt SET rate_per_km_dh = dh_rate_per_km, minimum_distance_dh = dh_minmum_distance, minimum_fare_dh = dh_minmum_fare, rate_per_hour_dh = dh_rate_per_hour,
ignore_first_hrs_dh=dh_ignore_first_hrs,package_info_distance_hourly=package_info_distance_hourly
WHERE CabType = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_hour_vehicle` (IN `dh_rate_per_km` INT, IN `dh_minmum_distance` INT, IN `dh_minmum_fare` INT, IN `dh_rate_per_hour` INT, IN `vehicleId` INT)   BEGIN
UPDATE cab_list_mgmt SET rate_per_km_dh = dh_rate_per_km, minimum_distance_dh = dh_minmum_distance, minimum_fare_dh = dh_minmum_fare, rate_per_hour_dh = dh_rate_per_hour  WHERE id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_waiting` (IN `dw_rate_per_km` INT, IN `dw_minmum_distance` INT, IN `dw_minmum_fare` INT, IN `waiting_fees_per_min` VARCHAR(50), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `package_info_distance_waiting` TEXT)   BEGIN
UPDATE booking_bill 
SET rate_per_km_dw = dw_rate_per_km, minimum_distance_dw = dw_minmum_distance, minimum_fare_dw = dw_minmum_fare, waiting_fees = waiting_fees_per_min,package_info_distance_waiting=package_info_distance_waiting  
WHERE Id = RecId;
UPDATE cab_list_mgmt 
SET UpdatedStatus = 0, rate_per_km_dw = dw_rate_per_km, minimum_distance_dw = dw_minmum_distance, minimum_fare_dw = dw_minmum_fare, waiting_fees = waiting_fees_per_min, package_info_distance_waiting=package_info_distance_waiting  
WHERE CabType = cabTypeId AND BookingType = BookingTypeId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_waiting_status` (IN `dw_rate_per_km` INT, IN `dw_minmum_distance` INT, IN `dw_minmum_fare` INT, IN `waiting_fees_per_min` VARCHAR(50), IN `RecId` INT, IN `BookingTypeId` INT, IN `cabTypeId` INT, IN `package_info_distance_waiting` TEXT)   BEGIN
UPDATE booking_bill 
SET rate_per_km_dw = dw_rate_per_km, minimum_distance_dw = dw_minmum_distance, minimum_fare_dw = dw_minmum_fare, waiting_fees = waiting_fees_per_min,package_info_distance_waiting=package_info_distance_waiting  
WHERE Id = RecId;
UPDATE cab_list_mgmt 
SET rate_per_km_dw = dw_rate_per_km, minimum_distance_dw = dw_minmum_distance, minimum_fare_dw = dw_minmum_fare, waiting_fees = waiting_fees_per_min,package_info_distance_waiting=package_info_distance_waiting  
WHERE CabType = cabTypeId AND BookingType = BookingTypeId AND UpdatedStatus = 0;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_distance_waiting_vehicle` (IN `dw_rate_per_km` INT, IN `dw_minmum_distance` INT, IN `dw_minmum_fare` INT, IN `waiting_fees_per_min` VARCHAR(50), IN `vehicleId` INT)   BEGIN
UPDATE cab_list_mgmt SET rate_per_km_dw = dw_rate_per_km, minimum_distance_dw = dw_minmum_distance, minimum_fare_dw = dw_minmum_fare, waiting_fees = waiting_fees_per_min  WHERE id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_save_fair_manage` (IN `taxText` FLOAT, IN `rounding` VARCHAR(50), IN `leveli` VARCHAR(50), IN `Direction` VARCHAR(50), IN `rate_per_km` INT, IN `first_km_rate` INT, IN `vehicle_minmum_distance` INT, IN `vehicle_minmum_fare` INT, IN `CancelFee` VARCHAR(50), IN `nightChrge` VARCHAR(50), IN `nightChStrtTime` VARCHAR(50), IN `nightChEndTime` VARCHAR(50), IN `vehicle_rate_hour` INT, IN `rate_upto_distance` VARCHAR(500), IN `extraArray` VARCHAR(500), IN `hourlyRate` VARCHAR(500), IN `vehicleId` INT, IN `premium` VARCHAR(50), IN `frequent_location` VARCHAR(500), IN `postCodeArr` VARCHAR(500))  NO SQL BEGIN
UPDATE cab_list_mgmt SET basic_tax = taxText,rounding = rounding,level = leveli,direction = Direction,	Per_Km_Charge=rate_per_km,first_km_rate = first_km_rate,Min_Distance = vehicle_minmum_distance, MinimumCharge = vehicle_minmum_fare,cancellation_fees = CancelFee,NightCharges = nightChrge,night_rate_begins =  nightChStrtTime,night_rate_ends = nightChEndTime,	tripCharge_per_minute = vehicle_rate_hour, rate_upto_distance= rate_upto_distance,extras = extraArray,waitingfee_upto_minutes = hourlyRate,premiums=premium,frequent_location=frequent_location,postcode_to_postcode_fair=postCodeArr WHERE id = vehicleId;
SELECT ROW_COUNT() as affectedrow ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_cab_type` (IN `city` VARCHAR(50), IN `state` VARCHAR(50), IN `country` VARCHAR(50), IN `vehicleNo` VARCHAR(50), IN `vehicleModel` VARCHAR(50), IN `since_i` DATE, IN `to_i` DATE)   BEGIN
SELECT booking_bill.Id, cab_list_mgmt.Manufacturer, cab_list_mgmt.Registration_Date, booking_bill.CabName,tblcountry.CountryName,
booking_bill.CabType,tblstates.state,tblcity.name,booking_bill.MinimumCharge,booking_bill.Per_Km_Charge,booking_bill.tripCharge_per_minute, 
cab_list_mgmt.VehicleModel, cab_list_mgmt.vehicleNumber FROM booking_bill INNER JOIN tblcity ON booking_bill.CityId = tblcity.id 
INNER JOIN tblstates ON tblcity.state = tblstates.id INNER JOIN tblcountry ON tblcountry.id = tblstates.country_code 
INNER JOIN cab_list_mgmt ON cab_list_mgmt.CabType = booking_bill.CabType 
INNER JOIN driver ON cab_list_mgmt.id = driver.vehicleId
where tblstates.state LIKE concat('%',state,'%') and tblcity.name LIKE concat('%',city,'%') and tblcountry.CountryName LIKE concat('%',country,'%') 
and cab_list_mgmt.VehicleModel LIKE concat('%',vehicleModel,'%') and cab_list_mgmt.vehicleNumber LIKE concat('%',vehicleNo,'%') 
and  driver.created_date BETWEEN since_i AND to_i ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_complaint_type` (IN `booking_id_i` VARCHAR(50), IN `complaint_type_i` VARCHAR(50), IN `created_since_i` DATETIME, IN `created_to_i` DATETIME, IN `closed_since_i` DATETIME, IN `closed_to_i` DATETIME, IN `status_i` VARCHAR(50))   BEGIN
SELECT complaint.ID as com_id,complaint.StatusID as com_status, cab_booking.CSR_ID as emp,CONCAT(cab_booking.DropAddress,cab_booking.DropArea) as drop_area,cab_booking.ID as id,booking_charges.totalBill, cab_booking.booking_reference as ref,master_package.Master_Package as booking_type,CONCAT(cab_booking.PickupDate," ",cab_booking.PickupTime) as ordertime,concat(client.clientName,'<br>(',appid.`type`,')') as partner,REPLACE(rt_cabmanager_cabs.name,'·','') as vehicle,CONCAT(user_info.FirstName," ",user_info.LastName) as clientname,CONCAT(driver.FirstName," ",driver.LastName) as driver_name, cab_booking.MobileNo as mob_no,user_info.UID as client_id,driver.UID as driver_id,CONCAT(cab_booking.PickupAddress,' ',cab_booking.PickupArea) as departure,driver.VehicleRegistrationNo as reg,cab_status.`status` as `status` FROM cab_booking JOIN cab_status ON cab_booking.`status`=cab_status.`status_id` JOIN user_info ON user_info.UID=cab_booking.ClientID JOIN master_package ON cab_booking.BookingType=master_package.Package_Id LEFT JOIN driver ON cab_booking.pickup=driver.uid LEFT JOIN rt_cabmanager_cabs ON driver.TypeOfvehicle=rt_cabmanager_cabs.id JOIN appid ON appid.id=cab_booking.partner JOIN client ON appid.clientId=client.id LEFT JOIN booking_charges ON cab_booking.ID=booking_charges.BookingID INNER JOIN complaint ON cab_booking.booking_reference=complaint.BookingID WHERE cab_status.`type`='cab' AND cab_booking.booking_reference LIKE concat('%',booking_id_i,'%') AND complaint.ComplaintType LIKE concat('%',complaint_type_i,'%') AND DATE(complaint.ComplaintDate) BETWEEN created_since_i AND created_to_i AND DATE(complaint.updated_date) BETWEEN closed_since_i AND closed_to_i AND complaint.StatusID LIKE concat('%',status_i,'%') order by cab_booking.ID desc;   
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_driver` (IN `did` VARCHAR(50), IN `vdriver` VARCHAR(50), IN `dname` VARCHAR(50), IN `dext` VARCHAR(50), IN `drivername` VARCHAR(50), IN `extref` VARCHAR(50))   BEGIN
SELECT driver.UID,driver.FirstName,driver.Email,driver.`status`,driver.ContactNo,driver.VehicleRegistrationNo,driver.DrivingLicenceNo,
driver.is_active,active.`status` as approvedStatus,
driver.created_date,cab_master.CabName as vehicleName, ignition_type.CabIgnitionType,
count(pickup) as booking 
FROM driver  
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id 
INNER JOIN cab_master ON driver.vehicleId = cab_master.cabId 
INNER JOIN `ignition_type` ON ignition_type.id = cab_master.CabIgnitionTypeId
LEFT JOIN cab_booking ON driver.UID=cab_booking.pickup 
INNER JOIN user ON driver.UID = user.ID 
INNER JOIN active ON driver.is_active = active.status_id 
LEFT JOIN vendor on driver.vendor_id = vendor.id 
WHERE  driver.UID LIKE CONCAT('%',did,'%') 
AND driver.DrivingLicenceNo LIKE CONCAT('%',vdriver,'%') 
AND driver.FirstName LIKE CONCAT('%',dname,'%') 
AND driver.refname LIKE CONCAT('%',extref,'%') 
AND cab_list_mgmt.external_reference LIKE CONCAT('%',dext,'%') 
group by(UID);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_driver_group` (IN `group_id` VARCHAR(50), IN `group_name` VARCHAR(50), IN `veh_id` VARCHAR(50), IN `veh_ext_ref` VARCHAR(50), IN `drivar_name` VARCHAR(50), IN `driver_ext_ref` VARCHAR(50))   BEGIN
SELECT vendor.id,vendor.UID,vendor.group_name,vendor.vendor_name FROM vendor INNER JOIN driver ON vendor.id=driver.vendor_id 
INNEr JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id
WHERE CASE WHEN group_id = '' THEN 
0=0 ELSE
vendor.id = group_id
END AND vendor.`status`='1' AND vendor.group_name LIKE CONCAT ('%',group_name,'%') AND driver.VehicleRegistrationNo LIKE CONCAT ('%',veh_id,'%')
AND cab_list_mgmt.external_reference LIKE CONCAT ('%',veh_ext_ref,'%') AND driver.FirstName LIKE CONCAT ('%',drivar_name,'%') 
AND driver.refname LIKE CONCAT ('%',driver_ext_ref,'%') 
group by (vendor.id);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_enquiry_list` (IN `created_since_i` DATETIME, IN `created_to_i` DATETIME, IN `closed_since_i` DATETIME, IN `closed_to_i` DATETIME, IN `enq_type_i` VARCHAR(50), IN `status_i` VARCHAR(50))   BEGIN
SELECT enquiry.Id, enquiry.CallerName, enquiry.EmailId, enquiry.CallerName, enquiry.CSRID, enquiry.Message, enquiry.EnqType,
 enquiry.EnquiryDate, enquiry.`Status`, enquiry.ClosedDate FROM enquiry where DATE(enquiry.EnquiryDate) BETWEEN created_since_i 
 AND created_to_i and DATE(enquiry.ClosedDate)  BETWEEN closed_since_i AND closed_to_i and enquiry.EnqType LIKE concat('%',enq_type_i,'%')
  and enquiry.`Status` LIKE concat('%',status_i,'%') ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_group_driver` (IN `driver_id` VARCHAR(50), IN `driver_name` VARCHAR(50), IN `veh_id` VARCHAR(50), IN `veh_ext_ref` VARCHAR(50), IN `driverName` VARCHAR(50), IN `driver_ext_ref` VARCHAR(50))   BEGIN
SELECT vendor.id,vendor.UID,vendor.group_name,vendor.vendor_name FROM vendor INNER JOIN driver ON vendor.id=driver.vendor_id 
INNEr JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id
WHERE CASE WHEN driver_id = '' THEN 
0=0 ELSE
driver.UID = driver_id
END AND vendor.`status`='1' AND driver.FirstName LIKE CONCAT ('%',driver_name,'%') AND driver.VehicleRegistrationNo LIKE CONCAT ('%',veh_id,'%')
AND cab_list_mgmt.external_reference LIKE CONCAT ('%',veh_ext_ref,'%') AND driver.FirstName LIKE CONCAT ('%',driverName,'%') 
AND driver.refname LIKE CONCAT ('%',driver_ext_ref,'%') 
group by (vendor.id);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_vehicle_driver` (IN `lplate` VARCHAR(50), IN `vehmake` VARCHAR(50), IN `vehmodel` VARCHAR(50), IN `vehexternal` VARCHAR(50))   BEGIN
SELECT driver.UID,driver.FirstName,driver.Email,driver.status,driver.ContactNo,driver.VehicleRegistrationNo,driver.DrivingLicenceNo,
driver.is_active,driver.created_date,cab_list_mgmt.name,count(cab_booking.pickup) as booking, user.isVerified,active.status as vehicleName 
FROM `driver` 
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id 
LEFT JOIN cab_booking ON driver.UID=cab_booking.pickup 
INNER JOIN user ON driver.UID = user.ID 
INNER JOIN active ON driver.is_active=active.status_id 
LEFT JOIN vendor on driver.vendor_id = vendor.id 
WHERE driver.DrivingLicenceNo LIKE CONCAT('%',lplate,'%') 
AND driver.MakeOfVehicle LIKE CONCAT('%',vehmake,'%') 
AND driver.ModelOfVehicle LIKE CONCAT('%',vehmodel,'%') 
AND driver.refname LIKE CONCAT('%',vehexternal,'%') group by(UID);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_vehicle_group` (IN `plate_no` VARCHAR(50), IN `veh_make` INT, IN `veh_model` INT, IN `ext_ref` VARCHAR(50))   BEGIN
SELECT vendor.id,vendor.UID,vendor.group_name,vendor.vendor_name,driver.VehicleRegistrationNo ,driver.ModelOfVehicle, driver.MakeOfVehicle ,cab_list_mgmt.external_reference
FROM driver INNER JOIN vendor ON vendor.id=driver.vendor_id 
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id
WHERE 
CASE WHEN veh_model = '' THEN 
0=0 ELSE
driver.ModelOfVehicle LIKE CONCAT ('%',veh_model,'%') END
AND CASE WHEN veh_make = '' THEN 
0=0 ELSE
driver.MakeOfVehicle LIKE CONCAT ('%',veh_make,'%') END
AND  CASE WHEN plate_no = '' THEN 
0=0 ELSE
driver.VehicleRegistrationNo LIKE CONCAT ('%',plate_no,'%') END
AND cab_list_mgmt.external_reference LIKE CONCAT ('%',ext_ref,'%')
group by (vendor.id);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_search_vehicle_type` (IN `vehicle_no_i` VARCHAR(50), IN `vehicle_type_i` VARCHAR(50), IN `city_i` VARCHAR(50), IN `state_i` VARCHAR(50), IN `country_i` VARCHAR(50), IN `vehicle_owner_i` VARCHAR(50))   BEGIN
SELECT cab_list_mgmt.id, cab_list_mgmt.vehicleNumber, cab_list_mgmt.name, cab_list_mgmt.VehicleModel, booking_bill.CabName, cab_list_mgmt.Manufacturer, cab_list_mgmt.capacity ,cab_list_mgmt.fuelType,cab_list_mgmt.colour,cab_list_mgmt.Registration_Date, driver.FirstName, tblcity.name, tblstates.state, tblcountry.CountryName  FROM cab_list_mgmt INNER JOIN booking_bill ON cab_list_mgmt.CabType = booking_bill.Id INNER JOIN  tblcity ON tblcity.id = booking_bill.CityId INNER JOIN tblstates ON tblcity.state = tblstates.id INNER JOIN tblcountry ON tblstates.country_code = tblcountry.ID  LEFT JOIN driver ON cab_list_mgmt.id = driver.vehicleId where cab_list_mgmt.vehicleNumber LIKE concat('%',vehicle_no_i,'%') and booking_bill.CabName LIKE concat('%',vehicle_type_i,'%') and tblcity.name LIKE concat('%',city_i,'%') and tblstates.state LIKE concat('%',state_i,'%') and tblcountry.CountryName LIKE concat('%',country_i,'%') and driver.FirstName LIKE concat('%',vehicle_owner_i,'%') ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_share_calculation` (IN `companyShare` VARCHAR(50), IN `partnerShare` VARCHAR(50), IN `driverShare` VARCHAR(50))   BEGIN
UPDATE client SET company_share = companyShare, partner_share = partnerShare, driver_share = driverShare where clientName = 'Hello42';
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_sub_complaint_type` (IN `complaintType_i` VARCHAR(100), IN `subComplaint_i` VARCHAR(200), IN `created_by_i` VARCHAR(100))   BEGIN
DECLARE subComplaint_exists int;
SELECT COUNT(*) INTO subComplaint_exists FROM sub_complaint WHERE `complaint_type` = complaintType_i AND sub_complaint = subComplaint_i;
IF subComplaint_exists =0 THEN
INSERT INTO sub_complaint (`complaint_type`,`sub_complaint`,`created_by`,`date`) values(complaintType_i,subComplaint_i,created_by_i,NOW());
END IF;
SELECT subComplaint_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_update_action_type` (IN `action_id_i` INT, IN `manage_action_i` VARCHAR(50), IN `actionType_UpdatedBy_i` VARCHAR(50), IN `action_Status_i` VARCHAR(50))   BEGIN
DECLARE actionType_exists int;
SELECT COUNT(*) INTO actionType_exists FROM tblactiontype WHERE `action` = manage_action_i AND `status` = action_Status_i;
IF actionType_exists =0 THEN
UPDATE tblactiontype SET `action` = manage_action_i, updated_by = actionType_UpdatedBy_i, updated_on = NOW() ,`status` = action_Status_i WHERE id = action_id_i;
END IF;
SELECT actionType_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_update_complaint_status` (IN `complaint_Text_i` VARCHAR(50), IN `ComplaintId_i` INT, IN `updated_by_i` VARCHAR(50))   BEGIN
UPDATE complaint SET StatusID = complaint_Text_i, updated_by = updated_by_i, updated_date = NOW() WHERE ID = ComplaintId_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_update_complaint_type` (IN `complaint_id_i` INT, IN `complaintType_UpdatedBy_i` VARCHAR(50), IN `desc_i` VARCHAR(50))   BEGIN
DECLARE complaintType_exists int;
SELECT COUNT(*) INTO complaintType_exists FROM sub_complaint WHERE `sub_complaint` = desc_i;
IF complaintType_exists =0 THEN
UPDATE sub_complaint SET updated_by = complaintType_UpdatedBy_i, updated_on = NOW() ,`sub_complaint` = desc_i WHERE id = complaint_id_i;
END IF;
SELECT complaintType_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_update_enquiry_status` (IN `enquiry_Text_i` VARCHAR(50), IN `EnquiryId_i` INT, IN `updated_by_i` VARCHAR(500))   BEGIN
Update enquiry SET `Status` = enquiry_Text_i, ClosedDate = NOW(), updated_by = updated_by_i WHERE Id = EnquiryId_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_update_enquiry_type` (IN `enquiry_id_i` INT, IN `manage_enquery_i` VARCHAR(50), IN `enquiryType_UpdatedBy_i` VARCHAR(50), IN `Enquiry_Status_i` VARCHAR(50))   BEGIN
DECLARE enquiryType_exists int;
SELECT COUNT(*) INTO enquiryType_exists FROM enquiry_type WHERE enquiry_type = manage_enquery_i AND `status` = Enquiry_Status_i;
IF enquiryType_exists =0 THEN
UPDATE enquiry_type SET enquiry_type = manage_enquery_i, updated_by = enquiryType_UpdatedBy_i, updated_on = NOW() ,`status` = Enquiry_Status_i WHERE id = enquiry_id_i;
END IF;
SELECT enquiryType_exists;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_username_check` (IN `duserName` VARCHAR(50))   BEGIN
DECLARE uCount INT;
SELECT COUNT(*) INTO uCount FROM `user` WHERE `LoginName` collate latin1_general_ci	=duserName ;
SELECT uCount;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_user_bank_detail` (IN `userId` INT)   BEGIN
Select name as bank_account_name,ac_holder_name as account_holder, address as bank_adds, ac_no AS account_no, ifsc_code,ibn_no from bank_details where user_id = userId;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_user_feedback` (IN `booking_id` INT, IN `feedback` VARCHAR(500))   BEGIN
UPDATE
  booking
SET
  user_feedback = feedback
WHERE
  booking_id = booking_id ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_user_feedback_old` (IN `booking_id` INT, IN `feedback` VARCHAR(500))   BEGIN
Update cab_booking set user_feedback = feedback where ID = booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_vehicle_edit` (IN `vids` INT)   BEGIN
SELECT * FROM `cab_list_mgmt` WHERE `id`=vids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_vehicle_search_driver` (IN `groupId` VARCHAR(50), IN `groupV` VARCHAR(50), IN `groupName` VARCHAR(50), IN `groupVref` VARCHAR(50), IN `groupDname` VARCHAR(50), IN `groupDext` VARCHAR(50))   BEGIN
SELECT driver.UID,driver.FirstName,driver.Email,driver.`status`,driver.ContactNo,driver.VehicleRegistrationNo,driver.DrivingLicenceNo,
driver.is_active,active.`status` as approvedStatus,driver.created_date,cab_list_mgmt.name as vehicleName,
count(pickup) as booking FROM driver  
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.id 
LEFT JOIN cab_booking ON driver.UID=cab_booking.pickup 
INNER JOIN user ON driver.UID = user.ID 
INNER JOIN active ON driver.is_active = active.status_id 
LEFT JOIN vendor on driver.vendor_id = vendor.id  
WHERE driver.vendor_id LIKE CONCAT('%',groupId,'%') 
AND driver.DrivingLicenceNo LIKE CONCAT('%',groupV,'%')  
AND driver.refname LIKE CONCAT('%',groupVref,'%') 
AND driver.FirstName LIKE CONCAT('%',groupDname,'%') 
AND driver.refname LIKE CONCAT('%',groupDext,'%') 
AND CASE WHEN groupName!='' THEN 
vendor.group_name LIKE CONCAT ('%',groupName,'%')  
ELSE
0=0
END
group by(driver.UID);
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_a_vehicle_update` (IN `ids` INT, IN `vtype` VARCHAR(50), IN `model` VARCHAR(50), IN `ref` VARCHAR(50), IN `vyear` VARCHAR(50), IN `lplate` VARCHAR(50), IN `col` VARCHAR(50), IN `act` INT)   BEGIN
UPDATE `cab_list_mgmt` SET `CabType`=vtype,`VehicleModel`=model,`external_reference`=ref,`year`=vyear,`license_plate`=lplate,`colour`=col,`is_active`=act WHERE `id`=ids;
SELECT ROW_COUNT() AS count;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_booking_data` (IN `param` VARCHAR(255))   BEGIN
  SET @param = param;
  SET @query = CONCAT( 'SELECT * FROM booking WHERE booking_id=' );
  SET @query = CONCAT( @query, ' IF( '', @param, '' IS NOT NULL, '' );
  SET @query = CONCAT( @query, @param, '', TRUE )' );
  PREPARE stmt FROM @query;
  EXECUTE stmt;
  DROP PREPARE stmt;  
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_booking_info` (IN `booking_id` INT(2))   BEGIN
DECLARE distance_n varchar(50); 
SELECT distinct(booking.booking_id),currency.name as currency_n,mp.name as BookingType,mvt.vehicle_type as CarType,CONCAT(user.first_name," ",user.last_name," (",user.mobile,")") as driver_name,user.mobile as driver_mobile,user.email as driver_email,uvm.vehicle_master_id,vm.id,CONCAT(vm.vehicle_no," ",mvm.name) as driver_details,vm.vehicle_no,mvm.name as vehicle_name,
bc.cancellation_price,bc.waitingCharge,bc.tripCharge,bc.total_tax_price,bc.totalBill,bc.is_paid,bc.paid_at,bc.currency,bc.invoice_number,bc.payment_type,bc.fees,bc.total_price,bc.total_tax_price,bc.duration_rate,bc.starting_rate,bc.base_price,bc.tax_price,bc.starting_charge,bc.distance_charge,bc.duration_charge,bc.minimum_price,bc.minimumCharge,bc.minimum_distance,bc.distance_rate,bc.nightcharge_price as night_charge,bc.peak_time_price as peakTimePrice,bc.extracharges,be.*,bpd.*,cs.status as booking_status_name,booking.status as booking_status,concat(client.first_name,' ',client.last_name) as clientname,
client.id AS client_id,
client.mobile as client_mobile,
client.email as  client_email,
registeruser.id as user_id,
concat(registeruser.first_name,' ',registeruser.last_name) as username,
registeruser.mobile as user_mobile,
registeruser.email as user_email,
booking.*,
COALESCE(bapd.drop_address,bpd.drop_address) as drop_address,
COALESCE(bapd.drop_area,bpd.drop_area) as drop_area,  bad.arrival_time_pre,
  bad.arrival_time_post,
  bad.arrival_time_actual,
  bad.actual_waiting_distance,
  bad.actual_driven_distance,
  bad.actual_distance,
  bad.actual_time,
  bad.actual_driven_duration,
dispatch.type_of_dispatch,
if(dispatch.type_of_dispatch=1,'Point To Point','Garage To garage') As type_of_dispatch_name,
dispatch.garage_type,
dispatch.address as garage_address,
dispatch.city as garage_city,
dispatch.pincode as garage_pincode,
dispatch.latitude as garage_latitude,
dispatch.longitude as garage_longitude
FROM booking
LEFT JOIN user ON booking.driver_id=user.id
Left join user as client ON booking.client_id = client.id
LEFT JOIN user as registeruser ON booking.user_id = registeruser.id
LEFT JOIN master_package as mp ON booking.master_package_id=mp.id
LEFT JOIN master_vehicle_type as mvt ON booking.master_vehicle_type_id=mvt.id
LEFT JOIN base_vehicle_type AS bvt ON booking.base_vehicle_id = bvt.base_vehicle_id
LEFT JOIN dispatch_location AS dispatch ON bvt.base_comb_id = dispatch.base_comb_id    
LEFT JOIN user_vehicle_mapping as uvm ON booking.driver_id=uvm.user_id
LEFT JOIN vehicle_master as vm ON uvm.vehicle_master_id=vm.vehicle_master_id
LEFT JOIN master_vehicle_model as mvm ON vm.id=mvm.id
LEFT JOIN booking_charges as bc ON booking.booking_id=bc.BookingID
LEFT JOIN booking_estimation as be ON booking.booking_id=be.booking_id
LEFT JOIN booking_pickdrop_details as bpd ON booking.booking_id=bpd.booking_id
LEFT JOIN cab_status as cs ON booking.status=cs.status_id AND cs.type='cab'
LEFT JOIN booking_actual_pickdrop_details AS bapd ON booking.booking_id= bapd.booking_id
LEFT JOIN booking_actual_details AS bad ON booking.booking_id = bad.booking_id
LEFT JOIN master_currency AS currency ON be.currency_id = currency.id
WHERE booking.booking_id=booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_booking_info_23-06-20` (IN `booking_id` INT(2))   BEGIN
DECLARE distance_n varchar(50); 
SELECT distinct(booking.booking_id),currency.name as currency_n,mp.name as BookingType,mvt.vehicle_type as CarType,CONCAT(user.first_name," ",user.last_name," (",user.mobile,")") as driver_name,user.mobile as driver_mobile,user.email as driver_email,uvm.vehicle_master_id,vm.id,CONCAT(vm.vehicle_no," ",mvm.name) as driver_details,vm.vehicle_no,mvm.name as vehicle_name,
bc.cancellation_price,bc.waitingCharge,bc.tripCharge,bc.total_tax_price,bc.totalBill,bc.is_paid,bc.paid_at,bc.currency,bc.invoice_number,bc.payment_type,bc.fees,bc.total_price,bc.total_tax_price,bc.duration_rate,bc.starting_rate,bc.base_price,bc.tax_price,bc.starting_charge,bc.distance_charge,bc.duration_charge,bc.minimum_price,bc.minimumCharge,bc.minimum_distance,bc.distance_rate,bc.nightcharge_price as night_charge,bc.peak_time_price as peakTimePrice,bc.extracharges,be.*,bpd.*,cs.status as booking_status_name,booking.status as booking_status,concat(client.first_name,' ',client.last_name) as clientname,
client.mobile as client_mobile,
client.email as  client_email,
concat(registeruser.first_name,' ',registeruser.last_name) as username,
registeruser.mobile as user_mobile,
registeruser.email as user_email,
booking.*,
COALESCE(bapd.drop_address,bpd.drop_address) as drop_address,
COALESCE(bapd.drop_area,bpd.drop_area) as drop_area,  bad.arrival_time_pre,
  bad.arrival_time_post,
  bad.arrival_time_actual,
  bad.actual_waiting_distance,
  bad.actual_driven_distance,
  bad.actual_distance,
  bad.actual_time,
  bad.actual_driven_duration
FROM booking
LEFT JOIN user ON booking.driver_id=user.id
Left join user as client ON booking.client_id = client.id
LEFT JOIN user as registeruser ON booking.user_id = registeruser.id
LEFT JOIN master_package as mp ON booking.master_package_id=mp.id
LEFT JOIN master_vehicle_type as mvt ON booking.master_vehicle_type_id=mvt.id
LEFT JOIN user_vehicle_mapping as uvm ON booking.driver_id=uvm.user_id
LEFT JOIN vehicle_master as vm ON uvm.vehicle_master_id=vm.vehicle_master_id
LEFT JOIN master_vehicle_model as mvm ON vm.id=mvm.id
LEFT JOIN booking_charges as bc ON booking.booking_id=bc.BookingID
LEFT JOIN booking_estimation as be ON booking.booking_id=be.booking_id
LEFT JOIN booking_pickdrop_details as bpd ON booking.booking_id=bpd.booking_id
LEFT JOIN cab_status as cs ON booking.status=cs.status_id AND cs.type='cab'
LEFT JOIN 
booking_actual_pickdrop_details AS bapd ON booking.booking_id= bapd.booking_id
LEFT JOIN
booking_actual_details AS bad ON booking.booking_id = bad.booking_id
LEFT JOIN 
master_currency AS currency ON be.currency_id = currency.id
WHERE booking.booking_id=booking_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_booking_info_old` (IN `booking_id` INT)   BEGIN
DECLARE currency_n varchar(50);
DECLARE distance_n varchar(50);
SELECT tblcountry.currency ,tblcountry.distance_unit into currency_n,distance_n FROM tblcountry WHERE tblcountry.CountryName='India';
SELECT distinct(cab_booking.ID),distance_n,currency_n, CONCAT(driver.FirstName," ",driver.LastName," (",driver.ContactNo,")") as driver_name,CONCAT(cab_master.CabRegistrationNumber," ",cab_master.CabName) as driver_details,cancellation_price,waitingCharge,tripCharge,total_tax_price,totalBill,is_paid,paid_at,currency,invoice_number,payment_type,fees,total_price,total_tax_price,duration_rate,starting_rate,base_price,tax_price,starting_charge,distance_charge,duration_charge,minimum_price,booking_charges.minimumCharge,booking_charges.minimum_distance,booking_charges.distance_rate,cab_booking.*
FROM cab_booking
LEFT JOIN driver ON cab_booking.pickup=driver.UID 
LEFT JOIN cab_master ON cab_master.CabId=driver.vehicleId 
LEFT JOIN booking_charges ON cab_booking.id=booking_charges.bookingid 
WHERE cab_booking.id=booking_id; 
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_bill` (IN `BookingId_i` INT)   BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select LoginName INTO userEmailId FROM user INNER JOIN cab_booking ON user.ID = cab_booking.ClientID WHERE cab_booking.ID = BookingId_i LIMIT 0,1;
select PickupDate,PickupTime,CarType,pickup,PickupArea,bookingtype INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from cab_booking where ID = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.Sub_Package_Id into configPackageNo from master_package WHERE master_package.Package_Id=booking_type;
select MinimumCharge,WaitingCharge_per_minute,tripCharge_per_minute,Per_Km_Charge,NightCharges,booking_bill.night_rate_begins,booking_bill.night_rate_ends,speed_per_km,	Waitning_minutes,Min_Distance, configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId from cab_booking INNER JOIN booking_bill ON cab_booking.CarType = booking_bill.id where cab_booking.ID=BookingId_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_complete_bill` (IN `BookingId_i` INT)  NO SQL BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select LoginName INTO userEmailId FROM user INNER JOIN cab_booking ON user.ID = cab_booking.ClientID WHERE cab_booking.ID = BookingId_i LIMIT 0,1;
select PickupDate,PickupTime,CarType,pickup,PickupArea,bookingtype INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from cab_booking where ID = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.Sub_Package_Id into configPackageNo from master_package WHERE master_package.Package_Id=booking_type;
select minimum_fare_dw,WaitingCharge_per_minute,tripCharge_per_minute,rate_per_km_dw,NightCharges,waiting_fees,basic_tax,night_rate_begins,night_rate_ends,Date_Timei,
speed_per_km,Waitning_minutes,minimum_distance_dw, configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId,CabFor,booking_reference
from cab_booking 
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
where cab_booking.ID=BookingId_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_complete_bill_new` (IN `BookingId_i` INT, IN `bookingType` VARCHAR(50))  NO SQL BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select email INTO userEmailId FROM user INNER JOIN booking ON user.id = booking.client_id WHERE booking.booking_id = BookingId_i LIMIT 0,1;
select bpd.pickup_date,bpd.pickup_time,booking.master_vehicle_type_id,booking.driver_id,bpd.pickup_area,booking.master_package_id INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from booking_pickdrop_details AS bpd INNER JOIN booking ON bpd.booking_id = booking.booking_id  where booking.booking_id = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.id into configPackageNo from master_package WHERE master_package.id=booking_type;
IF bookingType=1 THEN
Select Date_Timei,configPackageNo,bpd.pickup_date as PickDate,bpd.pickup_time AS PickTime,Date_Timei,bpd.drop_area as DropPlace,userEmailId,booking.reference_number as booking_reference,bpd.pickup_state as state
from booking
LEFT JOIN booking_pickdrop_details AS bpd ON bpd.booking_id = booking.booking_id
INNER JOIN driver ON booking.driver_id = driver.user_id
where booking.booking_id=BookingId_i;
ELSE
select Date_Timei, configPackageNo,bpd.pickup_date as PickDate,bpd.pickup_time AS PickTime,bpd.drop_area as DropPlace,userEmailId,booking.reference_number as booking_reference,bpd.pickup_state as state
from booking 
INNER JOIN booking_pickdrop_details AS bpd ON bpd.booking_id = booking.booking_id
INNER JOIN driver ON booking.driver_id = driver.user_id
where booking.booking_id=BookingId_i;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_complete_bill_new_old` (IN `BookingId_i` INT, IN `bookingType` VARCHAR(50))  NO SQL BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select LoginName INTO userEmailId FROM user INNER JOIN cab_booking ON user.ID = cab_booking.ClientID WHERE cab_booking.ID = BookingId_i LIMIT 0,1;
select PickupDate,PickupTime,CarType,pickup,PickupArea,bookingtype INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from cab_booking where ID = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.Sub_Package_Id into configPackageNo from master_package WHERE master_package.Package_Id=booking_type;
IF bookingType=101 THEN
select cab_list_mgmt.*, Date_Timei,configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId,cab_booking.CabFor,cab_booking.booking_reference,tblcity.state
from cab_booking 
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
where cab_booking.ID=BookingId_i;
ELSE
select cab_list_mgmt.*,Date_Timei, configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId,cab_booking.CabFor,cab_booking.booking_reference,tblcity.state
from cab_booking 
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN cab_list_mgmt ON driver.vehicleId = cab_list_mgmt.CabId AND cab_booking.BookingType = cab_list_mgmt.BookingType AND cab_booking.CarType = cab_list_mgmt.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
where cab_booking.ID=BookingId_i;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_complete_bill_not_matched` (IN `BookingId_i` INT, IN `bookingType` VARCHAR(50))  NO SQL BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select email INTO userEmailId FROM user INNER JOIN booking ON user.id = booking.client_id WHERE booking.booking_id = BookingId_i LIMIT 0,1;
select bpd.pickup_date,bpd.pickup_time,booking.master_vehicle_type_id,booking.driver_id,bpd.pickup_area,booking.master_package_id INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from booking_pickdrop_details AS bpd INNER JOIN booking ON bpd.booking_id = booking.booking_id  where booking.booking_id = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.id into configPackageNo from master_package WHERE master_package.id=booking_type;
IF bookingType=1 THEN
select booking_estimation.*, Date_Timei,configPackageNo,PickDate,PickTime,DropPlace,userEmailId,cab_booking.CabFor,booking.reference_number as booking_reference,pickdrop.state_id as state
from booking 
INNER JOIN booking_pickdrop_details AS pickdrop ON booking.booking_id = pickdrop.booking_id
INNER JOIN driver ON booking.driver_id = driver.user_id
INNER JOIN booking_estimation ON booking.booking_id = booking_estimation.booking_id
where booking.booking_id=BookingId_i;
ELSE
select booking_estimation.*, Date_Timei,configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId,booking.reference_number as booking_reference,pickdrop.pickup_state as state
from booking 
INNER JOIN booking_pickdrop_details AS pickdrop ON booking.booking_id = pickdrop.booking_id
INNER JOIN booking_estimation ON booking.booking_id = booking_estimation.booking_id
INNER JOIN driver ON booking.driver_id = driver.user_id
where booking.booking_id=BookingId_i;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_cab_booking_complete_bill_not_matched_old` (IN `BookingId_i` INT, IN `bookingType` VARCHAR(50))  NO SQL BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select LoginName INTO userEmailId FROM user INNER JOIN cab_booking ON user.ID = cab_booking.ClientID WHERE cab_booking.ID = BookingId_i LIMIT 0,1;
select PickupDate,PickupTime,CarType,pickup,PickupArea,bookingtype INTO PickDate,PickTime,CabTyp,pickupDr,DropPlace,booking_type from cab_booking where ID = BookingId_i LIMIT 0,1;
select Date_Time INTO Date_Timei from booking_tracker where BookingID = BookingId_i and CabStatus = 4 LIMIT 0,1;
select master_package.Sub_Package_Id into configPackageNo from master_package WHERE master_package.Package_Id=booking_type;
IF bookingType=101 THEN
select booking_bill.*, Date_Timei,configPackageNo,PickDate,PickTime,DropPlace,userEmailId,cab_booking.CabFor,cab_booking.booking_reference,tblcity.state
from cab_booking 
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn AND tblcity.id = booking_bill.CityId
where cab_booking.ID=BookingId_i;
ELSE
select booking_bill.*, Date_Timei,configPackageNo,PickDate,PickTime,Date_Timei,DropPlace,userEmailId,cab_booking.CabFor,cab_booking.booking_reference,tblcity.state
from cab_booking 
INNER JOIN driver ON cab_booking.pickup = driver.UID
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn AND tblcity.id = booking_bill.CityId
where cab_booking.ID=BookingId_i;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_driver_cash` (IN `bookingid_i` INT, IN `driverid_i` INT, IN `paid_i` VARCHAR(50), IN `amount` INT, IN `toll` INT, IN `road` INT, IN `other` INT)   BEGIN
DECLARE totalbill_i DOUBLE;
DECLARE bill_deducted DOUBLE;
DECLARE share_deducted INT;
Declare comp_share INT;
DECLARE partner_share_i INT;
Declare security_amt_i INT;
DECLARE book_ref TEXT;
DECLARE basic_tax_price TEXT;
DECLARE extra INT;
SET extra=toll+road+other;
SET totalbill_i=amount;
IF paid_i='cash' THEN
SELECT total_tax_price into basic_tax_price FROM booking_charges WHERE BookingID=bookingid_i; 
SELECT cab_booking.booking_reference into book_ref FROM cab_booking WHERE id=bookingid_i; 
SELECT company_share,driver_share,partner_share into comp_share,share_deducted,partner_share_i FROM client WHERE client.id=1; 
UPDATE driver SET `status`=0 WHERE UID=driverid_i;
UPDATE cab_booking SET `status`=11 WHERE id=bookingid_i;
INSERT INTO booking_logs (`bookingid`,`status`,`time`) VALUES(bookingid_i,11,NOW());
SET  bill_deducted = (((totalbill_i-(extra+basic_tax_price))*(100-share_deducted))/100);
UPDATE driver SET SecurityAmt = (SecurityAmt-(bill_deducted+basic_tax_price)) WHERE UID=driverid_i;
SELECT SecurityAmt into security_amt_i FROM driver WHERE UID=driverid_i;
UPDATE booking_charges SET totalBill=amount,partnershare=partner_share_i,companyshare=comp_share,drivershare=share_deducted,is_paid=1,paid_at=NOW(),payment_type='CASH' WHERE BookingID=bookingid_i;
INSERT INTO driver_transaction (`user_id`,`amount`,`currentbalance`,`status`,`booking_ref`,`reason`) VALUES (driverid_i,bill_deducted,security_amt_i,'Debit',book_ref,'Deducted from Booking');
ELSE
UPDATE driver SET `status`=0 WHERE UID=driverid_i;
UPDATE cab_booking SET `status`=12 WHERE id=bookingid_i;
INSERT INTO booking_logs (`bookingid`,`status`) VALUES(bookingid_i,12);
UPDATE booking_charges SET is_paid=1,paid_at=NOW(),payment_type='CREDIT',totalBill=amount,extracharges=extra WHERE BookingID=bookingid_i;
END IF;
SELECT SecurityAmt,totalbill_i,security_amt_i from driver WHERE UID=driverid_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_driver_rating` (IN `dids` VARCHAR(50), IN `uids` VARCHAR(50), IN `drate` VARCHAR(50), IN `booking_id` INT)   BEGIN
DECLARE avgamount INT;
INSERT INTO `driver_rating` (`UID`,`DID`,`rating`) VALUES (uids,dids,drate);
SELECT AVG(rating) INTO avgamount FROM driver_rating WHERE DID= dids;
Update cab_booking set driver_rating = drate where ID = booking_id;
UPDATE user SET rating=avgamount WHERE ID=dids;
SELECT avgamount;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_estimated_bill` (IN `car_type` INT, IN `bookingid_i` INT)  NO SQL BEGIN
DECLARE currency VARCHAR(50);
DECLARE measure VARCHAR(50);
DECLARE book_type INT;
DECLARE cab_for INT;
DECLARE approx_distance_charge INT;
select tblcountry.currency ,tblcountry.distance_unit into currency, measure from tblcountry where CountryName= 'India';
SELECT cab_booking.BookingType,cab_booking.CabFor,cab_booking.approx_distance_charge,cab_booking.estimated_price,cab_booking.min_Distance as MinDistance into book_type,cab_for,approx_distance_charge FROM cab_booking WHERE id=bookingid_i;
SELECT booking_bill.night_rate_begins,booking_bill.night_rate_ends,booking_bill.MinimumCharge,booking_bill.WaitingCharge_per_minute,booking_bill.tripCharge_per_minute,booking_bill.Per_Km_Charge,booking_bill.NightCharges,
booking_bill.waiting_fees,booking_bill.speed_per_km,booking_bill.Waitning_minutes,booking_bill.Min_Distance,book_type,cab_for,approx_distance_charge,currency,measure,booking_bill.basic_tax 
from booking_bill 
where booking_bill.Id = car_type;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_estimated_bill_new` (IN `car_type` INT, IN `cab_id` INT, IN `bookingid_i` INT, IN `cabIn` VARCHAR(255), IN `bookingType` VARCHAR(50))  NO SQL BEGIN
IF bookingType=101 THEN
SELECT 
cab_booking.BookingType,cab_booking.CabFor,cab_booking.approx_distance_charge,cab_booking.estimated_price,cab_booking.min_Distance,cab_booking.CabIn,cab_booking.local_subpackage,
cab_list_mgmt.night_rate_begins,cab_list_mgmt.night_rate_ends,cab_list_mgmt.MinimumCharge,cab_list_mgmt.WaitingCharge_per_minute,cab_list_mgmt.tripCharge_per_minute,cab_list_mgmt.Per_Km_Charge,cab_list_mgmt.NightCharges,
cab_list_mgmt.waiting_fees,cab_list_mgmt.Waitning_minutes,cab_list_mgmt.Min_Distance,cab_list_mgmt.basic_tax,tblcity.state,tbllocalpackage.Economy_Price,tbllocalpackage.Sidan_Price,tbllocalpackage.Prime_Price,tblcountry.currency ,tblcountry.distance_unit 
from cab_booking 
INNER JOIN cab_list_mgmt ON cab_list_mgmt.BookingType = cab_booking.BookingType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN tbllocalpackage ON tbllocalpackage.Package = cab_booking.local_subpackage AND tbllocalpackage.City_ID = tblcity.state
INNER JOIN tblcountry ON tblcountry.CountryName = 'India'
where  cab_list_mgmt.CabType= cab_booking.CarType AND cab_list_mgmt.CabId= cab_id AND cab_booking.id=bookingid_i;
ELSE
SELECT 
cab_booking.BookingType,cab_booking.CabFor,cab_booking.approx_distance_charge,cab_booking.estimated_price,cab_booking.min_Distance,cab_booking.CabIn,cab_booking.local_subpackage,
cab_list_mgmt.night_rate_begins,cab_list_mgmt.night_rate_ends,cab_list_mgmt.MinimumCharge,cab_list_mgmt.WaitingCharge_per_minute,cab_list_mgmt.tripCharge_per_minute,cab_list_mgmt.Per_Km_Charge,cab_list_mgmt.NightCharges,
cab_list_mgmt.waiting_fees,cab_list_mgmt.Waitning_minutes,cab_list_mgmt.Min_Distance,cab_list_mgmt.basic_tax,tblcity.state,tblcountry.currency ,tblcountry.distance_unit 
from cab_booking 
INNER JOIN cab_list_mgmt ON cab_list_mgmt.BookingType = cab_booking.BookingType
INNER JOIN tblcity ON tblcity.name = cab_booking.CabIn
INNER JOIN tblcountry ON tblcountry.CountryName = 'India'
where  cab_list_mgmt.CabType= cab_booking.CarType AND cab_list_mgmt.CabId= cab_id AND cab_booking.id=bookingid_i;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_estimated_price` (IN `BookingId_i` INT)   BEGIN
DECLARE PickDate VARCHAR(20);
DECLARE PickTime VARCHAR(20);
DECLARE Date_Timei VARCHAR(20);
DECLARE CabTyp INT;
DECLARE pickupDr INT;
DECLARE configPackageNo INT;
DECLARE booking_type INT;
DECLARE DropPlace VARCHAR(100);
DECLARE userEmailId VARCHAR(100);
select LoginName INTO userEmailId FROM user 
INNER JOIN cab_booking ON user.ID = cab_booking.ClientID 
WHERE cab_booking.ID = BookingId_i 
LIMIT 0,1;
select PickupDate,
		 PickupTime,
		 CarType,
		 pickup,
		 PickupArea,
		 bookingtype 
		 INTO 
		 PickDate,
		 PickTime,
		 CabTyp,
		 pickupDr,
		 DropPlace,
		 booking_type 
from cab_booking 
where ID = BookingId_i 
LIMIT 0,1;
select Date_Time INTO Date_Timei 
from booking_tracker 
where BookingID = BookingId_i and CabStatus = 4 
LIMIT 0,1;
select master_package.Sub_Package_Id into configPackageNo from master_package 
WHERE master_package.Package_Id=booking_type;
select MinimumCharge,
		 WaitingCharge_per_minute,
		 tripCharge_per_minute,
		 Per_Km_Charge,
		 NightCharges,
		 booking_bill.night_rate_begins,
		 booking_bill.night_rate_ends,
		 speed_per_km,
		 Waitning_minutes,
		 Min_Distance,
		 booking_bill.basic_tax, 
		 configPackageNo,
		 PickDate,
		 PickTime,
		 Date_Timei,
		 DropPlace,
		 userEmailId,
		 cab_booking.BookingType,
		 cabfor.Hrs as CabFor
FROM cab_booking
INNER JOIN booking_bill ON cab_booking.BookingType = booking_bill.BookingTypeId AND cab_booking.CarType = booking_bill.CabType
LEFT JOIN cabfor ON cab_booking.CabFor = cabfor.id
where cab_booking.ID=BookingId_i;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_forget_password` (IN `email` VARCHAR(50), IN `token` VARCHAR(200))   BEGIN
DECLARE id_count INT;
DECLARE ids INT;
SELECT `ID` INTO id_count FROM user WHERE `LoginName` COLLATE latin1_general_ci=email or `UserNo` COLLATE latin1_general_cs =email LIMIT 0,1;
IF id_count> 1 THEN
INSERT INTO tblactivation(UID,Verification_code) VALUES(id_count,token);
END IF;		
SELECT ids,id_count;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_get_fare_mode` (IN `packagemodeid` INT, IN `basevehicleid` INT)   BEGIN
IF packagemodeid=1 THEN
SELECT * FROM distance_fare WHERE base_vehicle_id=basevehicleid;
ELSEIF packagemodeid = 2 THEN
SELECT * FROM hourly_fare WHERE base_vehicle_id = basevehicleid;
ELSEIF packagemodeid = 3 THEN
SELECT * FROM distance_hour_fare WHERE base_vehicle_id=basevehicleid;
ELSEIF packagemodeid = 4 THEN
SELECT * FROM distance_waiting_fare WHERE base_vehicle_id=basevehicleid;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_get_user_profile` (IN `user_id` INT(16))   BEGIN
SELECT user.first_name,user.email,user.mobile,user_info.image,user_info.address AS Address1,vm.image AS vehicleimg,vm.ignition_type_id ,fueltype.fuel_type AS fuelType,vm.registration_number as CabRegistrationNumber,vtype.id as vehicleId, vtype.vehicle_type as TypeOfvehicle FROM user LEFT JOIN user_info ON user.id=user_info.user_id LEFT JOIN user_vehicle_mapping as vmap ON user.id = vmap.user_id LEFT JOIN vehicle_master AS vm ON vmap.vehicle_master_id =  vm.vehicle_master_id LEFT JOIN master_vehicle_model as vmodel ON vm.id = vmodel.id  LEFT JOIN master_vehicle_type AS vtype ON vmodel.vehicle_type_id =vtype.id LEFT JOIN master_fuel_type AS fueltype ON vm.ignition_type_id=fueltype.id  WHERE user.id=user_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_get_user_profile_old` (IN `user_id` INT)   BEGIN
SELECT * FROM user_info WHERE UID=user_id;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_list_of_vehicles` ()   BEGIN
SELECT `id`,`name` FROM `cab_list_mgmt`;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_local_booking` (IN `DeviceType` VARCHAR(50), IN `bookingtype` VARCHAR(50), IN `cablocation` VARCHAR(50), IN `cablocationfor` VARCHAR(50), IN `cartypes` INT, IN `cablocationnationality` VARCHAR(50), IN `cablocaladults` INT, IN `cablocalchild` INT, IN `cablocalluggages` INT, IN `cablocalpickuparea` VARCHAR(50), IN `cablocaladdress` VARCHAR(50), IN `pickuplatlat` DOUBLE, IN `pickuplatlng` DOUBLE, IN `pickupdate` VARCHAR(50), IN `pickuptime` VARCHAR(50), IN `datebooking` DATETIME, IN `name` VARCHAR(100), IN `phone` VARCHAR(50), IN `email` VARCHAR(100), IN `user_agent` TEXT, IN `peakTime` INT, IN `alt_phone` VARCHAR(50))   BEGIN
	DECLARE userId INT;
	DECLARE userExists INT;
	DECLARE normailUserId INT;
	DECLARE userNewId INT;
	SELECT COUNT(*) , `ID` INTO userExists,normailUserId 
	FROM `user` 
	WHERE `LoginName` COLLATE latin1_general_ci = email AND `UserNo` COLLATE latin1_general_cs = phone ;
	IF userExists=1 THEN
		INSERT INTO `cab_booking` (`DeviceType`, `BookingType`,`ClientId`,`UserName`,`EmailId`,`CabIn`,`MobileNo`,`CabFor`,`CarType`,`Nationality`,`No_Of_Adults`,`No_Of_Childs`,`No_Of_Luggages`,`PickupArea`,`PickupAddress`,`PickupLatitude`,`PickupLongtitude`,`PickupDate`,`PickupTime`,`BookingDate`,`Status`,`useragent`,`partner`,`peakTime`) 
		VALUES (DeviceType, bookingtype,normailUserId,name,email,cablocation,phone,cablocationfor,cartypes,cablocationnationality,cablocaladults,cablocalchild,cablocalluggages,cablocalpickuparea,cablocaladdress,pickuplatlat,pickuplatlng,pickupdate,pickuptime,datebooking,1,user_agent,1,peakTime);
		SELECT last_insert_id() INTO userId;
		INSERT INTO `booking_logs` (bookingid,`status`,message,`time`) VALUES (userId,1,'Requesting car',datebooking);			
		INSERT INTO `booking_stack`(`booking_id`,`lat`,`long`,`status`) VALUES (userId,pickuplatlat,pickuplatlng,'');
	ELSE
		INSERT INTO `user` (`LoginName`,`UserNo`,`UserType`) VALUES (email,phone,2);
		SELECT last_insert_id() INTO userNewId;
		INSERT INTO  user_info(`uid`,`firstname`,`email`,`mobno`,`AlternateContactNo`) VALUES (userNewId,name,email,phone,alt_phone);
		INSERT INTO `cab_booking` (`DeviceType`, `BookingType`,`ClientId`,`UserName`,`EmailId`,`MobileNo`,`CabIn`,`CabFor`,`CarType`,`Nationality`,`No_Of_Adults`,`No_Of_Childs`,`No_Of_Luggages`,`PickupArea`,`PickupAddress`,`PickupLatitude`,`PickupLongtitude`,`PickupDate`,`PickupTime`,`BookingDate`,`Status`,`Partner`,`peakTime`) 
		VALUES (DeviceType, bookingtype,userNewId,name,email,phone,cablocation,cablocationfor,cartypes,cablocationnationality,cablocaladults,cablocalchild,cablocalluggages,cablocalpickuparea,cablocaladdress,pickuplatlat,pickuplatlng,pickupdate,pickuptime,datebooking,1,1,peakTime);
		SELECT last_insert_id() INTO userId;
		INSERT INTO `booking_logs` (bookingid,`status`,message,`time`) VALUES (userId,1,'Requesting car',datebooking);			
		INSERT INTO `booking_stack`(`booking_id`,`lat`,`long`,`status`) VALUES (userId,pickuplatlat,pickuplatlng,'');
	END IF;
	SELECT userId,userNewId,userExists,normailUserId;	
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_login` (IN `username` VARCHAR(500), IN `userpass` VARCHAR(500), IN `gcmid` TEXT, IN `token` VARCHAR(50))   BEGIN
DECLARE checklogin VARCHAR(100) ; 
DECLARE id_s INT ; 
DECLARE type_data INT ; 
DECLARE login_state INT ;
  SELECT
    COUNT(*),
    login_status
  INTO
    checklogin,
    login_state
  FROM
    `user`
  WHERE
    (
      `email` COLLATE latin1_general_ci = username OR `mobile` COLLATE latin1_general_cs = username
    ) AND `password` COLLATE latin1_general_ci = userpass AND `is_verified` = 1 ; 
IF checklogin = 1 THEN
  SELECT
    user_type_id,
    id
  INTO
    type_data,
    id_s
  FROM
    `user`
  WHERE
    (
      `email` COLLATE latin1_general_ci = username OR `mobile` COLLATE latin1_general_cs = username
    )
  LIMIT 0, 1 ; 
IF type_data = 3 THEN
UPDATE
  user
SET
  gcm_id = ''
WHERE
  `gcm_id` COLLATE latin1_general_cs = gcmid AND user_type_id = 3 ;
SELECT
  token,
  type_data,
  checklogin,
  login_state,
  b.id,
  b.email,
  b.first_name,
  c.city_id,
  b.mobile,
  b.imei,
  a.security_amt,
  c.image AS prof_img,
  mc.name as city_name
FROM
  user b
left JOIN
  user_info c ON b.id = c.user_id
Left Join 
  driver a ON b.id = a.user_id
left join 
  master_city mc ON c.city_id = mc.id
WHERE
  b.id = id_s ;
INSERT
INTO
  `driver_status`(`uid`,
  `status`,
  `login_time`)
VALUE
  (id_s,
  '1',
  NOW()) ; 
ELSE
UPDATE
  user
SET
  gcm_id = ''
WHERE
  `gcm_id` COLLATE latin1_general_cs = gcmid AND user_type_id != 3 ;
SELECT
  token,
  login_state,
  b.referral_key,
  type_data,
  checklogin,
  b.id,
  b.email,
  b.first_name,
  a.city_id,
  b.mobile,
  a.image AS prof_img,
  mc.name as city_name
FROM
  user b
Left JOIN
  user_info a ON b.id = a.user_id
left join 
  master_city mc ON a.city_id = mc.id
WHERE
  b.id = id_s ;
END IF ; 
IF login_state = 0 THEN
UPDATE
  user
SET
  `login_status` = 1,
  is_active = 1,
  `gcm_id` = gcmid,
  `token` = token,
  login_time = NOW()
WHERE
  `id` = id_s ;
INSERT
INTO
  log_in_log(
    userId,
    `login_time`,
    login_date,
    lat,
    `log`,
    `status`
  )
VALUES(
  id_s,
  NOW(), DATE(login_time), '', '', token) ;
END IF ;
  END IF ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_login_old` (IN `username` VARCHAR(500), IN `userpass` VARCHAR(500), IN `gcmid` TEXT, IN `token` VARCHAR(50))   BEGIN
DECLARE checklogin VARCHAR(100);
DECLARE id_s INT;
DECLARE type_data INT;
DECLARE login_state INT;
SELECT COUNT(*),loginStatus INTO checklogin,login_state FROM `user` WHERE (`LoginName` COLLATE latin1_general_ci = username OR `UserNo` COLLATE latin1_general_cs = username) AND `Password` COLLATE latin1_general_ci =userpass AND `isVerified`=1;
IF checklogin = 1 THEN
SELECT UserType,ID INTO type_data,id_s FROM `user` WHERE (`LoginName`COLLATE latin1_general_ci = username OR `UserNo`COLLATE latin1_general_cs = username) LIMIT 0,1;
IF type_data=3 THEN
UPDATE user SET gcm_id='' WHERE `gcm_id` COLLATE latin1_general_cs =gcmid and UserType=3;
SELECT token,type_data,checklogin,login_state,b.ID,a.FirstName,a.City,a.ContactNo,a.imei,a.SecurityAmt,b.loginname,a.Email,c.image as prof_img FROM driver a 
INNER JOIN user_info c ON a.UID = c.UID
INNER JOIN user b ON a.UID = b.ID WHERE b.ID=id_s;
INSERT INTO `driverstatus` (`uid`,`status`,`login_time`) VALUE (id_s,'1',NOW());
ELSE
UPDATE user SET gcm_id='' WHERE `gcm_id`COLLATE latin1_general_cs =gcmid and UserType!=3;
SELECT token,login_state,b.referralKey,type_data,checklogin,b.ID, a.FirstName,a.City,a.MobNo,a.Email,a.image as prof_img FROM user_info a INNER JOIN user b ON a.UID = b.ID WHERE b.ID=id_s;
END IF;
IF login_state=0 THEN
UPDATE user SET `loginStatus`=1,is_active=1,`gcm_id` =gcmid,`token`=token ,loginTime=NOW() WHERE `ID`=id_s;
INSERT INTO log_in_log (userId,`login_time`,login_date,lat,`log`,`status`) VALUES (id_s,NOW(),DATE(login_time),'','',token);
END IF;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_reject_booking` (IN `id_i` INT, IN `book_i` INT)   BEGIN
DECLARE update_id INT;
SELECT booking_register.id into update_id FROM booking_register WHERE booking_register.driverId=id_i and booking_register.bookingid=book_i order by id desc LIMIT 0,1;
UPDATE booking_register SET `status`='R' WHERE id=update_id ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_reporting` (IN `cabBookingId` VARCHAR(50), IN `driverLat` VARCHAR(50), IN `driverLong` VARCHAR(50), IN `cabDriverId` INT)   BEGIN
DECLARE pickdatebook VARCHAR(50);
DECLARE picktimebook VARCHAR(50);
DECLARE clientIdbook INT;
DECLARE usernumber VARCHAR(50);
SELECT bpd.`pickup_date`,bpd.`pickup_time`,booking.`client_id`,user.mobile  INTO pickdatebook,picktimebook,clientIdbook,usernumber FROM `booking_pickdrop_details` as bpd left join booking ON bpd.booking_id=booking.booking_id join user ON booking.client_id = user.id  WHERE booking.`booking_id`= cabBookingId and booking.booking_status='1' ;
INSERT INTO `booking_logs` (`bookingid`,`user_id`,`status`,`message`,`time`) VALUES (cabBookingId,cabDriverId,'5','Reported',NOW());
UPDATE booking Left Join booking_actual_details as bad ON booking.booking_id = bad.booking_id SET booking.`status`=5,bad.arrival_time_actual=NOW() WHERE booking.booking_id=CabBookingId and booking.booking_status='1';
INSERT INTO `booking_tracker` (`BookingID`,`DriverId`,`Latitutude`,`Logitude`,`Date_Time`,`CabStatus`) VALUES (cabBookingId,cabDriverId,driverLat,driverLong,NOW(),'5');
SELECT  pickdatebook,picktimebook,usernumber;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_reporting_old` (IN `cabBookingId` VARCHAR(50), IN `driverLat` VARCHAR(50), IN `driverLong` VARCHAR(50), IN `cabDriverId` INT)   BEGIN
DECLARE pickdatebook VARCHAR(50);
DECLARE picktimebook VARCHAR(50);
DECLARE clientIdbook INT;
DECLARE usernumber VARCHAR(50);
SELECT `PickupDate`,`PickupTime`,`ClientID` INTO pickdatebook,picktimebook,clientIdbook FROM `cab_booking` WHERE `ID`= cabBookingId and BookingStatus='1';
SELECT `UserNo` INTO usernumber FROM `user` WHERE `ID` =clientIdbook;
INSERT INTO `booking_logs` (`bookingid`,`status`,`message`,`time`) VALUES (cabBookingId,'5','Reported',NOW());
UPDATE cab_booking SET `status`=5,arrival_time_actual=NOW() WHERE id=CabBookingId and BookingStatus='1';
INSERT INTO `booking_tracker` (`BookingID`,`DriverId`,`Latitutude`,`Logitude`,`Date_Time`,`CabStatus`) VALUES (cabBookingId,cabDriverId,driverLat,driverLong,NOW(),'5');
SELECT  pickdatebook,picktimebook,usernumber;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_reset_password` (IN `newPass` VARCHAR(100), IN `cPass` VARCHAR(100), IN `code` VARCHAR(100))   BEGIN
DECLARE id_user INT;
SELECT `UID` INTO id_user FROM `tblactivation` WHERE BINARY Verification_code=code AND `isUsed`=0 ORDER BY id DESC LIMIT 0,1;

UPDATE `tblactivation` SET `isUsed`=1 WHERE BINARY Verification_code=code;
END IF;
SELECT id_user;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_send_message` (IN `id_i` INT, IN `booking_id` INT, IN `message` TEXT)   BEGIN
DECLARE user_id int;
DECLARE driver_id int;
DECLARE gcm text;
SELECT cab_booking.ClientID,cab_booking.pickup into user_id,driver_id from cab_booking WHERE id=booking_id;
IF user_id = id_i THEN
SELECT user.gcm_id into gcm FROM user WHERE id=driver_id;
INSERT INTO booking_msg(booking_msg.bookingid,booking_msg.sender,booking_msg.receiver,booking_msg.msg,booking_msg.`datetime`) VALUES (booking_id,id_i,driver_id,message,NOW());
ELSEIF driver_id=id_i THEN 
SELECT user.gcm_id into gcm FROM user WHERE id=user_id;
INSERT INTO booking_msg(booking_msg.bookingid,booking_msg.sender,booking_msg.receiver,booking_msg.msg,booking_msg.`datetime`) VALUES (booking_id,id_i,user_id,message,NOW());
END IF;
SELECT gcm;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_signup` (IN `userEmailIdLog` VARCHAR(50), IN `userName` VARCHAR(50), IN `mobileNo` VARCHAR(50), IN `landNo` VARCHAR(50), IN `cities` VARCHAR(50), IN `adds` VARCHAR(50), IN `emailId` VARCHAR(50), IN `altEmails` VARCHAR(50), IN `companyuserName` VARCHAR(50), IN `userMobile` VARCHAR(50), IN `UserLandline` VARCHAR(50), IN `userEmails` VARCHAR(50), IN `altUserEmails` VARCHAR(50), IN `userAddress` VARCHAR(50), IN `usersCity` VARCHAR(50), IN `userPins` VARCHAR(50), IN `image` TEXT, IN `userpassword` VARCHAR(250), IN `userRoles` VARCHAR(50), IN `UserNos` VARCHAR(50), IN `activationcode` VARCHAR(250), IN `userlang` VARCHAR(50))   BEGIN
DECLARE userexists INT;
DECLARE lastusersid INT;
DECLARE idcom INT;
DECLARE afectactive INT;
DECLARE num INT;
DECLARE lastcompanyid INT;
SELECT COUNT(*) INTO userexists FROM `user` WHERE `LoginName` COLLATE latin1_general_ci =userEmailIdLog  or LoginName COLLATE latin1_general_ci=UserNos or 
UserNo COLLATE latin1_general_ci=userEmailIdLog or UserNo COLLATE latin1_general_ci=UserNos;
IF userexists <1 THEN
	INSERT INTO `user`(`LoginName`,`Password`,`UserType`,`amount`,`UserNo`,`create_date`) VALUES (userEmailIdLog,userpassword,userRoles,0,mobileNo,NOW());
	SELECT ROW_COUNT() INTO num;
	SELECT LAST_INSERT_ID() INTO lastusersid;
	IF lastusersid >0 THEN
		INSERT INTO `user_info`(`UID`,`FirstName`,`City`,`Address1`,`Email`,`AltEmail`,`MobNo`,`LandNo`,`image`,`language`) VALUES 
		(lastusersid,userName,cities,adds,emailId,altEmails,mobileNo,landNo,image,userlang);
		SELECT ROW_COUNT() INTO idcom;
		IF idcom >0 THEN
			INSERT INTO `company`(`CompanyName`,`CompanyCity`,`CompanyAddress`,`CompanyPIN`,`ComMob`,`CompLand`,`Email`,`AltEmail`) VALUES 
			(companyuserName,cities,adds,userPins,userMobile,UserLandline,userEmails,altUserEmails);
			SELECT ROW_COUNT() INTO afectactive;
			SELECT LAST_INSERT_ID() INTO lastcompanyid;
			IF afectactive >0 THEN
			INSERT INTO `tblactivation` (`UID`,`Verification_code`) VALUES (lastusersid,activationcode) ;
			END IF;
		END IF;
	END IF;
END IF;
SELECT num,lastusersid,userexists,afectactive,lastcompanyid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_start_trip` (IN `bookid` INT, IN `driverid` INT)   BEGIN
DECLARE lastid INT;
UPDATE booking SET `status`=7 WHERE booking_id=bookid;
INSERT INTO booking_tracker (`BookingID`,`DriverId`,`Date_Time`,`CabStatus`) VALUES (bookid,driverid,NOW(),'7');
INSERT INTO booking_logs (`bookingid`,`user_id`,`status`,`message`,`time`) VALUES (bookid,driverid,'7','Trip Start',NOW()); 
SELECT LAST_INSERT_ID() INTO lastid;
SELECT lastid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_start_trip_old` (IN `bookid` INT, IN `driverid` INT)   BEGIN
DECLARE lastid INT;
UPDATE cab_booking SET `status`=7 WHERE id=bookid;
INSERT INTO booking_tracker (`BookingID`,`DriverId`,`Date_Time`,`CabStatus`) VALUES (bookid,driverid,NOW(),'7');
INSERT INTO booking_logs (`bookingid`,`status`,`message`,`time`) VALUES (bookid,'7','Trip Start',NOW()); 
SELECT LAST_INSERT_ID() INTO lastid;
SELECT lastid;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_total_payment_charges` (IN `TripCharge` INT, IN `waitingCh` INT, IN `TotalBill` INT, IN `MinimumChrage` INT, IN `BookingID_N` INT, IN `distance_i` DOUBLE, IN `dist_rate` INT, IN `trip_charge` INT, IN `tax_i` INT, IN `duration_i` INT, IN `address` TEXT, IN `lat` VARCHAR(50), IN `lon` VARCHAR(50), IN `time_i` TIME)  NO SQL BEGIN
DECLARE book_ref TEXT;
SELECT cab_booking.booking_reference into book_ref FROM cab_booking WHERE id=BookingID_N;
INSERT INTO booking_charges (tripCharge,waitingCharge,minimumCharge,BookingID,AddedTime,distance_rate,distance_charge,minimum_distance,total_tax_price,currency,invoice_number,total_price,tax_price,starting_rate,starting_charge,minimum_price,duration_rate,duration_charge)VALUES(TripCharge,waitingCh,MinimumChrage,BookingID_N,NOW(),dist_rate,TripCharge,trip_charge,tax_i,'RS',CONCAT('IN-',book_ref),TotalBill,tax_i,dist_rate,MinimumCharge,MinimumCharge,duration_i,trip_charge);
INSERT INTO booking_logs(bookingid,`status`,message,`time`) VALUES(BookingID_N,8,'Completed',NOW());
UPDATE cab_booking SET `status`=8,DropAddress=address,final_lat=lat,final_long=lon,actual_distance=distance_i,actual_time=time_i,expiration_time=NOW() WHERE id=BookingID_N;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_booking_details` (IN `ids` VARCHAR(50))   BEGIN
SELECT booking_charges.minimum_distance,cab_booking.appox_waiting_minute,
booking_charges.distance_charge,booking_charges.duration_charge,cab_booking.actual_distance,cab_booking.actual_driven_duration
 FROM `cab_booking` INNER JOIN driver ON cab_booking.pickup=driver.UID INNER JOIN booking_charges ON booking_charges.BookingID =cab_booking.ID WHERE cab_booking.ID=ids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_distance` ()   BEGIN
SELECT `Latitude`,`Longtitude1` FROM user WHERE `UserType`=3 ;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_helo_money` (IN `usersids` VARCHAR(50), IN `rocommendvis` VARCHAR(50))   BEGIN
DECLARE ids INT;
SELECT COUNT(ID) INTO ids FROM `user` WHERE `ID`= usersids;
IF ids>0 THEN
UPDATE `user` SET `recvia`=rocommendvis , amount=amount+50  WHERE `ID`=usersids;
SELECT ROW_COUNT() AS counter,ids;
END IF;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_history_all` (IN `userids` VARCHAR(50))   BEGIN
SELECT `PickupDate`,`PickupTime`,`PickupArea`,`ID` FROM `cab_booking` WHERE `ClientID`=userids;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_history_completed` (IN `userids` VARCHAR(50))   BEGIN
SELECT `PickupDate`,`PickupTime`,`PickupArea`,`ID` FROM `cab_booking` WHERE `ClientID`=userids AND `status`>3;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_user_history_pending` (IN `userIds` VARCHAR(50), IN `tomorrowdate` VARCHAR(50))   BEGIN
SELECT `PickupDate`,`PickupTime`,`PickupArea`,`ID` FROM `cab_booking` WHERE `ClientID`=userids AND CONCAT(`PickupDate`,' ',`PickupTime`) >= tomorrowdate;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_validation` (IN `userEmailIdLog` VARCHAR(100))   BEGIN
DECLARE checkusers INT;
SELECT  COUNT(*) INTO  checkusers FROM `user` WHERE  (BINARY `LoginName` =userEmailIdLog or BINARY `UserNo`=userEmailIdLog) AND UserType=3;
SELECT checkusers;
END$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `wp_vehicles` (IN `datanames` VARCHAR(50))   BEGIN
DECLARE vehicleNames VARCHAR(50);
SELECT `id`  FROM `cab_list_mgmt` WHERE `name` LIKE CONCAT('%', datanames, '%') LIMIT 0,10;
END$$

DELIMITER ;

-- --------------------------------------------------------

--
-- Table structure for table `activation`
--

CREATE TABLE `activation` (
  `id` int(11) NOT NULL,
  `UID` int(11) NOT NULL,
  `Verification_code` varchar(20) NOT NULL,
  `login_code` varchar(20) DEFAULT NULL,
  `isUsed` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `activation`
--

INSERT INTO `activation` (`id`, `UID`, `Verification_code`, `login_code`, `isUsed`) VALUES
(1, 2, '95510', NULL, 0),
(2, 3, '46597', NULL, 1),
(3, 4, '61829', NULL, 1),
(4, 4, '29902', NULL, 0),
(5, 4, '71277', NULL, 0),
(6, 4, '48807', NULL, 0),
(7, 5, '78340', NULL, 0),
(8, 6, '44820', NULL, 1),
(9, 6, '10181', NULL, 1),
(10, 6, '48920', NULL, 0),
(11, 6, '83310', NULL, 0),
(12, 6, '92442', NULL, 0),
(13, 6, '19557', NULL, 0),
(14, 6, '88533', NULL, 0),
(15, 6, '24906', NULL, 0),
(16, 6, '95634', NULL, 0),
(17, 6, '10945', NULL, 0),
(18, 6, '51313', NULL, 0),
(19, 6, '42621', NULL, 0),
(20, 6, '89375', NULL, 0),
(21, 6, '32718', NULL, 0),
(22, 6, '65814', NULL, 1),
(23, 6, '35490', NULL, 0),
(24, 7, '83903', NULL, 0),
(25, 7, '87179', NULL, 1),
(26, 7, '69694', NULL, 0),
(27, 7, '57758', NULL, 0),
(28, 7, '76753', NULL, 0),
(29, 7, '73485', NULL, 0),
(30, 8, '31257', NULL, 1),
(31, 8, '72790', NULL, 0),
(32, 8, '26601', NULL, 0),
(33, 8, '48462', NULL, 0),
(34, 8, '50866', NULL, 0),
(35, 8, '72726', NULL, 0),
(36, 8, '23737', NULL, 0),
(37, 9, '35125', NULL, 0),
(38, 10, '63270', NULL, 0),
(39, 10, '28584', NULL, 0),
(40, 10, '33560', NULL, 0),
(41, 10, '13792', NULL, 0),
(42, 10, '35352', NULL, 0),
(43, 10, '74194', NULL, 0),
(44, 10, '42623', NULL, 0),
(45, 10, '16234', NULL, 0),
(46, 10, '64918', NULL, 0),
(47, 11, '18886', NULL, 0),
(48, 11, '15725', NULL, 0),
(49, 11, '64791', NULL, 1),
(50, 11, '98549', NULL, 0),
(51, 11, '60410', NULL, 0),
(52, 12, '21540', NULL, 1),
(53, 12, '58851', NULL, 1),
(54, 12, '78171', NULL, 0),
(55, 13, '19752', NULL, 1),
(56, 13, '55508', NULL, 0),
(57, 13, '45552', NULL, 0),
(58, 13, '50167', NULL, 0),
(59, 13, '67340', NULL, 0),
(60, 13, '26926', NULL, 0),
(61, 13, '75084', NULL, 0),
(62, 13, '80904', NULL, 0),
(63, 13, '39923', NULL, 0),
(64, 13, '17034', NULL, 0),
(65, 13, '78620', NULL, 0),
(66, 14, '11437', NULL, 1),
(67, 15, '86538', NULL, 1),
(68, 15, '43843', NULL, 1),
(69, 15, '99278', NULL, 1),
(70, 15, '20040', NULL, 1),
(71, 15, '88270', NULL, 1),
(72, 15, '69182', NULL, 1),
(73, 15, '78982', NULL, 1),
(74, 15, '27963', NULL, 1),
(75, 15, '39809', NULL, 1),
(76, 15, '33337', NULL, 1),
(77, 15, '27702', NULL, 1),
(78, 15, '79525', NULL, 1),
(79, 16, '11614', NULL, 1),
(80, 16, '56472', NULL, 0),
(81, 17, '65844', NULL, 1),
(82, 18, '56778', NULL, 1),
(83, 19, '15076', NULL, 1),
(84, 20, '46354', NULL, 1),
(85, 21, '14775', NULL, 0),
(86, 22, '94082', NULL, 0),
(87, 22, '61799', NULL, 1);

-- --------------------------------------------------------

--
-- Table structure for table `active`
--

CREATE TABLE `active` (
  `id` int(11) NOT NULL,
  `status` varchar(50) NOT NULL,
  `status_id` int(11) NOT NULL,
  `status_class` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `active`
--

INSERT INTO `active` (`id`, `status`, `status_id`, `status_class`) VALUES
(1, 'Approved', 1, 'approved'),
(2, 'On Hold', 2, 'onhold'),
(3, 'Black Listed', 3, 'blacklisted'),
(4, 'Inactive', 4, 'unaprovestatus'),
(5, 'Unapproved', 5, 'unapproved');

-- --------------------------------------------------------

--
-- Table structure for table `active_weekdays`
--

CREATE TABLE `active_weekdays` (
  `id` int(11) NOT NULL,
  `mapping_id` int(11) NOT NULL,
  `bkg_type_id` int(11) NOT NULL,
  `weekdays_id` varchar(20) DEFAULT NULL,
  `created_date` datetime NOT NULL,
  `modified_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_by` int(11) NOT NULL,
  `modified_by` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '1',
  `ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `active_weekdays_log`
--

CREATE TABLE `active_weekdays_log` (
  `id` int(11) NOT NULL,
  `mapping_id` int(11) NOT NULL,
  `bkg_type_id` int(11) NOT NULL,
  `weekdays_id` varchar(20) DEFAULT NULL,
  `created_date` datetime NOT NULL,
  `modified_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_by` int(11) NOT NULL,
  `modified_by` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '1',
  `ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `admin_log`
--

CREATE TABLE `admin_log` (
  `id` int(11) NOT NULL,
  `adminId` int(11) NOT NULL,
  `status` varchar(200) NOT NULL,
  `login_time` datetime NOT NULL,
  `logout_time` datetime NOT NULL,
  `login_date` date NOT NULL,
  `logout_date` date NOT NULL,
  `login_diff` time NOT NULL,
  `lat` varchar(100) NOT NULL,
  `log` varchar(100) NOT NULL,
  `ipaddress` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `admin_text`
--

CREATE TABLE `admin_text` (
  `id` int(11) NOT NULL,
  `page` text NOT NULL,
  `field` text NOT NULL,
  `text` text NOT NULL,
  `value` text NOT NULL,
  `label_id` int(11) NOT NULL,
  `language` varchar(100) NOT NULL,
  `type` int(11) NOT NULL DEFAULT '0',
  `status` int(11) NOT NULL DEFAULT '1',
  `module` varchar(1000) DEFAULT NULL,
  `sub_module` varchar(1000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `admin_text`
--

INSERT INTO `admin_text` (`id`, `page`, `field`, `text`, `value`, `label_id`, `language`, `type`, `status`, `module`, `sub_module`) VALUES
(1, '1', 'total_taxis_registered', 'Total Taxis Registered', '', 1, 'EN', 0, 1, NULL, NULL),
(2, '1', 'total_calls', 'Total Calls', '', 2, 'EN', 0, 1, NULL, NULL),
(3, '1', 'total_jobs', 'Total Jobs', '', 3, 'EN', 0, 1, NULL, NULL),
(4, '1', 'total_revenue', 'Total Revenue', '', 4, 'EN', 0, 1, NULL, NULL),
(5, '1', 'taxis_on_road', 'Taxis On Road', '', 5, '', 0, 1, NULL, NULL),
(6, '1', 'total_missed_calls', 'Total Missed Calls', '', 6, '', 0, 1, NULL, NULL),
(7, '1', 'jobs_1', 'Jobs From Delhi', 'delhi', 7, '', 2, 1, NULL, NULL),
(8, '1', 'complaints_maintence', 'Complaints Maintence', '', 8, '', 0, 1, NULL, NULL),
(9, '1', 'cash_duty', 'Cash Duty', '', 9, '', 0, 1, NULL, NULL),
(10, '1', 'taxis_logged_in', 'Taxis Logged in', '', 10, '', 0, 1, NULL, NULL),
(11, '1', 'jobs_in_progress', 'Jobs In Progress', '', 11, '', 0, 1, NULL, NULL),
(12, '1', 'jobs_2', 'Jobs From Noida', 'noida', 12, '', 2, 1, NULL, NULL),
(13, '1', 'complaints_taxi_delay', 'Complaints Taxi Delay', '', 13, '', 0, 1, NULL, NULL),
(14, '1', 'credit_duty', 'Credit Duty', '', 14, '', 0, 1, NULL, NULL),
(15, '1', 'taxis_logged_off', 'Taxis Logged Off', '', 15, '', 0, 1, NULL, NULL),
(16, '1', 'jobs_advance', 'Jobs Advance', '', 16, '', 0, 1, NULL, NULL),
(17, '1', 'jobs_3', 'Job From Faridabad', 'faridabad', 17, '', 2, 1, NULL, NULL),
(18, '1', 'drivers_complaints', 'Driver\'s Complaints', '', 18, '', 0, 1, NULL, NULL),
(19, '1', 'agent_wise_revenue', 'AGENT WISE REVENUE', '', 19, '', 0, 1, NULL, NULL),
(20, '1', 'blocked_driver', 'Blocked Driver', '', 20, '', 0, 1, NULL, NULL),
(21, '1', 'total_enquiry', 'Total Enquiry', '', 21, '', 0, 1, NULL, NULL),
(22, '1', 'jobs_4', 'Jobs From Gurgaon', 'gurgaon', 22, '', 2, 1, NULL, NULL),
(23, '1', 'cce_complint', 'CCE Complint', '', 23, '', 0, 1, NULL, NULL),
(24, '1', 'vikash', 'Vikash', '', 24, '', 0, 1, NULL, NULL),
(25, '1', 'taxis_not_functional', 'Taxis Not Functional', '', 25, '', 0, 1, NULL, NULL),
(26, '1', 'total_complaints', 'total Complaints', '', 26, '', 0, 1, NULL, NULL),
(27, '1', 'out_station_duty', 'Out Station Duty', '', 27, '', 0, 1, NULL, NULL),
(28, '1', 'lost__found', 'Lost & Found', '', 28, '', 0, 1, NULL, NULL),
(29, '1', 'amit', 'Amit', '', 29, '', 0, 1, NULL, NULL),
(30, '1', 'available_drivers', 'Available Drivers', '', 30, '', 0, 1, NULL, NULL),
(31, '1', 'extra_charging', 'Extra Charging', '', 31, '', 0, 1, NULL, NULL),
(32, '1', 'jobs_cancelled', 'Jobs Cancelled', '', 32, '', 0, 1, NULL, NULL),
(33, '1', 'extra_charging', 'Extra Charging', '', 33, '', 0, 1, NULL, NULL),
(34, '1', 'available_drivers', 'Available Drivers', '', 34, '', 0, 1, NULL, NULL),
(35, '1', 'extra_charging', 'Extra Charging', '', 35, '', 0, 1, NULL, NULL),
(36, '1', 'jobs_cancelled', 'Jobs Cancelled', '', 36, '', 0, 1, NULL, NULL),
(37, '1', 'west', 'West', '', 37, '', 0, 1, NULL, NULL),
(38, '1', 'bid_rejects', 'Bid Rejects', '', 38, '', 0, 1, NULL, NULL),
(39, '1', 'credit_duty', 'Credit Duty', '', 39, '', 0, 1, NULL, NULL),
(40, '1', 'bill_not_given', 'Bill Not Given', '', 40, '', 0, 1, NULL, NULL),
(41, '1', 'south', 'South', '', 41, '', 0, 1, NULL, NULL),
(42, '1', 'time_constraints', 'Time Constraints', '', 42, '', 0, 1, NULL, NULL),
(43, '1', 'credit_duty', 'Credit Duty', '', 43, '', 0, 1, NULL, NULL),
(44, '1', 'airport_drop', 'Airport drop', '', 44, '', 0, 1, NULL, NULL),
(45, '1', 'miss_behaved_by_driver', 'Miss Behaved by driver', '', 45, '', 0, 1, NULL, NULL),
(46, '1', 'east', 'East', '', 46, '', 0, 1, NULL, NULL),
(47, '1', 'agent_wise_report', 'AGENT WISE REPORT', '', 47, '', 0, 1, NULL, NULL),
(48, '1', 'railway_station_drop', 'Railway Station Drop', '', 48, '', 0, 1, NULL, NULL),
(49, '1', 'north', 'North', '', 49, '', 0, 1, NULL, NULL),
(50, '1', 'agent_wise_report_should_be__link_to_upload_agent_wise_report_downloads', 'AGENT WISE REPORT Should be  link to upload Agent Wise Report Downloads', '', 50, '', 0, 1, NULL, NULL),
(51, '1', 'noida', 'Noida', '', 51, '', 0, 1, NULL, NULL),
(52, '1', 'gurgaon', 'Gurgaon', '', 52, '', 0, 1, NULL, NULL),
(53, '1', 'amount', 'Amount', '', 0, '', 0, 1, NULL, NULL),
(54, '1', 'company_share', 'Hello42&nbsp;Share', '', 0, '', 0, 1, NULL, NULL),
(55, '1', 'taxis_registered_2', 'Taxis Registered 2', '', 55, '', 0, 1, NULL, NULL),
(56, '1', 'taxi_busy_2', 'Taxi Busy', '', 56, '', 0, 1, NULL, NULL),
(57, '1', 'total_missed_call_2', 'Total Missed Call', '', 57, '', 0, 1, NULL, NULL),
(58, '1', 'job_in_progress_2', 'Job In Progress', '', 58, '', 0, 1, NULL, NULL),
(59, '1', 'jobs_advance_2', 'Jobs Advance', '', 59, '', 0, 1, NULL, NULL),
(60, '1', 'total_enquiry_2', 'Total Enquiry', '', 60, '', 0, 1, NULL, NULL),
(61, '1', 'total_complaints_2', 'Total Complaints', '', 61, '', 0, 1, NULL, NULL),
(62, '1', 'extra_charging_2', 'Extra Charging', '', 62, '', 0, 1, NULL, NULL),
(63, '1', 'revenue_call_center_2', 'Revenue Call Center', '', 63, '', 0, 1, NULL, NULL),
(64, '1', 'taxis_on_road_2', 'Taxis On Road', '', 64, '', 0, 1, NULL, NULL),
(65, '1', 'taxi_free_2', 'Taxi Free', '', 65, '', 0, 1, NULL, NULL),
(66, '1', 'available_drivers_2', 'Available Drivers', '', 66, '', 0, 1, NULL, NULL),
(67, '1', 'west_2', 'West', '', 67, '', 0, 1, NULL, NULL),
(68, '1', 'south_2', 'South', '', 68, '', 0, 1, NULL, NULL),
(69, '1', 'east_2', 'East', '', 69, '', 0, 1, NULL, NULL),
(70, '1', 'north_2', 'North', '', 70, '', 0, 1, NULL, NULL),
(71, '1', 'bid_reject_2', 'Bid Reject', '', 71, '', 0, 1, NULL, NULL),
(72, '1', 'time_constraints_2', 'Time Constraints', '', 72, '', 0, 1, NULL, NULL),
(73, '1', 'complaints_maintence_2', 'Complaints Maintence', '', 73, '', 0, 1, NULL, NULL),
(74, '1', 'lost__found_2', 'Lost & Found', '', 74, '', 0, 1, NULL, NULL),
(75, '1', 'earning_1000_2', 'Earning < Rs. 1000', '', 75, '', 0, 1, NULL, NULL),
(76, '1', 'taxis_not_functional_2', 'Taxis Not Functional', '', 76, '', 0, 1, NULL, NULL),
(77, '1', 'taxi_delay_2', 'Taxi Delay', '', 77, '', 0, 1, NULL, NULL),
(78, '1', 'drivers_logged_in_2', 'Drivers Logged In', '', 78, '', 0, 1, NULL, NULL),
(79, '1', 'kerbs_2', 'Kerbs', '', 79, '', 0, 1, NULL, NULL),
(80, '1', 'jobs_from_delhi_2', 'Jobs From Delhi', '', 80, '', 0, 1, NULL, NULL),
(81, '1', 'credit_duty_2', 'Credit Duty', '', 81, '', 0, 1, NULL, NULL),
(82, '1', 'jobs_from_noida_gzb_2', 'Jobs From Noida/GZB', '', 82, '', 0, 1, NULL, NULL),
(83, '1', 'short_distance_2', 'Short Distance', '', 83, '', 0, 1, NULL, NULL),
(84, '1', 'complnts_taxi_delay_2', 'Complnts Taxi Delay', '', 84, '', 0, 1, NULL, NULL),
(85, '1', 'total_revenue_2', 'Total Revenue', '', 85, '', 0, 1, NULL, NULL),
(86, '1', 'earning_1000_2', 'Earning > Rs. 1000', '', 86, '', 0, 1, NULL, NULL),
(87, '1', 'taxis_logged_off_2', 'Taxis Logged Off', '', 87, '', 0, 1, NULL, NULL),
(88, '1', 'total_calls_received_2', 'Total Calls Received', '', 88, '', 0, 1, NULL, NULL),
(89, '1', 'total_jobs_2', 'Total Jobs', '', 89, '', 0, 1, NULL, NULL),
(90, '1', 'jobs_cancelled_2', 'Jobs Cancelled', '', 90, '', 0, 1, NULL, NULL),
(91, '1', 'jobs_from_gurgaon_2', 'Jobs From Gurgaon', '', 91, '', 0, 1, NULL, NULL),
(92, '1', 'out_station_duty_2', 'Out Station Duty', '', 92, '', 0, 1, NULL, NULL),
(93, '1', 'job_from_faridabad_2', 'Job From Faridabad', '', 93, '', 0, 1, NULL, NULL),
(94, '1', 'fare_related_enquiry_2', 'Fare Related Enquiry', '', 94, '', 0, 1, NULL, NULL),
(95, '1', 'drivers_complaints_2', 'Drivers Complaints', '', 95, '', 0, 1, NULL, NULL),
(96, '1', 'revenue_from_kerbs_2', 'Revenue from Kerbs', '', 96, '', 0, 1, NULL, NULL),
(97, '1', 'point_cash', 'Cash', '', 97, 'EN', 0, 1, NULL, NULL),
(98, '2', 'filter', 'Filter', '', 98, '', 0, 1, NULL, NULL),
(99, '2', 'general_filter_head', 'General', '', 98, '', 0, 1, NULL, NULL),
(100, '2', 'client_filter_head', 'Client', '', 98, '', 0, 1, NULL, NULL),
(101, '2', 'driver_filter_head', 'Driver', '', 98, '', 0, 1, NULL, NULL),
(102, '2', 'vehicle_filter_head', 'Vehicle', '', 98, '', 0, 1, NULL, NULL),
(103, '2', 'location_filter_head', 'Location', '', 98, '', 0, 1, NULL, NULL),
(104, '2', 'state_filter_head', 'Status', '', 98, '', 0, 1, NULL, NULL),
(105, '2', 'payment_filter_head', 'Payment', '', 98, '', 0, 1, NULL, NULL),
(106, '2', 'booking_id_filter', 'ID', '', 98, '', 0, 1, NULL, NULL),
(107, '2', 'booking_type_filter', 'Booking Type', '', 98, '', 0, 1, NULL, NULL),
(108, '2', 'initial_request_data_filter', 'Initial Request Data', '', 98, '', 0, 1, NULL, NULL),
(109, '2', 'vehicle_owner_filter', 'Vehicle Owner', '', 98, '', 0, 1, NULL, NULL),
(110, '2', 'driver_filter', 'Driver', '', 98, '', 0, 1, NULL, NULL),
(111, '2', 'partner_filter', 'Partner', '', 98, '', 0, 1, NULL, NULL),
(112, '2', 'search_filter', 'Search', '', 0, '', 0, 1, NULL, NULL),
(113, '2', 'clear_filter', 'Clear', '', 0, '', 0, 1, NULL, NULL),
(114, '2', 'booking_id_table', 'Id', '', 0, '', 0, 1, NULL, NULL),
(115, '2', 'pickup_time_table', 'Pickup Time', '', 0, '', 0, 1, NULL, NULL),
(116, '2', 'vehicle_table', 'Vehicle Time', '', 0, '', 0, 1, NULL, NULL),
(117, '2', 'booking_type_table', 'Booking Type', '', 0, '', 0, 1, NULL, NULL),
(118, '2', 'partner_table', 'Partner', '', 0, '', 0, 1, NULL, NULL),
(119, '2', 'client_table', 'Client', '', 0, '', 0, 1, NULL, NULL),
(120, '2', 'departure_table', 'Departure', '', 0, '', 0, 1, NULL, NULL),
(121, '2', 'drop_area', 'Drop Area', '', 0, '', 0, 1, NULL, NULL),
(122, '2', 'status', 'Status', '', 0, '', 0, 1, NULL, NULL),
(123, '', 'booking_id', 'Booking Id', '', 0, '', 0, 1, 'booking_info', 'In'),
(124, '', 'user_agent', 'UserAgent', '', 0, '', 0, 1, 'booking_info', 'In'),
(125, '', 'comments_for_the_client', 'Comments For The Client', '', 0, '', 0, 1, 'booking_info', 'In'),
(126, '', 'comments_for_the_driver', 'Comment For The Driver', '', 0, '', 0, 1, 'booking_info', 'In'),
(127, '', 'drivers_note', 'Drivers Note', '', 0, '', 0, 1, 'booking_info', 'In'),
(128, '', 'clients_note', 'Clients Note', '', 0, '', 0, 1, 'booking_info', 'In'),
(129, '', 'features', 'Features', '', 0, '', 0, 1, 'booking_info', 'In'),
(130, '', 'vehicle_type', 'Vehicle Type', '', 0, '', 0, 1, 'booking_info', 'In'),
(131, '', 'is_account_booking', 'Is Account Booking', '', 0, '', 0, 1, 'booking_info', 'In'),
(132, '', 'is_corporate_booking', 'Is Corporate Booking', '', 0, '', 0, 1, 'booking_info', 'In'),
(133, '', 'is_account_booking', 'Is Account Booking', '', 0, '', 0, 1, 'booking_info', 'In'),
(134, '', 'is_credit_card_available', 'Is Credit Card Available', '', 0, '', 0, 1, 'booking_info', 'In'),
(135, '', 'voucher_id', 'Voucher Id', '', 0, '', 0, 1, 'booking_info', 'In'),
(136, '', 'voucher_type', 'Voucher Type', '', 0, '', 0, 1, 'booking_info', 'In'),
(137, '', 'voucher_amount', 'Voucher Amount', '', 0, '', 0, 1, 'booking_info', 'In'),
(138, '', 'external_booking_reference', 'External Booking Reference', '', 0, '', 0, 1, 'booking_info', 'Out'),
(139, '', 'arrival_time_pre', 'Arrival Time Pre', '', 0, '', 0, 1, 'booking_info', 'Out'),
(140, '', 'arrival_time_post', 'Arrival Time Post', '', 0, '', 0, 1, 'booking_info', 'Out'),
(141, '', 'arrival_time_actual', 'Arrival Time Actual', '', 0, '', 0, 1, 'booking_info', 'Out'),
(142, '', 'expiration_time', 'Expiration Time', '', 0, '', 0, 1, 'booking_info', 'Out'),
(143, '', 'actual_driving_duration', 'Actual Driving Duration', '', 0, '', 0, 1, 'booking_info', 'Out'),
(144, '', 'actual_waiting_distance', 'Actual Waiting Distance', '', 0, '', 0, 1, 'booking_info', 'Out'),
(145, '', 'actual_distance', 'Actual Distance', '', 0, '', 0, 1, 'booking_info', 'Out'),
(146, '', 'booking_type', 'Booking Type', '', 0, '', 0, 1, 'booking_info', 'Out'),
(147, '', 'booking_date', 'Booking Date', '', 0, '', 0, 1, 'booking_info', 'Out'),
(148, '', 'pickup_date', 'Pickup Date', '', 0, '', 0, 1, 'booking_info', 'Out'),
(149, '', 'pickup_area', 'Pickup Area', '', 0, '', 0, 1, 'booking_info', 'Out'),
(150, '', 'pickup_address', 'Pickup Address', '', 0, '', 0, 1, 'booking_info', 'Out'),
(151, '', 'drop_address', 'Drop Address', '', 0, '', 0, 1, 'booking_info', 'Out'),
(152, '', 'drop_area', 'Drop Area', '', 0, '', 0, 1, 'booking_info', 'Out'),
(153, '', 'estimated_distance', 'Estimated Distance', '', 0, '', 0, 1, 'booking_info', 'Out'),
(154, '', 'estimated_time', 'Estimated Time', '', 0, '', 0, 1, 'booking_info', 'Out'),
(155, '', 'estimated_price', 'Estimated Price', '', 0, '', 0, 1, 'booking_info', 'Out'),
(156, '', 'rating', 'Rating', '', 0, '', 0, 1, 'booking_info', 'Driver Rating'),
(157, '', 'reason', 'Reason', '', 0, '', 0, 1, 'booking_info', 'Driver Rating'),
(158, '', 'comment', 'Comment', '', 0, '', 0, 1, 'booking_info', 'Driver Rating'),
(159, '', 'rating', 'Rating', '', 0, '', 0, 1, 'booking_info', 'Client Rating'),
(160, '', 'reason', 'Reason', '', 0, '', 0, 1, 'booking_info', 'Client Rating'),
(161, '', 'comment', 'Comment', '', 0, '', 0, 1, 'booking_info', 'Client Rating'),
(162, '', 'created_at', 'Created At', '', 0, '', 0, 1, 'payment_info', 'Price'),
(163, '', 'is_paid', 'Is Paid', '', 0, '', 0, 1, 'payment_info', 'Price'),
(164, '', 'paid_at', 'Paid At', '', 0, '', 0, 1, 'payment_info', 'Price'),
(165, '', 'currency', 'Currency', '', 0, '', 0, 1, 'payment_info', 'Price'),
(166, '', 'invoice_number', 'Invoice Number', '', 0, '', 0, 1, 'payment_info', 'Price'),
(167, '', 'external_reference', 'External Refernece', '', 0, '', 0, 1, 'payment_info', 'Price'),
(168, '', 'payment_type', 'Payment Type', '', 0, '', 0, 1, 'payment_info', 'Price'),
(169, '', 'fees', 'Fees', '', 0, '', 0, 1, 'payment_info', 'Price'),
(170, '', 'total_price', 'Total Price', '', 0, '', 0, 1, 'payment_info', 'Price'),
(171, '', 'total_tax_price', 'Total Tax Price', '', 0, '', 0, 1, 'payment_info', 'Price'),
(172, '', 'company_base_index', 'Company Base Index', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(173, '', 'partner_index', 'Partner Index', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(174, '', 'distance_rate', 'Distance Rate', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(175, '', 'duration_rate', 'Duration Rate', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(176, '', 'starting_rate', 'Starting Rate', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(177, '', 'base_price', 'Base Price', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(178, '', 'tax_price', 'Tax Price', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(179, '', 'fraction_discount', 'Fraction Discount', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(180, '', 'voucher_amount', 'Voucher Amount', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(181, '', 'price_type', 'Price Type', '', 0, '', 0, 1, 'payment_info', 'Payment Parts'),
(182, '', 'starting_rate_2', 'Starting Rate', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(183, '', 'distance_rate_2', 'Distance Rate', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(184, '', 'duration_rate_2', 'Duration Rate', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(185, '', 'minimum_price_2', 'Minimum Price', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(186, '', 'cancellation_price', 'Cancellation Price', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(187, '', 'no_show_fee', 'No Show Fee', '', 0, '', 0, 1, 'payment_info', 'Applied Tarrifs'),
(188, '', 'internal_id', 'Internal Id', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(189, '', 'external_id', 'External Id', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(190, '', 'external_reference', 'External Reference', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(191, '', 'card_type', 'Card Type', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(192, '', 'card_number', 'Card Number', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(193, '', 'expired_at', 'Expired At', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(194, '', 'card_owner', 'Card Owner', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(195, '', 'created_at', 'Created At', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(196, '', 'verified_date', 'Verified Date', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(197, '', 'active', 'Active', '', 0, '', 0, 1, 'payment_info', 'Credit Card Details'),
(198, '', 'client_name', 'Client Name', '', 0, '', 0, 1, 'client_info', 'personal_info'),
(199, '', 'contact', 'Contact', '', 0, '', 0, 1, 'client_info', 'personal_info'),
(200, '', 'email', 'Email', '', 0, '', 0, 1, 'client_info', 'personal_info'),
(201, '', 'alt_email', 'Alt Email', '', 0, '', 0, 1, 'client_info', 'personal_info'),
(202, '', 'landline', 'Landline', '', 0, '', 0, 1, 'client_info', 'personal_info'),
(203, '', 'name', 'Name', '', 0, '', 0, 1, 'driver_info', 'Transport Details'),
(204, '', 'contact_no', 'Contact No', '', 0, '', 0, 1, 'driver_info', 'Transport Details'),
(205, '', 'primary_language', 'Primary Language', '', 0, '', 0, 1, 'driver_info', 'Transport Details'),
(206, '', 'average_rating', 'Average Rating', '', 0, '', 0, 1, 'driver_info', 'Transport Details'),
(207, '', 'group_name', 'Name', '', 0, '', 0, 1, 'driver_info', 'Driver Group'),
(208, '', 'group_owner', 'Group Owner', '', 0, '', 0, 1, 'driver_info', 'Driver Group'),
(209, '', 'driver_name', 'Name', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(210, '', 'driver_contact_no', 'Contact No', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(211, '', 'current_status', 'Current Status', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(212, '', 'current_signup_status', 'Current Signup Status', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(213, '', 'average_rating', 'Average Rating (60 days)', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(214, '', 'bank_iban', 'Bank IBAN', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(215, '', 'bank_swift', 'Bank Swift', '', 0, '', 0, 1, 'driver_info', 'Driver'),
(216, '', 'license_plate', 'License Plate', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(217, '', 'make', 'Make', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(218, '', 'model', 'Model', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(219, '', 'year', 'Year', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(220, '', 'color', 'Color', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(221, '', 'vehicle_type', 'Vehicle Type', '', 0, '', 0, 1, 'driver_info', 'Vehicle'),
(222, '5', 'complaint_management_head', 'Complaint Management', '', 0, '', 0, 1, NULL, NULL),
(223, '5', 'enquiry_list_tab', 'Enquiry List', '', 0, '', 0, 1, NULL, NULL),
(224, '5', 'enquiry_type_tab', 'Enquiry Type', '', 0, '', 0, 1, NULL, NULL),
(225, '5', 'action_taken_type_tab', 'Action Taken Type', '', 0, '', 0, 1, NULL, NULL),
(226, '5', 'complaint_filter_head', 'Filter', '', 0, '', 0, 1, NULL, NULL),
(227, '5', 'booking_id_complaint_filter_heading', 'Booking ID', '', 0, '', 0, 1, NULL, NULL),
(228, '5', 'complaint_type_complaint_filter_heading', 'Complaint Type', '', 0, '', 0, 1, NULL, NULL),
(229, '5', 'created_date_complaint_filter_heading', 'Created Date', '', 0, '', 0, 1, NULL, NULL),
(230, '5', 'updated_date_complaint_filter_heading', 'Updated Date', '', 0, '', 0, 1, NULL, NULL),
(231, '5', 'status_complaint_filter_heading', 'Status', '', 0, '', 0, 1, NULL, NULL),
(232, '5', 'searchVehicle', 'Search', '', 0, '', 0, 1, NULL, NULL),
(233, '5', 'clear_complaint_filter', 'Clear', '', 0, '', 0, 1, NULL, NULL),
(255, '5', 'complaint_type', 'Complaint Type', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(256, '5', 'complaint_subtype', 'Complaint Subtype', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(257, '5', 'caller_name', 'Caller Name', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(258, '5', 'csr', 'CSR', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(259, '5', 'complaint_description', 'Complaint Description', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(260, '5', 'complaint_date', 'Complaint Date', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(261, '5', 'updated_by', 'Updated By', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(262, '5', 'updated_date', 'Updated Date', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(263, '5', 'current_status', 'Current Status', '', 0, '', 0, 1, 'driver_info', 'Complaint'),
(264, '5', 'complaint_list_tab', 'Complaint List', '', 0, '', 0, 1, NULL, NULL),
(265, '5', 'complaint_type_tab', 'Complaint Type', '', 0, '', 0, 1, NULL, NULL),
(266, '5', 'id_complaint_type_table', 'ID', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(267, '5', 'complaint_type_complaint_type_table', 'Complaint Type', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(268, '5', 'description_complaint_type_table', 'Description', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(269, '5', 'createdby_complaint_type_table', 'Created By', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(270, '5', 'createdon_complaint_type_table', 'Created On', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(271, '5', 'updated_by__complaint_type_table', 'Updated By', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(272, '5', 'updatedon_complaint_type_table', 'Updated On', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(273, '5', 'action_complaint_type_table', 'Action', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(274, '5', 'add_complaintType', 'Add Type', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(275, '5', 'complaintType_addComplaintPopup', 'Complaint type', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(276, '5', 'subComplaint_addComplaintPopup', 'Sub Complaint', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(277, '5', 'manage_complaintType', 'Manage Complaint', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(278, '5', 'id_manageComplaintPopup', 'ID', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(279, '5', 'complaintType_manageComplaintPopup', 'Complaint Type', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(280, '5', 'description_manageComplaintPopup', 'Description', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(281, '5', 'updateButton_manageComplaintPopup', 'Update', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(282, '5', 'deleteButton_manageComplaintPopup', 'Delete', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(283, '5', 'addButon_addComplaintPopup', 'Add', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(284, '5', 'confirmDeletion_manageComplaintPopup', 'Do You Want To Delete Complaint Type', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(285, '5', 'yes_manageComplaintPopup', 'Yes', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(286, '5', 'no_manageComplaintPopup', 'No', '', 0, '', 0, 1, 'complaint_type_info', 'Complaint Type'),
(287, '5', 'id_enquiryType_table', 'ID', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(288, '5', 'enquiryType_enquiry_type_table', 'Enquiry Type', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(289, '5', 'createdBy_enquiry_type_table', 'Created By', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(290, '5', 'createdOn_enquiry_type_table', 'Created On', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(291, '5', 'updatedBy_enquiry_type_table', 'Updated By', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(292, '5', 'updatedOn_enquiry_type_table', 'Updated On', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(293, '5', 'status_enquiry_type_table', 'Status', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(294, '5', 'action_enquiry_type_table', 'Action', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(295, '5', 'add_enquiryType', 'Add Type', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(296, '5', 'enquiryType_addEnquiryPopup', 'Enquiry Type', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(297, '5', 'status_addEnquiryPopup', 'Status', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(298, '5', 'addButton_addEnquirypopup', 'Add', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(299, '5', 'manage_EnquiryType', 'Manage Enquiry', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(300, '5', 'id_manageEnquiryPopup', 'ID', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(301, '5', 'enquiryType_manageEnquiryPopup', 'Enquiry Type', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(302, '5', 'status_manageEnquiryPopup', 'Status', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(303, '5', 'updateButton_manageEnquiryPopup', 'Update', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(304, '5', 'deleteButton_manageEnquiryPopup', 'Delete', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(305, '5', 'confirmDeletion_manageEnquiryPopup', 'Do You Want To Delete Enquiry Type', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(306, '5', 'yes_manageEnquiry Popup', 'Yes', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(307, '5', 'no_manageEnquiryPopup', 'No', '', 0, '', 0, 1, 'enquiry_type_info', 'Enquiry Type'),
(308, '5', 'id_actionType_table', 'ID', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(309, '5', 'actionType_action_type_table', 'Action Type', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(310, '5', 'createdBy_action_type_table', 'Created By', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(311, '5', 'createdOn_action_type_table', 'Created On', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(312, '5', 'updatedBy_action_type_table', 'Updated By', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(313, '5', 'updatedOn_action_type_table', 'Updated On', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(314, '5', 'status_action_type_table', 'Status', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(315, '5', 'action_action_type_table', 'Action', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(316, '5', 'add_actionType', 'Add Type', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(317, '5', 'actionType_addActionPopup', 'Action Type', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(318, '5', 'status_addActionPopup', 'Status', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(319, '5', 'addButton_addActionpopup', 'Add', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(320, '5', 'manage_actionType', 'Manage Action', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(321, '5', 'id_manageActionPopup', 'ID', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(322, '5', 'actionType_manageActionPopup', 'Action Type', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(323, '5', 'status_manageActionPopup', 'Status', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(324, '5', 'updateButton_manageActionPopup', 'Update', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(325, '5', 'deleteButton_manageActionPopup', 'Delete', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(326, '5', 'confirmDeletion_manageActionPopup', 'Do you want to delete Action Type', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(327, '5', 'yes_manageActionPopup', 'Yes', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(328, '5', 'no_manageActionPopup', 'No', '', 0, '', 0, 1, 'action_type_info', 'Action Type'),
(347, '5', 'enquiryList_filterHead', 'Filter', '', 0, '', 0, 1, '', ''),
(348, '5', 'createdDate_enquiryFilterHeading', 'Created Date', '', 0, '', 0, 1, '', ''),
(349, '5', 'updatedDate_enquiryFilterHeading', 'Updated Date', '', 0, '', 0, 1, '', ''),
(350, '5', 'enquiryType_enquiryFilterHeading', 'Enquiry Date', '', 0, '', 0, 1, '', ''),
(351, '5', 'status_enquiryFilterHeading', 'Status', '', 0, '', 0, 1, '', ''),
(352, '5', 'id_enquiryListTable', 'Id', '', 0, '', 0, 1, '', ''),
(353, '5', 'callerName_enquiryListTable', 'Caller Name', '', 0, '', 0, 1, '', ''),
(354, '5', 'email_enquiryListTable', 'Email', '', 0, '', 0, 1, '', ''),
(355, '5', 'contactNo_enquiryListTable', 'Contact No', '', 0, '', 0, 1, '', ''),
(356, '5', 'csrID_enquiryListTable', 'CSR ID', '', 0, '', 0, 1, '', ''),
(357, '5', 'description_enquiryListTable', 'Description', '', 0, '', 0, 1, '', ''),
(358, '5', 'enquiryType_enquiryListTable', 'Enquiry Type', '', 0, '', 0, 1, '', ''),
(359, '5', 'enquiryDate_enquiryListTable', 'Enquiry Date', '', 0, '', 0, 1, '', ''),
(360, '5', 'status_enquiryListTable', 'Status', '', 0, '', 0, 1, '', ''),
(361, '5', 'updatedBy_enquiryListTable', 'Updated By', '', 0, '', 0, 1, '', ''),
(362, '5', 'updatedDate_enquiryListTable', 'Updated On', '', 0, '', 0, 1, '', ''),
(363, '5', 'id_enquiry_list_info', 'ID', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(364, '5', 'csrID_enquiry_list_info', 'CSR ID', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(365, '5', 'callerId_enquiry_list_info', 'Caller ID', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(366, '5', 'callerName_enquiry_list_info', 'Caller Name', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(367, '5', 'contactNo_enquiry_list_info', 'Contact No', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(368, '5', 'email_enquiry_list_info', 'Email', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(369, '5', 'city_enquiry_list_info', 'City', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(370, '5', 'enquiryType_enquiry_list_info', 'Enquiry Type', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(371, '5', 'address_enquiry_list_info', 'Address', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(372, '5', 'locality_enquiry_list_info', 'Locality', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(373, '5', 'message_enquiry_list_info', 'Message', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(374, '5', 'contracted_enquiry_list_info', 'Contracted', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(375, '5', 'enquiryDate_enquiry_list_info', 'Enquiry Date', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(376, '5', 'status_enquiry_list_info', 'Status', '', 0, '', 0, 1, 'enquiry_list_info', 'Enquiry Details'),
(408, '8', 'fair_management_head', 'Fair Management', '', 0, '', 0, 1, '', ''),
(409, '8', 'fair_management_filterHead', 'Filter', '', 0, '', 0, 1, '', ''),
(410, '8', 'vehicleNo_fairFilterHeading', 'Vehicle No', '', 0, '', 0, 1, '', ''),
(411, '8', 'vehicleModel_fareFilterHeading', 'Vehicle Model', '', 0, '', 0, 1, '', ''),
(412, '8', 'registrartionDate_fareFilterHeading', 'Registration Date', '', 0, '', 0, 1, '', ''),
(413, '8', 'country_fairFilterHeading', 'Country', '', 0, '', 0, 1, '', ''),
(414, '8', 'state_fairFilterHeading', 'State', '', 0, '', 0, 1, '', ''),
(415, '8', 'city_fairFilterHeading', 'City', '', 0, '', 0, 1, '', ''),
(416, '8', 'sno_fairTable', 'S.No', '', 0, '', 0, 1, '', ''),
(417, '8', 'cabType_fairTable', 'Cab Type', '', 0, '', 0, 1, '', ''),
(418, '8', 'country_fairTable', 'Country', '', 0, '', 0, 1, '', ''),
(419, '8', 'state_fairTable', 'State', '', 0, '', 0, 1, '', ''),
(420, '8', 'city_fairTable', 'City', '', 0, '', 0, 1, '', ''),
(421, '8', 'ratePerKm_fairTable', 'Rate/Km', '', 0, '', 0, 1, '', ''),
(422, '8', 'ratePerHour_fairTable', 'Rate/Hour', '', 0, '', 0, 1, '', ''),
(423, '8', 'minimumCharge_fairTable', 'Minimum Charge', '', 0, '', 0, 1, '', ''),
(424, '8', 'action_fairTable', 'Action', '', 0, '', 0, 1, '', ''),
(425, '8', 'package_head', '1. Package Calculation', '', 0, '', 0, 1, '', ''),
(426, '8', 'localHire_package', 'Local Hire', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(427, '8', 'distance_localHirePackage', 'Distance', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(428, '8', 'hour_localHirePackage', 'Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(429, '8', 'distanceHour_localHirePackage', 'Distance + Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(430, '8', 'distanceWaiting_localHirePackage', 'Distance + Waiting', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(431, '8', 'point_package', 'Point To Point', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(432, '8', 'distance_pointPackage', 'Distance', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(433, '8', 'hour_pointPackage', 'Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(434, '8', 'distanceHour_pointPackage', 'Distance + Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(435, '8', 'distanceWaiting_pointPackage', 'Distance + Waiting', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(436, '8', 'airport_package', 'Airport Transfer', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(437, '8', 'distance_airportPackage', 'Distance', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(438, '8', 'hour_airportPackage', 'Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(439, '8', 'distanceHour_airportPackage', 'Distance + Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(440, '8', 'distanceWaiting_airportPackage', 'Distance + Waiting', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(441, '8', 'outstation_package', 'Outstation', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(442, '8', 'distance_outstationPackage', 'Distance', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(443, '8', 'hour_outstationPackage', 'Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(444, '8', 'distanceHour_outstationPackage', 'Distance + Hour', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(445, '8', 'distanceWaiting_outstationPackage', 'Distance + Waiting', '', 0, '', 0, 1, 'package_info', 'Package Calculation'),
(446, '8', 'distance_head', '2. Distance', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(447, '8', 'distanceRates_distance', 'Distance Rates', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(448, '8', 'ratePerKm_distance', 'Rate Per Km', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(449, '8', 'ratePerKmRupees_distance', 'Rs', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(450, '8', 'firstKmRate_distance', 'Ignore First Km Rate', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(451, '8', 'minimumCharge_distance', 'Minimum Fare', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(452, '8', 'minimumChargeRupees_distance', 'Rs', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(453, '8', 'roundUpKm_distance', 'Round Up Kms', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(454, '8', 'cancellationFees_distance', 'Cancellation Fees', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(455, '8', 'cancellationFeeRupees_cancellation', 'Rs', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(456, '8', 'cancellationFeePercent_cancellation', '%', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(457, '8', 'accumulated_distance', 'Distances', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(458, '8', 'accumulated_distance_detail', 'You May Wish To Charge Different Rate Per Km \nDepending On The Length Of The Journey', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(459, '8', 'accumulated_instance', 'Accumulated Instances', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(460, '8', 'km_upto_accumulated', 'Kms Up To', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(461, '8', 'rate_per_km_accumulated', 'Rate Per Km', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(462, '8', 'ratePerKmRupeesUnit_distance', 'Rs', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(463, '8', 'hour_head', '3. Hour', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(464, '8', 'hourlyRates_hour', 'Hourly Rates', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(465, '8', 'ratePerHour_hour', 'Rate Per hour', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(466, '8', 'ratePerHourRupees_hour', 'Rs', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(467, '8', 'waitingTime_hour', 'Waiting Time Fees', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(468, '8', 'waitingTimeDetail_hour', 'You Can Charge An Additional Fee For Waiting \nTime Upto 10 Minutes, Another From 11- 20 \nMinutes, And So On', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(469, '8', 'waitingMinutesUpTo_hour', 'Minutes Up To', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(470, '8', 'waitingFee_hour', 'Fee', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(471, '8', 'waitingFeeRupees_hour', 'Rs', '', 0, '', 0, 1, 'hour_info', 'Hour'),
(472, '8', 'distanceHour_head', '4. Distance + Hour', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(473, '8', 'distanceRates_distanceHour', 'Distance Rates', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(474, '8', 'ratePerKm_distanceHour', 'Rate Per Km', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(475, '8', 'ratePerKmRupees_distanceHour', 'Rs', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(476, '8', 'firstKmRate_distanceHour', 'Ignore First Km After', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(477, '8', 'minimumFare_distanceHour', 'Minimum Fare', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(478, '8', 'minimumFareRupees_distanceHour', 'Rs', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(479, '8', 'hourlyRates_distanceHour', 'Hourly Rates', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(480, '8', 'ratePerHour_distanceHour', 'Rate Per Hour', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(481, '8', 'ratePerHourRupees_distanceHour', 'Rs', '', 0, '', 0, 1, 'distanceHour_info', 'Distance + Hour'),
(482, '8', 'distanceWaiting_head', '5. Distance Waiting', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(483, '8', 'distanceRate_distanceWaiting', 'Distance Rates', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(484, '8', 'ratePerKm_distanceWaiting', 'Rate Per Km', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(485, '8', 'ratePerKmRupees_distanceWaiting', 'Rs', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(486, '8', 'firstKmRate_distanceWaiting', 'Ignore First Km After', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(487, '8', 'minimumFare_distanceWaiting', 'Minimum Fare', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(488, '8', 'minimumFareRupees_distanceWaiting', 'Rs', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(489, '8', 'waitTime_distanceWaiting', 'Waiting Time Fees', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(490, '8', 'waitTimeDetail_distanceWaiting', 'You Can Charge An Additional Fee For Waiting Time\n Upto 10 Minutes, Another From 11- 20 Mminutes, \nAnd So On', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(491, '8', 'minuteUpTo_distanceWaiting', 'Minutes Up To', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(492, '8', 'minuteUpToRupees_distanceWaiting', 'Rs', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(493, '8', 'fee_distanceWaiting', 'Fee', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(494, '8', 'feeRupees_distanceWaiting', 'Rs', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(495, '8', 'afterFees_distanceWaiting', 'After That Fees Per Minute', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(496, '8', 'afterFessRupees_distanceWaiting', 'Rs', '', 0, '', 0, 1, 'distanceWaiting_info', 'Distance + Waiting'),
(497, '8', 'basic_head', '6. Basic', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(498, '8', 'tax_basic', 'Tax', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(499, '8', 'taxPercent_basic', '%', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(500, '8', 'cash_basic', 'Cash', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(501, '8', 'creditCard_basic', 'Account / Credit Card', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(502, '8', 'rounding_basic', 'Rounding', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(503, '8', 'cashRounding_basic', 'Cash', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(504, '8', 'creditCardRounding_basic', 'Account / Credit Card', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(505, '8', 'level_basic', 'Level', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(506, '8', 'normalLevel_basic', 'Normal', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(507, '8', 'decimalLevel_basic', 'Decimal', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(508, '8', 'unitLevel_basic', 'Unit', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(509, '8', 'direction_basic', 'Direction', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(510, '8', 'nearestDirection_basic', 'Nearest', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(511, '8', 'upDirection_basic', 'Up', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(512, '8', 'downDirection_basic', 'Down', '', 0, '', 0, 1, 'basic_info', 'Basic'),
(513, '8', 'premium_head', '7. Premium', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(514, '8', 'nightPremium_premium', 'Night Premium', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(515, '8', 'nightPremiumPercent_premium', '%', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(516, '8', 'nightPremiumRupees_premium', 'Rs', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(517, '8', 'nightRateBegin_premium', 'Night Rate begins', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(518, '8', 'nightRateEnd_premium', 'Night Rate Ends', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(519, '8', 'premiums_premium', 'Premiums', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(520, '8', 'premiumsDetail_premium', 'A Premium is a Fee Automatically Added To a Fare At\nThe Time Of Booking Note, This Ts Different From An \nExtra Add On. Premiums Might Include Bookings \ntaken by credit Card. or on bank Holidays', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(521, '8', 'creditCard_premium', 'Credit Card', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(522, '8', 'creditCardPercent_premium', '%', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(523, '8', 'creditCardRupees_premium', 'Rs', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(524, '8', 'extras_premium', 'Extras', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(525, '8', 'extrasDetail_premium', 'An Extra Is Any Additional Cost On Top Of The Quoted\n Fare. E.g. You May Wish To Charge Extra For A Child \nSeat Or A Parking Fee. Add Bespoke Extras Here. \nWith a Percentage Of The Fare Or Fixed Amount \nAdded', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(526, '8', 'extrasRupees_premium', 'Rs', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(527, '8', 'extrasPercent_premium', '%', '', 0, '', 0, 1, 'premium_info', 'Premium'),
(528, '8', 'fixedRoute_head', '8. Fixed Routes', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(529, '8', 'frequentPostcode_fixedRoute', 'Frequent Location to Postcode', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(530, '8', 'frequentPostcodeDetail_fixedRoute', 'You must define Frequent locations in \nPreferences > Frequent Locations before you can set custom priceshare. Use a complete postcode / Zip code, or just a prefix for postcode areas.', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(531, '8', 'frequentLocation_fixedRoute', 'Frequent Location', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(532, '8', 'postcode_fixedRoute', 'Postcode To Postcode', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(533, '8', 'postcodeDetail__fixedRoute', 'Fix rates from one Postcode (or Zip code) to \nanother; this can be done using exact Postcodes \nor postcode areas (prefix only)', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(534, '8', 'pickUpPostcode_fixedRoute', 'Pick Up Postcode', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(535, '8', 'dropOffPostcode_fixedRoute', 'Drop Off Postcode', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(536, '8', 'value_fixedRoute', 'Value', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(537, '8', 'postcodeRupees_fixedRoute', 'Rs', '', 0, '', 0, 1, 'fixedRoute_info', 'Fixed Routes'),
(538, '8', 'share_head', '9. Share', '', 0, '', 0, 1, 'share_info', 'Share'),
(539, '8', 'different_share', 'Different Shares', '', 0, '', 0, 1, 'share_info', 'Share'),
(540, '8', 'company_share', 'Company Share', '', 0, '', 0, 1, 'share_info', 'Share'),
(541, '8', 'companyPercent_share', '%', '', 0, '', 0, 1, 'share_info', 'Share'),
(542, '8', 'partner_share', 'Partner Share', '', 0, '', 0, 1, 'share_info', 'Share'),
(543, '8', 'partnerPercent_share', '%', '', 0, '', 0, 1, 'share_info', 'Share'),
(544, '8', 'driver_share', 'Driver Share', '', 0, '', 0, 1, 'share_info', 'Share'),
(545, '8', 'driverPercent_share', '%', '', 0, '', 0, 1, 'share_info', 'Share'),
(546, '8', 'firstKmRateRupees_distance', 'Rs', '', 0, '', 0, 1, 'distance_info', 'Distance'),
(547, '2', 'booking_header', 'Booking', '', 98, '', 0, 1, NULL, NULL),
(548, '8', 'FormType_fairTable', 'Booking Type', '', 0, '', 0, 1, NULL, NULL),
(549, '8', 'CalculatedBy_fairTable', 'Calculated By', '', 0, '', 2, 1, NULL, NULL);

-- --------------------------------------------------------

--
