Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud-3252947
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
cloud-3252947
Commits
56319bce
Commit
56319bce
authored
9 years ago
by
Yas Naoi
Browse files
Options
Downloads
Patches
Plain Diff
Once again
parent
280d7860
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/cloud_billing/cloud_billing.inc
+40
-16
40 additions, 16 deletions
modules/cloud_billing/cloud_billing.inc
with
40 additions
and
16 deletions
modules/cloud_billing/cloud_billing.inc
+
40
−
16
View file @
56319bce
...
...
@@ -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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment