public function saveAs(Request $request) { // retrieve all records as collection $records = Assessment::select('report_date_id', 'institution_id', 'occupation_id', 'assessed_regular_male', 'assessed_regular_female', 'assessed_extension_male', 'assessed_extension_female', 'assessed_short_term_male', 'assessed_short_term_female', 'competent_regular_male', 'competent_regular_female', 'competent_extension_male', 'competent_extension_female', 'competent_short_term_male', 'competent_short_term_female')->where('report_date_id', $request->report_date_id_source)->get(); if (count($records) > 0) { // update report date id to target report date id foreach ($records as $rec) { $rec->report_date_id = $request->report_date_id_target; } // insert into the table Assessment::insert($records->toArray()); // send a flash message $request->session()->flash('alert-success', 'Save as operation was successful!'); } else { // send a flash message $request->session()->flash('alert-danger', 'Save as operation failed! No records found from source.'); } return redirect('assessments'); }
public function competent() { $result = Assessment::select(DB::raw('sum(competent_regular_male) as regular_male, sum(competent_regular_female) as regular_female, sum(competent_extension_male) as extension_male, sum(competent_extension_female) as extension_female, sum(competent_regular_male) + sum(competent_regular_female) as regular_total, sum(competent_extension_male) + sum(competent_extension_female) as extension_total, sum(competent_regular_male) + sum(competent_regular_female) + sum(competent_extension_male) + sum(competent_extension_female) as total'))->whereIn('report_date_id', ReportDate::select('id')->where('petsa', $this->petsa)->lists('id'))->whereIn('institution_id', Institution::select('id')->where('region_id', $this->region_id)->lists('id'))->get(); return $result; }