<?php

//function dashboard_get_petty_cash_outstanding_employees($company_code, $employee_code, $expenses_filter, $from_date, $to_date)
//{
//    $trans_sql = get_sql_for_employee_petty_cash_outstanding_transactions($company_code, $employee_code, $expenses_filter, $from_date, $to_date);
//    
//    $sql = "SELECT DISTINCT(employee_code), SUM(amount) approved_total  
//            FROM ($trans_sql) tmp_table 
//            GROUP BY employee_code 
//            ORDER BY approved_total DESC";
//    
//    return db_query($sql); 
//    
//}

//function dashboard_get_petty_cash_outstanding_employees($from_date, $to_date) {
//    
//    $sql = "SELECT ex.expense_type_id , SUM(ex.approved_amount) approved_total , n.value_name  expense_type_name 
//            FROM ".TB_PREF."i_owe_you_expenses ex  
//                JOIN ".TB_PREF."i_owe_you_batches b  
//                    ON ex.iou_batch_no = b.batch_no 
//                JOIN ".TB_PREF."list_values n   
//                    ON n.id = ex.expense_type_id  
//            WHERE b.tran_date >= ".db_escape($from_date)." 
//                AND b.tran_date <= ".db_escape($to_date)." 
//            GROUP BY ex.expense_type_id  
//            ORDER BY approved_total DESC ";    
//                
//        return db_query($sql, "dashboard_get_petty_cash_expense_types"); 
//}


function dashboard_get_period_petty_cash_outstanding_total($company_code, $employee_code, $expenses_filter, $from_date, $to_date){
    
    $trans_sql = get_sql_for_employee_petty_cash_outstanding_transactions($company_code, $employee_code, $expenses_filter, $from_date, $to_date);
    
    $sql = "SELECT SUM(amount) total FROM ($trans_sql) tmp_table";
    
    $result =  db_query($sql);
    return db_result_value($result, "total");
    
    
}
    
//function dashboard_get_petty_cash_period_expense_type_total($expense_type_id, $from_date, $to_date) {
//    
//    $sql = "SELECT SUM(ex.approved_amount) approved_amount   
//            FROM ".TB_PREF."i_owe_you_expenses ex  
//                JOIN ".TB_PREF."i_owe_you_batches b  
//                    ON ex.iou_batch_no = b.batch_no  
//            WHERE b.tran_date >= ".db_escape($from_date)." 
//                AND b.tran_date <= ".db_escape($to_date)." 
//                AND ex.expense_type_id = ".db_escape($expense_type_id);
//    
//                
//        $result = db_query($sql, "dashboard_get_petty_cash_period_expense_type_total"); 
//        
//        return db_result_value($result, 'approved_amount');
//}
