Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Billing Search #3216

Merged
merged 1 commit into from
Mar 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion html/pages/bills.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,32 @@
</thead>
<tbody>
<?php
foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`') as $bill) {
$wheres = array();
$params = array();

if (!empty($_GET['search'])) {
$wheres[] = 'bills.bill_name LIKE ?';
$params[] = '%'.$_GET['search'].'%';
}
if (!empty($_GET['bill_type'])) {
$wheres[] = 'bill_type = ?';
$params[] = $_GET['bill_type'];
}
if ($_GET['state'] === 'under') {
$wheres[] = "((bill_type = 'cdr' AND rate_95th <= bill_cdr) OR (bill_type = 'quota' AND total_data <= bill_quota))";
} else if ($_GET['state'] === 'over') {
$wheres[] = "((bill_type = 'cdr' AND rate_95th > bill_cdr) OR (bill_type = 'quota' AND total_data > bill_quota))";
}

$query = 'SELECT *
FROM `bills`
';
if (sizeof($wheres) > 0) {
$query .= 'WHERE ' . implode(' AND ', $wheres) . "\n";
}
$query .= 'ORDER BY bills.bill_name';

foreach (dbFetchRows($query, $params) as $bill) {
if (bill_permitted($bill['bill_id'])) {
unset($class);
$day_data = getDates($bill['bill_day']);
Expand Down
121 changes: 74 additions & 47 deletions html/pages/bills/pmonth.inc.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

$no_refresh = true;
$pagetitle[] = 'Previous Billing Period';
$i = 0;

echo '<table class="table table-condensed">
echo '<table class="table table-condensed table-striped">
<thead>
<tr>
<th>Billing name</th>
<th>Type</th>
Expand All @@ -14,58 +15,84 @@
<th>95 percentile</th>
<th>Overusage</th>
<th></th>
</tr>';
</tr>
</thead>
<tbody>';

$wheres = array();
$params = array();

foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_name`') as $bill) {
if (!empty($_GET['search'])) {
$wheres[] = 'bills.bill_name LIKE ?';
$params[] = '%'.$_GET['search'].'%';
}
if (!empty($_GET['bill_type'])) {
$wheres[] = 'bill_history.bill_type = ?';
$params[] = $_GET['bill_type'];
}
if ($_GET['state'] === 'under') {
$wheres[] = 'bill_history.bill_overuse = 0';
} else if ($_GET['state'] === 'over') {
$wheres[] = 'bill_history.bill_overuse > 0';
}

$query = 'SELECT bills.bill_name, bill_history.*
FROM `bills`
INNER JOIN (SELECT bill_id, MAX(bill_hist_id) AS bill_hist_id FROM bill_history WHERE bill_dateto < NOW() AND bill_dateto > subdate(NOW(), 40) GROUP BY bill_id) qLastBills ON bills.bill_id = qLastBills.bill_id
INNER JOIN bill_history ON qLastBills.bill_hist_id = bill_history.bill_hist_id
';
if (sizeof($wheres) > 0) {
$query .= 'WHERE ' . implode(' AND ', $wheres) . "\n";
}
$query .= 'ORDER BY bills.bill_name';

foreach (dbFetchRows($query, $params) as $bill) {
if (bill_permitted($bill['bill_id'])) {
$day_data = getDates($bill['bill_day']);
$datefrom = $day_data['2'];
$dateto = $day_data['3'];
foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? AND `bill_datefrom` = ? ORDER BY `bill_datefrom` LIMIT 1', array($bill['bill_id'], $datefrom, $dateto)) as $history) {
unset($class);
$type = $history['bill_type'];
$percent = $history['bill_percent'];
$dir_95th = $history['dir_95th'];
$rate_95th = format_si($history['rate_95th']).'bps';
$total_data = format_bytes_billing($history['traf_total']);
$datefrom = $bill['bill_datefrom'];
$dateto = $bill['bill_dateto'];

unset($class);
$type = $bill['bill_type'];
$percent = $bill['bill_percent'];
$dir_95th = $bill['dir_95th'];
$rate_95th = format_si($bill['rate_95th']).'bps';
$total_data = format_bytes_billing($bill['traf_total']);

$background = get_percentage_colours($percent);
$row_colour = ((!is_integer($i / 2)) ? $list_colour_a : $list_colour_b);
$background = get_percentage_colours($percent);

if ($type == 'CDR') {
$allowed = format_si($history['bill_allowed']).'bps';
$used = format_si($history['rate_95th']).'bps';
$in = format_si($history['rate_95th_in']).'bps';
$out = format_si($history['rate_95th_out']).'bps';
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_si($history['bill_overuse']).'bps</span>');
}
else if ($type == 'Quota') {
$allowed = format_bytes_billing($history['bill_allowed']);
$used = format_bytes_billing($history['total_data']);
$in = format_bytes_billing($history['traf_in']);
$out = format_bytes_billing($history['traf_out']);
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_bytes_billing($history['bill_overuse']).'</span>');
}
if ($type == 'CDR') {
$allowed = format_si($bill['bill_allowed']).'bps';
$used = format_si($bill['rate_95th']).'bps';
$in = format_si($bill['rate_95th_in']).'bps';
$out = format_si($bill['rate_95th_out']).'bps';
$overuse = (($bill['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_si($bill['bill_overuse']).'bps</span>');
}
else if ($type == 'Quota') {
$allowed = format_bytes_billing($bill['bill_allowed']);
$used = format_bytes_billing($bill['total_data']);
$in = format_bytes_billing($bill['traf_in']);
$out = format_bytes_billing($bill['traf_out']);
$overuse = (($bill['bill_overuse'] <= 0) ? '-' : '<span style="color: #'.$background['left'].'; font-weight: bold;">'.format_bytes_billing($bill['bill_overuse']).'</span>');
}

$total_data = (($type == 'Quota') ? '<b>'.$total_data.'</b>' : $total_data);
$rate_95th = (($type == 'CDR') ? '<b>'.$rate_95th.'</b>' : $rate_95th);
$total_data = (($type == 'Quota') ? '<b>'.$total_data.'</b>' : $total_data);
$rate_95th = (($type == 'CDR') ? '<b>'.$rate_95th.'</b>' : $rate_95th);

echo "
<tr style=\"background: $row_colour;\">
<td><a href=\"".generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $history['bill_hist_id'])).'"><span style="font-weight: bold;" class="interface">'.$bill['bill_name'].'</a></span><br />from '.strftime('%x', strtotime($datefrom)).' to '.strftime('%x', strtotime($dateto))."</td>
<td>$type</td>
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<td>$total_data</td>
<td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</td>
<td>".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'</td>
</tr>';
echo "
<tr>
<td><a href=\"".generate_url(array('page' => 'bill', 'bill_id' => $bill['bill_id'], 'view' => 'history', detail => $bill['bill_hist_id'])).'"><span style="font-weight: bold;" class="interface">'.$bill['bill_name'].'</a></span><br />from '.strftime('%x', strtotime($datefrom)).' to '.strftime('%x', strtotime($dateto))."</td>
<td>$type</td>
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<td>$total_data</td>
<td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</td>
<td>".print_percentage_bar(250, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']).'</td>
</tr>';

$i++;
} //end foreach
}//end if
}//end foreach

echo '</table>';
echo '</tbody>
</table>';
23 changes: 9 additions & 14 deletions html/pages/bills/search.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@

?>

<form method='post' action='' class="form-inline" role="form">
<fieldset class="form-group" disabled title="Search is currently broken">
<form method='get' action='' class="form-inline" role="form">
<fieldset class="form-group">
Bills
<input type="text" name="hostname" id="hostname" class="form-control input-sm" value="<?php echo $_POST['hostname']; ?>" />
<select name='os' id='os' class="form-control input-sm">
<input type="text" name="search" id="search" class="form-control input-sm" value="<?php echo $_GET['search']; ?>" />
<select name='bill_type' id='bill_type' class="form-control input-sm">
<option value=''>All Types</option>
<option value=''>CDR</option>
<option value=''>95th</option>
<option value=''>Quota</option>
<option value='cdr' <?php if ($_GET['bill_type'] === 'cdr') { echo 'selected'; } ?>>CDR</option>
<option value='quota' <?php if ($_GET['bill_type'] === 'quota') { echo 'selected'; } ?>>Quota</option>
</select>
<select name='hardware' id='hardware' class="form-control input-sm">
<select name='state' id='state' class="form-control input-sm">
<option value=''>All States</option>
<option value=''>Under Quota</option>
<option value=''>Over Quota</option>
</select>
<select name='location' id='location' class="form-control input-sm">
<option value=''>All Customers</option>
<option value='under' <?php if ($_GET['state'] === 'under') { echo 'selected'; } ?>>Under Quota</option>
<option value='over' <?php if ($_GET['state'] === 'over') { echo 'selected'; } ?>>Over Quota</option>
</select>
<button type="submit" class="btn btn-default input-sm">Search</button>
</fieldset>
Expand All @@ -30,7 +26,6 @@
echo '<a class="btn btn-default btn-sm" href="bills/"><i class="fa fa-clock-o"></i> Current Billing Period</a>';
}
else {
// FIXME - generate_url
echo '<a class="btn btn-default btn-sm" href="bills/view=history/"><i class="fa fa-history"></i> Previous Billing Period</a>';
}

Expand Down