public function postCityProcess(Request $request)
 {
     ini_set('auto_detect_line_endings', TRUE);
     $file = fopen(Config::get('app.filepath') . $request->FileName, "r");
     ## Get the header line = FirstName(0),LastName(1),Phone(2),Neighborhood(3),Borough(4),Caller(5),Called(6),
     ## VM(7),Texted(8),RSVP(9),Event(10),Date(11),DoNotContact(12),BadPhone(13),Comments(14)
     $x = 0;
     while (($data = fgetcsv($file)) !== FALSE) {
         if ($x == 0) {
             $x = $x + 1;
             continue;
         }
         #; Find Volunteer or add if does not exist
         if ($data[2] != "") {
             // check first by phone number
             $volunteers = \teambernieny\Volunteer::where('Phone', '=', $data[2])->get();
         }
         if (sizeof($volunteers) == 0) {
             $volunteer = new \teambernieny\Volunteer();
             $volunteer->FirstName = $data[0];
             $volunteer->LastName = $data[1];
             $volunteer->Phone = $data[2];
             $volunteer->County = $data[4];
             $volunteer->neighborhood_id = $this->checkNeighborhood($data[3], $data[4]);
             if ($request->CDistrict != "") {
                 $volunteer->CDistrict = $request->CDistrict;
             }
             $volunteer->user_id = "1";
             $volunteer->save();
             $volunteer_id = $volunteer->id;
         } else {
             $volunteer_id = $volunteers[0]->id;
             $volunteer = $volunteers[0];
         }
         if ($data[12] == "1") {
             $volunteer->DoNotContact = true;
         }
         if ($data[13] == "1") {
             $volunteer->BadPhone = true;
         }
         #; Check to see if volunteer was Called or texted -- add contact event if so
         $data[6] = strtoupper($data[6]);
         $data[7] = strtoupper($data[7]);
         $data[8] = strtoupper($data[8]);
         $data[9] = strtoupper($data[9]);
         if ($data[6] == "Y" || $data[8] == "Y" || $data[6] == "YES" || $data[8] == "YES") {
             if ($data[10] != "") {
                 //get event info if there is a name in the event column
                 $events = \teambernieny\Event::where('Name', '=', $data[10])->get();
                 if (sizeof($events) > 0) {
                     $event_id = $events[0]->id;
                 } else {
                     //add if event doesn't exist
                     $event = new \teambernieny\Event();
                     $event->Name = $data[12];
                     $event->neighborhood_id = "1";
                     $event->Date = date('Y/m/d');
                     $event->save();
                     $event_id = $event->id;
                 }
             } else {
                 $event_id = null;
                 //no event indicated
             }
             #; create contact event
             $contactevent = new \teambernieny\Contactevent();
             $contactevent->volunteer_id = $volunteer_id;
             $contactevent->event_id = $event_id;
             $contactevent->Purpose = "Invitation";
             // if RSVPed
             if ($data[9] == "Y" || $data[9] == "SENT" || $data[9] == "YES") {
                 $contactevent->RSVP = true;
             } else {
                 $contactevent->RSVP = false;
             }
             // if Called
             if ($data[6] == "Y" || $data[6] == "YES") {
                 $contactevent->Call = true;
             } else {
                 $contactevent->Call = false;
             }
             // if Texted
             if ($data[8] == "Y" || $data[8] == "YES") {
                 $contactevent->Text = true;
             } else {
                 $contactevent->Text = false;
             }
             //if left a voicemail
             if ($data[7] == "Y" || $data[7] == "YES") {
                 $contactevent->VoiceMail = true;
             } else {
                 $contactevent->VoiceMail = false;
             }
             $contactevent->Date = date('Y-m-d', strtotime($data[11]));
             $contactevent->Comment = $data[14];
             $contactevent->Caller = $data[5];
             $contactevent->Completed = true;
             $contactevent->user_id = null;
             $contactevent->save();
         }
     }
     fclose($file);
     return view('contactevent.process')->with(['message' => "File Processed"]);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $file = fopen("/uploads/20160113.csv", "r");
     $line = fgets($file);
     ## Get the header line = Event(0),Date(1),FirstName(2),LastName(3),Gender(4),Phone(5),Zip(6),Neighborhood(7),Email(8),Street(9),City(10),State(11),HostEvent(12),AttendEvent(13),Comment(14)
     while (($line = fgets($handle)) !== false) {
         $data = explode(",", $line);
         if ($data[0] != "") {
             //check for event
             $events = \teambernieny\Event::where('Name', '=', $data[0])->get();
             if (sizeof($events) > 0) {
                 $event = $events[0];
             } else {
                 //add if doesn't exist
                 $event = new \teambernieny\Event();
                 $event->Name = $data[0];
                 $event->neighborhood_id = "1";
                 $event->Date = "2016-01-13";
                 $event->save();
             }
         } else {
             // add to migration if no event indicated
             $event = \teambernieny\Event::find('1');
         }
         if ($data[8] != "") {
             // if there is an email
             $volunteers = \teambernieny\Volunteer::where('Email', '=', $data[8])->get();
         } elseif ($data[5] != "") {
             $volunteers = \teambernieny\Volunteer::where('Phone', '=', $data[5])->get();
         } else {
             continue;
         }
         if (sizeof($volunteers) == 0) {
             $volunteer = new \teambernieny\Volunteer();
             $neighborhoods = \teambernieny\Neighborhood::select('id')->where('Name', '=', $data[7])->get();
             if (sizeof($neighborhoods) > 0) {
                 $neighborhood = $neighborhoods->first();
             } else {
                 $neighborhood = new \teambernieny\Neighborhood();
                 $neighborhood->Name = $data[7];
                 $neighborhood->Borough = $data[10];
                 $neighborhood->save();
             }
             $volunteer->FirstName = $data[2];
             $volunteer->LastName = $data[3];
             $volunteer->Phone = $data[5];
             $volunteer->Zip = $data[6];
             $volunteer->neighborhood_id = $neighborhood->id;
             $volunteer->Email = $data[8];
             $volunteer->Street = $data[9];
             $volunteer->City = $data[10];
             $volunteer->State = $data[11];
         } else {
             $volunteer = $volunteers[0];
         }
         //Add attendance
         $attendance = new \teambernieny\EventVolunteers();
         $attendance->event_id = $event->id;
         $attendance->volunteer_id = $volunteer->id;
         $attendance->Relationship = "Attendee";
         $attendance->save();
         if ($data[12] == "1") {
             $newcommitment = new \teambernieny\Commitment();
             $newcommitment->event_volunteers_id = $attendance->id;
             $newcommitment->Type = "Host";
             $newcommitment->save();
         }
         if ($data[13] == "1") {
             $newcommitment = new \teambernieny\Commitment();
             $newcommitment->event_volunteers_id = $attendance->id;
             $newcommitment->Type = "Attend";
             $newcommitment->save();
         }
     }
     fclose($file);
 }