<?php

function dashboard_get_transport_petty_cash_expense_vehicles($from_date, $to_date, $expense_type_id=0) {
    
    $sql = "SELECT ex.expense_item_id vehicle_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  
            WHERE ex.expense_category_id = ".db_escape(EC_VEHICLE_MAINTENANCE)." 
                AND b.tran_date >= ".db_escape($from_date)." 
                AND b.tran_date <= ".db_escape($to_date);
    
    if($expense_type_id > 0){
        $sql .= " AND ex.expense_type_id = ".db_escape($expense_type_id);
    }
    
    $sql .= " GROUP BY ex.expense_item_id 
            ORDER BY approved_total DESC ";    
                
        return db_query($sql, "dashboard_get_transport_petty_cash_expense_vehicles"); 
}

function dashboard_get_transport_petty_cash_period_expense_type_total($vehicle_id, $from_date, $to_date,$expense_type_id=0) {
    
    $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 ex.expense_category_id = ".db_escape(EC_VEHICLE_MAINTENANCE)."  
                AND b.tran_date >= ".db_escape($from_date)." 
                AND b.tran_date <= ".db_escape($to_date)." 
                AND ex.expense_item_id = ".db_escape($vehicle_id);
    
    if($expense_type_id > 0){
        $sql .= " AND ex.expense_type_id = ".db_escape($expense_type_id);
    }
    
                
        $result = db_query($sql, "dashboard_get_transport_petty_cash_period_expense_type_total"); 
        
        return db_result_value($result, 'approved_amount');
}
