<?php

//function get_fi_material_issues($cutoff_date)
//{
//    $sql = "SELECT im.im_no trans_no, 
//                    im.im_date tran_date,
//                    pm.cost_account 
//            FROM ".TB_PREF."issue_materials im    
//                JOIN ".TB_PREF."projects_master pm ON 
//                    im.project_id = pm.project_id  
//            WHERE im.im_date <= ".db_escape($cutoff_date)."  
//                    AND im.fi_batch_no = 0 
//            ORDER BY im.im_no LIMIT 1";
//
//    return db_query($sql);
//}
//
//function get_fi_material_issue_details($im_no)
//{
//    $sql = "SELECT d.id,
//                    d.im_no trans_no,
//                    d.item_code,
//                    d.qty_issued quantity, 
//                    d.unit_cost, 
//                    d.task_id,                
//                    sm.mb_flag, 
//                    sm.inventory_account, 
//                    sm.cogs_account,
//                    sm.adjustment_account, 
//                    sm.sales_account, 
//                    sm.assembly_account 
//            FROM ".TB_PREF."issue_material_details d 
//                JOIN ".TB_PREF."stock_master sm ON 
//                    d.item_code = sm.stock_id 
//            WHERE d.im_no = ".db_escape($im_no);
//                    
//
//    return db_query($sql);
//}

function get_fi_material_returns($cutoff_date, $batch_size)
{
    $sql = "SELECT rm.rm_no trans_no, 
                    rm.rm_date tran_date, 
                    rm.project_id,
                    pm.cost_account,
                    pm.type_id project_type_id 
            FROM ".TB_PREF."return_materials rm 
                JOIN ".TB_PREF."projects_master pm ON 
                    rm.project_id = pm.project_id  
            WHERE rm.rm_date <= ".db_escape($cutoff_date)."  
                    AND rm.fi_batch_no = 0 
            ORDER BY rm.rm_no LIMIT ".$batch_size;

    return db_query($sql);
}

function get_fi_material_return_details($rm_no)
{
    $sql = "SELECT rmd.id detail_line_id,
                    rmd.rm_no trans_no,
                    rmd.item_code,
                    rmd.qty_returned, 
                    rmd.unit_cost, 
                    rmd.task_id,                
                    sm.mb_flag,  
                    sm.inventory_account, 
                    sm.cogs_account,
                    sm.coc_account,
                    sm.cost_account,
                    sm.adjustment_account, 
                    sm.sales_account, 
                    sm.assembly_account,
                    sm.stock_id,
                    sm.description  
            FROM ".TB_PREF."return_material_details rmd 
                JOIN ".TB_PREF."stock_master sm ON 
                    rmd.item_code = sm.stock_id 
            WHERE rmd.rm_no = ".db_escape($rm_no);
                    

    return db_query($sql);
}

?>