mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Updated billing features within API + docs
This commit is contained in:
@ -550,49 +550,6 @@ function get_port_graphs() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
function list_bills() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$bill_id = $router['bill_id'];
|
||||
if (isset($_GET['custid'])) {
|
||||
$sql = '`bill_custid` = ?';
|
||||
$param = array($_GET['custid']);
|
||||
}
|
||||
else if (isset($_GET['ref'])) {
|
||||
$sql = '`bill_ref` = ?';
|
||||
$param = array($_GET['ref']);
|
||||
}
|
||||
else if (is_numeric($bill_id)) {
|
||||
$sql = '`bill_id` = ?';
|
||||
$param = array($bill_id);
|
||||
}
|
||||
|
||||
else {
|
||||
$sql = '';
|
||||
$param = array();
|
||||
}
|
||||
|
||||
if (count($param) >= 1) {
|
||||
$sql = "WHERE $sql";
|
||||
}
|
||||
|
||||
$bills = dbFetchRows("SELECT * FROM `bills` $sql", $param);
|
||||
$total_bills = count($bills);
|
||||
$output = array(
|
||||
'status' => 'ok',
|
||||
'err-msg' => '',
|
||||
'count' => $total_bills,
|
||||
'bills' => $bills,
|
||||
);
|
||||
$app->response->setStatus('200');
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function list_alert_rules() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
@ -886,3 +843,76 @@ function list_oxidized() {
|
||||
echo _json_encode($devices);
|
||||
|
||||
}
|
||||
|
||||
function list_bills() {
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$status = 'ok';
|
||||
$err_msg = '';
|
||||
$message = '';
|
||||
$code = 200;
|
||||
$bills = array();
|
||||
$bill_id = mres($router['bill_id']);
|
||||
$bill_ref = mres($_GET['ref']);
|
||||
$bill_custid = mres($_GET['custid']);
|
||||
if (!empty($bill_custid)) {
|
||||
$sql = '`bill_custid` = ?';
|
||||
$param = array($bill_custid);
|
||||
}
|
||||
elseif (!empty($bill_ref)) {
|
||||
$sql = '`bill_ref` = ?';
|
||||
$param = array($bill_ref);
|
||||
}
|
||||
elseif (is_numeric($bill_id)) {
|
||||
$sql = '`bill_id` = ?';
|
||||
$param = array($bill_id);
|
||||
}
|
||||
else {
|
||||
$sql = '';
|
||||
$param = array();
|
||||
}
|
||||
|
||||
if (count($param) >= 1) {
|
||||
$sql = "WHERE $sql";
|
||||
}
|
||||
|
||||
foreach (dbFetchRows("SELECT `bills`.*,COUNT(port_id) AS `ports_total` FROM `bills` LEFT JOIN `bill_ports` ON `bill_ports`.`bill_id`=`bills`.`bill_id` $sql GROUP BY `bill_name`,`bill_ref` ORDER BY `bill_name`",$param) as $bill) {
|
||||
$day_data = getDates($bill['bill_day']);
|
||||
$ports_total = $bill['ports_total'];
|
||||
$datefrom = $day_data['0'];
|
||||
$dateto = $day_data['1'];
|
||||
$rate_data = $bill;
|
||||
$rate_95th = $rate_data['rate_95th'];
|
||||
$dir_95th = $rate_data['dir_95th'];
|
||||
$total_data = $rate_data['total_data'];
|
||||
$rate_average = $rate_data['rate_average'];
|
||||
|
||||
if ($bill['bill_type'] == "cdr") {
|
||||
$type = "CDR";
|
||||
$allowed = format_si($bill['bill_cdr'])."bps";
|
||||
$used = format_si($rate_data['rate_95th'])."bps";
|
||||
$percent = round(($rate_data['rate_95th'] / $bill['bill_cdr']) * 100,2);
|
||||
$background = get_percentage_colours($percent);
|
||||
$overuse = $rate_data['rate_95th'] - $bill['bill_cdr'];
|
||||
$overuse = (($overuse <= 0) ? "-" : format_si($overuse));
|
||||
}
|
||||
elseif ($bill['bill_type'] == "quota") {
|
||||
$type = "Quota";
|
||||
$allowed = format_bytes_billing($bill['bill_quota']);
|
||||
$used = format_bytes_billing($rate_data['total_data']);
|
||||
$percent = round(($rate_data['total_data'] / ($bill['bill_quota'])) * 100,2);
|
||||
$background = get_percentage_colours($percent);
|
||||
$overuse = $rate_data['total_data'] - $bill['bill_quota'];
|
||||
$overuse = (($overuse <= 0) ? "-" : format_bytes_billing($overus));
|
||||
}
|
||||
$bill['allowed'] = $allowed;
|
||||
$bill['used'] = $used;
|
||||
$bill['percent'] = $percent;
|
||||
$bill['overuse'] = $overuse;
|
||||
$bills[] = $bill;
|
||||
}
|
||||
$count = count($bills);
|
||||
$output = array("status" => $status, "err-msg" => $err_msg, "count" => $count, "bills" => $bills);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
Reference in New Issue
Block a user