diff --git a/lib/NGCP/Schema/Result/contacts.pm b/lib/NGCP/Schema/Result/contacts.pm index 757bbee2..3f6d0b81 100644 --- a/lib/NGCP/Schema/Result/contacts.pm +++ b/lib/NGCP/Schema/Result/contacts.pm @@ -110,6 +110,8 @@ __PACKAGE__->add_columns( extra => { list => [ "active", "terminated"] }, is_nullable => 0, }, + "timezone", + { data_type => "varchar", is_nullable => 1, size => 80 }, ); __PACKAGE__->set_primary_key("id"); @@ -302,6 +304,12 @@ NGCP::Schema::Result::contacts is_nullable: 1 size: 31 +=head2 timezone + + data_type: 'varchar' + is_nullable: 1 + size: 80 + =head1 PRIMARY KEY =over 4 diff --git a/lib/NGCP/Schema/Result/contract_timezone.pm b/lib/NGCP/Schema/Result/contract_timezone.pm new file mode 100644 index 00000000..8403e2c4 --- /dev/null +++ b/lib/NGCP/Schema/Result/contract_timezone.pm @@ -0,0 +1,58 @@ +package NGCP::Schema::Result::contract_timezone; +use Scalar::Util qw(blessed); +use base qw/DBIx::Class::Core/; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMicro", +); + +__PACKAGE__->table("billing.v_contract_timezone"); + +__PACKAGE__->add_columns( + "contact_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 1, + }, + "contract_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "name", + { + data_type => "varchar", + size => 80, + is_nullable => 1, + }, +); + +__PACKAGE__->belongs_to( + "contract", + "NGCP::Schema::Result::contracts", + { id => "contract_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->belongs_to( + "contact", + "NGCP::Schema::Result::contacts", + { id => "contact_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; + diff --git a/lib/NGCP/Schema/Result/reseller_timezone.pm b/lib/NGCP/Schema/Result/reseller_timezone.pm new file mode 100644 index 00000000..c5f34539 --- /dev/null +++ b/lib/NGCP/Schema/Result/reseller_timezone.pm @@ -0,0 +1,58 @@ +package NGCP::Schema::Result::reseller_timezone; +use Scalar::Util qw(blessed); +use base qw/DBIx::Class::Core/; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMicro", +); + +__PACKAGE__->table("billing.v_reseller_timezone"); + +__PACKAGE__->add_columns( + "contact_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 1, + }, + "reseller_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "name", + { + data_type => "varchar", + size => 80, + is_nullable => 1, + }, +); + +__PACKAGE__->belongs_to( + "reseller", + "NGCP::Schema::Result::resellers", + { id => "reseller_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->belongs_to( + "contact", + "NGCP::Schema::Result::contacts", + { id => "contact_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; + diff --git a/lib/NGCP/Schema/Result/timezones.pm b/lib/NGCP/Schema/Result/timezones.pm new file mode 100644 index 00000000..7fa32d9f --- /dev/null +++ b/lib/NGCP/Schema/Result/timezones.pm @@ -0,0 +1,51 @@ +package NGCP::Schema::Result::timezones; +use Scalar::Util qw(blessed); +use base qw/DBIx::Class::Core/; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMicro", +); +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); +__PACKAGE__->table("timezones"); + + +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "name", + { + data_type => "varchar", + size => 80, + is_nullable => 0, + }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +my $timezones_sql = 'SELECT @rc:=@rc+1 as id, t.name FROM (' . + (join " UNION ALL ", + map { sprintf "SELECT '%s' as name", $_ } + DateTime::TimeZone->all_names) . + ') t, (SELECT @rc:=0) as cnt'; + +__PACKAGE__->set_primary_key("name"); + +__PACKAGE__->result_source_instance->is_virtual(1); + +__PACKAGE__->result_source_instance->view_definition($timezones_sql); + +1; + diff --git a/lib/NGCP/Schema/Result/voip_subscriber_timezone.pm b/lib/NGCP/Schema/Result/voip_subscriber_timezone.pm new file mode 100644 index 00000000..02f21c84 --- /dev/null +++ b/lib/NGCP/Schema/Result/voip_subscriber_timezone.pm @@ -0,0 +1,71 @@ +package NGCP::Schema::Result::voip_subscriber_timezone; +use Scalar::Util qw(blessed); +use base qw/DBIx::Class::Core/; + +our $VERSION = '2.007'; + +__PACKAGE__->load_components( + "InflateColumn::DateTime", + "Helper::Row::ToJSON", + "+NGCP::Schema::InflateColumn::DateTime::EpochMicro", +); + +__PACKAGE__->table("billing.v_subscriber_timezone"); + +__PACKAGE__->add_columns( + "contact_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 1, + }, + "subscriber_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 0, + }, + "uuid", + { + data_type => "char", + size => 36, + is_nullable => 0, + }, + "name", + { + data_type => "varchar", + size => 80, + is_nullable => 1, + }, +); + +__PACKAGE__->belongs_to( + "voip_subscriber", + "NGCP::Schema::Result::voip_subscribers", + { id => "subscriber_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->belongs_to( + "contract", + "NGCP::Schema::Result::contracts", + { id => "contract_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->belongs_to( + "contact", + "NGCP::Schema::Result::contacts", + { id => "contact_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +sub TO_JSON { + my ($self) = @_; + return { + map { blessed($_) && $_->isa('DateTime') ? $_->datetime : $_ } %{ $self->next::method } + }; +} + +1; + diff --git a/lib/NGCP/Schema/Result/voip_subscribers.pm b/lib/NGCP/Schema/Result/voip_subscribers.pm index 795efc63..c26421ae 100644 --- a/lib/NGCP/Schema/Result/voip_subscribers.pm +++ b/lib/NGCP/Schema/Result/voip_subscribers.pm @@ -110,6 +110,13 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->might_have( + "timezone", + 'NGCP::Schema::Result::voip_subscriber_timezone', + { 'foreign.subscriber_id' => 'self.id' }, + { cascade_copy => 0, cascade_delete => 0 }, +); + __PACKAGE__->belongs_to( "contact", "NGCP::Schema::Result::contacts",