Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

$(function(){
        $('input[name$=itemId]').live('change', function(){
                updateItemDetails($(this).closest('tr'), $(this).val());
        });
        
        $('#addrow').live('click', function(){
                addNewRowForLineItem($('table#indentTable'));
        });
        
        $('a#remove-lineitem').live('click', function(){
                $(this).closest('tr').remove();
        });

        $('#generateIndentSheet').live('click', function(){
                downloadIndentSheet();
        });
});

function updateItemDetails(rowDom, itemId) {
        $.ajax({
                type    :       'GET',
                url             :       '/inventory/hotspot-indent!getItemDetails',
                data    :       'itemId=' + itemId,
                success :       function(response) {
                        itemdetail = eval('(' + response + ')');
                        $(rowDom).find('div#modelName').html(itemdetail.modelName);
                        $(rowDom).find('div#availableQty').html(itemdetail.availableQty);
                        $(rowDom).find('div#reservedQty').html(itemdetail.reservedQty);
                        $(rowDom).find('div#previouslyOrderedQty').html(itemdetail.openPOCount);
                        $(rowDom).find('div#avgSale').html(itemdetail.detailedAvgSales);
                        $(rowDom).find('div#minStockLevel').html(itemdetail.minStockLevel);
                        $(rowDom).find('div#numberOfDaysStock').html(itemdetail.numDaysStock);
                        $(rowDom).find('div#additionalQty').html(itemdetail.additionalQty);
                }
        });
}

function addNewRowForLineItem(table) {
    $(table).find('#new-item-detail').clone(true).insertAfter($(table).find('tbody>tr:last'));

    var newRow = $(table).find('tbody>tr:last');

    // Enabling the new record added
    $(newRow).find('input').removeAttr('disabled');
    $(newRow).removeAttr('id');

    // Making this row visible
    $(newRow).show();
}

function downloadIndentSheet() {
        var jsonData = '[';
        var rowCount = 0;
        $('#indentTable tr').each(function(){
                rowCount++;
                if(rowCount<=2){
                        ;
                } else {
                        jsonData = jsonData + '{"itemId":"';
                        jsonData = jsonData + $(this).find('input.itemId').val();
                        jsonData = jsonData + '","quantity":"';
                        jsonData = jsonData + $(this).find('input.quantity').val();
                        jsonData = jsonData + '"},'
                }
        });
        jsonData = jsonData.substring(0,jsonData.length-1);
        jsonData = jsonData + ']';
        
        $('<form id = "tempForm" method = "POST" action = "/inventory/hotspot-indent/">').appendTo('body');
        $('form#tempForm').append($('<input id = "jsoninput" name = "jsonData" value ='+jsonData +'>'));
        $('form#tempForm').submit();
}