  select  distinct ChassisNumber,SalesManID,challanno,KeyNo,ParkingNo,MobileNumber,
CustomerName,Email,MulkiyaNo,PlateNumber,mv2.MasterValue as VehicleBrand,mv2.MasterValueID as VehicleBrandID,mv.MasterValue as VehicleType,
mv.MasterValueID as VehicleTypeID,mv1.MasterValue as VehicleModel,mv1.MasterValueID as VehicleModelID,mv3.MasterValue as VehicleColor,
mv3.MasterValueID as VehicleColorID,mv4.MasterValue as VehicleYear,mv4.MasterValueID as VehicleYearID from InvoiceMaster as im
   inner join MASTER_VALUES as mv on im.VehicleType=mv.MasterValueID
   inner join MASTER_VALUES as mv1 on im.VehicleModel=mv1.MasterValueID
inner join MASTER_VALUES as mv2 on im.VehicleBrand=mv2.MasterValueID
inner join MASTER_VALUES as mv3 on im.VehicleColor=mv3.MasterValueID
inner join MASTER_VALUES as mv4 on im.VehicleYear=mv4.MasterValueID

   where $searchbox  InvoiceType=5 and im.active=1 and  not EXISTS(select 1 from InvoiceMaster as b where im.MobileNumber=b.MobileNumber and im.ChassisNumber=b.ChassisNumber
   and im.MulkiyaNo=b.MulkiyaNo and im.PlateNumber=b.PlateNumber   and im.Email=b.Email and im.CustomerName=b.CustomerName )