Initial checkin v13.0
This commit is contained in:
137
ext/modules/attendance/api/AttendanceActionManager.php
Normal file
137
ext/modules/attendance/api/AttendanceActionManager.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?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 getPunch($req){
|
||||
$date = $req->date;
|
||||
$arr = explode(" ",$date);
|
||||
$date = $arr[0];
|
||||
|
||||
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
|
||||
|
||||
//Find any open punch
|
||||
$attendance = new Attendance();
|
||||
$attendance->Load("employee = ? and DATE_FORMAT( in_time, '%Y-%m-%d' ) = ? and (out_time is NULL or out_time = '0000-00-00 00:00:00')",array($employee->id,$date));
|
||||
|
||||
if($attendance->employee == $employee->id){
|
||||
//found an open punch
|
||||
return new IceResponse(IceResponse::SUCCESS,$attendance);
|
||||
}else{
|
||||
return new IceResponse(IceResponse::SUCCESS,null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
24
ext/modules/attendance/api/AttendanceModulesManager.php
Normal file
24
ext/modules/attendance/api/AttendanceModulesManager.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
if (!class_exists('AttendanceModulesManager')) {
|
||||
class AttendanceModulesManager extends AbstractModuleManager{
|
||||
|
||||
public function initializeUserClasses(){
|
||||
if(defined('MODULE_TYPE') && MODULE_TYPE != 'admin'){
|
||||
$this->addUserClass("Attendance");
|
||||
}
|
||||
}
|
||||
|
||||
public function initializeFieldMappings(){
|
||||
|
||||
}
|
||||
|
||||
public function initializeDatabaseErrorMappings(){
|
||||
|
||||
}
|
||||
|
||||
public function setupModuleClassDefinitions(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
70
ext/modules/attendance/index.php
Normal file
70
ext/modules/attendance/index.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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)
|
||||
*/
|
||||
|
||||
$moduleName = 'attendance';
|
||||
define('MODULE_PATH',dirname(__FILE__));
|
||||
include APP_BASE_PATH.'header.php';
|
||||
include APP_BASE_PATH.'modulejslibs.inc.php';
|
||||
?><div class="span9">
|
||||
|
||||
<ul class="nav nav-tabs" id="modTab" style="margin-bottom:0px;margin-left:5px;border-bottom: none;">
|
||||
<li class="active"><a id="tabAttendance" href="#tabPageAttendance">Attendance</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="tabPageAttendance">
|
||||
<div id="Attendance" class="reviewBlock" data-content="List" style="padding-left:5px;">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<style>
|
||||
#Attendance .dataTables_filter label{
|
||||
float:left;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var modJsList = new Array();
|
||||
modJsList['tabAttendance'] = new AttendanceAdapter('Attendance','Attendance','','in_time desc');
|
||||
modJsList['tabAttendance'].setRemoteTable(true);
|
||||
modJsList['tabAttendance'].updatePunchButton(true);
|
||||
|
||||
var modJs = modJsList['tabAttendance'];
|
||||
|
||||
</script>
|
||||
<div class="modal" id="PunchModel" tabindex="-1" role="dialog" aria-labelledby="messageModelLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-times"/></button>
|
||||
<h3 style="font-size: 17px;">Punch Time</h3>
|
||||
</div>
|
||||
<div class="modal-body" style="max-height:530px;" id="AttendanceForm">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include APP_BASE_PATH.'footer.php';?>
|
||||
236
ext/modules/attendance/lib.js
Normal file
236
ext/modules/attendance/lib.js
Normal file
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
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)
|
||||
*/
|
||||
|
||||
function AttendanceAdapter(endPoint,tab,filter,orderBy) {
|
||||
this.initAdapter(endPoint,tab,filter,orderBy);
|
||||
this.punch = null;
|
||||
}
|
||||
|
||||
AttendanceAdapter.inherits(AdapterBase);
|
||||
|
||||
AttendanceAdapter.method('updatePunchButton', function() {
|
||||
this.getPunch('changePunchButtonSuccessCallBack');
|
||||
});
|
||||
|
||||
|
||||
AttendanceAdapter.method('getDataMapping', function() {
|
||||
return [
|
||||
"id",
|
||||
"in_time",
|
||||
"out_time",
|
||||
"note"
|
||||
];
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getHeaders', function() {
|
||||
return [
|
||||
{ "sTitle": "ID" ,"bVisible":false},
|
||||
{ "sTitle": "Time-In" },
|
||||
{ "sTitle": "Time-Out"},
|
||||
{ "sTitle": "Note"}
|
||||
];
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getFormFields', function() {
|
||||
return [
|
||||
[ "id", {"label":"ID","type":"hidden"}],
|
||||
[ "time", {"label":"Time","type":"datetime"}],
|
||||
[ "note", {"label":"Note","type":"textarea","validation":"none"}]
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
AttendanceAdapter.method('getCustomTableParams', function() {
|
||||
var that = this;
|
||||
var dataTableParams = {
|
||||
"aoColumnDefs": [
|
||||
{
|
||||
"fnRender": function(data, cell){
|
||||
return that.preProcessRemoteTableData(data, cell, 1)
|
||||
} ,
|
||||
"aTargets": [1]
|
||||
},
|
||||
{
|
||||
"fnRender": function(data, cell){
|
||||
return that.preProcessRemoteTableData(data, cell, 2)
|
||||
} ,
|
||||
"aTargets": [2]
|
||||
},
|
||||
{
|
||||
"fnRender": function(data, cell){
|
||||
return that.preProcessRemoteTableData(data, cell, 3)
|
||||
} ,
|
||||
"aTargets": [3]
|
||||
},
|
||||
{
|
||||
"fnRender": that.getActionButtons,
|
||||
"aTargets": [that.getDataMapping().length]
|
||||
}
|
||||
]
|
||||
};
|
||||
return dataTableParams;
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('preProcessRemoteTableData', function(data, cell, id) {
|
||||
if(id == 1){
|
||||
if(cell == '0000-00-00 00:00:00' || cell == "" || cell == undefined || cell == null){
|
||||
return "";
|
||||
}
|
||||
return Date.parse(cell).toString('yyyy MMM d <b>HH:mm</b>');
|
||||
}else if(id == 2){
|
||||
if(cell == '0000-00-00 00:00:00' || cell == "" || cell == undefined || cell == null){
|
||||
return "";
|
||||
}
|
||||
return Date.parse(cell).toString('MMM d <b>HH:mm</b>');
|
||||
}else if(id == 3){
|
||||
if(cell != undefined && cell != null){
|
||||
if(cell.length > 20){
|
||||
return cell.substring(0,20)+"..";
|
||||
}
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
AttendanceAdapter.method('getActionButtonsHtml', function(id,data) {
|
||||
/*
|
||||
var html = '<div style="width:80px;"><img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit" onclick="modJs.edit(_id_);return false;"></img><img class="tableActionButton" src="_BASE_images/download.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Download Document" onclick="download(\'_attachment_\');return false;"></img><img class="tableActionButton" src="_BASE_images/delete.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Delete" onclick="modJs.deleteRow(_id_);return false;"></img></div>';
|
||||
html = html.replace(/_id_/g,id);
|
||||
html = html.replace(/_attachment_/g,data[5]);
|
||||
html = html.replace(/_BASE_/g,this.baseUrl);
|
||||
return html;
|
||||
*/
|
||||
return "";
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getTableTopButtonHtml', function() {
|
||||
if(this.punch == null || this.punch == undefined){
|
||||
return '<button id="punchButton" style="float:right;" onclick="modJs.showPunchDialog();return false;" class="btn btn-small">Punch-in <span class="icon-time"></span></button>';
|
||||
}else{
|
||||
return '<button id="punchButton" style="float:right;" onclick="modJs.showPunchDialog();return false;" class="btn btn-small">Punch-out <span class="icon-time"></span></button>';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
AttendanceAdapter.method('save', function() {
|
||||
var that = this;
|
||||
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
|
||||
if(validator.checkValues()){
|
||||
var params = validator.getFormParameters();
|
||||
params['cdate'] = this.getClientDate(new Date()).toISOString().slice(0, 19).replace('T', ' ');
|
||||
var reqJson = JSON.stringify(params);
|
||||
var callBackData = [];
|
||||
callBackData['callBackData'] = [];
|
||||
callBackData['callBackSuccess'] = 'saveSuccessCallback';
|
||||
callBackData['callBackFail'] = 'getPunchFailCallBack';
|
||||
|
||||
this.customAction('savePunch','modules=attendance',reqJson,callBackData);
|
||||
}
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('saveSuccessCallback', function(callBackData) {
|
||||
this.punch = callBackData;
|
||||
this.getPunch('changePunchButtonSuccessCallBack');
|
||||
$('#PunchModel').modal('hide');
|
||||
this.get([]);
|
||||
});
|
||||
|
||||
|
||||
AttendanceAdapter.method('cancel', function() {
|
||||
$('#PunchModel').modal('hide');
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('showPunchDialog', function() {
|
||||
this.getPunch('showPunchDialogShowPunchSuccessCallBack');
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getPunch', function(successCallBack) {
|
||||
var that = this;
|
||||
var object = {};
|
||||
|
||||
object['date'] = this.getClientDate(new Date()).toISOString().slice(0, 19).replace('T', ' ');
|
||||
object['offset'] = this.getClientGMTOffset();
|
||||
var reqJson = JSON.stringify(object);
|
||||
var callBackData = [];
|
||||
callBackData['callBackData'] = [];
|
||||
callBackData['callBackSuccess'] = successCallBack;
|
||||
callBackData['callBackFail'] = 'getPunchFailCallBack';
|
||||
|
||||
this.customAction('getPunch','modules=attendance',reqJson,callBackData);
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('postRenderForm', function(object, $tempDomObj) {
|
||||
$("#Attendance").show();
|
||||
});
|
||||
|
||||
|
||||
|
||||
AttendanceAdapter.method('showPunchDialogShowPunchSuccessCallBack', function(callBackData) {
|
||||
this.punch = callBackData;
|
||||
$('#PunchModel').modal('show');
|
||||
if(this.punch == null){
|
||||
$('#PunchModel').find("h3").html("Punch Time-in");
|
||||
modJs.renderForm();
|
||||
}else{
|
||||
$('#PunchModel').find("h3").html("Punch Time-out");
|
||||
modJs.renderForm(this.punch);
|
||||
}
|
||||
|
||||
var picker = $('#time_datetime').data('datetimepicker');
|
||||
picker.setLocalDate(new Date());
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('changePunchButtonSuccessCallBack', function(callBackData) {
|
||||
this.punch = callBackData;
|
||||
if(this.punch == null){
|
||||
$("#punchButton").html('Punch-in <span class="icon-time"></span>');
|
||||
}else{
|
||||
$("#punchButton").html('Punch-out <span class="icon-time"></span>');
|
||||
}
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getPunchFailCallBack', function(callBackData) {
|
||||
this.showMessage("Error Occured while Time Punch", callBackData);
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getClientDate', function (date) {
|
||||
|
||||
var offset = this.getClientGMTOffset();
|
||||
var tzDate = date.addMinutes(offset*60);
|
||||
return tzDate;
|
||||
|
||||
});
|
||||
|
||||
AttendanceAdapter.method('getClientGMTOffset', function () {
|
||||
|
||||
var rightNow = new Date();
|
||||
var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
|
||||
var temp = jan1.toGMTString();
|
||||
var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
|
||||
var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
|
||||
|
||||
return std_time_offset;
|
||||
|
||||
});
|
||||
11
ext/modules/attendance/meta.json
Normal file
11
ext/modules/attendance/meta.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"label":"Attendance",
|
||||
"menu":"Time Management",
|
||||
"order":"2",
|
||||
"icon":"fa-clock-o",
|
||||
"user_levels":["Admin","Manager","Employee"],
|
||||
|
||||
"permissions":
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user