# --------------------------------------------------------------------
+---------
# Subroutine: produceDailyReport
# Parameters: hashref argument hash produced by getopts
# hashref merchant's contact data
# hashref transactional data
# Returns: Nothing
# ====================================================================
+=========
# runs through the list of transactions collating a report for sending
+ to the
# merchant.
# If there is any success/fail data from customer reports or CGI calls
+ then
# this is also included.
# --------------------------------------------------------------------
+---------
sub produceDailyReport{
my $opts = shift();
my $merchantInfo = shift();
my $data = shift();
my $email_address = $opts{'e'} ||
$merchantInfo->{'CONTACT'}->{'SBDAYMAIL'}
+||
$merchantInfo->{'CONTACT'}->{'SBDAYMAILO'}
+;
my $template = HTML::Template->new(
filename => SBR_MERCHANTTEMPLATEDAILY,
die_on_bad_params => 0,
loop_context_vars => 1,
global_vars => 1);
$template->param('transactions',$data);
$template->param('report_type',"Daily");
$template->param('MNAM',$merchantInfo->{'NAME'});
$template->param('merchant_name',$merchantInfo->{'NAME'});
$template->param('current_date',scalar(localtime()));
$template->param('period_start',join '/',reverse split '-',cal
+cYesterday($opts));
$template->param('period_end',join '/',reverse split '-',calcY
+esterday($opts));
#create the totals for passsed/failed transactions
my $totals = totalData($data);
$template->param('total_passed',$totals->{'total_passed'});
$template->param('total_failed',$totals->{'total_failed'});
$template->param('no_passed',$totals->{'no_passed'});
$template->param('no_failed',$totals->{'no_failed'});
$template->param('total_trans',$totals->{'total_trans'});
$template->param('no_trans',$totals->{'no_trans'});
$template->param('CURS',$data->[0]->{'CURS'}); #we need the cu
+rrency :)
$template->param('currency_symbol',$data->[0]->{'CURS'});
#make sure template is aware of email and cgi reports
if(isCustomerReport($opts)){
$template->param('customer_reports',1);
}
if(isMerchantCGICalls($opts)){
$template->param('cgi_calls',1);
}
my $msg = MIME::Lite->new(
From => SBR_MERCHANTFROMADDRESSDAILY,
To => $email_address,
Subject => SBR_MERCHANTSUBJECTDAILY,
Type => 'text/html',
Data => $template->output()
);
#we need to add any images to the mail if they exist
my $parser = HTML::LinkExtor->new();
$parser->parse($template->output());
foreach my $link ($parser->links){
if ($link->[0] eq 'img'){
my_print("Image found [".$link->[2]."] ");
if ($link->[2] =~ /^https?:\/\//){
my_print("Absolute! Ignored.\n");
}else{
my ($imgtype,$junk) = reverse split '\
+.',$link->[2];
$imgtype =~ s/^jpg$/jpeg/; #propper mi
+me name?
if(open(TEST,"<".$link->[2])){
my_print("Attaching\n");
close(TEST);
$msg->attach(Type =>'image/'.$
+imgtype,
Path =>$link->[2],
Filename=>$link->[2],
#Disposition => 'inlin
+e');
Disposition => 'attach
+ment');
}else{
my_print("Not found, Skipped!!
+\n");
}
}
}
}
if($opts{'d'}){
#debug mode
my_print($msg->as_string);
}else{
$msg->send();
}
return 1; #stub
}