Skip to content
Snippets Groups Projects
Commit 56319bce authored by Yas Naoi's avatar Yas Naoi
Browse files

Once again

parent 280d7860
No related branches found
No related tags found
No related merge requests found
......@@ -52,11 +52,13 @@ function cloud_billing_report($form, $form_submit = '', $cloud_context = '') {
$month_range_list = _cloud_billing_get_month_range_array();
foreach ($month_range_list as $start => $end ) {
$query = _cloud_billing_generate_report($start, $end, $cloud_context);
$result = db_query( $query );
$total = 0;
foreach ($result as $billing_obj) {
$total_instance_type_charge = 0;
$unit_price = $billing_obj->linux_or_unix_usage;
$total_hours = _cloud_billing_instance_total_hours($start, $end, $billing_obj->launch_time, $billing_obj->terminated_date);
......@@ -91,9 +93,12 @@ function cloud_billing_report($form, $form_submit = '', $cloud_context = '') {
* Theme the billing report
*/
function theme_cloud_billing_report($form) {
$form = $form['form'];
$rows = array();
foreach (element_children($form['date']) as $key) {
$rows[] = array(
drupal_render($form['date'][$key]),
drupal_render($form['totals'][$key]),
......@@ -164,19 +169,25 @@ function cloud_billing_report_details($form, $form_submit = '', $start = '', $en
$order = isset($_REQUEST['order']) ? $_REQUEST['order'] : FALSE;
$sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : FALSE;
if (empty($order) === FALSE) {
if (strpos($order, 'Description') === 0) {
$query .= ' order by description ';
}
elseif (strpos($order, 'Rate') === 0) {
$query .= ' order by linux_or_unix_usage ';
}
elseif (strpos($order, 'Instance') === 0) {
$query .= ' order by instance_type ';
}
$query .= $sort . ' ';
}
else { // default
$query .= ' order by linux_or_unix_usage asc ';
}
......@@ -198,7 +209,6 @@ function cloud_billing_report_details($form, $form_submit = '', $start = '', $en
foreach ($result_types as $types) {
$total_hours = _cloud_billing_instance_total_hours($start, $end, $types->launch_time, $types->terminated_date);
// print_r("total hours: start: $start / end: $end / launch time: " . $types->launch_time . " / terminated.date: " . $types->terminated_date . " / total_hours: $total_hours<br />");
if ($instance_type == $types->instance_type and $total_hours > 0) {
......@@ -226,11 +236,11 @@ function cloud_billing_report_details($form, $form_submit = '', $start = '', $en
$form['instance_type'][$billing_obj->id] = array('#markup' => t( $billing_obj->instance_type ));
$form['description' ][$billing_obj->id] = array('#markup' => t( $billing_obj->description . ' instance ' ));
$form['stinstnaces' ][$billing_obj->id] = array('#markup' => t(($total_instances > 0)
? $total_instances
: 0 ));
? $total_instances
: 0 ));
$form['usage' ][$billing_obj->id] = array('#markup' => t(($total_hours_calc > 0)
? $total_hours_calc
: 0 ));
? $total_hours_calc
: 0 ));
$form['totals' ][$billing_obj->id] = array('#markup' => t( '$' . number_format($total_instance_type_charge, 2)));
$form['start' ][$billing_obj->id] = array('#markup' => $start_date);
$form['end' ][$billing_obj->id] = array('#markup' => $end_date);
......@@ -264,6 +274,7 @@ function theme_cloud_billing_report_details($form) {
$form['rate'] = !empty($form['rate']) ? $form['rate'] : '';
$form['pager']['#value'] = !empty($form['pager']['#value']) ? $form['pager']['#value'] : '';
$rows = array();
foreach (element_children($form['rate']) as $key) {
$rows[] = array(
......@@ -311,6 +322,7 @@ function theme_cloud_billing_report_details($form) {
function _cloud_billing_get_month_range_array() {
$month_range_list = array();
for ($i = 0; $i < 12; $i++ ) { //for last 1 year
_cloud_billing_get_month_range($start, $end, $i);
$month_range_list[$start] = $end;
......@@ -441,40 +453,51 @@ function _cloud_billing_get_runtime($launch_time, $curr_time = '') {
$launch_tmp_time = date_parse($launch_time);
$gm_launch_time = gmmktime( $launch_tmp_time['hour'], $launch_tmp_time['minute'], $launch_tmp_time['second'], $launch_tmp_time['month'], $launch_tmp_time['day'], $launch_tmp_time['year'] );
$gm_launch_time = gmmktime($launch_tmp_time['hour' ],
$launch_tmp_time['minute'],
$launch_tmp_time['second'],
$launch_tmp_time['month' ],
$launch_tmp_time['day' ],
$launch_tmp_time['year' ] );
if (!empty($curr_time)) {
$curr_tmp_time = date_parse($curr_time);
$gm_current_time = gmmktime( $curr_tmp_time['hour'], $curr_tmp_time['minute'], $curr_tmp_time['second'], $curr_tmp_time['month'], $curr_tmp_time['day'], $curr_tmp_time['year'] );
$gm_current_time = gmmktime($curr_tmp_time['hour' ],
$curr_tmp_time['minute'],
$curr_tmp_time['second'],
$curr_tmp_time['month' ],
$curr_tmp_time['day' ],
$curr_tmp_time['year' ] );
}
else {
$gm_current_time = gmmktime();
}
print "launch time: $launch_time | launch_tmp_time: $launch_tmp_time | gm_launch_time: $gm_launch_time | gm_current_time: $gm_current_time<br />";
$diff = $gm_current_time - $gm_launch_time;
print "$gm_current_time - $gm_launch_time = diff: $diff<br />";
$days = $diff / (86400);
$hr = $diff / (3600);
$min = $diff / (60);
$hr = $diff / ( 3600);
$min = $diff / ( 60);
$sec = $diff;
$hours = 0;
if ( round( $days) > 0 ) {
$hours = $days * 24;
}
elseif ( round( $hr ) > 0 ) {
$hours = $hr;
}
elseif ( round( $min ) > 0 ) {
$hours = $min / 60;
}
elseif ( round( $sec ) > 0 ) {
$hours = $sec / 3600;
}
return round($hours);
}
......@@ -492,7 +515,6 @@ print "$gm_current_time - $gm_launch_time = diff: $diff<br />";
* This is Instance terminated date
* @return returns hour values
*/
function _cloud_billing_instance_total_hours($start, $end, $runtime, $terminated) {
$return_data = array();
......@@ -503,22 +525,24 @@ function _cloud_billing_instance_total_hours($start, $end, $runtime, $terminated
$instance_launch_date = gmdate('c', strtotime($runtime));
if (!empty($terminated)) {
$instance_terminated_date = gmdate('c', strtotime($terminated));
}
if (strtotime($start_date) < strtotime($instance_launch_date)) {
$start_date = $instance_launch_date;
}
if (strtotime($end_date) > strtotime(gmdate('c'))) {
$end_date = gmdate('c');
}
if (!empty($terminated) && strtotime($end_date) >= strtotime($instance_terminated_date)) {
$end_date = $instance_terminated_date;
}
print "start: $start | start_date: $start_date | end_date: $end_date<br />";
$total_hours = _cloud_billing_get_runtime($start_date, $end_date);
return $total_hours;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment