diff --git a/lib/NGCP/Panel/Form/Balance/BalanceIntervalAPI.pm b/lib/NGCP/Panel/Form/Balance/BalanceIntervalAPI.pm index 71eb6a5ca3..8a8987d278 100644 --- a/lib/NGCP/Panel/Form/Balance/BalanceIntervalAPI.pm +++ b/lib/NGCP/Panel/Form/Balance/BalanceIntervalAPI.pm @@ -119,7 +119,7 @@ has_field 'free_time_spent' => ( #required => 1, element_attr => { rel => ['tooltip'], - title => ['The free-time spent during this interval in EUR/USD/etc.'] + title => ['The free-time spent during this interval in seconds.'] }, ); @@ -163,4 +163,4 @@ has_field 'underrun_lock' => ( 1; -# vim: set tabstop=4 expandtab: \ No newline at end of file +# vim: set tabstop=4 expandtab: diff --git a/lib/NGCP/Panel/Form/Balance/CustomerBalanceAPI.pm b/lib/NGCP/Panel/Form/Balance/CustomerBalanceAPI.pm index dd52cc9a11..11ea8a8fd6 100644 --- a/lib/NGCP/Panel/Form/Balance/CustomerBalanceAPI.pm +++ b/lib/NGCP/Panel/Form/Balance/CustomerBalanceAPI.pm @@ -4,32 +4,30 @@ use HTML::FormHandler::Moose; extends 'NGCP::Panel::Form::Balance::CustomerBalance'; use Moose::Util::TypeConstraints; -has_field 'cash_balance_interval' => ( +has_field 'cash_debit' => ( type => 'Money', - label => 'Cash Balance (Interval)', - required => 1, - inflate_method => sub { return $_[1] * 100 }, - deflate_method => sub { return $_[1] / 100 }, + #label => 'Cash Balance (Interval)', + #required => 1, element_attr => { rel => ['tooltip'], - title => ['The current cash balance of the customer in EUR/USD/etc for the current interval (Read-only).'], + title => ['The amount spent during the current interval in EUR/USD/etc (read-only).'], }, ); -has_field 'free_time_balance_interval' => ( +has_field 'free_time_spent' => ( type => 'Integer', - label => 'Free-Time Balance', - required => 1, + #label => 'Free-Time Balance', + #required => 1, element_attr => { rel => ['tooltip'], - title => ['The current free-time balance of the customer for the current interval in seconds (Read-only).'], + title => ['The free-time spent during the current interval in seconds (read-only).'], }, ); has_block 'fields' => ( tag => 'div', class => [qw/modal-body/], - render_list => [qw/cash_balance cash_balance_interval free_time_balance free_time_balance_interval/], + render_list => [qw/cash_balance cash_debit free_time_balance free_time_spent/], ); 1; diff --git a/lib/NGCP/Panel/Role/API/CustomerBalances.pm b/lib/NGCP/Panel/Role/API/CustomerBalances.pm index c03ae1017c..194af44617 100644 --- a/lib/NGCP/Panel/Role/API/CustomerBalances.pm +++ b/lib/NGCP/Panel/Role/API/CustomerBalances.pm @@ -16,24 +16,24 @@ use NGCP::Panel::Utils::ProfilePackages qw(); use NGCP::Panel::Utils::DateTime; sub _item_rs { - + my ($self, $c, $include_terminated,$now) = @_; - + my $item_rs = NGCP::Panel::Utils::Contract::get_contract_rs( schema => $c->model('DB'), include_terminated => (defined $include_terminated && $include_terminated ? 1 : 0), now => $now, - ); + ); if($c->user->roles eq "admin") { } elsif($c->user->roles eq "reseller") { - $item_rs = $item_rs->search({ + $item_rs = $item_rs->search({ 'contact.reseller_id' => $c->user->reseller_id },{ join => 'contact', }); } - return $item_rs; + return $item_rs; } @@ -44,9 +44,13 @@ sub get_form { sub hal_from_item { my ($self, $c, $item, $form) = @_; - + my %resource = $item->get_inflated_columns; + #$resource{cash_balance} /= 100.0; + ##$resource{cash_balance_interval} /= 100.0; $resource{cash_balance} /= 100.0; + $resource{cash_debit} = (delete $resource{cash_balance_interval}) / 100.0; + $resource{free_time_spent} = delete $resource{free_time_balance_interval}; my $hal = Data::HAL->new( links => [ @@ -86,7 +90,7 @@ sub item_by_id { return NGCP::Panel::Utils::ProfilePackages::get_contract_balance(c => $c, contract => $self->item_rs($c)->find($id), now => $now); - + } sub update_item { @@ -103,9 +107,9 @@ sub update_item { balance => $item, now => $now, new_cash_balance => $resource->{cash_balance} * 100.0); - + $resource->{cash_balance} *= 100.0; - # silently forbid to update cash_balance_interval and free_time_balance_interval + # ignoring cash_debit and free_time_spent: $item->update({ cash_balance => $resource->{cash_balance}, free_time_balance => $resource->{free_time_balance},