diff --git a/billing-calculate.php b/billing-calculate.php index 39d566c939..3cd4c05785 100755 --- a/billing-calculate.php +++ b/billing-calculate.php @@ -42,7 +42,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) { // Send the current dir_95th to the getRates function so it knows to aggregate or return the max in/out value and highest direction $dir_95th = $bill['dir_95th']; - if ($period > 0 && $dateto > $date_updated) { + if ($period['period'] > 0 && $dateto > $date_updated) { $rate_data = getRates($bill['bill_id'], $datefrom, $dateto, $dir_95th); $rate_95th = $rate_data['rate_95th']; $dir_95th = $rate_data['dir_95th']; @@ -102,6 +102,8 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) { 'traf_total' => $rate_data['total_data'], 'traf_in' => $rate_data['total_data_in'], 'traf_out' => $rate_data['total_data_out'], + 'bill_peak_out' => $period['peak_out'], + 'bill_peak_in' => $period['peak_in'], 'bill_used' => $used, 'bill_overuse' => $overuse, 'bill_percent' => $percent, @@ -133,10 +135,10 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) { ]; dbInsert($update, 'bill_history'); echo ' Generated history! '; - }//end if + } //end if echo "\n\n"; - }//end if + } //end if $i++; - }//end while + } //end while }//end foreach diff --git a/database/migrations/2021_07_06_1845_alter_bill_history_max_min.php b/database/migrations/2021_07_06_1845_alter_bill_history_max_min.php new file mode 100644 index 0000000000..a98a6a06b3 --- /dev/null +++ b/database/migrations/2021_07_06_1845_alter_bill_history_max_min.php @@ -0,0 +1,33 @@ +bigInteger('bill_peak_out')->nullable()->after('traf_total'); + $table->bigInteger('bill_peak_in')->nullable()->after('bill_peak_out'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bill_history', function (Blueprint $table) { + $table->dropColumn(['bill_peak_in', 'bill_peak_out']); + }); + } +} diff --git a/doc/API/Bills.md b/doc/API/Bills.md index 2677ce0ee1..87874b4d05 100644 --- a/doc/API/Bills.md +++ b/doc/API/Bills.md @@ -260,6 +260,8 @@ Output: "traf_in": "3235123452544", "traf_out": "33608406566", "traf_total": "3268731859110", + "bill_peak_out": "2782349290", + "bill_peak_in": "10161119", "pdf": null } ], diff --git a/includes/billing.php b/includes/billing.php index e2ebb86291..36c32e98cf 100644 --- a/includes/billing.php +++ b/includes/billing.php @@ -216,7 +216,7 @@ function getSum($bill_id, $datefrom, $dateto) function getPeriod($bill_id, $datefrom, $dateto) { - $ptot = dbFetchCell('SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]); + $ptot = dbFetchRow('SELECT SUM(period) as `period`, MAX(in_delta) as `peak_in`, MAX(out_delta) as `peak_out` FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]); return $ptot; }//end getPeriod() diff --git a/includes/html/pages/bill/history.inc.php b/includes/html/pages/bill/history.inc.php index a4acf31fde..b986015654 100644 --- a/includes/html/pages/bill/history.inc.php +++ b/includes/html/pages/bill/history.inc.php @@ -55,6 +55,8 @@ echo ' + + @@ -91,6 +93,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY $out = Number::formatBase($history['traf_out'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); $overuse = (($history['bill_overuse'] <= 0) ? '-' : '' . Number::formatBase($history['bill_overuse'], \LibreNMS\Config::get('billing.base')) . ''); } + $peakOut = Number::formatBase($history['bill_peak_out'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); + $peakIn = Number::formatBase($history['bill_peak_in'], \LibreNMS\Config::get('billing.base'), 2, 3, ''); $total_data = (($type == 'Quota') ? '' . $total_data . '' : $total_data); $rate_95th = (($type == 'CDR') ? '' . $rate_95th . '' : $rate_95th); @@ -105,6 +109,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY + + diff --git a/misc/db_schema.yaml b/misc/db_schema.yaml index 5d7b545b32..132e1afb81 100644 --- a/misc/db_schema.yaml +++ b/misc/db_schema.yaml @@ -313,6 +313,8 @@ bill_history: - { Field: traf_in, Type: bigint, 'Null': false, Extra: '' } - { Field: traf_out, Type: bigint, 'Null': false, Extra: '' } - { Field: traf_total, Type: bigint, 'Null': false, Extra: '' } + - { Field: bill_peak_out, Type: bigint, 'Null': true, Extra: '' } + - { Field: bill_peak_in, Type: bigint, 'Null': true, Extra: '' } - { Field: pdf, Type: longblob, 'Null': true, Extra: '' } Indexes: PRIMARY: { Name: PRIMARY, Columns: [bill_hist_id], Unique: true, Type: BTREE } @@ -2131,4 +2133,4 @@ wireless_sensors: wireless_sensors_sensor_class_index: { Name: wireless_sensors_sensor_class_index, Columns: [sensor_class], Unique: false, Type: BTREE } wireless_sensors_sensor_type_index: { Name: wireless_sensors_sensor_type_index, Columns: [sensor_type], Unique: false, Type: BTREE } Constraints: - wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' } + wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' } \ No newline at end of file
Allowed Inbound OutboundPeak OutPeak In Total 95th %ile Overusage$allowed $in $out$peakOut$peakIn $total_data $rate_95th $overuse