This commit is contained in:
2023-04-28 12:22:26 +08:00
parent 88e0a25ecd
commit c9723008af
1047 changed files with 443540 additions and 1 deletions

View File

@ -0,0 +1,682 @@
$(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);
}

View File

@ -0,0 +1,359 @@
$(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"] };
}
//r.Amount = r.Amount.toFixed(2);
var fr = { Values: r };
rows.push(fr);
//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 = new GridView('#fuelremaininglist');
grid_fuelremainingdt.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: '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: '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 = 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.isurl = true;
col.text = 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;
col.resizable = false;
}
columns.push(col);
}
grid_fuelremainingdt.canMultiSelect = false;
grid_fuelremainingdt.columns = columns;
grid_fuelremainingdt.init();
grid_fuelremainingdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_fuelremainingdt.source[rowindex];
if (rowdata) {
}
}
}
function InitFuelRemainingHisGridData() {
grid_fuelremaininghisdt = new GridView('#fuelremaininghislist');
grid_fuelremaininghisdt.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: '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.canMultiSelect = false;
grid_fuelremaininghisdt.columns = columns;
grid_fuelremaininghisdt.init();
grid_fuelremaininghisdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_fuelremaininghisdt.source[rowindex];
if (rowdata) {
}
}
}
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"] };
}
var fr = { Values: r };
rows.push(fr);
}
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();
}

View File

@ -0,0 +1,358 @@
$(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" : "";
}
r.Amount = r.Amount.toFixed(2);
var fr = { Values: r };
rows.push(fr);
//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 = new GridView('#fuelusedlist');
grid_fueluseddt.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: '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: '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 = 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.isurl = true;
col.text = 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;
col.resizable = false;
}
columns.push(col);
}
grid_fueluseddt.canMultiSelect = false;
grid_fueluseddt.columns = columns;
grid_fueluseddt.init();
grid_fueluseddt.selectedrowchanged = function (rowindex) {
var rowdata = grid_fueluseddt.source[rowindex];
if (rowdata) {
}
}
}
function InitFuelusedHisGridData() {
grid_fuelusedhisdt = new GridView('#fuelusedhislist');
grid_fuelusedhisdt.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: '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.canMultiSelect = false;
grid_fuelusedhisdt.columns = columns;
grid_fuelusedhisdt.init();
grid_fuelusedhisdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_fuelusedhisdt.source[rowindex];
if (rowdata) {
}
}
}
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"] };
}
var fr = { Values: r };
rows.push(fr);
}
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();
}

View File

@ -0,0 +1,359 @@
$(function () {
InitIdlehourGridData();
//InitIdlehourHisGridData();
});
var grid_idlehourdt;
var grid_idlehourhisdt;
function ShowIdlehours(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 === "UOM")
r[j] = "Hour";
}
r.Hours = r.Hours.toFixed(2);
var fr = { Values: r };
rows.push(fr);
//if (r.DataSource.toLowerCase() == "calamp")
// hasCalamp = true;
}
grid_idlehourdt.sortIndex = -1;
grid_idlehourdt.sortDirection = -1;
grid_idlehourdt.setData(rows);
$("#idlehourlist").css("height", autoheight(grid_idlehourdt));
grid_idlehourdt && grid_idlehourdt.resize();
if (IsSupperAdmin && hasCalamp) {
$('#btnidlehouradjust').css("display", '');
}
else
$('#btnidlehouradjust').css("display", 'none');
}
function InitIdlehourGridData() {
grid_idlehourdt = new GridView('#idlehourlist');
grid_idlehourdt.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_IDLEHOURS", "Idle Hours"), valueIndex: 'Hours', css: { 'width': 80, '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: '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 = 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.isurl = true;
col.text = GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary');
col.events = {
onclick: function () {
openSetPrimary(3, 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;
col.resizable = false;
}
columns.push(col);
}
grid_idlehourdt.canMultiSelect = false;
grid_idlehourdt.columns = columns;
grid_idlehourdt.init();
grid_idlehourdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_idlehourdt.source[rowindex];
if (rowdata) {
}
}
}
function InitIdlehourHisGridData() {
grid_idlehourhisdt = new GridView('#idlehourhislist');
grid_idlehourhisdt.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: '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_idlehourhisdt.canMultiSelect = false;
grid_idlehourhisdt.columns = columns;
grid_idlehourhisdt.init();
grid_idlehourhisdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_idlehourhisdt.source[rowindex];
if (rowdata) {
}
}
}
function getIdlehours() {
grid_idlehourdt.setData([]);
showLoading();
devicerequest("GetAssetCurrentIdlehours", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowIdlehours(data);
}, function (err) {
hideLoading();
});
}
function getIdlehourHis() {
grid_idlehourhisdt.setData([]);
showLoading();
devicerequest("GetCalampIdlehourHistory", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowIdlehourHis(data);
}, function (err) {
hideLoading();
});
}
function getIdlehourHisPreview() {
var item = {
'CustomerID': contractorid,
'AssetID': machineid,
'Idlehour': $('#dialogadjust_idlehour').val(),
'UOM': $('#dialogadjust_sel_idlehouruom').val(),
'IdlehourDate': $('#dialogadjust_idlehourdate').val(),
'Notes': $('#dialogadjust_notes').val()
};
var alerttitle = GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour');
if (item.Idlehour !== "") {
if (isNaN(item.Idlehour)) {
showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR", 'Idlehour format error.'), alerttitle);
$('#adjustodomask').hide();
return;
}
else {
if (item.Idlehour <= 0) {
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
$('#adjustodomask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY", "Idlehour cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
grid_idlehourhisdt.setData([]);
showLoading();
if (item.IdlehourDate === "") {
showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY", "Idlehour date cannot be empty."), alerttitle);
$('#adjustodomask').hide();
hideLoading();
return;
}
var offset = $('#dialogadjust_idlehourtimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var hour = $('#dialogadjust_timehour').val();
var minute = $('#dialogadjust_timeminute').val();
item.IdlehourDate = item.IdlehourDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("GetCalampIdlehourHistoryPreview", param, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowIdlehourHis(data);
}, function (err) {
hideLoading();
});
}
function ShowIdlehourHis(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"] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_idlehourhisdt.sortIndex = -1;
grid_idlehourhisdt.sortDirection = -1;
grid_idlehourhisdt.setData(rows);
}
//************************Adjust Idlehour**************************************//
function openAdjustIdlehour() {
$('#dialogadjust_idlehour').val('');
$('#dialogadjust_sel_idlehouruom').val('Mile');
$('#dialogadjust_idlehourtimezone').val("UTC");
$('#dialogadjust_idlehourdate').val(currentdate);
$('#dialogadjust_timehour').val('00');
$('#dialogadjust_timeminute').val('00');
$('#dialogadjust_notes').val('');
$('#dialog_adjustidlehour .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour'));
showmaskbg(true);
$('#dialog_adjustidlehour')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_adjustidlehour').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_adjustidlehour').width()) / 2
})
.showDialog();
$('#dialogadjust_idlehour').focus();
getIdlehourHis();
}
function OnAdjustIdlehour() {
var alerttitle = GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour');
$('#adjustodomask').show();
showConfirm('Do you want to adjust the idlehour?', alerttitle, function () {
var item = {
'CustomerID': contractorid,
'AssetID': machineid,
'Idlehour': $('#dialogadjust_idlehour').val(),
'UOM': $('#dialogadjust_sel_idlehouruom').val(),
'IdlehourDate': $('#dialogadjust_idlehourdate').val(),
'Notes': $('#dialogadjust_notes').val()
};
if (item.Idlehour !== "") {
if (isNaN(item.Idlehour)) {
showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR", 'Idlehour format error.'), alerttitle);
$('#adjustodomask').hide();
return;
}
else {
if (item.Idlehour <= 0) {
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
$('#adjustodomask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY", "Idlehour cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
if (item.IdlehourDate === "") {
showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY", "Idlehour date cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
var offset = $('#dialogadjust_idlehourtimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var hour = $('#dialogadjust_timehour').val();
var minute = $('#dialogadjust_timeminute').val();
item.IdlehourDate = item.IdlehourDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveAdjustIdlehour", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
getIdlehours();
showAlert(GetTextByKey("P_MA_ADJUSTIDLEHOURSUCCESSFULLY", "Adjust Idlehour Successfully."), alerttitle);
}
$('#dialog_adjustidlehour').hideDialog();
$('#adjustodomask').hide();
}, function (err) {
showloading(false);
showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTIDLEHOUR", 'Failed to adjust Idlehour.'), alerttitle);
$('#adjustodomask').hide();
});
}, function () {
$('#adjustodomask').hide();
});
}
function OnPreviewIdlehour() {
getIdlehourHisPreview();
}

View File

@ -0,0 +1,356 @@
$(function () {
InitLocationGridData();
//InitLocationHisGridData();
});
var grid_locationdt;
var grid_locationhisdt;
function ShowLocations(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" : "";
}
var fr = { Values: r };
rows.push(fr);
//if (r.DataSource.toLowerCase() == "calamp")
// hasCalamp = true;
}
grid_locationdt.sortIndex = -1;
grid_locationdt.sortDirection = -1;
grid_locationdt.setData(rows);
$("#locationlist").css("height", autoheight(grid_locationdt));
grid_locationdt && grid_locationdt.resize();
if (IsSupperAdmin && hasCalamp) {
$('#btnlocationadjust').css("display", '');
}
else
$('#btnlocationadjust').css("display", 'none');
}
function InitLocationGridData() {
grid_locationdt = new GridView('#locationlist');
grid_locationdt.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: 'Longitude', caption: GetTextByKey("P_MA_LONGITUDE", "Longitude"), valueIndex: 'Longitude', css: { 'width': 90, 'text-align': 'left' } },
{ name: 'Latitude', caption: GetTextByKey("P_MA_LATITUDE", "Latitude"), valueIndex: 'Latitude', css: { 'width': 90, '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 = 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.isurl = true;
col.text = GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary');
col.events = {
onclick: function () {
openSetPrimary(2, 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;
col.resizable = false;
}
columns.push(col);
}
grid_locationdt.canMultiSelect = false;
grid_locationdt.columns = columns;
grid_locationdt.init();
grid_locationdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_locationdt.source[rowindex];
if (rowdata) {
}
}
}
function InitLocationHisGridData() {
grid_locationhisdt = new GridView('#locationhislist');
grid_locationhisdt.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: '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_locationhisdt.canMultiSelect = false;
grid_locationhisdt.columns = columns;
grid_locationhisdt.init();
grid_locationhisdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_locationhisdt.source[rowindex];
if (rowdata) {
}
}
}
function getLocations() {
grid_locationdt.setData([]);
showLoading();
devicerequest("GetAssetCurrentLocation", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowLocations(data);
}, function (err) {
hideLoading();
});
}
function getLocationHis() {
grid_locationhisdt.setData([]);
showLoading();
devicerequest("GetCalampLocationHistory", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowLocationHis(data);
}, function (err) {
hideLoading();
});
}
function getLocationHisPreview() {
var item = {
'CustomerID': contractorid,
'AssetID': machineid,
'Location': $('#dialogadjust_location').val(),
'UOM': $('#dialogadjust_sel_locationuom').val(),
'LocationDate': $('#dialogadjust_locationdate').val(),
'Notes': $('#dialogadjust_notes').val()
};
var alerttitle = GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location");
if (item.Location !== "") {
if (isNaN(item.Location)) {
showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR", 'Location format error.'), alerttitle);
$('#adjustodomask').hide();
return;
}
else {
if (item.Location <= 0) {
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
$('#adjustodomask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY", "Location cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
grid_locationhisdt.setData([]);
showLoading();
if (item.LocationDate === "") {
showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY", "Location date cannot be empty."), alerttitle);
$('#adjustodomask').hide();
hideLoading();
return;
}
var offset = $('#dialogadjust_locationtimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var hour = $('#dialogadjust_timehour').val();
var minute = $('#dialogadjust_timeminute').val();
item.LocationDate = item.LocationDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("GetCalampLocationHistoryPreview", param, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
ShowLocationHis(data);
}, function (err) {
hideLoading();
});
}
function ShowLocationHis(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"] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_locationhisdt.sortIndex = -1;
grid_locationhisdt.sortDirection = -1;
grid_locationhisdt.setData(rows);
}
//************************Adjust Location**************************************//
function openAdjustLocation() {
$('#dialogadjust_location').val('');
$('#dialogadjust_sel_locationuom').val('Mile');
$('#dialogadjust_locationtimezone').val("UTC");
$('#dialogadjust_locationdate').val(currentdate);
$('#dialogadjust_timehour').val('00');
$('#dialogadjust_timeminute').val('00');
$('#dialogadjust_notes').val('');
$('#dialog_adjustlocation .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location"));
showmaskbg(true);
$('#dialog_adjustlocation')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_adjustlocation').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_adjustlocation').width()) / 2
})
.showDialog();
$('#dialogadjust_location').focus();
getLocationHis();
}
function OnAdjustLocation() {
$('#adjustodomask').show();
var alerttitle = GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location");
showConfirm('Do you want to adjust the location?', alerttitle, function () {
var item = {
'CustomerID': contractorid,
'AssetID': machineid,
'Location': $('#dialogadjust_location').val(),
'UOM': $('#dialogadjust_sel_locationuom').val(),
'LocationDate': $('#dialogadjust_locationdate').val(),
'Notes': $('#dialogadjust_notes').val()
};
if (item.Location !== "") {
if (isNaN(item.Location)) {
showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR", 'Location format error.'), alerttitle);
$('#adjustodomask').hide();
return;
}
else {
if (item.Location <= 0) {
showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
$('#adjustodomask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY", "Location cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
if (item.LocationDate === "") {
showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY", "Location date cannot be empty."), alerttitle);
$('#adjustodomask').hide();
return;
}
var offset = $('#dialogadjust_locationtimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var hour = $('#dialogadjust_timehour').val();
var minute = $('#dialogadjust_timeminute').val();
item.LocationDate = item.LocationDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveAdjustLocation", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
getLocations();
showAlert(GetTextByKey("P_MA_ADJUSTLOCATIONSUCCESSFULLY", "Adjust Location Successfully."), alerttitle);
}
$('#dialog_adjustlocation').hideDialog();
$('#adjustodomask').hide();
}, function (err) {
showloading(false);
showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTLOCATION", 'Failed to adjust Location.'), alerttitle);
$('#adjustodomask').hide();
});
}, function () {
$('#adjustodomask').hide();
});
}
function OnPreviewLocation() {
getLocationHisPreview();
}

View File

@ -0,0 +1,659 @@
$(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);
}

View File

@ -0,0 +1,275 @@
$(function () {
initTime();
initTimeZone();
$('#dialog_adjustodometer').dialog(function () {
showmaskbg(false);
});
$('#dialog_addodometer').dialog(function () {
showmaskbg(false);
});
$('#dialog_adjustenginehours').dialog(function () {
showmaskbg(false);
});
$('#dialog_addenginehours').dialog(function () {
showmaskbg(false);
});
$('#dialog_setprimary').dialog(function () {
showmaskbg(false);
});
$('#dialogadjust_odometerdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogadd_odometerdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogaddenginehours_date').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogenginehours_date').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$("#tdAuditEngineHours").click(auditHide);
$("#tdAuditOdometers").click(auditHide);
$("#tdAuditLocation").click(auditHide);
$("#tdAuditIdlehour").click(auditHide);
$("#tdAuditFuelused").click(auditHide);
$("#tdAuditFuelRemaining").click(auditHide);
});
function auditHide(e) {
var target = $(e.target);
if (target.data("hide") == 1) {
target.data("hide", 0);
var p = target.parent();
p.next().show();
p.next().next().show();
target.removeClass("plus").addClass("minus");
}
else {
target.data("hide", 1);
var p = target.parent();
p.next().hide();
p.next().next().hide();
target.removeClass("minus").addClass("plus");
}
}
function initTime() {
var c = $('#dialogadjust_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadjust_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadd_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadd_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogenginehours_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogenginehours_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogaddenginehours_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogaddenginehours_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
}
function initTimeZone() {
devicerequest("GetTimeZones", "", function (data) {
if (data) {
var sel = $("#dialogadjust_odometertimezone");
sel.empty();
var sel1 = $("#dialogadjust_enginehourstimezone");
sel1.empty();
var sel2 = $("#dialogadd_odometertimezone");
sel2.empty();
var sel3 = $("#dialogadd_enginehourstimezone");
sel3.empty();
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
sel.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel1.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel2.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel3.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
}
}
sel.val("UTC");
sel1.val("UTC");
sel2.val("UTC");
sel3.val("UTC");
}
}, function (err) {
});
}
function getCustomerTimeZone() {
assetrequest("GetCustomerTimeZone", contractorid, function (data) {
if (data) {
customertimezone = data.Key;
customerdatetime = data.Value;
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_odometertimezone").val(customertimezone);
$("#dialogadd_odometertimezone").val(customertimezone);
$('#dialogadjust_odometerdate').val(time);
$('#dialogadjust_timehour').val(hours);
$('#dialogadjust_timeminute').val(minutes);
$('#dialogadd_odometerdate').val(time);
$('#dialogadd_timehour').val(hours);
$('#dialogadd_timeminute').val(minutes);
$("#dialogadjust_enginehourstimezone").val(customertimezone);
$("#dialogadd_enginehourstimezone").val(customertimezone);
$('#dialogenginehours_date').val(time);
$('#dialogenginehours_timehour').val(hours);
$('#dialogenginehours_timeminute').val(minutes);
$('#dialogaddenginehours_date').val(time);
$('#dialogaddenginehours_timehour').val(hours);
$('#dialogaddenginehours_timeminute').val(minutes);
}
}, function (err) {
});
}
/************************Set As Primary**************************************/
var selectedDataSource = undefined;
var selectedType;
function openSetPrimary(type, datasource) {
selectedDataSource = datasource;
selectedType = type;
$('#dialogprimary_notes').val('');
$('#dialog_setprimary .dialog-title span.title').text('Set As Primary');
showmaskbg(true);
$('#dialog_setprimary')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_setprimary').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_setprimary').width()) / 2
})
.showDialogfixed();
$('#dialogprimary_notes').focus();
}
function OnSetPrimary() {
if (!selectedDataSource)
return;
var item = {
'Type': selectedType,
'CustomerID': contractorid,
'AssetID': machineid,
'DataSource': selectedDataSource.DataSource,
'SubSource': selectedDataSource.SubSource,
'Notes': $('#dialogprimary_notes').val()
};
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("ChangePrimaryDataSource", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'));
} else {
if (selectedType == 0) {
getOdometers();
getMachineInfo();
}
else if (selectedType == 1) {
getEnineHours();
getMachineInfo();
}
else if (selectedType == 2)
getLocations();
else if (selectedType == 3)
getIdlehours();
else if (selectedType == 4)
getFueluseds();
}
$('#dialog_setprimary').hideDialog();
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTDOMETERSETASPRIMARY", 'Failed to set as primary.'), GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'));
});
}

View File

@ -0,0 +1,444 @@
$(function () {
InitJobSiteGridData();
InitContactGridData();
InitAssetGroupGridData();
$('#dialog_addmake').dialog(function () {
showmaskbg(false);
});
$('#dialog_addmodel').dialog(function () {
showmaskbg(false);
});
$('#dialog_assetduplicates').dialog(function () {
showmaskbg(false);
});
$('#dialog_mergeasset').dialog(function () {
showmaskbg(false);
});
});
var activejobsitedata;
function GetActiveJobsites() {
devicerequest('GetActiveJobsites', contractorid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
activejobsitedata = data;
SetJobSites(jobsitsata);
}
});
}
var contactdata;
function GetContacts() {
devicerequest('GetContacts', contractorid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
contactdata = data;
SetContacts(contactids);
}
});
}
function SetJobSites(data) {
if (!activejobsitedata)
return;
for (var i = 0; i < activejobsitedata.length; i++) {
var js = activejobsitedata[i];
js.OnSite = false;
js.InJobSite = false;
js.Sugguested = false;
js.StatusText = "";
if (data && data.length > 0) {
for (var j = 0; j < data.length; j++) {
var js1 = data[j];
if (js.ID == js1.JobSiteID) {
js.OnSite = js1.OnSite;
js.InJobSite = js1.InJobSite;
js.Sugguested = js1.Sugguested;
if (js.InJobSite && !js.OnSite)
js.StatusText = "Auto-Assigned";
if (js.OnSite)
js.StatusText = "Manually-Assigned";
if (js.Sugguested && !js.InJobSite)
js.StatusText = "Current Location";
break;
}
}
}
}
ShowActiveJobSites(activejobsitedata);
}
function SetContacts(ids) {
if (!contactdata)
return;
for (var i = 0; i < contactdata.length; i++) {
var contact = contactdata[i];
contact.Assigned = false;
if (ids && ids.length > 0) {
for (var j = 0; j < ids.length; j++) {
if (contact.IID == ids[j]) {
contact.Assigned = true;
break;
}
}
}
}
ShowContacts(contactdata);
}
function ShowActiveJobSites(data) {
var onsiterows = [];
var injobsiterows = [];
var sugguestedrows = [];
var otherrows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
var fr = { Values: r };
if (r.OnSite)
onsiterows.push(fr)
else if (r.InJobSite)
injobsiterows.push(fr);
else if (r.Sugguested)
sugguestedrows.push(fr);
else
otherrows.push(fr);
}
var rows = [];
for (var i = 0; i < onsiterows.length; i++) {
rows.push(onsiterows[i]);
}
for (var i = 0; i < injobsiterows.length; i++) {
rows.push(injobsiterows[i]);
}
for (var i = 0; i < sugguestedrows.length; i++) {
rows.push(sugguestedrows[i]);
}
for (var i = 0; i < otherrows.length; i++) {
rows.push(otherrows[i]);
}
grid_jobsitedt.sortDirection = -1;
grid_jobsitedt.setData(rows);
}
var grid_jobsitedt;
function InitJobSiteGridData() {
grid_jobsitedt = new GridView('#jobsitelist');
grid_jobsitedt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'OnSite', caption: GetTextByKey("P_MA_ONSITE", "On Site"), valueIndex: 'OnSite', type: 3, css: { 'width': 60, 'text-align': 'center' } },
{ name: 'Name', caption: GetTextByKey("P_MA_JOBSITENAME", "Jobsite Name"), valueIndex: 'Name', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'StatusText', caption: GetTextByKey("P_MA_ASSIGNMENT", "Assignment"), valueIndex: 'StatusText', css: { 'width': 120, '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;
col.bgFilter = function (item) {
if (item.OnSite || item.InJobSite || item.Sugguested)
return 'silver';
}
if (list_columns[hd].type) {
col.type = list_columns[hd].type;
}
if (col.name === "OnSite") {
col.events = {
onchange: function () {
inputChanged = true;
jobsiteinputChanged = true;
}
};
col.tooltip = GetTextByKey("P_MA_ONSITETITLE", "The On Site box should only be checked if the asset has a permanent assignment not based on location. Geofence and Jobsite Add/Remove will not be triggered if checked.");
}
columns.push(col);
}
grid_jobsitedt.canMultiSelect = true;
grid_jobsitedt.columns = columns;
grid_jobsitedt.init();
grid_jobsitedt.selectedrowchanged = function (rowindex) {
var rowdata = grid_jobsitedt.source[rowindex];
if (rowdata) {
}
}
}
function ShowContacts(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
var fr = { Values: r };
rows.push(fr);
}
grid_contactdt.sortIndex = 0;//已选默认拍在前面
grid_contactdt.sortDirection = -1;
grid_contactdt.setData(rows);
}
var grid_contactdt;
function InitContactGridData() {
grid_contactdt = new GridView('#contactlist');
grid_contactdt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Assigned', caption: GetTextByKey("P_MA_ASSIGNED", "Assigned"), valueIndex: 'Assigned', type: 3, css: { 'width': 75, 'text-align': 'center' } },
{ name: 'DisplayName', caption: GetTextByKey("P_MA_CONTACTNAME", "Contact Name"), valueIndex: 'DisplayName', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'ContactTypeName', caption: GetTextByKey("P_MA_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactTypeName', 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 = 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 === "Assigned") {
col.events = {
onchange: function () {
inputChanged = true;
}
};
}
columns.push(col);
}
grid_contactdt.canMultiSelect = false;
grid_contactdt.columns = columns;
grid_contactdt.init();
grid_contactdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_contactdt.source[rowindex];
if (rowdata) {
}
}
}
function reshowgrid() {
setTimeout(function () {
$("#jobsitelist").css("height", $(window).height() - $("#jobsitelist").offset().top - 10);
grid_jobsitedt && grid_jobsitedt.resize();
$("#contactlist").css("height", $(window).height() - $("#contactlist").offset().top - 10);
grid_contactdt && grid_contactdt.resize();
});
}
/****** Groups******/
var assetgroups
var grid_assetgroups;
function InitAssetGroupGridData() {
grid_assetgroups = new GridView('#assetgrouplist');
grid_assetgroups.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'GroupName', caption: GetTextByKey("P_MA_GROUPNAME", "Group Name"), valueIndex: 'GroupName', css: { 'width': 300, '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 === "Selected") {
col.events = {
onchange: function () {
inputChanged = true;
}
};
}
columns.push(col);
}
grid_assetgroups.canMultiSelect = false;
grid_assetgroups.columns = columns;
grid_assetgroups.init();
}
function GetMachineGroups() {
$('#tbodymachinegroup').empty();
devicerequest('GetMachineGroups', contractorid + String.fromCharCode(170) + "", function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
assetgroups = data;
ShowMachineGroups(data);
}
});
}
function ShowMachineGroups() {
var rows = [];
for (var i = 0; i < assetgroups.length; i++) {
var r = assetgroups[i];
r.Selected = false
var fr = { Values: r };
rows.push(fr);
}
grid_assetgroups.setData(rows);
}
function SetMachineGroups(ids) {
if (!assetgroups)
return;
for (var i = 0; i < assetgroups.length; i++) {
var group = assetgroups[i];
group.Selected = false;
if (ids && ids.length > 0) {
for (var j = 0; j < ids.length; j++) {
if (ids[j].toLowerCase() == group.GroupID.toLowerCase()) {
group.Selected = true;
break;
}
}
}
}
grid_assetgroups.reload();
}
function reshowgroupgrid() {
setTimeout(function () {
$("#assetgrouplist").css("height", $(window).height() - $("#assetgrouplist").offset().top - 10);
grid_assetgroups && grid_assetgroups.resize();
});
}
function OnAddMake() {
showmaskbg(true);
$('#dialog_addmake')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addmake').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addmake').width()) / 2
})
.showDialog();
$('#dialog_makename').focus();
}
function OnSaveMake() {
var item = {
'Name': $.trim($('#dialog_makename').val()),
'AlterActiveName': $.trim($('#dialog_makename').val())
};
var alerttitle = GetTextByKey("P_MA_ADDMAKE", "Add Make");
item.ID = -1;
if (!item.Name || item.Name.length == 0) {
showAlert(GetTextByKey("P_MA_MAKENAMEEMPTY", 'Make name cannot be empty.'), alerttitle);
$('#dialog_makename').focus();
return;
}
$("#addmakemask").show();
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveMachineMake", param, function (data) {
if (data !== 'OK') {
showAlert(data, alerttitle);
$("#addmakemask").hide();
} else {
GetMachineMakes(item.Name);
$('#dialog_addmake').hideDialog();
showmaskbg(false);
$("#addmakemask").hide();
}
}, function (err) {
showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMAKE", 'Failed to save Make.'), alerttitle);
$("#addmakemask").hide();
});
}
function OnAddModel() {
showmaskbg(true);
$('#dialog_addmodel')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addmodel').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addmodel').width()) / 2
})
.showDialog();
$('#dialog_modelname').val("");
$('#dialog_modelname').focus();
$('#dialog_makeforaddmodel').val($('#dialog_make').val());
$('#dialog_typeforaddmodel').dropdownVal("");
}
function OnSaveModel() {
var item = {
'Name': $.trim($('#dialog_modelname').val()),
'MakeID': $.trim($('#dialog_makeforaddmodel').val()),
'TypeID': $.trim($('#dialog_typeforaddmodel').dropdownVal())
};
var alerttitle = "Add Model";
item.ID = -1;
if (!item.Name || item.Name.length == 0) {
showAlert(GetTextByKey("P_MA_MODELNAMECANNOTBEEMPTY", 'Model name cannot be empty.'), alerttitle);
$('#dialog_modelname').focus();
return;
}
$("#addmodelmask").show();
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SAVEMACHINEMODEL", param, function (data) {
if (data !== 'OK') {
showAlert(data, alerttitle);
$("#addmodelmask").hide();
} else {
GetMachineModels(item.MakeID, item.Name);
$('#dialog_addmodel').hideDialog();
$("#addmodelmask").hide();
showmaskbg(false);
}
}, function (err) {
showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMODEL", 'Failed to save model.'), alerttitle);
$("#addmodelmask").hide();
});
}

View File

@ -0,0 +1,549 @@
$(function () {
InitPMGridData();
$('#dialog_pm').dialog(function () {
showmaskbg(false);
});
});
function SetAssetItem(asset) {
$("#dialog_pm").data("asset", asset);
}
function showConfirmOKCancel(msg, title, fok, fcancel) {
showmaskbg(true);
_dialog.showConfirmOKCancel(msg, title, function (e) {
showmaskbg(false);
if (typeof fok === 'function') {
fok(e);
}
}, function () {
if (fcancel)
fcancel();
showmaskbg(false);
});
}
/****** PM******/
var pmschedules
var grid_pmschedules;
function InitPMGridData() {
grid_pmschedules = new GridView('#pmschedulelist');
grid_pmschedules.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'PmScheduleName', caption: GetTextByKey("P_MA_SCHEDULENAME", "Schedule Name"), valueIndex: 'PmScheduleName', css: { 'width': 200, 'text-align': 'left' } },
{ name: 'StartValue', caption: GetTextByKey("P_MA_INITIALSERVICEVALUE", "Initial Service Value"), valueIndex: 'StartValue', css: { 'width': 120, 'text-align': 'right' } },
{ name: 'LastAlertTimeString', caption: GetTextByKey("P_MA_LASTSERVICEDATE", "Last Service Date"), valueIndex: 'LastAlertTimeString', css: { 'width': 120, 'text-align': 'left' } },
{ name: 'ServiceName', caption: GetTextByKey("P_MA_LASTSERVICEPERFORMED", "Last Service Performed"), valueIndex: 'ServiceName', css: { 'width': 140, '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 === "Selected") {
col.events = {
onchange: function () {
if (this.Selected) {
showSetPMDialog(this);
this.Selected = false;//弹出对话框并取消勾选因为此时机器并没有真正加入到计划在对话框OK刷新列表
grid_pmschedules.reload();
}
else {
var item = this;
var msg = GetTextByKey("P_MA_REMOVEASSETFROMSCHEDULE", "Do you want to remove this asset from the schedule?");
if (item.UnMaintainedAlert && item.UnMaintainedAlert > 0) {
var msg = GetTextByKey("P_MA_REMOVEASSETFROMSCHEDULE_TIPS", "Select OK below will result in the deletion of existing unassigned PM alerts for this asset.<br/> If you do not want those alerts deleted, select CANCEL and assign appropriate alerts to a maintenance record or work order in asset health prior to deletion/removal.");
}
showConfirmOKCancel(msg, GetTextByKey("P_MA_REMOVEASSET", 'Remove Asset'), function () {
removeAssetFromPMSchedule(item);
}, function () {
item.Selected = true;
grid_pmschedules.reload();
});
}
}
};
}
columns.push(col);
}
grid_pmschedules.canMultiSelect = false;
grid_pmschedules.columns = columns;
grid_pmschedules.init();
}
function getAssetPMSchedules() {
showLoading();
assetrequest('GetPMSchedulesByAsset', machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
pmschedules = data;
ShowPMSchedules(data);
}
}, function () {
hideLoading();
});
}
function ShowPMSchedules() {
var rows = [];
for (var i = 0; i < pmschedules.length; i++) {
var r = pmschedules[i];
if (r.PmScheduleType === "HM" || r.PmScheduleType === "PM")
r.StartValue = r.StartHours;
else if (r.PmScheduleType === "ADM" || r.PmScheduleType === "RDM")
r.StartValue = r.StartOdometer;
else
r.StartValue = r.StartDateString;
var fr = { Values: r };
rows.push(fr);
}
grid_pmschedules.setData(rows);
}
function reshowpmgrid() {
setTimeout(function () {
$("#pmschedulelist").css("height", $(window).height() - $("#pmschedulelist").offset().top - 10);
grid_pmschedules && grid_pmschedules.resize();
});
}
function addAssetToPMSchedule(item) {
showLoading();
assetrequest('AddAssetToPMSchedule', JSON.stringify(item), function (data) {
hideLoading();
if (data === "OK") {
$('#dialog_pm').hideDialog();
showmaskbg(false);
getAssetPMSchedules();
}
else
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
}, function () {
hideLoading();
});
}
function removeAssetFromPMSchedule(schedule) {
var assetid = $("#dialog_pm").data("asset").ID;
var scheduleid = schedule.PmScheduleID;
showLoading();
assetrequest('RemoveAssetFromPMSchedule', JSON.stringify([assetid, scheduleid]), function (data) {
hideLoading();
if (data === "OK") {
//showAlert(data, 'Removed Successfully.');
getAssetPMSchedules();
}
else
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
}, function () {
hideLoading();
});
}
function showSetPMDialog(pmschedule) {
showmaskbg(true);
//$('#dialog_pm .dialog-title span.title').text('Set PM Schedule');
if (pmschedule) {
var contentctrl = $("#dialog_pm .dialog-content");
contentctrl.empty();
//scheduletype === "HM" || scheduletype === "RDM" || scheduletype === "TBM"
if (pmschedule.PmScheduleType === "PM" || pmschedule.PmScheduleType === "ADM") {
createAbsoluteContent(contentctrl, pmschedule);
}
else if (pmschedule.PmScheduleType === "HM" || pmschedule.PmScheduleType === "RDM") {
createRelativeContent(contentctrl, pmschedule);
}
else if (pmschedule.PmScheduleType === "TBM") {
createTBMContent(contentctrl, pmschedule);
}
}
$('#dialog_pm').css({
'top': (document.documentElement.clientHeight - $('#dialog_adjustenginehours').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_adjustenginehours').width()) / 2
}).showDialogfixed();
}
function createAbsoluteContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = getFirstLineText(pmschedule);
else
text = GetTextByKey("P_MA_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MA_ONEORMORESERVICESWASMISSEDALERTMEFOR", "One or more services was missed. Alert me for ");
contentctrl.append($("<span></span>").text(text));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
contentctrl.append($("<span> </span>").text(GetTextByKey("P_MA_NOW", " now.")));
if (pmschedule.Intervals) {
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var interval = pmschedule.Intervals[i];
if (!interval.Recurring) continue;//暂不考虑非周期性Service
selInterval.append($("<option></option>").val(interval.PmIntervalID).text(interval.ServiceName));
}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked"))
selInterval.prop("disabled", true);
else
selInterval.prop("disabled", false);
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetID = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (pmschedule.PmScheduleType === "PM")
item.StartHours = asset.EngineHours;
else {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
if (radio2 && radio2.prop("checked")) {
item.SelectedIntervalID = selInterval.val();
}
addAssetToPMSchedule(item);
});
}
function createRelativeContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = getFirstLineText(pmschedule);
else
text = GetTextByKey("P_MA_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MA_CALCULATEBASEDUPONLASTSERVICETHE", "Calculate based upon last service. The ");
contentctrl.append($("<span></span>").text(text));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
contentctrl.append($("<span></span>").text(GetTextByKey("P_MA_SERVICEWASPERFORMEDAT", " service was performed at ")));
var txtStartValue = $("<input type='text' style='width:80px;' />").prop("disabled", true);
contentctrl.append(txtStartValue);
if (pmschedule.AllIntervals) {
var asset = $("#dialog_pm").data("asset");
var value = 0;
if (pmschedule.PmScheduleType === "HM")
value = Math.round(asset.EngineHours);
else
value = Math.round(asset.Odometer);
if (isNaN(value))
value = 0;
var tempIntervals = getIntervalValues(value, pmschedule.AllIntervals);
for (var i = 0; i < tempIntervals.length; i++) {
var interval = tempIntervals[i];
selInterval.append($("<option></option>").val(interval).text(interval));
}
//for (var i = 0; i < pmschedule.AllIntervals.length; i++) {
// var interval = pmschedule.AllIntervals[i];
// selInterval.append($("<option></option>").val(interval).text(interval));
//}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked")) {
txtStartValue.prop("disabled", true);
selInterval.prop("disabled", true);
}
else {
txtStartValue.prop("disabled", false);
selInterval.prop("disabled", false);
}
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetID = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (radio1.prop("checked")) {
if (pmschedule.PmScheduleType === "HM")
item.StartHours = asset.EngineHours;
else {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
}
else {
if (pmschedule.PmScheduleType === "HM") {
item.StartHours = txtStartValue.val();
if (item.StartHours === "" || isNaN(item.StartHours))
item.StartHours = asset.EngineHours;
}
else {
item.StartOdometer = txtStartValue.val();
if (item.StartOdometer === "" || isNaN(item.StartOdometer)) {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
}
item.StartIntervalValue = selInterval.val();
}
addAssetToPMSchedule(item);
});
}
function createTBMContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MA_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = GetTextByKey("P_MA_TRIGGERANALERTASIFSERVICEISDUETODAY", "Trigger an alert as if service is due today.");
else
text = GetTextByKey("P_MA_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MA_CALCULATEBASEDUPONLASTSERVICETHELASTSERVICEDATAWAS", "Calculate based upon last service. The last service date was ");
contentctrl.append($("<span></span>").text(text));
var dateparent = $("<span></span>");
contentctrl.append(dateparent);
var txtLastServiceDate = $("<input type='text' style='width:80px;' />").prop("disabled", true);
txtLastServiceDate.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false
}).text(currentdate);
dateparent.append(txtLastServiceDate);
contentctrl.append($("<span></span>").text(GetTextByKey("P_MA_FOR", " for ")));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
if (pmschedule.Intervals) {
for (var i = 0; i < pmschedule.AllIntervals.length; i++) {
var interval = pmschedule.AllIntervals[i];
selInterval.append($("<option></option>").val(interval).text(interval));
}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked")) {
txtLastServiceDate.prop("disabled", true);
selInterval.prop("disabled", true);
}
else {
txtLastServiceDate.prop("disabled", false);
selInterval.prop("disabled", false);
}
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetId = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (radio1.prop("checked")) {
item.StartDate = nowdate;
}
else {
item.StartDate = txtLastServiceDate.val();
item.StartIntervalValue = selInterval.val();
if (item.StartDate == "")
item.StartDate = "1900-01-01";
}
addAssetToPMSchedule(item);
});
}
function hasAvailableIntervals(pmschedule) {
if (!pmschedule.Intervals || pmschedule.Intervals.length == 0)
return false;
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var ii = pmschedule.Intervals[i];
if (ii.Recurring)
return true;
}
return false;
}
function getIntervalValues(currentValue, allIntervals) {
var result = [];//取当前值的前两个和后10个Interval
if (allIntervals && allIntervals.length > 0) {
var maxInterval = allIntervals[allIntervals.length - 1];
var pervoid = parseInt(currentValue / maxInterval);
var remain = currentValue % maxInterval;
if (remain > 0)
pervoid++;
var maxpervoid = pervoid + 1;
var minpervoid = pervoid - Math.ceil(10 / allIntervals.length) - 1;//10表示向后取10
if (minpervoid < 0)
minpervoid = 0;
for (var pi = maxpervoid; pi >= minpervoid; pi--) {
for (var i = allIntervals.length - 1; i >= 0; i--) {
var interval = allIntervals[i];
var tempinterval = pi * maxInterval + interval;
result.push(tempinterval);
if (tempinterval >= currentValue) {
if (result.length > 2)
result.splice(0, 1);
}
else if (result.length == 12)
break;
}
}
}
return result;
}
function getFirstLineText(pmschedule) {
var text = "";
if (pmschedule.Intervals && pmschedule.Intervals.length > 0) {
var asset = $("#dialog_pm").data("asset");
var unit = "";
var value = 0;
if (pmschedule.PmScheduleType === "PM" || pmschedule.PmScheduleType === "HM") {
unit = "hours";
value = Math.round(asset.EngineHours);
}
else {
unit = pmschedule.PmScheduleUom;
value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
value = Math.round(value);
}
}
if (isNaN(value))
value = 0;
var minoffset = null;
var nextInterval = null;
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var ii = pmschedule.Intervals[i];
if (!ii.Recurring) continue;//暂不考虑非周期性Service
var offset = 0;
if (value == 0)
offset = ii.Interval;
else if (value % ii.Interval > 0)
offset = ii.Interval - value % ii.Interval;
if (!nextInterval || offset < minoffset) {
nextInterval = ii;
minoffset = offset;
continue;
}
if (offset == minoffset && (ii.Priority < nextInterval.Priority
|| (ii.Priority == nextInterval.Priority && ii.Interval > nextInterval.Interval)))
nextInterval = ii;
}
if (nextInterval) {
text = GetTextByKey("P_MA_THEFIRSTALERTWILLBE", "The first alert will be ");
text += nextInterval.NotificationPeriod + " " + unit;
if (value != 0 && value % nextInterval.Interval == 0)
parseInt(value / nextInterval.Interval) * nextInterval.Interval
else
value = (parseInt(value / nextInterval.Interval) + 1) * nextInterval.Interval;
text += GetTextByKey("P_MA_BEFORETHEASSETREADING", " before the asset reading ") + value + " " + unit;
text += GetTextByKey("P_MA_FOR", " for ") + nextInterval.ServiceName + ".";
}
}
return text;
}

View File

@ -0,0 +1,303 @@
$(function () {
$('#dialog_adddocument').dialog(function () {
showmaskbg(false);
});
});
function setPreviewAttachment() {
filedata = undefined;
$("#tbAssetAttas").empty();
$('#tr_document_file').hide();
$('#browseattfile').hide();
}
function getAttachments(machineid) {
$('#tbody_documents').empty();
if (!machineid) return;
showLoading();
devicerequest("GetAttachments", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
var attdata = [];
if (data && data.length > 0) {
attdata = data;
}
else
attdata = [];
sortTableData($('#tbdocuments'), attdata);
showAttachments(attdata);
}, function (err) {
hideLoading();
});
}
function onEditDocument() {
var doc = $(this).data('document');
if (!doc)
doc = $(this).parents("tr").data('document');
openAddDocument(doc);
}
function openDocumentUrl() {
var doc = $(this).parents("tr").data('document');
window.open(doc.Url);
}
function showAttachments(data) {
var trs = [];
for (var i = 0; i < data.length; i++) {
var doc = data[i];
var tr = $('<tr></tr>').data('document', doc).dblclick(onEditDocument);
var span = $('<span style="cursor:pointer;"></span>').text(doc.Name).attr('title', doc.Name).click(openDocumentUrl);
tr.append($('<td class="machinetd" style="width: 120px;"></td>').append(span));
tr.append($('<td class="machinetd" style="width: 100px;"></td>').text(doc.AddedBy).attr('title', doc.AddedBy));
tr.append($('<td class="machinetd" style="width: 80px;"></td>').text(doc.VisibleOnWorkOrder ? "Yes" : "No"));
tr.append($('<td class="machinetd" style="width: 80px;"></td>').text(doc.VisibleOnMap ? "Yes" : "No"));
tr.append($('<td class="machinetd" style="width: 80px;"></td>').text(doc.VisibleOnMobile ? "Yes" : "No"));
tr.append($('<td class="machinetd" style="width: 100px;"></td>').text(doc.AddedOnLocalStr).attr('title', doc.AddedOnLocalStr));
tr.append($('<td class="machinetd" style="width: 200px;"></td>').html(replaceHtmlText(doc.Description)).attr('title', doc.Description));
var spview = $('<span class="button_document iconview" title="' + GetTextByKey('P_MA_VIEW', 'View') + '"></span>').click(openDocumentUrl);
var spedit = $('<span class="button_document iconedit" title="' + GetTextByKey('P_MA_EDIT', 'Edit') + '"></span>').click(onEditDocument);
var spdel = $('<span class="button_document icondelete" title="' + GetTextByKey('P_MA_DELETE', 'Delete') + '"></span>').click(onDeleteDocument);;
tr.append($('<td class="machinetd" style="width: 80px;"></td>').append(spview).append(spedit).append(spdel));
trs.push(tr);
}
$('#tbody_documents').append(trs);
}
var assetdocumentid;
function openAddDocument(doc) {
setPreviewAttachment();
if (doc) {
assetdocumentid = doc.Id;
$('#tr_document_radio').hide();
$('#dialog_adddoc_name').val(doc.Name);
$('#dialog_adddoc_desc').val(doc.Description);
$('#dialog_visibleonwo').prop('checked', doc.VisibleOnWorkOrder);
$('#dialog_visibleonmap').prop('checked', doc.VisibleOnMap);
$('#dialog_visibleonmobile').prop('checked', doc.VisibleOnMobile);
if (doc.FileType.toLowerCase() === "url") {
$('#dialog_rdourl').prop('checked', true);
$('#dialog_adddoc_url').attr("disabled", true);
$('#dialog_adddoc_url').val(doc.Url);
$('#tr_document_url').show();
} else {
$('#dialog_rdofile').prop('checked', true);
$('#tr_document_url').hide();
}
}
else {
assetdocumentid = undefined;
$('#dialog_adddoc_url').attr("disabled", false);
$('#tr_document_url').show();
$('#tr_document_radio').show();
$('#dialog_adddoc_name').val('');
$('#dialog_adddoc_url').val('');
$('#dialog_adddoc_desc').val('');
$('#dialog_rdourl').prop('checked', true);
$('#dialog_visibleonwo').attr("checked", false);
$('#dialog_visibleonmap').attr("checked", false);
$('#dialog_visibleonmobile').attr("checked", false);
}
$('#dialog_adddocument .dialog-title span.title').text(GetTextByKey("P_MA_ADDITIONALDOCUMENTATION", 'Additional Documentation'));
showmaskbg(true);
$('#dialog_adddocument')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_adddocument').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_adddocument').width()) / 2
})
.showDialogfixed();
$('#dialog_adddoc_name').focus();
}
var filedata;
function BrowseAssetDocument() {
var file = $('<input type="file" style="display: none;" multiple="multiple" />');
file.change(function () {
var files = this.files;
var file = files[0];
if (file.size == 0) {
alert(GetTextByKey("P_MA_DOCUMENTTIPS", "Document size is 0kb, uploading failed."));
return false;
}
if (file.size > 50 * 1024 * 1024) {
alert(GetTextByKey("P_MA_DOCUMENTTIPS1", "Document is too large. Maximum file size is 50 MB."));
return false;
}
filedata = file;
if ($('#dialog_adddoc_name').val() === "")
$('#dialog_adddoc_name').val(file.name);
$('#tbAssetAttas').empty();
var trrecoard = $('<tr></tr>').data('file', file);
var tdfile = $('<td style=""></td>');
var filename = $("<label style='border-bottom: 1px solid;cursor:pointer;word-break: break-all;'></label>").text(file.name).click(function () {
//window.open("../filesvc.ashx?attchid=" + this.parentElement.parentElement.id + "&sourceType=assetattachment");
});
var imgDom = $('<span class="sbutton icondelete" style="padding:0;margin-left:5px;" ></span>').click(function () {
deletePreviewAssetAttachment(this);
});
tdfile.append(filename, imgDom);
trrecoard.append(tdfile).appendTo($('#tbAssetAttas'));
}).click();
}
function deletePreviewAssetAttachment(e) {
filedata = undefined;
var tr = $(e).parent().parent();
$(tr).remove();
}
function OnSaveDocument() {
if (!machineid) {
OnSave(0, false, function () {
SaveAssetDocument(filedata);
});
return;
}
else {
if (!assetdocumentid)
SaveAssetDocument(filedata);
else
UpdateAssetDocument();
}
}
function SaveAssetDocument(file) {
$('#adddocumentmask').show();
var alerttitle = GetTextByKey("P_MA_ADDITIONALDOCUMENTATION", 'Additional Documentation');
var item = {
'CustomerID': contractorid,
'AssetID': machineid,
'Name': $('#dialog_adddoc_name').val(),
'VisibleOnWorkOrder': $('#dialog_visibleonwo').is(':checked'),
'VisibleOnMap': $('#dialog_visibleonmap').is(':checked'),
'VisibleOnMobile': $('#dialog_visibleonmobile').is(':checked'),
'Description': $('#dialog_adddoc_desc').val()
};
if (item.Name === "") {
showAlert(GetTextByKey("P_MA_NAMECANNOTBEEMPTY", 'Name cannot be empty.'), alerttitle);
$('#adddocumentmask').hide();
return;
}
var type = $('input[name="rdoattachmentmode"]:checked').val();
if (type === "0") {
item.FileType = "URL";
item.Url = $('#dialog_adddoc_url').val();
if (item.Url === "") {
showAlert(GetTextByKey("P_MA_URLCANNOTBEEMPTY", 'Url cannot be empty.'), alerttitle);
$('#adddocumentmask').hide();
return;
}
}
else {
if (!file) {
showAlert(GetTextByKey("P_MA_FILECANNOTBEEMPTY", 'File cannot be empty.'), alerttitle);
$('#adddocumentmask').hide();
return;
}
item.FileType = file.name.substring(file.name.lastIndexOf("."));
}
showloading(true);
var formData = new FormData();
formData.append("iconFile", file);
formData.append("MethodName", "UploadAssetDocument");
formData.append("ClientData", htmlencode(JSON.stringify(item)));
$.ajax({
url: 'ManageMachines.aspx',
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
data: formData,
async: true,
success: function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
getAttachments(machineid);
}
$('#dialog_adddocument').hideDialog();
$('#adddocumentmask').hide();
},
error: function (err) {
showloading(false);
showAlert(err.statusText, alerttitle);
$('#adddocumentmask').hide();
}
});
}
function UpdateAssetDocument() {
$('#adddocumentmask').show();
var item = {
'Id': assetdocumentid,
'CustomerID': contractorid,
'Name': $('#dialog_adddoc_name').val(),
'VisibleOnWorkOrder': $('#dialog_visibleonwo').is(':checked'),
'VisibleOnMap': $('#dialog_visibleonmap').is(':checked'),
'VisibleOnMobile': $('#dialog_visibleonmobile').is(':checked'),
'Description': $('#dialog_adddoc_desc').val()
};
if (item.Name === "") {
showAlert(GetTextByKey("P_MA_NAMECANNOTBEEMPTY", 'Name cannot be empty.'), alerttitle);
$('#adddocumentmask').hide();
return;
}
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("UpdateAssetDocument", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_MA_ADDITIONALDOCUMENTATION", 'Additional Documentation'));
} else {
getAttachments(machineid);
}
$('#dialog_adddocument').hideDialog();
$('#adddocumentmask').hide();
}, function (err) {
showloading(false);
showAlert(err.statusText, GetTextByKey("P_MA_ADDITIONALDOCUMENTATION", 'Additional Documentation'));
$('#adddocumentmask').hide();
});
}
function onDeleteDocument() {
var alerttitle = GetTextByKey("P_MA_DELETEDOCUMENTATION", "Delete Documentation");
var doc = $(this).parents("tr").data('document');
showConfirm(GetTextByKey("P_MA_DELETEDOCUMENTTTIPS", 'Are you sure you want to delete the document?'), alerttitle, function () {
devicerequest("DeleteAttachment", contractorid + String.fromCharCode(170) + doc.Id, function (data) {
if (data !== 'OK')
showAlert(data, alerttitle);
else
getAttachments(machineid);
}, function (err) {
showAlert(GetTextByKey("P_MA_FAILEDDELETEDOCUMENT", 'Failed to delete this document.'), alerttitle);
});
});
}
function viewAttachment(attid) {
window.open("../filesvc.ashx?attchid=" + attid + "&custid=" + contractorid + "&sourceType=assetattachment");
}

View File

@ -0,0 +1,114 @@

var dialogAttachToAssets;
$(function () {
dialogAttachToAssets = new $assetselector('dialog_machines');
dialogAttachToAssets.forceSingle = true;
dialogAttachToAssets.onDialogClosed = function () {
showmaskbg(false);
};
dialogAttachToAssets.onOK = function (source, selectedIndex) {
var selectedAsset = null;
if (selectedIndex >= 0)
selectedAsset = source[selectedIndex].Values;
$("#dialog_attachtoasset").val(selectedAsset.Name).data("AttachedtoAssetId", selectedAsset.MachineID ? selectedAsset.MachineID : selectedAsset.Id);
inputChanged = true;
showmaskbg(false);
};
$("#btnSelectAttachToAsset").click(function () {
showmaskbg(true);
dialogAttachToAssets.companyId = $('#sel_contractor').val();
dialogAttachToAssets.showSelector(3, true);//与mergeasset中的showSelector冲突需设置force
});
$("#btnUnattach").click(function () {
$("#dialog_attachtoasset").val("").data("AttachedtoAssetId", null);
inputChanged = true;
});
});
function getAssetAttachmentInfo(machineid) {
showAssetAttachmentInfo(null);
if (!machineid) return;
showLoading();
assetrequest("GetAssetAttachmentInfo", contractorid + String.fromCharCode(170) + machineid, function (data) {
hideLoading();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
showAssetAttachmentInfo(data);
}, function (err) {
hideLoading();
});
}
function showAssetAttachmentInfo(attachinfo) {
if (attachinfo) {
$("#dialog_assettypetoattachto").val(attachinfo.AssetTypeToAttachTo);
$("#dialog_attachstyle").val(attachinfo.Style);
$("#dialog_attachcapacitycyd").val(attachinfo.Capacity_CYD);
$("#dialog_attachcapacityweight").val(attachinfo.Capacity_Weight);
$("#dialog_attachdimension1").val(attachinfo.Dimension1);
$("#dialog_attachdimension2").val(attachinfo.Dimension2);
$("#dialog_attacholdnumber").val(attachinfo.OldNumber);
$("#dialog_attachtomake").val(attachinfo.AttachToMake);
$("#dialog_attachtomodel").val(attachinfo.AttachToModel);
$("#dialog_attachedtoanasset").val(attachinfo.AttachedtoAsset ? "1" : "0");
$("#dialog_attachtoasset").val(attachinfo.AttachedtoAssetName).data("AttachedtoAssetId", attachinfo.AttachedtoAssetId);
}
else {
$("#dialog_assettypetoattachto").val("");
$("#dialog_attachstyle").val("");
$("#dialog_attachcapacitycyd").val("");
$("#dialog_attachcapacityweight").val("");
$("#dialog_attachdimension1").val("");
$("#dialog_attachdimension2").val("");
$("#dialog_attacholdnumber").val("");
$("#dialog_attachtomake").val("");
$("#dialog_attachtomodel").val("");
$("#dialog_attachedtoanasset").val("");
$("#dialog_attachtoasset").val("").data("AttachedtoAssetId", null);
}
}
function getAssetAttachmentInfoInput(alerttitle) {
var attachinfo = {};
attachinfo.AssetTypeToAttachTo = $("#dialog_assettypetoattachto").val();
attachinfo.Style = $("#dialog_attachstyle").val();
attachinfo.Capacity_CYD = $("#dialog_attachcapacitycyd").val();
var formattedcorrectly = GetTextByKey("P_MA_ISNOTFORMATTEDCORRECTLY", ' is not formatted correctly.');
if (attachinfo.Capacity_CYD !== "" && (isNaN(attachinfo.Capacity_CYD) || !IsNumber.test(attachinfo.Capacity_CYD))) {
showAlert(GetTextByKey("P_MA_CAPACITYCYD", 'Capacity (CYD)') + formattedcorrectly, alerttitle);
return false;
}
attachinfo.Capacity_Weight = $("#dialog_attachcapacityweight").val();
if (attachinfo.Capacity_Weight !== "" && (isNaN(attachinfo.Capacity_Weight) || !IsNumber.test(attachinfo.Capacity_Weight))) {
showAlert(GetTextByKey("P_MA_CAPACITYWEIGHT", 'Capacity (Weight)') + formattedcorrectly, alerttitle);
return false;
}
attachinfo.Dimension1 = $("#dialog_attachdimension1").val();
if (attachinfo.Dimension1 !== "" && (isNaN(attachinfo.Dimension1) || !IsNumber.test(attachinfo.Dimension1))) {
showAlert(GetTextByKey("P_MA_DIMENSION1INCM", 'Dimension #1 (in/cm)') + formattedcorrectly, alerttitle);
return false;
}
attachinfo.Dimension2 = $("#dialog_attachdimension2").val();
if (attachinfo.Dimension2 !== "" && (isNaN(attachinfo.Dimension2) || !IsNumber.test(attachinfo.Dimension2))) {
showAlert(GetTextByKey("P_MA_WIDTH", 'Width') + formattedcorrectly, alerttitle);
return false;
}
attachinfo.OldNumber = $("#dialog_attacholdnumber").val();
if (attachinfo.OldNumber !== "" && (isNaN(attachinfo.OldNumber) || !IsNumber.test(attachinfo.OldNumber))) {
showAlert(GetTextByKey("P_MA_OLDNUMBER", 'Old Number') + formattedcorrectly, alerttitle);
return false;
}
attachinfo.AttachToMake = $("#dialog_attachtomake").val();
attachinfo.AttachToModel = $("#dialog_attachtomodel").val();
attachinfo.AttachedtoAsset = $("#dialog_attachedtoanasset").val() == "1";
attachinfo.AttachedtoAssetId = $("#dialog_attachtoasset").data("AttachedtoAssetId");
return attachinfo;
}

View File

@ -0,0 +1,188 @@

var MachineAttributes = [];
function GetMachineAttributes(machineid) {
if (!contractorid)
contractorid = "";
assetrequest('GetMachineAttributes', contractorid + String.fromCharCode(170) + machineid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
MachineAttributes = data;
ShowMachineAttributes(data);
}
else
MachineAttributes = [];
});
}
function ShowMachineAttributes(categorys) {
//$('.li_attribute').remove();
//$('.divtab').remove();
$('.divtab').empty();
var ulcontainer = $('#ul_container');
var divbefore = $('#tab_pm');
var libefore = $('#li_attachmentinfo');
for (var j = 0; j < categorys.length; j++) {
var cate = categorys[j];
if (cate.TabID == 3) continue;//屏蔽Attachment Info
var cateid = "category" + j;
var tabid = "tab" + cate.TabID;
var divpage = $("#" + tabid);
var tab = null;
if (divpage.length == 0) {
var li = $('<li class="li_attribute"></li>').text(cate.TabName).attr('data-href', tabid);
libefore.after(li);
divpage = $('<div class="divtab"></div>').attr('id', tabid).attr('data-page', tabid);
divbefore.after(divpage);
}
var tab = divpage.children().eq(0);
if (tab.length == 0) {
tab = $('<table></table>');
divpage.append(tab);
}
var tr = $("<tr></tr>");
var tdcate = $('<td class="categoryname minus" colspan="2"></td>').text(" " + cate.DisplayText).data("cid", cateid).data("hide", 0);
tdcate.click(tab, function (e) {
var target = $(e.target);
if (target.data("hide") == 0) {
target.data("hide", 1);
e.data.find("." + target.data("cid")).hide();
target.removeClass("minus").addClass("plus");
}
else {
target.data("hide", 0);
e.data.find("." + target.data("cid")).show();
target.removeClass("plus").addClass("minus");
}
});
tr.append(tdcate);
tab.append(tr);
var atts = cate.MachineAttributes;
if (atts.length > 0) {
for (var i = 0; i < atts.length; i++) {
var att = atts[i];
var tr = $("<tr></tr>").addClass(cateid);
tr.append($('<td class="label"></td>').text(att.DisplayText + ":").attr("title", att.Description));
var attributeid = "attributeid_" + att.ID;
var input = $('<input type="text" />');
if (att.DataType == 0) {
if (att.Multiline)
input = $('<textarea></textarea>');
else if (att.Dropdown) {
input = $('<select style="width:204px;"></select>');
if (att.DataSource) {
var sources = att.DataSource.split(';');
for (var si in sources) {
input.append($("<option value='" + sources[si] + "'>" + sources[si] + "</option >"));
}
}
}
}
else if (att.DataType == 4) {
$(input).datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
}
else if (att.DataType == 5)
input = $('<select><option value="Yes">Yes</option ><option value="No">No</option></select>');
$(input).attr('id', 'attributeid_' + att.ID).attr('maxlength', att.Length);
$(input).val(att.Value);
$(input).change(function () {
inputChanged = true;
})
var td1 = $('<td></td>');
td1.append(input);
tr.append(td1);
tab.append(tr);
}
}
}
if (!$('#div_container').data("tabed")) {
ulcontainer.append($('<li style="clear: both;"></li>'));
$('#div_container').data("tabed", true);
$('#div_container').tab();
$(window).resize();
ulcontainer.find("li").click(function (e) {
setRightMask($(e.target).attr("data-href"));
});
}
setRightMask();
}
function ClearMachineAttributeValue() {
if (MachineAttributes) {
for (var i = 0; i < MachineAttributes.length; i++) {
var ma = MachineAttributes[i];
if (ma && ma.MachineAttributes) {
for (var j = 0; j < ma.MachineAttributes.length; j++) {
var att = ma.MachineAttributes[j];
$('#attributeid_' + att.ID).val("");
}
}
}
}
}
function getAttributeInput(alerttitle) {
var attributedata = [];
if (MachineAttributes.length > 0) {
for (var j = 0; j < MachineAttributes.length; j++) {
var atts = MachineAttributes[j].MachineAttributes;
for (var i = 0; i < atts.length; i++) {
var att = atts[i];
var attvalue = $('#attributeid_' + att.ID).val();
if (att.DataType == 1 || att.DataType == 2 || att.DataType == 3) {
if (attvalue !== "") {
if (isNaN(attvalue) || !IsNumber.test(attvalue)) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
if (att.DataType == 1 && attvalue.indexOf(".") != -1) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
else if (att.DataType == 3)
attvalue = parseFloat(attvalue).toFixed(att.Precision);
}
}
else if (att.DataType == 4) {
if (attvalue.length > 0) {
if (!checkDate(attvalue)) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
}
else {
attvalue = "";
}
}
att.Value = attvalue;
attributedata.push(att);
}
}
}
return attributedata;
}

View File

@ -0,0 +1,302 @@

//****************************设备管理和机器管理共用*****************************************/
function getDevicePairingLogsByDevice() {
$('#div_attlarge').empty();
if (deviceid) {
var cid = $('#sel_contractor').val();
devicerequest('GetDevicePairingLogsByDevice', JSON.stringify([cid, deviceid, ""]), function (data) {
if (data && typeof data != "string") {
showDevicePairingLogs(data, 0);
}
});
}
}
function getDevicePairingLogsByAsset() {
$('#div_attlarge').empty();
if (machineid) {
devicerequest('GetDevicePairingLogsByAsset', JSON.stringify([contractorid, machineid, ""]), function (data) {
if (data && typeof data != "string") {
showDevicePairingLogs(data, 1);
}
});
}
}
function OnExpendParingInfo(e) {
var t = $(e);
var tid = t.attr("target");
if (t.hasClass("iconchevrondown")) {
t.removeClass("iconchevrondown").addClass("iconchevronright");
$("#" + tid).hide();
}
else {
t.removeClass("iconchevronright").addClass("iconchevrondown");
$("#" + tid).show();
if (!t.data("loaded")) {
getPairingAttachments(t);
}
}
}
function showDevicePairingLogs(logs, type) {//0.device,1.asset
$('#div_attlarge').empty();
if (logs && logs.length > 0) {
for (var i = 0; i < logs.length; i++) {
var log = logs[i];
var trid = "paringinfo_tr" + log.Id;
var tab = $('<table class="main_table maintenance"></table>');
$('#div_attlarge').append(tab);
var tr = $('<tr style="line-height: 35px;"></tr>');
tab.append(tr);
var td = $('<td class="subtitle"></td>');
tr.append(td);
var spanexpend = $('<span class="sbutton iconchevronright woattafoldicon" target="' + trid + '" onclick="OnExpendParingInfo(this)" style="margin-left: 0; padding-right: 5px;"></span>').data('log', log).data('type', type);
td.append(spanexpend);
var spantitle = $('<span></span>').text(("Paired to {0} on {1} by {2}").replace('{0}', type === 0 ? log.AssetName : (log.SourceName + " " + log.SerialNumber)).replace('{1}', log.InstallTime_LocalStr).replace('{2}', log.InstallerName));
td.append(spantitle);
tr = $('<tr id="' + trid + '" class="tr_intervals woattafoldtr"></tr>').hide();
tab.append(tr);
td = $('<td id="paringinfo_td' + log.Id + '"></td>');
tr.append(td);
}
}
}
function getPairingAttachments(t) {
var cid = $('#sel_contractor').val();
var pairinglog = $(t).data('log');
var type = $(t).data('type');
devicerequest('GetPairingAttachments', JSON.stringify([cid, pairinglog.Id]), function (data) {
if (data && typeof data != "string") {
$(t).data('loaded', true);
showPairingAttachments(pairinglog, data, type);
}
});
}
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
function getPairingSignature(pairinglogid, logtab) {
devicerequest('GetPairingSignature', JSON.stringify(pairinglogid), function (data) {
if (data && data != null && data.length > 0) {
var logtr = $('<tr></tr>');
logtab.append(logtr);
var logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Signature: '));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>');
logtr.append(logtd);
var jpeg = data;
if (typeof (data) !== "string") {
jpeg = arrayBufferToBase64(data);
}
var imgsig = $('<img style="height: 110px;" />').attr('src', 'data:image/png;base64,' + jpeg);
$(logtd).append(imgsig);
}
});
}
function getPairingAttachmentCategory(key) {
switch (key) {
case "Odometer":
return GetTextByKey("P_XXXX", "Odometer");
case "Engine Hours":
return GetTextByKey("P_XXXX", "Engine Hours");
case "Mounting Location":
return GetTextByKey("P_XXXX", "Mounting Location");
case "Power Connection":
return GetTextByKey("P_XXXX", "Power Connection");
case "Ground Connection":
return GetTextByKey("P_XXXX", "Ground Connection");
case "Ignition Connection":
return GetTextByKey("P_XXXX", "Ignition Connection");
case "Asset Number":
return GetTextByKey("P_XXXX", "Asset Number");
case "Left Front of Asset":
return GetTextByKey("P_XXXX", "Left Front of Asset");
case "Right Rear of Asset":
return GetTextByKey("P_XXXX", "Right Rear of Asset");
case "VIN":
return GetTextByKey("P_XXXX", "VIN");
case "ESN of GPS Device":
return GetTextByKey("P_XXXX", "ESN of GPS Device");
default:
break;
}
return key;
}
var imgTypes = [".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];
var printTypes = ['.pdf', ".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];//types to be loaded to print
function showPairingAttachments(pairinglog, attas, type) {//0.device,1.asset
var ptd = $('#paringinfo_td' + pairinglog.Id);
ptd.empty();
var log = pairinglog;
//Mountion LocationEngineHoursOdometer
var divinfo = $('<div class="edit-content"></div>');
var logtab = $('<table class="tab_deviceparing"></table>');
divinfo.append(logtab);
var logtr = $('<tr></tr>');
logtab.append(logtr);
var logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Date Time:'));
logtr.append(logtd);
logtd = $('<td style="width:300px;"></td>').text(log.InstallTime_LocalStr);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Installer:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.InstallerName);
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
if (type == 0) {
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'VIN:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.AssetVIN);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Asset Name:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.AssetName);
logtr.append(logtd);
}
else {
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Device SN:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.SerialNumber);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Source:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.SourceName);
logtr.append(logtd);
}
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Engine Hours: '));
logtr.append(logtd);
logtd = $('<td></td>').text(log.EngineHours < 0 ? '' : log.EngineHours.toLocaleString());
logtr.append(logtd);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Odometer: '));
logtr.append(logtd);
logtd = $('<td></td>').text(log.Odometer < 0 ? '' : (log.Odometer.toLocaleString() + " " + log.OdometerUnit));
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Mounting Location:'));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>').text(log.MountionLocation);
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Notes: '));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>').text(log.Notes);
logtr.append(logtd);
getPairingSignature(log.Id, logtab);
ptd.append(divinfo);
if (attas && attas.length > 0) {
for (var i = 0; i < attas.length; i++) {
var att = attas[i];
var category_str = att.Category.replace(/\s+/g, '').toLowerCase();
var div_atts = $('#divatt_' + pairinglog.Id + "_" + category_str);
if (div_atts.length == 0) {
div_atts = $('<div id="divatt_' + pairinglog.Id + "_" + category_str + '" style="min-height: 80px; overflow: auto; padding-left: 20px;"></div>');
ptd.append(div_atts);
var div1 = $('<div style=" margin-top: 15px;margin-bottom:5px;"></div>');
var ext_span = $('<span style="font-weight:500;font-size:16px;"></span>').text(getPairingAttachmentCategory(att.Category));
div1.append(ext_span);
div_atts.append(div1);
}
}
for (var i = 0; i < attas.length; i++) {
var att = attas[i];
var category_str = att.Category.replace(/\s+/g, '').toLowerCase();
var div_atts = $('#divatt_' + pairinglog.Id + "_" + category_str);
var pdiv = $('<div class="divattp"></div>');
var div = createAttaDiv(att, true);
var div1 = $('<div style=" margin-top: 15px;"></div>');
var sdownload = $('<span class="attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
openDownloadFrame(e.data.FullSizeUrl + "&d=1");
});
div.append(sdownload);
pdiv.append(div);
var caption = att.FileName;
var div3 = $('<div style="text-align:center;clear:both;"></div>');
var iptcaption = $('<input type="text" style="width: 196px;height:24px;border:1px solid #fff;" class="inp_name" maxlength="200"/>').attr('data-ori', caption).val(caption);
iptcaption.data('attdata', att);
div3.append(iptcaption);
pdiv.append(div3);
div_atts.append(pdiv);
}
}
}
function createAttaDiv(att) {
var div = $('<div class="divatt"></div>').attr('title', att.FileName).attr('title', att.Notes === "" ? att.FileName : att.Notes)
if (!att.FileType || att.FileType == "") att.FileType = ".jpg";
if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0) {
var pic = $('<img class="picture"></img>').attr('src', att.ThumbnailUrl);
pic.click(att, function (e) {
window.open(e.data.FullSizeUrl, "_blank")
});
div.append(pic);
}
else {
var sdown = $('<img class="picture" />').click(att, function (e) {
window.open(e.data.FullSizeUrl);
});
setAttachemntIcon(att.FileType, sdown);
div.append(sdown);
}
return div
}
function openPrintFrame(attatype, id) {
var frame = $("<iframe style='display:none;'></iframe>");
$(document.body).after(frame);
//frame.attr("src", url);
frame.attr("src", _network.root + "Print.aspx?pt=3&at=" + attatype + "&id=" + id);
frame.on('load', function () {
setTimeout(function () {
frame.contents().find("body").css("text-align", "center");
//frame.contents().find("img").css("max-height", window.screen.availHeight).css("max-width", window.screen.availWidth);
frame.contents().find("img").css("max-height", "98%").css("max-width", "98%");
frame[0].contentWindow.print();
});
setTimeout(function () {
frame.remove();
}, 60000);
});
}
function openDownloadFrame(url) {
var frame = $("<iframe style='display:none;'></iframe>");
$(document.body).after(frame);
frame.attr("src", url);
var timer = setInterval(function () {
if (frame[0].contentDocument && (frame[0].contentDocument.readyState == "complete" || frame[0].contentDocument.readyState == 4)) {
frame.remove();
clearInterval(timer);
}
}, 5000);
}

View File

@ -0,0 +1,393 @@

var allassets;
function GetMachines() {
worequest("GetMachines", "", function (data) {
if (data && data.length > 0) {
allassets = data;
editableSelectFromAsset.setEnable(true);
editableSelectToAsset.setEnable(true);
editableSelectFromAsset.datasource = data;
editableSelectFromAsset.valuepath = "Id"
editableSelectFromAsset.displaypath = "DisplayName";
editableSelectToAsset.datasource = data;
editableSelectToAsset.valuepath = "Id"
editableSelectToAsset.displaypath = "DisplayName";
}
}, function (err) {
});
}
function openMergeAssets() {
ClearAssetDetail();
if (!allassets)
GetMachines();
showmaskbg(true);
$('#dialog_mergeassets').css({
'top': (document.documentElement.clientHeight - $('#dialog_mergeassets').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_mergeassets').width()) / 2
}).showDialogfixed();
}
function ClearAssetDetail() {
$('#tab_assetinfo').show();
$('#tab_mergeassets').hide();
$('#btn_mergenext').show();
$('#btn_mergeprevious').hide();
editableSelectFromAsset.val('');
editableSelectToAsset.val('');
$('#dialog_newhide').attr("checked", false);
$('#dialog_newonroad').attr("checked", false);
$('#dialog_newtelematics').attr("checked", false);
$('#dialog_newattachment').attr("checked", false);
$('#dialog_newpreloaded').attr("checked", false);
$('#dialog_newsn').text("");
$('#dialog_newname').text("");
$('#dialog_newname2').text("");
$('#dialog_newdevicesn').text("");
$('#dialog_newyear').text("");
$('#dialog_newmake').text("");
$('#dialog_newmodel').text("");
$('#dialog_neweqclass').text("");
$('#dialog_newtype').text("");
$('#dialog_newdescription').val("");
$('#dialog_newenginehours').text("");
$('#dialog_newodometer').text("");
$('#dialog_newaddedon').text("");
$('#dialog_newaddedby').text("");
$('#dialog_oldhide').attr("checked", false);
$('#dialog_oldonroad').attr("checked", false);
$('#dialog_oldtelematics').attr("checked", false);
$('#dialog_oldAttachment').attr("checked", false);
$('#dialog_oldpreloaded').attr("checked", false);
$('#dialog_oldsn').text("");
$('#dialog_oldname').text("");
$('#dialog_oldname2').text("");
$('#dialog_olddevicesn').text("");
$('#dialog_oldyear').text("");
$('#dialog_oldmake').text("");
$('#dialog_oldmodel').text("");
$('#dialog_oldeqclass').text("");
$('#dialog_oldtype').text("");
$('#dialog_olddescription').val("");
$('#dialog_oldenginehours').text("");
$('#dialog_oldodometer').text("");
$('#dialog_oldaddedon').text("");
$('#dialog_oldaddedby').text("");
$('.radio_both').prop('checked', true);
$('#dialog_mergenotes').val('');
}
function showAssetDetail(assetid, type) {
var contractorid = "";
if (IsDealer)
contractorid = htmlencode($.trim($('#sel_contractor').val()));
assetrequest("GetMachineInfo", contractorid + String.fromCharCode(170) + assetid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
var asset = data;
if (type === 1) {
$('#dialog_newhide').attr("checked", asset.Hidden);
$('#dialog_newonroad').attr("checked", asset.OnRoad);
$('#dialog_newtelematics').attr("checked", asset.TelematicsEnabled);
$('#dialog_newattachment').attr("checked", asset.Attachment);
$('#dialog_newpreloaded').attr("checked", asset.Preloaded);
$('#dialog_newsn').text(asset.VIN);
$('#dialog_newname').text(asset.Name);
$('#dialog_newname2').text(asset.Name2);
$('#dialog_newdevicesn').text(asset.PairedDeviceSN);
$('#dialog_newyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
$('#dialog_newmake').text(asset.MakeName);
$('#dialog_newmodel').text(asset.ModelName);
$('#dialog_neweqclass').text(asset.EQClass);
$('#dialog_newtype').text(asset.TypeName);
$('#dialog_newdescription').val(asset.Description);
$('#dialog_newenginehours').text(asset.EngineHours ? asset.EngineHours : "");
$('#dialog_newodometer').text(asset.Odometer ? asset.Odometer : "");
$('#dialog_newaddedon').text(asset.AddedOnStr);
$('#dialog_newaddedby').text(asset.AddedByUserName);
}
else {
$('#dialog_oldhide').attr("checked", asset.Hidden);
$('#dialog_oldonroad').attr("checked", asset.OnRoad);
$('#dialog_oldtelematics').attr("checked", asset.TelematicsEnabled);
$('#dialog_oldAttachment').attr("checked", asset.Attachment);
$('#dialog_oldpreloaded').attr("checked", asset.Preloaded);
$('#dialog_oldsn').text(asset.VIN);
$('#dialog_oldname').text(asset.Name);
$('#dialog_oldname2').text(asset.Name2);
$('#dialog_olddevicesn').text(asset.PairedDeviceSN);
$('#dialog_oldyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
$('#dialog_oldmake').text(asset.MakeName);
$('#dialog_oldmodel').text(asset.ModelName);
$('#dialog_oldeqclass').text(asset.EQClass);
$('#dialog_oldtype').text(asset.TypeName);
$('#dialog_olddescription').val(asset.Description);
$('#dialog_oldenginehours').text(asset.EngineHours ? asset.EngineHours : "");
$('#dialog_oldodometer').text(asset.Odometer ? asset.Odometer : "");
$('#dialog_oldaddedon').text(asset.AddedOnStr);
$('#dialog_oldaddedby').text(asset.AddedByUserName);
}
}, function (err) {
});
}
function OnNext() {
var fromasset = editableSelectFromAsset.selecteditem();
var toasset = editableSelectToAsset.selecteditem();
if (!fromasset || !toasset) {
showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE", "Please select two assets to merge."), GetTextByKey("P_MA_MERGEASSET", "Merge Asset"));
return;
}
var tips = GetTextByKey('P_MA_MERGEASSETTIPS', 'Merge asset {0} to asset {1}, please select the data to be retained:').replace('{0}', fromasset.DisplayName).replace('{1}', toasset.DisplayName);
$('#span_mergetips').text(tips);
$('.span_asseta').text(fromasset.DisplayName);
$('.span_assetb').text(toasset.DisplayName);
$('#tab_assetinfo').hide();
$('#tab_mergeassets').show();
$('#btn_mergenext').hide();
$('#btn_mergeprevious').show();
}
function OnPrevious() {
$('#tab_mergeassets').hide();
$('#tab_assetinfo').show();
$('#btn_mergenext').show();
$('#btn_mergeprevious').hide();
}
function SaveMergeAsset() {
var fromasset = editableSelectFromAsset.selecteditem();
var toasset = editableSelectToAsset.selecteditem();
if (!fromasset || !toasset) {
showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE", "Please select two assets to merge."), GetTextByKey("P_MA_MERGEASSET", "Merge Asset"));
return;
}
var contractorid = "";
if (IsDealer)
contractorid = htmlencode($.trim($('#sel_contractor').val()));
var notes = $('#dialog_mergenotes').val();
var fromassetid = fromasset.Id;
var toassetid = toasset.Id;
var items = [];
items.push({ 'Key': 0, 'Tag': 'Odometer', 'Value': $('input[name="radio_odometer"]:checked').val() });
items.push({ 'Key': 1, 'Tag': 'Engine Hours', 'Value': $('input[name="radio_enginehours"]:checked').val() });
items.push({ 'Key': 2, 'Tag': 'Location', 'Value': $('input[name="radio_location"]:checked').val() });
items.push({ 'Key': 3, 'Tag': 'Idle Hours', 'Value': $('input[name="radio_idlehours"]:checked').val() });
items.push({ 'Key': 4, 'Tag': 'Fuel Used', 'Value': $('input[name="radio_fuelused"]:checked').val() });
items.push({ 'Key': 5, 'Tag': 'Fuel Remaining', 'Value': $('input[name="radio_fuelremaining"]:checked').val() });
items.push({ 'Key': 6, 'Tag': 'Attribute', 'Value': $('input[name="radio_attribute"]:checked').val() });
items.push({ 'Key': 7, 'Tag': 'Battery', 'Value': $('input[name="radio_battery"]:checked').val() });
items.push({ 'Key': 8, 'Tag': 'Preventative Maintenance', 'Value': $('input[name="radio_pmplans"]:checked').val() });
items.push({ 'Key': 9, 'Tag': 'Jobsite', 'Value': $('input[name="radio_jobsite"]:checked').val() });
var p = [
contractorid,
fromassetid,
toassetid,
notes,
JSON.stringify(items)
];
var param = JSON.stringify(p);
$("#dialogmask").show();
assetrequest('SaveMergeAsset', param, function (data) {
if (data === "") {
showAlert(GetTextByKey('P_MA_MERGESUCCESSFULLY', 'Merge successfully.'), GetTextByKey('P_MA_MERGEASSET', 'Merge Asset'));
} else {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
}
$('#dialog_mergeassets').hideDialog();
showmaskbg(false);
$("#dialogmask").hide();
});
}
function openAssetMergeHistory() {
window.open("AssetMergeHistory.aspx");
}
//************************Begin Merge Asset(New)*********************************//
function OnMergeAsset() {
showmaskbg(true);
dialogSelectMergeAssets.exceptShareAsset = true;
dialogSelectMergeAssets.exceptSource = [machineid];
dialogSelectMergeAssets.showSelector(3, true);//与attachmentInfo中的showSelector冲突,需设置force
$('#mask_bg').css('height', '100%');
}
var mergeassetid;
var mergeasset;
function showMergeAsset() {
showmaskbg(true);
$('#dialog_mergeasset').css({
'top': (document.documentElement.clientHeight - $('#dialog_mergeasset').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_mergeasset').width()) / 2
}).showDialogfixed();
var asset = assetinfo;
$('#dialog_merge_newhide').attr("checked", asset.Hidden);
$('#dialog_merge_newonroad').attr("checked", asset.OnRoad);
$('#dialog_merge_newtelematics').attr("checked", asset.TelematicsEnabled);
$('#dialog_merge_newattachment').attr("checked", asset.Attachment);
$('#dialog_merge_newpreloaded').attr("checked", asset.Preloaded);
$('#dialog_merge_newsn').text(asset.VIN);
$('#dialog_merge_newname').text(asset.Name);
$('#dialog_merge_newname2').text(asset.Name2);
$('#dialog_merge_newdevicesn').text(asset.PairedDeviceSN);
$('#dialog_merge_newyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
$('#dialog_merge_newmake').text(asset.MakeName);
$('#dialog_merge_newmodel').text(asset.ModelName);
$('#dialog_merge_neweqclass').text(asset.EQClass);
$('#dialog_merge_newtype').text($("#dialog_type").find("option:selected").text());
$('#dialog_merge_newdescription').val(asset.Description);
$('#dialog_merge_newenginehours').text(asset.EngineHours);
$('#dialog_merge_newodometer').text(asset.Odometer);
$('#dialog_merge_newaddedon').text(asset.AddedOnStr);
$('#dialog_merge_newaddedby').text(asset.AddedByUserName);
GetAssetDatasources(asset.Id, false);
showMergeOldAsset();
GetAssetDatasources(mergeassetid, true);
}
function showMergeOldAsset() {
$("#mergeassetmask").show();
assetrequest("GetMachineInfo", contractorid + String.fromCharCode(170) + mergeassetid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
$("#mergeassetmask").hide();
return;
}
mergeasset = data;
var asset = mergeasset;
$('#dialog_merge_oldhide').attr("checked", asset.Hidden);
$('#dialog_merge_oldonroad').attr("checked", asset.OnRoad);
$('#dialog_merge_oldtelematics').attr("checked", asset.TelematicsEnabled);
$('#dialog_merge_oldAttachment').attr("checked", asset.Attachment);
$('#dialog_merge_oldpreloaded').attr("checked", asset.Preloaded);
$('#dialog_merge_oldsn').text(asset.VIN);
$('#dialog_merge_oldname').text(asset.Name);
$('#dialog_merge_oldname2').text(asset.Name2);
$('#dialog_merge_olddevicesn').text(asset.PairedDeviceSN);
$('#dialog_merge_oldyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
$('#dialog_merge_oldmake').text(asset.MakeName);
$('#dialog_merge_oldmodel').text(asset.ModelName);
$('#dialog_merge_oldeqclass').text(asset.EQClass);
$('#dialog_merge_oldtype').text(asset.Type);
$('#dialog_merge_olddescription').val(asset.Description);
$('#dialog_merge_oldenginehours').text(asset.EngineHours ? asset.EngineHours : "");
$('#dialog_merge_oldodometer').text(asset.Odometer ? asset.Odometer : "");
$('#dialog_merge_oldaddedon').text(asset.AddedOnStr);
$('#dialog_merge_oldaddedby').text(asset.AddedByUserName);
$("#mergeassetmask").hide();
}, function (err) {
$("#mergeassetmask").hide();
});
}
function onMergeUseAsset(mergetype) {
$('#dialog_mergeasset').hideDialog();
$("#mergeassetmask").hide();
DoMergeAsset(mergetype);
}
function DoMergeAsset(mergetype) {
if (mergetype == -1 || !machineid)
return;
var mid = -1;
var tomid = -1;
var msg = "";
var alerttile = "";
if (mergetype === 0) {
mid = mergeassetid;
tomid = machineid;
alerttile = GetTextByKey("P_MA_XXXXX", 'Merge Asset');
msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?');
}
else if (mergetype === 1) {
mid = machineid;
tomid = mergeassetid;
alerttile = GetTextByKey("P_MA_XXXXX", 'Merge Asset');
msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?');
}
showConfirm(msg, alerttile, function (e) {
MergeAsset(mid, tomid, mergetype);
});
}
function MergeAsset(mid, tomid, mergetype) {
showmaskbg(true);
assetrequest("MergeAsset", htmlencode(JSON.stringify([contractorid, mid, tomid, ""])), function (data) {
showmaskbg(false);
if (data != "") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
}
else {
needRefreshDataOnCancel = true;
if (mergetype === 1)
OnExit(1);
else
OnEdit();
}
}, function (err) {
showmaskbg(false);
});
}
function OnDeleteAsset() {
if (!machineid)
return;
var mid = machineid;
var alerttile = GetTextByKey("P_MA_XXXXX", 'Delete Asset');
var msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: This will delete the Asset. Are you sure you want to proceed?');
showConfirm(msg, alerttile, function (e) {
DeleteAsset(mid);
});
}
function DeleteAsset(mid) {
showmaskbg(true);
assetrequest("DeleteAssets", htmlencode(JSON.stringify([contractorid, JSON.stringify([mid]), ""])), function (data) {
showmaskbg(false);
if (data != "") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
}
else {
needRefreshDataOnCancel = true;
OnExit(1);
}
}, function (err) {
showmaskbg(false);
});
}
function GetAssetDatasources(mid, isold) {
assetrequest("GetAssetDatasources", htmlencode(JSON.stringify([contractorid, mid])), function (data) {
if (data && data.length > 0) {
var target = isold ? $("#dialog_merge_olddatasource") : $("#dialog_merge_newdatasource");
for (var i = 0; i < data.length; i++) {
target.append($("<div></div>").text(data[i]));
}
}
}, function (err) {
});
}
//**************************End Merge Asset(New)*******************************//

View File

@ -0,0 +1,324 @@

var _selectedRental = null;
$(function () {
$('#dialog_rentaldate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_projectreturndate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_returndate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_rentaltermbillingdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
});
function SetMachineRental(rental) {
//if (IsAdmin)
// $('#btnManageRentalHistory').css('display', '');
//else
// $('#btnManageRentalHistory').css('display', 'none');
//if (rental != null) {
// $('#tab_rentalconnect :input[type="text"]').attr('disabled', false);
// $('#dialog_outside').attr('disabled', false);
// $('#dialog_termunit').attr('disabled', false);
// $('#dialog_comments').attr('disabled', false);
//}
//else {
// $('#tab_rentalconnect :input[type="text"]').attr('disabled', true);
// $('#dialog_outside').attr('disabled', true);
// $('#dialog_termunit').attr('disabled', true);
// $('#dialog_comments').attr('disabled', true);
// $('#btnManageRentalHistory').css('display', 'none');
//}
if (rental != null) {
//if (rental.data)
// rental = rental.data;
$('#tab_rentalconnect').data('rentalid', rental.RentalID);
$('#dialog_outside').val(rental.Outside);
$('#dialog_vendor').val(rental.Vendor);
$('#dialog_rentalrate').val(rental.RentalRate);
$('#dialog_term').val(rental.Term);
$('#dialog_termunit').val(rental.TermUnit);
$('#dialog_rentaldate').val(rental.RentalDateStr);
$('#dialog_projectreturndate').val(rental.ProjectReturnDateStr);
$('#dialog_returndate').val(rental.ReturnDateStr);
$('#dialog_ponumber').val(rental.PONumber);
$('#dialog_comments').val(rental.Comments);
$('#dialog_rentaltermbillingdate').val(rental.RentalTermBillingDateStr);
$('#dialog_billingcycledays').val(rental.BillingCycleDays < 0 ? "" : rental.BillingCycleDays);
$('#dialog_insuredvalue').val(rental.InsuredValue);
}
else {
$('#tab_rentalconnect').data('rentalid', '');
$('#dialog_outside').val('');
$('#dialog_vendor').val('');
$('#dialog_rentalrate').val('');
$('#dialog_term').val('');
$('#dialog_termunit').val('');
$('#dialog_rentaldate').val('');
$('#dialog_projectreturndate').val('');
$('#dialog_returndate').val('');
$('#dialog_ponumber').val('');
$('#dialog_comments').val('');
$('#dialog_rentaltermbillingdate').val('');
$('#dialog_billingcycledays').val('');
$('#dialog_insuredvalue').val('');
}
}
function getRentalInput(alerttitle) {
var rentalid = $('#tab_rentalconnect').data('rentalid');
if (rentalid === "")
rentalid = -1;
var rental = {
'RentalID': rentalid,
'MachineID': machineid,
'Outside': $('#dialog_outside').val(),
'Vendor': $('#dialog_vendor').val(),
'RentalRate': $('#dialog_rentalrate').val(),
'Term': $('#dialog_term').val(),
'TermUnit': $('#dialog_termunit').val(),
'RentalDate': $('#dialog_rentaldate').val(),
'RentalDateStr': $('#dialog_rentaldate').val(),
'ProjectReturnDate': $('#dialog_projectreturndate').val(),
'ProjectReturnDateStr': $('#dialog_projectreturndate').val(),
'ReturnDate': $('#dialog_returndate').val(),
'ReturnDateStr': $('#dialog_returndate').val(),
'PONumber': $('#dialog_ponumber').val(),
'Comments': $('#dialog_comments').val(),
'RentalTermBillingDate': $('#dialog_rentaltermbillingdate').val(),
'BillingCycleDays': $('#dialog_billingcycledays').val(),
'InsuredValue': $('#dialog_insuredvalue').val()
};
if (rental.RentalRate !== "" && isNaN(rental.RentalRate)) {
showAlert(GetTextByKey("P_MA_RENTALRATEFORMATERROR", 'Rental Rate format error.'), alerttitle);
return false;
}
if (rental.RentalRate === "") {
rental.RentalRate = 0;
}
if (rental.Term === "") {
rental.Term = 0;
}
if (isNaN(rental.Term) || !IsInteger.test(rental.Term) || eval(rental.Term) < 0) {
showAlert(GetTextByKey("P_MA_RENTALTERMMUSTBEANINTEGEREQUALTOORGREATERTHAN0", 'Rental Term must be an integer equal to or greater than 0. '), alerttitle);
return false;
}
if (rental.RentalDate.length <= 0) {
showAlert(GetTextByKey("P_MA_RENTALDATECANNOTBEEMPTY", 'Rental Date cannot be empty.'), alerttitle);
return false;
}
if (rental.BillingCycleDays !== "") {
if (isNaN(rental.BillingCycleDays) || !IsInteger.test(rental.BillingCycleDays) || eval(rental.BillingCycleDays) < 0) {
showAlert(GetTextByKey("P_MA_THENUMBEROFDAYSINBILLINGCYCLEMUSTBEANINTEGEREQUALTOORGREATERTHAN0", 'The Number of Days in Billing Cycle must be an integer equal to or greater than 0.'), alerttitle);
return false;
}
} else
rental.BillingCycleDays = -1;
if (rental.InsuredValue !== "" && isNaN(rental.InsuredValue)) {
showAlert(GetTextByKey("P_MR_INSUREDVALUEFORMATERROR", 'Insured Value format error.'), alerttitle);
return false;
}
if (rental.InsuredValue === "") {
rental.InsuredValue = 0;
}
return rental;
}
var IsInteger = /^[0-9]+$/;
function SaveRental() {
if (!rentalChanged) return;
var alerttitle = "";
var rentalid = $('#tab_rentalconnect').data('rentalid');
if (rentalid === "")
rentalid = -1;
if (rentalid > 0)
alerttitle = GetTextByKey("P_MA_EDITRENTAL", "Edit Rental");
else
alerttitle = GetTextByKey("P_MA_ADDRENTAL", "Add Rental");
var rental = getRentalInput(alerttitle);
if (!rental) return;
if (!machineid) {
OnSave(0, false, function () {
getRentals(machineid);
});
return;
}
else {
DoSaveRental(rental, alerttitle);
}
}
function DoSaveRental(item, alerttitle) {
var rentaldate = new Date(item.RentalDate.replace("-", "/"));
var pjdate = new Date(item.ProjectReturnDate.replace("-", "/"));
var returndate = new Date(item.ReturnDate.replace("-", "/"));
if (rentaldate > pjdate) {
showAlert(GetTextByKey("P_MA_PROJRETURNDATEMUSTBELATERTHANRENTALDATE", "Proj. Return Date must be later than than Rental Date."), alerttitle);
return false;
}
if (rentaldate > returndate) {
showAlert(GetTextByKey("P_MA_RETURNDATEMUSTBELATERTHANRENTALDATE", "Return Date must be later than Rental Date."), alerttitle);
return false;
}
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveRental", contractorid + String.fromCharCode(170) + param, function (data) {
showloading(false);
if (typeof (data) === "string") {
if (data === "Rental dates entered overlap with another entry. Please adjust the dates.")
data = GetTextByKey("P_MA_RENTALDATESENTEREDOVERLAPWITHANOTHERENTRY", "Rental dates entered overlap with another entry. Please adjust the dates.");
showAlert(data, GetTextByKey("P_MA_SAVERENTAL", 'Save Rental'));
} else {
rentalChanged = false;
item.RentalID = data;
$('#tab_rentalconnect').data('rentalid', item.RentalID);
showAlert(GetTextByKey("P_MA_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_MA_SAVERENTAL", 'Save Rental'));
getRentals(machineid);
}
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MA_FAILEDTOSAVERENTAL", 'Failed to save Rental.'), GetTextByKey("P_MA_SAVERENTAL", 'Save Rental'));
});
}
function CancelRental() {
SetMachineRental(_selectedRental);
}
function jumpToAddRental() {
window.open("AddRental.aspx?cid=" + contractorid + "&mid=" + machineid);
}
function getRentals(machineid) {
if (!machineid)
return;
_selectedRental = null;
$("#rentalListDiv").hide();
showLoading();
devicerequest("SearchRentalsByAsset", JSON.stringify([contractorid, machineid]), function (data) {
$('#tbody_rentals').empty();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
rentalsdata = data;
$("#rentalListDiv").show();
}
else
rentalsdata = [];
sortTableData($('#tbRentals'), rentalsdata);
showRentals(rentalsdata);
SetMachineRental(_selectedRental);
hideLoading();
}, function (err) {
hideLoading();
});
}
function rentalsTrClick() {
var rental = $(this).data('rental');
SetMachineRental(rental);
_selectedRental = rental;
$('#tbody_rentals tr').removeClass('selected');
$(this).addClass('selected');
}
function showRentals(data) {
var trs = [];
for (var i = 0; i < data.length; i++) {
var rental = data[i];
var tr = $('<tr></tr>').data('rental', rental).click(rentalsTrClick);
if (rental.Selected) {
_selectedRental = rental;
tr.addClass('selected');
}
tr.append($('<td class="machinetd" style="width: 10%;"></td>').text(rental.RentalDateStr));
tr.append($('<td class="machinetd" style="width: 12%;"></td>').text(rental.ProjectReturnDateStr));
tr.append($('<td class="machinetd" style="width: 12%;"></td>').text(rental.ReturnDateStr));
//tr.append($('<td class="machinetd" style="width: 10%;"></td>').html(replaceHtmlText(rental.Outside)));
tr.append($('<td class="machinetd" style="width: 12%;"></td>').html(replaceHtmlText(rental.Vendor)));
tr.append($('<td class="machinetd" style="width: 10%;"></td>').text(rental.RentalRate));
tr.append($('<td class="machinetd" style="width: 10%;"></td>').text(rental.Term));
tr.append($('<td class="machinetd" style="width: 10%;"></td>').text(getLangTermUnit(rental.TermUnit)));
//tr.append($('<td style="width: 24%;"></td>').attr('title', rental.Comments).html(replaceHtmlText(rental.Comments)));
trs.push(tr);
}
$('#tbody_rentals').append(trs);
}
function getLangTermUnit(unit) {
var langunit = unit
if (unit === "Hourly")
langunit = GetTextByKey("P_MA_HOURLY", "Hourly");
else if (unit === "Daily")
langunit = GetTextByKey("P_MA_DAILY", "Daily");
else if (unit === "Weekly")
langunit = GetTextByKey("P_MA_WEEKLY", "Weekly");
else if (unit === "Monthly")
langunit = GetTextByKey("P_MA_MONTHLY", "Monthly");
else if (unit === "Annually")
langunit = GetTextByKey("P_MA_ANNUALLY", "Annually");
return langunit;
}
function ManageRentalHistory() {
window.open("MachineDeviceManagement.aspx?cid=" + contractorid + "&mid=" + machineid + "#nav_managrentals");
}
function AddRental() {
showRentalConfirm(GetTextByKey("P_MA_WOULDSAVECHANGES", 'Would you like to save changes?'), GetTextByKey("P_MA_RENTAL", 'Rental'),
function () {
SaveRental();//Edit
}, function () {
$('#tab_rentalconnect').data('rentalid', '');
SaveRental(); //Add
}, null);
}