[freeside-commits] branch master updated. 642bb1970300250739af3ce7a8706a9771781e05
Mark Wells
mark at 420.am
Tue Nov 27 13:05:12 PST 2012
The branch, master has been updated
via 642bb1970300250739af3ce7a8706a9771781e05 (commit)
from 2c4799e43db745b27b507c7c779ecdaf6628b0f3 (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 642bb1970300250739af3ce7a8706a9771781e05
Author: Mark Wells <mark at freeside.biz>
Date: Tue Nov 27 13:03:36 2012 -0800
ICS invoice batch: send batch and summary report in the same message, #17620
diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm
index 08819fc..6577320 100644
--- a/FS/FS/Cron/upload.pm
+++ b/FS/FS/Cron/upload.pm
@@ -326,14 +326,16 @@ sub spool_upload {
}
}
- send_report('bridgestone-confirm_template',
- {
- agentnum=> $agentnum,
- zipfile => $zipfile,
- prefix => $prefix,
- seq => $seq,
- rows => $rows,
- }
+ send_email(
+ prepare_report('bridgestone-confirm_template',
+ {
+ agentnum=> $agentnum,
+ zipfile => $zipfile,
+ prefix => $prefix,
+ seq => $seq,
+ rows => $rows,
+ }
+ )
);
$seq++;
@@ -376,16 +378,26 @@ sub spool_upload {
close $reg;
close $big;
+ # zip up all three files for transport
my $zipfile = "$basename" . '.zip';
my $command = "cd $dir; zip $zipfile $regfile $bigfile";
system($command) and die "'$command' failed\n";
- my $error = $upload_target->put("$dir/$zipfile");
+ # upload them, unless we're using email, in which case
+ # the zip file will ride along with the report. yes, this
+ # kind of defeats the purpose of the upload_target interface,
+ # but at least we have a place to store the configuration.
+ my $error = '';
+ if ( $upload_target->protocol ne 'email' ) {
+ $error = $upload_target->put("$dir/$zipfile");
+ }
+
+ # create the report
for (values %sum) {
$_ = sprintf('%.2f', $_);
}
- send_report('ics-confirm_template',
+ my %report = prepare_report('ics-confirm_template',
{
agentnum => $agentnum,
count => \%count,
@@ -393,8 +405,23 @@ sub spool_upload {
error => $error,
}
);
+ if ( $upload_target->protocol eq 'email' ) {
+ $report{'to'} =
+ join('@', $upload_target->username, $upload_target->hostname);
+ $report{'subject'} = $upload_target->subject;
+ $report{'mimeparts'} = [
+ { Path => "$dir/$zipfile",
+ Type => 'application/zip',
+ Encoding => 'base64',
+ Filename => $zipfile,
+ Disposition => 'attachment',
+ }
+ ];
+ }
+ $error = send_email(%report);
if ( $error ) {
+ # put the original spool file back
rename "$dir/$file-$date.csv", "$dir/$file.csv";
die $error;
}
@@ -421,7 +448,8 @@ sub spool_upload {
=item send_report CONFIG PARAMS
Retrieves the config value named CONFIG, parses it as a Text::Template,
-extracts "to" and "subject" headers, and sends it by email.
+extracts "to" and "subject" headers, and returns a hash that can be passed
+to L<FS::Misc::send_email>.
PARAMS is a hashref to be passed to C<fill_in>. It must contain
'agentnum' to look up the per-agent config.
@@ -429,7 +457,8 @@ PARAMS is a hashref to be passed to C<fill_in>. It must contain
=cut
# we used it twice, so it's now a subroutine
-sub send_report {
+
+sub prepare_report {
my ($config, $params) = @_;
my $agentnum = $params->{agentnum};
@@ -452,7 +481,7 @@ sub send_report {
$head =~ /^to:\s*(.*)$/im;
my $to = $1;
- send_email(
+ (
to => $to,
from => $conf->config('invoice_from', $agentnum),
subject => $subject,
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Cron/upload.pm | 55 ++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 42 insertions(+), 13 deletions(-)
More information about the freeside-commits
mailing list