<?php

function get_fi_subcontractor_invoices($cutoff_date, $batch_size)
{
    $sql = "SELECT si.order_no trans_no, 
                    si.ord_date tran_date,
                    si.supplier_id,
                    si.rate_include_taxes,
                    si.total,
                    si.taxes,
                    si.project_id,
                    supp.purchase_account,
                    supp.payable_account,
                    supp.payment_discount_account,
                    supp.curr_code,
                    pm.cost_account 
                    
            FROM ".TB_PREF."subcontractor_invoices si 
                JOIN ".TB_PREF."suppliers supp ON 
                    si.supplier_id = supp.supplier_id 
                JOIN ".TB_PREF."projects_master pm ON 
                    si.project_id = pm.project_id  
                    
            WHERE si.ord_date <= ".db_escape($cutoff_date)."  
                    AND si.approval_status = ".db_escape(AS_APPROVED)."  
                    AND si.fi_batch_no = 0 
                    
            ORDER BY si.order_no LIMIT ".$batch_size;

    return db_query($sql);
}


function get_fi_subcontractor_invoice_details($order_no)
{
    $sql = "SELECT sid.*
                                      
            FROM ".TB_PREF."subcontractor_invoice_details sid 
             
                    
            WHERE sid.order_no = ".db_escape($order_no);                    

    return db_query($sql);
}


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

    return db_query($sql);
}



?>