Subversion Repositories SmartDukaan

Rev

Rev 30859 | Rev 30867 | Go to most recent revision | 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");
        });


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


        });

        $(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', '.credit-requirement-send', function() {
                var row = $(this).closest("tr");
                console.log(row);
                var rowIndex = $(this).closest('tr').prevAll().length;
                console.log(rowIndex);
                var securityCheck = $(row).find(".checkhidden input[type=hidden]").val();

                console.log(securityCheck)
                var fofoId = $(row).find("td:eq(0)").text();



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

                console.log(freedays)

                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") == true) {
                        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("td:eq(12) input[type='text']").val();
                var freedays = $(row).find("td:eq(13) input[type='text']").val();

                var status = $(row).find("td:eq(14) option:selected").val();

                console.log(freedays)

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

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

                        });
                }


        })
});

function loadSdCredit(domId) {

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

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