TT#157700 invoice templates call direction mode

so far the invoice contained outgoing calls only.

this change introduces the "call direction" mode
for invoice templates, to configure invoices with
either

 - outgoing calls only
 - incoming calls only
 - both outgoing and incoming calls

Change-Id: I3a9d4e3dbb83de63cc2bfab5f1c55714fe487c25
mr10.4
Rene Krenn 4 years ago
parent c460d03686
commit ebfcc70505

@ -16,7 +16,7 @@ has_field 'reseller' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/reseller name type/],
render_list => [qw/reseller name type call_direction/],
);
1;

@ -33,6 +33,22 @@ has_field 'type' => (
},
);
has_field 'call_direction' => (
type => 'Select',
label => 'Call direction',
required => 1,
options => [
{ label => 'incoming calls only', value => 'in' },
{ label => 'outgoing calls only', value => 'out' },
{ label => 'incoming and outgoing calls', value => 'in_out' },
],
default => 'out',
element_attr => {
rel => ['tooltip'],
title => ['The call directions to include in the invoice.'],
},
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -43,7 +59,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/name type/],
render_list => [qw/name type call_direction/],
);
has_block 'actions' => (

@ -246,14 +246,18 @@ sub get_contract_zonesfees {
my %params = @_;
my $c = $params{c};
my $in = delete $params{in};
my $out = delete $params{out};
my $call_direction = delete $params{call_direction};
my ($zonecalls_rs_in, $zonecalls_rs_out) = get_contract_zonesfees_rs(%params);
my @zones = (
$in ? $zonecalls_rs_in->all : (),
$out ? $zonecalls_rs_out->all : (),
);
my @zones = ();
if ($call_direction) {
if ($call_direction eq "in" or $call_direction eq "in_out") {
push(@zones,$zonecalls_rs_in->all);
}
if ($call_direction eq "out" or $call_direction eq "in_out") {
push(@zones,$zonecalls_rs_out->all);
}
}
my %allzones;
for my $zone (@zones) {
@ -283,7 +287,7 @@ sub get_contract_zonesfees {
sub get_contract_calls_rs{
my %params = @_;
(my($c,$customer_contract_id,$stime,$etime)) = @params{qw/c customer_contract_id stime etime/};
(my($c,$customer_contract_id,$stime,$etime,$call_direction)) = @params{qw/c customer_contract_id stime etime call_direction/};
$stime ||= NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' );
$etime ||= $stime->clone->add( months => 1 );
@ -295,26 +299,46 @@ sub get_contract_calls_rs{
my @colnames = @cols;
push(@cols,qw/source_customer_billing_zones_history.zone source_customer_billing_zones_history.detail/);
push(@colnames,qw/zone zone_detail/);
my $calls_rs = $c->model('DB')->resultset('cdr')->search_rs({
# source_user_id => { 'in' => [ map {$_->uuid} @{$contract->{subscriber}} ] },
my $calls_rs = $c->model('DB')->resultset('cdr')->search({
'call_status' => 'ok',
'source_user_id' => { '!=' => '0' },
'start_time' =>
[ -and =>
{ '>=' => $stime->epoch},
{ '<=' => $etime->epoch},
],
'source_account_id' => $customer_contract_id,
},{
select => \@cols,
as => \@colnames,
'join' => 'source_customer_billing_zones_history',
'order_by' => 'start_time',
});
},{
select => \@cols,
as => \@colnames,
'join' => 'source_customer_billing_zones_history',
'order_by' => 'start_time',
}
);
#suppression rs decoration at last, after any "select =>"
return NGCP::Panel::Utils::CallList::call_list_suppressions_rs($c,$calls_rs,NGCP::Panel::Utils::CallList::SUPPRESS_INOUT);
if ($call_direction) {
if ($call_direction eq "in") {
$calls_rs = $calls_rs->search({
destination_account_id => $customer_contract_id,
});
#suppression rs decoration at last, after any "select =>"
return NGCP::Panel::Utils::CallList::call_list_suppressions_rs($c,$calls_rs,NGCP::Panel::Utils::CallList::SUPPRESS_IN);
} elsif ($call_direction eq "out") {
$calls_rs = $calls_rs->search({
source_account_id => $customer_contract_id,
});
#suppression rs decoration at last, after any "select =>"
return NGCP::Panel::Utils::CallList::call_list_suppressions_rs($c,$calls_rs,NGCP::Panel::Utils::CallList::SUPPRESS_OUT);
} elsif ($call_direction eq "in_out") {
$calls_rs = $calls_rs->search({
-or => [
{ source_account_id => $customer_contract_id },
{ destination_account_id => $customer_contract_id },
],
});
#suppression rs decoration at last, after any "select =>"
return NGCP::Panel::Utils::CallList::call_list_suppressions_rs($c,$calls_rs,NGCP::Panel::Utils::CallList::SUPPRESS_INOUT);
}
}
}

@ -77,8 +77,7 @@ sub create_invoice{
contract_id => $contract_id,
stime => $stime,
etime => $etime,
in => 0,
out => 1,
call_direction => $tmpl->call_direction,
group_by_detail => 1,
);
my $calllist_rs = NGCP::Panel::Utils::Contract::get_contract_calls_rs(
@ -86,6 +85,7 @@ sub create_invoice{
customer_contract_id => $contract_id,
stime => $stime,
etime => $etime,
call_direction => $tmpl->call_direction,
);
my $calllist = [ map {
my $call = {$_->get_inflated_columns};

Loading…
Cancel
Save