From 50f5d60aef5ee82be33c978db6424372bfd7995b Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 28 Jul 2009 22:21:40 +0000 Subject: [PATCH] feature to email CSV of CDRs with invoices #5727 --- FS/FS/Conf.pm | 7 +++++++ FS/FS/Schema.pm | 1 + FS/FS/cust_bill.pm | 32 ++++++++++++++++++++++++++++++-- FS/FS/cust_main.pm | 2 +- httemplate/edit/cust_main/billing.html | 7 +++++++ httemplate/view/cust_main/billing.html | 7 +++++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 20abd4546..40fbaf6c5 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2169,6 +2169,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'voip-cust_email_csv_cdr', + 'section' => '', + 'description' => 'Enable the per-customer option for including CDR information as a CSV attachment on emailed invoices.', + 'type' => 'checkbox', + }, + + { 'key' => 'svc_forward-arbitrary_dst', 'section' => '', 'description' => "Allow forwards to point to arbitrary strings that don't necessarily look like email addresses. Only used when using forwards for weird, non-email things.", diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index b2f590aec..649e0aa49 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -698,6 +698,7 @@ sub tables_hashref { 'cdr_termination_percentage', 'decimal', 'NULL', '', '', '', 'invoice_terms', 'varchar', 'NULL', $char_d, '', '', 'archived', 'char', 'NULL', 1, '', '', + 'email_csv_cdr', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'custnum', 'unique' => [ [ 'agentnum', 'agent_custid' ] ], diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 9937bc76d..4e28af39c 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -704,6 +704,18 @@ sub generate_email { #'Filename' => 'invoice.pdf', ); + my @otherparts = (); + if ( $self->cust_main->email_csv_cdr ) { + + push @otherparts, build MIME::Entity + 'Type' => 'text/csv', + 'Encoding' => '7bit', + 'Data' => [ map { "$_\n" } $self->call_details ], + 'Disposition' => 'attachment', + ; + + } + if ( $conf->exists('invoice_email_pdf') ) { #attaching pdf too: @@ -731,7 +743,7 @@ sub generate_email { my $pdf = build MIME::Entity $self->mimebuild_pdf('', $args{'template'}, %cdrs); - $return{'mimeparts'} = [ $related, $pdf ]; + $return{'mimeparts'} = [ $related, $pdf, @otherparts ]; } else { @@ -743,7 +755,7 @@ sub generate_email { # image/png $return{'content-type'} = 'multipart/related'; - $return{'mimeparts'} = [ $alternative, $image ]; + $return{'mimeparts'} = [ $alternative, $image, @otherparts ]; $return{'type'} = 'multipart/alternative'; #Content-Type of first part... #$return{'disposition'} = 'inline'; @@ -3033,6 +3045,22 @@ sub _items_payments { } +=item call_details + +Returns an array of CSV strings representing the call details for this invoice + +=cut + +sub call_details { + my $self = shift; + map { $_->details( 'format_function' => sub{ shift }, + 'escape_function' => sub{ return() }, + ) + } + grep { $_->pkgnum } + $self->cust_bill_pkg; +} + =back diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 518ab4d98..f6ac186f9 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1869,7 +1869,7 @@ sub check { $self->payname($1); } - foreach my $flag (qw( tax spool_cdr squelch_cdr archived )) { + foreach my $flag (qw( tax spool_cdr squelch_cdr archived email_csv_cdr )) { $self->$flag() =~ /^(Y?)$/ or return "Illegal $flag: ". $self->$flag(); $self->$flag($1); } diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html index 3f3d80176..363dd0419 100644 --- a/httemplate/edit/cust_main/billing.html +++ b/httemplate/edit/cust_main/billing.html @@ -438,6 +438,13 @@ % } +% if ( $conf->exists('voip-cust_email_csv_cdr') ) { + + email_csv_cdr eq "Y" ? 'CHECKED' : '' %>> Attach CDRs as CSV to emailed invoices + +% } else { + +% } % if ( $show_term || $cust_main->cdr_termination_percentage ) { diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html index 049461dbd..c8d0c47cd 100644 --- a/httemplate/view/cust_main/billing.html +++ b/httemplate/view/cust_main/billing.html @@ -216,6 +216,13 @@ Billing information % } +% if ( $conf->exists('voip-cust_email_csv_cdr') ) { + + Email CDRs as CSV + <% $cust_main->email_csv_cdr ? 'yes' : 'no' %> + +% } + % if ( $show_term || $cust_main->cdr_termination_percentage ) { CDR termination settlement -- 2.11.0