338 lines
13 KiB
JavaScript
338 lines
13 KiB
JavaScript
$(function () {
|
|
InitFuelusedGridData();
|
|
//InitFuelusedHisGridData();
|
|
});
|
|
|
|
var grid_fueluseddt;
|
|
var grid_fuelusedhisdt;
|
|
|
|
function ShowFueluseds(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 === "AsofTimeLocal")
|
|
r[j] = { DisplayValue: r["ReceivedDateStr"], Value: r[j] };
|
|
}
|
|
r.Amount = { DisplayValue: r.Amount.toFixed(2), Value: r.Amount };
|
|
rows.push(r);
|
|
|
|
//if (r.DataSource.toLowerCase() == "calamp")
|
|
// hasCalamp = true;
|
|
}
|
|
grid_fueluseddt.sortIndex = -1;
|
|
grid_fueluseddt.sortDirection = -1;
|
|
grid_fueluseddt.setData(rows);
|
|
|
|
$("#fuelusedlist").css("height", autoheight(grid_fueluseddt));
|
|
grid_fueluseddt && grid_fueluseddt.resize();
|
|
|
|
if (IsSupperAdmin && hasCalamp) {
|
|
$('#btnfuelusedadjust').css("display", '');
|
|
}
|
|
else
|
|
$('#btnfuelusedadjust').css("display", 'none');
|
|
}
|
|
|
|
function InitFuelusedGridData() {
|
|
grid_fueluseddt = createGridView('#fuelusedlist');
|
|
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_FUELUSED", "Fuel Used"), 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(4, 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_fueluseddt.multiSelect = false;
|
|
grid_fueluseddt.columns = columns;
|
|
grid_fueluseddt.init();
|
|
}
|
|
|
|
function InitFuelusedHisGridData() {
|
|
grid_fuelusedhisdt = createGridView('#fuelusedhislist');
|
|
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_fuelusedhisdt.multiSelect = false;
|
|
grid_fuelusedhisdt.columns = columns;
|
|
grid_fuelusedhisdt.init();
|
|
}
|
|
|
|
|
|
function getFueluseds() {
|
|
grid_fueluseddt.setData([]);
|
|
showLoading();
|
|
|
|
devicerequest("GetAssetCurrentFuelused", contractorid + String.fromCharCode(170) + machineid, function (data) {
|
|
hideLoading();
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
ShowFueluseds(data);
|
|
}, function (err) {
|
|
hideLoading();
|
|
});
|
|
}
|
|
|
|
function getFuelusedHis() {
|
|
grid_fuelusedhisdt.setData([]);
|
|
showLoading();
|
|
|
|
devicerequest("GetCalampFuelusedHistory", contractorid + String.fromCharCode(170) + machineid, function (data) {
|
|
hideLoading();
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
ShowFuelusedHis(data);
|
|
}, function (err) {
|
|
hideLoading();
|
|
});
|
|
}
|
|
|
|
function getFuelusedHisPreview() {
|
|
var item = {
|
|
'CustomerID': contractorid,
|
|
'AssetID': machineid,
|
|
'Fuelused': $('#dialogadjust_fuelused').val(),
|
|
'UOM': $('#dialogadjust_sel_fueluseduom').val(),
|
|
'FuelusedDate': $('#dialogadjust_fueluseddate').val(),
|
|
'Notes': $('#dialogadjust_notes').val()
|
|
};
|
|
|
|
var alerttitle = GetTextByKey("P_MA_ADJUSTFUELUSED", "Adjust Fuelused");
|
|
if (item.Fuelused !== "") {
|
|
if (isNaN(item.Fuelused)) {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDFORMATERROR", 'Fuelused format error.'), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
else {
|
|
if (item.Fuelused <= 0) {
|
|
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDCANNOTBEEMPTY", "Fuelused cannot be empty."), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
|
|
grid_fuelusedhisdt.setData([]);
|
|
showLoading();
|
|
|
|
if (item.FuelusedDate === "") {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDDATACANNOTBEEMPTY", "Fuelused date cannot be empty."), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
hideLoading();
|
|
return;
|
|
}
|
|
var offset = $('#dialogadjust_fuelusedtimezone').find("option:selected").attr("offset");
|
|
item.OffsetMinute = offset;
|
|
|
|
var hour = $('#dialogadjust_timehour').val();
|
|
var minute = $('#dialogadjust_timeminute').val();
|
|
|
|
item.FuelusedDate = item.FuelusedDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
|
|
devicerequest("GetCalampFuelusedHistoryPreview", param, function (data) {
|
|
hideLoading();
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
ShowFuelusedHis(data);
|
|
}, function (err) {
|
|
hideLoading();
|
|
});
|
|
}
|
|
|
|
function ShowFuelusedHis(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_fuelusedhisdt.sortIndex = -1;
|
|
grid_fuelusedhisdt.sortDirection = -1;
|
|
grid_fuelusedhisdt.setData(rows);
|
|
}
|
|
|
|
|
|
//************************Adjust Fuelused**************************************//
|
|
|
|
function openAdjustFuelused() {
|
|
$('#dialogadjust_fuelused').val('');
|
|
$('#dialogadjust_sel_fueluseduom').val('Mile');
|
|
$('#dialogadjust_fuelusedtimezone').val("UTC");
|
|
$('#dialogadjust_fueluseddate').val(currentdate);
|
|
$('#dialogadjust_timehour').val('00');
|
|
$('#dialogadjust_timeminute').val('00');
|
|
$('#dialogadjust_notes').val('');
|
|
$('#dialog_adjustfuelused .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTFUELUSED", "Adjust Fuelused"));
|
|
showmaskbg(true);
|
|
$('#dialog_adjustfuelused')
|
|
.attr('act', 'add')
|
|
.css({
|
|
'top': (document.documentElement.clientHeight - $('#dialog_adjustfuelused').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_adjustfuelused').width()) / 2
|
|
})
|
|
.showDialog();
|
|
$('#dialogadjust_fuelused').focus();
|
|
|
|
getFuelusedHis();
|
|
}
|
|
|
|
function OnAdjustFuelused() {
|
|
$('#adjustodomask').show();
|
|
var alerttitle = GetTextByKey("P_MA_ADJUSTFUELUSED", "Adjust Fuelused");
|
|
showConfirm(GetTextByKey("P_MA_DOYOUWANTTOADJUSTTHEFUELUSED", 'Do you want to adjust the fuelused?'), alerttitle, function () {
|
|
var item = {
|
|
'CustomerID': contractorid,
|
|
'AssetID': machineid,
|
|
'Fuelused': $('#dialogadjust_fuelused').val(),
|
|
'UOM': $('#dialogadjust_sel_fueluseduom').val(),
|
|
'FuelusedDate': $('#dialogadjust_fueluseddate').val(),
|
|
'Notes': $('#dialogadjust_notes').val()
|
|
};
|
|
|
|
if (item.Fuelused !== "") {
|
|
if (isNaN(item.Fuelused)) {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDFORMATERROR", 'Fuelused format error.'), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
else {
|
|
if (item.Fuelused <= 0) {
|
|
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDCANNOTBEEMPTY", "Fuelused cannot be empty."), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
|
|
if (item.FuelusedDate === "") {
|
|
showAlert(GetTextByKey("P_MA_FUELUSEDDATACANNOTBEEMPTY", "Fuelused cannot be empty."), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
return;
|
|
}
|
|
var offset = $('#dialogadjust_fuelusedtimezone').find("option:selected").attr("offset");
|
|
item.OffsetMinute = offset;
|
|
|
|
var hour = $('#dialogadjust_timehour').val();
|
|
var minute = $('#dialogadjust_timeminute').val();
|
|
|
|
item.FuelusedDate = item.FuelusedDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
|
|
|
|
showloading(true);
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
|
|
devicerequest("SaveAdjustFuelused", param, function (data) {
|
|
showloading(false);
|
|
if (data !== 'OK') {
|
|
showAlert(data, alerttitle);
|
|
} else {
|
|
getFueluseds();
|
|
showAlert(GetTextByKey("P_MA_ADJUSTFUELUSEDSUCCESSFULLY", "Adjust Fuelused Successfully."), alerttitle);
|
|
}
|
|
|
|
$('#dialog_adjustfuelused').hideDialog();
|
|
$('#adjustodomask').hide();
|
|
}, function (err) {
|
|
showloading(false);
|
|
showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTFUELUSED", 'Failed to adjust Fuelused.'), alerttitle);
|
|
$('#adjustodomask').hide();
|
|
});
|
|
}, function () {
|
|
$('#adjustodomask').hide();
|
|
});
|
|
|
|
}
|
|
|
|
|
|
function OnPreviewFuelused() {
|
|
getFuelusedHisPreview();
|
|
}
|