/* 
 * Author       : Jai K
 * Purpose      : Script for Inventory Report
 * Created On   : 2017-01-31 18:28
 */

$(document).on('ready', function(){
    
    $('[name="item"]').on('change', function(){
        var itemId = $(this).val();
        
        if( itemId != '' ) {
            // Get Details
            
            var data = {
                act     : 'details',
                itemId  : itemId, 
            };
            
            $.post( baseURL + controller + '/ajax/', data, function(res){
                var res     = JSON.parse(res) || ""
                ,   details = res.details[0]
                ,   availQty = details.available_qty || 0
                ,   issuedQty= details.issued_qty || 0
                ,   balQty  = details.bal_issued_qty || 0;
                
                $('[name="qty"]').val( details.quantity || 0 );
                $('[name="sell_price"]').val( details.selling_price || '0.00' );
                $('[name="available_qty"]').val( availQty );
                $('[name="sale_qty"]').val( issuedQty );
                $('[name="balance_qty"]').val( balQty > 0 ? balQty : ( availQty - issuedQty ) );
                
                if( res.details != '' ) {
                    
                }
                
            });
            
            
        }
    });
    
});


