Subversion Repositories SmartDukaan

Rev

Rev 35769 | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function () {
    $(document).on('click', ".lead", function () {
        loadLead("main-content");
    });

    $(document).on('click', ".team-commitment", function () {
        loadTeamCommitment("main-content");
    });


    $(document).on('click', ".partner-health", function () {
        loadPartnerHealth("main-content");
    });

    $(document).on('click', ".lead-detail", function () {
        loadLeadDetail("main-content");
    });


    $(document).on('click', ".submitCommitment",
        function () {
            var startDateTime = getDatesFromPicker('input[name="commitmentDate"]').startDate;
            doGetAjaxRequestHandler(context + "/getTeamCommitment?date="
                + startDateTime, function (response) {
                $('.teamcommitmentcontainer').html(response);

            });
        });


    $(document).on('click', ".submitDateWiseLead", function () {

        var startDate = $("#startDate").val();
        var endDate = $("#endDate").val();
        var status = $("#statusFilter").val();
        var color = $("#colorFilter").val();

        if (color == null) {
            color = "";
        }

        if (startDate && endDate) {
            var start = new Date(startDate);
            var end = new Date(endDate);
            if (end < start) {
                alert("End date must be after start date");
                return;
            }
        }

        doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status + "&color=" + color + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
            $('#' + 'main-content').html(response);
        });


    })
    ;$(document).on('click', ".downloadDateWiseLead", function () {

        var startDate = $("#startDate").val();
        var endDate = $("#endDate").val();
        var status = $("#statusFilter").val();
        var color = $("#colorFilter").val();

        if (color == null) {
            color = "";
        }

        if (startDate && endDate) {
            var start = new Date(startDate);
            var end = new Date(endDate);
            if (end < start) {
                alert("End date must be after start date");
                return;
            }
        }

        let endPoint = `${context}/downloadDateWiseLead?leadStatus=${status}&color=${color}&startDate=${startDate}&endDate=${endDate}`;
        window.location.href = endPoint;

    });


    $(document).on('click', ".visit-request-plan", function () {

        doGetAjaxRequestHandler(context + "/visitPlan", function (response) {
            $('#' + 'main-content').html(response);
        });

    });

    $(document).on('click', ".visitPlan", function () {

        let dateWisePlan = $("#dateVisitSearch").val();

        doGetAjaxRequestHandler(context + "/visit/getVisitPlan?date=" + dateWisePlan, function (response) {
            $('#' + 'main-content').html(response);
        });

    });

    $(document).on('click', ".lead-close", function () {
        loadClosedLead("main-content");
    });

    $(document).on('click', "#lead-close-paginated .next",
        function () {

            var searchText = $("#authUser").val();
            // var searchTxt=$("#scheme-search-text").val();
            console.log(searchText);
            if (typeof (searchText) == "undefined" || !searchText) {
                searchText = "";
            }

            if ((searchText)) {
                var params = {};
                params['searchTerm'] = searchText;
                loadPaginatedNextItems('/searchLeadPaginated', params,
                    'lead-close-paginated', 'close-lead-table',
                    'lead-close-container');
            } else {

                loadPaginatedNextItems('/getPaginatedClosedLeads', null,
                    'lead-close-paginated', 'close-lead-table',
                    'lead-close-container');
            }
            $(this).blur();
        });

    $(document).on('click', "#lead-close-paginated .previous",
        function () {
            var searchText = $("#authUser").val();
            // var searchTxt=$("#scheme-search-text").val();
            console.log(searchText);
            if (typeof (searchText) == "undefined" || !searchText) {
                searchText = "";
            }

            if ((searchText)) {
                var params = {};
                params['searchTerm'] = searchText;
                loadPaginatedPreviousItems('/searchLeadPaginated', params,
                    'lead-close-paginated', 'close-lead-table',
                    'lead-close-container');
            } else {
                loadPaginatedPreviousItems('/getPaginatedClosedLeads',
                    null, 'lead-close-paginated', 'close-lead-table',
                    'lead-close-container');
            }
            $(this).blur();
        });

    $(document).on('click', "#close-lead-search-button", function () {
        var searchText = $("#authUser").val();
        if (typeof (searchText) == "undefined" || !searchText) {
            searchText = "";
        }
        loadLeadSearchInfo(searchText);
    });

    $(document).on("keyup", "#authUser", function (e) {
        var keyCode = e.keyCode || e.which;
        if (keyCode == 13) {
            $("#close-lead-search-button").click();
        }
    });
    $(document).on('click', ".view",
        function () {
            var id = $(this).data('requestid');
            console.log(id);
            doGetAjaxRequestHandler(context + "/getLeadActivity?leadId="
                + id, function (response) {

                console.log(response)

                $('#fetchLeadActivityData .modal-content').html(response);

            });
        });

    $(document).on('click', ".newLead", function () {
        $('#newEntryLeadModal').modal('show');
        $("#scheduleTime").hide();
    });

    $(document).on('click', ".show-lead", function () {
        var status = $("#statusFilter").val();
        doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status, function (response) {
            $('#' + 'main-content').html(response);
        });
    });


    $(document).on('click', ".show-colowise-lead", function () {
        var status = $("#statusFilter").val();
        var color = $("#colorFilter").val();
        doGetAjaxRequestHandler(context + "/getOpenLead?leadStatus=" + status + "&color=" + color, function (response) {
            $('#' + 'main-content').html(response);
        });
    });

    $(document).on('click', "#uploadIvoryLead", function () {

        window.location.href = context + "/downloadIvoryLead";
    });

    $(document).on('click', ".submitLeadGenerate", function () {

        console.log("hello");
        if (confirm('Confirm upload ?')) {
            var fileSelector = $(this)[0];
            if (fileSelector != undefined) {
                var url = `${context}/csvFileAndSetLead`;
                console.log(url);
                var file = $(".fileLeadGenerate")[0].files[0];
                let fileInput = $(this);
                console.log("file" + file);
                console.log("fileInput" + fileInput);
                doAjaxUploadRequestHandler(
                    url,
                    'POST',
                    file, function (response) {

                        console.log("reponse" + response);

                        if (response == true) {
                            alert("successfully uploaded");


                        }
                    });

            }
        } else {
            // Do nothing!
        }
    });


    $(document).on('click', ".lead-request",
        function () {

            var firstName = $('input[name="firstName"]').val();
            var lastName = $('input[name="lastName"]').val();
            var mobile = $('input[name="mobile"]').val();
            var address = $('input[name="address"]').val();
            var status = $("#status").val();
            var city = $('input[name="city"]').val();
            var state = $("#state").val();
            var remark = $("#createRemark").val();
            var assignTo = $("#createAssignTo").val();
            var source = $("#leadSource").val();
            var communicationType = $("#communicationTye").val();

            var conversionprobability = $("#conversionprobabilit").val();


            var outletName = $('input[name="leadoutletName"]').val();
            var counterSize = $('input[name="leadcounterSize"]').val();
            var table = document.getElementById('brandtable');
            var brandValueJson = [];
            var leadBrands;

            console.log(conversionprobability)


            if (firstName === "" && lastName === "" && mobile === ""
                && address === "" && status === "" && city === ""
                && state === "" && remark === "" && source === "") {
                alert("Field can't be empty");
                return;
            }


            if (firstName === "") {
                alert("First Name is required");
                return;
            }
            if (lastName === "") {
                alert("Last Name is required");
                return;
            }
            if (mobile === "") {
                alert("Mobile is required");
                return;
            }
            if (status === "") {
                alert("Status is required");
                return;
            }
            if (address === "") {
                alert("address is required");
                return;
            }
            if (city === "") {
                alert("city is required");
                return;
            }

            if (state === "") {
                alert("state is required");
                return;
            }
            if (source === "") {
                alert("Source is required")
                return;
            }

            if (remark === "") {
                alert("Remark is required");
                return;
            }

            if (conversionprobability === "") {
                alert("Conversion Probability is required");
                return;
            }
            if (status == "followUp" || status == "pending" || status == "finalized") {
                if (outletName === "") {
                    alert("Outlet Name is required");
                    return;
                }

                if (counterSize === "") {
                    alert("Counter Size is required");
                    return;
                }

                if (localStorage.getItem("frontph") == "undefined" && localStorage.getItem("frontph") == null) {
                    alert("Front Document is required");
                    return;
                }

                if (localStorage.getItem("internalMarketh") == "undefined" || localStorage.getItem("internalMarketh") == null) {
                    alert("Front With Market Document is required");
                    return;
                }

                if (localStorage.getItem("leftShoth") == "undefined" || localStorage.getItem("leftShoth") == null) {
                    alert("Internal Left Shot Document is required");
                    return;
                }

                if (localStorage.getItem("leftWallh") == "undefined" || localStorage.getItem("leftWallh") == null) {
                    alert("Internal Left Wall Document is required");
                    return;
                }


                if (localStorage.getItem("rightWallh") == "undefined" || localStorage.getItem("rightWallh") == null) {
                    alert("Internal Right Wall Document is required");
                    return;
                }


                for (i = 1; i < table.rows.length; i++) {

                    var objCells = table.rows[i].cells;

                    leadBrands = {
                        brand: objCells[0].innerText,
                        value: objCells[1].getElementsByTagName('input')[0].value
                    }
                    brandValueJson.push(leadBrands);
                }


            }


            var leaddetailData = {}
            leaddetailData['firstName'] = firstName;
            leaddetailData['lastName'] = lastName
            leaddetailData['mobile'] = mobile
            leaddetailData['address'] = address
            leaddetailData['city'] = city
            leaddetailData['state'] = state
            leaddetailData['status'] = status
            leaddetailData['remark'] = remark
            leaddetailData['assignTo'] = assignTo
            leaddetailData['source'] = source
            leaddetailData['colorCheck'] = conversionprobability


            if (status == "followUp") {
                leaddetailData['schelduleTimestamp'] = getDatesFromPicker('#scheduleTime').startDate;

                leaddetailData['communicationType'] = communicationType
            }


            leaddetailData['outletName'] = outletName;

            leaddetailData['counterSize'] = counterSize;


            leaddetailData['leadBrands'] = brandValueJson;

            console.log(localStorage.getItem("frontp"));


            leaddetailData['frontp'] = localStorage
                .getItem("frontph");


            leaddetailData['frontWithMarket'] = localStorage
                .getItem("internalMarketh");


            leaddetailData['internalLongShot'] = localStorage
                .getItem("leftShoth");


            leaddetailData['internalLeftWall'] = localStorage
                .getItem("leftWallh");


            leaddetailData['internalRightWall'] = localStorage
                .getItem("rightWallh");

            console.log(leaddetailData);

            if (confirm("Are you sure you want to add lead!") == true) {
                doPostAjaxRequestWithJsonHandler(context + "/createLead",
                    JSON.stringify(leaddetailData), function (response) {
                        if (response == 'true') {
                            alert("successfully Add");
                            $('#newEntryLeadModal').modal('hide');
                            $('.modal-backdrop').remove();
                            loadLead("main-content");
                        } else {
                            alert(response);
                        }
                    });

                return false;
            }
        });
    var leadId = null;
    var row = null;
    $(document).on('click', ".editLead", function () {
        $('#editLeadData').modal('show');

        $("#remark").val("");
        $("#assignTo").val("");
        $("#editStatus").val("");
        $("#reason").val("");
        $("#editCity").val("");
        $("#editState").val("");
        $("#editSource").val("");
        $("#editScheduleTime").hide();


        localStorage.removeItem("frontph");
        localStorage.removeItem("leftShoth");
        localStorage.removeItem("rightWallh");
        localStorage.removeItem("leftWallh");
        localStorage.removeItem("internalMarketh");

        row = $(this).closest("tr");
        leadId = $(this).data('leadid');

        doAjaxRequestHandler(
            context + "/getLeadDetailByLeadId?leadId=" + leadId,
            "GET",
            function (response) {

                var data = response.response;
                if (!data) return;
                console.log(data);
                $("#editCity").val(data.city);
                $("#editState").val(data.state);
                $("input[name='outletName']").val(data.outletName);
                $("input[name='counterSize']").val(data.counterSize);
            }
        );
    });


    $(document).on('click', ".lead-edit-request",
        function () {


            console.log(row);
            var rowIndex = $(this).closest('tr').prevAll().length;
            var remark = $('input[name="remark"]').val();
            var assignTo = $("#assignTo").val();
            var editStatus = $("#editStatus").val();
            var city = $('input[name="editCity"]').val();
            var state = $("#editState").val();
            var reason = $("#reason").val();

            var startDate = $("#startDate").val();
            var endDate = $("#endDate").val();
            var leadStatus = $("#statusFilter").val();
            var color = $("#colorFilter").val();
            var communicationType = $("#communicationType").val();

            var conversionprobability = $("#conversionprobability").val();
            var editSource = $("#editSource").val();

            console.log(conversionprobability)


            console.log(startDate)
            console.log(leadStatus)

            console.log(color)
            console.log(reason)

            if (remark === "" && assignTo === "" && editStatus === "") {
                alert("All fields is required");
                return;
            }

            if (assignTo === "") {
                alert("assignTo is required");
                return;
            }

            if (remark === "") {
                alert("Remark is required");
                return;
            }


            if (editStatus === "") {
                alert("status is required");
                return;
            }

            if (editStatus === "notInterested") {
                if (reason == null) {
                    alert("Reason  is required");
                    return;
                }
            }
            var leadActivityData = {}
            leadActivityData['id'] = leadId;
            leadActivityData['remark'] = remark;
            leadActivityData['assignTo'] = assignTo
            leadActivityData['status'] = editStatus
            leadActivityData['reason'] = reason
            leadActivityData['colorCheck'] = conversionprobability
            if (city && city.trim() !== "") {
                leadActivityData.city = city;
            }

            if (state && state.trim() !== "") {
                leadActivityData.state = state;
            }

            if (editSource && editSource.trim() !== "") {
                leadActivityData.source = editSource;
            }


            if (editStatus == "followUp") {
                leadActivityData['scheldule'] = getDatesFromPicker('input[name="editScheduleTime"]').startDate
                leadActivityData['communicationType'] = communicationType

            }

            console.log(leadActivityData);
            if (confirm("Are you sure you want to add lead!") == true) {
                doPostAjaxRequestWithJsonHandler(context + "/editLead", JSON.stringify(leadActivityData), function (response) {
                    console.log(response);
                    $('#editLeadData').modal('hide');
                    $('.modal-backdrop').remove();
                    row.html(response);
                });
            }

        });


    $(document).on('click', ".show-partner-health",
        function () {

            var email = $("#authUserFilter").val();

            console.log(email)
            doGetAjaxRequestHandler(context + "/partnerHealth?email="
                + email, function (response) {
                console.log(response)
                $('#' + 'main-content').html(response);

            });
        });


    $(document).on('click', ".lead-detail-entry",
        function () {

            console.log("hello");
            var outletName = $('input[name="outletName"]').val();
            var counterSize = $('input[name="counterSize"]').val();
            var table = document.getElementById('editbrandtable');
            var brandValueJson = [];
            var leadBrands;

            if (outletName === "") {
                alert("Outlet Name is required");
                return;
            }

            if (counterSize === "") {
                alert("Counter Size is required");
                return;
            }

            if (localStorage.getItem("frontph") == "undefined" && localStorage.getItem("frontph") == null) {
                alert("Front Document is required");
                return;
            }

            if (localStorage.getItem("internalMarketh") == "undefined" || localStorage.getItem("internalMarketh") == null) {
                alert("Front With Market Document is required");
                return;
            }

            if (localStorage.getItem("leftShoth") == "undefined" || localStorage.getItem("leftShoth") == null) {
                alert("Internal Left Shot Document is required");
                return;
            }

            if (localStorage.getItem("leftWallh") == "undefined" || localStorage.getItem("leftWallh") == null) {
                alert("Internal Left Wall Document is required");
                return;
            }


            if (localStorage.getItem("rightWallh") == "undefined" || localStorage.getItem("rightWallh") == null) {
                alert("Internal Right Wall Document is required");
                return;
            }


            for (i = 1; i < table.rows.length; i++) {

                var objCells = table.rows[i].cells;

                leadBrands = {
                    brand: objCells[0].innerText,
                    value: objCells[1].getElementsByTagName('input')[0].value
                }
                brandValueJson.push(leadBrands);
            }


            var leadDetailObject = {};

            leadDetailObject['leadId'] = leadId;


            leadDetailObject['outletName'] = outletName;

            leadDetailObject['counterSize'] = counterSize;

            leadDetailObject['leadBrands'] = brandValueJson;


            console.log(localStorage.getItem("frontp"));


            leadDetailObject['frontp'] = localStorage
                .getItem("frontph");


            leadDetailObject['frontWithMarket'] = localStorage
                .getItem("internalMarketh");


            leadDetailObject['internalLongShot'] = localStorage
                .getItem("leftShoth");


            leadDetailObject['internalLeftWall'] = localStorage
                .getItem("leftWallh");


            leadDetailObject['internalRightWall'] = localStorage
                .getItem("rightWallh");

            console.log(leadDetailObject);

            if (confirm("Are you sure you want to add lead detail!") == true) {
                doPostAjaxRequestWithJsonHandler(context + "/leadDetail", JSON.stringify(leadDetailObject), function (response) {
                    console.log(response);
                    if (response == 'true') {
                        alert("Submit Successfully");
                    }

                });
            }

        });


    $(document).on('change', '.frontp',
        function () {

            if (confirm('Document has been selected, Do you want to upload ?')) {

                var documentId = uploadImage(this, "frontph");


            } else {

            }
        });

    $(document).on('change', '.internalMarket',
        function () {

            if (confirm('Document has been selected, Do you want to upload ?')) {

                var documentId = uploadImage(this, "internalMarketh");

            } else {

            }
        });

    $(document).on('change', '.leftShot',

        function () {
            if (confirm('Document has been selected, Do you want to upload ?')) {
                var documentId = uploadImage(this, "leftShoth");
            } else {

            }
        });

    $(document).on('change', '.leftWall',
        function () {
            if (confirm('Document has been selected, Do you want to upload ?')) {
                var documentId = uploadImage(this, "leftWallh");
            } else {

            }
        });

    $(document).on('change', '.rightWall',
        function () {
            if (confirm('Document has been selected, Do you want to upload ?')) {
                var documentId = uploadImage(this, "rightWallh");
            } else {
            }
        });


});

function uploadImage(fileSelector, attrName) {
    var documentId;
    if (fileSelector != undefined
        && fileSelector.files[0] != undefined) {
        var url = context
            + '/document-upload';

        console.log(url);
        var file = fileSelector.files[0];

        console.log(file)
        doAjaxUploadRequestHandler(
            url,
            'POST',
            file,
            function (response) {
                console.log(response)
                documentId = response.response.document_id;
                console
                    .log("documentId : "
                        + documentId);


                localStorage
                    .setItem(
                        attrName,
                        documentId);

            });
        return documentId;
    }

}


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

function loadClosedLead(domId, searchTerm) {
    doGetAjaxRequestHandler(context + "/getClosedLead", function (response) {
        $('#' + domId).html(response);
    })
}

function statusAction() {
    var val = $('#status').val();
    if (val == "followUp") {
        $("#scheduleTime").show();
    } else {
        $("#scheduleTime").hide();
    }

}


function editStatusAction() {
    var val = $('#editStatus').val();
    if (val == "followUp") {
        $("#editScheduleTime").show();
    } else {
        $("#editScheduleTime").hide();
    }

}

function loadLeadSearchInfo(search_text) {
    loadSearchLead("main-content", search_text);
}

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

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

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

function loadSearchLead(domId, search_text) {
    doGetAjaxRequestHandler(context + "/searchLeads?searchTerm=" + search_text,
        function (response) {
            $('#' + domId).html(response);
        });
}

$(document).on('click', ".arr-button-mk",
    function () {
        var startDate = $('.arr-start_date').val();
        doGetAjaxRequestHandler(context + "/rbmTodayArr?startDate=" + startDate, function (response) {
            $('#main-content').html(response);

        });
    });

$(document).on('click', ".rbm-today-arr",
    function () {
        doGetAjaxRequestHandler(context + "/rbmTodayArr", function (response) {
            $('#main-content').html(response);

        });
    });
$(document).on('click', '.reassign', function () {
    $('#bulkReassignFile').val(null);
    $('#bulkReassignFile').click();
});

$(document).on('change', '#bulkReassignFile', function () {

    if (!confirm("Confirm bulk reassign upload?")) {
        return;
    }

    var file = this.files[0];
    if (!file) {
        alert("No file selected");
        return;
    }

    doAjaxUploadRequestHandler(
        context + "/upload-assign-id",
        'POST',
        file,
        function (response) {
            alert("Bulk reassignment completed");
            loadLead("main-content");
        }
    );
});