Subversion Repositories SmartDukaan

Rev

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

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

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

        $("a.wh-display-name").live('click', 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');
        });

        $("a.debit-note").live('click', 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');
        });
        
        
        $("a.request-return").live('click', function() {
                if(confirm("Are you sure?")) {
                        createReturnRequest($(this).data("inventoryitemid"), $(this));
                }
        });
        $("a.approve-return").live('click', function() {
                if(confirm("Are you sure to Approve?")) {
                        approveReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
                }
        });
        $("a.deny-return").live('click', function() {
                if(confirm("Are you sure to Deny?")) {
                        denyReturnRequest($(this).closest('td').data("returnid"), $(this).closest('td'));
                }
        });
        /*$("a.generate-debit-note").live('click', function() {
                if(confirm("Are you sure?")) {
                        generateDebitNote($(this).closest('tr').data("id"));
                }
        });*/
        /*$('#store-container').find('a').live('click', function (){
                fofoId=$(this).data('id');
                doAjaxRequestHandler(context+"/return/inventory/" + fofoId, "GET", function(response){
                        inventoryTable.rows().remove().rows.add($(response)).draw(false);
                });
        });*/
        $('#inventory-container').find('a').live('click', 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){
                        
        });
}