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,165 @@
<?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 Time_sheetsActionManager extends SubActionManager{
public function getTimeEntries($req){
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
$timeSheetEntry = new EmployeeTimeEntry();
$list = $timeSheetEntry->Find("timesheet = ? order by date_start",array($req->id));
$mappingStr = $req->sm;
$map = json_decode($mappingStr);
if(!$list){
LogManager::getInstance()->info($timeSheetEntry->ErrorMsg());
}
if(!empty($mappingStr)){
$list = $this->baseService->populateMapping($list,$map);
}
return new IceResponse(IceResponse::SUCCESS,$list);
}
public function changeTimeSheetStatus($req){
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
$subordinate = new Employee();
$subordinates = $subordinate->Find("supervisor = ?",array($employee->id));
$subordinatesIds = array();
foreach($subordinates as $sub){
$subordinatesIds[] = $sub->id;
}
$timeSheet = new EmployeeTimeSheet();
$timeSheet->Load("id = ?",array($req->id));
if($timeSheet->id != $req->id){
return new IceResponse(IceResponse::ERROR,"Timesheet not found");
}
if($req->status == 'Submitted' && $employee->id == $timeSheet->employee){
}else if(!in_array($timeSheet->employee, $subordinatesIds) && $this->user->user_level != 'Admin'){
return new IceResponse(IceResponse::ERROR,"This Timesheet does not belong to any of your subordinates");
}
$oldStatus = $timeSheet->status;
$timeSheet->status = $req->status;
if($oldStatus == $req->status){
return new IceResponse(IceResponse::SUCCESS,"");
}
$ok = $timeSheet->Save();
if(!$ok){
LogManager::getInstance()->info($timeSheet->ErrorMsg());
}
$timeSheetEmployee = $this->baseService->getElement('Employee',$timeSheet->employee,null,true);
$this->baseService->audit(IceConstants::AUDIT_ACTION, "Timesheet [".$timeSheetEmployee->first_name." ".$timeSheetEmployee->last_name." - ".date("M d, Y (l)",strtotime($timeSheet->date_start))." to ".date("M d, Y (l)",strtotime($timeSheet->date_end))."] status changed from:".$oldStatus." to:".$req->status);
if($timeSheet->status == "Submitted" && $employee->id == $timeSheet->employee){
$notificationMsg = $employee->first_name." ".$employee->last_name." submitted timesheet from ".date("M d, Y (l)",strtotime($timeSheet->date_start))." to ".date("M d, Y (l)",strtotime($timeSheet->date_end));
$this->baseService->notificationManager->addNotification($employee->supervisor,$notificationMsg,'{"type":"url","url":"g=modules&n=time_sheets&m=module_Time_Management#tabSubEmployeeTimeSheetAll"}',IceConstants::NOTIFICATION_TIMESHEET);
}else if($timeSheet->status == "Approved" || $timeSheet->status == "Rejected"){
$notificationMsg = $employee->first_name." ".$employee->last_name." ".$timeSheet->status." timesheet from ".date("M d, Y (l)",strtotime($timeSheet->date_start))." to ".date("M d, Y (l)",strtotime($timeSheet->date_end));
$this->baseService->notificationManager->addNotification($timeSheet->employee,$notificationMsg,'{"type":"url","url":"g=modules&n=time_sheets&m=module_Time_Management#tabEmployeeTimeSheetApproved"}',IceConstants::NOTIFICATION_TIMESHEET);
}
return new IceResponse(IceResponse::SUCCESS,"");
}
public function createPreviousTimesheet($req){
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
$timeSheet = new EmployeeTimeSheet();
$timeSheet->Load("id = ?",array($req->id));
if($timeSheet->id != $req->id){
return new IceResponse(IceResponse::ERROR,"Timesheet not found");
}
if($timeSheet->employee != $employee->id){
return new IceResponse(IceResponse::ERROR,"You don't have permissions to add this Timesheet");
}
$end = date("Y-m-d", strtotime("last Saturday", strtotime($timeSheet->date_start)));
$start = date("Y-m-d", strtotime("last Sunday", strtotime($end)));
$tempTimeSheet = new EmployeeTimeSheet();
$tempTimeSheet->Load("employee = ? and date_start = ?",array($employee->id, $start));
if($employee->id == $tempTimeSheet->employee){
return new IceResponse(IceResponse::ERROR,"Timesheet already exists");
}
$newTimeSheet = new EmployeeTimeSheet();
$newTimeSheet->employee = $employee->id;
$newTimeSheet->date_start = $start;
$newTimeSheet->date_end = $end;
$newTimeSheet->status = "Pending";
$ok = $newTimeSheet->Save();
if(!$ok){
LogManager::getInstance()->info("Error creating time sheet : ".$newTimeSheet->ErrorMsg());
return new IceResponse(IceResponse::ERROR,"Error creating Timesheet");
}
return new IceResponse(IceResponse::SUCCESS,"");
}
public function getSubEmployeeTimeSheets($req){
$employee = $this->baseService->getElement('Employee',$this->getCurrentProfileId(),null,true);
$subordinate = new Employee();
$subordinates = $subordinate->Find("supervisor = ?",array($employee->id));
$subordinatesIds = "";
foreach($subordinates as $sub){
if($subordinatesIds != ""){
$subordinatesIds.=",";
}
$subordinatesIds.=$sub->id;
}
$subordinatesIds.="";
$mappingStr = $req->sm;
$map = json_decode($mappingStr);
$timeSheet = new EmployeeTimeSheet();
$list = $timeSheet->Find("employee in (".$subordinatesIds.")",array());
if(!$list){
LogManager::getInstance()->info($timeSheet->ErrorMsg());
}
if(!empty($mappingStr)){
$list = $this->baseService->populateMapping($list,$map);
}
return new IceResponse(IceResponse::SUCCESS,$list);
}
}

View File

@@ -0,0 +1,67 @@
<?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 Time_sheetsInitialize extends AbstractInitialize{
public function init(){
//Add Employee time sheets if it is not already created for current week
$empId = $this->getCurrentProfileId();
if(date('w', strtotime("now")) == 0) {
$start = date("Y-m-d", strtotime("now"));
}else{
$start = date("Y-m-d", strtotime("last Sunday"));
}
if(date('w', strtotime("now")) == 6) {
$end = date("Y-m-d", strtotime("now"));
}else{
$end = date("Y-m-d", strtotime("next Saturday"));
}
$timeSheet = new EmployeeTimeSheet();
$timeSheet->Load("employee = ? and date_start = ? and date_end = ?",array($empId,$start,$end));
if($timeSheet->date_start == $start && $timeSheet->employee == $empId){
}else{
if(!empty($empId)){
$timeSheet->employee = $empId;
$timeSheet->date_start = $start;
$timeSheet->date_end = $end;
$timeSheet->status = "Pending";
$ok = $timeSheet->Save();
if(!$ok){
LogManager::getInstance()->info("Error creating time sheet : ".$timeSheet->ErrorMsg());
}
}
}
//Generate missing timesheets
}
}

View File

@@ -0,0 +1,82 @@
<?php
if (!class_exists('Time_sheetsModulesManager')) {
class Time_sheetsModulesManager extends AbstractModuleManager{
public function initializeUserClasses(){
$this->addUserClass("EmployeeTimeSheet");
$this->addUserClass("EmployeeTimeEntry");
}
public function initializeFieldMappings(){
}
public function initializeDatabaseErrorMappings(){
}
public function setupModuleClassDefinitions(){
$this->addModelClass('EmployeeTimeSheet');
$this->addModelClass('EmployeeTimeEntry');
}
}
}
if (!class_exists('EmployeeTimeSheet')) {
class EmployeeTimeSheet extends ICEHRM_Record {
var $_table = 'EmployeeTimeSheets';
public function getAdminAccess(){
return array("get","element","save","delete");
}
public function getManagerAccess(){
return array("get","element","save","delete");
}
public function getUserAccess(){
return array("get","element");
}
public function getUserOnlyMeAccess(){
return array("element","save","delete");
}
}
class EmployeeTimeEntry extends ICEHRM_Record {
var $_table = 'EmployeeTimeEntry';
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");
}
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,"");
}
}
}

View File

@@ -0,0 +1,19 @@
<form class="form-horizontal" id="_id_" role="form">
<div class="box-body">
<div class="control-group">
<div class="controls">
<span class="label label-warning" id="_id__error" style="display:none;"></span>
</div>
</div>
_fields_
<div class="control-group row">
<div class="controls col-sm-9">
<button onclick="try{modJs.save()}catch(e){};return false;" class="saveBtn btn btn-primary pull-right"><i class="fa fa-save"></i> Save</button>
<button onclick="modJs.cancel();return false;" class="cancelBtn btn pull-right" style="margin-right:5px;"><i class="fa fa-times-circle-o"></i> Cancel</button>
</div>
<div class="controls col-sm-3">
</div>
</div>
</div>
</form>

View File

@@ -0,0 +1,163 @@
<?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 = 'employee_TimeSheet';
define('MODULE_PATH',dirname(__FILE__));
include APP_BASE_PATH.'header.php';
include APP_BASE_PATH.'modulejslibs.inc.php';
//custom code
$employeeProjects = array();
$allowAllProjects = $settingsManager->getSetting("Projects: Make All Projects Available to Employees");
if($allowAllProjects == 0){
$employeeProjects = array();
$employeeProjectsTemp = $baseService->get("EmployeeProject");
foreach($employeeProjectsTemp as $p){
$project = new Project();
$project->Load("id = ?",$p->project);
$p->name = $project->name;
$employeeProjects[] = $p;
}
}else{
$employeeProjects = $baseService->get("Project");
}
?><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="tabEmployeeTimeSheetAll" href="#tabPageEmployeeTimeSheetAll">All My TimeSheets</a></li>
<li class=""><a id="tabEmployeeTimeSheetApproved" href="#tabPageEmployeeTimeSheetApproved">Approved TimeSheets</a></li>
<li class=""><a id="tabEmployeeTimeSheetPending" href="#tabPageEmployeeTimeSheetPending">Pending TimeSheets</a></li>
<li class=""><a id="tabSubEmployeeTimeSheetAll" href="#tabPageSubEmployeeTimeSheetAll">Subordinate TimeSheets</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tabPageEmployeeTimeSheetAll">
<div id="EmployeeTimeSheetAll" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="EmployeeTimeSheetAllForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
<div class="tab-pane" id="tabPageEmployeeTimeSheetApproved">
<div id="EmployeeTimeSheetApproved" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="EmployeeTimeSheetApprovedForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
<div class="tab-pane" id="tabPageEmployeeTimeSheetPending">
<div id="EmployeeTimeSheetPending" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="EmployeeTimeSheetPendingForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
<div class="tab-pane" id="tabPageSubEmployeeTimeSheetAll">
<div id="SubEmployeeTimeSheetAll" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="SubEmployeeTimeSheetAllForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
</div>
</div>
</div>
</div>
<script>
var modJsList = new Array();
modJsList['tabEmployeeTimeSheetAll'] = new EmployeeTimeSheetAdapter('EmployeeTimeSheet','EmployeeTimeSheetAll','','date_start desc');
modJsList['tabEmployeeTimeSheetAll'].setShowAddNew(false);
modJsList['tabEmployeeTimeSheetAll'].setRemoteTable(true);
modJsList['tabEmployeeTimeSheetApproved'] = new EmployeeTimeSheetAdapter('EmployeeTimeSheet','EmployeeTimeSheetApproved',{"status":"Approved"});
modJsList['tabEmployeeTimeSheetApproved'].setShowAddNew(false);
modJsList['tabEmployeeTimeSheetApproved'].setRemoteTable(true);
modJsList['tabEmployeeTimeSheetPending'] = new EmployeeTimeSheetAdapter('EmployeeTimeSheet','EmployeeTimeSheetPending',{"status":"Pending"});
modJsList['tabEmployeeTimeSheetPending'].setShowAddNew(false);
modJsList['tabEmployeeTimeSheetPending'].setRemoteTable(true);
modJsList['tabSubEmployeeTimeSheetAll'] = new SubEmployeeTimeSheetAdapter('EmployeeTimeSheet','SubEmployeeTimeSheetAll','','date_start desc');
modJsList['tabSubEmployeeTimeSheetAll'].setShowAddNew(false);
modJsList['tabSubEmployeeTimeSheetAll'].setRemoteTable(true);
modJsList['tabEmployeeTimeEntry'] = new EmployeeTimeEntryAdapter('EmployeeTimeEntry','EmployeeTimeEntry','','');
modJsList['tabEmployeeTimeEntry'].setShowAddNew(false);
modJsList['tabEmployeeTimeEntry'].setAllProjectsAllowed(<?=$allowAllProjects?>);
modJsList['tabEmployeeTimeEntry'].setEmployeeProjects(<?=json_encode($employeeProjects)?>);
var modJs = modJsList['tabEmployeeTimeSheetAll'];
</script>
<div class="modal" id="TimeSheetStatusModel" 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;">Change Timesheet Status</h3>
</div>
<div class="modal-body">
<form id="TimeSheetStatusForm">
<div class="control-group">
<label class="control-label" for="timesheet_status">Timesheet Status</label>
<div class="controls">
<select class="" type="text" id="timesheet_status" name="timesheet_status">
<option value="Approved">Approved</option>
<option value="Pending">Pending</option>
<option value="Rejected">Rejected</option>
<option value="Submitted">Submitted</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" onclick="modJs.changeTimeSheetStatus();">Change Status</button>
<button class="btn" onclick="modJs.closeTimeSheetStatus();">Not Now</button>
</div>
</div>
</div>
</div>
<div class="modal" id="TimeEntryModel" 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;">Time Entry</h3>
</div>
<div class="modal-body" style="max-height:530px;" id="EmployeeTimeEntryForm">
</div>
</div>
</div>
</div>
<?php include APP_BASE_PATH.'footer.php';?>

View File

@@ -0,0 +1,696 @@
/*
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 EmployeeTimeSheetAdapter(endPoint,tab,filter,orderBy) {
this.initAdapter(endPoint,tab,filter,orderBy);
}
EmployeeTimeSheetAdapter.inherits(AdapterBase);
this.currentTimesheetId = null;
this.currentTimesheet = null;
EmployeeTimeSheetAdapter.method('getDataMapping', function() {
return [
"id",
"date_start",
"date_end",
"status"
];
});
EmployeeTimeSheetAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" ,"bVisible":false},
{ "sTitle": "Start Date"},
{ "sTitle": "End Date"},
{ "sTitle": "Status"}
];
});
EmployeeTimeSheetAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden"}],
[ "date_start", {"label":"TimeSheet Start Date","type":"date","validation":""}],
[ "date_end", {"label":"TimeSheet End Date","type":"date","validation":""}],
[ "details", {"label":"Reason","type":"textarea","validation":"none"}]
];
});
EmployeeTimeSheetAdapter.method('preProcessTableData', function(row) {
row[1] = Date.parse(row[1]).toString('MMM d, yyyy (dddd)');
row[2] = Date.parse(row[2]).toString('MMM d, yyyy (dddd)');
return row;
});
EmployeeTimeSheetAdapter.method('renderForm', function(object) {
var formHtml = this.templates['formTemplate'];
var html = "";
$("#"+this.getTableName()+'Form').html(formHtml);
$("#"+this.getTableName()+'Form').show();
$("#"+this.getTableName()).hide();
$('#timesheet_start').html(Date.parse(object.date_start).toString('MMM d, yyyy (dddd)'));
$('#timesheet_end').html(Date.parse(object.date_end).toString('MMM d, yyyy (dddd)'));
this.currentTimesheet = object;
this.getTimeEntries();
});
EmployeeTimeSheetAdapter.method('openTimeEntryDialog', function() {
this.currentTimesheetId = this.currentId;
var obj = modJsList['tabEmployeeTimeEntry'];
$('#TimeEntryModel').modal({
backdrop: 'static',
keyboard: false
});
obj.currentTimesheet = this.currentTimesheet;
obj.renderForm();
obj.timesheetId = this.currentId;
});
EmployeeTimeSheetAdapter.method('closeTimeEntryDialog', function() {
$('#TimeEntryModel').modal('hide');
});
EmployeeTimeSheetAdapter.method('getTimeEntries', function() {
timesheetId = this.currentId;
var sourceMappingJson = JSON.stringify(modJsList['tabEmployeeTimeEntry'].getSourceMapping());
object = {"id":timesheetId,"sm":sourceMappingJson};
var reqJson = JSON.stringify(object);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'getTimeEntriesSuccessCallBack';
callBackData['callBackFail'] = 'getTimeEntriesFailCallBack';
this.customAction('getTimeEntries','modules=time_sheets',reqJson,callBackData);
});
EmployeeTimeSheetAdapter.method('getTimeEntriesSuccessCallBack', function(callBackData) {
var entries = callBackData;
var html = "";
var temp = '<tr><td><img class="tableActionButton" src="_BASE_images/delete.png" style="cursor:pointer;" rel="tooltip" title="Delete" onclick="modJsList[\'tabEmployeeTimeEntry\'].deleteRow(_id_);return false;"></img></td><td>_start_</td><td>_end_</td><td>_duration_</td><td>_project_</td><td>_details_</td>';
for(var i=0;i<entries.length;i++){
try{
var t = temp;
t = t.replace(/_start_/g,Date.parse(entries[i].date_start).toString('MMM d, yyyy [hh:mm tt]'));
t = t.replace(/_end_/g,Date.parse(entries[i].date_end).toString('MMM d, yyyy [hh:mm tt]'));
var mili = Date.parse(entries[i].date_end) - Date.parse(entries[i].date_start);
var minutes = Math.round(mili/60000);
var hourMinutes = (minutes % 60);
var hours = (minutes-hourMinutes)/60;
t = t.replace(/_duration_/g,"Hours ("+hours+") - Min ("+hourMinutes+")");
if(entries[i].project == 'null' || entries[i].project == null || entries[i].project == undefined){
t = t.replace(/_project_/g,"None");
}else{
t = t.replace(/_project_/g,entries[i].project);
}
t = t.replace(/_project_/g,entries[i].project);
t = t.replace(/_details_/g,entries[i].details);
t = t.replace(/_id_/g,entries[i].id);
t = t.replace(/_BASE_/g,this.baseUrl);
html += t;
}catch(e){}
}
$('.timesheet_entries_table_body').html(html);
if(modJs.getTableName() == 'SubEmployeeTimeSheetAll'){
$('#submit_sheet').hide();
$('#add_time_sheet_entry').hide();
}else{
if(this.currentElement.status == 'Approved'){
$('#submit_sheet').hide();
$('#add_time_sheet_entry').hide();
}else{
$('#submit_sheet').show();
$('#add_time_sheet_entry').show();
}
}
});
EmployeeTimeSheetAdapter.method('getTimeEntriesFailCallBack', function(callBackData) {
this.showMessage("Error", "Error occured while getting timesheet entries");
});
EmployeeTimeSheetAdapter.method('createPreviousTimesheet', function(id) {
object = {"id":id};
var reqJson = JSON.stringify(object);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'createPreviousTimesheetSuccessCallBack';
callBackData['callBackFail'] = 'createPreviousTimesheetFailCallBack';
this.customAction('createPreviousTimesheet','modules=time_sheets',reqJson,callBackData);
});
EmployeeTimeSheetAdapter.method('createPreviousTimesheetSuccessCallBack', function(callBackData) {
$('.tooltip').css("display","none");
$('.tooltip').remove();
//this.showMessage("Success", "Previous Timesheet created");
this.get([]);
});
EmployeeTimeSheetAdapter.method('createPreviousTimesheetFailCallBack', function(callBackData) {
this.showMessage("Error", callBackData);
});
EmployeeTimeSheetAdapter.method('changeTimeSheetStatusWithId', function(id, status) {
if(status == "" || status ==null || status == undefined){
this.showMessage("Status Error","Please select a status");
return;
}
object = {"id":id,"status":status};
var reqJson = JSON.stringify(object);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'changeTimeSheetStatusSuccessCallBack';
callBackData['callBackFail'] = 'changeTimeSheetStatusFailCallBack';
this.customAction('changeTimeSheetStatus','modules=time_sheets',reqJson,callBackData);
});
EmployeeTimeSheetAdapter.method('changeTimeSheetStatusSuccessCallBack', function(callBackData) {
this.showMessage("Successful", "Timesheet status changed successfully");
this.get([]);
});
EmployeeTimeSheetAdapter.method('changeTimeSheetStatusFailCallBack', function(callBackData) {
this.showMessage("Error", "Error occured while changing Timesheet status");
});
EmployeeTimeSheetAdapter.method('getActionButtonsHtml', function(id,data) {
var html = '';
if(this.getTableName() == "EmployeeTimeSheetAll"){
html = '<div style="width:80px;"><img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit Timesheet Entries" onclick="modJs.edit(_id_);return false;"></img><img class="tableActionButton" src="_BASE_images/redo.png" style="cursor:pointer;margin-left:15px;" rel="tooltip" title="Create previous time sheet" onclick="modJs.createPreviousTimesheet(_id_);return false;"></img></div>';
}else{
html = '<div style="width:80px;"><img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit Timesheet Entries" onclick="modJs.edit(_id_);return false;"></img></div>';
}
html = html.replace(/_id_/g,id);
html = html.replace(/_BASE_/g,this.baseUrl);
return html;
});
EmployeeTimeSheetAdapter.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": that.getActionButtons,
"aTargets": [that.getDataMapping().length]
}
]
};
return dataTableParams;
});
EmployeeTimeSheetAdapter.method('preProcessRemoteTableData', function(data, cell, id) {
return Date.parse(cell).toString('MMM d, yyyy (dddd)');
});
/*
* Subordinate TimeSheets
*/
function SubEmployeeTimeSheetAdapter(endPoint,tab,filter,orderBy) {
this.initAdapter(endPoint,tab,filter,orderBy);
}
this.timeSheetStatusChangeId = null;
SubEmployeeTimeSheetAdapter.inherits(EmployeeTimeSheetAdapter);
SubEmployeeTimeSheetAdapter.method('getDataMapping', function() {
return [
"id",
"employee",
"date_start",
"date_end",
"status"
];
});
SubEmployeeTimeSheetAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" ,"bVisible":false},
{ "sTitle": "Employee","bSearchable":true},
{ "sTitle": "Start Date","bSearchable":true},
{ "sTitle": "End Date","bSearchable":true},
{ "sTitle": "Status"}
];
});
SubEmployeeTimeSheetAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden"}],
[ "employee", {"label":"Employee","type":"select","allow-null":false,"remote-source":["Employee","id","first_name+last_name"]}],
[ "date_start", {"label":"TimeSheet Start Date","type":"date","validation":""}],
[ "date_end", {"label":"TimeSheet Start Date","type":"date","validation":""}],
[ "details", {"label":"Reason","type":"textarea","validation":"none"}]
];
});
/*
SubEmployeeTimeSheetAdapter.method('get', function(callBackData) {
var that = this;
var sourceMappingJson = JSON.stringify(this.getSourceMapping());
var filterJson = "";
if(this.getFilter() != null){
filterJson = JSON.stringify(this.getFilter());
}
var orderBy = "";
if(this.getOrderBy() != null){
orderBy = this.getOrderBy();
}
var object = {'sm':sourceMappingJson,'ft':filterJson,'ob':orderBy};
var reqJson = JSON.stringify(object);
var callBackData = [];
callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'getCustomSuccessCallBack';
callBackData['callBackFail'] = 'getFailCallBack';
this.customAction('getSubEmployeeTimeSheets','modules=time_sheets',reqJson,callBackData);
});
*/
SubEmployeeTimeSheetAdapter.method('isSubProfileTable', function() {
return true;
});
SubEmployeeTimeSheetAdapter.method('getCustomSuccessCallBack', function(serverData) {
var data = [];
var mapping = this.getDataMapping();
for(var i=0;i<serverData.length;i++){
var row = [];
for(var j=0;j<mapping.length;j++){
row[j] = serverData[i][mapping[j]];
}
data.push(this.preProcessTableData(row));
}
this.tableData = data;
this.createTable(this.getTableName());
$("#"+this.getTableName()+'Form').hide();
$("#"+this.getTableName()).show();
});
SubEmployeeTimeSheetAdapter.method('preProcessTableData', function(row) {
row[2] = Date.parse(row[2]).toString('MMM d, yyyy (dddd)');
row[3] = Date.parse(row[3]).toString('MMM d, yyyy (dddd)');
return row;
});
SubEmployeeTimeSheetAdapter.method('openTimeSheetStatus', function(timeSheetId,status) {
this.currentTimesheetId = timeSheetId;
$('#TimeSheetStatusModel').modal('show');
$('#timesheet_status').val(status);
this.timeSheetStatusChangeId = timeSheetId;
});
SubEmployeeTimeSheetAdapter.method('closeTimeSheetStatus', function() {
$('#TimeSheetStatusModel').modal('hide');
});
SubEmployeeTimeSheetAdapter.method('changeTimeSheetStatus', function() {
var timeSheetStatus = $('#timesheet_status').val();
this.changeTimeSheetStatusWithId(this.timeSheetStatusChangeId,timeSheetStatus);
this.closeTimeSheetStatus();
this.timeSheetStatusChangeId = null;
});
SubEmployeeTimeSheetAdapter.method('getActionButtonsHtml', function(id,data) {
var html;
html = '<div style="width:80px;"><img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit Timesheet Entries" onclick="modJs.edit(_id_);return false;"></img><img class="tableActionButton" src="_BASE_images/run.png" style="cursor:pointer;margin-left:15px;" rel="tooltip" title="Change TimeSheet Status" onclick="modJs.openTimeSheetStatus(_id_,\'_status_\');return false;"></img></div>';
html = html.replace(/_id_/g,id);
html = html.replace(/_BASE_/g,this.baseUrl);
html = html.replace(/_status_/g,data[3]);
return html;
});
SubEmployeeTimeSheetAdapter.method('getCustomTableParams', function() {
var that = this;
var dataTableParams = {
"aoColumnDefs": [
{
"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;
});
/**
* EmployeeTimeEntryAdapter
*/
function EmployeeTimeEntryAdapter(endPoint,tab,filter,orderBy) {
this.initAdapter(endPoint,tab,filter,orderBy);
}
EmployeeTimeEntryAdapter.inherits(AdapterBase);
this.timesheetId = null;
this.currentTimesheet = null;
this.allProjectsAllowed = 1;
this.employeeProjects = [];
EmployeeTimeEntryAdapter.method('getDataMapping', function() {
return [
"id",
"project",
"date_start",
"time_start",
"date_end",
"time_end",
"details"
];
});
EmployeeTimeEntryAdapter.method('getHeaders', function() {
return [
{ "sTitle": "ID" ,"bVisible":false},
{ "sTitle": "Project"},
{ "sTitle": "Start Date"},
{ "sTitle": "Start Time"},
{ "sTitle": "End Date"},
{ "sTitle": "End Time"},
{ "sTitle": "Details"}
];
});
EmployeeTimeEntryAdapter.method('getFormFields', function() {
return [
[ "id", {"label":"ID","type":"hidden"}],
[ "project", {"label":"Project","type":"select2","allow-null":true,"remote-source":["Project","id","name"]}],
//[ "project", {"label":"Project","type":"select","source":[]}],
[ "date_select", {"label":"Date","type":"select","source":[]}],
[ "date_start", {"label":"Start Time","type":"time","validation":""}],
/*[ "time_start", {"label":"Start Time","type":"time"}],*/
[ "date_end", {"label":"End Time","type":"time","validation":""}],
/*[ "time_end", {"label":"End Time","type":"time"}],*/
[ "details", {"label":"Details","type":"textarea","validation":""}]
];
});
/*
EmployeeTimeEntryAdapter.method('renderForm', function(object) {
var formHtml = this.templates['orig_formTemplate'];
formHtml = formHtml.replace(/modJs/g,"modJsList['tabEmployeeTimeEntry']");
var html = "";
var fields = this.getFormFields();
for(var i=0;i<fields.length;i++){
html += this.renderFormField(fields[i]);
}
formHtml = formHtml.replace(/_id_/g,this.getTableName()+"_submit");
formHtml = formHtml.replace(/_fields_/g,html);
$("#"+this.getTableName()+'Form').html(formHtml);
$("#"+this.getTableName()+'Form').show();
$("#"+this.getTableName()+'Form .datefield').datepicker({'viewMode':2});
$("#"+this.getTableName()+'Form .timefield').timepicker({ 'step': 15 });
if(object != undefined && object != null){
this.fillForm(object);
}
});
*/
EmployeeTimeEntryAdapter.method('getDates', function(startDate, stopDate) {
var dateArray = new Array();
var currentDate = startDate;
while (currentDate <= stopDate) {
dateArray.push( new Date (currentDate) );
currentDate = currentDate.add({ days: 1 });
}
return dateArray;
});
EmployeeTimeEntryAdapter.method('renderForm', function(object) {
var formHtml = this.getCustomTemplate('time_entry_form.html');
formHtml = formHtml.replace(/modJs/g,"modJsList['tabEmployeeTimeEntry']");
var html = "";
var fields = this.getFormFields();
for(var i=0;i<fields.length;i++){
var metaField = this.getMetaFieldForRendering(fields[i][0]);
if(metaField == "" || metaField == undefined){
html += this.renderFormField(fields[i]);
}else{
var metaVal = object[metaField];
if(metaVal != '' && metaVal != null && metaVal != undefined && metaVal.trim() != ''){
html += this.renderFormField(JSON.parse(metaVal));
}else{
html += this.renderFormField(fields[i]);
}
}
}
//append dates
var dateStart = new Date(this.currentTimesheet.date_start.replace(" ","T"));
var dateStop = new Date(this.currentTimesheet.date_end.replace(" ","T"));
var datesArray = this.getDates(dateStart, dateStop);
var optionList = "";
for(var i=0; i<datesArray.length; i++){
optionList += '<option value="'+datesArray[i].toString("yyyy-MM-dd")+'">'+datesArray[i].toString("d-MMM-yyyy")+'</option>';
}
formHtml = formHtml.replace(/_id_/g,this.getTableName()+"_submit");
formHtml = formHtml.replace(/_fields_/g,html);
$("#"+this.getTableName()+'Form').html(formHtml);
$("#"+this.getTableName()+'Form').show();
$("#"+this.getTableName()).hide();
$("#"+this.getTableName()+'Form .datefield').datepicker({'viewMode':2});
$("#"+this.getTableName()+'Form .datetimefield').datetimepicker({
language: 'en'
});
$("#"+this.getTableName()+'Form .timefield').datetimepicker({
language: 'en',
pickDate: false
});
$("#"+this.getTableName()+'Form .select2Field').select2();
$("#date_select").html(optionList);
var projectOptionList = "";
projectOptionList += '<option value="NULL">None</option>';
if(this.allProjectsAllowed == 0){
for(var i=0;i<this.employeeProjects.length;i++){
projectOptionList += '<option value="'+this.employeeProjects[i].project+'">'+this.employeeProjects[i].name+'</option>';
}
}else{
for(var i=0;i<this.employeeProjects.length;i++){
projectOptionList += '<option value="'+this.employeeProjects[i].id+'">'+this.employeeProjects[i].name+'</option>';
}
}
$("#project").html(projectOptionList);
if(object != undefined && object != null){
this.fillForm(object);
}
});
EmployeeTimeEntryAdapter.method('cancel', function() {
$('#TimeEntryModel').modal('hide');
});
EmployeeTimeEntryAdapter.method('setAllProjectsAllowed', function(allProjectsAllowed) {
this.allProjectsAllowed = allProjectsAllowed;
});
EmployeeTimeEntryAdapter.method('setEmployeeProjects', function(employeeProjects) {
this.employeeProjects = employeeProjects;
});
/*
EmployeeTimeEntryAdapter.method('save', function() {
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
if(validator.checkValues()){
var params = validator.getFormParameters();
params.date_end = params.date_start;
$(params).attr('timesheet',this.timesheetId);
if(params.time_start.indexOf("am") != -1 && params.time_start.indexOf("12:") != -1){
params.time_start = params.time_start.replace("12:","00:");
}
if(params.time_end.indexOf("am") != -1 && params.time_end.indexOf("12:") != -1){
params.time_end = params.time_end.replace("12:","00:");
}
params.date_start = Date.parse(params.date_start+" "+params.time_start.replace('am',' AM').replace('pm',' PM')).toString("yyyy-MM-dd HH:mm:ss");
params.date_end = Date.parse(params.date_end+" "+params.time_end.replace('am',' AM').replace('pm',' PM')).toString("yyyy-MM-dd HH:mm:ss");
var msg = this.doCustomValidation(params);
if(msg == null){
var id = $('#'+this.getTableName()+"_submit #id").val();
if(id != null && id != undefined && id != ""){
$(params).attr('id',id);
}
this.add(params,[]);
this.cancel();
}else{
$("#"+this.getTableName()+'Form .label').html(msg);
$("#"+this.getTableName()+'Form .label').show();
}
}
});
*/
EmployeeTimeEntryAdapter.method('save', function() {
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
if(validator.checkValues()){
var params = validator.getFormParameters();
$(params).attr('timesheet',this.timesheetId);
params.time_start = params.date_start;
params.time_end = params.date_end;
params.date_start = params.date_select+" "+params.date_start;
params.date_end = params.date_select+" "+params.date_end;
var msg = this.doCustomValidation(params);
if(msg == null){
var id = $('#'+this.getTableName()+"_submit #id").val();
if(id != null && id != undefined && id != ""){
$(params).attr('id',id);
}
this.add(params,[]);
this.cancel();
}else{
$("#"+this.getTableName()+'Form .label').html(msg);
$("#"+this.getTableName()+'Form .label').show();
}
}
});
EmployeeTimeEntryAdapter.method('doCustomValidation', function(params) {
var st = Date.parse(params.date_start.replace(" ","T"));
var et = Date.parse(params.date_end.replace(" ","T"));
if(st.compareTo(et) != -1){
return "Start time should be less than End time";
}
/*
var sd = Date.parse(this.currentTimesheet.date_start);
var ed = Date.parse(this.currentTimesheet.date_end).addDays(1);
if(sd.compareTo(et) != -1 || sd.compareTo(st) > 0 || st.compareTo(ed) != -1 || et.compareTo(ed) != -1){
return "Start time and end time shoud be with in " + sd.toString('MMM d, yyyy (dddd)') + " and " + ed.toString('MMM d, yyyy (dddd)');
}
*/
return null;
});
EmployeeTimeEntryAdapter.method('addSuccessCallBack', function(callBackData,serverData) {
this.get(callBackData);
modJs.getTimeEntries();
});
EmployeeTimeEntryAdapter.method('deleteRow', function(id) {
this.deleteObj(id,[]);
});
EmployeeTimeEntryAdapter.method('deleteSuccessCallBack', function(callBackData,serverData) {
modJs.getTimeEntries();
});

View File

@@ -0,0 +1,11 @@
{
"label":"Time Sheets",
"menu":"Time Management",
"order":"3",
"icon":"fa-check-circle-o",
"user_levels":["Admin","Manager","Employee"],
"permissions":
{
}
}

View File

@@ -0,0 +1,23 @@
<form class="form-horizontal" id="timesheet_entries_cont">
<span style="font-size:15px;font-weight:bold;color:#999;margin-left:10px;">
Timesheet From <span id="timesheet_start"></span> to <span id="timesheet_end"></span>
</span>
<table class="table table-condensed table-bordered table-striped" id="timesheet_entries" style="width:100%;font-size:12px;margin-left:5px;">
<thead>
<tr>
<th></th>
<th>Start</th>
<th>End</th>
<th>Duration</th>
<th>Project</th>
<th>Details</th>
</tr>
</thead>
<tbody id="timesheet_entries_table_body" class="timesheet_entries_table_body">
</tbody>
</table>
<div class="control-group">
<button id="add_time_sheet_entry" style="margin-left:5px;display:none;" onclick="try{modJs.openTimeEntryDialog()}catch(e){};return false;" class="btn"><span class="icon-plus-sign"></span> Add Time Entry</button>
<button id="submit_sheet" onclick="modJs.changeTimeSheetStatusWithId(modJs.currentId,'Submitted');return false;" class="btn" style="display:none;"><span class="icon-ok"></span> Submit Timesheet</button>
</div>
</form>