/**
  * Execute the job.
  *
  * @param UserRepository $repository
  * @return void
  */
 public function handle(UserRepository $repository)
 {
     $person = User::addHouseholdMember($this->firstname, $this->lastname, $this->middleinitial, $this->gender, $this->mobile_no, $this->email);
     $repository->save($person);
     $member = HouseholdMember::addMember($this->household_id, $person->id);
     $household = Household::findOrFail($this->household_id);
     $household->members()->save($member);
     event(new UserHasRegistered($person));
 }
 public function getIndex()
 {
     $stats = array();
     $stats['accounts_pending_approval'] = User::query()->pending()->count();
     // TODO: unify 'Y'/'N'/0/1
     $stats['nominations_pending_review'] = Household::where('draft', 'N')->where('reviewed', 0)->count();
     $stats['nominations_approved'] = Household::where('reviewed', 1)->count();
     $stats['nominations_reviewed'] = Household::where('approved', 1)->count();
     $stats['children_approved'] = Household::where('reviewed', 1)->join('child', 'child.household_id', '=', 'household.id')->count();
     $stats['children_reviewed'] = Household::where('household.approved', 1)->join('child', 'child.household_id', '=', 'household.id')->count();
     $stats['children_pending'] = Household::where('household.reviewed', 0)->where('household.draft', 'N')->join('child', 'child.household_id', '=', 'household.id')->count();
     $stats['drafts'] = Household::query()->draft()->count();
     $stats['orgs'] = DB::table('household')->select('affiliation.type', DB::raw('count(case when household.approved = 1 then 1 else null end) as approved'), DB::raw('count(case when household.reviewed = 1 then 1 else null end) as reviewed'), DB::raw('count(case when household.draft = "N" and household.reviewed = 0 then 1 else null end) as pending'))->join('users', 'users.id', '=', 'household.nominator_user_id')->join('affiliation', 'affiliation.id', '=', 'users.affiliation_id')->groupBy('affiliation.type')->get();
     return view('admin.dashboard.index', $stats);
 }
 public function upload_attachment(Request $request)
 {
     $file = $request->file('file');
     if (!$file->isValid()) {
         return ["error" => $file->getErrorMessage()];
     }
     if (!Auth::user()->hasRole('admin') && Household::findOrFail($request->household_id)->nominator_user_id != Auth::user()->id) {
         return ["error" => "permission denied"];
     }
     $path = "user-" . Auth::user()->id . "/" . md5_file($file->getPathName()) . "_" . $file->getClientOriginalName();
     $res = Storage::disk("forms")->put($path, fopen($file->getPathName(), "r"));
     if (!$res) {
         return ["error" => "failed"];
     }
     $attachment = new HouseholdAttachment();
     $attachment->owner_user_id = Auth::user()->id;
     $attachment->path = $path;
     $attachment->household_id = $request->household_id;
     $attachment->save();
     return ["ok" => true, "path" => $path, "id" => $attachment->id];
 }
Example #4
0
 /**
  * Execute the job.
  *
  * @param HouseholdRepository $repository
  * @return void
  */
 public function handle(HouseholdRepository $repository)
 {
     // persist
     $household = Household::setup($this->head_id, $this->address, $this->coordinates);
     $repository->save($household);
 }
Example #5
0
 public function save(Household $household)
 {
     return $household->save();
 }
Example #6
0
 public function exportExcel()
 {
     if (Gate::denies('download', Household::class)) {
         abort(403);
     }
     $records = Household::join('families', 'households.id', '=', 'families.household_id')->join('persons', 'families.id', '=', 'persons.family_id')->select(['households.household_code', \DB::raw("CONCAT(persons.last_name, ', ', persons.first_name) as 'household_head'"), 'households.barangay', 'households.zone'])->where('persons.relationship', '=', 'Head of the household');
     if (\Auth::user()->group->assigned_barangay != 'All') {
         $records = $records->where('households.barangay', '=', \Auth::user()->group->assigned_barangay);
     }
     $records = $records->orderBy('households.household_code', 'asc')->get();
     $recordsArray = [];
     $recordsArray[] = ['household_code', 'household_head', 'barangay', 'zone'];
     foreach ($records as $record) {
         $recordsArray[] = $record->toArray();
     }
     $now = Carbon::now('Asia/Manila');
     $file_name = 'arp_households_' . $now->format('Ymd_His');
     Excel::create($file_name, function ($excel) use($recordsArray) {
         $excel->setTitle('ARP Households');
         $excel->setDescription('List of ARP Households');
         $excel->sheet('Households', function ($sheet) use($recordsArray) {
             $sheet->fromArray($recordsArray, null, 'A1', false, false);
         });
     })->download('xlsx');
 }
Example #7
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $data = array('title' => 'Dashboard', 'household_count' => Household::all()->count(), 'family_count' => Family::all()->count(), 'person_count' => Person::all()->count(), 'guest_count' => Guest::all()->count());
     return view('dashboard')->with($data);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     return \App\Household::with("child", "address", "phone")->where("id", "=", $id)->get();
 }
 /**
  * Whether or not the user has reached their limit of nominations for the year
  *
  * TODO: Rejected nominations should not count toward the limit
  * TODO: Need to use current year for limit
  *
  * @return bool
  */
 public function getMaxNominationsReachedAttribute()
 {
     $nominated_by_user = Household::query()->where("nominator_user_id", "=", $this->id)->notRejected()->count();
     return $nominated_by_user >= $this->nomination_limit;
 }
 public function packing_slips(Request $request)
 {
     if (!\Auth::user()->hasRole("admin")) {
         abort(403);
     }
     $radio = $request->cookie('packing_slip_radio');
     $phone = $request->cookie('packing_slip_phone');
     if (!$phone || !$radio) {
         return redirect('/admin/packing_slip_config');
     }
     $households = Household::query()->where('approved', '=', 1);
     // TODO: limit which packing slips to print
     // $after = $request->input('after');
     // if($after != NULL){
     //     $when = strtotime($after);
     //     if(!$when){
     //         Flash::error('Invalid date or time: ' . $after);
     //         return redirect('/admin');
     //     }
     //     $households = $households->andWhere('updated_at', '>=', date('y-m-d H:i:s', $when));
     // }
     return view("admin.households.packing_slip", ["households" => $households->get(), "assistance" => ["phone" => $phone, "radio" => $radio]]);
 }
 public function division_report()
 {
     $csv = Export::newCSV(["family number", "head of household", "street", "street2", "city", "state", "zip", "phone numbers", "email", "division", "response area"]);
     $households = Household::where('approved', 1)->get();
     foreach ($households as $h) {
         $a = $h->address->count() ? $h->address[0] : new HouseholdAddress();
         $phones = implode(", ", array_map(function ($p) {
             return $p['phone_number'] . " (" . $p['phone_type'] . ")";
         }, $h->phone->toArray()));
         $csv->insertOne([$h->id, $h->name_last . ", " . $h->name_first, $a->address_street, $a->address_street2, $a->address_city, $a->address_state, $a->address_zip, $phones, $h->email, $a->cmpd_division, $a->cmpd_response_area]);
     }
     $csv->output('GiftProjectDivisionReport_' . date("YmdHis") . '.csv');
     flush();
     exit(0);
 }
Example #12
0
 private function getImageDir($householdId)
 {
     return Household::findOrFail($householdId)->getTaskImagesDir();
 }