public function validateSave($obj)
 {
     if (SettingsManager::getInstance()->getSetting("Attendance: Time-sheet Cross Check") == "1") {
         $attendance = new Attendance();
         $list = $attendance->Find("employee = ? and in_time <= ? and out_time >= ?", array($obj->employee, $obj->date_start, $obj->date_end));
         if (empty($list) || count($list) == 0) {
             return new IceResponse(IceResponse::ERROR, "The time entry can not be added since you have not marked attendance for selected period");
         }
     }
     return new IceResponse(IceResponse::SUCCESS, "");
 }
Exemplo n.º 2
0
	public function savePunch($req){
		$req->date = $req->time;
		
		/*
		if(strtotime($req->date) > strtotime($req->cdate)){
			return new IceResponse(IceResponse::ERROR,"You are not allowed to punch a future time");
		}
		*/
		
		//check if there is an open punch
		$openPunch = $this->getPunch($req)->getData();
		
		if(empty($openPunch)){
			$openPunch = new Attendance();
		}

		$dateTime = $req->date;
		$arr = explode(" ",$dateTime);
		$date = $arr[0];
		
		$currentDateTime = $req->cdate;
		$arr = explode(" ",$currentDateTime);
		$currentDate = $arr[0];
		
		if($currentDate != $date){
			return new IceResponse(IceResponse::ERROR,"You are not allowed to punch time for a previous date");
		}
	
		$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
		
		//check if dates are differnet
		$arr = explode(" ",$openPunch->in_time);
		$inDate = $arr[0];
		if(!empty($openPunch->in_time) && $inDate != $date){
			return new IceResponse(IceResponse::ERROR,"Attendance entry should be within a single day");
		}
		
		//compare dates
		if(!empty($openPunch->in_time) && strtotime($dateTime) <= strtotime($openPunch->in_time)){
			return new IceResponse(IceResponse::ERROR,"Punch-in time should be lesser than Punch-out time");
		}
	
		//Find all punches for the day
		$attendance = new Attendance();
		$attendanceList = $attendance->Find("employee = ? and DATE_FORMAT( in_time,  '%Y-%m-%d' ) = ?",array($employee->id,$date));
		
		foreach($attendanceList as $attendance){
			if(!empty($openPunch->in_time)){
				if($openPunch->id == $attendance->id){
					continue;
				}
				if(strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)){
					//-1---0---1---0 || ---0--1---1---0
					return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 1");
				}else if(strtotime($attendance->out_time) >= strtotime($openPunch->in_time) && strtotime($attendance->in_time) <= strtotime($openPunch->in_time)){
					//---0---1---0---1 || ---0--1---1---0
					return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 2");
				}else if(strtotime($attendance->out_time) <= strtotime($dateTime) && strtotime($attendance->in_time) >= strtotime($openPunch->in_time)){
					//--1--0---0--1--
					return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 3 ".$attendance->id);
				}	
			}else{
				if(strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)){
					//---0---1---0 
					return new IceResponse(IceResponse::ERROR,"Time entry is overlapping with an existing one 4");
				}	
			}
		}
		if(!empty($openPunch->in_time)){
			$openPunch->out_time = $dateTime;
			$openPunch->note = $req->note;
			$this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch Out \ time:".$openPunch->out_time);
		}else{
			$openPunch->in_time = $dateTime;
			$openPunch->out_time = '0000-00-00 00:00:00';
			$openPunch->note = $req->note;
			$openPunch->employee = $employee->id;
			$this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch In \ time:".$openPunch->in_time);
		}
		$ok = $openPunch->Save();
		
		if(!$ok){
			LogManager::getInstance()->info($openPunch->ErrorMsg());
			return new IceResponse(IceResponse::ERROR,"Error occured while saving attendance");
		}
		return new IceResponse(IceResponse::SUCCESS,$openPunch);
	
	}
Exemplo n.º 3
0
 public function Find($whereOrderBy, $bindarr = false, $pkeysArr = false, $extra = array())
 {
     $shift = intval(SettingsManager::getInstance()->getSetting("Attendance: Shift (Minutes)"));
     $employee = new Employee();
     $data = array();
     $employees = $employee->Find("1=1");
     $attendance = new Attendance();
     $attendanceToday = $attendance->Find("date(in_time) = ?", array(date("Y-m-d")));
     $attendanceData = array();
     //Group by employee
     foreach ($attendanceToday as $attendance) {
         if (isset($attendanceData[$attendance->employee])) {
             $attendanceData[$attendance->employee][] = $attendance;
         } else {
             $attendanceData[$attendance->employee] = array($attendance);
         }
     }
     foreach ($employees as $employee) {
         $entry = new stdClass();
         $entry->id = $employee->id;
         $entry->employee = $employee->id;
         if (isset($attendanceData[$employee->id])) {
             $attendanceEntries = $attendanceData[$employee->id];
             foreach ($attendanceEntries as $atEntry) {
                 if ($atEntry->out_time == "0000-00-00 00:00:00" || empty($atEntry->out_time)) {
                     if (strtotime($atEntry->in_time) < time() + $shift * 60) {
                         $entry->status = "Clocked In";
                         $entry->statusId = 0;
                     }
                 }
             }
             if (empty($entry->status)) {
                 $entry->status = "Clocked Out";
                 $entry->statusId = 1;
             }
         } else {
             $entry->status = "Not Clocked In";
             $entry->statusId = 2;
         }
         $data[] = $entry;
     }
     function cmp($a, $b)
     {
         return $a->statusId - $b->statusId;
     }
     usort($data, "cmp");
     return $data;
 }
Exemplo n.º 4
0
 public function savePunch($req)
 {
     $employee = $this->baseService->getElement('Employee', $req->employee, null, true);
     $inDateTime = $req->in_time;
     $inDateArr = explode(" ", $inDateTime);
     $inDate = $inDateArr[0];
     $outDateTime = $req->out_time;
     $outDate = "";
     if (!empty($outDateTime)) {
         $outDateArr = explode(" ", $outDateTime);
         $outDate = $outDateArr[0];
     }
     $note = $req->note;
     //check if dates are differnet
     if (!empty($outDate) && $inDate != $outDate) {
         return new IceResponse(IceResponse::ERROR, "Attendance entry should be within a single day");
     }
     //compare dates
     if (!empty($outDateTime) && strtotime($outDateTime) <= strtotime($inDateTime)) {
         return new IceResponse(IceResponse::ERROR, "Punch-in time should be lesser than Punch-out time");
     }
     //Find all punches for the day
     $attendance = new Attendance();
     $attendanceList = $attendance->Find("employee = ? and DATE_FORMAT( in_time,  '%Y-%m-%d' ) = ?", array($employee->id, $inDate));
     foreach ($attendanceList as $attendance) {
         if (!empty($req->id) && $req->id == $attendance->id) {
             continue;
         }
         if (empty($attendance->out_time) || $attendance->out_time == "0000-00-00 00:00:00") {
             return new IceResponse(IceResponse::ERROR, "There is a non closed attendance entry for today. Please mark punch-out time of the open entry before adding a new one");
         } else {
             if (!empty($outDateTime)) {
                 if (strtotime($attendance->out_time) >= strtotime($outDateTime) && strtotime($attendance->in_time) <= strtotime($outDateTime)) {
                     //-1---0---1---0 || ---0--1---1---0
                     return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
                 } else {
                     if (strtotime($attendance->out_time) >= strtotime($inDateTime) && strtotime($attendance->in_time) <= strtotime($inDateTime)) {
                         //---0---1---0---1 || ---0--1---1---0
                         return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
                     } else {
                         if (strtotime($attendance->out_time) <= strtotime($outDateTime) && strtotime($attendance->in_time) >= strtotime($inDateTime)) {
                             //--1--0---0--1--
                             return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
                         }
                     }
                 }
             } else {
                 if (strtotime($attendance->out_time) >= strtotime($inDateTime) && strtotime($attendance->in_time) <= strtotime($inDateTime)) {
                     //---0---1---0
                     return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
                 }
             }
         }
     }
     $attendance = new Attendance();
     if (!empty($req->id)) {
         $attendance->Load("id = ?", array($req->id));
     }
     $attendance->in_time = $inDateTime;
     if (empty($outDateTime)) {
         $attendance->out_time = "0000-00-00 00:00:00";
     } else {
         $attendance->out_time = $outDateTime;
     }
     $attendance->employee = $req->employee;
     $attendance->note = $note;
     $ok = $attendance->Save();
     if (!$ok) {
         error_log($attendance->ErrorMsg());
         return new IceResponse(IceResponse::ERROR, "Error occured while saving attendance");
     }
     return new IceResponse(IceResponse::SUCCESS, $attendance);
 }
Exemplo n.º 5
0
 public function getData($report, $req)
 {
     error_log(json_encode($report));
     error_log(json_encode($req));
     $employeeTimeEntry = new EmployeeTimeEntry();
     $timeEntryList = $employeeTimeEntry->Find("employee = ? and date(date_start) >= ? and  date(date_end) <= ?", array($req['employee'], $req['date_start'], $req['date_end']));
     $seconds = 0;
     $graphTimeArray = array();
     foreach ($timeEntryList as $entry) {
         $seconds = strtotime($entry->date_end) - strtotime($entry->date_start);
         $key = date("Y-m-d", strtotime($entry->date_end));
         if (isset($graphTimeArray[$key])) {
             $graphTimeArray[$key] += $seconds;
         } else {
             $graphTimeArray[$key] = $seconds;
         }
     }
     //$minutes = (int)($seconds/60);
     //Find Attendance Entries
     $attendance = new Attendance();
     $atteandanceList = $attendance->Find("employee = ? and date(in_time) >= ? and  date(out_time) <= ? and in_time < out_time", array($req['employee'], $req['date_start'], $req['date_end']));
     $seconds = 0;
     $graphAttendanceArray = array();
     $firstTimeInArray = array();
     $lastTimeOutArray = array();
     foreach ($atteandanceList as $entry) {
         $seconds = strtotime($entry->out_time) - strtotime($entry->in_time);
         $key = date("Y-m-d", strtotime($entry->in_time));
         if (isset($graphAttendanceArray[$key])) {
             $graphAttendanceArray[$key] += $seconds;
             $lastTimeOutArray[$key] = $entry->out_time;
         } else {
             $graphAttendanceArray[$key] = $seconds;
             $firstTimeInArray[$key] = $entry->in_time;
             $lastTimeOutArray[$key] = $entry->out_time;
         }
     }
     /////////////////////////////////////////
     $employeeObject = new Employee();
     $employeeObject->Load("id = ?", array($req['employee']));
     $reportData = array();
     //$reportData[] = array($employeeObject->first_name." ".$employeeObject->last_name,"","","","");
     $reportData[] = array("Date", "First Punch-In Time", "Last Punch-Out Time", "Time in Office", "Time in Timesheets");
     //Iterate date range
     $interval = DateInterval::createFromDateString('1 day');
     $period = new DatePeriod(new DateTime($req['date_start']), $interval, new DateTime($req['date_end']));
     foreach ($period as $dt) {
         $dataRow = array();
         $key = $dt->format("Y-m-d");
         $dataRow[] = $key;
         if (isset($firstTimeInArray[$key])) {
             $dataRow[] = $firstTimeInArray[$key];
         } else {
             $dataRow[] = "Not Found";
         }
         if (isset($lastTimeOutArray[$key])) {
             $dataRow[] = $lastTimeOutArray[$key];
         } else {
             $dataRow[] = "Not Found";
         }
         if (isset($graphAttendanceArray[$key])) {
             $dataRow[] = round($graphAttendanceArray[$key] / 3600, 2);
         } else {
             $dataRow[] = 0;
         }
         if (isset($graphTimeArray[$key])) {
             $dataRow[] = round($graphTimeArray[$key] / 3600, 2);
         } else {
             $dataRow[] = 0;
         }
         $reportData[] = $dataRow;
     }
     return $reportData;
 }
 private function getTotalOverTimeCost($id, $salary)
 {
     $attendance = new Attendance();
     $attendances = $attendance->Find('employee = ?', array($id));
     $hourPay = $salary / 22 / 8;
     $total = 0;
     foreach ($attendances as $dayAttendance) {
         if ($dayAttendance->in_time - $dayAttendance->out_time > 8) {
             $overTimeHours = $dayAttendance->in_time - $dayAttendance->out_time - 8;
             $total += $overTimeHours * $hourPay;
         }
     }
     $total = floor($total);
     return $total;
 }
Exemplo n.º 7
0
 public function savePunch($req)
 {
     $useServerTime = SettingsManager::getInstance()->getSetting('Attendance: Use Department Time Zone');
     $currentEmployeeTimeZone = BaseService::getInstance()->getCurrentEmployeeTimeZone();
     if ($useServerTime == '1' && !empty($currentEmployeeTimeZone)) {
         date_default_timezone_set('Asia/Colombo');
         $date = new DateTime("now", new DateTimeZone('Asia/Colombo'));
         $date->setTimezone(new DateTimeZone($currentEmployeeTimeZone));
         $req->time = $date->format('Y-m-d H:i:s');
     }
     $req->date = $req->time;
     //check if there is an open punch
     $openPunch = $this->getPunch($req)->getData();
     if (empty($openPunch)) {
         $openPunch = new Attendance();
     }
     $dateTime = $req->date;
     $arr = explode(" ", $dateTime);
     $date = $arr[0];
     $employee = $this->baseService->getElement('Employee', $this->getCurrentProfileId(), null, true);
     //check if dates are differnet
     $arr = explode(" ", $openPunch->in_time);
     $inDate = $arr[0];
     if (!empty($openPunch->in_time) && $inDate != $date) {
         return new IceResponse(IceResponse::ERROR, "Attendance entry should be within a single day");
     }
     //compare dates
     if (!empty($openPunch->in_time) && strtotime($dateTime) <= strtotime($openPunch->in_time)) {
         return new IceResponse(IceResponse::ERROR, "Punch-in time should be lesser than Punch-out time");
     }
     //Find all punches for the day
     $attendance = new Attendance();
     $attendanceList = $attendance->Find("employee = ? and DATE_FORMAT( in_time,  '%Y-%m-%d' ) = ?", array($employee->id, $date));
     foreach ($attendanceList as $attendance) {
         if (!empty($openPunch->in_time)) {
             if ($openPunch->id == $attendance->id) {
                 continue;
             }
             if (strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)) {
                 //-1---0---1---0 || ---0--1---1---0
                 return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
             } else {
                 if (strtotime($attendance->out_time) >= strtotime($openPunch->in_time) && strtotime($attendance->in_time) <= strtotime($openPunch->in_time)) {
                     //---0---1---0---1 || ---0--1---1---0
                     return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
                 } else {
                     if (strtotime($attendance->out_time) <= strtotime($dateTime) && strtotime($attendance->in_time) >= strtotime($openPunch->in_time)) {
                         //--1--0---0--1--
                         return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one " . $attendance->id);
                     }
                 }
             }
         } else {
             if (strtotime($attendance->out_time) >= strtotime($dateTime) && strtotime($attendance->in_time) <= strtotime($dateTime)) {
                 //---0---1---0
                 return new IceResponse(IceResponse::ERROR, "Time entry is overlapping with an existing one");
             }
         }
     }
     if (!empty($openPunch->in_time)) {
         $openPunch->out_time = $dateTime;
         $openPunch->note = $req->note;
         $this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch Out \\ time:" . $openPunch->out_time);
     } else {
         $openPunch->in_time = $dateTime;
         $openPunch->out_time = '0000-00-00 00:00:00';
         $openPunch->note = $req->note;
         $openPunch->employee = $employee->id;
         $this->baseService->audit(IceConstants::AUDIT_ACTION, "Punch In \\ time:" . $openPunch->in_time);
     }
     $ok = $openPunch->Save();
     if (!$ok) {
         LogManager::getInstance()->info($openPunch->ErrorMsg());
         return new IceResponse(IceResponse::ERROR, "Error occured while saving attendance");
     }
     return new IceResponse(IceResponse::SUCCESS, $openPunch);
 }
 public function getAttendance($req)
 {
     if (empty($req->start)) {
         $req->start = date("Y-m-01");
     }
     if (empty($req->end)) {
         $req->end = date("Y-m-t", strtotime($req->start));
     }
     //Find Attendance Entries
     $attendance = new Attendance();
     if (empty($req->employee)) {
         $atteandanceList = $attendance->Find("date(in_time) >= ? and  date(out_time) <= ? and in_time < out_time", array($req->start, $req->end));
     } else {
         $atteandanceList = $attendance->Find("employee = ? and date(in_time) >= ? and  date(out_time) <= ? and in_time < out_time", array($req->employee, $req->start, $req->end));
     }
     $seconds = 0;
     $graphAttendanceArray = array();
     foreach ($atteandanceList as $entry) {
         $seconds = strtotime($entry->out_time) - strtotime($entry->in_time);
         $key = date("Y-m-d", strtotime($entry->in_time));
         if (isset($graphAttendanceArray[$key])) {
             $graphAttendanceArray[$key] += $seconds;
         } else {
             $graphAttendanceArray[$key] = $seconds;
         }
     }
     $data[0] = array();
     $data[0] = array("key" => "Attendance", "values" => array());
     //Iterate date range
     $interval = DateInterval::createFromDateString('1 day');
     $period = new DatePeriod(new DateTime($req->start), $interval, new DateTime($req->end));
     foreach ($period as $dt) {
         $key = $dt->format("Y-m-d");
         if (isset($graphAttendanceArray[$key])) {
             $data[0]['values'][] = array("x" => $key, "y" => round($graphAttendanceArray[$key] / 3600, 2));
         } else {
             $data[0]['values'][] = array("x" => $key, "y" => 0);
         }
     }
     return new IceResponse(IceResponse::SUCCESS, $data);
 }