[freeside-commits] branch FREESIDE_4_BRANCH updated. 51b2e1987790eb224ead07ed0a8aef828a4965de

Ivan ivan at 420.am
Tue Feb 2 12:45:27 PST 2016


The branch, FREESIDE_4_BRANCH has been updated
       via  51b2e1987790eb224ead07ed0a8aef828a4965de (commit)
      from  df740c217a8f133f0143a9a2cd293bf5dd22944f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 51b2e1987790eb224ead07ed0a8aef828a4965de
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Feb 2 12:45:24 2016 -0800

    zip email CDRs, RT#40112

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index afacc29..9b05411 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3549,18 +3549,29 @@ and customer address. Include units.',
   {
     'key'         => 'voip-cdr_email',
     'section'     => 'telephony',
-    'description' => 'Include the call details on emailed invoices (and HTML invoices viewed in the backend), even if the customer is configured for not printing them on the invoices.',
+    'description' => 'Include the call details inline on emailed invoices (and HTML invoices viewed in the backend), even if the customer is configured for not printing them on the invoices.  Useful for including these details in electronic delivery but omitting them when printing.',
     'type'        => 'checkbox',
   },
 
   {
     'key'         => 'voip-cust_email_csv_cdr',
-    'section'     => 'telephony',
-    'description' => 'Enable the per-customer option for including CDR information as a CSV attachment on emailed invoices.',
+    'section'     => 'deprecated',
+    'description' => 'Deprecated, see voip-cdr_email_attach instead.  Used to enable the per-customer option for including CDR information as a CSV attachment on emailed invoices.',
     'type'        => 'checkbox',
   },
 
   {
+    'key'         => 'voip-cdr_email_attach',
+    'section'     => 'telephony',
+    'description' => 'Enable the per-customer option for including CDR information as an attachment on emailed invoices.',
+    'type'        => 'select',
+    'select_hash' => [ ''    => 'Disabled',
+                       'csv' => 'Text (CSV) attachment',
+                       'zip' => 'Zip attachment',
+                     ],
+  },
+
+  {
     'key'         => 'cgp_rule-domain_templates',
     'section'     => '',
     'description' => 'Communigate Pro rule templates for domains, one per line, "svcnum Name"',
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 1106310..6d661f1 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -12,6 +12,8 @@ use Date::Format;
 use Date::Language;
 use Text::Template 1.20;
 use File::Temp 0.14;
+use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
+use IO::Scalar;
 use HTML::Entities;
 use Cwd;
 use FS::UID;
@@ -2255,15 +2257,41 @@ sub generate_email {
   my @otherparts = ();
   if ( ref($self) eq 'FS::cust_bill' && $cust_main->email_csv_cdr ) {
 
-    push @otherparts, build MIME::Entity
-      'Type'        => 'text/csv',
-      'Encoding'    => '7bit',
-      'Data'        => [ map { "$_\n" }
-                           $self->call_details('prepend_billed_number' => 1)
-                       ],
-      'Disposition' => 'attachment',
-      'Filename'    => 'usage-'. $self->invnum. '.csv',
-    ;
+    if ( $conf->exists('voip-cust_email_csv_cdr_zip') ) {
+
+      my $data = join('', map "$_\n",
+                   $self->call_details(prepend_billed_number=>1)
+                 );
+
+      my $zip = new Archive::Zip;
+      my $file = $zip->addString( $data, 'usage-'.$self->invnum.'.csv' );
+      $file->desiredCompressionMethod( COMPRESSION_DEFLATED );
+
+      my $zipdata = '';
+      my $SH = IO::Scalar->new(\$zipdata);
+      my $status = $zip->writeToFileHandle($SH);
+      die "Error zipping CDR attachment: $!" unless $status == AZ_OK;
+
+      push @otherparts, build MIME::Entity
+        'Type'       => 'application/zip',
+        'Encoding'   => 'base64',
+        'Data'       => $zipdata,
+        'Filename'    => 'usage-'. $self->invnum. '.zip',
+      ;
+
+    } else {
+ 
+      push @otherparts, build MIME::Entity
+        'Type'        => 'text/csv',
+        'Encoding'    => '7bit',
+        'Data'        => [ map { "$_\n" }
+                             $self->call_details('prepend_billed_number' => 1)
+                         ],
+        'Disposition' => 'attachment',
+        'Filename'    => 'usage-'. $self->invnum. '.csv',
+      ;
+
+    }
 
   }
 
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index bffda56..f3f0798 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -160,6 +160,11 @@ If you need to continue using the old Form 477 report, turn on the
     $conf->delete('batch-errors_to');
   }
 
+  if ( $conf->exists('voip-cust_email_csv_cdr') ) {
+    $conf->set('voip_cdr_email_attach', 'csv');
+    $conf->delete('voip-cust_email_csv_cdr') ;
+  }
+
   enable_banned_pay_pad() unless length($conf->config('banned_pay-pad'));
 
 }
diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html
index fbe3e48..fcb44a5 100644
--- a/httemplate/edit/cust_main/billing.html
+++ b/httemplate/edit/cust_main/billing.html
@@ -234,7 +234,7 @@ function toggle(obj) {
       <INPUT TYPE="hidden" NAME="squelch_cdr" VALUE="<% $cust_main->squelch_cdr %>">
 % }
 
-% if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
+% if ( $conf->config('voip-cdr_email_attach') ) { 
       <TR>
        <TD COLSPAN="2"><INPUT TYPE="checkbox" NAME="email_csv_cdr" VALUE="Y" <% $cust_main->email_csv_cdr eq "Y" ? 'CHECKED' : '' %>> <% mt('Attach CDRs as CSV to emailed invoices') |h %></TD>
       </TR>
diff --git a/httemplate/view/cust_main/billing.html b/httemplate/view/cust_main/billing.html
index 97b4baf..cca140b 100644
--- a/httemplate/view/cust_main/billing.html
+++ b/httemplate/view/cust_main/billing.html
@@ -242,7 +242,7 @@
    </TR>
 % }
 
-% if ( $conf->exists('voip-cust_email_csv_cdr') ) { 
+% if ( $conf->config('voip-cdr_email_attach') ) { 
   <TR>
     <TH ALIGN="right"><% mt('Email CDRs as CSV') |h %></TH>
     <TD><% $cust_main->email_csv_cdr ? $yes : $no %></TD>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                          |   17 +++++++++---
 FS/FS/Template_Mixin.pm                |   46 +++++++++++++++++++++++++-------
 FS/FS/Upgrade.pm                       |    5 ++++
 httemplate/edit/cust_main/billing.html |    2 +-
 httemplate/view/cust_main/billing.html |    2 +-
 5 files changed, 58 insertions(+), 14 deletions(-)




More information about the freeside-commits mailing list