$bits = 0; } $html_part .= "<tr>\n"; $html_part .= " <td>" . $item["type"] . "</td>\n"; $html_part .= " <td>" . $item["value_text"] . "</td>\n"; $html_part .= " <td>" . number_format($bits / unit_multi($graph["rate_overage"]["unit"]), 2) . " " . $graph["rate_overage"]["unit"] . "</td>\n"; $html_part .= " <td>Overage</td>\n"; $html_part .= " <td>" . $config_customers[$customer]["currency"]["pre"] . $graph["rate_overage"]["amount"]; $html_part .= $config_customers[$customer]["currency"]["post"] . " per " . $graph["rate_overage"]["unit"] . "</td>\n"; $html_part .= " <td>" . $config_customers[$customer]["currency"]["pre"]; $html_part .= number_format($total, $config_customers[$customer]["currency"]["precision"]); $html_part .= $config_customers[$customer]["currency"]["post"] . "</td>\n"; $html_part .= "</tr>\n"; $text_part .= " Type: " . $item["type"] . "\n"; $text_part .= " Text: " . $item["value_text"] . "\n"; $text_part .= " Bits: " . number_format($bits / unit_multi($graph["rate_overage"]["unit"]), 2) . " " . $graph["rate_overage"]["unit"] . "\n"; $text_part .= " Rate Type: Overage\n"; $text_part .= " Rate Amount: " . $config_customers[$customer]["currency"]["pre"] . $graph["rate_overage"]["amount"]; $text_part .= $config_customers[$customer]["currency"]["post"] . " per " . $graph["rate_overage"]["unit"] . "\n"; $text_part .= " Total: " . $config_customers[$customer]["currency"]["pre"]; $text_part .= number_format($total, $config_customers[$customer]["currency"]["precision"]); $text_part .= $config_customers[$customer]["currency"]["post"] . "\n"; $csv_file .= "\"" . $config_customers[$customer]["description"] . "\","; $csv_file .= "\"" . $config_customers[$customer]["timeframe"]["start_formatted"] . "\","; $csv_file .= "\"" . $config_customers[$customer]["timeframe"]["end_formatted"] . "\","; $csv_file .= "\"" . $graph["graph_title"] . "\","; $csv_file .= "\"" . $item["type"] . "\","; $csv_file .= "\"" . $billing_timeframe["type"] . "\","; if (isset($billing_timeframe["every"])) { $csv_file .= "\"" . $billing_timeframe["every"] . "\","; } else {
function calculate_rate($rate, $type, $bits) { $output = 0; if ($type == "overage") { if ($bits > $rate["rate_overage"]["threshold"]) { $bits = $bits - $rate["rate_overage"]["threshold"]; } else { $bits = 0; } $multi = unit_multi($rate["rate_overage"]["unit"]); $output = $bits / $multi * $rate["rate_overage"]["amount"]; } elseif ($type == "committed") { if ($bits > $rate["rate_overage"]["threshold"]) { $bits = $rate["rate_overage"]["threshold"]; } $multi = unit_multi($rate["rate_committed"]["unit"]); $output = $bits / $multi * $rate["rate_committed"]["amount"]; if (isset($rate["rate_committed"]["minimum"])) { if ($output < $rate["rate_committed"]["minimum"]) { $output = $rate["rate_committed"]["minimum"]; } } } elseif ($type == "regular") { $multi = unit_multi($rate["rate"]["unit"]); $output = $bits / $multi * $rate["rate"]["amount"]; if (isset($rate["rate"]["minimum"])) { if ($output < $rate["rate"]["minimum"]) { $output = $rate["rate"]["minimum"]; } } } elseif ($type == "fixed") { $output = $rate["rate_fixed"]["amount"]; } return round($output, 4); }