Subversion Repositories SmartDukaan

Rev

Rev 27754 | Rev 27797 | Go to most recent revision | 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', ".active-store", 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', ".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);
                        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");
        console.log(fofoId);
        if (confirm("Are you sure you want to deactivate store!") == true) {
            deactivateStore("main-content", fofoId);
        }

    });
    $(document).on('click', ".login_as", function () {
        var fofoId = $('#partnerId').val();
        loginAsPartner(fofoId);

    });

    $(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', ".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;
            }
        });

});

function getDistance(lat1, lon1, lat2, lon2) {
    var deg2rad = 0.017453292519943295; // === Math.PI / 180
    var 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 retailerInfo(domId) {
    doGetAjaxRequestHandler(context + "/retailerInfo", function (response) {
        $('#' + domId).html(response);

    });

}

function partnerInfo(domId) {
    doGetAjaxRequestHandler(context + "/getPartnerReadonlyInfo", function (response) {
        $('#' + domId).html(response);

    });
}

function storeInfo(domId) {
    doGetAjaxRequestHandler(context + "/getAllStores", function (response) {
        $('#' + domId).html(response);
    });
}

function inactiveStoreInfo(domId) {
    doGetAjaxRequestHandler(context + "/getAllInactiveStores", function (
        response) {
        $('#' + domId).html(response);
    });
}

function deactivateStore(domId, fofoId) {
    doPostAjaxRequestHandler(context + "/deactivateStore?fofoId=" + fofoId,
        function (response) {
            if (response == "true") {
                alert("successfully deactivated!");
                storeInfo(domId);
            }

        });
}

function loginAsPartner(fofoId) {
    doGetAjaxRequestHandler(context + "/login-as-partner?fofoId=" + fofoId,
        function (response) {
            window.create({
                "url": "/dashboard",
                "incognito": true
            });
        });
}

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;
    }

}