Subversion Repositories SmartDukaan

Rev

Rev 23419 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function() {
        $(".good_inventory").live('click', function() {
                loadGoodInventory("main-content","");
        });
        
        $(".catalog").live('click', function() {
                loadCatalog("main-content","");
        });
        
        $(".item_aging").live('click', function() {
                getInventoryItemAgingByInterval("main-content", "");
        });
        
        $("#item-aging-paginated .next").live('click', function() {
                var end = $( "#item-aging-paginated .end" ).text();
                getItemAgingNextPreviousItems(end, "");
                $("#item-aging-paginated .next").blur();
    });
        
        $("#item-aging-search-button").live('click', function() {
                searchContent = $("#item-aging-search-text").val();
                if (typeof (searchContent) == "undefined" || !searchContent){
                        searchContent = "";
                }
                getInventoryItemAgingByInterval("main-content", searchContent);
    });
        
        
        $("#item-aging-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
        if(keyCode == 13){
                $("#item-aging-search-button").click();
        }
        });
        
        $("#item-aging-paginated .previous").live('click', function() {
                var start = $( "#item-aging-paginated .start" ).text();
                getItemAgingNextPreviousItems(start - 11, "");
                $("#item-aging-paginated .previous").blur();
    });
        
        $(".download_aging_report").live('click', function() {
                downloadAgingReport();
        });
        
        $(".item-ledger-report-download-page").live('click', function() {
                loadItemLedgerReportDownloadPage("main-content");
        });
        
        /*$(".item-ledger-report-download").live('click', function() {
                var startEndDateTime = $('input[name="startEndDateTime"]').val().split("-");
                var startDateTime = $.trim(startEndDateTime[0]);
                var endDateTime = $.trim(startEndDateTime[1]);
                downloadItemLedgerReport(startDateTime, endDateTime);
        });*/
        
        $(".bad_inventory").live('click', function() {
                loadBadInventory("main-content","");
        });
        
        $("#good-inventory-paginated .next").live('click', function() {
                var start = $( "#good-inventory-paginated .start" ).text();
                var end = $( "#good-inventory-paginated .end" ).text();
                var searchText = $("#good-inventory-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                getNextItems(start,end, searchText);
                $("#good-inventory-paginated .next").blur();
                
    });
        
        $("#good-inventory-paginated .previous").live('click', function() {
                var start = $( "#good-inventory-paginated .start" ).text();
                var end =  $( "#good-inventory-paginated .end" ).text();
                var searchText = $("#good-inventory-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                var pre = end - 20;
                getPreviousItems(start, end, pre, searchText);
                $("#good-inventory-paginated .previous").blur();
    });
        
        $("#good-inventory-search-button").live('click', function() {
                var searchText = $("#good-inventory-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                loadGoodInventorySearchInfo(searchText);
    });
        
        $("#good-inventory-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
        if(keyCode == 13){
                $("#good-inventory-search-button").click();
        }
        });
        
        
        $("#catalog-paginated .next").live('click', function() {
                var start = $( "#catalog-paginated .start" ).text();
                var end = $( "#catalog-paginated .end" ).text();
                var searchText = $("#catalog-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                getNextCatalogItems(start,end,searchText);
                $("#catalog-paginated .next").blur();
    });
        
        $("#catalog-paginated .previous").live('click', function() {
                var start = $( "#catalog-paginated .start" ).text();
                var end =  $( "#catalog-paginated .end" ).text();
                var searchText = $("#catalog-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                var pre = end - 20;
                getPreviousCatalogItems(start,end,pre,searchText);
                $("#catalog-paginated .previous").blur();
    });
        
        $("#catalog-search-button").live('click', function() {
                var searchText = $("#catalog-search-text").val();
                if (typeof (searchText) == "undefined" || !searchText){
                        searchText = "";
                }
                loadCatalogSearchInfo(searchText);
    });
        
        $("#catalog-search-text").live("keyup", function(e) {
                var keyCode = e.keyCode || e.which;
        if(keyCode == 13){
                $("#catalog-search-button").click();
        }
        });
        
});


function loadGoodInventory(domId, search_text){
        doAjaxRequestHandler(context+"/getCurrentInventorySnapshot/?searchTerm="+search_text, "GET", function(response){
                $('#' + domId).html(response);
        });
}

function loadCatalog(domId, search_text){
        doAjaxRequestHandler(context+"/getCatalog/?searchTerm="+search_text, "GET", function(response){
                $('#' + domId).html(response);
        });
}

function getInventoryItemAgingByInterval(domId, searchContent){
        doAjaxRequestWithJsonHandler(context+"/getInventoryItemAgingByInterval?searchContent="+searchContent, "POST", JSON.stringify([5,15,30,45]), function(response){
                $('#' + domId).html(response);
        });
}


function downloadAgingReport(){
        data = JSON.stringify([5,15,30,45]),
        doAjaxPostDownload(context+"/downloadInventoryItemAgingByInterval",
                        data, "InventoryItemAging.xlsx");
        
}

function downloadItemLedgerReport(){
        console.log("downloadItemLedgerReport Button clicked")
        var startDateTime = $('input[name="startDateTime"]').val();
        console.log("startDateTime : "+startDateTime);
        var endDateTime = $('input[name="endDateTime"]').val();
        console.log("endDateTime : "+endDateTime);
        //data = JSON.stringify([5,10,15,20,25,30,35,40]),
        doAjaxGetDownload(context+"/itemLedger/complete/download?startDateTime="+startDateTime+"&endDateTime="+endDateTime,
                        "ItemCompleteLedegerReport.xlsx");
}


function getItemAgingNextPreviousItems(offset, searchContent){
        console.log("getItemAgingNextPreviousItems() called");
        doAjaxRequestWithJsonHandler(context+"/getInventoryItemAgingByInterval?offset="+offset+"&searchContent="+searchContent, "POST", JSON.stringify([5,15,30,45]), function(response){
                $('#main-content').html(response);
        });
        
}


function loadBadInventory(domId, search_text){
        doAjaxRequestHandler(context+"/getBadInventorySnapshot/?searchTerm="+search_text, "GET", function(response){
                $('#' + domId).html(response);
        });
}


function getNextItems(start, end, searchText){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        doAjaxRequestHandler(context+"/getPaginatedCurrentInventorySnapshot/?offset="+end+"&searchTerm="+searchText, "GET", function(response){
                $( "#good-inventory-paginated .end" ).text(+end + +10);
                $( "#good-inventory-paginated .start" ).text(+start + +10);
                var last = $( "#good-inventory-paginated .end" ).text();
                var temp = $( "#good-inventory-paginated .size" ).text();
                if (parseInt(last) >= parseInt(temp)){
                        $("#good-inventory-paginated .next").prop('disabled', true);
                        //$( "#good-inventory-paginated .end" ).text(temp);
                }
            $('#good-inventory-table').html(response);
            $("#good-inventory-paginated .previous").prop('disabled', false);
        });
        
    
}

function getPreviousItems(start,end,pre,searchText){
        doAjaxRequestHandler(context+"/getPaginatedCurrentInventorySnapshot/?offset="+pre+"&searchTerm="+searchText, "GET", function(response){
                $( "#good-inventory-paginated .end" ).text(+end - +10);
                $( "#good-inventory-paginated .start" ).text(+start - +10);
                $('#good-inventory-table').html(response);
                $("#good-inventory-paginated .next").prop('disabled', false);
                if (parseInt(pre)==0)
                {
                        $("#good-inventory-paginated .previous").prop('disabled', true);
                }
        });
        
}

function loadGoodInventorySearchInfo(search_text){
        loadGoodInventory("main-content",search_text);
}


function getNextCatalogItems(start, end, searchText){
        console.log(start);
        console.log(end);
        console.log(+end + +10);
        console.log(+start + +10);
        doAjaxRequestHandler(context+"/getPaginatedCatalog/?offset="+end+"&searchTerm="+searchText, "GET", function(response){
                $( "#catalog-paginated .end" ).text(+end + +10);
                $( "#catalog-paginated .start" ).text(+start + +10);
                var last = $( "#catalog-paginated .end" ).text();
                var temp = $( "#catalog-paginated .size" ).text();
                if (parseInt(last) >= parseInt(temp)){
                        $("#catalog-paginated .next").prop('disabled', true);
                }
            $('#catalog-table').html(response);
            $("#catalog-paginated .previous").prop('disabled', false);
        });
}

function getPreviousCatalogItems(start,end,pre,searchText){
        doAjaxRequestHandler(context+"/getPaginatedCatalog/?offset="+pre+"&searchTerm="+searchText, "GET", function(response){
                $( "#catalog-paginated .end" ).text(+end - +10);
                $( "#catalog-paginated .start" ).text(+start - +10);
                $('#catalog-table').html(response);
                $("#catalog-paginated .next").prop('disabled', false);
                if (parseInt(pre)==0)
                {
                        $("#catalog-paginated .previous").prop('disabled', true);
                }
        });
        
}

function loadCatalogSearchInfo(search_text){
        loadCatalog("main-content",search_text);
}

function loadItemLedgerReportDownloadPage(domId){
        doAjaxRequestHandler(context+"/itemLedger/downloadPage", "GET", function(response){
                $('#' + domId).html(response);
        });
}