public function saveAs(Request $request) { // retrieve all records as collection $records = CooperativeTraining::select('report_date_id', 'institution_id', 'occupation_id', 'mse_list', 'mse_mou', 'mse_joint_plan', 'mse_training', 'mse_trainers', 'ml_list', 'ml_mou', 'ml_joint_plan', 'ml_training', 'ml_trainers', 'remarks')->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 CooperativeTraining::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('cooperative-trainings'); }
public function mls($subsector_id) { $result = CooperativeTraining::where('report_date_id', $this->report_date_id)->where('institution_id', $this->institution_id)->whereIn('occupation_id', DB::table('occupations')->select('id')->where(array('subsector_id' => $subsector_id))->lists('id'))->sum('ml_training'); return $result; }
public function registered_companies() { $result = CooperativeTraining::select(DB::raw('sum(mse_list) as mse, sum(ml_list) as medium_large, sum(mse_list) + sum(ml_list) 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; }