Use localtime in TS and set createtime for subs.

Consequently use server's localtime to align with auto-filled timestamps.
Set create_timestamp when creating subscribers.
agranig/1_0_subfix
Andreas Granig 12 years ago committed by Andrew Pogrebennyk
parent 0035fa897a
commit 3ca68fae13

@ -6,6 +6,7 @@ use NGCP::Panel::Form::Contract;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::Contract;
use NGCP::Panel::Utils::Subscriber;
use NGCP::Panel::Utils::DateTime;
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
my ($self, $c) = @_;
@ -34,11 +35,11 @@ sub contract_list :Chained('/') :PathPart('contract') :CaptureArgs(0) {
'=' => $mapping_rs->search({
contract_id => { -ident => 'me.id' },
start_date => [ -or =>
{ '<=' => DateTime->now },
{ '<=' => NGCP::Panel::Utils::DateTime::current_local },
{ -is => undef },
],
end_date => [ -or =>
{ '>=' => DateTime->now },
{ '>=' => NGCP::Panel::Utils::DateTime::current_local },
{ -is => undef },
],
},{
@ -106,7 +107,7 @@ sub create :Chained('contract_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->{create_timestamp} = $form->{modify_timestamp} = DateTime->now;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
$contract->billing_mappings->create({
@ -198,7 +199,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$schema->txn_do(sub {
if($form->values->{billing_profile}{id} != $billing_mapping->billing_profile->id) {
$contract->billing_mappings->create({
start_date => DateTime->now(),
start_date => NGCP::Panel::Utils::DateTime::current_local,
billing_profile_id => $form->values->{billing_profile}{id},
});
}
@ -206,7 +207,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
delete $form->values->{billing_profile};
$form->values->{contact_id} = $form->values->{contact}{id};
delete $form->values->{contact};
$form->{modify_timestamp} = DateTime->now;
$form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
$contract->update($form->values);
# if status changed, populate it down the chain
@ -319,7 +320,7 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->{create_timestamp} = $form->{modify_timestamp} = DateTime->now;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
my $product = $schema->resultset('products')->find({ class => 'sippeering' });
@ -401,7 +402,7 @@ sub customer_create :Chained('customer_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->{create_timestamp} = $form->{modify_timestamp} = DateTime->now;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
$contract->billing_mappings->create({
@ -481,7 +482,7 @@ sub reseller_create :Chained('reseller_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->{create_timestamp} = $form->{modify_timestamp} = DateTime->now;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
my $product = $schema->resultset('products')->find({ class => 'reseller' });

@ -8,6 +8,7 @@ use NGCP::Panel::Form::CustomerDailyFraud;
use NGCP::Panel::Form::CustomerBalance;
use NGCP::Panel::Form::CustomerSubscriber;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::DateTime;
use UUID qw/generate unparse/;
=head1 NAME
@ -69,7 +70,7 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
});
}
my $stime = DateTime->now->truncate(to => 'month');
my $stime = NGCP::Panel::Utils::DateTime::current_local()->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1);
my $balance = $contract->first->contract_balances
->find({
@ -84,11 +85,11 @@ sub base :Chained('list_customer') :PathPart('') :CaptureArgs(1) {
-and => [
-or => [
start_date => undef,
start_date => { '<=' => DateTime->now },
start_date => { '<=' => NGCP::Panel::Utils::DateTime::current_local },
],
-or => [
end_date => undef,
end_date => { '>=' => DateTime->now },
end_date => { '>=' => NGCP::Panel::Utils::DateTime::current_local },
]
],
},
@ -204,6 +205,7 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
admin => $c->request->params->{administrative} || 0,
account_id => $contract->id,
domain_id => $prov_domain->id,
create_timestamp => NGCP::Panel::Utils::DateTime::current_local,
});
my $voip_preferences = $schema->resultset('voip_preferences')->search({

@ -330,7 +330,7 @@ sub create_defaults :Path('create_defaults') :Args(0) {
$c->detach('/denied_page') unless $c->request->method eq 'POST';
$c->detach('/denied_page')
if($c->user->read_only);
my $now = DateTime->now;
my $now = NGCP::Panel::Utils::DateTime::current_local;
my %defaults = (
contacts => {
firstname => 'Default',

@ -7,6 +7,7 @@ use XML::Mini::Document;
use URI::Encode;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::XMLDispatcher;
use NGCP::Panel::Utils::DateTime;
sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) {
my ($self, $c) = @_;
@ -105,10 +106,7 @@ EOF
push @users, {
username => $key,
auth_count => $usr->{$key}->{auth_count},
last_auth => DateTime->from_epoch(
epoch => $usr->{$key}->{last_auth},
time_zone => DateTime::TimeZone->new(name => 'local')
),
last_auth => NGCP::Panel::Utils::DateTime::epoch_local($usr->{$key}->{last_auth}),
} if($usr->{$key}->{auth_count} >= $c->config->{security}->{failed_auth_attempts});
}
}

@ -8,6 +8,8 @@ use NGCP::Panel::Utils::Subscriber;
use NGCP::Panel::Utils::Datatables;
use NGCP::Panel::Utils::Callflow;
use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Utils::Message;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Form::Subscriber;
use NGCP::Panel::Form::SubscriberEdit;
use NGCP::Panel::Form::SubscriberCFSimple;
@ -160,6 +162,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) {
admin => $c->request->params->{administrative} || 0,
account_id => $contract->id,
domain_id => $prov_domain->id,
create_timestamp => NGCP::Panel::Utils::DateTime::current_local,
});
if($number) {
$schema->resultset('voip_dbaliases')->create({

@ -17,7 +17,7 @@ sub create_contract_balance {
# first, calculate start and end time of current billing profile
# (we assume billing interval of 1 month)
my $stime = DateTime->now->truncate(to => 'month');
my $stime = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1)->subtract(seconds => 1);
# calculate free_time/cash ratio
@ -25,7 +25,7 @@ sub create_contract_balance {
my $free_cash = $profile->interval_free_cash || 0;
if($free_time or $free_cash) {
$etime->add(seconds => 1);
my $ctime = DateTime->now->truncate(to => 'day');
my $ctime = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'day');
my $ratio = ($etime->epoch - $ctime->epoch) / ($etime->epoch - $stime->epoch);
$cash_balance = sprintf("%.4f", $free_cash * $ratio);

@ -0,0 +1,21 @@
package NGCP::Panel::Utils::DateTime;
use Sipwise::Base;
sub current_local {
return DateTime->now(
time_zone => DateTime::TimeZone->new(name => 'local')
);
}
sub epoch_local {
my $epoch = shift;
return DateTime->from_epoch(
time_zone => DateTime::TimeZone->new(name => 'local'),
epoch => $epoch,
);
}
1;
# vim: set tabstop=4 expandtab:

@ -21,7 +21,7 @@ has 'priority' => (
around handle => sub {
my ($foo, $self, $c) = @_;
my $stime = DateTime->now->truncate(to => 'month');
my $stime = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1);
$c->stash(

@ -21,7 +21,7 @@ has 'priority' => (
around handle => sub {
my ($foo, $self, $c) = @_;
my $stime = DateTime->now->truncate(to => 'month');
my $stime = NGCP::Panel::Utils::DateTime::current_local->truncate(to => 'month');
my $etime = $stime->clone->add(months => 1);
my $reseller = $c->model('DB')->resultset('resellers')->find($c->user->reseller_id);

Loading…
Cancel
Save