From e4e2cfe3cfd7552d54ea7aaf706a23c4b1ea0b67 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 30 Nov 2014 17:49:52 +0000 Subject: [PATCH 1/6] Fixed global search box bootstrap code --- html/includes/print-menubar.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 7333d8ad32..bd7325e7a9 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -460,15 +460,12 @@ if ($_SESSION['authenticated'])
  • About 
  • -
  • -
    -
    - -
    -
    -
  • - + From 13712b1aedfa7d2a633fbbb09ceb8b9fedc2450e Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 2 Dec 2014 21:16:08 +0000 Subject: [PATCH 2/6] Fixed bill display issues when calculating CDR --- html/pages/bill/edit.inc.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/html/pages/bill/edit.inc.php b/html/pages/bill/edit.inc.php index 5135879c90..51a893f2a7 100644 --- a/html/pages/bill/edit.inc.php +++ b/html/pages/bill/edit.inc.php @@ -19,12 +19,12 @@ if ($bill_data['bill_type'] == "quota") { } if ($bill_data['bill_type'] == "cdr") { $data = $bill_data['bill_cdr']; - $tmp['kbps'] = $data / $base / $base; - $tmp['mbps'] = $data / $base / $base / $base; - $tmp['gbps'] = $data / $base / $base / $base / $base; - if ($tmp['gbps']>1 and ($tmp['mbps']<$base)) { $cdr = array("type" => "gbps", "select_tbps" => " selected", "data" => $tmp['gbps']); } - elseif (($tmp['mbps']>1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_gbps" => " selected", "data" => $tmp['mbps']); } - elseif (($tmp['kbps']>1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_mbps" => " selected", "data" => $tmp['kbps']); } + $tmp['kbps'] = $data / $base; + $tmp['mbps'] = $data / $base / $base; + $tmp['gbps'] = $data / $base / $base / $base; + if ($tmp['gbps']>=1 and ($tmp['gbps']<$base)) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } + elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); } + elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); } } ?> From d9a5d11782b3efebd6a5e99c08b741058c588bdf Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 2 Dec 2014 21:38:32 +0000 Subject: [PATCH 3/6] More fixes to CDR and Quota values --- html/pages/bill/edit.inc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/html/pages/bill/edit.inc.php b/html/pages/bill/edit.inc.php index 51a893f2a7..6434c93e77 100644 --- a/html/pages/bill/edit.inc.php +++ b/html/pages/bill/edit.inc.php @@ -13,16 +13,16 @@ if ($bill_data['bill_type'] == "quota") { $tmp['mb'] = $data / $base / $base; $tmp['gb'] = $data / $base / $base / $base; $tmp['tb'] = $data / $base / $base / $base / $base; - if (($tmp['tb']>1) and ($tmp['tb']<$base)) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); } - elseif (($tmp['gb']>1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); } - elseif (($tmp['mb']>1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); } + if ($tmp['tb']>=1) { $quota = array("type" => "tb", "select_tb" => " selected", "data" => $tmp['tb']); } + elseif (($tmp['gb']>=1) and ($tmp['gb']<$base)) { $quota = array("type" => "gb", "select_gb" => " selected", "data" => $tmp['gb']); } + elseif (($tmp['mb']>=1) and ($tmp['mb']<$base)) { $quota = array("type" => "mb", "select_mb" => " selected", "data" => $tmp['mb']); } } if ($bill_data['bill_type'] == "cdr") { $data = $bill_data['bill_cdr']; $tmp['kbps'] = $data / $base; $tmp['mbps'] = $data / $base / $base; $tmp['gbps'] = $data / $base / $base / $base; - if ($tmp['gbps']>=1 and ($tmp['gbps']<$base)) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } + if ($tmp['gbps']>=1) { $cdr = array("type" => "gbps", "select_gbps" => " selected", "data" => $tmp['gbps']); } elseif (($tmp['mbps']>=1) and ($tmp['mbps']<$base)) { $cdr = array("type" => "mbps", "select_mbps" => " selected", "data" => $tmp['mbps']); } elseif (($tmp['kbps']>=1) and ($tmp['kbps']<$base)) { $cdr = array("type" => "kbps", "select_kbps" => " selected", "data" => $tmp['kbps']); } } From 1108ef7939cc71468d5c9cc700a33d08a55ea674 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 2 Dec 2014 23:43:11 +0000 Subject: [PATCH 4/6] Added new api route for billing --- html/api_v0.php | 4 +++ html/includes/api_functions.inc.php | 30 ++++++++++++++++++++ html/pages/api-docs.inc.php | 43 ++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/html/api_v0.php b/html/api_v0.php index 2e965a410d..550506db18 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -45,6 +45,10 @@ $app->group('/api', function() use ($app) { $app->group('/portgroups', function() use ($app) { $app->get('/:group', 'authToken', 'get_graph_by_portgroup')->name('get_graph_by_portgroup');//api/v0/portgroups/$group }); + $app->group('/bills', function() use ($app) { + $app->get('/:bill_id', 'authToken', 'list_bills')->name('get_bill');//api/v0/bills/$bill_id + }); + $app->get('/bills', 'authToken', 'list_bills')->name('list_bills');//api/v0/bills }); $app->get('/v0', 'authToken', 'show_endpoints');//api/v0 }); diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index c8b40bb2af..a02ef291b0 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -465,3 +465,33 @@ function get_port_graphs() { $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } + +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']); + } elseif(isset($_GET['ref'])) { + $sql = "`bill_ref` = ?"; + $param = array($_GET['ref']); + } elseif(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); +} + diff --git a/html/pages/api-docs.inc.php b/html/pages/api-docs.inc.php index 02d9330b8e..83ebc78fc7 100644 --- a/html/pages/api-docs.inc.php +++ b/html/pages/api-docs.inc.php @@ -319,11 +319,52 @@ if ($_SESSION['userlevel'] == '10') curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
    "https://librenms.example.com/api/v0/devices/localhost/ports?columns=ifDescr,ifName"
    + + List Bills + + + /api + /v0 + /bills + +
      +
    • custid = the customer reference for the bill
    • +
    • ref = the billing reference for the bill
    • +
    + + + JSON + + + + curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
    "https://librenms.example.com/api/v0/bills"
    + + + curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
    "https://librenms.example.com/api/v0/bills?custid=Testing"
    + + + Retrieve Bill information + + + /api + /v0 + /bills/$bill_id + +
      +
    + + + JSON + + + + curl -H "X-Auth-Token: 91c60e737e342c205be5bba8e2954d27" \
    "https://librenms.example.com/api/v0/bills/$bill_id"
    +
    -
    -