<?php

function get_fi_inventory_adjustments($cutoff_date, $trans_type, $batch_size)
{
    $sql = "SELECT sa.* 
            FROM ".TB_PREF."stock_adjustments sa   
            WHERE sa.ai_date <= ".db_escape($cutoff_date)."  
                    AND sa.type = ".db_escape($trans_type)."  
                    AND sa.fi_batch_no = 0 
            ORDER BY sa.id LIMIT ".$batch_size;

    return db_query($sql);
}

function get_fi_inventory_adjustments_details($trans_type, $im_no)
{
    $sql = "SELECT mov.trans_id detail_line_id,
                    mov.type,
                    mov.trans_no,
                    mov.stock_id,
                    mov.qty, 
                    mov.standard_cost,               
                    stk.mb_flag, 
                    stk.inventory_account, 
                    stk.adjustment_account, 
                    stk.description 
            FROM ".TB_PREF."stock_moves mov  
                JOIN ".TB_PREF."stock_master stk ON 
                    stk.stock_id = mov.stock_id 
            WHERE mov.type = ".db_escape($trans_type)." 
                    AND mov.trans_no = ".db_escape($im_no);
                    

    return db_query($sql);
}
