mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Refactor billing (#14979)
* Refactor common billing code into a namespace Prevents issues of usages where the code hasn't been loaded. * remove redundant Billing in method names * remove accidental duplication * more use statements * Style fixes
This commit is contained in:
@@ -34,6 +34,7 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Alerting\QueryBuilderParser;
|
||||
use LibreNMS\Billing;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
use LibreNMS\Exceptions\InvalidTableColumnException;
|
||||
@@ -1582,15 +1583,15 @@ function list_bills(Illuminate\Http\Request $request)
|
||||
$overuse = $rate_data['rate_95th'] - $bill['bill_cdr'];
|
||||
$overuse = (($overuse <= 0) ? '-' : Number::formatSi($overuse, 2, 3, ''));
|
||||
} elseif (strtolower($bill['bill_type']) == 'quota') {
|
||||
$allowed = format_bytes_billing($bill['bill_quota']);
|
||||
$used = format_bytes_billing($rate_data['total_data']);
|
||||
$allowed = Billing::formatBytes($bill['bill_quota']);
|
||||
$used = Billing::formatBytes($rate_data['total_data']);
|
||||
if ($bill['bill_quota'] > 0) {
|
||||
$percent = Number::calculatePercent($rate_data['total_data'], $bill['bill_quota']);
|
||||
} else {
|
||||
$percent = '-';
|
||||
}
|
||||
$overuse = $rate_data['total_data'] - $bill['bill_quota'];
|
||||
$overuse = (($overuse <= 0) ? '-' : format_bytes_billing($overuse));
|
||||
$overuse = (($overuse <= 0) ? '-' : Billing::formatBytes($overuse));
|
||||
}
|
||||
$bill['allowed'] = $allowed;
|
||||
$bill['used'] = $used;
|
||||
@@ -1634,9 +1635,9 @@ function get_bill_graphdata(Illuminate\Http\Request $request)
|
||||
$to = $request->get('to', time());
|
||||
$reducefactor = $request->get('reducefactor');
|
||||
|
||||
$graph_data = getBillingBitsGraphData($bill_id, $from, $to, $reducefactor);
|
||||
$graph_data = Billing::getBitsGraphData($bill_id, $from, $to, $reducefactor);
|
||||
} elseif ($graph_type == 'monthly') {
|
||||
$graph_data = getHistoricTransferGraphData($bill_id);
|
||||
Billing::getHistoricTransferGraphData($bill_id);
|
||||
}
|
||||
|
||||
if (! isset($graph_data)) {
|
||||
@@ -1703,11 +1704,11 @@ function get_bill_history_graphdata(Illuminate\Http\Request $request)
|
||||
case 'bits':
|
||||
$reducefactor = $request->get('reducefactor');
|
||||
|
||||
$graph_data = getBillingHistoryBitsGraphData($bill_id, $bill_hist_id, $reducefactor);
|
||||
$graph_data = Billing::getHistoryBitsGraphData($bill_id, $bill_hist_id, $reducefactor);
|
||||
break;
|
||||
case 'day':
|
||||
case 'hour':
|
||||
$graph_data = getBillingBandwidthGraphData($bill_id, $bill_hist_id, null, null, $graph_type);
|
||||
$graph_data = Billing::getBandwidthGraphData($bill_id, $bill_hist_id, null, null, $graph_type);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user