Subversion Repositories SmartDukaan

Rev

Rev 26320 | Rev 27763 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(document).on('click', "a.view-returns", function() {
                viewReturnStores("main-content");
        });
        $(document).on('click', "a.pending-returns", function() {
                viewPendingReturns("main-content");
        });
        $(document).on('click', "a.approved-returns", function() {
                viewApprovedReturns("main-content");
        });

        $(document).on('click', "a.view-debit-note", function() {
                viewDebitNotes("main-content");
        });

        $(document).on('click', "a.wh-display-name", function() {
                var whId = $(this).closest('tr').data('id');
                $("#approved-returns-container").find("tr.filter").hide().filter('[data-id="' + whId + '"]').show();
                $(this).closest('table').find('tr').removeClass('warning');
                $(this).closest('tr').addClass('warning');
        });

        $(document).on('click', "a.debit-note", function() {
                var debitNoteId = $(this).closest('tr').data('id');
                $("#debit-note-items").find("tr.filter").hide().filter('[data-id="' + debitNoteId + '"]').show();
                $(this).closest('table').find('tr').removeClass('warning');
                $(this).closest('tr').addClass('warning');
        });
        
        
        $(document).on('click', "a.request-return", function() {
                if(confirm("Are you sure?")) {
                        createReturnRequest($(this).data("inventoryitemid"), $(this));
                }
        });
        $(document).on('click', "a.approve-return", function() {
                if(confirm("Are you sure to Approve?")) {
                        approveReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
                }
        });
        $(document).on('click', "a.deny-return", function() {
                if(confirm("Are you sure to Deny?")) {
                        denyReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
                }
        });
        /*$(document).on('click', "a.generate-debit-note", function() {
                if(confirm("Are you sure?")) {
                        generateDebitNote($(this).closest('tr').data("id"));
                }
        });*/
        /*$(document).on('click', '#store-container').find('a', function (){
                fofoId=$(this).data('id');
                doAjaxRequestHandler(context+"/return/inventory/" + fofoId, "GET", function(response){
                        inventoryTable.rows().remove().rows.add($(response)).draw(false);
                });
        });*/
        $(document).on('click', '#inventory-container').find('a', function (){
                itemId=$(this).data('id');
                doAjaxRequestHandler(context+"/return/inventory/" + fofoId + "/" + itemId, "GET", function(response){
                        returnsTable.rows().remove().rows.add($(response)).draw(false);
                });
        });
});

function viewReturnStores(domId){
        doAjaxRequestHandler(context+"/return/stores", "GET", function(response){
                $('#' + domId).html(response);
        });
}

function viewPendingReturns(domId){
        doAjaxRequestHandler(context+"/return/pending", "GET", function(response){
                $('#' + domId).html(response);
        });
}

function viewApprovedReturns(domId){
        doAjaxRequestHandler(context+"/return/approved", "GET", function(response){
                $('#' + domId).html(response);
                $("#approved-returns").find('a:first').click();
        });
}

function viewDebitNotes(domId){
        doAjaxRequestHandler(context+"/return/debit-note-created", "GET", function(response){
                $('#' + domId).html(response);
                $("#debit-notes").find('a:first').click();
        });
}

function createReturnRequest(inventoryItemId, container){
        doAjaxRequestHandler(context+"/return/inventory/" + inventoryItemId, "PUT", function(response){
                if(response=='true') {
                        container.closest('td').html('Return requested');
                }
        });
}

function approveReturnRequest(inventoryItemId, container){
        doAjaxRequestHandler(context+"/return/inventory/approve/" + inventoryItemId, "PUT", function(response){
                if(response=='true') {
                        container.closest('td').html('Return Approved');
                }
        });
}

function denyReturnRequest(inventoryItemId, container){
        doAjaxRequestHandler(context+"/return/inventory/deny/" + inventoryItemId, "PUT", function(response){
                if(response=='true') {
                        container.closest('td').html('Return denied');
                }
        });
}

function viewDebitNote(warehouseId){
        doAjaxRequestHandler(context+"/return/debit-note/view/" + warehouseId, "GET", function(response){
                //Download PDF code
        });
}

function generateDebitNote(warehouseId){
        doAjaxRequestHandler(context+"/return/debit-note/generate/" + warehouseId, "PUT", function(response){
                if(response=='true') {
                        //Download the pdf 
                }
        });     
}

function getDebitNote(debitNotedId) {
        doAjaxRequestHandler(context+"/return/debit-note/" + debitNotedId, "GET", function(response){
                        
        });
}