feature to email CSV of CDRs with invoices #5727
authorjeff <jeff>
Tue, 28 Jul 2009 22:21:40 +0000 (22:21 +0000)
committerjeff <jeff>
Tue, 28 Jul 2009 22:21:40 +0000 (22:21 +0000)
FS/FS/Conf.pm
FS/FS/Schema.pm
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
httemplate/edit/cust_main/billing.html
httemplate/view/cust_main/billing.html

index 20abd45..40fbaf6 100644 (file)
@@ -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.",
index b2f590a..649e0aa 100644 (file)
@@ -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' ] ],
index 9937bc7..4e28af3 100644 (file)
@@ -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
 
index 518ab4d..f6ac186 100644 (file)
@@ -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);
   }
index 3f3d801..363dd04 100644 (file)
       <INPUT TYPE="hidden" NAME="squelch_cdr" VALUE="<% $cust_main->squelch_cdr %>">
 % }
 
+% if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
+      <TR>
+       <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="email_csv_cdr" VALUE="Y" <% $cust_main->email_csv_cdr eq "Y" ? 'CHECKED' : '' %>> Attach CDRs as CSV to emailed invoices</TD>
+      </TR>
+% } else { 
+      <INPUT TYPE="hidden" NAME="email_csv_cdr" VALUE="<% $cust_main->email_csv_cdr %>">
+% }
 
 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
       <TR>
index 049461d..c8d0c47 100644 (file)
@@ -216,6 +216,13 @@ Billing information
   </TR>
 % } 
 
+% if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
+  <TR>
+    <TD ALIGN="right">Email&nbsp;CDRs&nbsp;as&nbsp;CSV</TD>
+    <TD BGCOLOR="#ffffff"><% $cust_main->email_csv_cdr ? 'yes' : 'no' %></TD>
+  </TR>
+% } 
+
 % if ( $show_term || $cust_main->cdr_termination_percentage ) {
   <TR>
     <TD ALIGN="right">CDR termination settlement</TD>