Skip to content

Commit

Permalink
initial package billing (#1486)
Browse files Browse the repository at this point in the history
* initial package billing
  • Loading branch information
dmitry-sinina authored Jun 23, 2024
1 parent fb9e7a6 commit 019e16c
Show file tree
Hide file tree
Showing 32 changed files with 6,716 additions and 74 deletions.
45 changes: 45 additions & 0 deletions app/admin/billing/package_counters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

ActiveAdmin.register Billing::PackageCounter, as: 'Package Counters' do
menu parent: 'Billing', label: 'Package Counters', priority: 11

actions :index, :show

acts_as_export :id,
[:account_name, proc { |row| row.account.try(:name) }],
[:service_name, proc { |row| row.service.try(:name) }],
:prefix,
:exclude,
:duration

includes :account, :service

filter :id
account_filter :account_id_eq
filter :service
filter :prefix
filter :duration
filter :exclude

index do
selectable_column
id_column
actions
column :account
column :service
column :prefix
column :exclude
column :duration
end

show do
attributes_table do
row :id
row :account
row :service
row :prefix
row :exclude
row :duration
end
end
end
2 changes: 2 additions & 0 deletions app/admin/cdr/cdrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def scoped_collection
scope :with_trace, show_count: false
scope :not_authorized, show_count: false
scope :bad_routing, show_count: false
scope :package_billing, show_count: false

filter :id
filter :routing_tag_ids_include,
Expand Down Expand Up @@ -580,6 +581,7 @@ def scoped_collection
row :destination_initial_rate
row :destination_next_interval
row :destination_next_rate
row :package_counter

row :routing_plan
row :routing_group
Expand Down
8 changes: 6 additions & 2 deletions app/admin/routing/destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
:dp_margin_fixed, :dp_margin_percent,
:profit_control_mode_name,
:valid_from, :valid_till,
:asr_limit, :acd_limit, :short_calls_limit, :reverse_billing,
:asr_limit, :acd_limit, :short_calls_limit, :reverse_billing, :allow_package_billing,
[:routing_tag_names, proc { |row| row.model.routing_tags.map(&:name).join(', ') }],
[:routing_tag_mode_name, proc { |row| row.routing_tag_mode.try(:name) }]

Expand All @@ -66,6 +66,7 @@
filter :initial_rate
filter :next_rate
filter :connect_fee
filter :allow_package_billing

filter :network_prefix_country_id_eq,
as: :select,
Expand Down Expand Up @@ -105,7 +106,7 @@
:dp_margin_percent, :rate_policy_id, :reverse_billing, :initial_rate,
:reject_calls, :use_dp_intervals, :test, :profit_control_mode_id,
:valid_from, :valid_till, :asr_limit, :acd_limit, :short_calls_limit, :batch_prefix,
:reverse_billing, :routing_tag_mode_id, routing_tag_ids: []
:reverse_billing, :routing_tag_mode_id, :allow_package_billing, routing_tag_ids: []

action_item :show_rates, only: [:show] do
link_to 'Show Rates', destination_destination_next_rates_path(resource.id)
Expand Down Expand Up @@ -174,6 +175,7 @@ def scoped_collection

column :rate_policy, &:rate_policy_name
column :reverse_billing
column :allow_package_billing

## fixed price
column :initial_interval
Expand Down Expand Up @@ -222,6 +224,7 @@ def scoped_collection
f.input :valid_till, as: :date_time_picker
f.input :rate_policy_id, as: :select, include_blank: false, collection: Routing::DestinationRatePolicy::POLICIES.invert
f.input :reverse_billing
f.input :allow_package_billing
f.input :initial_interval
f.input :next_interval
f.input :use_dp_intervals
Expand Down Expand Up @@ -272,6 +275,7 @@ def scoped_collection
row :valid_till, &:decorated_valid_till
row :rate_policy, &:rate_policy_name
row :reverse_billing
row :allow_package_billing
row :initial_interval
row :next_interval
row :use_dp_intervals
Expand Down
35 changes: 35 additions & 0 deletions app/models/billing/package_counter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: billing.package_counters
#
# id :bigint(8) not null, primary key
# duration :integer(4) default(0), not null
# exclude :boolean default(FALSE), not null
# prefix :string not null
# account_id :integer(4) not null
# service_id :bigint(8)
#
# Indexes
#
# package_counters_account_id_idx (account_id)
# package_counters_prefix_idx (((prefix)::prefix_range)) USING gist
# package_counters_service_id_idx (service_id)
#
# Foreign Keys
#
# package_counters_account_id_fkey (account_id => accounts.id)
#
class Billing::PackageCounter < ApplicationRecord
self.table_name = 'billing.package_counters'

belongs_to :account, class_name: 'Account'
belongs_to :service, class_name: 'Billing::Service', optional: true

validates :duration, presence: true

def display_name
"PC##{id}"
end
end
5 changes: 4 additions & 1 deletion app/models/cdr/cdr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# orig_call_id :string
# orig_gw_external_id :bigint(8)
# orig_gw_id :integer(4)
# package_counter_id :bigint(8)
# pop_id :integer(4)
# rateplan_id :integer(4)
# routing_group_id :integer(4)
Expand Down Expand Up @@ -205,7 +206,7 @@ class Cdr::Cdr < Cdr::Base
routing_plan vendor
term_gw orig_gw customer_auth vendor_acc customer_acc
dst_area customer rateplan pop src_area lnp_database
node sign_term_transport_protocol
node sign_term_transport_protocol package_counter
].freeze

include Partitionable
Expand Down Expand Up @@ -241,6 +242,7 @@ class Cdr::Cdr < Cdr::Base
belongs_to :auth_orig_transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :auth_orig_transport_protocol_id, optional: true
belongs_to :sign_orig_transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :sign_orig_transport_protocol_id, optional: true
belongs_to :sign_term_transport_protocol, class_name: 'Equipment::TransportProtocol', foreign_key: :sign_term_transport_protocol_id, optional: true
belongs_to :package_counter, class_name: 'Billing::PackageCounter', foreign_key: :package_counter_id, optional: true

scope :success, -> { where success: true }
scope :failure, -> { where success: false }
Expand Down Expand Up @@ -270,6 +272,7 @@ class Cdr::Cdr < Cdr::Base
scope :not_authorized, -> { where('customer_auth_id is null') }
scope :bad_routing, -> { where('customer_auth_id is not null AND disconnect_initiator_id=0') }
scope :with_trace, -> { where('dump_level_id > 0') }
scope :package_billing, -> { where('package_counter_id is not null') }

scope :account_id_eq, ->(account_id) { where('vendor_acc_id =? OR customer_acc_id =?', account_id, account_id) }

Expand Down
1 change: 1 addition & 0 deletions app/models/report/realtime/bad_routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# orig_call_id :string
# orig_gw_external_id :bigint(8)
# orig_gw_id :integer(4)
# package_counter_id :bigint(8)
# pop_id :integer(4)
# rateplan_id :integer(4)
# routing_group_id :integer(4)
Expand Down
1 change: 1 addition & 0 deletions app/models/report/realtime/not_authenticated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# orig_call_id :string
# orig_gw_external_id :bigint(8)
# orig_gw_id :integer(4)
# package_counter_id :bigint(8)
# pop_id :integer(4)
# rateplan_id :integer(4)
# routing_group_id :integer(4)
Expand Down
1 change: 1 addition & 0 deletions app/models/report/realtime/origination_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# orig_call_id :string
# orig_gw_external_id :bigint(8)
# orig_gw_id :integer(4)
# package_counter_id :bigint(8)
# pop_id :integer(4)
# rateplan_id :integer(4)
# routing_group_id :integer(4)
Expand Down
1 change: 1 addition & 0 deletions app/models/report/realtime/termination_distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
# orig_call_id :string
# orig_gw_external_id :bigint(8)
# orig_gw_id :integer(4)
# package_counter_id :bigint(8)
# pop_id :integer(4)
# rateplan_id :integer(4)
# routing_group_id :integer(4)
Expand Down
1 change: 1 addition & 0 deletions app/models/routing/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# id :bigint(8) not null, primary key
# acd_limit :float default(0.0), not null
# allow_package_billing :boolean default(FALSE), not null
# asr_limit :float default(0.0), not null
# connect_fee :decimal(, ) default(0.0)
# dp_margin_fixed :decimal(, ) default(0.0), not null
Expand Down
9 changes: 9 additions & 0 deletions app/policies/billing/package_counter_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Billing
class PackageCounterPolicy < ::RolePolicy
section 'Billing/PackageCounter'
class Scope < ::RolePolicy::Scope
end
end
end
5 changes: 5 additions & 0 deletions config/policy_roles.yml.distr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ user:
change: true
remove: true
perform: true
Billing/PackageCounter:
read: true
change: true
remove: true
perform: true
Billing/Contact:
read: true
change: true
Expand Down
Loading

0 comments on commit 019e16c

Please sign in to comment.