{
'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"',
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;
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',
+ ;
+
+ }
}
$conf->set('previous_balance-exclude_from_total', '');
}
+ if ( $conf->exists('voip-cust_email_csv_cdr') ) {
+ $conf->set('voip_cdr_email_attach', 'csv');
+ $conf->delete('voip-cust_email_csv_cdr') ;
+ }
+
}
sub upgrade_overlimit_groups {
<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>
</TR>
% }
-% if ( $conf->exists('voip-cust_email_csv_cdr') ) {
+% if ( $conf->config('voip-cdr_email_attach') ) {
<TR>
<TD ALIGN="right"><% mt('Email CDRs as CSV') |h %></TD>
<TD BGCOLOR="#ffffff"><% $cust_main->email_csv_cdr ? $yes : $no %></TD>