Subversion Repositories SmartDukaan

Rev

Rev 31405 | Rev 31409 | Go to most recent revision | 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 leadDate = $("#dateWiseLead").val();
                var status = $("#statusFilter").val();
                var color = $("#colorFilter").val();

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


                console.log(leadDate);

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


        });


        $(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();

                        console.log(communicationType);
                        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;
                        }

                        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
                        if (status == "followUp") {
                                leaddetailData['schelduleTimestamp'] = getDatesFromPicker('#scheduleTime').startDate;

                                leaddetailData['communicationType'] = communicationType
                        }
                        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");

                                                }
                                        });

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

                $('input[name="remark"]').val("")
                $("#assignTo").val("")
                $("#editStatus").val("");
                $("#reason").val("");
                $("#statusFilter").val("");


                row = $(this).closest("tr");
                $("#editScheduleTime").hide();
                leadId = $(this).data('leadid');
                console.log(leadId)

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

                                console.log(response.response)

                                var data = response.response;

                                if (data != null) {
                                        $('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 reason = $("#reason").val();

                        var leadDate = $("#dateWiseLead").val();
                        var leadStatus = $("#statusFilter").val();
                        var color = $("#colorFilter").val();
                        var communicationType = $("#communicationType").val();


                        console.log(leadDate)
                        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

                        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('brandtable');
                        var brandValueJson = [];
                        var leadBrands;

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

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

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

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

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

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


                        if (localStorage.getItem("rightWall") == "undefined") {
                                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"));

                        if (localStorage.getItem("frontp") == "undefined") {
                                leadDetailObject['frontp'] = 0;
                        } else {
                                leadDetailObject['frontp'] = localStorage
                                        .getItem("frontp");
                        }

                        if (localStorage.getItem("internalMarket") == "undefined") {
                                leadDetailObject['frontWithMarket'] = 0;
                        } else {
                                leadDetailObject['frontWithMarket'] = localStorage
                                        .getItem("internalMarket");
                        }

                        if (localStorage.getItem("leftShot") == "undefined") {
                                leadDetailObject['internalLongShot'] = 0;
                        } else {
                                leadDetailObject['internalLongShot'] = localStorage
                                        .getItem("leftShot");
                        }

                        if (localStorage.getItem("leftWall") == "undefined") {
                                leadDetailObject['internalLeftWall'] = 0;
                        } else {
                                leadDetailObject['internalLeftWall'] = localStorage
                                        .getItem("leftWall");
                        }

                        if (localStorage.getItem("rightWall") == "undefined") {
                                leadDetailObject['internalRightWall'] = 0;
                        } else {
                                leadDetailObject['internalRightWall'] = localStorage
                                        .getItem("rightWall");
                        }

                        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 fileSelector = $('#frontp')[0];

                                var documentId = uploadImage(fileSelector, "frontp");





                        } else {

                        }
                });

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

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

                                var fileSelector = $('#internalMarket')[0];

                                var documentId = uploadImage(fileSelector, "internalMarket");

                        } else {

                        }
                });

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

                function() {

                        if (confirm('Document has been selected, Do you want to upload ?')) {
                                var fileSelector = $('#leftShot')[0];

                                var documentId = uploadImage(fileSelector, "leftShot");



                        } else {

                        }
                });

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

                        if (confirm('Document has been selected, Do you want to upload ?')) {
                                var fileSelector = $('#leftWall')[0];

                                var documentId = uploadImage(fileSelector, "leftWall");



                        } else {

                        }
                });

        $(document).on('change', '#rightWall',

                function() {

                        if (confirm('Document has been selected, Do you want to upload ?')) {
                                var fileSelector = $('#rightWall')[0];

                                var documentId = uploadImage(fileSelector, "rightWall");




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