<?php

function dashboard_get_period_new_suppliers($from_date, $to_date) {
    
    $old_suppliers_sql = "SELECt DISTINCT supplier_id 
            FROM ".TB_PREF."purch_orders  
            WHERE ord_date < ".db_escape($from_date);
    
    $new_suppliers_sql = "SELECT DISTINCT supplier_id,  SUM(total + taxes) grand_total 
            FROM ".TB_PREF."purch_orders  
            WHERE ord_date >= ".db_escape($from_date)." 
                AND ord_date <= ".db_escape($to_date)." 
                AND supplier_id NOT IN($old_suppliers_sql) 
            GROUP BY supplier_id 
            ORDER BY grand_total DESC ";
                
        return db_query($new_suppliers_sql, "dashboard_get_period_new_suppliers"); 
}

function dashboard_get_new_supplier_pos_total($supplier_id, $from_date, $to_date) {
    
    $sql = "SELECT SUM(total + taxes) po_total 
            FROM ".TB_PREF."purch_orders   
            WHERE ord_date >= ".db_escape($from_date)." 
                AND ord_date <= ".db_escape($to_date)." 
                AND supplier_id = ".db_escape($supplier_id);
    
                
        $result = db_query($sql, "dashboard_get_new_supplier_pos_total"); 
        
        return db_result_value($result, 'po_total');
}
