$(function () { InitFuelRemainingGridData(); }); var grid_fuelremainingdt; var grid_fuelremaininghisdt; function ShowFuelRemainings(data) { var rows = []; var hasCalamp = false; 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 === "Amount") r[j] = { DisplayValue: r["PercentText"], Value: r["Amount"] }; else if (j === "AsofTimeLocal") r[j] = { DisplayValue: r["ReceivedDateStr"], Value: r[j] }; } //r.Amount = r.Amount.toFixed(2); rows.push(r); //if (r.DataSource.toLowerCase() == "calamp") // hasCalamp = true; } grid_fuelremainingdt.sortIndex = -1; grid_fuelremainingdt.sortDirection = -1; grid_fuelremainingdt.setData(rows); $("#fuelremaininglist").css("height", autoheight(grid_fuelremainingdt)); grid_fuelremainingdt && grid_fuelremainingdt.resize(); if (IsSupperAdmin && hasCalamp) { $('#btnfuelremainingadjust').css("display", ''); } else $('#btnfuelremainingadjust').css("display", 'none'); } function InitFuelRemainingGridData() { grid_fuelremainingdt = createGridView('#fuelremaininglist'); 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: 'Amount', caption: GetTextByKey("P_MA_FUELREMAINING", "Fuel Remaining"), valueIndex: 'Amount', css: { 'width': 100, 'text-align': 'left' } }, //{ name: 'Units', caption: GetTextByKey("P_MA_UNITS", "Units"), valueIndex: 'UOM', css: { 'width': 80, 'text-align': 'left' } }, { name: 'ReceivedDate', caption: GetTextByKey("P_MA_RECEIVEDDATE", "Received Date"), valueIndex: 'AsofTimeLocal', css: { 'width': 130, 'text-align': 'left' } }, { name: 'SetPrmary', caption: "", css: { 'width': 30, '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 = true; 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.sortable = false; col.resizable = false; col.type = GridView.ColumnTypes.Icon; col.text = "key"; //GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'); col.events = { onclick: function () { openSetPrimary(5, this); } }; col.classFilter = function (e) { return "icon-col"; }; col.styleFilter = function (e) { return { display: e.IsPrimary === "Yes" ? 'none' : '' }; }; col.attrs = { 'title': GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary') }; col.visible = IsSupperAdmin; } columns.push(col); } grid_fuelremainingdt.multiSelect = false; grid_fuelremainingdt.columns = columns; grid_fuelremainingdt.init(); } function InitFuelRemainingHisGridData() { grid_fuelremaininghisdt = createGridView('#fuelremaininghislist'); var list_columns = [ { name: 'DeviceAirId', caption: GetTextByKey("P_MA_DEVICEAIRID", "Device Air ID"), valueIndex: 'DeviceAirId', 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': 90, '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: '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 = true; 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_fuelremaininghisdt.multiSelect = false; grid_fuelremaininghisdt.columns = columns; grid_fuelremaininghisdt.init(); } function getFuelRemainings() { grid_fuelremainingdt.setData([]); showLoading(); devicerequest("GetAssetCurrentFuelRemaining", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowFuelRemainings(data); }, function (err) { hideLoading(); }); } function getFuelRemainingHis() { grid_fuelremaininghisdt.setData([]); showLoading(); devicerequest("GetCalampFuelRemainingHistory", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowFuelRemainingHis(data); }, function (err) { hideLoading(); }); } function getFuelRemainingHisPreview() { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'FuelRemaining': $('#dialogadjust_fuelremaining').val(), 'UOM': $('#dialogadjust_sel_fuelremaininguom').val(), 'FuelRemainingDate': $('#dialogadjust_fuelremainingdate').val(), 'Notes': $('#dialogadjust_notes').val() }; var alerttitle = GetTextByKey("P_MA_ADJUSTFUELREMAINING", "Adjust FuelRemaining"); if (item.FuelRemaining !== "") { if (isNaN(item.FuelRemaining)) { showAlert(GetTextByKey("P_MA_FUELREMAININGFORMATERROR", 'FuelRemaining format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.FuelRemaining <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_FUELREMAININGCANNOTBEEMPTY", "FuelRemaining cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } grid_fuelremaininghisdt.setData([]); showLoading(); if (item.FuelRemainingDate === "") { showAlert(GetTextByKey("P_MA_FUELREMAININGDATACANNOTBEEMPTY", "FuelRemaining date cannot be empty."), alerttitle); $('#adjustodomask').hide(); hideLoading(); return; } var offset = $('#dialogadjust_fuelremainingtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.FuelRemainingDate = item.FuelRemainingDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; var param = JSON.stringify(item); param = htmlencode(param); devicerequest("GetCalampFuelRemainingHistoryPreview", param, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowFuelRemainingHis(data); }, function (err) { hideLoading(); }); } function ShowFuelRemainingHis(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; 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"] }; } rows.push(r); } grid_fuelremaininghisdt.sortIndex = -1; grid_fuelremaininghisdt.sortDirection = -1; grid_fuelremaininghisdt.setData(rows); } //************************Adjust FuelRemaining**************************************// function openAdjustFuelRemaining() { $('#dialogadjust_fuelremaining').val(''); $('#dialogadjust_sel_fuelremaininguom').val('Mile'); $('#dialogadjust_fuelremainingtimezone').val("UTC"); $('#dialogadjust_fuelremainingdate').val(currentdate); $('#dialogadjust_timehour').val('00'); $('#dialogadjust_timeminute').val('00'); $('#dialogadjust_notes').val(''); $('#dialog_adjustfuelremaining .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTFUELREMAINING", "Adjust FuelRemaining")); showmaskbg(true); $('#dialog_adjustfuelremaining') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adjustfuelremaining').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adjustfuelremaining').width()) / 2 }) .showDialog(); $('#dialogadjust_fuelremaining').focus(); getFuelRemainingHis(); } function OnAdjustFuelRemaining() { $('#adjustodomask').show(); var alerttitle = GetTextByKey("P_MA_ADJUSTFUELREMAINING", "Adjust FuelRemaining"); showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEFUELREMAINING", 'Do you want to adjust the fuelremaining?'), alerttitle, function () { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'FuelRemaining': $('#dialogadjust_fuelremaining').val(), 'UOM': $('#dialogadjust_sel_fuelremaininguom').val(), 'FuelRemainingDate': $('#dialogadjust_fuelremainingdate').val(), 'Notes': $('#dialogadjust_notes').val() }; if (item.FuelRemaining !== "") { if (isNaN(item.FuelRemaining)) { showAlert(GetTextByKey("P_MA_FUELREMAININGFORMATERROR", 'FuelRemaining format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.FuelRemaining <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_FUELREMAININGCANNOTBEEMPTY", "FuelRemaining cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } if (item.FuelRemainingDate === "") { showAlert(GetTextByKey("P_MA_FUELREMAININGDATACANNOTBEEMPTY", "FuelRemaining cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } var offset = $('#dialogadjust_fuelremainingtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.FuelRemainingDate = item.FuelRemainingDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustFuelRemaining", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, alerttitle); } else { getFuelRemainings(); showAlert(GetTextByKey("P_MA_ADJUSTFUELREMAININGSUCCESSFULLY", "Adjust FuelRemaining Successfully."), alerttitle); } $('#dialog_adjustfuelremaining').hideDialog(); $('#adjustodomask').hide(); }, function (err) { showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTFUELREMAINING", 'Failed to adjust FuelRemaining.'), alerttitle); $('#adjustodomask').hide(); }); }, function () { $('#adjustodomask').hide(); }); } function OnPreviewFuelRemaining() { getFuelRemainingHisPreview(); }