+sub download_note { # is a class method
+ my $class = shift;
+ my $pay_batch = shift;
+ my $conf = FS::Conf->new;
+ my $agentnum = $pay_batch->agentnum;
+ my ($process_date, $upload_date) = process_dates($conf, $agentnum);
+ my $date_format = $conf->config('date_format') || '%D';
+ my $days_until_upload = $upload_date->delta_days(DateTime->now);
+
+ my $note = '';
+ if ( $days_until_upload->days == 0 ) {
+ $note = 'Upload this file before 11:00 AM today'.
+ ' (' . $upload_date->strftime($date_format) . '). ';
+ } elsif ( $days_until_upload->days == 1 ) {
+ $note = 'Upload this file before 11:00 AM tomorrow'.
+ ' (' . $upload_date->strftime($date_format) . '). ';
+ } else {
+ $note = 'Upload this file before 11:00 AM on '.
+ $upload_date->strftime($date_format) . '. ';
+ }
+ $note .= 'Payments will be processed on '.
+ $process_date->strftime($date_format) . '.';
+
+ $note;
+}
+
+sub process_dates { # returns both process and upload dates
+ my ($conf, $agentnum) = @_;
+ my @config;
+ if ( $conf->exists('batch-spoolagent') ) {
+ @config = $conf->config('batchconfig-eft_canada', $agentnum);
+ } else {
+ @config = $conf->config('batchconfig-eft_canada');
+ }
+
+ my $process_delay = $config[4] || 1;
+
+ my $ut = DateTime->now; # the latest time we assume the user
+ # could upload the file
+ $ut->truncate(to => 'day')->set_hour(10); # is 10 AM on whatever day
+ if ( $ut < DateTime->now ) {
+ # then we would submit the file today but it's already too late
+ $ut->add(days => 1);
+ }
+ while ( $ut->day_of_week == 6 # Saturday
+ or $ut->day_of_week == 7 # Sunday
+ or is_holiday($ut)
+ )
+ {
+ $ut->add(days => 1);
+ }
+ # $ut is now the latest time that the user can upload the file.
+
+ # that time, plus the process delay, is the _earliest_ process date we can
+ # request. if that's on a weekend or holiday, the process date has to be
+ # later.
+
+ my $pt = $ut->clone();
+ $pt->add(days => $process_delay);
+ while ( $pt->day_of_week == 6
+ or $pt->day_of_week == 7
+ or is_holiday($pt)
+ )
+ {
+ $pt->add(days => 1);
+ }
+
+ ($pt, $ut);
+}
+