/**
* To Manage Fleet
* @module Inventory
*/
/**
* This class contains functions related to show device details and their state (Operational/Non-operational/Disabled/Archive/All")
* @class ManageFleet
* @constructor
*/
//Global variables
var activeRequest_City, activeRequest_UserDetails, activeRequest, activeRequest_Edit, vSelectedRow;
//For Checking Whether Dealer Contact No. Or Van Registration No. Exist
var vDealerContactExist = false;
var vVanRegistratioNoExist = false;
//Get the value Dealer Contact No. Or Van Registration No. On Focus
var vDealerContactNoOnFocus = "";
var vRegistrationNoOnFocus = "";
//Show Message if Dealer Contact No. Or Van Registration No. is Exist
var vVanRegistrationNoExistMsg = "";
var vDealerContactNoExistMsg = "";
/**
* Function to Add Kendo Window.
* @method addKendoWindowToDiv
* @param {String} divId Id of Kendo Window
* @param {String} titleText Title Of Kendo Window
* @param {String} width width Of Kendo Window
* @param {String} left left Of Kendo Window
* @param {String} top top Of Kendo Window
* @for ManageFleet
*/
function addKendoWindowToDiv(divId, titleText, width, left) {
$(divId).kendoWindow({
width: width,
title: titleText,
modal: true,
resizable: false,
draggable: true,
position: {
top: 95,
left: left
}
});
}
/**
* Function to Enter Only Apha Numeric Character in Textbox.
* @method AlphaNumeic
* @param {Object} e Get Event Detail
* @param {Object} t Get Textbox Detail
* @for ManageFleet
*/
function AlphaNumeic(e, t) {
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
if (t.value.length == 1) {
// control keys
if ((key == null) || (key == 0) || (key == 8) ||
(key == 9) || (key == 13) || (key == 27))
return true;
else if ((("abcdefghijklmnopqrstuvwxyz").indexOf(keychar) > -1))
return true;
else
return false;
}
else {
// control keys
if ((key == null) || (key == 0) || (key == 8) ||
(key == 9) || (key == 13) || (key == 27))
return true;
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
return true;
else
return false;
}
}
/**
* Function to Set Kendo Window Title.
* @method SetKendoWindowTitle
* @param {String} divId Id of Kendo Window
* @param {String} titleText Title Of Kendo Window
* @for ManageFleet
*/
function SetKendoWindowTitle(divId, titleText) {
var dialog = $(divId).data("kendoWindow");
dialog.title(titleText);
}
/**
* Function to Close Kendo Window.
* @method closeWindow
* @param {String} divId Id of Kendo Window
* @for ManageFleet
*/
function closeWindow(divId) {
$(divId).data("kendoWindow").close();
}
/**
* Function to Get All Dealer Name According to State And City and State Must be Selected but City is optional
* @method GetDealerNameList
* @Param {Boolean} vChkValidation (Check Validation or not)
* @Param {Integer} vRowIndex Click on Dealer List Row Or Not
* @for ManageFleet
*/
function GetDealerNameList(vChkValidation, vRowIndex) {
$("#spanState").hide();
stateVal = $("#stateCombobox").val();
cityVal = $("#cityCombobox").val();
if (stateVal != 0 || vChkValidation == false) {
$("#div_load").show();
$.ajax({
type: "POST",
url: "/Inventory/GetDealerList/",
data: { sStateIdNo: stateVal, sCityIdNo: cityVal },
success: function (data) {
//Bind html
HideDealerDetailMessage();
$("#divDealerList").html(data);
//console.log(data);
//$("#btnAdd").click();
//btnCancelAddUser();
},
error: function (data) {
console.log(data);
},
complete: function (data) {
//$("#divDealerList").html(data);
//vRowIndex = 0;
//$('#tableDealerList > tbody > tr').each(function () {
// vRowIndex++;
// if ($("#hdnDealerId").val() == this.id) {
// return;
// }
//});
if (vRowIndex != -1) {
$('#tableDealerList tbody tr').eq(vRowIndex).click();
}
$("#div_load").hide();
}
});
}
else {
$("#spanState").show();
}
}
/**
* Function to Load All State on Page Load
* @method loadStateChoices
* @for ManageFleet
*/
function loadStateChoices() {
SecurityToken = securityToken;
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
$.ajax({
type: "POST",
url: WCFRESTURL.GetStateListIdWise,
data: { Token: SecurityToken, UtcMinutes: utcMinutes, UserId: UserId },
dataType: "json",
success: function (data) {
//data.push({
// StateId: 0,
// StateAlias: "-Select-"
//});
data.sort(function SortState(a, b) { // non-anonymous as you ordered...
return b.StateAlias < a.StateAlias ? 1 // if b should come earlier, push a to end
: b.StateAlias > a.StateAlias ? -1 // if b should come later, push a to begin
: 0; // a and b are equal
});
$("#stateCombobox").kendoComboBox({
dataTextField: "StateAlias",
dataValueField: "StateId",
filter: "contains",
dataSource: data,
change: function () {
// loading cities according to state id
//$("#stateCombobox").data('kendoComboBox').select(0);
loadCityChoices($("#stateCombobox").val());
}
});
},
complete: function () {
$("#stateCombobox,#cityCombobox").focus(function () {
$(this).select();
});
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
/**
* Function to Fill City According to State Id For Kendo Ui Combo.
* @method loadCityChoices
* @Param : vRowIndex Click on Dealer List Row Or Not
* @for ManageFleet
*/
function loadCityChoices(stateId) {
SecurityToken = securityToken;
utcMinutes = parseInt(UtcMinutes, 10);
UserId = userId;
if (stateId != 0) {
$.ajax({
type: "POST",
url: WCFRESTURL.GetCityListStateIdWise,
data: { Token: SecurityToken, UtcMinutes: utcMinutes, UserId: UserId, StateId: stateId },
dataType: "json",
success: function (data) {
data.push({
CityId: 0,
CityName: "-All-"
});
data.sort(function SortCity(a, b) { // non-anonymous as you ordered...
return b.CityName < a.CityName ? 1 // if b should come earlier, push a to end
: b.CityName > a.CityName ? -1 // if b should come later, push a to begin
: 0; // a and b are equal
});
$("#cityCombobox").kendoComboBox({
dataTextField: "CityName",
dataValueField: "CityId",
filter: "contains",
dataSource: data
});
},
complete: function () {
$("#cityCombobox").data("kendoComboBox").select(0);
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
}
}
/**
* Function to load city list state wise.
* @method LoadCityList
* @param {String} stateId selected state id
* @for ManageFleet
*/
function LoadCityList(stateId) {
var selectedState = $('#ddState').find('option:selected').text();
$("#stateName").val(selectedState);
var stateVal;
stateVal = $("#ddState").val();
if (stateVal != "-Select-")
stateVal = $("#ddState").val();
else
stateVal = 0;
if (stateVal != "") {
if (activeRequest_City && activeRequest_City.readystate != 4) {
activeRequest_City.abort();
}
activeRequest_City = $.ajax({
type: "GET",
url: "/UserInventory/showCityStateWise/",
data: { stateVal: stateVal },
success: function (data) {
// empty City dropdown
$("#ddCity").text("");
// by default add select text.
$("#ddCity").append($('<option></option>').val("").html("-Select-"));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter < data.list.length; counter++) {
$("#ddCity").append(
$('<option></option>').val(data.list[counter].Value).html(data.list[counter].Text));
}
}
if ($("#CityName").val() != "") {
$("#ddCity").val($("#CityName").val());
}
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* Function to load city list state wise.
* @method LoadCityListForVan
* @param {String} stateId selected state id
* @for ManageFleet
*/
function LoadCityListForVan(stateId, city) {
var selectedState = $('#ddState').find('option:selected').text();
$("#stateName").val(selectedState);
var stateVal;
stateVal = $("#ddState").val();
if (stateVal != "-Select-")
stateVal = $("#ddState").val();
else
stateVal = 0;
if (stateVal != "") {
if (activeRequest_City && activeRequest_City.readystate != 4) {
activeRequest_City.abort();
}
activeRequest_City = $.ajax({
type: "GET",
url: "/UserInventory/showCityStateWise/",
data: { stateVal: stateVal },
success: function (data) {
// empty City dropdown
$("#ddVanCity").text("");
// by default add select text.
$("#ddVanCity").append($('<option></option>').val("").html("-Select-"));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter < data.list.length; counter++) {
$("#ddVanCity").append(
$('<option></option>').val(data.list[counter].Value).html(data.list[counter].Text));
}
}
$("#ddVanCity option").filter(function () {
return this.text == city;
}).attr('selected', true);
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* Function to load City list and Update Grid.
* @method LoadCityListAndUpdateGrid
* @param {String} stateId selected state id
* @for ManageFleet
*/
function LoadCityListAndUpdateGrid(stateId) {
var selectedState = $('#ddState').find('option:selected').text();
$("#stateName").val(selectedState);
var stateVal;
stateVal = $("#ddState").val();
if (stateVal != "-Select-")
stateVal = $("#ddState").val();
else
stateVal = 0;
UpdateStateInGrid();
if (stateVal != "") {
if (activeRequest_City && activeRequest_City.readystate != 4) {
activeRequest_City.abort();
}
activeRequest_City = $.ajax({
type: "GET",
url: "/UserInventory/showCityStateWise/",
data: { stateVal: stateVal },
success: function (data) {
// empty City dropdown
$("#ddCity").text("");
// by default add select text.
$("#ddCity").append($('<option></option>').val("").html("-Select-"));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter < data.list.length; counter++) {
$("#ddCity").append(
$('<option></option>').val(data.list[counter].Value).html(data.list[counter].Text));
}
}
if ($("#CityName").val() != "") {
$("#ddCity").val($("#CityName").val());
}
$("#hdnDealerDefaultLatitude").val("");
$("#hdnDealerDefaultLongitude").val("");
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* Function to Van Update State in Grid if Dealer State Chnage in Add Mode
* @method UpdateStateInGrid
* @for ManageFleet
*/
function UpdateStateInGrid() {
var vDealerState = $('#ddState').find('option:selected').text();
var grid = $("#gridDealer").data("kendoGrid");
var datasource = grid.dataSource.data();
for (var i = 0; i <= datasource.length - 1; i++) {
datasource[i].set("VanState", vDealerState);
}
}
/**
* Function to Van Update City in Grid if Dealer City Chnage in Add Mode
* @method UpdateCityInGrid
* @for ManageFleet
*/
function UpdateCityInGrid() {
var vDealerCity = $('#ddCity').find('option:selected').text();
var grid = $("#gridDealer").data("kendoGrid");
var datasource = grid.dataSource.data();
for (var i = 0; i <= datasource.length - 1; i++) {
datasource[i].set("VanCity", vDealerCity);
}
}
/**
* Function to load city list state wise.
* @method LoadCityList
* @param {String} stateId selected state id
* @for ManageFleet
*/
function LoadCityListOnDealer(stateId) {
var selectedState = $('#ddlState').find('option:selected').text();
var stateVal;
stateVal = $("#ddlState").val();
if (stateVal != "-Select-")
stateVal = $("#ddlState").val();
else
stateVal = 0;
if (stateVal != "") {
if (activeRequest_City && activeRequest_City.readystate != 4) {
activeRequest_City.abort();
}
activeRequest_City = $.ajax({
type: "GET",
url: "/UserInventory/showCityStateWise/",
data: { stateVal: stateVal },
success: function (data) {
// empty City dropdown
$("#ddlCity").text("");
// by default add select text.
$("#ddlCity").append($('<option></option>').val("").html("-Select-"));
// add data to dropdown.
if (data.list) {
for (var counter = 0; counter < data.list.length; counter++) {
$("#ddlCity").append(
$('<option></option>').val(data.list[counter].Value).html(data.list[counter].Text));
}
}
if ($("#CityName").val() != "") {
$("#ddlCity").val($("#CityName").val());
}
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* Function to load State And City On Page Load.
* @method UpdateCityInGrid
* @for ManageFleet
*/
$(document).ready(function () {
loadStateChoices();
loadCityChoices($("#stateCombobox").val());
$("#btnDelete").hide();
});
/**
* This function create a popup for Add Van Detail.
* @method VanDetail
* @for ManageFleet
*/
function VanDetail() {
if (AllValidAddVanDetail()) {
addKendoWindowToDiv("#divCreateDealer", "Add Van Detail", "833px", 385);
// Ajax request
if (activeRequest && activeRequest.readystate != 4) {
activeRequest.abort();
}
$("#div_load").show();
activeRequest = $.ajax({
type: "POST",
url: "/Inventory/AddorEditVanDetail",
success: function (data) {
$("#divCreateDealer").parent().addClass("responsive_popup") //addClass for respond the menu
$("#divCreateDealer").html('');
$("#divCreateDealer").html('');
$("#divCreateDealer").html(data);
SetKendoWindowTitle("#divCreateDealer", "Add Van Detail");
//open form in new dialog box
$("#divCreateDealer").data("kendoWindow").open();
//$("#VanCity").val($("#ddCity option:selected").val());
$("#VanState").val($("#ddState option:selected").text());
LoadCityListForVan($("#ddState option:selected").val(), $("#ddCity option:selected").text());
//$('#VanRegistrationNo').attr('readonly', false);
$("#btnSaveVan").prop('value', 'Save');
//Set vSelectedRow = undefined so that after van added in grid no row will be selected
//it Will affect on Add Van Detail Because we get selected Row but no row is selected
vSelectedRow = undefined;
vRegistrationNoOnFocus = "";
HideVanDetailMessage();
},
complete: function () {
$("#div_load").hide();
},
error: function (data) {
console.log(data);
}
});
}
}
/**
* This function is used to Add or Edit Van Detail In Grid.
* @method btnAddVanDetail
* @for ManageFleet
*/
function btnAddVanDetail() {
HideVanDetailMessage();
var VanAlias = $("#VanAlias").val();
var VanState = $("#VanState").val();
var VanCity = $("#ddVanCity option:selected").val();;
var ModelName = $("#VanModelName").val();
var VanRegistrationNo = $("#VanRegistrationNo").cleanVal();
var ServiceEngineerName = $("#ServiceEngineerName").val();
var ServiceEngineerContactNumber = $("#ServiceEngineerContactNumber").val();
var ServiceEngineerApplicationLicenseKey = $("#ServiceEngineerApplicationLicenseKey").val();
var VanId = $("#hdnVanId").val();
var VanIsVisitedInterState = $("#VanIsVisitedInterState").is(':checked');
if (AllValidVanDetail()) {
if (vVanRegistratioNoExist == false) {
$("#div_load").show();
oDealer = {};
oDealer.VanId = VanId;
oDealer.VanAlias = VanAlias;
oDealer.VanState = VanState;
oDealer.VanCity = VanCity;
oDealer.VanModelName = ModelName;
oDealer.VanRegistrationNo = VanRegistrationNo;
oDealer.ServiceEngineerName = ServiceEngineerName;
oDealer.ServiceEngineerContactNumber = ServiceEngineerContactNumber;
oDealer.VanIsVisitedInterState = VanIsVisitedInterState;
oDealer.ServiceEngineerApplicationLicenseKey = ServiceEngineerApplicationLicenseKey;
var datasource;
var grid = $("#gridDealer").data("kendoGrid");
if (grid != null)
datasource = grid.dataSource;
if (typeof (vSelectedRow) == "undefined") {
if (VanId == 0) {
datasource.add({
VanId: oDealer.VanId, VanAlias: oDealer.VanAlias, VanState: oDealer.VanState, VanCity: oDealer.VanCity,
VanModelName: oDealer.VanModelName, VanRegistrationNo: oDealer.VanRegistrationNo, ServiceEngineerName: oDealer.ServiceEngineerName,
ServiceEngineerContactNumber: oDealer.ServiceEngineerContactNumber, VanIsVisitedInterState: oDealer.VanIsVisitedInterState,
ServiceEngineerApplicationLicenseKey: oDealer.ServiceEngineerApplicationLicenseKey
});
}
}
else {
vSelectedRow.set("VanAlias", oDealer.VanAlias);
vSelectedRow.set("VanState", oDealer.VanState);
vSelectedRow.set("VanCity", oDealer.VanCity);
vSelectedRow.set("VanModelName", oDealer.VanModelName);
vSelectedRow.set("VanRegistrationNo", oDealer.VanRegistrationNo);
vSelectedRow.set("ServiceEngineerName", oDealer.ServiceEngineerName);
vSelectedRow.set("ServiceEngineerContactNumber", oDealer.ServiceEngineerContactNumber);
vSelectedRow.set("ServiceEngineerApplicationLicenseKey", oDealer.ServiceEngineerApplicationLicenseKey);
vSelectedRow.set("VanIsVisitedInterState", oDealer.VanIsVisitedInterState);
}
closeWindow("#divCreateDealer");
$("#div_load").hide();
}
else {
jAlert(vVanRegistrationNoExistMsg, 'message');
}
}
return false;
}
/**
* This function is used Delete the Dealer.
* @method DeleteRecord
* @param {Bollean} IsDeleted Record is save or deleted
* @for ManageFleet
*/
function DeleteRecord(IsDeleted) {
//jConfirm('Are you sure that you want to delete the Dealer <b> ' + ConfirmDealerName + '</b> ?', 'Delete', function (result) {
jConfirm(MANAGE_FLEET_MESSAGES.confirmDeleteDealer + ' <b> ' + ConfirmDealerName + '</b> ?', 'Delete', function (result) {
if (result) {
SaveRecord(IsDeleted);
}
});
return false;
}
//function OnBeginManageFleet() {
// return true;
//}
/**
* This function is used Delete the Dealer.
* @method SaveRecord
* @param {Boolean} IsDeleted Record is deleted or not
* @for ManageFleet
*/
function SaveRecord(IsDeleted) {
//if (IsDeleted == true) {
// jConfirm('Are you sure that you want to delete the EOS Team Member <b> ' + ConfirmDealerName + '</b> ?', 'Delete', function (result) {
// isd
// })
//}
if (AllValid() || IsDeleted == true) {
if (vDealerContactExist == false || IsDeleted == true) {
$("#div_load").show();
var grid = $("#gridDealer").data("kendoGrid");
var datasource = grid.dataSource;
var vOrganizationId = $("#ddOrganization option:selected").val();
var vDealerName = $("#DealerDealerName").val();
var vStateId = $("#ddState option:selected").text();
var vCityId = $("#ddCity option:selected").val();
var vanList = datasource.data();
var vDealerId = $("#hdnDealerId").val();
var vNewDealerId = $("#NewDealerId").val();
var vDealerContactNo = $("#DealerContactNo").val();
var vDealerDefaultLatitude = $("#hdnDealerDefaultLatitude").val();
var vDealerDefaultLongitude = $("#hdnDealerDefaultLongitude").val();
var DealerData = {
DealerOrganizationId: vOrganizationId,
DealerDealerName: vDealerName,
DealerState: vStateId,
DealerCity: vCityId,
VanList: vanList,
DealerId: vDealerId,
DealerContactNo: vDealerContactNo,
DealerDealerDefaultLattitude: vDealerDefaultLatitude,
DealerDealerDefaultLongitude: vDealerDefaultLongitude,
IsDeleted: IsDeleted,
NewDealerId: vNewDealerId
};
$.ajax({
contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: '/Inventory/SaveManageFleet',
data: JSON.stringify(DealerData),
success: function (data) {
jAlert(data.message, 'message');
HideDealerDetailMessage();
HideVanDetailMessage();
if (IsDeleted) {
//$("#cityCombobox").data("kendoComboBox").select(0);
//$("#stateCombobox").data("kendoComboBox").select(0);
//loadStateChoices();
//loadCityChoices($("#stateCombobox").val());
document.getElementById("btnAdd").click();
GetDealerNameList(false, vRowIndex);
}
else if (data.success == false) {
//do nothing
}
else {
$("#btnAdd").show();
$("#btnDelete").show();
//alert(DealerId);
$("#hdnDealerId").val(data.DealerId);
GetDealerDetailByID(data.DealerId);
}
//$("#tableDealerList tbody tr.eq(" + vRowIndex + ")").trigger('click');
//$("#tableDealerList tbody tr.SelectedRow").trigger('click');
},
failure: function (response) {
},
complete: function () {
if ($("#stateCombobox").val() != "") {
GetDealerNameList(false, -1);
}
$("#div_load").hide();
}
});
}
else {
jAlert(vDealerContactNoExistMsg, 'message');
}
}
return false;
}
/**
*This function is used to Manage Fleet in Add Mode
* @method addDealer
* @for ManageFleet
*/
function addDealer() {
var sDealer = "";
//send ajax report to add user
$.ajax({
type: "Get",
url: "/Inventory/AddOrEditFleet/",
data: { sDealerId: sDealer },
success: function (data) {
$("#divAddOrEditFleet").html("");
$("#divAddOrEditFleet").html(data);
$("#btnAdd,#btnDelete").hide();
//$("#ddOrganization").show();
//$("#ddState").show();
//$("#ddCity").show();
//$("#DealerOrganizationName").hide();
//$("#DealerStateName").hide();
//$("#DealerCity").hide();
$("#btnSaveFleet").prop('value', 'Save');
HideDealerDetailMessage();
HideVanDetailMessage();
$("#NewDealerId").prop('readonly', false);
},
error: function (data) {
console.log(data);
}
});
}
/**
* This function is Used to Validate the Complete Control Before Saving Dealer Detail
* @method AllValid
* @for ManageFleet
*/
function AllValid() {
HideDealerDetailMessage();
var DealerOrganization = $("#ddOrganization option:selected").val();
var DealerName = $("#DealerDealerName").val();
var DealerState = $("#ddState option:selected").val();
var DealerCity = $("#ddCity option:selected").val();
var DealerContactNo = $("#DealerContactNo").val();
var DealerId = $("#NewDealerId").val();
var vResult = false;
//var grid = $("#gridDealer").data("kendoGrid");
//var datasource = grid.dataSource.data().length;
if (DealerId == "") {
$("#spnDealerId").html("*");
$("#spnDealerId").show();
}
else if (DealerId.length < 6 || DealerId.length > 8) {
$("#spnDealerId").html("Dealer SCode length should be in between 6 and 8 characters.");
$("#spnDealerId").show();
}
else if (DealerOrganization == "")
$("#spnOrganizationId").show();
else if (DealerName == "")
$("#spnDealerName").show();
else if (DealerState == "")
$("#spnDealerState").show();
else if (DealerCity == "")
$("#spnDealerCity").show();
else if (DealerContactNo == "") {
$("#spnDealerContactNo").html("*");
$("#spnDealerContactNo").show();
}
else if (DealerContactNo.length != 10) {
$("#spnDealerContactNo").html("Mobile No. should be of 10 characters.");
$("#spnDealerContactNo").show();
}
else if ($("#hdnDealerDefaultLatitude").val() == "" || $("#hdnDealerDefaultLatitude").val() == "0")
//jAlert("Please Set Dealer Location");
jAlert(MANAGE_FLEET_MESSAGES.setDealerLocation);
else if (ChkDealerStateAndCityWithVanStateVanStateAndCity() == false) {
}
else
vResult = true;
//else if (datasource == 0)
// alert("Please enter van detail");
return vResult;
}
/**
* This function is Used to Validate the Complete Control Before Saving Dealer Van Detail
* @method AllValidVanDetail
* @for ManageFleet
*/
function AllValidVanDetail() {
HideVanDetailMessage();
var VanAlias = $("#VanAlias").val();
var VanState = $("#VanState").val();
var VanCity = $("#ddVanCity option:selected").val();
var VanModelName = $("#VanModelName").val();
var VanRegistrationNo = $("#VanRegistrationNo").val();
var ServiceEngineerName = $("#ServiceEngineerName").val();
var ServiceEngineerContactNumber = $("#ServiceEngineerContactNumber").val();
var vResult = false;
if (VanAlias == "")
$("#spnVanName").show();
else if (VanState == "")
$("#spnVanState").show();
else if (VanCity == "")
$("#spanVanCity").show();
else if (VanModelName == "")
$("#spanVanModelName").show();
else if (VanRegistrationNo == "")
$("#spanVanRegistration").show();
else if (ServiceEngineerName == "")
$("#spanVanServiceEngineerName").show();
else if (ServiceEngineerContactNumber == "") {
$("#spanVanServiceEngineerContactNo").html("*");
$("#spanVanServiceEngineerContactNo").show();
}
else if (ServiceEngineerContactNumber.length != 10) {
$("#spanVanServiceEngineerContactNo").html("Mobile No. should be of 10 characters.");
$("#spanVanServiceEngineerContactNo").show();
}
else
vResult = true;
return vResult;
}
/**
* This function is Used to Check the Duplicate Contact No Of Dealer
* @method CheckDealerDupContactNo
* @for ManageFleet
*/
function CheckDealerDupContactNo() {
var sDealerDetail = "dealer";
var sDealerContactNo = $("#DealerContactNo").val();
if (vDealerContactNoOnFocus != sDealerContactNo) {
$("#div_load").show();
//send ajax report to add user
$.ajax({
type: "POST",
url: "/Inventory/CheckDealerContactNoAndVanRegistrationNo/",
data: { sDealerDetail: sDealerDetail, sDealerContactNo: sDealerContactNo },
success: function (data) {
if (data.status == "2") {
vDealerContactExist = true;
vDealerContactNoExistMsg = data.message;
jAlert(data.message, 'message');
}
else if (data.status == "1") {
vDealerContactExist = false;
}
},
error: function (data) {
console.log(data);
},
complete: function () {
$("#div_load").hide();
}
});
}
else {
vDealerContactExist = false;
}
}
/**
* This function is Used to Check the Duplicate Registration No Of Van And Also Check in grid
* @method CheckVanDupRegistrationNo
* @for ManageFleet
*/
function CheckVanDupRegistrationNo() {
var sDealerDetail = "van";
var sVanRegistrationNo = $("#VanRegistrationNo").cleanVal();
if (CheckVanRegistrationOnGrid(sVanRegistrationNo)) {
if (vRegistrationNoOnFocus != sVanRegistrationNo) {
//send ajax report to add user
$.ajax({
type: "POST",
url: "/Inventory/CheckDealerContactNoAndVanRegistrationNo/",
data: { sDealerDetail: sDealerDetail, sDealerContactNo: sVanRegistrationNo },
success: function (data) {
if (data.status == "2") {
vVanRegistratioNoExist = true;
vVanRegistrationNoExistMsg = data.message;
jAlert(data.message, 'message');
}
else if (data.status == "1") {
vVanRegistratioNoExist = false;
}
},
error: function (data) {
console.log(data);
}
});
}
else {
vVanRegistratioNoExist = false;
}
}
}
/**
* This function is Used to Check the Duplicate Registration No. in grid
* @method CheckVanRegistrationOnGrid
* @param {string} vVanRegistrationNo Van Registration that exist or not
* @for ManageFleet
*/
function CheckVanRegistrationOnGrid(vVanRegistrationNo) {
var grid = $("#gridDealer").data("kendoGrid");
datasource = grid.dataSource;
var RegistrationNoList = datasource.data();
for (var i = 0; i <= RegistrationNoList.length - 1; i++) {
if (typeof (vSelectedRow) != "undefined" && vSelectedRow.VanRegistrationNo.toUpperCase() == vVanRegistrationNo.toUpperCase()) {
vVanRegistratioNoExist = false;
return true;
}
else if (RegistrationNoList[i].VanRegistrationNo.toUpperCase() == vVanRegistrationNo.toUpperCase() && typeof (vSelectedRow) != "undefined" &&
vSelectedRow.VanRegistrationNo.toUpperCase() != vVanRegistrationNo.toUpperCase()) {
vVanRegistratioNoExist = true;
vVanRegistrationNoExistMsg = "This registration is already added by you for Van : " + RegistrationNoList[i].VanAlias;
jAlert(vVanRegistrationNoExistMsg, 'message');
return false;
}
else if (RegistrationNoList[i].VanRegistrationNo.toUpperCase() == vVanRegistrationNo.toUpperCase()) {
vVanRegistratioNoExist = true;
vVanRegistrationNoExistMsg = "This registration is already added by you for Van : " + RegistrationNoList[i].VanAlias;
jAlert(vVanRegistrationNoExistMsg, 'message');
return false;
}
}
vVanRegistratioNoExist = false;
return true;
}
/**
* This function is Used to Check Whether the Dealer State ANd city is same as Van state or city Or not
* @method ChkDealerStateAndCityWithVanStateVanStateAndCity
* @for ManageFleet
*/
function ChkDealerStateAndCityWithVanStateVanStateAndCity() {
var grid = $("#gridDealer").data("kendoGrid");
datasource = grid.dataSource;
var VanList = datasource.data();
var vStateId = $("#ddState option:selected").text();
var vCityId = $("#ddCity option:selected").val();
for (var i = 0; i <= VanList.length - 1; i++) {
if (VanList[i].VanState != vStateId) {
//jAlert("The dealer state and van state should be same. please check van : " + VanList[i].VanAlias, 'message');
jAlert(MANAGE_FLEET_MESSAGES.chkDealerVanStateCity + " " + VanList[i].VanAlias, 'message');
return false;
}
}
return true;
}
/**
* This function is Used to Hide The Validation Message For Add Van Detail
* @method AllValidAddVanDetail
* @for ManageFleet
*/
function AllValidAddVanDetail() {
HideDealerDetailMessage();
var DealerState = $("#ddState option:selected").val();
var DealerCity = $("#ddCity option:selected").val();
var vResult = false;
if (DealerState == "")
$("#spnDealerState").show();
else if (DealerCity == "" || DealerCity == "-Select-")
$("#spnDealerCity").show();
else if (vDealerContactExist == true)
jAlert(vDealerContactNoExistMsg, 'message');
else
vResult = true;
return vResult;
}
/**
* This function is Used to Perform Cancel Button On Van Detail
* @method btnUndoVanDealerDetail
* @for ManageFleet
*/
function btnUndoVanDealerDetail() {
if (typeof (vSelectedRow) != "undefined") {
if ($("#hdnVanId").val() != "" || vSelectedRow.VanAlias != "") {
$("#VanAlias").val(vSelectedRow.VanAlias);
$("#VanState").val(vSelectedRow.VanState);
$("#VanCity").val(vSelectedRow.VanCity);
$("#VanModelName").val(vSelectedRow.VanModelName);
$("#VanRegistrationNo").val(vRegNo);
$("#ServiceEngineerName").val(vSelectedRow.ServiceEngineerName);
$("#ServiceEngineerContactNumber").val(vSelectedRow.ServiceEngineerContactNumber);
$('#VanIsVisitedInterState').prop('checked', vSelectedRow.VanIsVisitedInterState);
}
}
else {
$("#VanAlias").val("");
$("#VanModelName").val("");
$("#VanRegistrationNo").val("");
$("#ServiceEngineerName").val("");
$("#ServiceEngineerContactNumber").val("");
$('#VanIsVisitedInterState').prop('checked', false);
}
return false;
}
/**
* This function is Used to Perform Cancel Button On Dealer Detail
* @method btnCancelAddUser
* @for ManageFleet
*/
function btnCancelAddUser() {
//$("#tableDealerList tbody tr.SelectedRow").trigger('click');
if (document.getElementById('tableDealerList')) {
$("#tableDealerList tbody tr.SelectedRow").trigger('click');
} else {
$("#divDealerList").html("");
$("#btnAdd").show();
}
}