<?php

function view_dashboard_transport_petty_cash_expenses_details($vehicle_id, $from_date, $to_date, $expense_type_id=0) {
    

     $sql = "SELECT b.*,
                SUM(ex.approved_amount) total,
                f.name float_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."petty_cash_floats f   
                    ON f.id = b.float_id      
            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);
    }
    
    $sql .= " GROUP BY b.batch_no 
            ORDER BY b.tran_date  ";
                
        return db_query($sql, "view_dashboard_transport_petty_cash_expenses_details"); 
     
}
