//************************Add Odometer**************************************// var isAddOdo = true; var primarydatadourceMVOdo; var assetdataOdo; function openAddOdometer(asset) { primarydatadourceMVOdo = undefined; assetdataOdo = 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]; $('#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(''); if (assetdataOdo.TelematicsEnabled && !assetdataOdo.Odometer.IsEmpty && (assetdataOdo.Odometer.DataSource.toLowerCase() == "calamp" || assetdataOdo.Odometer.DataSource.toLowerCase() == "pedigree")) { isAddOdo = false; primarydatadourceMVOdo = assetdataOdo.Odometer.DataSource; } else isAddOdo = true; $('#dialog_addodometer .dialog-title span.title').text(isAddOdo ? GetTextByKey("P_MV_ADDODOMETER", 'Add Odometer') : GetTextByKey("P_MV_ADJUSTODOMETER", 'Adjust 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 alerttitle = isAddOdo ? GetTextByKey("P_MV_ADDODOMETER", 'Add Odometer') : GetTextByKey("P_MV_ADJUSTODOMETER", 'Adjust Odometer'); var contractorid = $("#selContractor").val(); if (!contractorid) contractorid = ""; var item = { 'CustomerID': contractorid, 'AssetID': assetdataOdo.Id, 'Odometer': $('#dialogadd_odometer').val(), 'UOM': $('#dialogadd_sel_odometeruom').val(), 'OdometerDate': $('#dialogadd_odometerdate').val(), 'Notes': $('#dialogadd_notes').val(), 'DataSource': primarydatadourceMVOdo }; if (item.Odometer !== "") { if (isNaN(item.Odometer)) { _dialog.showAlert(GetTextByKey("P_MV_ODOMETERFORMATERROR", 'Odometer format error.'), alerttitle); $('#addodomask').hide(); return; } else { if (item.Odometer <= 0) { _dialog.showAlert(GetTextByKey("P_MV_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#addodomask').hide(); return; } } } else { _dialog.showAlert(GetTextByKey("P_MV_ODOMETRCANNOTBEEMPTY", "Odometer cannot be empty."), alerttitle); $('#addodomask').hide(); return; } if (item.OdometerDate === "") { _dialog.showAlert(GetTextByKey("P_MV_ODOMETRDATACANNOTBEEMPTY", "Odometer date cannot be empty."), alerttitle); $('#addodomask').hide(); return; } var offset = $('#dialogadd_odometertimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var timezonetext = $('#dialogadd_enginehourstimezone').find("option:selected").text(); var hour = $('#dialogadd_timehour').val(); var minute = $('#dialogadd_timeminute').val(); item.OdometerDate = item.OdometerDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; var time = hour + ":" + minute var alertmsg = ""; if (isAddOdo) { alertmsg = GetTextByKey("P_MV_UPDATETHEODOMETER", "Do you want to update the odometer to reflect: {0} {1} at {2} {3}?").replace('{0}', item.Odometer).replace('{1}', item.UOM).replace('{2}', time).replace('{3}', timezonetext); } else { alertmsg = GetTextByKey("P_MV_UPDATETHEODOMETER1", "If you proceed, odometer will be updated to reflect: {0} {1} at {2}
{3}.

Note that this asset is telematic enabled and the primary data source is {4}.

Would you like to proceed?").replace('{0}', item.Odometer).replace('{1}', item.UOM).replace('{2}', time).replace('{3}', timezonetext).replace('{4}', assetdataOdo.Odometer.DataSourceName); } showConfirm1(alertmsg, alerttitle, function () { $('#addodomask').hide(); if (isAddOdo) AddManuallyInputOdometer(item, alerttitle); else CheckOdometerMinnimumTime(item, alerttitle); }, function () { $('#addodomask').hide(); }); } function AddManuallyInputOdometer(item, alerttitle) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("AddManuallyInputOdometer", param, function (data) { if (data !== 'OK') { _dialog.showAlert(data, alerttitle); } else { //loadAssetInfo(); _dialog.showAlert(GetTextByKey("P_MV_ODOMETERUPDATESUCCESSFUL", "Odometer Update Successful."), alerttitle); } $('#dialog_addodometer').hideDialog(); $('#addodomask').hide(); }, function (err) { _dialog.showAlert(GetTextByKey("P_MV_FAILEDTOADDODOMETER", 'Failed to add Odometer.'), alerttitle); $('#addodomask').hide(); }); } function CheckOdometerMinnimumTime(item, alerttitle) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("CheckOdometerMinnimumTime", param, function (data) { if (data > 0) { if (data == 1) _dialog.showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME", "The adjustment cannot be completed as provided. The odometer reading date provided cannot be prior to initial telematic data available for the asset."), alerttitle); else _dialog.showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME1", "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."), alerttitle); $('#addodomask').hide(); return; } else { SaveAdjustOdometer(item, alerttitle); } }, function (err) { }); } function SaveAdjustOdometer(item, alerttitle) { var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustOdometer", param, function (data) { if (data !== 'OK') { _dialog.showAlert(data, alerttitle); } else { //loadAssetInfo(); _dialog.showAlert(GetTextByKey("P_MV_ODOMETERUPDATESUCCESSFUL", "Odometer Update Successful."), alerttitle); } $('#dialog_addodometer').hideDialog(); $('#addodomask').hide(); }, function (err) { _dialog.showAlert(GetTextByKey("P_MV_FAILEDTOADJUSTODOMETER", 'Failed to adjust Odometer.'), alerttitle); $('#addodomask').hide(); }); }