Rev 35962 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
$(function() {$(document).on('click', "#retailer-details-search-button", function() {searchContent = $("#retailer-details-search-text").val();if (typeof (searchContent) == "undefined" || !searchContent) {searchContent = "";}getRetailerDetailsByEmailIdOrMobileNumber("retailer-details-container", searchContent);});$(document).on('click', ".activate-store-temporary", function() {var row = $(this).closest("tr");var fofoId = $(this).data("fofoid");var ActiveDays = $(row).find("td:eq(4) input[type='text']").val();console.log("ActiveDays" + ActiveDays);console.log("fofoId" + fofoId);var days = parseInt(ActiveDays);if (confirm("Are you sure you want to activate this store!") == true) {doPostAjaxRequestHandler(context + "/activateStoreTemporary?fofoId=" + fofoId + "&days=" + days,function(response) {if (response == "true") {alert("successfully activated!");inactiveStoreInfo("main-content");}});}});$(document).on('click', ".partner-info", function() {var userIds = {};userIds['userIds'] = $('#fofo-users').val();console.log(userIds)doPostAjaxRequestWithJsonHandler(context + "/getPartnerinfo", JSON.stringify(userIds), function(response) {$('.storePartnerInfo').html(response);});});$(document).on('click', ".active-store", function() {store("main-content");});$(document).on('click', ".allStoreInfo", function() {storeInfo("main-content");});$(document).on('click', ".inactive-store", function() {inactiveStoreInfo("main-content");});$(document).on('click', ".retailer-info", function() {retailerInfo("main-content");});$(document).on('click', ".partner-readonly-info", function() {partnerInfo("main-content")});$(document).on('click', ".block-brand-mapping", function() {blockBrandMapping("main-content")});$(document).on('click', ".brands-limit", function() {brandsLimit("main-content")});$(document).on('click', ".add-partner-pincode", function() {allPartnerPincode("main-content")});$(document).on('click', ".partnerInfoReadOnly",function() {var fofoId = $('#fofo-users').val();loginAsPartnerReadonly(fofoId);});$(document).on('change', "#retailerAddressPinCode",function() {var pincode = $('#retailerAddressPinCode').val();if (undefined != pincode) {doGetAjaxRequestHandler(context + "/postOffice?pinCode="+ pincode,function(response) {console.log(response.response.state);$('#retailerAddressCity').find('option').not(':first').remove();$('#retailerAddressState').val("");$('#retailerAddressState').val(response.response.state);loadDistrictNames(response.response.state);loadASTDetail(response.response.state);for (let city of response.response.cities) {var opt = $("<option>").val(city).text(city);$('#retailerAddressCity').append(opt);}});}});$(document).on("keyup", "#retailer-details-search-text", function(e) {var keyCode = e.keyCode || e.which;if (keyCode == 13) {$("#retailer-details-search-button").click();}});$(document).on('click', ".deactivate-store", function() {var fofoId = $(this).data("fofoid");var storeCode = $(this).data("storecode");console.log(fofoId);if (confirm("Are you sure you want to deactivate store!") == true) {deactivateStore("main-content", fofoId, storeCode);}});$(document).on('click', ".activate-store-forever", function() {var fofoId = $(this).data("fofoid");console.log(fofoId);if (confirm("Are you sure you want to activate this store!") == true) {activateStoreForever("main-content", fofoId);}});$(document).on('click', ".login_as", function() {var fofoId = $('#partnerId').val();loginAsPartner(fofoId);});$('#partnerSecondary').on('click', '.brandFocusedStock', function() {var fofoId = $(this).data('fofoid');var brand = $(this).data('brand');doGetAjaxRequestHandler("https://partners.smartdukaan.com" + "/getPartnerShortageStock?brand=" + brand + "&fofoId="+ fofoId, function(response) {$('#itemWiseBrandStock .modal-content').html(response);});});$(document).on('click', ".agingDataAfterNintyDays", function() {var fofoId = $(this).data('fofoid');console.log(fofoId)doPostAjaxRequestWithJsonHandler("https://partners.smartdukaan.com" + "/getInventoryItemAgingByFofoId?fofoId="+ fofoId, JSON.stringify([90]),function(response) {$('#agingItemWiseBrandStock .modal-content').html(response);});});$(document).on('click', ".extend-billing", function() {var fofoId = $(this).data("fofoid");console.log(fofoId);if (confirm("Are you sure you want to extend Billing?")) {extendBilling($(this).parent(), fofoId);}});/** $(document).on('change', '#retailerAddressState', function() { var stateName =* $(this).find('option:selected').text();** loadDistrictNames(stateName); });*/$(document).on('click', "#location", function() {if ($(this).is(":checked")) {$("#divLocation").show();} else {$("#divLocation").hide();}});$(document).on('click', ".changePartnerCategory", function() {$clickedElement = $(this);var fofoId = $clickedElement.data("id");$tdElement = $(this).closest('td');doGetAjaxRequestHandler(context + "/getPartnerCategory?fofoId=" + fofoId, function(response) {$tdElement.html(response);$tdElement.find('.partnerCategory').multiselect({includeSelectAllOption: true,multiple: true,maxHeight: 200,buttonWidth: '180px',numberDisplayed: 1,nonSelectedText: 'Category',nSelectedText: ' - Category Selected',allSelectedText: 'All Category Selected',enableFiltering: true,enableCaseInsensitiveFiltering: true});});});$(document).on('click', ".update-category",function() {var fofoId = $(this).data('fofoid');var partnerType = $('#partnerCategory').val();var durationMonths = $('#upgradeDuration').val();if (confirm("Are you sure you want to upgrade for " + durationMonths + " month(s)?") == true) {doPostAjaxRequestHandler(context+ "/updatePartnerCategory?fofoId="+ fofoId + "&partnerType=" + partnerType + "&durationMonths=" + durationMonths, function(response) {if (response == "true") {alert("Update successfully");storeInfo("main-content");}});}});$(document).on('click', ".addlocationbutton",function() {var userId = $('#retailerId').text();var name = $('#personName').val();var line1 = $('#line1').val();var line2 = $('#line2').val();var city = $('#city').val();var state = $('#state').val();var pin = $('#pinCode').val();if (name === "" && line1 === "" && city === "" && pin === "") {alert("Field can't be empty");return;}if (name === "") {alert("name is required");return;}if (line1 === "") {alert("line1 is required");return;}if (city === "") {alert("city is required");return;}if (pin === "") {alert("pin is required");return;}var locationData = {};locationData['userId'] = $('#retailerId').text();locationData['name'] = $('#personName').val();locationData['line1'] = $('#line1').val();locationData['line2'] = $('#line2').val();locationData['city'] = $('#city').val();locationData['state'] = $('#state').val();locationData['pin'] = $('#pinCode').val();if (confirm("Are you sure you want to add location!") == true) {doPostAjaxRequestWithJsonHandler(context + "/addLocation",JSON.stringify(locationData), function(response) {if (response == 'true') {alert("successfully Add");$("#addLocationModal").modal('hide');}});return false;}});//Performance$(document).on('click', ".partner-performance-access", function() {doGetAjaxRequestHandler(context + "/getPartnersForPerformance", function(response) {$('#' + "main-content").html(response);});});$(document).on('click', ".partnerPerformance", function() {var fofoId = $('#fofo-users').val();var url = context + "/partnerPerformance?fofoId=" + fofoId;//$('.partner-performance-container').html(`<iframe class="wrapper" src="${url}" style="width:100%;height:100vh"> </iframe>`);doGetAjaxRequestHandler(context + "/partnerPerformance?fofoId=" + fofoId, function(response) {$('.partner-performance-container').html(response);});});$(document).on('click', ".retailer-filter", function() {doGetAjaxRequestHandler(context + "/getFilters", function(response) {$('#' + "main-content").html(response);});});$(document).on('click', ".filters", function() {var credit = $('#credit').is(':checked');var billing = $('#billing').is(':checked');var investment = $('#investment').is(':checked');var secondary = $('#secondary').is(':checked');var tertiary = $('#tertiary').is(':checked');var mtds = $('#mtds').is(':checked');var mtdt = $('#mtdt').is(':checked');var investmentPct = $('#investmentvalue').val();var secondaryDays = $('#secondaryvalue').val();var tertiaryDays = $('#tertiaryvalue').val();var mtdsPct = $('#mtdsvalue').val();var mtdtPct = $('#mtdtvalue').val();console.log(investmentPct)var retailerFilters = {};retailerFilters['credit'] = credit;retailerFilters['billing'] = billingif (investment) {retailerFilters['investmentPct'] = investmentPct}if (secondary) {retailerFilters['secondaryDays'] = secondaryDays}if (tertiary) {retailerFilters['tertiaryDays'] = tertiaryDays}if (mtds) {retailerFilters['mtdsPct'] = mtdsPct}if (mtdt) {retailerFilters['mtdtPct'] = mtdtPct}console.log(JSON.stringify(retailerFilters));doAjaxRequestWithJsonHandler(context + "/getFilteredRetailers", 'POST', JSON.stringify(retailerFilters), function(response) {$('.filtered-partner-performance-container').html(response);});});$(document).on('click', ".default-email-val", function() {var credit = $('#credit').is(':checked');var billing = $('#billing').is(':checked');var investment = $('#investment').is(':checked');var secondary = $('#secondary').is(':checked');var tertiary = $('#tertiary').is(':checked');var mtds = $('#mtds').is(':checked');var mtdt = $('#mtdt').is(':checked');var investmentPct = $('#investmentvalue').val();var secondaryDays = $('#secondaryvalue').val();var tertiaryDays = $('#tertiaryvalue').val();var mtdsPct = $('#mtdsvalue').val();var mtdtPct = $('#mtdtvalue').val();console.log(investmentPct)var retailerFilters = {};retailerFilters['credit'] = credit;retailerFilters['billing'] = billingretailerFilters['investmentPct'] = investmentPctretailerFilters['secondaryDays'] = secondaryDaysretailerFilters['tertiaryDays'] = tertiaryDaysretailerFilters['mtdsPct'] = mtdsPctretailerFilters['mtdtPct'] = mtdtPctdoAjaxRequestWithJsonHandler(context + "/defaultFilterSetForEmail", 'POST', JSON.stringify(retailerFilters), function(response) {if (response == "true") {alert("Successfully Done")}});});});function getDistance(lat1, lon1, lat2, lon2) {var deg2rad = 0.017453292519943295; // === Math.PI / 180var cos = Math.cos;lat1 *= deg2rad;lon1 *= deg2rad;lat2 *= deg2rad;lon2 *= deg2rad;var diam = 12742; // Diameter of the earth in km (2 * 6371)var dLat = lat2 - lat1;var dLon = lon2 - lon1;var a = ((1 - cos(dLat)) + (1 - cos(dLon)) * cos(lat1) * cos(lat2)) / 2;return parseFloat(diam * Math.asin(Math.sqrt(a))).toFixed(2);}function getRetailerDetailsByEmailIdOrMobileNumber(domId, emailIdOrMobileNumber) {doGetAjaxRequestHandler(context + "/retailerDetails?emailIdOrMobileNumber="+ emailIdOrMobileNumber, function(response) {$('#' + domId).html(response);if ($("#location").is(":checked")) {$("#divLocation").show();}});}function updateRetailerDocument() {// $("#updateRetailerShopDocument0").click( function() {console.log("Update Retailer Document Clicked");// console.log(ownerId);var emailIdOrMobileNumber = $('#retailer-details-search-text').val();console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);var file = $('#retailerDocument')[0].files[0];console.log("file : " + file.name);uploadRetailerDocument("retailer-details-container", file,emailIdOrMobileNumber);}function updateRetailerShopDocument(ownerId) {// $("#updateRetailerShopDocument0").click( function() {console.log("Update Retailer Shop Document Clicked");console.log(ownerId);var shopSize = parseInt($("#shopDetailsSize").attr('size'));console.log("size : " + shopSize);for (var index = 0; index < shopSize; index++) {if ("updateRetailerShopDocument" + index == ownerId) {var emailIdOrMobileNumber = $('#retailer-details-search-text').val();console.log("emailIdOrMobileNumber: " + emailIdOrMobileNumber);var shopId = $('#retailerShopDocument' + index).attr("shopId");console.log("shopId : " + shopId);var file = $('#retailerShopDocument' + index)[0].files[0];console.log("file : " + file.name);uploadRetailerShopDocument("retailer-details-container", file,emailIdOrMobileNumber, shopId);}}}function loadDistrictNames(stateName) {if (undefined != $("#districtName")) {doGetAjaxRequestHandler(context + "/district/all/stateName?stateName=" + stateName,function(response) {console.log(response);var districtMasters = response.response;// districtMasters = districtMasters.response;var districtNameElements = '<option value="" disabled selected>District Name</option>';for (index = 0; index < districtMasters.length; index++) {districtNameElements = districtNameElements+ '<option value="'+ districtMasters[index].name + '">'+ districtMasters[index].name + '</option>';}$('#districtName').html(districtNameElements);});}}function loadASTDetail(stateName) {doGetAjaxRequestHandler(context + "/astDetail?stateName=" + stateName,function (asts) {$('#retailerAstId').find('option').not(':first').remove();for (let ast of asts) {var opt = $("<option>").val(ast.id).text(ast.area + "(" + ast.areaDescription + ")" + " - " + ast.territory + "(" + ast.territoryDescription + ")");$('#retailerAstId').append(opt);}});}function retailerInfo(domId) {doGetAjaxRequestHandler(context + "/retailerInfo", function(response) {$('#' + domId).html(response);});}function partnerInfo(domId) {doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function(response) {$('#' + domId).html(response);});}function blockBrandMapping(domId) {doGetAjaxRequestHandler(context + "/getBlockBrandMapping", function(response) {$('#' + domId).html(response);});}function brandsLimit(domId) {doGetAjaxRequestHandler(context + "/getBrandslimit", function(response) {$('#' + domId).html(response);});}function storeInfo(domId) {doGetAjaxRequestHandler(context + "/getAllStores", function(response) {$('#' + domId).html(response);});}function store(domId) {doGetAjaxRequestHandler(context + "/getstore", function(response) {$('#' + domId).html(response);});}function inactiveStoreInfo(domId) {doGetAjaxRequestHandler(context + "/getAllInactiveStores", function(response) {$('#' + domId).html(response);});}function allPartnerPincode(domId) {doGetAjaxRequestHandler(context + "/getAllPartnerPincode", function(response) {$('#' + domId).html(response);});}function deactivateStore(domId, fofoId, storeCode) {doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,function(response) {if (response == "true") {alert("Store marked inactive successfully!");storeInfo(domId);askClosureConfirmation(domId, fofoId, storeCode);}});}function askClosureConfirmation(domId, fofoId, storeCode) {var inputCode = prompt("To also PERMANENTLY close this store (cannot be undone), type the store code: " + storeCode + "\n\nPress Cancel to skip.");if (inputCode === null) {return;}if (inputCode.trim() === "") {alert("Store code is required to confirm closure.");askClosureConfirmation(domId, fofoId, storeCode);return;}if (inputCode.trim() !== storeCode) {alert("Store code does not match. Closure cancelled.");return;}doPostAjaxRequestHandler(context + "/closeStore?fofoId=" + fofoId + "&storeCode=" + encodeURIComponent(inputCode.trim()),function(closeResponse) {if (closeResponse == "true") {alert("Store permanently closed.");}storeInfo(domId);});}function activateStoreForever(domId, fofoId) {doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,function(response) {if (response == "true") {alert("successfully activated!");inactiveStoreInfo(domId);}});}function loginAsPartner(fofoId) {doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,function(response) {window.location.reload();});}function loginAsPartnerReadonly(fofoId) {doGetAjaxRequestHandler(context + "/login-as-partner-readonly?fofoId=" + fofoId,function(response) {window.create({"url": "/dashboard","incognito": true});});}function extendBilling(container, fofoId) {doPostAjaxRequestHandler(context + "/extendBilling?fofoId=" + fofoId,function(response) {if (isFinite(response)) {alert("successfully deactivated!");container.html("Billing extended upto "+ moment().add(1, 'day').format("DD-MM-YY")+ " Grace count(" + response + ")");}});}function updateLocationButton(id) {var userId = id;var name = $('#personName').val();var line1 = $('#line1').val();var line2 = $('#line2').val();var city = $('#city').val();var state = $('#state').val();var pin = $('#pinCode').val();console.log(id);if (name === "" && line1 === "" && city === "" && pin === "") {alert("Field can't be empty");return;}if (name === "") {alert("name is required");return;}if (line1 === "") {alert("line1 is required");return;}if (city === "") {alert("city is required");return;}if (pin === "") {alert("pin is required");return;}var changeLocationData = {};changeLocationData['userId'] = id;changeLocationData['name'] = $('#personName').val();changeLocationData['line1'] = $('#line1').val();changeLocationData['line2'] = $('#line2').val();changeLocationData['city'] = $('#city').val();changeLocationData['state'] = $('#state').val();changeLocationData['pin'] = $('#pinCode').val();console.log(changeLocationData);if (confirm("Are you sure you want to add location!") == true) {doPostAjaxRequestWithJsonHandler(context + "/updateLocation", JSON.stringify(changeLocationData), function(response) {if (response == 'true') {alert("successfully Update");$("#addLocationModal").modal('hide');}});return false;}}$(document).on('click', ".retailer_contacts", function () {doGetAjaxRequestHandler(context + "/alternateRetailerContacts",function (response) {$('#' + 'main-content').html(response);});});$(document).on('click', '.get-retailer-contacts', function () {if (typeof partnerId != "undefined") {doGetAjaxRequestHandler(context + "/retailer-contact-list?fofoId=" + partnerId,function (response) {$('.retailer-contacts-container').html(response);});}});$(document).on('click', '.retailer-contact-submit', function () {var contactName = $('#retailer-contact-name').val();var contactNumber = $('#retailer-contact-number').val();var brandName = $('#retailer-contact-brand').val();var contactType = $('#retailer-contact-type').val();if (typeof partnerId != "undefined") {doGetAjaxRequestHandler(context + "/add-retailer-contact-list?contactName=" + encodeURIComponent(contactName) + "&contactNumber=" + encodeURIComponent(contactNumber) + "&brandName=" + encodeURIComponent(brandName) + "&contactType=" + encodeURIComponent(contactType) + "&fofoId=" + partnerId,function (response) {$('#update-retailer-contact-modal').modal('toggle');$('.retailer-contacts-container').html(response);});}});$(document).on('click', '.update-contact-status', function () {var contactId = $(this).data('contactid');var active = $(this).data('status');if (typeof partnerId != "undefined") {doGetAjaxRequestHandler(context + "/update-contact-status?contactId=" + contactId + "&fofoId=" + partnerId + "&active=" + active,function (response) {$('.retailer-contacts-container').html(response);});}});// analysis dasboard js for retailer$(document).on('click', '.dashboard-view', function () {var fofoId = $(this).data('fofoid');window.open(context + "/analysisDashboard?fofoId=" + fofoId, '_blank');});$('#partnerTasks').modal({backdrop: 'static',keyboard: false});const emailId = getCookie('emailId');console.log("Email ID:", emailId);function showModal() {if (emailId && emailId.endsWith('@smartdukaan.com')) {console.log('SmartDukaan user - modal not shown');return;}$('#partnerTasks').removeAttr('aria-hidden');if (!emailId || !emailId.endsWith('@smartdukaan.com')) {$('#chartData').html('<div class="loader text-center " style=" height: 30px;\n' +' display: flex;\n' +' justify-content: center;\n' +' align-items: center;\n' +' font-size: 1.5rem;\n' +' font-weight: 200;\n' +' color: #555;" >Loading...</div>');doGetAjaxRequestHandler(context + "/dashboardModal", function (response, status) {if (status === 500) {return;}$('#chartData').html(response);$('#partnerTasks').css('zoom', '125%').modal('show');});} else {$('#chartData').html('<p>No data to load</p>');$('#partnerTasks').css('zoom', '125%').modal('show');}}$(document).ready(function () {const isAdmin = emailId && emailId.endsWith('@smartdukaan.com');console.log("user is admin?" + isAdmin)console.log("user email id?" + emailId)if (isAdmin) {console.log('Admin user - modal logic completely skipped');return;}const today = new Date().toDateString();const currentHour = new Date().getHours();const stored = JSON.parse(localStorage.getItem('modalData') || '{}');if (stored.date !== today) {localStorage.setItem('modalData', JSON.stringify({date: today, count: 1}));console.log('First login of day - showing modal');showModal();} else if (stored.count === 1 && currentHour >= 17) {localStorage.setItem('modalData', JSON.stringify({date: today, count: 2}));console.log('5 PM show - showing modal');showModal();} else {console.log('Modal conditions not met - not showing');$('#partnerTasks').modal('hide');$('.modal-backdrop').remove();}});$(document).on('click', '.partner-tasks-btn', function () {if (emailId && emailId.endsWith('@smartdukaan.com')) {console.log('SmartDukaan user - button click blocked');return;}doGetAjaxRequestHandler(context + "/dashboardModal", function (response) {$('#chartData').html(response);$('#partnerTasks').css('zoom', '125%').modal('show');$('#partnerTasks').modal('show');});});$('#partnerTasks').on('hidden.bs.modal', function () {$(this).data('modal', null);$('.modal-backdrop').remove();const bootstrapCss = document.getElementById('modal-bootstrap-css');if (bootstrapCss) {bootstrapCss.remove();}});