Exemplo n.º 1
0
 public function post(Request $request)
 {
     $rules = array('datetime' => 'required', 'txncode' => 'required', 'entrytype' => 'required');
     $validator = Validator::make($request->all(), $rules);
     if ($validator->fails()) {
         $respone = array('code' => '400', 'status' => 'error', 'message' => 'Error on validation');
     } else {
         $employee = Employee::with('branch')->where('rfid', '=', $request->input('rfid'))->get();
         if (!isset($employee[0])) {
             // employee does not exist having the RFID submitted
             $respone = array('code' => '401', 'status' => 'error', 'message' => 'Invalid RFID: ' . $request->input('rfid'), 'data' => '');
         } else {
             $timelog = new Timelog();
             //$timelog->employeeid	= $request->get('employeeid');
             $timelog->employeeid = $employee[0]->id;
             $timelog->datetime = $request->input('datetime');
             $timelog->txncode = $request->input('txncode');
             $timelog->entrytype = $request->input('entrytype');
             //$timelog->terminalid 	= $request->get('terminalid');
             $timelog->terminal = gethostname();
             $timelog->id = strtoupper(Timelog::get_uid());
             if ($timelog->save()) {
                 $respone = array('code' => '200', 'status' => 'success', 'message' => 'Record saved!');
                 $datetime = explode(' ', $timelog->datetime);
                 $txncode = $timelog->txncode == 'to' ? 'Time Out' : 'Time In';
                 $data = array('empno' => $employee[0]->code, 'lastname' => $employee[0]->lastname, 'firstname' => $employee[0]->firstname, 'middlename' => $employee[0]->middlename, 'position' => $employee[0]->position, 'date' => $datetime[0], 'time' => $datetime[1], 'txncode' => $timelog->txncode, 'txnname' => $txncode, 'branch' => $employee[0]->branch->code, 'timelogid' => $timelog->id);
                 $respone['data'] = $data;
             } else {
                 $respone = array('code' => '400', 'status' => 'error', 'message' => 'Error on saving locally!');
             }
         }
     }
     return json_encode($respone);
 }
Exemplo n.º 2
0
 private function empTlog($employeeid, $date, $i, $order)
 {
     return Timelog::employeeid($employeeid)->whereBetween('datetime', [$date->format('Y-m-d') . ' 06:00:00', $date->copy()->addDay()->format('Y-m-d') . ' 05:59:00'])->txncode($i)->orderBy('datetime', $order)->first();
 }
Exemplo n.º 3
0
 public function getTkIndex(Request $request)
 {
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] === '127.0.0.1') {
         $timelogs = Timelog::with('employee.branch')->orderBy('datetime', 'DESC')->take(20)->get();
     } else {
         $timelogs = Timelog::with(['employee' => function ($query) {
             $query->with(['branch' => function ($query) {
                 $query->select('code', 'descriptor', 'id');
             }, 'position' => function ($query) {
                 $query->select('code', 'descriptor', 'id');
             }])->select('code', 'lastname', 'firstname', 'branchid', 'positionid', 'id');
         }])->select('timelog.*')->join('hr.employee', function ($join) use($request) {
             $join->on('timelog.employeeid', '=', 'employee.id')->where('employee.branchid', '=', $this->_branchid);
         })->orderBy('datetime', 'DESC')->take(20)->get();
     }
     //return $timelogs;
     //if(count($timelogs) <= 0)
     //	return redirect()->route('auth.getlogin');
     $response = new Response(view('tk.index', compact('timelogs')));
     //->with('timelogs', $timelogs));
     $response->withCookie(cookie('branchid', $this->_branchid, 45000));
     $response->withCookie(cookie('code', session('user.branchcode'), 45000));
     return $response;
     //return view('tk.index', compact($timelogs));//->with('timelogs', $timelogs);
 }
Exemplo n.º 4
0
 /**
  * Get all the timelog for an employee on the day.
  *
  * @param  Employee $employee, Carbon $date ('Y-m-d')
  * @return Collection of timelog
  */
 public function employeeTimelogs(Employee $employee, $date)
 {
     $res = Timelog::employeeid($employee->id)->whereBetween('datetime', [$date->copy()->format('Y-m-d') . ' 06:00:00', $date->copy()->addDay()->format('Y-m-d') . ' 05:59:59'])->orderBy('datetime', 'ASC')->orderBy('txncode', 'ASC')->get();
     return count($res) > 0 ? $res : false;
 }