$(function () { InitEnginehoursGridData(); InitMostRecentEnginehoursGridData(); InitEnginehoursHisGridData(); }); var grid_enginehoursdt; var grid_enginehoursmostrecentdt; var grid_enginehourshisdt; var isCalampEH = false; var isPedigreeEH = false; var isOEMDD2EH = false; var primarydatadourcenameEH; var primarydatadourceEH; function ShowEngineHours(data) { var rows = []; isCalampEH = false; isPedigreeEH = false; isOEMDD2EH = false; primarydatadourcenameEH = undefined; primarydatadourceEH = undefined; for (var i = 0; i < data.length; i++) { var r = data[i]; for (var j in r) { if (j === "IsPrimary") r[j] = r[j] === true ? "Yes" : ""; else if (j === "UOM") r[j] = "Hour"; } r.Hours = r.Hours.toFixed(2); r.Corrected = r.Corrected.toFixed(2); var fr = { Values: r }; rows.push(fr); if (r.DataSource.toLowerCase() == "calamp" && r.IsPrimary.toLowerCase() == "yes") isCalampEH = true; else if (r.DataSource.toLowerCase() == "pedigree") { if (r.IsPrimary.toLowerCase() == "yes" && r.SubSource.toLowerCase() != "totalenginehours")//10471 isPedigreeEH = true; if (r.SubSource.toLowerCase() == "totalenginehours") r.DataSourceName = "HOS"; } else if (r.DataSource.toLowerCase() == "oemdd2" && r.IsPrimary.toLowerCase() == "yes") isOEMDD2EH = true; if (r.IsPrimary.toLowerCase() == "yes") { primarydatadourcenameEH = r.DataSourceName; primarydatadourceEH = r.DataSource; } } grid_enginehoursdt.sortIndex = 0; grid_enginehoursdt.sortDirection = -1; grid_enginehoursdt.setData(rows); $("#enginehourslist").css("height", autoheight(grid_enginehoursdt)); grid_enginehoursdt && grid_enginehoursdt.resize(); if ((IsSupperAdmin || isAllowed) && (isCalampEH || isPedigreeEH || isOEMDD2EH)) { $('#btnenginehoursadjust').css("display", ''); $('#btnenginehourshistory').css("display", ''); } else { $('#btnenginehoursadjust').css("display", 'none'); $('#btnenginehourshistory').css("display", 'none'); } if (primarydatadourcenameEH) { $('#span_adjustenginehours').text(primarydatadourcenameEH); $('#span_addenginehours').text(primarydatadourcenameEH); } else { $('#span_adjustenginehours').text(GetTextByKey("P_MA_EMPTY", 'empty')); $('#span_addenginehours').text(GetTextByKey("P_MA_EMPTY", 'empty')); } } function InitEnginehoursGridData() { grid_enginehoursdt = new GridView('#enginehourslist'); grid_enginehoursdt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'IsPrimary', caption: GetTextByKey("P_MA_ISPRIMARY", "Is Primary"), valueIndex: 'IsPrimary', css: { 'width': 80, 'text-align': 'left' } }, { name: 'DataSourceName', caption: GetTextByKey("P_MA_DATASOURCE", "Data Source"), valueIndex: 'DataSourceName', css: { 'width': 120, 'text-align': 'left' } }, { name: 'Hours', caption: GetTextByKey("P_MA_ENGINEHOURS", "Engine Hours"), valueIndex: 'Hours', css: { 'width': 90, 'text-align': 'left' } }, { name: 'Corrected', caption: GetTextByKey("P_MA_ADJUSTED", "Adjusted"), valueIndex: 'Corrected', css: { 'width': 75, 'text-align': 'left' } }, { name: 'UOM', caption: GetTextByKey("P_MA_UNITS", "Units"), valueIndex: 'UOM', css: { 'width': 60, 'text-align': 'left' } }, { name: 'ReceivedDate', caption: GetTextByKey("P_MA_RECEIVEDDATE", "Received Date"), valueIndex: 'ReceivedDateStr', css: { 'width': 130, 'text-align': 'left' } }, { name: 'SetPrmary', caption: "", css: { 'width': 100, 'text-align': 'left' } } ]; var columns = []; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = false; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; if (list_columns[hd].type) { col.type = list_columns[hd].type; } if (col.name === "SetPrmary") { col.isurl = true; col.text = GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'); col.events = { onclick: function () { openSetPrimary(1, this); } }; col.classFilter = function (e) { return "icon-col"; }; col.styleFilter = function (e) { return { display: e.IsPrimary === "Yes" || (!IsSupperAdmin && !isAllowed) ? 'none' : '' }; }; col.attrs = { 'title': GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary') }; col.resizable = false; } columns.push(col); } grid_enginehoursdt.canMultiSelect = false; grid_enginehoursdt.columns = columns; grid_enginehoursdt.init(); grid_enginehoursdt.selectedrowchanged = function (rowindex) { var rowdata = grid_enginehoursdt.source[rowindex]; if (rowdata) { } } } function InitMostRecentEnginehoursGridData() { grid_enginehoursmostrecentdt = new GridView('#enginehoursmostrecent'); grid_enginehoursmostrecentdt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'DeviceAirId', caption: GetTextByKey("P_MA_DEVICEAIRID", "Device Air ID"), valueIndex: 'DeviceAirId', css: { 'width': 140, 'text-align': 'left' } }, { name: 'DeviceSN', caption: GetTextByKey("P_MA_DEVICESN", "Device SN"), valueIndex: 'DeviceSN', css: { 'width': 140, 'text-align': 'left' } }, { name: 'SN', caption: GetTextByKey("P_MA_SN", "SN"), valueIndex: 'SN', css: { 'width': 140, 'text-align': 'left' } }, { name: 'AsofTime', caption: GetTextByKey("P_MA_EVENTDATEUTC", "Event Date(UTC)"), valueIndex: 'EventTimeText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'AsofTimeLocal', caption: GetTextByKey("P_MA_EVENTDATE", "Event Date"), valueIndex: 'EventTimeLocalText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'VBUS', caption: GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)"), valueIndex: 'VBUS', css: { 'width': 110, 'text-align': 'right' } }, { name: 'VBUS_Calc', caption: GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)"), valueIndex: 'VBUS_Calc', css: { 'width': 120, 'text-align': 'right' } }, { name: 'Gps', caption: GetTextByKey("P_MA_GPSRAW", "GPS(Raw)"), valueIndex: 'Gps', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Gps_Calc', caption: GetTextByKey("P_MA_GPSCALC", "GPS(Calc)"), valueIndex: 'Gps_Calc', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Raw', caption: GetTextByKey("P_MA_RAW", "Raw"), valueIndex: 'Raw', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Calculated', caption: GetTextByKey("P_MA_CALCULATED", "Calculated"), valueIndex: 'Calculated', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Unit', caption: GetTextByKey("P_MA_UNIT", "Unit"), valueIndex: 'UOM', css: { 'width': 60, 'text-align': 'right' } } ]; var columns = []; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = false; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; if (list_columns[hd].type) { col.type = list_columns[hd].type; } columns.push(col); } grid_enginehoursmostrecentdt.canMultiSelect = false; grid_enginehoursmostrecentdt.columns = columns; grid_enginehoursmostrecentdt.init(); } function InitEnginehoursHisGridData() { grid_enginehourshisdt = new GridView('#enginehourshislist'); grid_enginehourshisdt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'DeviceAirId', caption: GetTextByKey("P_MA_DEVICEAIRID", "Device Air ID"), valueIndex: 'DeviceAirId', css: { 'width': 140, 'text-align': 'left' } }, { name: 'DeviceSN', caption: GetTextByKey("P_MA_DEVICESN", "Device SN"), valueIndex: 'DeviceSN', css: { 'width': 140, 'text-align': 'left' } }, { name: 'SN', caption: GetTextByKey("P_MA_SN", "SN"), valueIndex: 'SN', css: { 'width': 140, 'text-align': 'left' } }, { name: 'AsofTime', caption: GetTextByKey("P_MA_EVENTDATEUTC", "Event Date(UTC)"), valueIndex: 'EventTimeText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'AsofTimeLocal', caption: GetTextByKey("P_MA_EVENTDATE", "Event Date"), valueIndex: 'EventTimeLocalText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'VBUS', caption: GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)"), valueIndex: 'VBUS', css: { 'width': 110, 'text-align': 'right' } }, { name: 'VBUS_Calc', caption: GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)"), valueIndex: 'VBUS_Calc', css: { 'width': 120, 'text-align': 'right' } }, { name: 'Gps', caption: GetTextByKey("P_MA_GPSRAW", "GPS(Raw)"), valueIndex: 'Gps', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Gps_Calc', caption: GetTextByKey("P_MA_GPSCALC", "GPS(Calc)"), valueIndex: 'Gps_Calc', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Raw', caption: GetTextByKey("P_MA_RAW", "Raw"), valueIndex: 'Raw', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Calculated', caption: GetTextByKey("P_MA_CALCULATED", "Calculated"), valueIndex: 'Calculated', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Unit', caption: GetTextByKey("P_MA_UNIT", "Unit"), valueIndex: 'UOM', css: { 'width': 60, 'text-align': 'right' } } ]; var columns = []; // head for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = false; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; if (list_columns[hd].type) { col.type = list_columns[hd].type; } columns.push(col); } grid_enginehourshisdt.canMultiSelect = false; grid_enginehourshisdt.columns = columns; grid_enginehourshisdt.init(); grid_enginehourshisdt.selectedrowchanged = function (rowindex) { var rowdata = grid_enginehourshisdt.source[rowindex]; if (rowdata) { } } } function getEnineHours() { showLoading(); grid_enginehoursdt.setData([]); devicerequest("GetAssetCurrentEngineHours", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowEngineHours(data); }, function (err) { hideLoading(); }); } function getEngineHoursHis() { grid_enginehoursmostrecentdt.setData([]); grid_enginehourshisdt.setData([]); showLoading(); var methodname = "GetCalampEngineHoursHistory"; if (isPedigreeEH) methodname = "GetPedigreeEngineHoursHistory"; if (isOEMDD2EH) methodname = "GetOEMDD2EngineHoursHistory"; devicerequest(methodname, contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } //ShowEngineHoursHis(data); ShowMostRecentEngineHours(data); }, function (err) { hideLoading(); }); } function getEngineHoursHisPreview() { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'EngineHours': $('#dialogenginehours_enginehours').val(), 'EngineHoursDate': $('#dialogenginehours_date').val(), 'Notes': $('#dialogenginehours_Notes').val() }; var alerttitle = GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours'); var enginehourstxt = GetTextByKey("P_MA_ENGINEHOURS", "Engine Hours"); if (item.EngineHours !== "") { if (isNaN(item.EngineHours)) { showAlert(GetTextByKey("P_MA_FORMATERROR", '{0} format error.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } else { if (item.EngineHours <= 0) { showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0", '{0} must be greater than 0.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } if (item.EngineHoursDate === "") { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } var offset = $('#dialogadjust_enginehourstimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogenginehours_timehour').val(); var minute = $('#dialogenginehours_timeminute').val(); item.EngineHoursDate = item.EngineHoursDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; CheckEngineHourMinimumTime(item, "preview"); } function GetCalampEngineHoursHistoryPreview(item) { grid_enginehourshisdt.setData([]); showLoading(); var param = JSON.stringify(item); param = htmlencode(param); var methodname = "GetCalampEngineHoursHistoryPreview"; if (isPedigreeEH) methodname = "GetPedigreeEngineHoursHistoryPreview"; if (isOEMDD2EH) methodname = "GetOEMDD2EngineHoursHistoryPreview"; devicerequest(methodname, param, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowEngineHoursHis(data); ShowMostRecentEngineHoursPreview(data); }, function (err) { hideLoading(); }); } var mostrecentrecord; function ShowMostRecentEngineHours(data) { var rows = []; for (var i = 0; i < data.length; i++) { mostrecentrecord = data[i]; var fr = { Values: mostrecentrecord }; rows.push(fr); break;// Display the most recent reading } grid_enginehoursmostrecentdt.sortIndex = -1; grid_enginehoursmostrecentdt.sortDirection = -1; grid_enginehoursmostrecentdt.setData(rows); } function ShowMostRecentEngineHoursPreview(data) { if (!mostrecentrecord) return; var offsetVBUS = 0; var offsetGPS = 0; for (var i = 0; i < data.length; i++) { var r = data[i]; offsetVBUS = r.VBUS - r.VBUS_Calc; offsetGPS = r.Gps - r.Gps_Calc; break; } var rows = []; var r = $.extend(true, {}, mostrecentrecord); r.VBUS_Calc = r.VBUS - offsetVBUS; r.VBUS_Calc = r.VBUS_Calc.toFixed(2); r.Gps_Calc = r.Gps - offsetGPS; r.Gps_Calc = r.Gps_Calc.toFixed(2); var fr = { Values: r }; rows.push(fr); grid_enginehoursmostrecentdt.sortIndex = -1; grid_enginehoursmostrecentdt.sortDirection = -1; grid_enginehoursmostrecentdt.setData(rows); } function ShowEngineHoursHis(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; r.VBUS = r.VBUS.toFixed(2); r.VBUS_Calc = r.VBUS_Calc.toFixed(2); r.Gps = r.Gps.toFixed(2); r.Gps_Calc = r.Gps_Calc.toFixed(2); for (var j in r) { if (j === "EventTimeText") r[j] = { DisplayValue: r["EventTimeText"], Value: r["AsofTime"] }; if (j === "EventTimeLocalText") r[j] = { DisplayValue: r["EventTimeLocalText"], Value: r["AsofTimeLocal"] }; } var fr = { Values: r }; rows.push(fr); } grid_enginehourshisdt.sortIndex = -1; grid_enginehourshisdt.sortDirection = -1; grid_enginehourshisdt.setData(rows); } //************************Adjust Engine Hours**************************************// function openAdjustEngineHours() { grid_enginehoursmostrecentdt.columns[0].visible = isCalampEH; grid_enginehoursmostrecentdt.columns[1].visible = isPedigreeEH; grid_enginehoursmostrecentdt.columns[2].visible = isOEMDD2EH; grid_enginehoursmostrecentdt.columns[5].caption = isCalampEH ? GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)") : GetTextByKey("P_MA_PEDIGREERAW", "Pedigree(Raw)"); grid_enginehoursmostrecentdt.columns[6].caption = isCalampEH ? GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)") : GetTextByKey("P_MA_PEDIGREEADJUSTED", "Pedigree(Adjusted)"); grid_enginehoursmostrecentdt.columns[5].visible = isCalampEH || isPedigreeEH; grid_enginehoursmostrecentdt.columns[6].visible = isCalampEH || isPedigreeEH; grid_enginehoursmostrecentdt.columns[7].visible = isCalampEH; grid_enginehoursmostrecentdt.columns[8].visible = isCalampEH; grid_enginehoursmostrecentdt.columns[9].visible = isOEMDD2EH; grid_enginehoursmostrecentdt.columns[10].visible = isOEMDD2EH; grid_enginehoursmostrecentdt.init(); grid_enginehourshisdt.columns[0].visible = isCalampEH; grid_enginehourshisdt.columns[1].visible = isPedigreeEH; grid_enginehourshisdt.columns[2].visible = isOEMDD2EH; grid_enginehourshisdt.columns[5].caption = isCalampEH ? GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)") : GetTextByKey("P_MA_PEDIGREERAW", "Pedigree(Raw)"); grid_enginehourshisdt.columns[6].caption = isCalampEH ? GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)") : GetTextByKey("P_MA_PEDIGREEADJUSTED", "Pedigree(Adjusted)"); grid_enginehourshisdt.columns[5].visible = isCalampEH || isPedigreeEH; grid_enginehourshisdt.columns[6].visible = isCalampEH || isPedigreeEH; grid_enginehourshisdt.columns[7].visible = isCalampEH; grid_enginehourshisdt.columns[8].visible = isCalampEH; grid_enginehourshisdt.columns[9].visible = isOEMDD2EH; grid_enginehourshisdt.columns[10].visible = isOEMDD2EH; grid_enginehourshisdt.init(); var datetime = customerdatetime.split(' '); var time = datetime[0]; var st = datetime[1].split(':'); var hours = st[0].length == 1 ? "0" + st[0] : st[0]; var minutes = st[1]; $('#dialogenginehours_enginehours').val(''); $('#dialogadjust_enginehourstimezone').val(customertimezone ? customertimezone : "UTC"); $('#dialogenginehours_date').val(time); $('#dialogenginehours_timehour').val(hours); $('#dialogenginehours_timeminute').val(minutes); $('#dialogenginehours_Notes').val(''); $('#dialog_adjustenginehours .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours')); showmaskbg(true); $('#dialog_adjustenginehours') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adjustenginehours').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adjustenginehours').width()) / 2 }) .showDialogfixed(); $('#dialogenginehours_enginehours').focus(); getEngineHoursHis(); } function OnAdjustEngineHours() { $('#adjustenginehoursmask').show(); var alerttitle = GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours'); var enginehourstxt = GetTextByKey("P_MA_ENGINEHOURS", "Engine Hours"); showConfirm('Do you want to adjust the engine hours?', alerttitle, function () { $('#adjustodomask').hide(); var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'EngineHours': $('#dialogenginehours_enginehours').val(), 'EngineHoursDate': $('#dialogenginehours_date').val(), 'Notes': $('#dialogenginehours_Notes').val(), 'DataSource': primarydatadourceEH }; if (item.EngineHours !== "") { if (isNaN(item.EngineHours)) { showAlert(GetTextByKey("P_MA_FORMATERROR", '{0} format error.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } else { if (item.EngineHours <= 0) { showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0", '{0} must be greater than 0.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } if (item.EngineHoursDate === "") { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#adjustenginehoursmask').hide(); return; } var offset = $('#dialogadjust_enginehourstimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogenginehours_timehour').val(); var minute = $('#dialogenginehours_timeminute').val(); item.EngineHoursDate = item.EngineHoursDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; CheckEngineHourMinimumTime(item, "submit"); }, function () { $('#adjustenginehoursmask').hide(); }); } function CheckEngineHourMinimumTime(item, type) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("CheckEngineHourMinimumTime", param, function (data) { if (data > 0) { if (data == 1) showAlert(GetTextByKey("P_MA_CHECKENGINEHOURSMINNIMUMTIME", "The adjustment cannot be completed as provided. The engine hours reading date provided cannot be prior to initial telematic data available for the asset."), GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours')); else showAlert(GetTextByKey("P_MA_CHECKENGINEHOURSMINNIMUMTIME1", "The adjustment cannot be completed as provided. The engine hours reading date provided must be prior to or equal to the latest telematic data available for the asset."), GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours')); $('#adjustenginehoursmask').hide(); return; } else { if (type === "submit") SaveAdjustEngineHours(item); else if (type === "preview") GetCalampEngineHoursHistoryPreview(item); } }, function (err) { }); } function SaveAdjustEngineHours(item) { showloading(true); var param = JSON.stringify(item); param = htmlencode(param); var alerttitle = GetTextByKey("P_MA_ADJUSTENGINEHOURS", GetTextByKey("P_MA_ADJUSTENGINEHOURS", 'Adjust Engine Hours')); devicerequest("SaveAdjustEngineHours", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, alerttitle); } else { getEnineHours(); getMachineInfo(); showAlert(GetTextByKey("P_MA_SUCCESSFULLY", "{0} Successfully.").replace('{0}', alerttitle), alerttitle); } $('#dialog_adjustenginehours').hideDialog(); $('#adjustenginehoursmask').hide(); }, function (err) { console.log(err); showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTO", "Failed to {0}.").replace('{0}', alerttitle), alerttitle); $('#adjustenginehoursmask').hide(); }); } function OnPreviewEngineHours() { getEngineHoursHisPreview(); } //************************Add Engine Hours**************************************// function openAddEnginHours() { var datetime = customerdatetime.split(' '); var time = datetime[0]; var st = datetime[1].split(':'); var hours = st[0].length == 1 ? "0" + st[0] : st[0]; var minutes = st[1]; $('#dialogaddgenginehours_enginehours').val(''); $('#dialogadd_enginehourstimezone').val(customertimezone ? customertimezone : "UTC"); $('#dialogaddenginehours_date').val(time); $('#dialogaddenginehours_timehour').val(hours); $('#dialogaddenginehours_timeminute').val(minutes); $('#dialogaddenginehours_Notes').val(''); $('#dialog_addenginehours .dialog-title span.title').text(GetTextByKey("P_MA_ADDENGINEHOURS", 'Add Engine Hours')); showmaskbg(true); $('#dialog_addenginehours') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_addenginehours').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_addenginehours').width()) / 2 }) .showDialogfixed(); $('#dialogaddgenginehours_enginehours').focus(); } function OnAddEngineHours() { $('#addenginehoursmask').show(); var alerttitle = GetTextByKey("P_MA_ADDENGINEHOURS", 'Add Engine Hours'); var enginehourstxt = GetTextByKey("P_MA_ENGINEHOURS", "Engine Hours"); showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADDTHEENGINEHOURS", 'Do you want to add the engine hours?'), alerttitle, function () { $('#adjustodomask').hide(); var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'EngineHours': $('#dialogaddgenginehours_enginehours').val(), 'EngineHoursDate': $('#dialogaddenginehours_date').val(), 'Notes': $('#dialogaddenginehours_Notes').val() }; if (item.EngineHours !== "") { if (isNaN(item.EngineHours)) { showAlert(GetTextByKey("P_MA_FORMATERROR", '{0} format error.').replace('{0}', enginehourstxt), alerttitle); $('#addenginehoursmask').hide(); return; } else { if (item.EngineHours <= 0) { showAlert(GetTextByKey("P_MA_MUSTBEGREATERTHAN0", '{0} must be greater than 0.').replace('{0}', enginehourstxt), alerttitle); $('#addenginehoursmask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#addenginehoursmask').hide(); return; } if (item.EngineHoursDate === "") { showAlert(GetTextByKey("P_MA_NOTBEEMPTY", '{0} cannot be empty.').replace('{0}', enginehourstxt), alerttitle); $('#addenginehoursmask').hide(); return; } var offset = $('#dialogadd_enginehourstimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogaddenginehours_timehour').val(); var minute = $('#dialogaddenginehours_timeminute').val(); item.EngineHoursDate = item.EngineHoursDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("AddManuallyInputEngineHours", param, function (data) { showloading(false); if (data !== 'OK') { if (data === "Failed") data = GetTextByKey("P_MA_FAILED", "Failed"); showAlert(data, alerttitle); } else { getEnineHours(); getMachineInfo(); showAlert(GetTextByKey("P_MA_SUCCESSFULLY", "{0} Successfully.").replace('{0}', GetTextByKey("P_MA_ADDENGINEHOURS", "Add Engine Hours")), alerttitle); } $('#dialog_addenginehours').hideDialog(); $('#addenginehoursmask').hide(); }, function (err) { console.log(err); showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTO", "Failed to {0}.").replace('{0}', GetTextByKey("P_MA_ADDENGINEHOURS", "Add Engine Hours")), alerttitle); $('#addenginehoursmask').hide(); }); }, function () { $('#addenginehoursmask').hide(); }); } /********************Adjustment History****************************************/ function openEngineHoursAdjustHistory() { window.open("EngineHoursAdjustHistory.aspx?cid=" + contractorid + "&mid=" + machineid); }