/**
  * Get the stats page
  *
  * @param Request $Request
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getIndex(Request $Request)
 {
     $requestData = $Request->all();
     $authUser = Auth::user();
     $data['quorumId'] = $authUser->quorum_id;
     $data['wardId'] = $authUser->ward_id;
     $year = $curYear = (int) date('Y');
     if (!empty($requestData['year'])) {
         $year = (int) $requestData['year'];
     }
     $data['firstYear'] = 2015;
     $data['nowYear'] = $curYear;
     $data['selectedYear'] = $year;
     $data['visitMonths'] = CompanionshipVisit::where('ward_id', '=', $authUser->ward_id)->select(DB::raw("*, COUNT(*) AS count, FIELD(visit_month,'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec') AS month_order"))->where('quorum_id', '=', $authUser->quorum_id)->where('visit_year', '=', $data['selectedYear'])->where('visited', '=', 'yes')->groupBy('visit_month')->having('count', '>', 0)->orderBy("month_order")->get();
     $data['members'] = [];
     foreach ($data['visitMonths'] as $month) {
         $Families = CompanionshipVisit::where('visit_month', '=', $month['visit_month'])->where('ward_id', '=', $authUser->ward_id)->where('quorum_id', '=', $authUser->quorum_id)->where('visit_year', '=', $data['selectedYear'])->where('visited', '=', 'yes')->get();
         foreach ($Families as $Family) {
             try {
                 $data['members'][$month['visit_month']][] = Member::withTrashed()->findOrFail($Family->member_id);
             } catch (Exception $exception) {
                 continue;
             }
         }
         if (!empty($data['members'][$month['visit_month']])) {
             usort($data['members'][$month['visit_month']], function ($one, $two) {
                 //Compare by last name first followed by first name.
                 return strcmp($one->lastName . $one->firstName, $two->lastName . $two->firstName);
             });
         }
     }
     return view('stats', $data);
 }
Ejemplo n.º 2
0
 public function postDelete(Request $Request)
 {
     Member::destroy(Input::get('id'));
     $status = 'Member Removed';
     if ($Request->ajax()) {
         return Response::json(['success' => true, 'status' => $status]);
     }
     return Redirect::back()->with('status', $status);
 }
Ejemplo n.º 3
0
 public function postReset(Request $Request)
 {
     $Member = Member::find(Input::get('id'));
     $Member->password = Hash::make('hometeach');
     $Member->save();
     $returnData = ['success' => true, 'message' => 'Password Reset for ' . $Member->firstName . ' ' . $Member->lastName . '!', 'status' => parent::MESSAGE_SUCCESS];
     if ($Request->ajax()) {
         return Response::json($returnData);
     }
     return Redirect::to('/members/edit?id=' . $Member->id)->with($returnData);
 }
Ejemplo n.º 4
0
 public function getIndex()
 {
     $authUser = Auth::user();
     $data['quorumId'] = $authUser->quorum_id;
     $data['wardId'] = $authUser->ward_id;
     $data['families'] = Member::where('ward_id', '=', $authUser->ward_id)->where('quorum_id', '=', $authUser->quorum_id)->orderBy('last_name', 'asc')->get();
     $districts = District::where('ward_id', '=', $authUser->ward_id)->where('quorum_id', '=', $authUser->quorum_id)->get();
     $data['districts'] = [];
     foreach ($districts as $district) {
         $data['districts'][] = Member::find($district->member_id);
     }
     return view('districts', $data);
 }
 public function getIndex()
 {
     $data = [];
     $authUser = Auth::user();
     $data['authId'] = $authUser->id;
     $data['wardId'] = $authUser->ward_id;
     $data['companionship'] = Companionship::where('ht_one_id', '=', $data['authId'])->orWhere('ht_two_id', '=', $data['authId'])->first();
     $data['allFamilies'] = [];
     if (!empty($data['companionship'])) {
         if ($data['companionship']->ht_one_id == $data['authId']) {
             $data['companion'] = Member::find($data['companionship']->ht_two_id);
         } else {
             $data['companion'] = Member::find($data['companionship']->ht_one_id);
         }
         $data['allFamilies'] = CompanionshipFamily::where('companionship_id', '=', $data['companionship']->id)->get();
     }
     if (!empty($data['companion'])) {
         $data['companionName'] = $data['companion']->first_name . ' ' . $data['companion']->last_name;
         $data['companionPhone'] = $data['companion']->phone;
     }
     $data['numFamilies'] = count($data['allFamilies']);
     $data['totalVisitCount'] = 0;
     if ($data['numFamilies'] > 0) {
         foreach ($data['allFamilies'] as $key => $family) {
             $count = 0;
             $familyData =& $data['myFamilies'][$key];
             $familyData['family'] = Member::find($family['member_id']);
             $familyData['visitMonth'] = [];
             $familyData['visitMonthYes'] = [];
             $familyData['visitMonthNo'] = [];
             $visits = CompanionshipVisit::where('member_id', '=', $family['member_id'])->where('visit_year', '=', date('Y'))->get();
             foreach ($visits as $visit) {
                 $familyData['visitMonth'][] = $visit->visitMonth;
                 if ($visit->visited === 'yes') {
                     $familyData['visitMonthYes'][] = $visit->visitMonth;
                     ++$count;
                 } else {
                     $familyData['visitMonthNo'][] = $visit->visitMonth;
                 }
             }
             $familyData['visitCount'] = $count;
             $data['totalVisitCount'] += $familyData['visitCount'];
             $familyData['comments'] = Comment::whereHas('companionship', function ($query) use($data) {
                 $query->where('ht_one_id', '=', $data['authId'])->orWhere('ht_two_id', '=', $data['authId']);
             })->where('family_id', '=', $family['member_id'])->get();
         }
     }
     $data['months'] = ['Jan' => 'January', 'Feb' => 'February', 'Mar' => 'March', 'Apr' => 'April', 'May' => 'May', 'Jun' => 'June', 'Jul' => 'July', 'Aug' => 'August', 'Sep' => 'September', 'Oct' => 'October', 'Nov' => 'November', 'Dec' => 'December'];
     $compMemberRow = CompanionshipFamily::where('member_id', '=', $data['authId'])->first();
     $data['myHomeTeachers'] = [];
     if ($compMemberRow) {
         $compRow = Companionship::where('id', '=', $compMemberRow->companionship_id)->first();
         $data['numHomeTeachers'] = 0;
         if (!empty($compRow->ht_one_id)) {
             $data['myHomeTeachers'][1] = Member::find($compRow->ht_one_id);
             ++$data['numHomeTeachers'];
         }
         if (!empty($compRow->ht_two_id)) {
             $data['myHomeTeachers'][2] = Member::find($compRow->ht_two_id);
             ++$data['numHomeTeachers'];
         }
     }
     $data['year'] = date('Y');
     return view('dashboard', $data);
 }
 private function getExistingHomeTeacherCompanionData($existingHomeTeachers)
 {
     $existingHomeTeacherCompanion = [];
     foreach ($existingHomeTeachers as $key => $homeTeachers) {
         $existingHomeTeacherCompanion[$key]['homeTeacher'][1] = Member::find($homeTeachers->ht_one_id);
         $existingHomeTeacherCompanion[$key]['homeTeacher'][2] = Member::find($homeTeachers->ht_two_id);
         $families = CompanionshipFamily::where('companionship_id', '=', $homeTeachers->id)->get();
         $existingHomeTeacherCompanion[$key]['families'] = [];
         foreach ($families as $family) {
             $taughtFamily =& $existingHomeTeacherCompanion[$key]['families'][];
             $taughtFamily = Member::find($family->member_id);
             $taughtFamily['ward_companionship_member_id'] = $family->id;
         }
         $district = District::find($homeTeachers->district_id);
         if ($district) {
             $existingHomeTeacherCompanion[$key]['districtMember'] = Member::find($district->member_id);
         }
     }
     return $existingHomeTeacherCompanion;
 }