<?php



function get_fi_goods_received_notes($cutoff_date, $batch_size)
{
    $sql = "SELECT grn.id trans_no, 
                    grn.supplier_id,
                    grn.delivery_date tran_date, 
                    grn.purch_order_no  
            FROM ".TB_PREF."grn_batch grn  
                JOIN ".TB_PREF."purch_orders po ON 
                    po.order_no = grn.purch_order_no   
                JOIN ".TB_PREF."suppliers sup ON 
                    sup.supplier_id = po.supplier_id  
            WHERE grn.delivery_date <= ".db_escape($cutoff_date)."  
                    AND grn.fi_batch_no = 0 
            ORDER BY grn.id LIMIT ".$batch_size;

    return db_query($sql);
}

function get_fi_goods_received_note_details($grn_no)
{
    $sql = "SELECT gi.id detail_line_id,
                    gi.grn_batch_id trans_no,
                    gi.item_code stock_id,
                    gi.qty_recd, 
                    gi.unit_cost,            
                    sm.mb_flag, 
                    sm.inventory_account, 
                    sm.cogs_account,
                    sm.adjustment_account, 
                    sm.sales_account, 
                    sm.assembly_account,
                    sm.description  
            FROM ".TB_PREF."grn_items gi  
                JOIN ".TB_PREF."stock_master sm ON 
                    gi.item_code = sm.stock_id 
            WHERE gi.grn_batch_id = ".db_escape($grn_no);
                    

    return db_query($sql);
}

?>