/**
  * Save a model with it's relations.
  *
  * @param $data
  * @param null $id
  *
  * @return static
  */
 public static function save($data, $id = null)
 {
     if ($id) {
         $employee = Employee::findOrFail($id);
         $employee->fill($data);
     } else {
         $employee = Employee::create($data);
     }
     Address::whereEmployeeId($employee->id)->delete();
     // flush
     Course::whereEmployeeId($employee->id)->delete();
     foreach (array_get($data, 'address', []) as $key => $d) {
         if (empty($d['city']) && empty($d['street']) && empty($d['number'])) {
             continue;
         }
         $address = new Address($d);
         $address->employee_id = $employee->id;
         $address->save();
     }
     foreach (array_get($data, 'course', []) as $key => $d) {
         if (empty($d['title']) && empty($d['start']) && empty($d['end'])) {
             continue;
         }
         $course = new Course($d);
         $course->employee_id = $employee->id;
         $course->save();
     }
     $employee->save();
     return $employee;
 }
Exemplo n.º 2
0
 private function getEmployeeDtr(Request $request, $employeeid)
 {
     $employee = Employee::findOrFail($employeeid);
     foreach ($this->dr->dateInterval() as $key => $date) {
         $timesheets[$key]['date'] = $date;
         $timelogs = $this->timelog->skipCriteria()->getRawEmployeeTimelog($employeeid, $date, $date)->all();
         //array_push($timesheets[$key]['timelog'], $this->timelog->generateTimesheet($employee->id, $date, collect($timelogs)));
         $timesheets[$key]['timelog'] = $this->timelog->generateTimesheet($employee->id, $date, collect($timelogs));
     }
     $header = new StdClass();
     $header->totalWorkedHours = collect($timesheets)->pluck('timelog')->sum('workedHours');
     return $this->setViewWithDR(view('timesheet.employee-dtr')->with('timesheets', $timesheets)->with('employee', $employee)->with('header', $header)->with('dr', $this->dr));
 }
Exemplo n.º 3
0
 public function makeDayEmployeeView(Request $request, $param1, $param2, $param3, $param4)
 {
     $employee = Employee::findOrFail($param4);
     // if fail -> 404
     $date = Carbon::create($param1, $param2, $param3, 0, 0, 0);
     $timelogs = $this->timelogs->employeeTimelogs($employee, $date);
     $dtrs = $this->dtrs->employeeByDate($employee, $date->format('Y-m-d'));
     //return dd($dtrs);
     return view('dtr.employee')->with('timelogs', $timelogs)->with('dtrs', $dtrs)->with('date', $date)->with('employee', $employee);
 }
 /**
  * This is sparta!!!
  *
  * @param Request $request
  * @param $id
  *
  * @return string
  */
 public function destroy(Request $request, $id)
 {
     if (Employee::findOrFail($id)->delete()) {
         return trans('messages.employee.deleted');
     }
 }
Exemplo n.º 5
0
 private function getEmployeeDtr(Request $request, $employeeid)
 {
     //$word = 'House NO 23/12 Muardabad Daska Road Sialkot 51310 Pakistan';
     //$w = explode(' ', $word);
     //return strlen($w[0]);
     //return $this->getChunk($word, 18, 4);
     $employee = Employee::findOrFail($employeeid);
     foreach ($this->dr->dateInterval() as $key => $date) {
         $timesheets[$key]['date'] = $date;
         //$timesheets[$key]['timelog'] = [];
         $timelogs = $this->timelog->skipCriteria()->getRawEmployeeTimelog($employeeid, $date, $date)->all();
         //array_push($timesheets[$key]['timelog'], $this->timelog->generateTimesheet($employee->id, $date, collect($timelogs)));
         $timesheets[$key]['timelog'] = $this->timelog->generateTimesheet($employee->id, $date, collect($timelogs));
     }
     //return dd($timesheets[0]->timein->timelog->datetime->format('Y-m-d'));
     //return dd($timesheets);
     $header = new StdClass();
     $header->totalWorkedHours = collect($timesheets)->pluck('timelog')->sum('workedHours');
     return $this->setViewWithDR(view('timesheet.employee-dtr')->with('timesheets', $timesheets)->with('employee', $employee)->with('header', $header)->with('dr', $this->dr));
 }
Exemplo n.º 6
0
 public function update($id, EmployeeRequest $request)
 {
     $employee = Employee::findOrFail($id);
     $file = $request->file('photo');
     $destinationPath = base_path() . '/public/image/employee/';
     if ($request->hasFile('photo')) {
         $name = time() . $file->getClientOriginalName();
         $file->move($destinationPath, $name);
         $employee->photo = $name;
     }
     $employee->name = $request->input('name');
     $employee->mobile = $request->input('mobile');
     $employee->email = $request->input('email');
     $employee->present_address = $request->input('present_address');
     $employee->permanent_address = $request->input('permanent_address');
     $employee->dob = $request->input('dob');
     $employee->designation_id = $request->input('designation_id');
     $employee->workspace_id = $request->input('workspace_id');
     $employee->employee_type = Config::get('common.employee_type.Regular');
     $employee->joining_date = $request->input('joining_date');
     $employee->updated_by = Auth::user()->id;
     $employee->updated_at = time();
     $employee->update();
     Session()->flash('flash_message', 'Employee has been updated!');
     return redirect('employees');
 }