Subversion Repositories SmartDukaan

Rev

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

$(function () {

    $(document).on('click', ".sd-credit", function () {

        loadSdCredit("main-content");
    });


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

        loadSanctionRequest("main-content");
    });

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

        loadRBML2SanctionRequest("main-content");
    });


    $(document).on('click', ".loan-summary", function () {

        loadLoanDetail("main-content");
    });


    $(document).on('click', ".sanction-order-hold", function () {

        loadSanctionHoldOrder("main-content");
    });


    $(document).on('click', ".sanction-order-unhold", function () {

        loadSanctionUnholdOrder("main-content");
    });
    var table = $('#sdCredit').DataTable();
    $(document).on('dblclick', '#sdCredit tbody tr', function () {
        console.log("dblclick");
        var data = table.row(this).data();


        $(this).find(":input").attr('disabled', false).show();

        /*      $(this).find("input[name=interestRate]").attr('disabled', true);
            $(this).find("input[name=freeDays]").attr('disabled', true);
            $(this).find("input[name=creditDays]").attr('disabled', true);
     */

    });

    $(document).on('input', 'table#sdCredit input[type=file]', function () {
        if (confirm('Confirm upload ?')) {
            var fileSelector = $(this)[0];
            if (fileSelector != undefined
                && fileSelector.files[0] != undefined) {
                var url = `${context}/document-upload`;
                console.log(url);
                var file = this.files[0];
                console.log("file" + file);
                let fileInput = $(this);
                console.log("fileInput" + file);
                doAjaxUploadRequestHandler(
                    url,
                    'POST',
                    file,
                    function (response) {
                        console.log(response);
                        var documentId = response.response.document_id;
                        console.log("documentId : " + documentId);
                        fileInput.closest('td').find("input[type=hidden]").val(documentId);
                    });
                // alert("Retailer Shop Document
                // is required");
            }
        } else {
            // Do nothing!
        }
    });


    $(document).on('click', ".reset-hard-limit", function () {
        var id = $(this).data('id');
        const self = this;
        if (confirm("Are you sure you want to reset hard limit")) {
            var hardLimitInput = $(this).closest('td').find('input[name="hardLimit"]');
            doPutAjaxRequestHandler(`${context}/resetHardLimit?id=${id}`, function (response) {
                if (response) {
                    alert("Hard Limit reset.");
                    hardLimitInput.val('false');
                    $(self).closest('td').find('.reset-hard-limit').hide();

                }
            });
        }
    });

    $(document).on('click', '.add-credit-exception', function () {
        var row = $(this).closest("tr");
        var fofoId = $(this).data('fofoId');
        var partnerName = $(row).find("td:eq(2)").text().trim();

        if (confirm("Are you sure you want to add credit exception for today for " + partnerName + "?")) {
            doPostAjaxRequestHandler(context + "/addCreditBlockedException?fofoId=" + fofoId, function (response) {
                if (response === 'true' || response === true) {
                    alert("Credit exception added successfully for today!");
                } else {
                    alert("Failed to add credit exception. Please try again.");
                }
            });
        }
    });

    $(document).on('click', '.credit-requirement-send', function () {
        var row = $(this).closest("tr");
        console.log(row);
        var rowIndex = $(this).closest('tr').prevAll().length;
        console.log(rowIndex);
        var fofoId = $(row).find("td:eq(0)").text();

        var securityCheck = $(row).find("input[type=hidden]").val();


        console.log(securityCheck);


        var limit = $(row).find("td:eq(5) input[type='text']").val();
        var interest = $(row).find("td:eq(9) input[type='text']").val();
        var freedays = $(row).find("td:eq(10) input[type='text']").val();
        var creditDays = $(row).find("td:eq(11) input[type='text']").val();


                var sdCreditReq = {};
                sdCreditReq['fofoId'] = fofoId
                sdCreditReq['securityCheck'] = securityCheck
                sdCreditReq['limit'] = limit
                sdCreditReq['interest'] = interest
                sdCreditReq['freeDays'] = freedays
                sdCreditReq['creditDays'] = creditDays

        var jsonObject = JSON.stringify(sdCreditReq);

                console.log(jsonObject);
        if (confirm("Are you sure you want to submit the request")) {
                        doAjaxRequestWithJsonHandler(context + "/creditRequirement", "POST", jsonObject, function(response) {
                                row.html(response);
                                row.css("background-color", "#F8F8FF");

            });
        }


    })

    $(document).on('click', '.sanction-request-send', function () {
        var row = $(this).closest("tr");
        console.log(row);
        var rowIndex = $(this).closest('tr').prevAll().length;
        console.log(rowIndex);
        var id = $(row).find("td:eq(0)").text();


        var approvalAmount = $(row).find(".approveamount input[type='text']").val();
        var freedays = $(row).find(".freedays input[type='text']").val();


        var status = $(row).find(".sanctionstatus option:selected").val();

        var stockHold = $(row).find(".stockholdcheckbox input[type='checkbox']").is(":checked") ? true : false;


        console.log(freedays)

        var sanctionReq = {};
        sanctionReq['id'] = id
        sanctionReq['status'] = status
        sanctionReq['approvalAmount'] = approvalAmount
        sanctionReq['freeDays'] = freedays

        sanctionReq['stockHold'] = stockHold


        var jsonObject = JSON.stringify(sanctionReq);

        console.log(jsonObject);
        if (confirm("Are you sure you want to submit the request") == true) {
            doAjaxRequestWithJsonHandler(context + "/sanctionRequest", "POST", jsonObject, function (response) {
                row.html(response);
                row.css("background-color", "#F8F8FF");

            });
        }


    })

    $(document).on('click', '.l2-sanction-approval-send', function () {
        var row = $(this).closest("tr");
        console.log(row);
        var rowIndex = $(this).closest('tr').prevAll().length;
        console.log(rowIndex);
        var id = $(row).find("td:eq(0)").text();


        var approvalAmount = $(row).find(".approveamount input[type='text']").val();
        var freedays = $(row).find(".freedays input[type='text']").val();


        var status = $(row).find(".sanctionstatus option:selected").val();

        var stockHold = $(row).find(".stockholdcheckbox input[type='checkbox']").is(":checked") ? true : false;


        console.log(freedays)

        var sanctionReq = {};
        sanctionReq['id'] = id
        sanctionReq['status'] = status
        sanctionReq['approvalAmount'] = approvalAmount
        sanctionReq['freeDays'] = freedays

        sanctionReq['stockHold'] = stockHold


        var jsonObject = JSON.stringify(sanctionReq);

        console.log(jsonObject);
        if (confirm("Are you sure you want to submit the request") == true) {
            doAjaxRequestWithJsonHandler(context + "/rbmL2ApprovalSanctionRequest", "POST", jsonObject, function (response) {
                row.html(response);
                row.css("background-color", "#F8F8FF");

            });
        }


    })


    $(document).on('click', '.sanction-request-unhold', function () {
        var row = $(this).closest("tr");
        console.log(row);
        var transactionId = $(row).find("td:eq(3)").text();
        if (confirm("Are you sure you want to Unhold the request") == true) {

            doPostAjaxRequestHandler(context + "/unholdOrder?transactionId="
                + transactionId, function (response) {
                if (response == 'true') {
                    alert("unhold successfully");
                    loadSanctionUnholdOrder("main-content");
                }

            });
        }


    })

});

function loadSdCredit(domId) {

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

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

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

function loadLoanDetail(domId) {

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


function loadSanctionHoldOrder(domId) {

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

function loadSanctionUnholdOrder(domId) {

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