public function short_term()
 {
     $result = ShortTermTraining::select(DB::raw('sum(below17_male) + sum(from17to19_male) + sum(above19_male) as male,
                                             sum(below17_female) + sum(from17to19_female) + sum(above19_female) as female,
                                             sum(below17_male) + sum(from17to19_male) + sum(above19_male) +
                                             sum(below17_female) + sum(from17to19_female) + sum(above19_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;
 }
 public function saveAs(Request $request)
 {
     // retrieve all records as collection
     $records = ShortTermTraining::select('report_date_id', 'institution_id', 'occupation_id', 'course_started', 'course_ended', 'below17_male', 'below17_female', 'from17to19_male', 'from17to19_female', 'above19_male', 'above19_female', 'no_education_male', 'no_education_female', 'elementary_male', 'elementary_female', 'high_school_male', 'high_school_female', 'preparatory_male', 'preparatory_female', 'higher_education_male', 'higher_education_female', 'mental_male', 'mental_female', 'visual_male', 'visual_female', 'hearing_male', 'hearing_female', 'physical_male', 'physical_female', 'cooperative', 'non_cooperative', '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
         ShortTermTraining::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.');
     }
     return redirect('short-term-trainings');
 }