<?php


function get_fi_stock_asset_transfer_headers($cutoff_date, $batch_size)
{
    $sql = "SELECT sath.id trans_no, 
                    sath.tran_date ,
                    sath.is_return 
            FROM ".TB_PREF."stock_asset_transfer_header sath  
            WHERE sath.tran_date <= ".db_escape($cutoff_date)."  
                    AND sath.fi_batch_no = 0 
            ORDER BY sath.id 
            LIMIT ".$batch_size;

    return db_query($sql, "get_fi_stock_asset_transfers");
}

function get_fi_stock_asset_transfer_details($trans_no)
{
    $sql = "SELECT c.asset_account, 
                    t.id,
                    t.asset_quantity,
                    t.value asset_value, 
                    t.stock_id,
                    t.stock_item_quantity, 
                    t.stock_item_cost, 
                    t.stock_project_id,
                    t.asset_project_id,
                    t.asset_id,
                    a.asset_code,
                    a.description asset_description,
                    sm.inventory_account,
                    gi.description stock_description 
            FROM ".TB_PREF."stock_asset_transfers t  
                JOIN ".TB_PREF."asset_master a 
                    ON a.asset_id = t.asset_id 
                JOIN ".TB_PREF."asset_catergories c  
                    ON c.id = a.asset_category_id  
                JOIN ".TB_PREF."stock_master sm   
                    ON sm.stock_id = t.stock_id   
                JOIN ".TB_PREF."grn_items gi   
                    ON gi.id = t.grn_line_no     

            WHERE t.trans_no = ".db_escape($trans_no);
                    

    return db_query($sql, "get_fi_stock_asset_transfer_details");
}