Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 59 lines (49 sloc) 1.44 KB
#!/usr/bin/env perl
use 5.14.1;
use Dancer qw/:syntax/;
use FindBin;
use Cwd qw/realpath/;
use lib "$FindBin::Bin/../lib";
use Biopay::Command;
use Biopay::EmailReceipt;
use Biopay::Receipt;
use Getopt::Long;
BEGIN {
Dancer::Config::setting('appdir',realpath("$FindBin::Bin/.."));
Dancer::Config::setting('views',realpath("$FindBin::Bin/../views"));
Dancer::Config::load();
}
my %opts;
GetOptions( \%opts,
'resend-last|r=i',
'for=i',
) or usage();
my $job_id = shift;
my $member;
if (my $mid = $opts{'resend-last'} || $opts{for}) {
$member = Biopay::Member->By_id($mid);
my $receipt = $member->last_receipt;
die "Couldn't find any receipts for member #$mid" unless $receipt;
Biopay::EmailReceipt->new(
member_id => $mid,
txn_ids => $receipt->txn_ids,
dues => $receipt->dues,
)->send;
}
elsif ($job_id) {
my $job = Biopay::Command->By_id($job_id) || die "Couldn't load command '$job_id'";
die "Command is of the wrong type: " . $job->{command}
unless $job->{command} eq 'send-receipt';
Biopay::EmailReceipt->new($job->args)->send;
$member = Biopay::Member->By_id($job->args->{member_id});
}
else {
usage();
}
if ($member and $member->in_protest) {
print " (Protest from @{[$member->id]}) ";
system($^X, "$FindBin::Bin/send-protest", $member->id)
and die "Could not send protest for member " . $member->id;
}
exit;
sub usage { die "USAGE: $0 <job_id>\n" }