<?php

function get_fi_utility_bills($cutoff_date, $batch_size)
{
    $sql = "SELECT ub.id trans_no, 
                    ub.date tran_date,
                    ub.supplier_id,
                    ub.rate_include_taxes,
                    ub.total,
                    ub.taxes,
                    ub.project_id,
                    supp.purchase_account,
                    supp.payable_account,
                    supp.payment_discount_account,
                    supp.curr_code,
                    pm.cost_account,
                    pm.type_id project_type_id 
            FROM ".TB_PREF."utility_bills ub 
                JOIN ".TB_PREF."suppliers supp ON 
                    ub.supplier_id = supp.supplier_id 
                JOIN ".TB_PREF."projects_master pm ON 
                    ub.project_id = pm.project_id  
            WHERE ub.date <= ".db_escape($cutoff_date)."  
                    AND ub.approval_status = ".AS_APPROVED."  
                    AND ub.fi_batch_no = 0 
            ORDER BY ub.id LIMIT ".$batch_size;

    return db_query($sql);
}

function get_fi_utility_bill_details($ub_id)
{
    $sql = "SELECT d.id detail_line_id,
                    d.ub_id trans_no,
                    d.amount, 
                    d.expense_type_id,               
                    expt.debit_account, 
                    expt.coc_account  
            FROM ".TB_PREF."utility_bill_details d 
                JOIN ".TB_PREF."utility_expense_types expt ON 
                    d.expense_type_id = expt.id 
            WHERE d.ub_id = ".db_escape($ub_id);
                    

    return db_query($sql);
}


function get_fi_utility_bill_taxes($ub_id)
{
    $sql = "SELECT ubtx.id,
                    ubtx.ub_id trans_no,
                    ubtx.amount, 
                    tt.sales_gl_code,               
                    tt.purchasing_gl_code,
                    tt.suspended         
                    
            FROM ".TB_PREF."utility_bill_taxes ubtx 
                JOIN ".TB_PREF."tax_types tt 
                    ON ubtx.tax_type_id = tt.id  
            WHERE ubtx.ub_id = ".db_escape($ub_id);
                    

    return db_query($sql);
}



?>