MT#12825 Export billing fees to csv file

Change-Id: I17bf0592c28e3e642ec83456237af14247db729a
changes/01/2301/4
Irina Peshinskaya 11 years ago
parent 6489a0d852
commit 4562fbf8c5

@ -495,6 +495,20 @@ sub fees_upload :Chained('fees_list') :PathPart('upload') :Args(0) {
$c->stash(form => $form);
}
sub fees_download :Chained('fees_list') :PathPart('download') :Args(0) {
my ($self, $c) = @_;
my $schema = $c->model('DB');
my $data = NGCP::Panel::Utils::Billing::combine_billing_fees(
c => $c,
profile => $c->stash->{'profile_result'},
schema => $schema,
);
$c->response->header ('Content-Disposition' => 'attachment; filename="billing_fees_'.$c->stash->{profile}->{id}.'.txt"');
$c->response->content_type('text/csv');
$c->response->body($$data);
return;
}
sub fees_edit :Chained('fees_base') :PathPart('edit') :Args(0) {
my ($self, $c) = @_;

@ -3,6 +3,7 @@ use strict;
use warnings;
use Text::CSV_XS;
use IO::String;
sub process_billing_fees{
my(%params) = @_;
@ -61,6 +62,36 @@ sub process_billing_fees{
return ( \@fees, \@fails, \$text );
}
sub combine_billing_fees{
my(%params) = @_;
my($c,$profile,$schema) = @params{qw/c profile schema/};
my $csv = Text::CSV_XS->new({ allow_whitespace => 1, binary => 1, keep_meta_info => 1 });
my @cols = @{ $c->config->{fees_csv}->{element_order} };
$csv->column_names(@cols);
my $io = IO::String->new();
my $fees_rs = $profile->billing_fees->search_rs(
undef,
{
'+select' => ['billing_zone.zone','billing_zone.detail'],
'+as' => ['zone','zone_detail'],
'join' => 'billing_zone',
}
);
#$csv->print($io, [ @cols ]);
#print $io "\n";
while ( my $billing_fee_row = $fees_rs->next ){
#$csv->print_hr($io, $billing_fee_row->get_inflated_columns);
my %billing_fee = $billing_fee_row->get_inflated_columns;
$csv->print($io, [ @billing_fee{@cols} ]);
print $io "\n";
}
return $io->string_ref;
}
sub get_contract_count_stmt {
return "select count(distinct c.id) from `billing`.`billing_mappings` bm join `billing`.`contracts` c on c.id = bm.contract_id where bm.`billing_profile_id` = `me`.`id` and c.status != 'terminated' and (bm.end_date is null or bm.end_date >= now())";
}

@ -22,6 +22,7 @@
helper.top_buttons = [
{ name = c.loc('Create Fee Entry'), uri = c.uri_for( profile.id, 'fees') _ "/create", icon = 'icon-star' },
{ name = c.loc('Upload Fees as CSV'), uri = c.uri_for_action('/billing/fees_upload',[c.req.captures.0]), icon = 'icon-star' },
{ name = c.loc('Download Fees as CSV'), uri = c.uri_for_action('/billing/fees_download',[c.req.captures.0]), icon = 'icon-star' },
{ name = c.loc('Edit Zones'), uri = c.uri_for_action('/billing/zones',[c.req.captures.0]), icon = 'icon-star' },
];
END;

Loading…
Cancel
Save