<?php


function get_fi_utility_bill_credit_notes($cutoff_date, $batch_size)
{
    $sql = "SELECT ubcn.id trans_no, 
                    ubcn.date tran_date,
                    ubcn.supplier_id,
                    ubcn.rate_include_taxes,
                    ubcn.total,
                    ubcn.taxes,
                    ubcn.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_bill_credit_notes ubcn
                JOIN ".TB_PREF."suppliers supp ON 
                    ubcn.supplier_id = supp.supplier_id             
                  
                JOIN ".TB_PREF."projects_master pm ON 
                    ubcn.project_id = pm.project_id  
                    
            WHERE ubcn.date <= ".db_escape($cutoff_date)." 
                    AND ubcn.approval_status = ".db_escape(AS_APPROVED)." 
                    AND ubcn.fi_batch_no = 0 
                    
            ORDER BY ubcn.id LIMIT ".$batch_size;

    return db_query($sql);
}


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

    return db_query($sql);
}


function get_fi_utility_bill_credit_note_taxes($trans_no)
{
    $sql = "SELECT tx.id,
                    tx.ubcn_id trans_no,
                    tx.amount, 
                    tt.sales_gl_code,               
                    tt.purchasing_gl_code,
                    tt.suspended 
                    
            FROM ".TB_PREF."utility_bill_credit_note_taxes tx 
                JOIN ".TB_PREF."tax_types tt ON 
                    tx.tax_type_id = tt.id 
                    
            WHERE tx.ubcn_id = ".db_escape($trans_no);
                    

    return db_query($sql);
}



?>