Exemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @returnpResponse
  */
 public function edit($society, $hid, $id)
 {
     if (Helpers::perm('admin', $society) or Helpers::perm('edit', $society)) {
         $pastoral = Pastoral::find($id);
         $pgid = Helpers::societySetting('group_pastors', $society);
         $addressee = Household::find($pastoral->household_id)->addressee;
         $pastorgroup = Group::where('id', '=', $pgid)->with('individual')->get();
         $pastors = array();
         foreach ($pastorgroup[0]->individual as $user) {
             $pastors[$user->id] = $user->surname . ", " . $user->firstname;
         }
         return View::make('pastorals.edit')->with('pastoral', $pastoral)->with('addressee', $addressee)->with('pastors', $pastors)->with('society', $society);
     } else {
         return view('shared.unauthorised');
     }
 }
Exemplo n.º 2
0
 public function dashboard($society)
 {
     $data['total_indivs'] = Individual::socindiv($society)->count();
     $data['total_households'] = Household::where('society_id', '=', $society)->count();
     $data['missing_gps'] = Household::where('society_id', '=', $society)->where('latitude', '=', null)->count();
     $data['missing_hc'] = Household::where('society_id', '=', $society)->where('householdcell', '=', '')->count();
     $data['missing_pa'] = Household::where('society_id', '=', $society)->where('addr1', '=', '')->count();
     $data['members'] = Individual::socindiv($society)->members()->count();
     $data['children'] = Individual::socindiv($society)->children()->count();
     $totaged = Individual::socindiv($society)->members()->get();
     $totnum = 0;
     $totyr = 0;
     foreach ($totaged as $thisa) {
         if ($thisa->age) {
             $totyr = $totyr + $thisa->age;
             $totnum++;
         }
     }
     $data['missing_bd'] = Individual::socindiv($society)->members()->where('birthdate', '<', '1901-01-01')->count();
     if ($totnum) {
         $data['avg_age'] = round($totyr / $totnum, 1);
     }
     $data['fellowship'] = Individual::socindiv($society)->members()->whereHas('group', function ($query) {
         $query->where('grouptype', '=', 'fellowship');
     })->count();
     $data['service'] = Individual::socindiv($society)->members()->whereHas('group', function ($query) {
         $query->where('grouptype', '=', 'service');
     })->count();
     $data['worship'] = Individual::socindiv($society)->members()->whereHas('group', function ($query) {
         $query->where('grouptype', '=', 'worship');
     })->count();
     $data['learning'] = Individual::socindiv($society)->members()->whereHas('group', function ($query) {
         $query->where('grouptype', '=', 'learning');
     })->count();
     $data['groups'] = Group::where('society_id', '=', $society)->where('statistics', '=', 'yes')->orderBy('groupname')->get();
     $data['society'] = $society;
     //$data['analyticsData'] = LaravelAnalytics::getVisitorsAndPageViews(7);
     return view('statistics.dashboard', $data);
 }
Exemplo n.º 3
0
 public function sendMessage($society, $type)
 {
     $soc = Society::find($society);
     $input = Input::all();
     $alldat = array();
     if ($input['leaderoptions'] == "everyone") {
         $allhouseholds = Household::with('individual')->where('society_id', '=', $society)->get();
         foreach ($allhouseholds as $hhh) {
             foreach ($hhh->individual as $iii) {
                 if ($iii->id == $hhh->householdcell) {
                     $dum = self::PopulateRecipient($iii);
                     if ($dum['cellphone'] != "" and $iii->memberstatus == "member") {
                         $alldat[$iii->id] = $dum;
                     }
                 }
             }
         }
     } elseif (isset($input['groups'])) {
         $groups = $input['groups'];
         if ($input['leaderoptions'] == "allmembers") {
             foreach ($groups as $thisgroup) {
                 $group = Group::with('individual')->find($thisgroup);
                 foreach ($group->individual as $indiv) {
                     $dum = self::PopulateRecipient($indiv);
                     $alldat[$indiv->id] = $dum;
                 }
             }
         } elseif ($input['leaderoptions'] == "leadersonly" or $input['leaderoptions'] == "leadersandlist") {
             foreach ($groups as $thisgroup) {
                 $group = Group::with('individual')->find($thisgroup);
                 foreach ($group->individual as $indiv) {
                     if ($group->contact == $indiv->id) {
                         $dum = self::PopulateRecipient($indiv);
                         if (!isset($alldat[$indiv->id])) {
                             $alldat[$indiv->id] = $dum;
                         }
                         if ($input['leaderoptions'] == "leadersandlist") {
                             if (isset($alldat[$indiv->id]['grouplist'])) {
                                 $alldat[$indiv->id]['grouplist'] = $alldat[$indiv->id]['grouplist'] . $group->id . ",";
                             } else {
                                 $alldat[$indiv->id]['grouplist'] = $group->id . ",";
                             }
                         }
                     }
                 }
             }
         }
     }
     if (isset($input['indivs'])) {
         foreach ($input['indivs'] as $individ) {
             $indiv = Individual::find($individ);
             $dum = self::PopulateRecipient($indiv);
             if (!isset($alldat[$individ])) {
                 $alldat[$individ] = $dum;
             }
         }
     }
     if ($type == "email") {
         if (isset($input['htmlbody'])) {
             $message = nl2br($input['message']) . file_get_contents($input['htmlbody']);
         } else {
             $message = nl2br($input['message']);
         }
         $message = HTML::decode($message);
         $subject = $input['subject'];
         $sender = Input::get('sender');
         Mail::queue('messages.message', array('msg' => $message), function ($message) use($subject, $soc, $alldat, $sender) {
             if (Input::file('attachment')) {
                 $message->attach(Input::file('attachment'), array('as' => Input::file('attachment')->getClientOriginalName(), 'mime' => Input::file('attachment')->getMimeType()));
             }
             foreach ($alldat as $thisrec) {
                 $name = $thisrec['name'];
                 $email = $thisrec['email'];
                 $household = $thisrec['household'];
                 if (isset($thisrec['grouplist'])) {
                     $grouplist = $thisrec['grouplist'];
                 } else {
                     $grouplist = "No group";
                 }
                 $message->from('*****@*****.**', $soc->society . " Methodist Church");
                 $message->to($email, $name)->replyTo($sender);
                 if ($subject == "") {
                     $subject = "Email from " . $soc->society . " Methodist Church";
                 }
                 if ($grouplist != "No group") {
                     $ggl = explode(",", substr($grouplist, 0, -1));
                     foreach ($ggl as $gl) {
                         $repdata = app('App\\Http\\Controllers\\ReportsController')->show($gl, true);
                         $tg = Group::find($gl);
                         $message->attachData($repdata, $tg->groupname . ".pdf");
                     }
                 }
                 $message->subject($subject);
             }
         });
         $results = array();
         foreach ($alldat as $tdat) {
             $result['name'] = $tdat['name'];
             $result['address'] = $tdat['email'];
             $result['household'] = $tdat['household'];
             $results[] = $result;
         }
     } else {
         $final = array();
         foreach ($alldat as $thisdat) {
             $ndx = intval($thisdat['household']);
             if (Input::get('economy') == "household") {
                 if (array_key_exists($ndx, $final)) {
                     $keyhouse = Household::find($ndx)->householdcell;
                     $keycell = Individual::find($keyhouse);
                     if (SMSfunctions::checkcell($keycell->cellphone)) {
                         $final[$ndx]['cellphone'] = $keycell->cellphone;
                         $final[$ndx]['name'] = $keycell->firstname . " " . $keycell->surname;
                         $final[$ndx]['household'] = $ndx;
                     }
                 } else {
                     $final[$ndx]['cellphone'] = $thisdat['cellphone'];
                     $final[$ndx]['name'] = $thisdat['name'];
                     $final[$ndx]['household'] = $ndx;
                 }
             } else {
                 $dummy['cellphone'] = $thisdat['cellphone'];
                 $dummy['name'] = $thisdat['name'];
                 $dummy['household'] = $ndx;
                 $final[] = $dummy;
             }
         }
         if ($soc->sms_provider == "bulksms") {
             if (count($final) > SMSfunctions::BS_get_credits($soc->sms_username, $soc->sms_password)) {
                 return Redirect::back()->withInput()->withErrors("Insufficient Bulk SMS credits to send SMS");
             }
             $url = 'http://community.bulksms.com/eapi/submission/send_sms/2/2.0';
             $port = 80;
         } elseif ($soc->sms_provider == "smsfactory") {
             if (count($final) > SMSfunctions::SF_checkCredits($soc->sms_username, $soc->sms_password)) {
                 return Redirect::back()->withInput()->withErrors("Insufficient SMS Factory credits to send SMS");
             }
         }
         $seven_bit_msg = Input::get('message') . " (From " . substr($soc->society, 0, 1) . "MC)";
         foreach ($final as $sms) {
             if ($soc->sms_provider == "bulksms") {
                 $transient_errors = array(40 => 1);
                 $msisdn = "+27" . substr($sms['cellphone'], 1);
                 $post_body = SMSfunctions::BS_seven_bit_sms($soc->sms_username, $soc->sms_password, $seven_bit_msg, $msisdn);
             }
             $dum2['name'] = $sms['name'];
             $dum2['household'] = $sms['household'];
             if (SMSfunctions::checkcell($sms['cellphone'])) {
                 if ($soc->sms_provider == "bulksms") {
                     $smsresult = SMSfunctions::BS_send_message($post_body, $url, $port);
                 } elseif ($soc->sms_provider == "smsfactory") {
                     $smsresult = SMSfunctions::SF_sendSms($soc->sms_username, $soc->sms_password, $sms['cellphone'], $seven_bit_msg);
                 }
                 $dum2['address'] = $sms['cellphone'];
             } else {
                 if ($sms['cellphone'] == "") {
                     $dum2['address'] = "No cell number provided.";
                 } else {
                     $dum2['address'] = "Invalid cell number: " . $sms['cellphone'] . ".";
                 }
             }
             $results[] = $dum2;
         }
         $data['results'] = $results;
     }
     $data['type'] = $type;
     $data['results'] = $results;
     return View::make('messages.results', $data);
 }
Exemplo n.º 4
0
 public function preparemove($society, $hid, $id)
 {
     $data['society'] = $society;
     $data['individual'] = Individual::find($id);
     $data['households'] = Household::lists('addressee', 'id');
     return view('individuals.move', $data);
 }
Exemplo n.º 5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($society, $hid, $id)
 {
     $specialday = Specialday::find($id);
     $addressee = Household::find($specialday->household_id)->addressee;
     return View::make('specialdays.edit')->with('specialday', $specialday)->with('addressee', $addressee)->with('society', $society);
 }
Exemplo n.º 6
0
 public function fixUp($society, $field)
 {
     $data['society'] = $society;
     $data['lets'] = array('1' => 'A', '2' => 'B', '3' => 'C', '4' => 'D', '5' => 'E', '6' => 'F', '7' => 'G', '8' => 'H', '9' => 'I', '10' => 'J', '11' => 'K', '12' => 'L', '13' => 'M', '14' => 'N', '15' => 'O', '16' => 'P', '17' => 'Q', '18' => 'R', '19' => 'S', '20' => 'T', '21' => 'U', '22' => 'V', '23' => 'W', '24' => 'X', '25' => 'Y', '26' => 'Z');
     if ($field == "gps") {
         $data['households'] = Household::where('latitude', '=', null)->orderBy('sortsurname')->get();
         return View::make('households.index', $data);
     } elseif ($field == "cellphone") {
         $data['households'] = Household::where('householdcell', '=', '')->orderBy('sortsurname')->get();
         return View::make('households.index', $data);
     } elseif ($field == "address") {
         $data['households'] = Household::where('addr1', '=', '')->orderBy('sortsurname')->get();
         return View::make('households.index', $data);
     } elseif ($field == "birthdate") {
         $data['individuals'] = Individual::where('birthdate', '<', '1901-01-01')->get();
         return View::make('individuals.index', $data);
     }
 }
Exemplo n.º 7
0
 public function birthdays($society)
 {
     $soc = Society::find($society);
     $houses = Household::with('individual')->where('society_id', '=', $society)->get();
     foreach ($houses as $house) {
         foreach ($house->individual as $indiv) {
             if ($indiv->memberstatus != 'non-member' and $indiv->birthdate != '0000-00-00' and $indiv->birthdate != '' and !is_null($indiv->birthdate)) {
                 $mth = intval(substr($indiv->birthdate, 5, 2));
                 $day = intval(substr($indiv->birthdate, 8, 2));
                 $dum = utf8_decode($indiv->firstname) . " " . utf8_decode($indiv->surname);
                 if ($indiv->cellphone != '') {
                     $dum = $dum . " (Cellphone: " . $indiv->cellphone . ")";
                 }
                 if ($house->homephone != '') {
                     $dum = $dum . " (Home phone: " . $house->homephone . ")";
                 }
                 if ($house->householdcell != 0 and $house->householdcell != $indiv->id) {
                     $dum = $dum . " (Additional cell number: " . $this->gethcell($house->householdcell) . ")";
                 }
                 $indivs[$mth][$day][] = $dum;
             }
         }
     }
     ksort($indivs);
     $pdf = new Fpdf();
     foreach ($indivs as $key => $mth) {
         ksort($mth);
         $pdf->AddPage('P');
         $pdf->SetAutoPageBreak(0, 0);
         $pdf->SetFont('Arial', 'B', 12);
         $monthName = date("F", mktime(null, null, null, $key));
         $pdf->text(10, 10, $soc->society . " Birthdays: " . $monthName);
         $pdf->SetFont('Arial', '', 9);
         $yy = 20;
         foreach ($mth as $dd => $day) {
             foreach ($day as $bd) {
                 $pdf->text(10, $yy, $dd . " " . $bd);
                 $yy = $yy + 4;
             }
         }
     }
     $pdf->Output();
 }