<?php

function dashboard_get_department_petty_cash_expense_projects($from_date, $to_date, $department_id) {
    
    $sql = "SELECT b.project_id , SUM(ex.approved_amount) approved_total 
            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."projects_master pm    
                    ON pm.project_id = b.project_id  
            WHERE b.tran_date >= ".db_escape($from_date)." 
                AND b.tran_date <= ".db_escape($to_date)." 
                AND pm.department_id = ".db_escape($department_id)." 
            GROUP BY b.project_id  
            ORDER BY approved_total DESC ";    
                
        return db_query($sql, "dashboard_get_department_petty_cash_expense_projects"); 
}

function dashboard_get_department_petty_cash_period_expense_type_total($project_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 b.project_id = ".db_escape($project_id);
    
                
        $result = db_query($sql, "dashboard_get_department_petty_cash_period_expense_type_total"); 
        
        return db_result_value($result, 'approved_amount');
}
