<?php

function get_months_range($from_month_id, $to_month_id)
{
    $sql = "SELECT * 
            FROM ".TB_PREF."months 
            WHERE display_order >= (SELECT display_order 
                                    FROM ".TB_PREF."months 
                                    WHERE id = ".db_escape($from_month_id).")
                                       
              AND display_order <= (SELECT display_order 
                                    FROM ".TB_PREF."months 
                                    WHERE id = ".db_escape($to_month_id).")
            ORDER BY display_order";
    
    return db_query($sql);
}


function get_department_average_overhead_factor($department_ids_in)
{
    $costs = $overheads = 1;
    
    $sql = "SELECT SUM(approved_cost_budgets_total) costs, 
                    SUM(approved_overhead_budgets_total) overhead 
            FROM ".TB_PREF."projects_master                 
            WHERE department_id IN (".$department_ids_in.") ";
    
    $result = db_query($sql);
    $row = db_fetch($result);
    if(isset($row['costs']) && $row['costs'] > 0){
        $costs = $row['costs'];
    }
    
    if(isset($row['overheads']) && $row['overheads'] > 0){
        $overheads = $row['overheads'];
    }
    
    $factor = $overheads / $costs;
    
    return $factor;
}

?>



































