171 lines
7.1 KiB
JavaScript
171 lines
7.1 KiB
JavaScript
|
|
//************************Add Engine Hours**************************************//
|
|
var isAddEH = true;
|
|
var primarydatadourceADEH;
|
|
function openAddEnginHours() {
|
|
primarydatadourceADEH = undefined;
|
|
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('');
|
|
if (assetdata.TelematicsEnabled && !assetdata.CurrentHours.IsEmpty &&
|
|
(assetdata.CurrentHours.DataSource.toLowerCase() == "calamp" || assetdata.CurrentHours.DataSource.toLowerCase() == "pedigree")) {
|
|
isAddEH = false;
|
|
primarydatadourceADEH = assetdata.CurrentHours.DataSource;
|
|
}
|
|
else
|
|
isAddEH = true;
|
|
|
|
$('#dialog_addenginehours .dialog-title span.title').text(isAddEH ? GetTextByKey("P_MV_ADDENGINEHOURS", 'Add Engine Hours') : GetTextByKey("P_MV_ADJUSTENGINEHOURS", 'Adjust 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 = isAddEH ? GetTextByKey("P_MV_ADDENGINEHOURS", 'Add Engine Hours') : GetTextByKey("P_MV_ADJUSTENGINEHOURS", 'Adjust Engine Hours');
|
|
var item = {
|
|
'CustomerID': contractorid,
|
|
'AssetID': assetid,
|
|
'EngineHours': $('#dialogaddgenginehours_enginehours').val(),
|
|
'EngineHoursDate': $('#dialogaddenginehours_date').val(),
|
|
'Notes': $('#dialogaddenginehours_Notes').val(),
|
|
'DataSource': primarydatadourceADEH
|
|
};
|
|
if (item.EngineHours !== "") {
|
|
if (isNaN(item.EngineHours)) {
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSFORMATERROR", 'Engine Hours format error.'), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
return;
|
|
}
|
|
else {
|
|
if (item.EngineHours <= 0) {
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSMUSTBEGREATERTHAN0", 'Engine Hours must be greater than 0.'), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSCANNOTBEEMPTY", "Engine Hours cannot be empty."), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
return;
|
|
}
|
|
|
|
if (item.EngineHoursDate === "") {
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSDATECANNOTBEEMPTY", "Engine Hours Date cannot be empty."), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
return;
|
|
}
|
|
var offset = $('#dialogadd_enginehourstimezone').find("option:selected").attr("offset");
|
|
item.OffsetMinute = offset;
|
|
var timezonetext = $('#dialogadd_enginehourstimezone').find("option:selected").text();
|
|
var hour = $('#dialogaddenginehours_timehour').val();
|
|
var minute = $('#dialogaddenginehours_timeminute').val();
|
|
item.EngineHoursDate = item.EngineHoursDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
|
|
|
|
var time = hour + ":" + minute
|
|
var alertmsg = "";
|
|
if (isAddEH) {
|
|
alertmsg = GetTextByKey("P_MV_UPDATEENGINEHOURS", "Do you want to update the engine hours to reflect: {0} hours at {1} {2}?").replace('{0}', item.EngineHours).replace('{1}', time).replace('{2}', timezonetext);
|
|
}
|
|
else {
|
|
alertmsg = GetTextByKey("P_MV_UPDATEENGINEHOURS1", "If you proceed, engine hours will be updated to reflect: {0} hours at {1} <br/>" +
|
|
" {2}. <br/><br/>Note that this asset is telematic enabled and the primary data source is {3}." +
|
|
"<br/><br/> Would you like to proceed?").replace('{0}', item.EngineHours).replace('{1}', time).replace('{2}', timezonetext).replace('{3}', assetdata.CurrentHours.DataSourceName);
|
|
}
|
|
|
|
showConfirm1(alertmsg, alerttitle, function () {
|
|
$('#addenginehoursmask').hide();
|
|
if (isAddEH)
|
|
AddManuallyInputEngineHours(item, alerttitle);
|
|
else
|
|
CheckEngineHourMinimumTime(item, alerttitle);
|
|
|
|
}, function () {
|
|
$('#addenginehoursmask').hide();
|
|
});
|
|
}
|
|
|
|
|
|
function AddManuallyInputEngineHours(item, alerttitle) {
|
|
showloading(true);
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
|
|
devicerequest("AddManuallyInputEngineHours", param, function (data) {
|
|
showloading(false);
|
|
if (data !== 'OK') {
|
|
showAlert(data, alerttitle);
|
|
} else {
|
|
loadAssetInfo();
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle);
|
|
}
|
|
|
|
$('#dialog_addenginehours').hideDialog();
|
|
$('#addenginehoursmask').hide();
|
|
}, function (err) {
|
|
console.log(err);
|
|
showloading(false);
|
|
showAlert(GetTextByKey("P_MV_FAILEDTOADDENGINEHOURS", 'Failed to add Engine Hours.'), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
});
|
|
}
|
|
|
|
function CheckEngineHourMinimumTime(item, alerttitle) {
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
devicerequest("CheckEngineHourMinimumTime", param, function (data) {
|
|
if (data > 0) {
|
|
if (data == 1)
|
|
showAlert(GetTextByKey("P_MV_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."), alerttitle);
|
|
else
|
|
showAlert(GetTextByKey("P_MV_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."), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
return;
|
|
} else {
|
|
SaveAdjustEngineHours(item, alerttitle);
|
|
}
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
function SaveAdjustEngineHours(item, alerttitle) {
|
|
showloading(true);
|
|
var param = JSON.stringify(item);
|
|
param = htmlencode(param);
|
|
|
|
devicerequest("SaveAdjustEngineHours", param, function (data) {
|
|
showloading(false);
|
|
if (data !== 'OK') {
|
|
showAlert(data, alerttitle);
|
|
} else {
|
|
loadAssetInfo();
|
|
showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle);
|
|
}
|
|
|
|
$('#dialog_addenginehours').hideDialog();
|
|
$('#addenginehoursmask').hide();
|
|
}, function (err) {
|
|
console.log(err);
|
|
showloading(false);
|
|
showAlert(GetTextByKey("P_MV_FAILEDTOADJUSTENGINEHOURS", 'Failed to adjust Engine Hours.'), alerttitle);
|
|
$('#addenginehoursmask').hide();
|
|
});
|
|
} |