Ejemplo 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', 'position')->where('rfid', '=', $request->input('rfid'))->first();
         if (!isset($employee)) {
             // 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->id;
             $timelog->datetime = $request->input('datetime');
             $timelog->txncode = strtolower($employee->branchid) == strtolower($this->_branchid) ? $request->input('txncode') : '9';
             $timelog->entrytype = $request->input('entrytype');
             $timelog->rfid = $employee->rfid;
             $timelog->terminalid = $request->cookie('branchcode') !== null ? $request->cookie('branchcode') : clientIP();
             //$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);
                 $data = array('empno' => $employee->code, 'lastname' => $employee->lastname, 'firstname' => $employee->firstname, 'middlename' => $employee->middlename, 'position' => $employee->position->descriptor, 'date' => $datetime[0], 'time' => $datetime[1], 'txncode' => $timelog->txncode, 'txnname' => $timelog->getTxnCode(), 'branch' => $employee->branch->code, 'timelogid' => $timelog->id);
                 $respone['data'] = $data;
             } else {
                 $respone = array('code' => '400', 'status' => 'error', 'message' => 'Error on saving locally!');
             }
         }
     }
     return json_encode($respone);
 }