Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/AccessSystem/Schema/Result/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ Emails are sent for:
=cut

sub create_payment {
my ($self, $OVERLAP_DAYS) = @_;
my ($self, $OVERLAP_DAYS, $no_new_bank_data) = @_;
$no_new_bank_data ||= 0;
my $schema = $self->result_source->schema;
my $dt_parser = $schema->storage->datetime_parser;

Expand Down Expand Up @@ -586,7 +587,7 @@ sub create_payment {
}
}

if($current_bal < $self->dues) {
if($current_bal < $self->dues ) {
# Expanded for fees update 2025:
# If previously valid, and payment (intention) is less than dues (which have changed!)
# and actually expired (during overlap), convert to donor-tier, fees to 0, store old tier/fees
Expand Down Expand Up @@ -628,6 +629,7 @@ sub create_payment {
warn "Member " . $self->bank_ref . " not covered fees, converted to Donor Tier";
return;
}

# Normal fail - intended to pay enough for tier but.. didnt? (Presumably stopped paying)
warn "Member " . $self->bank_ref . " balance not enough for another month.\n";
# Remind when actually expired, 5 days into the overlap
Expand All @@ -637,6 +639,14 @@ sub create_payment {
# has (or is about to) expire
# this will only send once!
my $last = $self->last_payment;

if($no_new_bank_data) {
# can't determine fail because we didnt get any new bank data
# add a day to last payment expiry if close to expiry:
$last->update({ expires_on_date => $last->expires_on_date->add(days => 1)});
return;
}

my $expiry = $self->real_expiry($OVERLAP_DAYS);
my $paid_date = sprintf("%s, %d %s %d",
$last->paid_on_date->day_abbr,
Expand Down
27 changes: 22 additions & 5 deletions script/from_bank.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,26 @@
$ENV{BARCLAYSCRAPE} ||= '/usr/src/extern/barclayscrape';
$ENV{ACCESS_HOME} ||= '/usr/src/extern/hackspace/AccessSystem';
my $today = DateTime->now()->ymd();
system("$ENV{BARCLAYSCRAPE}/barclayscrape.js --otp $ENV{CODE} get_ofx $ENV{ACCESS_HOME}");
system("cp 20845883789160.ofx $ENV{ACCESS_HOME}/ofx/$today.ofx");
system("scp -P 2222 $ENV{ACCESS_HOME}/ofx/$today.ofx castaway\@inside.swindon-makerspace.org:/opt/AccessSystem/ofx/");
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/update_payments.pl"');
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl"');
if(-e '20845883789160.ofx') {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat('20845883789160.ofx');
my $dt = DateTime->from_epoch(epoch => $atime);
if($dt->add(days => 1) < DateTime->now()) {
system('rm 20845883789160.ofx');
}
}
chdir($ENV{BARCLAYSCRAPE});
system("node barclayscrape.js --no-headless get_ofx $ENV{ACCESS_HOME}");
chdir($ENV{ACCESS_HOME});
if(-e '20845883789160.ofx') {
system("cp 20845883789160.ofx $ENV{ACCESS_HOME}/ofx/$today.ofx");
system("scp -P 2222 $ENV{ACCESS_HOME}/ofx/$today.ofx castaway\@inside.swindon-makerspace.org:/opt/AccessSystem/ofx/");
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/update_payments.pl"');
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl"');
} else {
print "NO NEW BANK DATA!\n";
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/membership_payments.pl --no_bank_transactions"');
}
system('ssh -p 2222 castaway@inside.swindon-makerspace.org "cd /opt/AccessSystem; CATALYST_HOME=/opt/AccessSystem carton exec perl -Ilib /opt/AccessSystem/script/send_communications.pl"');

17 changes: 16 additions & 1 deletion script/membership_payments.pl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use lib "$ENV{CATALYST_HOME}/lib";
use AccessSystem::Schema;
use OFX::Parse;
use Getopt::Long;

=head1 NAME membership_payments

Expand Down Expand Up @@ -63,6 +64,20 @@ =head2 TWEAKS
die "Please set the CATALYST_HOME environment variable and try again\n";
}

=head2 --no_bank_transactions

The script is called with this argument if we could not fetch new
transactions from the bank, instead of emailing expir(ed|ing) members
it should add them a day's grace to compensate for our lack of data.

=cut

my $no_bank_transactions = 0;
GetOptions(
'no_bank_transactions' => \$no_bank_transactions,
);


my $OVERLAP_DAYS = 14;

# Read config to get db connection info:
Expand All @@ -76,7 +91,7 @@ =head2 TWEAKS
my $people_rs = $schema->resultset('Person');
while (my $person = $people_rs->next) {
next if $person->parent_id;
$person->create_payment($OVERLAP_DAYS);
$person->create_payment($OVERLAP_DAYS, $no_bank_transactions);
}

# Update membership table, based on current validity of members:
Expand Down
Loading