/** store vehicles license */
 public function store_license(Request $request)
 {
     $license_types = LicenseTypeVehicle::where('vehicle_id', $request->vehicle_id)->get();
     $vehicle = Vehicle::select('plate_number', 'client_id')->findOrFail($request->vehicle_id);
     $cur_date = date("Y-m-d H:i:s");
     foreach ($license_types as $license_type) {
         $license_type_id = $license_type->license_type_id;
         if (isset($request->{'status_' . $license_type_id})) {
             $save = LicenseRenewalRequest::where('license_type_id', '=', $license_type->license_type_id)->where('vehicle_id', '=', $request->vehicle_id)->where('status', '!=', $request->{'status_' . $license_type_id})->update(['status' => $request->{'status_' . $license_type_id}]);
             //update renewal request where there is chnage in the status.
             if ($save) {
                 // create notification.
                 switch ($request->{'status_' . $license_type_id}) {
                     case 'pending':
                         $status = "The renewal request for the vehicle {$vehicle->plate_number} status has marked pending";
                         $type = "renewal_request";
                         break;
                     case 'in-progress':
                         $status = "Your renewal request for the vehicle {$vehicle->plate_number} is in progress";
                         $type = "renewal_request";
                         break;
                     case 'completed':
                         $status = "Your renewal request for the vehicle {$vehicle->plate_number} has completed";
                         $type = "renewal_completed";
                         break;
                 }
                 $input_data = array('sent_to' => $vehicle->client_id, 'sent_on' => $cur_date, 'message' => $status, 'type' => $type);
                 LicenseNotification::create($input_data);
             }
             //
         }
         global $formated_start_date;
         $start_date = $request->{'license_type_start_' . $license_type->license_type_id};
         $formated_start_date = date('Y-m-d', strtotime($start_date));
         $formated_end_date = date('Y-m-d', strtotime('+365 days', strtotime($start_date)));
         $saved_license = LicenseTypeVehicle::where('vehicle_id', $request->vehicle_id)->where('license_type_id', $license_type_id)->where(function ($query) {
             global $formated_start_date;
             $query->where('license_start_on', '=', $formated_start_date)->orWhere('license_start_on', '=', '0000-00-00 00:00:00');
         })->get()->toArray();
         // check the form license date with the db license date
         if (empty($saved_license)) {
             // license date has changed
             LicenseTypeVehicle::where('id', $license_type->id)->update(['deleted_at' => date("Y-m-d H:i:s")]);
             $insert_data = array('license_type_id' => $license_type->license_type_id, 'vehicle_id' => $request->vehicle_id, 'license_start_on' => $formated_start_date, 'license_end_on' => $formated_end_date);
             LicenseTypeVehicle::create($insert_data);
             //soft delete the previous license date
             //insert the new date
         } else {
             LicenseTypeVehicle::where('id', $license_type->id)->update(['license_start_on' => $formated_start_date, 'license_end_on' => $formated_end_date]);
         }
         /* $start_date = $request->{'license_type_start_'.$license_type->license_type_id};
               $formated_start_date = date('Y-m-d', strtotime($start_date));
               $formated_end_date = date('Y-m-d', strtotime('+365 days',strtotime($start_date)));
               LicenseTypeVehicle::where('id', $license_type->id)
               ->update(['license_start_on' => $formated_start_date, 'license_end_on' => $formated_end_date, 'updated_at' => date("Y-m-d H:i:s")]);
            */
     }
     Session::flash('flash_message', trans('vehicle.vehicle_on_update'));
     return Redirect::to($request->redirect_to);
 }
 public function store_license(Request $request)
 {
     $license_types = LicenseTypeVehicle::where('vehicle_id', $request->vehicle_id)->get();
     foreach ($license_types as $license_type) {
         $start_date = $request->{'license_type_start_' . $license_type->license_type_id};
         $formated_start_date = date('Y-m-d', strtotime($start_date));
         $formated_end_date = date('Y-m-d', strtotime('+365 days', strtotime($start_date)));
         LicenseTypeVehicle::where('id', $license_type->id)->update(['license_start_on' => $formated_start_date, 'license_end_on' => $formated_end_date, 'updated_at' => date("Y-m-d H:i:s")]);
     }
     Session::flash('flash_message', trans('vehicle.vehicle_on_update'));
     return Redirect::to('/vehicles');
 }