<?php

function view_dashboard_sales_pnl_details($from_date, $to_date, $entry_type_id=0, $type=-1) {   
    switch ($type) {
        case ST_POS_INVOICE:
        case ST_POS_CREDIT_NOTE:
            $all_sql = dashboard_get_sql_for_pos_invoices($from_date, $to_date, $entry_type_id, $type);
            break;

        case ST_UTILITY_BILLS:
            $all_sql = dashboard_get_sql_for_utility_bills($from_date, $to_date, $entry_type_id);
            break;
        
        case ST_PURCHORDER:
            $all_sql = dashboard_get_sql_for_purch_orders($from_date, $to_date);
            break;
        
        case ST_PAYROLL:
            $all_sql = dashboard_get_sql_for_salaries($from_date, $to_date);
            break;
        
        default:
            $sql_pos = dashboard_get_sql_for_pos_invoices($from_date, $to_date, $entry_type_id);
            $sql_ub = dashboard_get_sql_for_utility_bills($from_date, $to_date, $entry_type_id);
            $sql_po = dashboard_get_sql_for_purch_orders($from_date, $to_date);
            $sql_sl = dashboard_get_sql_for_salaries($from_date, $to_date);

            $all_sql = "$sql_pos UNION $sql_ub UNION $sql_po UNION $sql_sl";
            break;
    }
    
        $sql = "SELECT trans_type, trans_no, date, reference, entry_type_name, amount, project_id  
                FROM ($all_sql) tmp  
                ORDER BY date, trans_no"; 

            return db_query($sql, "view_dashboard_sales_pnl_details"); 
}