public function exportExcel() { if (Gate::denies('download', Family::class)) { abort(403); } $records = Family::join('households', 'families.household_id', '=', 'households.id')->join('persons', 'families.id', '=', 'persons.family_id')->select(['households.household_code', 'families.family_code', \DB::raw("CONCAT(persons.last_name, ', ', persons.first_name) as 'family_head'"), 'households.barangay', 'households.zone', 'families.years_living', 'families.current_living', 'families.current_living_other', 'families.still_living', 'families.assistance_ngo_agency', 'families.assistance_what', 'families.first_source', 'families.first_source_specific', 'families.first_source_member', 'families.first_source_gender', 'families.first_source_amount', 'families.second_source', 'families.second_source_specific', 'families.second_source_member', 'families.second_source_gender', 'families.second_source_amount', 'families.third_source', 'families.third_source_specific', 'families.third_source_member', 'families.third_source_gender', 'families.third_source_amount', 'families.combined_family_income', 'families.family_monthly_expenditure', 'families.amount_to_access_house', 'families.coping_strategies', 'families.power_making_decision', 'families.distance_health_facility', 'families.latrine_access', 'families.latrine_type', 'families.human_waste_disposal', 'families.source_for_drinking', 'families.source_domestic_use', 'families.access_sanitation_facilities', 'families.closest_evac_center', 'families.aware_living_in_ndz', 'families.hazards_affected_community', 'families.hazards_affected_community_other', 'families.land_ownership_status', 'families.with_land_title', 'families.pay_anything_to_live', 'families.aware_relocation_program', 'families.relocation_preference', 'families.relocation_preference_other', 'families.relocation_plan', 'families.relocation_plan_other', 'families.number_relatives_within_brgy', 'families.number_family_members', 'families.gps_points', 'families.ofda_beneficiary', 'families.remarks', 'families.profiling_date', 'families.interviewer_name'])->where('persons.relationship', 'LIKE', 'Head of the%'); if (\Auth::user()->group->assigned_barangay != 'All') { $records = $records->where('households.barangay', '=', \Auth::user()->group->assigned_barangay); } $records = $records->orderBy('families.family_code', 'asc')->get(); $recordsArray = []; $recordsArray[] = ['household_code', 'family_code', 'family_head', 'barangay', 'zone', 'years_living', 'current_living', 'current_living_other', 'still_living', 'assistance_ngo_agency', 'assistance_what', 'first_source', 'first_source_specific', 'first_source_member', 'first_source_gender', 'first_source_amount', 'second_source', 'second_source_specific', 'second_source_member', 'second_source_gender', 'second_source_amount', 'third_source', 'third_source_specific', 'third_source_member', 'third_source_gender', 'third_source_amount', 'combined_family_income', 'family_monthly_expenditure', 'amount_to_access_house', 'coping_strategies', 'power_making_decision', 'distance_health_facility', 'latrine_access', 'latrine_type', 'human_waste_disposal', 'source_for_drinking', 'source_domestic_use', 'access_sanitation_facilities', 'closest_evac_center', 'aware_living_in_ndz', 'hazards_affected_community', 'hazards_affected_community_other', 'land_ownership_status', 'with_land_title', 'pay_anything_to_live', 'aware_relocation_program', 'relocation_preference', 'relocation_preference_other', 'relocation_plan', 'relocation_plan_other', 'number_relatives_within_brgy', 'number_family_members', 'gps_points', 'ofda_beneficiary', 'remarks', 'profiling_date', 'interviewer_name']; foreach ($records as $record) { $recordsArray[] = $record->toArray(); } $now = Carbon::now('Asia/Manila'); $file_name = 'arp_families_' . $now->format('Ymd_His'); Excel::create($file_name, function ($excel) use($recordsArray) { $excel->setTitle('ARP Families'); $excel->setDescription('List of ARP Families'); $excel->sheet('Families', function ($sheet) use($recordsArray) { $sheet->fromArray($recordsArray, null, 'A1', false, false); }); })->download('xlsx'); }
/** * Get the families of the household. * * @return \Illuminate\Http\JsonResponse */ public function familyData($id) { $records = Family::join('households', 'families.household_id', '=', 'households.id')->join('persons', 'families.id', '=', 'persons.family_id')->select(['families.id', 'households.household_code', 'families.family_code', 'households.barangay', 'households.zone', \DB::raw('CONCAT(persons.last_name, ", ", persons.first_name) as family_head')])->where('persons.relationship', 'LIKE', 'Head of the%')->where('households.id', '=', $id); return Datatables::of($records)->addColumn('action', function ($record) { return '<a title="View" href="/family/' . $record->id . '" class="btn btn-xs blue"><i class="fa fa-search"></i></a> <a title="Edit" href="/family/' . $record->id . '/edit" class="btn btn-xs green"><i class="fa fa-edit"></i></a> <a title="Family Members" href="/family/' . $record->id . '/persons" class="btn btn-xs yellow"><i class="fa fa-user"></i></a>'; })->make(true); }