diff --git a/lib/NGCP/Panel/Controller/Invoice.pm b/lib/NGCP/Panel/Controller/Invoice.pm
index ed5d438ee7..f58d9586e0 100644
--- a/lib/NGCP/Panel/Controller/Invoice.pm
+++ b/lib/NGCP/Panel/Controller/Invoice.pm
@@ -170,7 +170,19 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac
out => 1,
group_by_detail => 1,
);
-
+ my $calllist_rs = NGCP::Panel::Utils::Contract::get_contract_calls_rs(
+ c => $c,
+ customer_contract_id => $contract_id,
+ stime => $stime,
+ etime => $etime,
+ );
+ my $calllist = [ map {
+ my $call = {$_->get_inflated_columns};
+ $call->{start_time} = $call->{start_time}->epoch;
+ $call->{source_customer_cost} += 0.0; # make sure it's a number
+ $call;
+ } $calllist_rs->all ];
+
my $billing_mapping = $customer->billing_mappings->find($customer->get_column('bmid'));
my $billing_profile = $billing_mapping->billing_profile;
@@ -194,13 +206,10 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac
$form->params->{period_start} = $stime->epoch;
$form->params->{period_end} = $etime->epoch;
-
my $vat = $customer->vat_rate // 0;
-
$form->params->{amount_net} =
($balance->cash_balance_interval ? $balance->cash_balance_interval / 100 : 0) +
($billing_profile->interval_charge // 0); # TODO: if not a full month, calculate fraction?
-
$form->params->{amount_vat} = $customer->add_vat ?
$form->params->{amount_net} * ($vat/100) : 0;
$form->params->{amount_total} = $form->params->{amount_net} + $form->params->{amount_vat};
@@ -239,36 +248,7 @@ sub create :Chained('inv_list') :PathPart('create') :Args() :Does(ACL) :ACLDetac
my $vars = {};
- my $calllist_rs = $c->model('DB')->resultset('cdr')->search({
- source_account_id => $customer->id,
- call_status => 'ok',
- start_time => { '>=' => $stime->epoch },
- start_time => { '<=' => $etime->epoch },
- },{
- select => [qw/
- source_user source_domain source_cli
- destination_user_in
- start_time duration call_type
- source_customer_cost
- source_customer_billing_zones_history.zone
- source_customer_billing_zones_history.detail
- /],
- as => [qw/
- source_user source_domain source_cli
- destination_user_in
- start_time duration call_type
- source_customer_cost
- zone
- zone_detail
- /],
- join => 'source_customer_billing_zones_history',
- });
- my $calllist = [ map {
- my $call = {$_->get_inflated_columns};
- $call->{start_time} = $call->{start_time}->epoch;
- $call->{source_customer_cost} += 0.0; # make sure it's a number
- $call;
- } $calllist_rs->all ];
+
# TODO: index 170 seems the upper limit here, then the calllist breaks
diff --git a/lib/NGCP/Panel/Utils/Contract.pm b/lib/NGCP/Panel/Utils/Contract.pm
index 6e4506e3dc..4455ba7000 100644
--- a/lib/NGCP/Panel/Utils/Contract.pm
+++ b/lib/NGCP/Panel/Utils/Contract.pm
@@ -392,6 +392,46 @@ sub get_contract_zonesfees {
return \%allzones;
}
+sub get_contract_calls_rs{
+ my %params = @_;
+ (my($c,$customer_contract_id,$stime,$etime)) = @params{qw/c customer_contract_id stime etime/};
+
+ $stime ||= NGCP::Panel::Utils::DateTime::current_local()->truncate( to => 'month' );
+ $etime ||= $stime->clone->add( months => 1 );
+
+ my $calls_rs = $c->model('DB')->resultset('cdr')->search( {
+# source_user_id => { 'in' => [ map {$_->uuid} @{$contract->{subscriber}} ] },
+ 'call_status' => 'ok',
+ 'source_user_id' => { '!=' => '0' },
+ 'start_time' =>
+ [ -and =>
+ { '>=' => $stime->epoch},
+ { '<=' => $etime->epoch},
+ ],
+ 'source_account_id' => $customer_contract_id,
+ },{
+ select => [qw/
+ source_user source_domain source_cli
+ destination_user_in
+ start_time duration call_type
+ source_customer_cost
+ source_customer_billing_zones_history.zone
+ source_customer_billing_zones_history.detail
+ /],
+ as => [qw/
+ source_user source_domain source_cli
+ destination_user_in
+ start_time duration call_type
+ source_customer_cost
+ zone
+ zone_detail
+ /],
+ 'join' => 'source_customer_billing_zones_history',
+ 'order_by' => 'start_time',
+ } );
+
+ return $calls_rs;
+}
1;
__END__
diff --git a/lib/NGCP/Panel/Utils/DateTime.pm b/lib/NGCP/Panel/Utils/DateTime.pm
index d785810ef7..729c68df8f 100644
--- a/lib/NGCP/Panel/Utils/DateTime.pm
+++ b/lib/NGCP/Panel/Utils/DateTime.pm
@@ -27,6 +27,7 @@ sub from_string {
# convert it to xxxx-xx-xxTxx:xx:xx
$s =~ s/^(\d{4}\-\d{2}\-\d{2})\s+(\d.+)$/$1T$2/;
my $ts = DateTime::Format::ISO8601->parse_datetime($s);
+ $ts->set_time_zone( DateTime::TimeZone->new(name => 'local') );
return $ts;
}
diff --git a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm
index 31174bbaaa..934b5d87ad 100644
--- a/lib/NGCP/Panel/Utils/InvoiceTemplate.pm
+++ b/lib/NGCP/Panel/Utils/InvoiceTemplate.pm
@@ -56,6 +56,8 @@ sub svg_pdf {
my $cmd = 'rsvg-convert';
my $cmd_full = $cmd.' '.join(' ', @cmd_args);
$c and $c->log->debug( $cmd_full );
+ print $cmd_full.";\n";
+ $$pdf_ref = capturex([0], $cmd, @cmd_args);
return 1;
}
@@ -64,7 +66,8 @@ sub preprocess_svg {
my($svg_ref) = @_;
$$svg_ref=~s/(?:{\s*)?(?:\s*})?//gs;
-
+ $$svg_ref = ''.$$svg_ref.'';
+
my $xp = XML::XPath->new($$svg_ref);
my $g = $xp->find('//g[@class="page"]');
@@ -75,9 +78,10 @@ sub preprocess_svg {
}
$$svg_ref = ($xp->findnodes('/'))[0]->toString();
+ $$svg_ref =~s/^|<\/root>$//;
- $$svg_ref=~s/<(g .*?)(?:display\s*=\s*["']*none["'[:blank:]]+)(.*?id *=["' ]+page[^"' ]*["' ]+)([^>]*)>/<$1$2$3>/gs;
- $$svg_ref=~s/<(g .*?)(id *=["' ]+page[^"' ]*["' ]+.*?)(?:display\s*=\s*["']*none["'[:blank:]]+)([^>]*)>/<$1$2$3>/gs;
+ #$$svg_ref=~s/<(g .*?)(?:display\s*=\s*["']*none["'[:blank:]]+)(.*?id *=["' ]+page[^"' ]*["' ]+)([^>]*)>/<$1$2$3>/gs;
+ #$$svg_ref=~s/<(g .*?)(id *=["' ]+page[^"' ]*["' ]+.*?)(?:display\s*=\s*["']*none["'[:blank:]]+)([^>]*)>/<$1$2$3>/gs;
}
sub sanitize_svg {
diff --git a/share/templates/invoice/default/invoice_template_svg.tt b/share/templates/invoice/default/invoice_template_svg.tt
index f692b5bb27..e99890f133 100644
--- a/share/templates/invoice/default/invoice_template_svg.tt
+++ b/share/templates/invoice/default/invoice_template_svg.tt
@@ -99,7 +99,7 @@
Total Price in [% cur %]
-
+