Fix zero time issue when updating time sheets

This commit is contained in:
gamonoid
2017-10-08 16:53:33 +02:00
parent 10403e280c
commit ddb46d8443

View File

@@ -16,7 +16,7 @@ along with iCE Hrm. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------ ------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd] Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah) Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/ */
@@ -79,9 +79,9 @@ EmployeeTimeSheetAdapter.method('renderForm', function(object) {
$('.timesheet_start').html(Date.parse(object.date_start).toString('MMM d, yyyy (dddd)')); $('.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)')); $('.timesheet_end').html(Date.parse(object.date_end).toString('MMM d, yyyy (dddd)'));
this.currentTimesheet = object; this.currentTimesheet = object;
this.getTimeEntries(); this.getTimeEntries();
var st = Date.parse(object.date_start); var st = Date.parse(object.date_start);
@@ -127,9 +127,9 @@ EmployeeTimeSheetAdapter.method('renderForm', function(object) {
}); });
$('#EmployeeTimesheetBlock').fullCalendar('gotoDate', st); $('#EmployeeTimesheetBlock').fullCalendar('gotoDate', st);
$('.fc-toolbar').hide(); $('.fc-toolbar').hide();
}); });
@@ -219,7 +219,7 @@ EmployeeTimeSheetAdapter.method('openTimeEntryDialog', function(object) {
obj.currentTimesheet = this.currentTimesheet; obj.currentTimesheet = this.currentTimesheet;
obj.renderForm(object); obj.renderForm(object);
obj.timesheetId = this.currentId; obj.timesheetId = this.currentId;
}); });
EmployeeTimeSheetAdapter.method('closeTimeEntryDialog', function() { EmployeeTimeSheetAdapter.method('closeTimeEntryDialog', function() {
@@ -231,14 +231,14 @@ EmployeeTimeSheetAdapter.method('getTimeEntries', function() {
timesheetId = this.currentId; timesheetId = this.currentId;
var sourceMappingJson = JSON.stringify(modJsList['tabEmployeeTimeEntry'].getSourceMapping()); var sourceMappingJson = JSON.stringify(modJsList['tabEmployeeTimeEntry'].getSourceMapping());
object = {"id":timesheetId,"sm":sourceMappingJson}; object = {"id":timesheetId,"sm":sourceMappingJson};
var reqJson = JSON.stringify(object); var reqJson = JSON.stringify(object);
var callBackData = []; var callBackData = [];
callBackData['callBackData'] = []; callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'getTimeEntriesSuccessCallBack'; callBackData['callBackSuccess'] = 'getTimeEntriesSuccessCallBack';
callBackData['callBackFail'] = 'getTimeEntriesFailCallBack'; callBackData['callBackFail'] = 'getTimeEntriesFailCallBack';
this.customAction('getTimeEntries','modules=time_sheets',reqJson,callBackData); this.customAction('getTimeEntries','modules=time_sheets',reqJson,callBackData);
}); });
@@ -246,18 +246,18 @@ EmployeeTimeSheetAdapter.method('getTimeEntriesSuccessCallBack', function(callBa
var entries = callBackData; var entries = callBackData;
var html = ""; 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>'; 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++){ for(var i=0;i<entries.length;i++){
try{ try{
var t = temp; var t = temp;
t = t.replace(/_start_/g,Date.parse(entries[i].date_start).toString('MMM d, yyyy [hh:mm tt]')); 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]')); 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 mili = Date.parse(entries[i].date_end) - Date.parse(entries[i].date_start);
var minutes = Math.round(mili/60000); var minutes = Math.round(mili/60000);
var hourMinutes = (minutes % 60); var hourMinutes = (minutes % 60);
var hours = (minutes-hourMinutes)/60; var hours = (minutes-hourMinutes)/60;
t = t.replace(/_duration_/g,"Hours ("+hours+") - Min ("+hourMinutes+")"); t = t.replace(/_duration_/g,"Hours ("+hours+") - Min ("+hourMinutes+")");
if(entries[i].project == 'null' || entries[i].project == null || entries[i].project == undefined){ if(entries[i].project == 'null' || entries[i].project == null || entries[i].project == undefined){
t = t.replace(/_project_/g,"None"); t = t.replace(/_project_/g,"None");
@@ -271,7 +271,7 @@ EmployeeTimeSheetAdapter.method('getTimeEntriesSuccessCallBack', function(callBa
html += t; html += t;
}catch(e){} }catch(e){}
} }
$('.timesheet_entries_table_body').html(html); $('.timesheet_entries_table_body').html(html);
if(modJs.getTableName() == 'SubEmployeeTimeSheetAll' || this.needStartEndTime+'' == '0'){ if(modJs.getTableName() == 'SubEmployeeTimeSheetAll' || this.needStartEndTime+'' == '0'){
$('.submit_sheet').hide(); $('.submit_sheet').hide();
@@ -297,14 +297,14 @@ EmployeeTimeSheetAdapter.method('getTimeEntriesFailCallBack', function(callBackD
EmployeeTimeSheetAdapter.method('createPreviousTimesheet', function(id) { EmployeeTimeSheetAdapter.method('createPreviousTimesheet', function(id) {
object = {"id":id}; object = {"id":id};
var reqJson = JSON.stringify(object); var reqJson = JSON.stringify(object);
var callBackData = []; var callBackData = [];
callBackData['callBackData'] = []; callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'createPreviousTimesheetSuccessCallBack'; callBackData['callBackSuccess'] = 'createPreviousTimesheetSuccessCallBack';
callBackData['callBackFail'] = 'createPreviousTimesheetFailCallBack'; callBackData['callBackFail'] = 'createPreviousTimesheetFailCallBack';
this.customAction('createPreviousTimesheet','modules=time_sheets',reqJson,callBackData); this.customAction('createPreviousTimesheet','modules=time_sheets',reqJson,callBackData);
}); });
@@ -320,21 +320,21 @@ EmployeeTimeSheetAdapter.method('createPreviousTimesheetFailCallBack', function(
}); });
EmployeeTimeSheetAdapter.method('changeTimeSheetStatusWithId', function(id, status) { EmployeeTimeSheetAdapter.method('changeTimeSheetStatusWithId', function(id, status) {
if(status == "" || status ==null || status == undefined){ if(status == "" || status ==null || status == undefined){
this.showMessage("Status Error","Please select a status"); this.showMessage("Status Error","Please select a status");
return; return;
} }
object = {"id":id,"status":status}; object = {"id":id,"status":status};
var reqJson = JSON.stringify(object); var reqJson = JSON.stringify(object);
var callBackData = []; var callBackData = [];
callBackData['callBackData'] = []; callBackData['callBackData'] = [];
callBackData['callBackSuccess'] = 'changeTimeSheetStatusSuccessCallBack'; callBackData['callBackSuccess'] = 'changeTimeSheetStatusSuccessCallBack';
callBackData['callBackFail'] = 'changeTimeSheetStatusFailCallBack'; callBackData['callBackFail'] = 'changeTimeSheetStatusFailCallBack';
this.customAction('changeTimeSheetStatus','modules=time_sheets',reqJson,callBackData); this.customAction('changeTimeSheetStatus','modules=time_sheets',reqJson,callBackData);
}); });
@@ -380,7 +380,7 @@ EmployeeTimeSheetAdapter.method('getActionButtonsHtml', function(id,data) {
EmployeeTimeSheetAdapter.method('getCustomTableParams', function() { EmployeeTimeSheetAdapter.method('getCustomTableParams', function() {
var that = this; var that = this;
var dataTableParams = { var dataTableParams = {
"aoColumnDefs": [ "aoColumnDefs": [
{ {
"fnRender": function(data, cell){ "fnRender": function(data, cell){
return that.preProcessRemoteTableData(data, cell, 1) return that.preProcessRemoteTableData(data, cell, 1)
@@ -464,13 +464,13 @@ SubEmployeeTimeSheetAdapter.method('getCustomSuccessCallBack', function(serverDa
} }
data.push(this.preProcessTableData(row)); data.push(this.preProcessTableData(row));
} }
this.tableData = data; this.tableData = data;
this.createTable(this.getTableName()); this.createTable(this.getTableName());
$("#"+this.getTableName()+'Form').hide(); $("#"+this.getTableName()+'Form').hide();
$("#"+this.getTableName()).show(); $("#"+this.getTableName()).show();
}); });
SubEmployeeTimeSheetAdapter.method('preProcessTableData', function(row) { SubEmployeeTimeSheetAdapter.method('preProcessTableData', function(row) {
@@ -492,9 +492,9 @@ SubEmployeeTimeSheetAdapter.method('closeTimeSheetStatus', function() {
SubEmployeeTimeSheetAdapter.method('changeTimeSheetStatus', function() { SubEmployeeTimeSheetAdapter.method('changeTimeSheetStatus', function() {
var timeSheetStatus = $('#timesheet_status').val(); var timeSheetStatus = $('#timesheet_status').val();
this.changeTimeSheetStatusWithId(this.timeSheetStatusChangeId,timeSheetStatus); this.changeTimeSheetStatusWithId(this.timeSheetStatusChangeId,timeSheetStatus);
this.closeTimeSheetStatus(); this.closeTimeSheetStatus();
this.timeSheetStatusChangeId = null; this.timeSheetStatusChangeId = null;
}); });
@@ -521,7 +521,7 @@ SubEmployeeTimeSheetAdapter.method('getActionButtonsHtml', function(id,data) {
'</div>'; '</div>';
} }
html = html.replace(/_id_/g,id); html = html.replace(/_id_/g,id);
html = html.replace(/_BASE_/g,this.baseUrl); html = html.replace(/_BASE_/g,this.baseUrl);
html = html.replace(/_sdate_/g,data[1]); html = html.replace(/_sdate_/g,data[1]);
@@ -534,7 +534,7 @@ SubEmployeeTimeSheetAdapter.method('getActionButtonsHtml', function(id,data) {
SubEmployeeTimeSheetAdapter.method('getCustomTableParams', function() { SubEmployeeTimeSheetAdapter.method('getCustomTableParams', function() {
var that = this; var that = this;
var dataTableParams = { var dataTableParams = {
"aoColumnDefs": [ "aoColumnDefs": [
{ {
"fnRender": function(data, cell){ "fnRender": function(data, cell){
return that.preProcessRemoteTableData(data, cell, 2) return that.preProcessRemoteTableData(data, cell, 2)
@@ -615,7 +615,7 @@ EmployeeTimeEntryAdapter.method('getFormFields', function() {
EmployeeTimeEntryAdapter.method('getDates', function(startDate, stopDate) { EmployeeTimeEntryAdapter.method('getDates', function(startDate, stopDate) {
var dateArray = new Array(); var dateArray = new Array();
var currentDate = startDate; var currentDate = startDate;
while (currentDate <= stopDate) { while (currentDate <= stopDate) {
@@ -631,7 +631,7 @@ EmployeeTimeEntryAdapter.method('renderForm', function(object) {
formHtml = formHtml.replace(/modJs/g,"modJsList['tabEmployeeTimeEntry']"); formHtml = formHtml.replace(/modJs/g,"modJsList['tabEmployeeTimeEntry']");
var html = ""; var html = "";
var fields = this.getFormFields(); var fields = this.getFormFields();
for(var i=0;i<fields.length;i++){ for(var i=0;i<fields.length;i++){
var metaField = this.getMetaFieldForRendering(fields[i][0]); var metaField = this.getMetaFieldForRendering(fields[i][0]);
if(metaField == "" || metaField == undefined){ if(metaField == "" || metaField == undefined){
@@ -644,32 +644,32 @@ EmployeeTimeEntryAdapter.method('renderForm', function(object) {
html += this.renderFormField(fields[i]); html += this.renderFormField(fields[i]);
} }
} }
} }
//append dates //append dates
//var dateStart = new Date(this.currentTimesheet.date_start); //var dateStart = new Date(this.currentTimesheet.date_start);
//var dateStop = new Date(this.currentTimesheet.date_end); //var dateStop = new Date(this.currentTimesheet.date_end);
//var datesArray = this.getDates(dateStart, dateStop); //var datesArray = this.getDates(dateStart, dateStop);
var optionList = ""; var optionList = "";
for(var i=0; i<this.currentTimesheet.days.length; i++){ for(var i=0; i<this.currentTimesheet.days.length; i++){
var k = this.currentTimesheet.days[i]; var k = this.currentTimesheet.days[i];
//optionList += '<option value="'+timeUtils.getMySQLFormatDate(k)+'">'+k.toUTCString().slice(0, -13)+'</option>'; //optionList += '<option value="'+timeUtils.getMySQLFormatDate(k)+'">'+k.toUTCString().slice(0, -13)+'</option>';
optionList += '<option value="'+k[0]+'">'+k[1]+'</option>'; optionList += '<option value="'+k[0]+'">'+k[1]+'</option>';
} }
formHtml = formHtml.replace(/_id_/g,this.getTableName()+"_submit"); formHtml = formHtml.replace(/_id_/g,this.getTableName()+"_submit");
formHtml = formHtml.replace(/_fields_/g,html); formHtml = formHtml.replace(/_fields_/g,html);
$("#"+this.getTableName()+'Form').html(formHtml); $("#"+this.getTableName()+'Form').html(formHtml);
$("#"+this.getTableName()+'Form').show(); $("#"+this.getTableName()+'Form').show();
$("#"+this.getTableName()).hide(); $("#"+this.getTableName()).hide();
$("#"+this.getTableName()+'Form .datefield').datepicker({'viewMode':2}); $("#"+this.getTableName()+'Form .datefield').datepicker({'viewMode':2});
$("#"+this.getTableName()+'Form .datetimefield').datetimepicker({ $("#"+this.getTableName()+'Form .datetimefield').datetimepicker({
language: 'en' language: 'en'
@@ -678,9 +678,9 @@ EmployeeTimeEntryAdapter.method('renderForm', function(object) {
language: 'en', language: 'en',
pickDate: false pickDate: false
}); });
$("#"+this.getTableName()+'Form .select2Field').select2(); $("#"+this.getTableName()+'Form .select2Field').select2();
$("#date_select").html(optionList); $("#date_select").html(optionList);
@@ -726,20 +726,20 @@ EmployeeTimeEntryAdapter.method('setEmployeeProjects', function(employeeProjects
EmployeeTimeEntryAdapter.method('save', function() { EmployeeTimeEntryAdapter.method('save', function() {
var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"}); var validator = new FormValidation(this.getTableName()+"_submit",true,{'ShowPopup':false,"LabelErrorClass":"error"});
if(validator.checkValues()){ if(validator.checkValues()){
var params = validator.getFormParameters(); var params = validator.getFormParameters();
$(params).attr('timesheet',this.timesheetId); $(params).attr('timesheet',this.timesheetId);
params.time_start = params.date_start; params.time_start = params.date_start;
params.time_end = params.date_end; params.time_end = params.date_end;
params.date_start = params.date_select+" "+params.date_start; params.date_start = params.date_select+" "+params.date_start;
params.date_end = params.date_select+" "+params.date_end; params.date_end = params.date_select+" "+params.date_end;
var msg = this.doCustomValidation(params); var msg = this.doCustomValidation(params);
if(msg == null){ if(msg == null){
var id = $('#'+this.getTableName()+"_submit #id").val(); var id = $('#'+this.getTableName()+"_submit #id").val();
if(id != null && id != undefined && id != ""){ if(id != null && id != undefined && id != ""){
@@ -751,7 +751,7 @@ EmployeeTimeEntryAdapter.method('save', function() {
$("#"+this.getTableName()+'Form .label').html(msg); $("#"+this.getTableName()+'Form .label').html(msg);
$("#"+this.getTableName()+'Form .label').show(); $("#"+this.getTableName()+'Form .label').show();
} }
} }
}); });
@@ -764,7 +764,7 @@ EmployeeTimeEntryAdapter.method('doCustomValidation', function(params) {
/* /*
var sd = Date.parse(this.currentTimesheet.date_start); var sd = Date.parse(this.currentTimesheet.date_start);
var ed = Date.parse(this.currentTimesheet.date_end).addDays(1); 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){ 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 "Start time and end time shoud be with in " + sd.toString('MMM d, yyyy (dddd)') + " and " + ed.toString('MMM d, yyyy (dddd)');
} }
@@ -779,7 +779,7 @@ EmployeeTimeEntryAdapter.method('addSuccessCallBack', function(callBackData,serv
EmployeeTimeEntryAdapter.method('deleteRow', function(id) { EmployeeTimeEntryAdapter.method('deleteRow', function(id) {
this.deleteObj(id,[]); this.deleteObj(id,[]);
}); });
EmployeeTimeEntryAdapter.method('deleteSuccessCallBack', function(callBackData,serverData) { EmployeeTimeEntryAdapter.method('deleteSuccessCallBack', function(callBackData,serverData) {
@@ -807,10 +807,10 @@ QtsheetAdapter.method('validateCellValue', function(element, evt, newValue) {
return false; return false;
} }
var val = parseFloat(newValue); var val = parseFloat(newValue);
if(val <= 0 || val > 24){ if(val < 0 || val > 24){
return false; return false;
} }
//Update total //Update total
//Find current column number //Find current column number
//Adding 2 because nth child is based on 1 and we are adding a virtual column for row names //Adding 2 because nth child is based on 1 and we are adding a virtual column for row names
@@ -845,7 +845,7 @@ QtsheetAdapter.method('validateCellValue', function(element, evt, newValue) {
if(columnTotal > 24){ if(columnTotal > 24){
return false; return false;
} }
modJs.addCellDataUpdate(element.data('colId'),element.data('rowId'),newValue); modJs.addCellDataUpdate(element.data('colId'),element.data('rowId'),newValue);
return true; return true;
}); });