//************************Add Engine Hours**************************************// var isAddEH = true; var primarydatadourceMVEH; var assetdataEH; function openAddEnginHours(asset) { primarydatadourceMVEH = undefined; assetdataEH = asset; 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 (assetdataEH.TelematicsEnabled && !assetdataEH.EngineHours.IsEmpty && (assetdataEH.EngineHours.DataSource.toLowerCase() == "calamp" || assetdataEH.EngineHours.DataSource.toLowerCase() == "pedigree")) { isAddEH = false; primarydatadourceMVEH = assetdataEH.EngineHours.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 contractorid = $("#selContractor").val(); if (!contractorid) contractorid = ""; var item = { 'CustomerID': contractorid, 'AssetID': assetdataEH.Id, 'EngineHours': $('#dialogaddgenginehours_enginehours').val(), 'EngineHoursDate': $('#dialogaddenginehours_date').val(), 'Notes': $('#dialogaddenginehours_Notes').val(), 'DataSource': primarydatadourceMVEH }; if (item.EngineHours !== "") { if (isNaN(item.EngineHours)) { _dialog.showAlert(GetTextByKey("P_MV_ENGINEHOURSFORMATERROR", 'Engine Hours format error.'), alerttitle); $('#addenginehoursmask').hide(); return; } else { if (item.EngineHours <= 0) { _dialog.showAlert(GetTextByKey("P_MV_ENGINEHOURSMUSTBEGREATERTHAN0", 'Engine Hours must be greater than 0.'), alerttitle); $('#addenginehoursmask').hide(); return; } } } else { _dialog.showAlert(GetTextByKey("P_MV_ENGINEHOURSCANNOTBEEMPTY", "Engine Hours cannot be empty."), alerttitle); $('#addenginehoursmask').hide(); return; } if (item.EngineHoursDate === "") { _dialog.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}
" + " {2}.

Note that this asset is telematic enabled and the primary data source is {3}." + "

Would you like to proceed?").replace('{0}', item.EngineHours).replace('{1}', time).replace('{2}', timezonetext).replace('{3}', assetdataEH.EngineHours.DataSourceName); } showConfirm1(alertmsg, alerttitle, function () { $('#addenginehoursmask').hide(); if (isAddEH) AddManuallyInputEngineHours(item, alerttitle); else CheckEngineHourMinimumTime(item, alerttitle); }, function () { $('#addenginehoursmask').hide(); }); } function AddManuallyInputEngineHours(item, alerttitle) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("AddManuallyInputEngineHours", param, function (data) { if (data !== 'OK') { _dialog.showAlert(data, alerttitle); } else { //loadAssetInfo(); _dialog.showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle); } $('#dialog_addenginehours').hideDialog(); $('#addenginehoursmask').hide(); }, function (err) { console.log(err); _dialog.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) _dialog.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 _dialog.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) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustEngineHours", param, function (data) { if (data !== 'OK') { _dialog.showAlert(data, alerttitle); } else { //loadAssetInfo(); _dialog.showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle); } $('#dialog_addenginehours').hideDialog(); $('#addenginehoursmask').hide(); }, function (err) { console.log(err); _dialog.showAlert(GetTextByKey("P_MV_FAILEDTOADJUSTENGINEHOURS", 'Failed to adjust Engine Hours.'), alerttitle); $('#addenginehoursmask').hide(); }); }