$(function () { InitOdometerGridData(); InitOdometerMostRecentGridData(); InitOdometerHisGridData(); }); var grid_odometerdt; var grid_odometermostrecentdt; var grid_odometerhisdt; var isCalampOdo = false; var isPedigreeOdo = false; var primarydatadourcenameOdo; var primarydatadourceOdo; function ShowOdometers(data) { var rows = []; isCalampOdo = false; isPedigreeOdo = false; isSmartWitness = false; primarydatadourcenameOdo = undefined; primarydatadourceOdo = 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" : ""; } r.Odometer = r.Odometer.toFixed(2); r.Corrected = r.Corrected.toFixed(2); var fr = { Values: r }; rows.push(fr); if (r.DataSource.toLowerCase() == "calamp" && r.IsPrimary.toLowerCase() == "yes") isCalampOdo = true; else if (r.DataSource.toLowerCase() == "pedigree") { if (r.IsPrimary.toLowerCase() == "yes" && r.SubSource.toLowerCase() != "odometer")//10471 isPedigreeOdo = true; if (r.SubSource.toLowerCase() == "odometer") r.DataSourceName = "HOS"; } else if (r.DataSource.toLowerCase() == "smartwitness" && r.IsPrimary.toLowerCase() == "yes") isSmartWitness = true; if (r.IsPrimary.toLowerCase() == "yes") { primarydatadourcenameOdo = r.DataSourceName; primarydatadourceOdo = r.DataSource; } } grid_odometerdt.sortIndex = -1; grid_odometerdt.sortDirection = -1; grid_odometerdt.setData(rows); $("#odometerlist").css("height", autoheight(grid_odometerdt)); grid_odometerdt && grid_odometerdt.resize(); if ((IsSupperAdmin || isAllowed) && (isCalampOdo || isPedigreeOdo || isSmartWitness)) { $('#btnodometeradjust').css("display", ''); $('#btnodometerhistory').css("display", ''); } else { $('#btnodometeradjust').css("display", 'none'); $('#btnodometerhistory').css("display", 'none'); } if (primarydatadourcenameOdo) { $('#span_adjustodometer').text(primarydatadourcenameOdo); $('#span_addodometer').text(primarydatadourcenameOdo); } else { $('#span_adjustodometer').text('empty'); $('#span_addodometer').text('empty'); } } function InitOdometerGridData() { grid_odometerdt = new GridView('#odometerlist'); grid_odometerdt.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: 'Odometer', caption: GetTextByKey("P_MA_ODOMETER", "Odometer"), valueIndex: 'Odometer', css: { 'width': 80, '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(0, 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_odometerdt.canMultiSelect = false; grid_odometerdt.columns = columns; grid_odometerdt.init(); grid_odometerdt.selectedrowchanged = function (rowindex) { var rowdata = grid_odometerdt.source[rowindex]; if (rowdata) { } } } function InitOdometerMostRecentGridData() { grid_odometermostrecentdt = new GridView('#odometermostrecent'); grid_odometermostrecentdt.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: 'AsofTime', caption: GetTextByKey("P_MA_EVENTDATEUTC", "Event Date(UTC)"), valueIndex: 'EventTimeText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'AsofTime_local', 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': 90, 'text-align': 'right' } }, { name: 'VBUS_Calc', caption: GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)"), valueIndex: 'VBUS_Calc', css: { 'width': 110, 'text-align': 'right' } }, { name: 'Gps', caption: GetTextByKey("P_MA_GPSRAW", "GPS(Raw)"), valueIndex: 'Gps', css: { 'width': 110, 'text-align': 'right' } }, { name: 'Gps_Calc', caption: GetTextByKey("P_MA_GPSCALC", "GPS(Calc)"), valueIndex: 'Gps_Calc', css: { 'width': 130, 'text-align': 'right' } }, { name: 'Unit', caption: GetTextByKey("P_MA_UNIT", "Unit"), valueIndex: 'UOM', css: { 'width': 60, '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; } columns.push(col); } grid_odometermostrecentdt.canMultiSelect = false; grid_odometermostrecentdt.columns = columns; grid_odometermostrecentdt.init(); } function InitOdometerHisGridData() { grid_odometerhisdt = new GridView('#odometerhislist'); grid_odometerhisdt.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: 'AsofTime', caption: GetTextByKey("P_MA_EVENTDATEUTC", "Event Date(UTC)"), valueIndex: 'EventTimeText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'AsofTime_local', 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': 90, 'text-align': 'right' } }, { name: 'VBUS_Calc', caption: GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)"), valueIndex: 'VBUS_Calc', css: { 'width': 110, 'text-align': 'right' } }, { name: 'Gps', caption: GetTextByKey("P_MA_GPSRAW", "GPS(Raw)"), valueIndex: 'Gps', css: { 'width': 110, 'text-align': 'right' } }, { name: 'Gps_Calc', caption: GetTextByKey("P_MA_GPSCALC", "GPS(Calc)"), valueIndex: 'Gps_Calc', css: { 'width': 130, 'text-align': 'right' } }, { name: 'Unit', caption: GetTextByKey("P_MA_UNIT", "Unit"), valueIndex: 'UOM', css: { 'width': 60, '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; } columns.push(col); } grid_odometerhisdt.canMultiSelect = false; grid_odometerhisdt.columns = columns; grid_odometerhisdt.init(); grid_odometerhisdt.selectedrowchanged = function (rowindex) { var rowdata = grid_odometerhisdt.source[rowindex]; if (rowdata) { } } } function getOdometers() { grid_odometerdt.setData([]); showLoading(); devicerequest("GetAssetCurrentOdometer", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowOdometers(data); }, function (err) { hideLoading(); }); } function getOdometerHis() { grid_odometermostrecentdt.setData([]); grid_odometerhisdt.setData([]); showLoading(); var methodname = ""; if (isCalampOdo) methodname = "GetCalampOdometerHistory"; else if (isPedigreeOdo) methodname = "GetPedigreeOdometerHistory"; else if (isSmartWitness) methodname = "GetSmartWitnessOdometerHistory"; devicerequest(methodname, contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowOdometerHis(data); ShowMostRecentOdometer(data); }, function (err) { hideLoading(); }); } function getOdometerHisPreview() { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Odometer': $('#dialogadjust_odometer').val(), 'UOM': $('#dialogadjust_sel_odometeruom').val(), 'OdometerDate': $('#dialogadjust_odometerdate').val(), 'Notes': $('#dialogadjust_notes').val() }; var alerttitle = GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer"); if (item.Odometer !== "") { if (isNaN(item.Odometer)) { showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR", 'Odometer format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Odometer <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY", "Odometer cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } if (item.OdometerDate === "") { showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY", "Odometer date cannot be empty."), alerttitle); $('#adjustodomask').hide(); hideLoading(); return; } var offset = $('#dialogadjust_odometertimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.OdometerDate = item.OdometerDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; CheckOdometerMinnimumTime(item, "preview"); } function GetOdometerHistoryPreview(item) { grid_odometerhisdt.setData([]); showLoading(); var param = JSON.stringify(item); param = htmlencode(param); if (isCalampOdo) methodname = "GetCalampOdometerHistoryPreview"; else if (isPedigreeOdo) methodname = "GetPedigreeOdometerHistoryPreview"; else if (isSmartWitness) methodname = "GetSmartWitnessOdometerHistoryPreview"; devicerequest(methodname, param, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowOdometerHis(data); ShowMostRecentOdometerPreview(data); }, function (err) { hideLoading(); }); } var mostrecentrecord function ShowMostRecentOdometer(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_odometermostrecentdt.sortIndex = -1; grid_odometermostrecentdt.sortDirection = -1; grid_odometermostrecentdt.setData(rows); } function ShowMostRecentOdometerPreview(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_odometermostrecentdt.sortIndex = -1; grid_odometermostrecentdt.sortDirection = -1; grid_odometermostrecentdt.setData(rows); } function ShowOdometerHis(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["AsofTime_Local"] }; } var fr = { Values: r }; rows.push(fr); } grid_odometerhisdt.sortIndex = -1; grid_odometerhisdt.sortDirection = -1; grid_odometerhisdt.setData(rows); } //************************Adjust Odometer**************************************// function openAdjustOdometer() { grid_odometermostrecentdt.columns[0].visible = isCalampOdo; grid_odometermostrecentdt.columns[1].visible = isPedigreeOdo || isSmartWitness; grid_odometermostrecentdt.columns[4].visible = !isSmartWitness; grid_odometermostrecentdt.columns[4].caption = isCalampOdo ? GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)") : GetTextByKey("P_MA_RAWRAW", "Raw(Raw)"); grid_odometermostrecentdt.columns[5].visible = !isSmartWitness; grid_odometermostrecentdt.columns[5].caption = isCalampOdo ? GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)") : "Raw(Adjusted)"; grid_odometermostrecentdt.columns[6].caption = isCalampOdo ? "GPS(Raw)" : "Odometer(Raw)"; grid_odometermostrecentdt.columns[7].caption = isCalampOdo ? "GPS(Calc)" : "Odometer(Adjusted)"; grid_odometermostrecentdt.init(); grid_odometerhisdt.columns[0].visible = isCalampOdo; grid_odometerhisdt.columns[1].visible = isPedigreeOdo || isSmartWitness; grid_odometerhisdt.columns[4].visible = !isSmartWitness; grid_odometerhisdt.columns[4].caption = isCalampOdo ? GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)") : GetTextByKey("P_MA_RAWRAW", "Raw(Raw)"); grid_odometerhisdt.columns[5].visible = !isSmartWitness; grid_odometerhisdt.columns[5].caption = isCalampOdo ? GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)") : "Raw(Adjusted)"; grid_odometerhisdt.columns[6].caption = isCalampOdo ? "GPS(Raw)" : "Odometer(Raw)"; grid_odometerhisdt.columns[7].caption = isCalampOdo ? "GPS(Calc)" : "Odometer(Adjusted)"; grid_odometerhisdt.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]; $('#dialogadjust_odometer').val(''); $('#dialogadjust_sel_odometeruom').val(systemunitofodometer); $('#dialogadjust_odometertimezone').val(customertimezone ? customertimezone : "UTC"); $('#dialogadjust_odometerdate').val(time); $('#dialogadjust_timehour').val(hours); $('#dialogadjust_timeminute').val(minutes); $('#dialogadjust_notes').val(''); $('#dialog_adjustodometer .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTODOMETER", 'Adjust Odometer')); showmaskbg(true); $('#dialog_adjustodometer') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adjustodometer').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adjustodometer').width()) / 2 }) .showDialogfixed(); $('#dialogadjust_odometer').focus(); getOdometerHis(); } function OnAdjustOdometer() { $('#adjustodomask').show(); var alerttitle = GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer"); showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEODOMETER", 'Do you want to adjust the odometer?'), alerttitle, function () { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Odometer': $('#dialogadjust_odometer').val(), 'UOM': $('#dialogadjust_sel_odometeruom').val(), 'OdometerDate': $('#dialogadjust_odometerdate').val(), 'Notes': $('#dialogadjust_notes').val(), 'DataSource': primarydatadourceOdo }; if (item.Odometer !== "") { if (isNaN(item.Odometer)) { showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR", 'Odometer format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Odometer <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY", "Odometer cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } if (item.OdometerDate === "") { showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY", "Odometer date cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } var offset = $('#dialogadjust_odometertimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.OdometerDate = item.OdometerDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; CheckOdometerMinnimumTime(item, "submit"); }, function () { $('#adjustodomask').hide(); }); } function CheckOdometerMinnimumTime(item, type) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("CheckOdometerMinnimumTime", param, function (data) { if (data > 0) { if (data == 1) showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME1", "The adjustment cannot be completed as provided. The odometer reading date provided cannot be prior to initial telematic data available for the asset."), GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer")); else showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME", "The adjustment cannot be completed as provided. The odometer reading date provided must be prior to or equal to the latest telematic data available for the asset."), GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer")); $('#adjustodomask').hide(); return; } else { if (type === "submit") SaveAdjustOdometer(item); else if (type === "preview") GetOdometerHistoryPreview(item); } }, function (err) { }); } function SaveAdjustOdometer(item) { showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustOdometer", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer")); } else { getOdometers(); getMachineInfo(); showAlert(GetTextByKey("P_MA_ADJUSTODOMETERSUCCESSFULLY", "Adjust Odometer Successfully."), GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer")); } $('#dialog_adjustodometer').hideDialog(); $('#adjustodomask').hide(); }, function (err) { showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTDOMETER", 'Failed to adjust Odometer.'), GetTextByKey("P_MA_ADJUSTODOMETER", "Adjust Odometer")); $('#adjustodomask').hide(); }); } function OnPreviewOdometer() { getOdometerHisPreview(); } //************************Add Odometer**************************************// function openAddOdometer() { 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]; $('#dialogadd_odometer').val(''); $('#dialogadd_sel_odometeruom').val(systemunitofodometer); $('#dialogadd_odometertimezone').val(customertimezone ? customertimezone : "UTC"); $('#dialogadd_odometerdate').val(time); $('#dialogadd_timehour').val(hours); $('#dialogadd_timeminute').val(minutes); $('#dialogadd_notes').val(''); $('#dialog_addodometer .dialog-title span.title').text(GetTextByKey("P_MA_ADDODOMETER", 'Add Odometer')); showmaskbg(true); $('#dialog_addodometer') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_addodometer').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_addodometer').width()) / 2 }) .showDialogfixed(); $('#dialogadd_odometer').focus(); } function OnAddOdometer() { $('#addodomask').show(); var alerttile = GetTextByKey("P_MA_ADDODOMETER", 'Add Odometer'); showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADDTHEODOMETER", 'Do you want to add the odometer?'), alerttile, function () { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Odometer': $('#dialogadd_odometer').val(), 'UOM': $('#dialogadd_sel_odometeruom').val(), 'OdometerDate': $('#dialogadd_odometerdate').val(), 'Notes': $('#dialogadd_notes').val() }; if (item.Odometer !== "") { if (isNaN(item.Odometer)) { showAlert(GetTextByKey("P_MA_ODOMETERFORMATERROR", 'Odometer format error.'), alerttile); $('#addodomask').hide(); return; } else { if (item.Odometer <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttile); $('#addodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_ODOMETRCANNOTBEEMPTY", "Odometer cannot be empty."), alerttile); $('#addodomask').hide(); return; } if (item.OdometerDate === "") { showAlert(GetTextByKey("P_MA_ODOMETRDATACANNOTBEEMPTY", "Odometer date cannot be empty."), alerttile); $('#addodomask').hide(); return; } var offset = $('#dialogadd_odometertimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadd_timehour').val(); var minute = $('#dialogadd_timeminute').val(); item.OdometerDate = item.OdometerDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("AddManuallyInputOdometer", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, alerttile); } else { getOdometers(); getMachineInfo(); showAlert("Add Odometer Successfully.", alerttile); } $('#dialog_addodometer').hideDialog(); $('#addodomask').hide(); }, function (err) { showloading(false); showAlert('Failed to add Odometer.', alerttile); $('#addodomask').hide(); }); }, function () { $('#addodomask').hide(); }); } /********************Adjustment History****************************************/ function openOdometerAdjustHistory() { window.open("OdometerAdjustHistory.aspx?cid=" + contractorid + "&mid=" + machineid); }