<?php

function get_fi_asset_quantity_adjustment_headers($cutoff_date, $batch_size)
{
    $sql = "SELECT h.*,
                    r.project_id 
            FROM ".TB_PREF."asset_quantity_adjustments h  
                JOIN ".TB_PREF."asset_quantity_adjustment_requests r 
                    ON h.aqar_id = r.id 
            WHERE h.tran_date <= ".db_escape($cutoff_date)."   
                    AND h.fi_batch_no = 0 
            ORDER BY h.id LIMIT ".$batch_size;

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

function get_fi_asset_quantity_adjustment_details($aqa_no)
{
    $sql = "SELECT d.id detail_line_id,
                    d.asset_id,
                    d.quantity, 
                    d.asset_value, 
                    rh.is_deduction,
                    c.asset_account, 
                    c.depreciation_account, 
                    c.accumulated_account, 
                    c.valuation_account, 
                    c.disposal_account, 
                    c.asset_adjustment_account  
            FROM ".TB_PREF."asset_quantity_adjustment_details d 
                JOIN ".TB_PREF."asset_quantity_adjustment_request_details rd 
                    ON rd.id = d.aqar_line_id 
                JOIN ".TB_PREF."asset_quantity_adjustment_requests rh  
                    ON rh.id = rd.aqar_id  
                JOIN ".TB_PREF."asset_master m 
                    ON m.asset_id = d.asset_id 
                JOIN ".TB_PREF."asset_catergories c 
                    ON c.id = m.asset_category_id 
            WHERE d.aqa_id = ".db_escape($aqa_no);


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