Exemplo n.º 1
0
 /**
  * This function is responsible for all the data that is 
  * needed by different pages viaajax
  * 
  * @return Depends on what what is being called 
  */
 public function data()
 {
     // BEGIN CHECK VEHICLE VIN
     if (isset($_POST['vehicles_vin']) && $_POST['vehicles_vin'] != "") {
         $vehicles_vin = $_POST['vehicles_vin'];
         $vehicles_vin_status = Vehicle::where('vehicles_vin', $vehicles_vin)->withTrashed()->get()->count();
         if ($vehicles_vin_status > 0) {
             return 1;
         }
     }
     // END CHECK VEHICLE VIN
     // BEGIN CHECK VEHICLE LIC NO
     if (isset($_POST['registrations_licence_plate_no']) && $_POST['registrations_licence_plate_no'] != "") {
         $registrations_licence_plate_no = $_POST['registrations_licence_plate_no'];
         $registrations_licence_plate_no_status = Registration::withTrashed()->where('registrations_licence_plate_no', $registrations_licence_plate_no)->get()->count();
         if ($registrations_licence_plate_no_status > 0) {
             return 1;
         }
     }
     // END CHECK VEHICLE LIC NO
     // BEGIN SHOW ALL MAKES (USER CLICKED ON YEAR)
     if (isset($_POST['inp']) && $_POST['inp'] == 1) {
         /* REMOVE TO SHOW ALL MODELS
         				$model_make_ar = ['-1' => 'Select Make'] + Model::distinct()->orderBy('model_make_id')->lists('model_make_id', 'model_make_id');
         			*/
         $vehicles_year = $_POST['vehicles_year'];
         $model_make_ar = ['-1' => 'Select Make'] + Model::where('model_year', $vehicles_year)->distinct()->orderBy('model_make_id')->lists('model_make_id', 'model_make_id');
         $model_make_ar['add_new'] = "Add New";
         foreach ($model_make_ar as $model_make_ar_fet) {
             echo "<option value='{$model_make_ar_fet}'>{$model_make_ar_fet}</option>";
         }
     }
     // END SHOW ALL MAKES (USER CLICKED ON YEAR)
     // BEGIN SHOW ALL ASSOCIATED MODELS NAME AND TRIM (USER CLICKED ON MAKE)
     if (isset($_POST['inp']) && $_POST['inp'] == 2) {
         $vehicles_year = $_POST['vehicles_year'];
         $vehicles_make_id = $_POST['vehicles_make_id'];
         $vehicles_name_trim_arr = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->get(['model_name', 'model_trim'])->toArray();
         foreach ($vehicles_name_trim_arr as $vehicles_name_trim_arr_fet) {
             $vehicles_name_trim[] = implode(', ', $vehicles_name_trim_arr_fet);
         }
         $vehicles_name_trim = array_unique($vehicles_name_trim);
         sort($vehicles_name_trim);
         $firstOp = "<option value='-1'>Select Model</option>";
         echo $firstOp;
         foreach ($vehicles_name_trim as $vehicles_name_trim_fet) {
             echo "<option value='{$vehicles_name_trim_fet}'>{$vehicles_name_trim_fet}</option>";
         }
     }
     // BEGIN SHOW ALL ASSOCIATED MODELS NAME AND TRIM (USER CLICKED ON MAKE)
     // BEGIN SHOW ALL ASSOCIATED BODY STYLE (USER CLICKED ON MODEL)
     if (isset($_POST['inp']) && $_POST['inp'] == 3) {
         $vehicles_year = $_POST['vehicles_year'];
         $vehicles_make_id = $_POST['vehicles_make_id'];
         $vehicles_name_trim = $_POST['vehicles_name_trim'];
         $vehicles_name_trim_ar = explode(',', $vehicles_name_trim);
         $model_name = trim($vehicles_name_trim_ar[0]);
         $model_trim = trim($vehicles_name_trim_ar[1]);
         $vehicles_body_ar = array_filter(array_unique(Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->lists('model_body')));
         sort($vehicles_body_ar);
         $firstOp = "<option value='-1'>Select Body Style</option>";
         echo $firstOp;
         foreach ($vehicles_body_ar as $vehicles_body) {
             echo "<option value='{$vehicles_body}'>{$vehicles_body}</option>";
         }
     }
     // END SHOW ALL ASSOCIATED BODY STYLE (USER CLICKED ON MODEL)
     // BEGIN SHOW ASSOCIATED BODY WEIGHT (USER CLICKED ON BODY STYLE)
     // ALSO RESPONSIBLE FOR REPLYING TO AJAX REQUEST WHEN USER CLICKED ON MODEL
     if (isset($_POST['inp']) && $_POST['inp'] == 4) {
         $vehicles_year = $_POST['vehicles_year'];
         $vehicles_make_id = $_POST['vehicles_make_id'];
         $vehicles_name_trim = $_POST['vehicles_name_trim'];
         $vehicles_name_trim_ar = explode(',', $vehicles_name_trim);
         $model_name = trim($vehicles_name_trim_ar[0]);
         $model_trim = trim($vehicles_name_trim_ar[1]);
         // USER CLICKED ON MODEL
         if (!isset($_POST['vehicles_body'])) {
             $model_weight_kg_ar = array_filter(array_unique(Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_year', $vehicles_year)->lists('model_weight_kg')));
             if (!empty($model_weight_kg_ar)) {
                 sort($model_weight_kg_ar);
                 $firstOp = "<option value='-1'>Select Gross Weight</option>";
                 echo $firstOp;
                 foreach ($model_weight_kg_ar as $model_weight_kg_ar_fet) {
                     echo "<option value='{$model_weight_kg_ar_fet}'>{$model_weight_kg_ar_fet}</option>";
                 }
             } else {
                 return 0;
             }
         } else {
             $vehicles_body = $_POST['vehicles_body'];
             $model_weight_kg_ar = array_filter(array_unique(Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->where('model_year', $vehicles_year)->lists('model_weight_kg')));
             if (!empty($model_weight_kg_ar)) {
                 sort($model_weight_kg_ar);
                 $firstOp = "<option value='-1'>Select Gross Weight</option>";
                 echo $firstOp;
                 foreach ($model_weight_kg_ar as $model_weight_kg_ar_fet) {
                     echo "<option value='{$model_weight_kg_ar_fet}'>{$model_weight_kg_ar_fet}</option>";
                 }
             } else {
                 return 0;
             }
         }
     }
     // END SHOW ASSOCIATED BODY WEIGHT (USER CLICKED ON BODY STYLE)
     // BEGIN CLICK ON VEHICLE USE TYPE
     if (isset($_POST['inp']) && $_POST['inp'] == 5) {
         $vehicles_use_type = $_POST['vehicles_use_type'];
         $vehicles_weight_kg = $_POST['vehicles_weight_kg'];
         // BEGIN SWITCH TO SWITCH BETWEEN DIFFERENT VEHICLE USE TYPES (EXCEPT COMMERCIAL - PASSENGER)
         switch ($vehicles_use_type) {
             //NONE SELECTED
             case -1:
                 $firstOp = "<option value='-1'>Select Class</option>";
                 echo $firstOp;
                 break;
                 // BEGIN COMMERCIAL OWN GOODS VEHICLE
             // BEGIN COMMERCIAL OWN GOODS VEHICLE
             case 3:
                 // CHECK VALUES BETWEEN MIN AND MAX WEIGHT
                 $vehicle_class_ar = FeesCommercialOwnGood::whereRaw('? BETWEEN coalesce(`fees_commercial_own_goods_min_kg`) AND coalesce(`fees_commercial_own_goods_max_kg`, ?)', [$vehicles_weight_kg, 10000])->lists('fees_commercial_own_goods_class', 'id');
                 foreach ($vehicle_class_ar as $id => $vehicle_class_ar_fet) {
                     echo "<option value='{$id}'>{$vehicle_class_ar_fet}</option>";
                 }
                 break;
                 // END COMMERCIAL OWN GOODS VEHICLE
                 // BEGIN MOTORCYCLE
             // END COMMERCIAL OWN GOODS VEHICLE
             // BEGIN MOTORCYCLE
             case 8:
                 $vehicle_class_ar = FeesMotorcycle::lists('fees_motorcycle_class', 'id');
                 $firstOp = "<option value='-1'>Select Class</option>";
                 asort($vehicle_class_ar);
                 echo $firstOp;
                 foreach ($vehicle_class_ar as $id => $vehicle_class_ar_fet) {
                     echo "<option value='{$id}'>{$vehicle_class_ar_fet}</option>";
                 }
                 break;
                 // END MOTORCYCLE
                 // BEGIN PRIVATE NGO, GG/MUNICIPALITY, COMPANYRENTAL AND RENTAL
             // END MOTORCYCLE
             // BEGIN PRIVATE NGO, GG/MUNICIPALITY, COMPANYRENTAL AND RENTAL
             default:
                 if ($vehicles_weight_kg != -1) {
                     // CHECK VALUES BETWEEN MIN AND MAX WEIGHT
                     $vehicle_class_ar = FeesPrivate::whereRaw('? BETWEEN coalesce(`fees_private_min_kg`) AND coalesce(`fees_private_max_kg`, ?)', [$vehicles_weight_kg, 10000])->lists('fees_private_class', 'id');
                     foreach ($vehicle_class_ar as $id => $vehicle_class_ar_fet) {
                         echo "<option value='{$id}'>{$vehicle_class_ar_fet}</option>";
                     }
                 }
                 // END PRIVATE NGO, GG/MUNICIPALITY, COMPANYRENTAL AND RENTAL
         }
         // END SWITCH TO SWITCH BETWEEN DIFFERENT VEHICLE USE TYPES (EXCEPT COMMERCIAL - PASSENGER)
     }
     // END CLICK ON VEHICLE USE TYPE
     // BEGIN CLICK ON VEHICLE USE TYPE(COMMERCIAL PASSENGERS)
     if (isset($_POST['inp']) && $_POST['inp'] == 6) {
         $vehicle_class_ar = FeesCommercialPassenger::lists('fees_commercial_passengers_no_of_passenger', 'id');
         $firstOp = "<option value='-1'>Select No. Of Passengers</option>";
         ksort($vehicle_class_ar);
         echo $firstOp;
         foreach ($vehicle_class_ar as $id => $vehicle_class_ar_fet) {
             echo "<option value='{$id}'>{$vehicle_class_ar_fet}</option>";
         }
     }
     // END CLICK ON VEHICLE USE TYPE(COMMERCIAL PASSENGERS)
     // BEGIN CLICK ON NO. OF PASSENGERS
     if (isset($_POST['inp']) && $_POST['inp'] == 7) {
         $vehicles_no_of_passengers = $_POST['vehicles_no_of_passengers'];
         $vehicle_class_ar = FeesCommercialPassenger::where('id', $vehicles_no_of_passengers)->lists('fees_commercial_passengers_class', 'id');
         foreach ($vehicle_class_ar as $id => $vehicle_class_ar_fet) {
             echo "<option value='{$id}'>{$vehicle_class_ar_fet}</option>";
         }
     }
     // END CLICK ON NO. OF PASSENGERS
     // BEGIN AJAX REQUEST TO GENERATE REGISTRATION NO. (MODEL ALREADY IN DB)
     if (isset($_POST['inp']) && $_POST['inp'] == 8) {
         $vehicles_make_id = trim(Input::get('vehicles_make_id'));
         $vehicles_name_trim = trim(Input::get('vehicles_name_trim'));
         $vehicles_name_trim_ar = explode(',', $vehicles_name_trim);
         $model_name = trim($vehicles_name_trim_ar[0]);
         $model_trim = trim($vehicles_name_trim_ar[1]);
         $vehicles_body = trim(Input::get('vehicles_body'));
         $vehicles_weight_kg = trim(Input::get('vehicles_weight_kg'));
         $new_wt = (int) Input::get('new_wt');
         $vehicles_year = trim(Input::get('vehicles_year'));
         $vehicles_use_type = Input::get('vehicles_use_type');
         $vehicles_class = Input::get('vehicles_class');
         $vehicles_class_abbr = trim(Input::get('vehicles_class_abbr'));
         // IF DEFAULT WEIGHT IS PRESENT
         if ($new_wt) {
             // IF MODEL HAS BODY
             if ($vehicles_body) {
                 $model = Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->whereNull('model_weight_kg')->first();
             } else {
                 $model = Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->whereNull('model_body')->whereNull('model_weight_kg')->first();
             }
         } else {
             // IF MODEL HAS BODY
             if ($vehicles_body) {
                 $model = Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->where('model_weight_kg', $vehicles_weight_kg)->first();
             } else {
                 $model = Model::where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->whereNull('model_body')->where('model_weight_kg', $vehicles_weight_kg)->first();
             }
         }
         $model_year = $model->model_year;
         $model_make_id = strtoupper(substr($model->model_make_id, 0, 4));
         $year = date("Y");
         $class_sequence = Vehicle::vehicleRegistrationSequence($vehicles_use_type, $vehicles_class);
         //$class_sequence =  str_pad(Vehicle::withTrashed()->where('vehicles_use_type', $vehicles_use_type)->where('vehicles_class', $vehicles_class)->count()+1, 7, 0, STR_PAD_LEFT);
         return $vehicles_class_abbr . "-" . $year . "-" . $model_year . "-" . $model_make_id . "-" . $class_sequence;
     }
     // END AJAX REQUEST TO GENERATE REGISTRATION NO. (MODEL ALREADY IN DB)
     // BEGIN AJAX REQUEST TO GENERATE REGISTRATION NO. (NEW MODEL)
     if (isset($_POST['inp']) && $_POST['inp'] == 9) {
         $vehicles_make_id = strtoupper(substr(trim(Input::get('vehicles_make_id')), 0, 4));
         $vehicles_year = trim(Input::get('vehicles_year'));
         $vehicles_use_type = Input::get('vehicles_use_type');
         $vehicles_class = Input::get('vehicles_class');
         $vehicles_class_abbr = trim(Input::get('vehicles_class_abbr'));
         $year = date("Y");
         $class_sequence = Vehicle::vehicleRegistrationSequence($vehicles_use_type, $vehicles_class);
         //$class_sequence =  str_pad(Vehicle::withTrashed()->where('vehicles_use_type', $vehicles_use_type)->where('vehicles_class', $vehicles_class)->count()+1, 7, 0, STR_PAD_LEFT);
         return $registration_number = $vehicles_class_abbr . "-" . $year . "-" . $vehicles_year . "-" . $vehicles_make_id . "-" . $class_sequence;
     }
     // END AJAX REQUEST TO GENERATE REGISTRATION NO. (NEW MODEL)
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING REGISTRATION NO. (vehicle.search, vehicle.search-by-reg)
     if (isset($_POST['registrations_no']) && $_POST['registrations_no'] != "") {
         $registrations_no = $_POST['registrations_no'];
         $vehicles_id_count = Registration::withTrashed()->where('registrations_no', $registrations_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::withTrashed()->where('registrations_no', $registrations_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::withTrashed()->find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('vehicle.edit', [$vehicles_id]);
             $urlShow = URL::route('vehicle.show', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$urlShow}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$urlShow} class='btn default btn-xs purple'>\n\t\t\t\t\t\t<i class='fa fa-edit'></i>Details</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING REGISTRATION NO.
     // BEGIN AJAX REQUEST TO SHOW VEHICLE HISTORY SEARCHED BY USING REGISTRATION NO. TO VIEW ITS HISTORY (vehicle.search-vehicle-history)
     if (isset($_POST['registrations_no_search_history']) && $_POST['registrations_no_search_history'] != "") {
         $registrations_no = $_POST['registrations_no_search_history'];
         $vehicles_id_count = Registration::where('registrations_no', $registrations_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::where('registrations_no', $registrations_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             //$urlShow = URL::route('vehicle.show', [$vehicles_id]);
             $urlHistory = URL::route('print.vehicle.history', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$urlHistory}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$urlHistory} class='btn default btn-xs purple'>\n\t\t\t\t\t\t</i>History</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE HISTORY SEARCHED BY USING REGISTRATION NO.
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING REGISTRATION NO. TO CHANGE ITS OWNER (vehicle.search-change-owner)
     if (isset($_POST['registrations_no_change_owner']) && $_POST['registrations_no_change_owner'] != "") {
         $registrations_no = $_POST['registrations_no_change_owner'];
         $vehicles_id_count = Registration::where('registrations_no', $registrations_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::where('registrations_no', $registrations_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('change.owner.edit', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$url}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t</i>Change Owner</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE HISTORY SEARCHED BY USING REGISTRATION NO.
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING REGISTRATION NO. TO UPDATE IT (vehicle.search-vehicle-update)
     if (isset($_POST['registrations_no_search_update']) && $_POST['registrations_no_search_update'] != "") {
         $registrations_no = $_POST['registrations_no_search_update'];
         $vehicles_id_count = Registration::where('registrations_no', $registrations_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::where('registrations_no', $registrations_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('vehicle.edit', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$url}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t</i>Update Vehicle</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE HISTORY SEARCHED BY USING REGISTRATION NO.
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING REGISTRATION NO. TO EDIT/UPDATE STICKER (vehicle.search-sticker)
     if (isset($_POST['registrations_no_update_sticker']) && $_POST['registrations_no_update_sticker'] != "") {
         $registrations_no = $_POST['registrations_no_update_sticker'];
         $vehicles_id_count = Registration::where('registrations_no', $registrations_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::where('registrations_no', $registrations_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('vehicle.sticker', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$url}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t</i>Issue/Renew Sticker</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE HISTORY SEARCHED BY USING REGISTRATION NO.
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING LICENSE PLATE NO (vehicle.search)
     if (isset($_POST['registrations_licence_plate_no_search']) && $_POST['registrations_licence_plate_no_search'] != "") {
         $registrations_licence_plate_no = $_POST['registrations_licence_plate_no_search'];
         $vehicles_id_count = Registration::withTrashed()->where('registrations_licence_plate_no', $registrations_licence_plate_no)->count();
         if ($vehicles_id_count != 0) {
             $vehicles_id = Registration::withTrashed()->where('registrations_licence_plate_no', $registrations_licence_plate_no)->first()->registrations_vehicle_id;
             $vehicles = Vehicle::withTrashed()->find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('vehicle.edit', [$vehicles_id]);
             $urlShow = URL::route('vehicle.show', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$urlShow}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t<i class='fa fa-edit'></i>Edit</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING LICENSE PLATE NO
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING DRIVER NIN (vehicle.search)
     if (isset($_POST['owners_nin_search']) && $_POST['owners_nin_search'] != "") {
         $owners_nin = $_POST['owners_nin_search'];
         $owner = Driver::where('drivers_nin', $owners_nin)->first();
         // DRIVER EXISTS
         if ($owner) {
             //$owner->id;
             $vehicles = $owner->vehicleOwnerTransferred;
             if ($vehicles->count() > 0) {
                 $row = "";
                 foreach ($vehicles as $vehicle) {
                     $vehicles_id = $vehicle->id;
                     $vehicles_vin = $vehicle->vehicles_vin;
                     $model_make_id = $vehicle->model->model_make_id;
                     $model_name = $vehicle->model->model_name;
                     $vehicle_use_types_name = $vehicle->vehicleUseType->vehicle_use_types_name;
                     $urlShow = URL::route('vehicle.show', [$vehicles_id]);
                     $url = URL::route('vehicle.edit', [$vehicles_id]);
                     $row .= "<tr>";
                     $row .= "<td><a href={$urlShow}>{$vehicles_vin}</a></td>";
                     $row .= "<td>{$model_make_id}</td>";
                     $row .= "<td>{$model_name}</td>";
                     $row .= "<td>{$vehicle_use_types_name}</td>";
                     $row .= "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t\t\t<i class='fa fa-edit'></i>Edit</a></td>";
                     $row .= "</tr>";
                 }
                 return $row;
             }
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING DRIVER NIN
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING STICKER (vehicle.search)
     if (isset($_POST['registrations_sticker_serial_no_search']) && $_POST['registrations_sticker_serial_no_search'] != "") {
         $registrations_sticker_serial_no = $_POST['registrations_sticker_serial_no_search'];
         $regRow = Registration::withTrashed()->where('registrations_sticker_serial_no', $registrations_sticker_serial_no)->first();
         if ($regRow) {
             $vehicles_id = $regRow->vehicle->id;
             $vehicles_vin = $regRow->vehicle->vehicles_vin;
             $model_make_id = $regRow->vehicle->model->model_make_id;
             $model_name = $regRow->vehicle->model->model_name;
             $vehicle_use_types_name = $regRow->vehicle->vehicleUseType->vehicle_use_types_name;
             $urlShow = URL::route('vehicle.show', [$vehicles_id]);
             $url = URL::route('vehicle.edit', [$vehicles_id]);
             $row = "";
             $row .= "<tr>";
             $row .= "<td><a href={$urlShow}>{$vehicles_vin}</a></td>";
             $row .= "<td>{$model_make_id}</td>";
             $row .= "<td>{$model_name}</td>";
             $row .= "<td>{$vehicle_use_types_name}</td>";
             $row .= "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t<i class='fa fa-edit'></i>Edit</a></td>";
             $row .= "</tr>";
             return $row;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING STICKER
     // BEGIN AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING COLLATERAL ID (vehicle.search)
     if (isset($_POST['liens_collateral_id_search']) && $_POST['liens_collateral_id_search'] != "") {
         $liens_collateral_id = $_POST['liens_collateral_id_search'];
         $lien_id_count = Lien::where('liens_collateral_id', $liens_collateral_id)->count();
         if ($lien_id_count != 0) {
             $lien = Lien::where('liens_collateral_id', $liens_collateral_id)->first();
             $vehicle = $lien->vehicle;
             $vehicles_id = $vehicle->id;
             $vehicles = Vehicle::find($vehicles_id);
             $vehicles_vin = $vehicles->vehicles_vin;
             $vehicles_model_id = $vehicles->vehicles_model_id;
             $vehicles_use_type_id = $vehicles->vehicles_use_type;
             $model = Model::find($vehicles_model_id);
             $model_make_id = $model->model_make_id;
             $model_name = $model->model_name;
             $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
             $url = URL::route('vehicle.edit', [$vehicles_id]);
             $urlShow = URL::route('vehicle.show', [$vehicles_id]);
             echo "<tr>";
             echo "<td><a href={$urlShow}>{$vehicles_vin}</a></td>";
             echo "<td>{$model_make_id}</td>";
             echo "<td>{$model_name}</td>";
             echo "<td>{$vehicle_use_types_name}</td>";
             echo "<td><a href={$url} class='btn default btn-xs purple'>\n\t\t\t\t\t\t<i class='fa fa-edit'></i>Edit</a></td>";
             echo "</tr>";
         } else {
             return 0;
         }
     }
     // END AJAX REQUEST TO SHOW VEHICLE SEARCHED BY USING COLLATERAL ID
     // BEGIN AJAX REQUEST TO CHECK IF FINES ARE ASSOCIATED WITH THE VEHICLE (FROM vehicle.show.blade.php)
     if (isset($_POST['vehicle_associated_fines']) && $_POST['vehicle_associated_fines'] != "") {
         //VEHICLE ID
         $vehicle_id = $_POST['vehicle_associated_fines'];
         return Vehicle::getVehiclePendingFinesMessage($vehicle_id);
     }
     // END AJAX REQUEST TO CHECK IF FINES ARE ASSOCIATED WITH THE VEHICLE (FROM vehicle.show.blade.php)
     // BEGIN AJAX REQUEST TO ADD NEW STICKER AND UPDATE ODOMETER (FROM vehicle.show.blade.php)
     if (isset($_POST['registrations_sticker_serial_no']) && $_POST['registrations_sticker_serial_no'] != "") {
         // VEHICLE ID
         $vehicles_id = trim($_POST['vehicles_id']);
         $registrations_sticker_serial_no = trim($_POST['registrations_sticker_serial_no']);
         // TAKE OLD ODOMETER IN LOG AND Update Odometer(Coming from registration renewal)
         if (isset($_POST['vehicles_odometer']) && $_POST['vehicles_odometer'] != 0) {
             $vehicles_odometer = $_POST['vehicles_odometer'];
             LogVehicleOdometer::create(['log_vehicle_odometer_vehicle_id' => $vehicles_id, 'log_vehicle_odometer_old_odometer' => $vehicles_odometer, 'log_vehicle_odometer_sticker' => $registrations_sticker_serial_no, 'log_vehicle_odometer_status' => 3]);
             Vehicle::find($vehicles_id)->update(['vehicles_odometer' => $vehicles_odometer]);
         } else {
             $logRow = LogVehicleOdometer::where('log_vehicle_odometer_vehicle_id', $vehicles_id)->where('log_vehicle_odometer_status', 1)->first();
             $logRow->log_vehicle_odometer_sticker = $registrations_sticker_serial_no;
             $logRow->save();
             //MARK FINES AS PAID(CASE IN WHICH VEHICLE STICKER IS BEING GENERATED FOR A VEHICLE WITH PRE-REGISTRATION FINES)
             //VEHICLE FINES
             $vehicleVoilations = ViolateVehicle::where('vehicle_id', $vehicles_id)->where('status', 2);
             if ($vehicleVoilations->count()) {
                 $vehicleVoilations->update(['status' => 1]);
             }
             //DRIVER FINES
             $driverVoilations = ViolateDriver::where('vehicle_id', $vehicles_id)->where('status', 2);
             if ($driverVoilations->count()) {
                 $driverVoilations->update(['status' => 1]);
             }
         }
         return Registration::registerSticker($vehicles_id, $registrations_sticker_serial_no);
     }
     // END AJAX REQUEST TO ADD NEW STICKER
     // BEGIN AJAX REQUEST TO CHECK IF STICKER IS ALREADY PRESENT
     if (Input::get('inp') == 10) {
         $registrations_sticker_serial_no = Input::get('sticker_no');
         $reg_check1 = Registration::where('registrations_sticker_serial_no', $registrations_sticker_serial_no)->first();
         if ($reg_check1) {
             return $reg_check1;
         } else {
             return LogVehicleOdometer::where('log_vehicle_odometer_sticker', $registrations_sticker_serial_no)->first();
         }
     }
     // END AJAX REQUEST TO CHECK IF STICKER IS ALREADY PRESENT
     // BEGIN AJAX REQUEST TO CHECK IF NIN ALREADY IN DATABASE
     if (Input::get('inp') == 11) {
         $old_drivers_nin_val_new = Input::get('old_drivers_nin_val_new');
         $owner = Driver::where('drivers_nin', $old_drivers_nin_val_new)->first();
         if ($owner) {
             if ($owner->drivers_mname) {
                 $owners_name = $owner->drivers_fname . " " . $owner->drivers_mname . " " . $owner->drivers_lname;
             } else {
                 $owners_name = $owner->drivers_fname . " " . $owner->drivers_lname;
             }
             $url = URL::route('driver.history', [$owner->id]);
             return "NIN already registered to <a href={$url}>{$owners_name}</a>";
         }
     }
     // END AJAX REQUEST TO CHECK IF NIN ALREADY IN DATABASE
     // BEGIN AJAX REQUEST TO CHECK IF Driver LICENSE NUMBER ALREADY IN DATABASE
     if (Input::get('inp') == 12) {
         $old_drivers_license_no_val_new = Input::get('old_drivers_license_no_val_new');
         $owner = Driver::where('drivers_license_no', $old_drivers_license_no_val_new)->first();
         if ($owner) {
             if ($owner->drivers_mname) {
                 $owners_name = $owner->drivers_fname . " " . $owner->drivers_mname . " " . $owner->drivers_lname;
             } else {
                 $owners_name = $owner->drivers_fname . " " . $owner->drivers_lname;
             }
             $url = URL::route('driver.history', [$owner->id]);
             return "License already registered to <a href={$url}>{$owners_name}</a>";
         }
     }
     // END AJAX REQUEST TO CHECK IF Driver LICENSE NUMBER ALREADY IN DATABASE
 }
Exemplo n.º 2
0
 public static function checkLicense($registrations_licence_plate_no_status)
 {
     $registrations_licence_plate_no_status = Registration::withTrashed()->where('registrations_licence_plate_no', $registrations_licence_plate_no_status)->get()->count();
     if ($registrations_licence_plate_no_status > 0) {
         return 1;
     }
 }