EOS/Scripts/Inventory/ManageFleet.js
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

1577 lines
52 KiB
JavaScript

/**
* 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 = "";
//For Checking Whether Van Contact No. Exist
var vVanContactNoExist = false;
var vVanContactNoExistMsg = "";
/**
* 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) {
if (divId == "divShowDealerLocation") {
$('#searchLocationTool').html('');
}
$(divId).data("kendoWindow").close();
}
function ReleaseIMEI() {
var txtReleaseIMEI = $("#inpReleaseIMEI").val();
$("#spanReleaseIMEI").hide();
if (txtReleaseIMEI == "") {
$("#spanReleaseIMEI").show();
}
else {
$.ajax({
type: "POST",
url: "/Inventory/ReleaseIMEI/",
data: { IMEI: txtReleaseIMEI },
success: function (data) {
if(data.success)
jAlert(data.message, 'Message');
else
jAlert(data.message, 'Warning');
},
error: function (data) {
jAlert(data.message, 'Error');
},
complete: function (data) {
}
});
}
}
/**
* Function to Get All Dealer Name According to State And City and State Must be Selected but City is optional i.e. All
* @method GetDealerNameList
* @Param {Boolean} vChkValidation (Check Validation or not)
* @Param {Integer} vRowIndex Click on Dealer List Row Or Not
* @for ManageFleet
*/
function getdealernamesFuelType() {
//var request = new RestRequest("Api/Global?dealer=&dealer1=&dealer2=&dealer3=", Method.POST);
//request.AddParameter("Token", _securityToken);
//request.AddParameter("UserId", sUserName);
//request.AddParameter("DealerStateParam", sStateName);
//request.AddParameter("DealerCityParam", sCityName);
var stateVal = $("#stateCombobox").val();
var cityVal = $("#cityCombobox").val();
var fueltype = $("#fueltypeCombobox").val();
var apiUrl = url + "Api/Admin?dealer=&dealer1=&dealer2";
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: securityToken, UserId: userId, DealerStateParam: stateVal, DealerCityParam: cityVal, fuel_type: fueltype},
success: function (data) {
var keyVar;
var html = "";
$('#tableDealerList').html('');
html = "<tbody>";
for (keyVar in data) {
if (data.hasOwnProperty(keyVar)) {
var strname = "";
var strfuel = "";
if (data[keyVar].FuelType == null) {
}
else {
array = data[keyVar].FuelType.split(',');
for (i in array) {
strfuel += (array[i].charAt(0)).toUpperCase()+",";
}
}
strfuel = strfuel.replace(/,\s*$/, "");
if (strfuel == "" || strfuel == null) {
strfuel = "";
}
else {
strfuel = "(" + strfuel + ")";
}
//alert(strfuel);
html += "<tr id=" + data[keyVar].DealerId + " data-username='" + data[keyVar].DealerDealerName + "(" + data[keyVar].DealerContactNo + ")' class=\"Admin_Wrp\">";
html += "<td class=\"Row1 prelative\"> <div><div class=\"LftPanel\"><label>" + data[keyVar].DealerDealerName + "(" + data[keyVar].DealerContactNo + ") " + strfuel+"</label>";
html += "<img src=\"/Content/css/images/workshop.png\" alt=\"workshop\" border=\"0\" class=\"workshopIcon\" ></div ></div ></td ></tr > ";
}
//alert(html);
html += "</tbody>";
/// FuelType = s.Field < string > ("_fuel_type"),
$('#tableDealerList').html(html);
}
},
complete: function () {
showDealerDetails();
} });
}
function GetDealerNameList(vChkValidation, vRowIndex) {
$("#spanState").hide();
stateVal = $("#stateCombobox").val();
cityVal = $("#cityCombobox").val();
//Session["UserName"] = fuel_type;
//stateVal = stateVal + '||' +
if (stateVal != 0 || vChkValidation == false) {
$("#div_load").show();
$.ajax({
type: "POST",
url: "/Inventory/GetDealerList/",
data: { sStateIdNo: stateVal, sCityIdNo: cityVal },
success: function (data) {
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 to get the Dealer List According to state
* @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 getting Dealer List
* @method loadCityChoices
* @Param : vRowIndex Click on Dealer List Row Or Not
* @for ManageFleet
*/
function loadfuelType() {
var fueltype = [];
fueltype.push({
productId: "Diesel/CNG",
productAlias: "Diesel/CNG"
});
fueltype.push({
productId: "Electric",
productAlias: "Electric"
});
fueltype.push({
productId: "Diesel/CNG/Electric",
productAlias: "Diesel/CNG/Electric"
});
fueltype.push({
productId: "All",
productAlias: "All"
});
$("#fueltypeCombobox").kendoComboBox({
dataTextField: "productId",
dataValueField: "productAlias",
filter: "contains",
dataSource: fueltype,
change: function () {
// loading cities according to state id
//$("#stateCombobox").data('kendoComboBox').select(0);
loadStateByFuelType($("#fueltypeCombobox").val());
}
});
}
function loadfuelTypeDealer() {
var fueltype = [];
fueltype.push({
productId: "Diesel/CNG",
productAlias: "Diesel/CNG"
});
fueltype.push({
productId: "Electric",
productAlias: "Electric"
});
fueltype.push({
productId: "Diesel/CNG/Electric",
productAlias: "Diesel/CNG/Electric"
});
$("#fueltypeComboboxDealer").kendoComboBox({
dataTextField: "productId",
dataValueField: "productAlias",
filter: "contains",
dataSource: fueltype,
change: function () {
}
});
}
function loadfuelTypeVan() {
var fueltype = [];
var delaerfueltype = $('#fueltypeComboboxDealer').val();
if (delaerfueltype == "Diesel/CNG") {
fueltype = [];
fueltype.push({
productId: "Diesel/CNG",
productAlias: "Diesel/CNG"
});
}
if (delaerfueltype == "Electric") {
fueltype = [];
fueltype.push({
productId: "Electric",
productAlias: "Electric"
});
}
if (delaerfueltype == "Diesel/CNG/Electric") {
fueltype = [];
fueltype.push({
productId: "Diesel/CNG",
productAlias: "Diesel/CNG"
});
fueltype.push({
productId: "Electric",
productAlias: "Electric"
});
fueltype.push({
productId: "Diesel/CNG/Electric",
productAlias: "Diesel/CNG/Electric"
});
}
$("#fueltypeComboboxVan").kendoComboBox({
dataTextField: "productId",
dataValueField: "productAlias",
filter: "contains",
dataSource: fueltype,
change: function () {
}
});
}
function loadStateByFuelType(fueltype) {
SecurityToken = securityToken;
utcMinutes = parseInt(UtcMinutes, 10);
var apiUrl = url + "Api/Admin?state=s&state1=s&state2=tt&state3=yes&state4=yes";
//alert(apiUrl);
UserId = userId;
$.ajax({
type: "POST",
url: apiUrl,
data: { Token: SecurityToken, UtcMinutes: utcMinutes, UserId: UserId, StateAlias: fueltype },
dataType: "json",
success: function (data) {
// alert(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 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 For Van.
* @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 () {
loadfuelType();
//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();
loadfuelTypeVan();
activeRequest = $.ajax({
type: "POST",
url: "/Inventory/AddorEditVanDetail",
success: function (data) {
$("#divCreateDealer").parent().addClass("responsive_popup"); //addClass for respond the menu
$("#divCreateDealer").parent().addClass("k-window2");
$("#divCreateDealer").html('');
$("#divCreateDealer").html('');
$("#divCreateDealer").html(data);
SetKendoWindowTitle("#divCreateDealer", "Add Van Detail");
//open form in new dialog box
$("#divCreateDealer").data("kendoWindow").open();
openKendoWindowInCenter("#divCreateDealer");
//$("#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);
}
});
}
}
var isvanfueltype = "";
var isdealerfueltype = "";
function setvalvan() {
isvanfueltype = 'van';
}
function setvaldealer() {
isdealerfueltype = 'dealer';
}
/**
* This function is used to Add or Edit Van Detail In Grid.
* @method btnAddVanDetail
* @for ManageFleet
*/
var numArray = [];
function btnAddVanDetail() {
_type = 'van';
HideVanDetailMessage();
var productvarian = $("#ddVehicleTypevan").val();
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();
//alert(VanRegistrationNo);
var num = VanRegistrationNo + '||' + $("#fueltypeComboboxVan").val();
numArray.push(num);
//alert(numArray[0] + '' + numArray[1]);
//return false;
var VanIsVisitedInterState = $("#VanIsVisitedInterState").is(':checked');
if (AllValidVanDetail()) {
if (vVanRegistratioNoExist == false && vVanContactNoExist == 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;
oDealer.IsVanRelease = true;
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, IsVanRelease: oDealer.IsVanRelease
});
}
}
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);
vSelectedRow.set("IsVanRelease", oDealer.IsVanRelease);
}
//$("#TableId").find("tr").last();
closeWindow("#divCreateDealer");
$("#div_load").hide();
}
else {
if (vVanContactNoExist == true)
{
jAlert(vVanContactNoExistMsg, 'message');
}
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
*/
var ddlval = "";
function onChangefuelType() {
// get organization id.
var fueltype = $("#ddVehicleType").val();
ddlval =fueltype;
strfueltype = fueltype;
}
function SaveRecord(IsDeleted) {
// alert(isvanfueltype + 'isvanfueltype' + isdealerfueltype)
var isvanchange = 'f';
var _newtype = "";
var isdealerchange = 'f';
var isbothchange = 'f';
if (isvanfueltype == '') {
}
if (isvanfueltype == 'van') {
isvanchange = 'y';
_newtype = "van";
}
if (isdealerfueltype == '') {
}
if (isdealerfueltype == 'dealer') {
isdealerchange = 'y';
_newtype = "dealer";
// alert('isdealerfueltype dealer');
}
if (isdealerchange == 'y' && isvanchange =='y') {
_newtype = 'both';
_type = "";
isbothchange = 'y';
}
//alert(_newtype + '_type' + _type);
// return false;
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
};
console.log(DealerData);
$.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();
$("#hdnDealerId").val(data.DealerId);
var apiUrl = url + "Api/Admin";
var fueltypeval = "";
console.log(_type + '_type');
//alert(_type);
if (_newtype.toLowerCase() == 'dealer') {
apiUrl = url + "Api/Admin";
var fueltype_val = $("#fueltypeComboboxDealer").val();
// alert('d');
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: fueltypeval, dealerId: data.DealerId, fuelValue: fueltype_val },
success: function (data) {
}
});
}
else if (_newtype.toLowerCase() == 'van') {
for (var i = 0; i < numArray.length; i++) {
//set marker map to null
// alert('v');
//var array = numArray[i].split('||');
var splitDistance = numArray[i].split("||");
//Fuel_type = splitDistance[1];
// alert( + 'aa' + );
//DealerOrVanContactNo = splitDistance[0];
apiUrl = url + "Api/Admin?van=s";
fueltypeval = splitDistance[1];
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: fueltypeval, regNo: splitDistance[0], fuelValue: JSON.stringify(splitDistance[1]) },
success: function (data) {
numArray = [];
}
});
}
}
else if (_newtype.toLowerCase() == 'both') {
apiUrl = url + "Api/Admin";
var fueltype_val = $("#fueltypeComboboxDealer").val();
//alert('b' + data.DealerId);
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: fueltypeval, dealerId: data.DealerId, fuelValue: fueltype_val },
success: function (data) {
}
});
for (var i = 0; i < numArray.length; i++) {
//set marker map to null
//alert();
//var array = numArray[i].split('||');
var splitDistance = numArray[i].split("||");
//Fuel_type = splitDistance[1];
// alert( + 'aa' + );
//DealerOrVanContactNo = splitDistance[0];
apiUrl = url + "Api/Admin?van=s";
fueltypeval = splitDistance[1];
$.ajax({
type: "Post",
url: apiUrl,
data: { Token: fueltypeval, regNo: splitDistance[0], fuelValue: JSON.stringify(splitDistance[1]) },
success: function (data) {
numArray = [];
}
});
}
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
*/
var _type = "dealer";
function addDealer() {
_type = "dealer";
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).removeClass("disable_btn");
},
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 ($('#ddVehicleType').val() == 'Select') {
$("#spnproductVariant").html("*");
$("#spnproductVariant").show();
}
else if (DealerContactNo.length != 10) {
$("#spnDealerContactNo").html(MANAGE_FLEET_MESSAGES.mobileNoValidation);
$("#spnDealerContactNo").show();
}
//else if ($("#hdnDealerDefaultLatitude").val() == "" || $("#hdnDealerDefaultLatitude").val() == "0")
// jAlert(MANAGE_FLEET_MESSAGES.setDealerLocation);
else if (ChkDealerStateAndCityWithVanStateVanStateAndCity() == false) {
}
else
vResult = true;
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(MANAGE_FLEET_MESSAGES.mobileNoValidation);
$("#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 = MANAGE_REASON_MESSAGES.registrationNoExist + RegistrationNoList[i].VanAlias;
jAlert(vVanRegistrationNoExistMsg, 'message');
return false;
}
else if (RegistrationNoList[i].VanRegistrationNo.toUpperCase() == vVanRegistrationNo.toUpperCase()) {
vVanRegistratioNoExist = true;
vVanRegistrationNoExistMsg = MANAGE_REASON_MESSAGES.registrationNoExist + 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();
}
}
function CheckDealerNameExistOrNot() {
var vDealerId = $("#hdnDealerId").val();
var vNewDealerId = $("#NewDealerId").val();
var DealerData = {
DealerId: vDealerId,
NewDealerId: vNewDealerId
};
if (!$('#NewDealerId').is('[readonly]')) {
$.ajax({
type: "POST",
url: "/Inventory/CheckDealerSCode/",
data: { sDealerScode: vNewDealerId },
success: function (data) {
if (data.success == true) {
jAlert(data.message, 'message');
$("#NewDealerId").val('');
}
//$("#tableDealerList tbody tr.eq(" + vRowIndex + ")").trigger('click');
//$("#tableDealerList tbody tr.SelectedRow").trigger('click');
},
failure: function (response) {
},
complete: function () {
$("#div_load").hide();
}
});
} else {
$("#hdnDealerId").val(vNewDealerId);
}
}
/**
* This function is Used to Check the Duplicate Contact No Of Van
* @method CheckVanDupContactNo
* @for ManageFleet
*/
function CheckVanDupContactNo() {
//var sDealerDetail = "van";
var sVanContactNo = $("#ServiceEngineerContactNumber").val();
var apiUrl = url + "Api/Dealer?UserType=yes&UserType2=user&Isdeleted=check";
//if (vDealerContactNoOnFocus != sVanContactNo) {
$("#div_load").show();
//send ajax report to add user
$.ajax({
type: "POST",
url: apiUrl,
data: { VanContactNo: sVanContactNo, Token: securityToken },
success: function (data) {
if (data.trim() == "") {
vVanContactNoExist = false;
}
else {
vVanContactNoExist = true;
vVanContactNoExistMsg = data.message;
jAlert(data.message, 'message');
}
// vVanContactNoExist = true;
// vVanContactNoExistMsg = data.message;
// jAlert(data.message, 'message');
//}
//else if (data.status == "1") {
// vVanContactNoExist = false;
//}
},
error: function (data) {
console.log(data);
},
complete: function () {
$("#div_load").hide();
}
});
//}
//else {
// vVanContactNoExist = true;
//}
}