MT#12757 regard VAT in calllists

Change-Id: I1c9bb1c3ede8feb461bafe87f96b1618ad6f81c6
changes/74/2374/8
Gerhard Jungwirth 10 years ago
parent e837311b76
commit b19079dd51

@ -2049,7 +2049,7 @@ sub master :Chained('base') :PathPart('details') :CaptureArgs(0) {
my $call_cols = [
{ name => "id", title => $c->loc('#') },
{ name => "direction", search => 1, literal_sql => 'if(source_user_id = "'.$c->stash->{subscriber}->uuid.'", "outcoming", "incoming")' },
{ name => "direction", search => 1, literal_sql => 'if(source_user_id = "'.$c->stash->{subscriber}->uuid.'", "outgoing", "incoming")' },
{ name => "source_user", search => 1, title => $c->loc('Caller') },
{ name => "destination_user", search => 1, title => $c->loc('Callee') },
{ name => "source_customer_billing_zones_history.detail", search => 1, title => $c->loc('Billing zone') },
@ -2061,8 +2061,14 @@ sub master :Chained('base') :PathPart('details') :CaptureArgs(0) {
{ name => "call_id", search => 1, title => $c->loc('Call-ID') },
) if($c->user->roles eq "admin" || $c->user->roles eq "reseller");
my $vat_factor = $c->config->{appearance}{cdr_apply_vat} && $c->stash->{subscriber}->contract->add_vat
? "* " . (1 + $c->stash->{subscriber}->contract->vat_rate / 100)
: "";
$c->log->debug("using vat_factor '$vat_factor'");
push @{ $call_cols }, (
{ name => "source_customer_cost", search => 1, title => $c->loc('Source Cust Cost (cents)'), show_total => 'sum' },
{ name => "total_customer_cost", search => 1, title => $c->loc('Cost'), show_total => 'sum',
literal_sql => 'if(source_user_id = "'.$c->stash->{subscriber}->uuid.'", source_customer_cost, destination_customer_cost)'.$vat_factor },
) ;
$c->stash->{calls_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, $call_cols);

@ -7,7 +7,6 @@ use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
has '+widget_wrapper' => ( default => 'Bootstrap' );
has_field 'submitid' => ( type => 'Hidden' );
has_field 'direction' => (
type => 'Select',
@ -18,7 +17,7 @@ has_field 'direction' => (
],
element_attr => {
rel => ['tooltip'],
title => ['Call direction, either "in" or "out"']
title => ['Call direction, either "in" or "out"'],
},
);
@ -27,7 +26,8 @@ has_field 'own_cli' => (
required => 1,
element_attr => {
rel => ['tooltip'],
title => ['The CLI of the own party. For PBX subscribers it is always the PBX extension, otherwise the source_cli or destination_user_in. CLI format is denormalized by caller-out rewrite rule of subscriber.']
title => ['The CLI of the own party. For PBX subscribers it is always the PBX extension, '
. 'otherwise the source_cli or destination_user_in. CLI format is denormalized by caller-out rewrite rule of subscriber.'],
},
);
@ -36,7 +36,9 @@ has_field 'other_cli' => (
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['The CLI of the other party, or null if CLIR was active. For intra-PBX calls it is the PBX extension, for inter-PBX calls it is the value of the field specified by the alias_field parameter if available, otherwise the souce_cli or destination_user_in. CLI format is denormalized by caller-out rewrite rule of subscriber.']
title => ['The CLI of the other party, or null if CLIR was active. For intra-PBX calls it is the PBX extension, '
. 'for inter-PBX calls it is the value of the field specified by the alias_field parameter if available, '
. 'otherwise the souce_cli or destination_user_in. CLI format is denormalized by caller-out rewrite rule of subscriber.'],
},
);
@ -101,6 +103,15 @@ has_field 'customer_cost' => (
},
);
has_field 'total_customer_cost' => (
type => 'Float',
required => 0,
element_attr => {
rel => ['tooltip'],
title => ['Total cost for the customer. VAT is included if applicable.'],
},
);
has_field 'customer_free_time' => (
type => 'PosInteger',
required => 0,

@ -13,6 +13,7 @@ use NGCP::Panel::Utils::DateTime;
# provides:
# * call_id
# * customer_cost
# * total_customer_cost
# * customer_free_time
# * direction
# * duration
@ -34,7 +35,7 @@ sub process_cdr_item {
my $intra = 0;
if($item->source_user_id && $item->source_account_id == $item->destination_account_id) {
$resource->{intra_customer} = JSON::true; # ?????????????
$resource->{intra_customer} = JSON::true;
$intra = 1;
} else {
$resource->{intra_customer} = JSON::false;
@ -185,6 +186,11 @@ sub process_cdr_item {
$resource->{duration} = NGCP::Panel::Utils::DateTime::sec_to_hms(ceil($item->duration));
$resource->{customer_cost} = $resource->{direction} eq "out" ?
$item->source_customer_cost : $item->destination_customer_cost;
if ($cust->add_vat) {
$resource->{total_customer_cost} = $resource->{customer_cost} * (1 + $cust->vat_rate / 100);
} else {
$resource->{total_customer_cost} = $resource->{customer_cost};
}
$resource->{customer_free_time} = $resource->{direction} eq "out" ?
$item->source_customer_free_time : 0;

@ -23,13 +23,13 @@ sub process {
unless ($use_rs_cb) {
for my $col(@{ $cols }) {
if ($col->{show_total}) {
$aggregate_cols->{$col->{accessor}} = $col->{show_total};
$aggregate_cols->{$col->{accessor}} = [$col->{show_total}, ($col->{literal_sql}) || $col->{accessor}];
}
my @parts = split /\./, $col->{name};
if($col->{literal_sql}) {
$rs = $rs->search_rs(undef, {
$col->{join} ? ( join => $col->{join} ) : (),
$col->{no_column} ? () : (
$col->{no_column} ? () : (
'+select' => { '' => \[$col->{literal_sql}], -as => $col->{accessor} },
'+as' => [ $col->{accessor} ],
)
@ -141,11 +141,11 @@ sub process {
});
}
}
$displayRecords = $use_rs_cb ? 0 : $rs->count;
for my $sum_col (keys %{ $aggregate_cols }) {
my $aggregation_method = $aggregate_cols->{$sum_col};
$aggregations->{$sum_col} = $rs->get_column($sum_col)->$aggregation_method;
my ($aggregation_method, $accessor) = @{ $aggregate_cols->{$sum_col} };
$aggregations->{$sum_col} = $rs->get_column(\[$accessor])->$aggregation_method;
}
# show specific row on top (e.g. if we come back from a newly created entry)

Loading…
Cancel
Save