public function createSession(Request $request)
 {
     $spCode = $_COOKIE['SPCode'];
     $rules = array('Account_No' => 'required', 'Member_Id' => 'required', 'Visit_Date' => 'required', 'Service_Type' => 'required', 'Member_Type' => 'required', 'Member_Name' => 'required');
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         $data = array('Response' => $validation->errors()->first());
         return Response::json($data);
     } else {
         $iniClaimID = $this->getClaimID(Input::get('Visit_Date'));
         $iniDate = date_create(Input::get('Visit_Date'));
         $ref = date_format($iniDate, 'M Y');
         try {
             $session = new Sessions();
             $session->Date_Created = date('Y-m-d');
             $session->Expiry_Date = date('Y-m-d', time() + 21 * 24 * 60 * 60);
             $session->Account_No = Input::get('Account_No');
             $session->Member_ID = Input::get('Member_Id');
             $session->Member_Type = Input::get('Member_Type');
             $session->Dependant_Code = Input::get('Member_Id');
             $session->Name_Of_Member = Input::get('Member_Name');
             $session->Terminal_ID = $spCode;
             $session->Service_Type = Input::get('Service_Type');
             $session->Hosp_Folder_No = Input::get('Folder_Number');
             $session->Status = 'Pending';
             //$session->Out_Patient_Limit = Input::get('Account_No');
             //$session->In_Patient_Limit = Input::get('Account_No');
             //$session->Optical_Limit = Input::get('Account_No');
             //$session->Dental_Limit = Input::get('Account_No');
             $session->Claim_No = $iniClaimID;
             //$session->Created_By = Auth::user()->get_user_id();
             if ($session->save()) {
                 //Create Claim
                 $claim = new Claims();
                 $claim->Claim_ID = $iniClaimID;
                 $claim->SP_Code = $_COOKIE['SPCode'];
                 $claim->Service_Provider = $_COOKIE['SPName'];
                 $claim->Account_No = Input::get('Account_No');
                 $claim->Member_ID = Input::get('Member_Id');
                 $claim->Dependant_ID = Input::get('Member_Id');
                 $claim->Member_Level = Input::get('Member_Type');
                 $claim->Date_Filed = Input::get('Visit_Date');
                 //$claim->SP_User_ID = Auth::user()->get_user_id();
                 $claim->Type_of_Service = Input::get('Service_Type');
                 $claim->Ref = $ref;
                 $claim->Status = 1;
                 //$claim->Terminal = Auth::user()->get_user_id();
                 //$claim->Created_By = Auth::user()->get_user_id();
                 if ($claim->save()) {
                     $data = array('OK' => 'OK', 'Claim_No' => $iniClaimID, 'Account_No' => Input::get('Account_No'));
                     return Response::json($data);
                 } else {
                     $data = array('Response' => 'Claim could not be created.');
                     return Response::json($data);
                 }
             }
         } catch (Exception $e) {
             $data = array('Response' => $e->getMessage());
             return Response::json($data);
         }
     }
 }
 /**
  * BlockControl.
  *
  * Block or unblock the user out off the system.
  * Preventing them to login into the system.
  *
  * @param int $status, The status code. 1 = Block | 0 = Unblock.
  * @param int $id      ,     The id off the user.
  */
 public function blockControl($status, $id)
 {
     if (!Auth::user()->is('admin') || Auth::user()->is('developer') || Auth::user()->is('moderator')) {
         return Redirect::route('trips.index', ['selector' => 'all']);
     }
     $user = user::find($id);
     $user->status = $status;
     $user->save();
     $sessionQuery = Sessions::where('user_id', $id)->get();
     if (count($sessionQuery) == 1 && $status == 1) {
         Sessions::where('user_id', $id)->delete();
     }
     // Set flash message data.
     // Displayed when u block a user
     if ($status == 0) {
         // unblock
         $message = 'U hebt een gebruiker terug geactiveerd';
     } elseif ($status == 1) {
         // block
         $message = 'U hebt een gebruiker geblokkeerd';
     } else {
         // unknown
         $message = 'wij konden niet uitmaken welke handeling u wou uitvoeren.';
     }
     session()->flash('flash_title', 'Success!');
     session()->flash('flash_message', $message);
     session()->flash('flash_message_important', '');
     return Redirect::back();
 }
 public function cancelClaim()
 {
     $ID = Input::get("CLAIM_ID");
     $affectedRows = Claims::where('Claim_ID', '=', $ID)->update(array('Status' => 2, 'Updated_By' => 1, 'Updated_At' => date('Y-m-d')));
     if ($affectedRows > 0) {
         $affectedRows1 = Sessions::where('Claim_No', '=', $ID)->update(array('Status' => 'Canceled', 'Updated_By' => 1, 'Updated_At' => date('Y-m-d')));
         if ($affectedRows1 > 0) {
             $ini = array('OK' => 'OK');
             return Response::json($ini);
         } else {
             $ini = array('No Data' => $ID);
             return Response::json($ini);
         }
     } else {
         $ini = array('No Data' => $ID);
         return Response::json($ini);
     }
 }