Initial checkin v13.0

This commit is contained in:
Thilina Hasantha
2015-10-10 20:18:50 +05:30
parent 5fdd19b2c5
commit eb3439b29d
1396 changed files with 318492 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
<?php
/*
This file is part of iCE Hrm.
iCE Hrm is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
iCE Hrm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with iCE Hrm. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
class AttendanceActionManager extends SubActionManager{
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){
LogManager::getInstance()->info($attendance->ErrorMsg());
return new IceResponse(IceResponse::ERROR,"Error occured while saving attendance");
}
return new IceResponse(IceResponse::SUCCESS,$attendance);
}
}

View File

@@ -0,0 +1,176 @@
<?php
if (!class_exists('AttendanceAdminManager')) {
class AttendanceAdminManager extends AbstractModuleManager{
public function initializeUserClasses(){
}
public function initializeFieldMappings(){
}
public function initializeDatabaseErrorMappings(){
}
public function setupModuleClassDefinitions(){
$this->addModelClass('Attendance');
}
}
}
//Model Classes
if (!class_exists('Attendance')) {
class Attendance extends ICEHRM_Record {
var $_table = 'Attendance';
public function getAdminAccess(){
return array("get","element","save","delete");
}
public function getManagerAccess(){
return array("get","element","save","delete");
}
public function getUserAccess(){
return array("get");
}
public function getUserOnlyMeAccess(){
return array("element","save","delete");
}
}
}
if (!class_exists('AttendanceStatus')) {
class AttendanceStatus extends ICEHRM_Record {
var $_table = 'Attendance';
public function getRecentAttendanceEntries($limit){
$shift = intval(SettingsManager::getInstance()->getSetting("Attendance: Shift (Minutes)"));
$attendance = new Attendance();
$attendanceToday = $attendance->Find("1 = 1 order by in_time desc limit ".$limit,array());
$attendanceData = array();
$employees = array();
foreach($attendanceToday as $atEntry){
$entry = new stdClass();
$entry->id = $atEntry->employee;
$dayArr = explode(" ",$atEntry->in_time);
$day = $dayArr[0];
if($atEntry->out_time == "0000-00-00 00:00:00" || empty($atEntry->out_time)){
if(strtotime($atEntry->in_time) < (time() + $shift * 60) && $day == date("Y-m-d")){
$entry->status = "Clocked In";
$entry->statusId = 0;
$entry->color = 'green';
$employee = new Employee();
$employee->Load("id = ?",array($entry->id));
$entry->employee = $employee->first_name." ".$employee->last_name;
$employees[$entry->id] = $entry;
}
}
if(!isset($employees[$entry->id])){
$employee = new Employee();
$employee->Load("id = ?",array($entry->id));
if($day == date("Y-m-d")){
$entry->status = "Clocked Out";
$entry->statusId = 1;
$entry->color = 'yellow';
}else{
$entry->status = "Not Clocked In";
$entry->statusId = 2;
$entry->color = 'gray';
}
$entry->employee = $employee->first_name." ".$employee->last_name;
$employees[$entry->id] = $entry;
}
}
return array_values($employees);
}
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;
}
public function getAdminAccess(){
return array("get","element","save","delete");
}
public function getManagerAccess(){
return array("get","element","save","delete");
}
public function getUserAccess(){
return array("get");
}
public function getUserOnlyMeAccess(){
return array("element","save","delete");
}
}
}