sub _nightly_summary { my $self = shift; my $tmpl_dir = $self->{'cfg'}->param("templates.template_dir"); my $tmpl = $self->{'cfg'}->param("rpt_tmpl.nightly_summary"); my $sql = "SELECT substr(NOW(),1,10);"; my $sth = $self->{'dbh_pb'}->prepare($sql); $sth->execute(); my ($date) = $sth->fetchrow_array(); $date = '2008-12-05'; # for testing after midnight my $my_template = "$tmpl_dir/$tmpl"; my $output; # my $output = '/home/hesco/nightly_summary.txt'; print STDERR "The template is: $my_template \nThe output file is: $output \n"; my $stats = $self->_compute_rpt_stats($date); my $template = Template->new(); # $template->process($my_template,$stats); $template->process($my_template,$stats,$output); print STDERR Dumper($output); # return $stats; } sub _compute_rpt_stats { my $self = shift; my $date = shift; my ($stats,$sql,$sth,$sth1,$result,@loop_data); my $dbh = $self->{'dbh_pb'}; my $sql_stats = $self->{'cfg'}->get_block("stats"); my $sql_stats_today = $self->{'cfg'}->get_block("stats_today"); # print STDERR Dumper(\$sql_stats); my @statistics = qw/shifts dialed spoken messages supporters new_subscribers yard_signs call_backs contributions pledges/; foreach my $statistic (@statistics){ # print "The next statistic is: $statistic.\n"; $sql = $sql_stats->{'sql_stats_' . $statistic}; if(length($sql) > 3){ # print STDERR $sql,"\n"; $sth1 = $dbh->prepare($sql); $sth1->execute(); ($stats->{'team'}->{$statistic}) = $sth1->fetchrow_array() || 'unknown'; } else { $stats->{'team'}->{$statistic} = 'unknown'; } $sql = $sql_stats_today->{'sql_stats_today_' . $statistic}; if(length($sql) > 3){ $sth1 = $dbh->prepare($sql); $sth1->execute($date); ($stats->{'team_today'}->{$statistic}) = $sth1->fetchrow_array() || 'unknown'; } else { $stats->{'team_today'}->{$statistic} = 'unknown'; } } $sql = $self->{'cfg'}->param("sql_rpt.sql_rpt_vols_worked_today"); $sth = $self->{'dbh_pb'}->prepare($sql); my @loop_data_worked_today = (); $sth->execute($date) or die "Unable to execute $sql."; while (my $row_hashref = $sth->fetchrow_hashref()){ my %row_data = (); $row_data{'NAME'} = $row_hashref->{'name'}; $row_data{'LOG_IN_DATE'} = $row_hashref->{'log_in_date'}; $row_data{'NUMS_ASSIGNED'} = $row_hashref->{'nums_assigned'}; push (@loop_data_worked_today, \%row_data); } $stats->{'loop'}->{'VOLS_WORKED_TODAY'} = \@loop_data_worked_today; # etc., etc., etc. # print Dumper(\$stats); return $stats; }