コード例 #1
0
 public function postGenerate(Request $request)
 {
     if ($request->ajax()) {
         return $this->ajaxPostGenerate($request);
     }
     $this->validate($request, ['fr' => 'required|date', 'to' => 'required|date']);
     $fr = Carbon::parse($request->fr);
     $to = Carbon::parse($request->to);
     if ($to->lt($fr)) {
         // if to < fr
         return redirect('dtr/generate')->withErrors(['message' => 'Date From is greater than Date To!']);
     }
     if ($to->diffInDays($fr) > 31) {
         // check in date range exceeded 1 mons
         return redirect('dtr/generate')->withErrors(['message' => 'Date range too high!']);
     }
     $employees = Employee::branchid(session('user.branchid'))->processing()->orderBy('lastname', 'ASC')->orderBy('firstname', 'ASC')->get();
     foreach ($this->getDates($fr, $to) as $date) {
         echo $date->format("Y-m-d") . '<br>';
         foreach ($employees as $employee) {
             echo $employee->lastname . ', ' . $employee->firstname . '<br>';
             $this->dtr = $this->dtrExistOrCreate($employee->id, $date->format('Y-m-d'));
             $this->setEmployeeMandtl($employee->id, $date->format('Y-m-d'));
             $this->setEmployeeTimelog($employee->id, $date);
             $this->checkDay($employee->branchid);
             $this->computeWorkHours();
             echo 'dtr: ' . $this->dtr->timein . ' - ' . $this->dtr->breakin . ' - ' . $this->dtr->breakout . ' - ' . $this->dtr->timeout . '<br>';
             echo $this->dtr->lid() . '<br>';
             $this->dtr->save();
         }
         echo '<hr>';
     }
 }