Various improvements made and not properly recorded.

I made various improvements quickly while processing payment 1 in 2018-12 and
this is the result.  I didn't commit incrementally, but I do now see that I
added the support for activating the travel ticket and some error message
cleanup.
This commit is contained in:
Bradley M. Kuhn 2019-02-28 14:40:09 -08:00
parent bf631e8259
commit 6a659c102c

View file

@ -14,9 +14,13 @@ use Date::Manip qw(ParseDate UnixDate);
our $RT_CMD; our $RT_CMD;
require 'rt-helper.pl'; require 'rt-helper.pl';
my($PAYMENT_DIR, $VERBOSE, $INTERACTIVE, $PAYMENT_NUMBER, $INVOICE_LINE, $INTERN_SUCCESS_FILE, our $VERBOSE;
my($PAYMENT_DIR, $INTERACTIVE, $PAYMENT_NUMBER, $INVOICE_LINE, $INTERN_SUCCESS_FILE,
$INTERN_FAIL_FILE, $LEDGER_ENTRY_DATE, $SVN_CMD, $ROUND, $TRAVEL_NOTICE_TICKET, $INTERN_FAIL_FILE, $LEDGER_ENTRY_DATE, $SVN_CMD, $ROUND, $TRAVEL_NOTICE_TICKET,
$OVERRIDE_APPROVAL_TAG); $OVERRIDE_APPROVAL_TAG, $TRAVEL_ACTIVATE_FILE);
my %TRAVEL_TICKET_DUE = ('2018-12' => 'Due=2020-12-03 00:00:00');
############################################################################### ###############################################################################
sub LedgerTagFromTicket($$) { sub LedgerTagFromTicket($$) {
@ -69,13 +73,57 @@ sub FindTaxTicketFromList(@) {
return $taxTicket; return $taxTicket;
} }
############################################################################### ###############################################################################
sub FindTravelTicketFromList(@) {
my $travelTicket;
my @possibles;
foreach my $ticket (@_) {
open(my $rtQueueFH, "-|", "$RT_CMD", "show", "-f", 'Queue', $ticket);
while (my $queueLine = <$rtQueueFH>) {
if ($queueLine =~ /\s*Queue\s*:\s*(\S+)\s*$/) {
my $queue = $1;
push(@possibles, $ticket) if $queue =~ /accounts-payable/;
}
}
close $rtQueueFH;
}
foreach my $ticket (@possibles) {
open(my $rtSubjectFH, "-|", "$RT_CMD", "show", "-f", 'Subject', $ticket);
while (my $subLine = <$rtSubjectFH>) {
if ($subLine =~ /\s*Subject\s*:\s*(.+)\s*$/) {
my $subject = $1;
$travelTicket = $ticket if $subject =~ /travel/i;
last;
}
}
close $rtSubjectFH;
}
return $travelTicket;
}
###############################################################################
sub TravelTicketDeLink($$) {
my ($travelNoticeTicket, $travelTicket) = @_;
my $found;
open(my $delTravelDependsFH, "-|", $RT_CMD, "link", '-d',
$travelTicket, 'dependson', $travelNoticeTicket);
while (my $line = <$delTravelDependsFH>) {
if ($line =~ /Link\s+not\s+found/i) {
$found = 0;
} elsif ($line =~ /no\s+longer\s+depends\s+on\s+Ticket/i) {
$found = 1;
}
last if defined $found;
}
close $delTravelDependsFH;
return $found
}
###############################################################################
GetOptions("paymentDir=s" => \$PAYMENT_DIR, "verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE, GetOptions("paymentDir=s" => \$PAYMENT_DIR, "verbose=i" => \$VERBOSE, "interactive" => \$INTERACTIVE,
"paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD, "paymentNumber=i" => \$PAYMENT_NUMBER, "rtCommand=s" => \$RT_CMD,
"invoiceLine=s" => \$INVOICE_LINE, "internSuccessFile=s", \$INTERN_SUCCESS_FILE, "invoiceLine=s" => \$INVOICE_LINE, "internSuccessFile=s", \$INTERN_SUCCESS_FILE,
"internFailFile=s", \$INTERN_FAIL_FILE, 'ledgerEntryDate=s' => \$LEDGER_ENTRY_DATE, "internFailFile=s", \$INTERN_FAIL_FILE, 'ledgerEntryDate=s' => \$LEDGER_ENTRY_DATE,
"svnCommand=s" => \$SVN_CMD, "round=s" => \$ROUND, "svnCommand=s" => \$SVN_CMD, "round=s" => \$ROUND,
'overrideApprovalTag=s' => \$OVERRIDE_APPROVAL_TAG, 'overrideApprovalTag=s' => \$OVERRIDE_APPROVAL_TAG, 'travelActivateFile=s' => \$TRAVEL_ACTIVATE_FILE,
'travelNoticeTicket=i' => \$TRAVEL_NOTICE_TICKET); 'travelNoticeTicket=i' => \$TRAVEL_NOTICE_TICKET);
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD; $RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
@ -90,6 +138,11 @@ unless (defined $ROUND and $ROUND =~ /^[\d\-]+$/) {
print STDERR "usage: $0 --round=<YEAR-MONTH> option is required and must formated as YYYY-MM\n"; print STDERR "usage: $0 --round=<YEAR-MONTH> option is required and must formated as YYYY-MM\n";
exit 1; exit 1;
} }
unless (defined $TRAVEL_TICKET_DUE{$ROUND}) {
print STDERR "usage: $0 --round=<YEAR-MONTH> option must be a round that this script knows the deadlines for, but it doesn't\n";
exit 1;
}
unless (defined $LEDGER_ENTRY_DATE and $LEDGER_ENTRY_DATE =~ /^[\d\-]+$/) { unless (defined $LEDGER_ENTRY_DATE and $LEDGER_ENTRY_DATE =~ /^[\d\-]+$/) {
print STDERR "usage: $0 --ledgerEntryDate=<DATE> option is required and must be in ISO 8601 format\n"; print STDERR "usage: $0 --ledgerEntryDate=<DATE> option is required and must be in ISO 8601 format\n";
exit 1; exit 1;
@ -110,16 +163,6 @@ unless (-r $INTERN_FAIL_FILE and -f $INTERN_FAIL_FILE) {
print STDERR "usage: $0 --internFailFile=<FILE> option is required and must be readible text file\n"; print STDERR "usage: $0 --internFailFile=<FILE> option is required and must be readible text file\n";
exit 1; exit 1;
} }
my %internCorrespond = ('success' => [], 'failed' => [] );
open (my $internUpdateFH, "<", File::Spec->catfile($PAYMENT_DIR, $INTERN_SUCCESS_FILE));
while (my $line = <$internUpdateFH>) {
push(@{$internCorrespond{success}}, $line);
}
my @internFailData;
open (my $internFailFH, "<", File::Spec->catfile($PAYMENT_DIR, $INTERN_FAIL_FILE));
while (my $line = <$internFailFH>) {
push(@{$internCorrespond{failed}}, $line);
}
unless (defined $PAYMENT_NUMBER and $PAYMENT_NUMBER =~ /^[123]$/) { unless (defined $PAYMENT_NUMBER and $PAYMENT_NUMBER =~ /^[123]$/) {
print STDERR "usage: $0 --paymentNumber=<VALUE> option is required and must be 1, 2 or 3\n"; print STDERR "usage: $0 --paymentNumber=<VALUE> option is required and must be 1, 2 or 3\n";
exit 1; exit 1;
@ -128,21 +171,77 @@ if ( (not defined $OVERRIDE_APPROVAL_TAG) and $PAYMENT_NUMBER == 1) {
print STDERR "usage: $0 --overrideApprovalTag=<STRING> option is required if payment number is 1\n"; print STDERR "usage: $0 --overrideApprovalTag=<STRING> option is required if payment number is 1\n";
exit 1; exit 1;
} }
unless (defined $TRAVEL_ACTIVATE_FILE or $PAYMENT_NUMBER != 1) {
print STDERR "usage: $0 --travelActivateFile=<TEXT_FILE> option is required and must be an file in $PAYMENT_DIR\n";
exit 1;
}
my %internCorrespond = ('success' => [], 'failed' => [], 'travel' => [] );
open (my $internUpdateFH, "<", File::Spec->catfile($PAYMENT_DIR, $INTERN_SUCCESS_FILE));
while (my $line = <$internUpdateFH>) {
push(@{$internCorrespond{success}}, $line);
}
open (my $internFailFH, "<", File::Spec->catfile($PAYMENT_DIR, $INTERN_FAIL_FILE));
while (my $line = <$internFailFH>) {
push(@{$internCorrespond{failed}}, $line);
}
if (defined $TRAVEL_ACTIVATE_FILE) {
open (my $travelActiveFH, "<", File::Spec->catfile($PAYMENT_DIR, $TRAVEL_ACTIVATE_FILE));
while (my $line = <$travelActiveFH>) {
push(@{$internCorrespond{travel}}, $line);
}
}
$VERBOSE = 0 unless defined $VERBOSE; $VERBOSE = 0 unless defined $VERBOSE;
opendir(my $dh, $PAYMENT_DIR);
my $oldInterns = 0; my $oldInterns = 0;
while (my $file = readdir $dh) { my(@processList);
unless ($file =~ /^\s*(success|faile?d?)-(\S+)\.txt\s*$/i) {
print STDERR "Skipping $file which does not match proper format...\n" if ($VERBOSE >= 2); if (@ARGV > 0) {
foreach my $ticket (@ARGV) {
if ($ticket =~ /^\d+$/) {
$ticket = "ticket/$ticket";
}
unless ($ticket =~ /^ticket\/\d+$/) {
print STDERR "Invalid ticket number on command line: $ticket\n";
exit 1;
}
push(@processList, $ticket);
}
} elsif ($PAYMENT_NUMBER != 1) {
opendir(my $dh, $PAYMENT_DIR);
@processList = readdir $dh;
close $dh;
} else {
open(my $rtLsFH, "-|", "$RT_CMD", "ls", "-i", 'Queue = outreachy-interns ' .
"AND Subject LIKE '" . $ROUND . "' AND status = 'needs-project-ok'");
while (my $lsLine = <$rtLsFH>) {
chomp $lsLine;
if ($lsLine =~ /ticket/) {
push(@processList, $lsLine);
}
}
close $rtLsFH;
}
foreach my $entry (@processList) {
my($ticket, $pass, $mentorDate);
if ($PAYMENT_NUMBER == 1) {
$ticket = $entry;
$pass = 1;
$mentorDate = $LEDGER_ENTRY_DATE;
} else {
unless ($entry =~ /^\s*(success|faile?d?)-(\S+)\.txt\s*$/i) {
print STDERR "Skipping $entry which does not match proper format...\n" if ($VERBOSE >= 2);
next; next;
} }
my($pass, $name) = ($1, $2); my $name;
($pass, $name) = ($1, $2);
$pass = ($pass =~ /success/) ? 1 : 0; $pass = ($pass =~ /success/) ? 1 : 0;
open(my $fh, "<", File::Spec->catfile($PAYMENT_DIR, $file)); open(my $fh, "<", File::Spec->catfile($PAYMENT_DIR, $entry));
my $mentorDate; my $mentorDate;
while (my $line = <$fh> ) { while (my $line = <$fh> ) {
if ($line =~ /^\s*Date\s*:\s*(.+)\s*$/) { if ($line =~ /^\s*Date\s*:\s*(.+)\s*$/) {
@ -151,13 +250,9 @@ while (my $file = readdir $dh) {
} }
} }
if (not defined $mentorDate) { if (not defined $mentorDate) {
if ($PAYMENT_NUMBER == 1) { print STDERR "\"$entry\": Skipping: Inside that file there is no valid Date: header" ;
$mentorDate = $LEDGER_ENTRY_DATE;
} else {
print STDERR "\"$file\": Skipping: Inside that file there is no valid Date: header" ;
next; next;
} }
}
my(@nameComponents) = split(/\s*-\s*/, $name); my(@nameComponents) = split(/\s*-\s*/, $name);
my(@searchTerms); my(@searchTerms);
foreach my $name (@nameComponents) { foreach my $name (@nameComponents) {
@ -167,14 +262,15 @@ while (my $file = readdir $dh) {
my $ticket = Outreachy_FindUniqueTicket($ROUND, @searchTerms); my $ticket = Outreachy_FindUniqueTicket($ROUND, @searchTerms);
if (not defined $ticket) { if (not defined $ticket) {
foreach my $term (@searchTerms) { foreach my $term (@searchTerms) {
print STDERR "\"$file\": full search failed, trying \"$term\" by itself\n" if ($VERBOSE > 6); print STDERR "\"$entry\": full search failed, trying \"$term\" by itself\n" if ($VERBOSE > 6);
$ticket = Outreachy_FindUniqueTicket($ROUND, ($term)); $ticket = Outreachy_FindUniqueTicket($ROUND, ($term));
last if (defined $ticket); last if (defined $ticket);
} }
} }
}
if (not defined $ticket) { if (not defined $ticket) {
if (not $INTERACTIVE) { if (not $INTERACTIVE) {
print STDERR "\"$file\": TICKET-NOT-FOUND: Skipped: unable to to find a matching ticket.\n"; print STDERR "\"$entry\": TICKET-NOT-FOUND: Skipped: unable to to find a matching ticket.\n";
next; next;
} else { } else {
# FIXME: prompt for ticket # FIXME: prompt for ticket
@ -183,7 +279,7 @@ while (my $file = readdir $dh) {
} }
my $completedInternshipField = GetCustomFieldForTicket($ticket, "completed-internship"); my $completedInternshipField = GetCustomFieldForTicket($ticket, "completed-internship");
if (not defined $completedInternshipField) { if (not defined $completedInternshipField) {
print STDERR "\"$file\": \"$ticket\": FIELD-NOT-FOUND: Skipping: cannot determine Entity from ticket.\n" ; print STDERR "\"$entry\": \"$ticket\": FIELD-NOT-FOUND: Skipping: cannot determine Entity from ticket.\n" ;
next; next;
} elsif ($completedInternshipField eq 'successful') { } elsif ($completedInternshipField eq 'successful') {
# Don't print to STDERR here, just keep a count since these are "old interns" # Don't print to STDERR here, just keep a count since these are "old interns"
@ -192,7 +288,7 @@ while (my $file = readdir $dh) {
} }
my $entity = LedgerTagFromTicket($ticket, 'Entity'); my $entity = LedgerTagFromTicket($ticket, 'Entity');
if (not defined $entity) { if (not defined $entity) {
print STDERR "\"$file\": \"$ticket\": ENTITY-NOT-FOUND: Skipping: cannot determine Entity from ticket.\n" ; print STDERR "\"$entry\": \"$ticket\": ENTITY-NOT-FOUND: Skipping: cannot determine Entity from ticket.\n" ;
next; next;
} }
@ -203,7 +299,7 @@ while (my $file = readdir $dh) {
# Check to see if this payment was already made # Check to see if this payment was already made
my $thisPayDate = PaymentDateByTicket($ticket, $PAYMENT_NUMBER); my $thisPayDate = PaymentDateByTicket($ticket, $PAYMENT_NUMBER);
if (defined $thisPayDate) { if (defined $thisPayDate) {
print STDERR "\"$file\": \"$ticket\": Skipped: payment $PAYMENT_NUMBER", print STDERR "\"$entry\": \"$ticket\": Skipped: payment $PAYMENT_NUMBER",
" was already made on \"$thisPayDate\""; " was already made on \"$thisPayDate\"";
if ($pass) { if ($pass) {
print STDERR ".\n"; print STDERR ".\n";
@ -218,7 +314,7 @@ while (my $file = readdir $dh) {
if ($prevPayNum > 0) { if ($prevPayNum > 0) {
my $lastPayDate = PaymentDateByTicket($ticket, $prevPayNum); my $lastPayDate = PaymentDateByTicket($ticket, $prevPayNum);
if (not defined $lastPayDate) { if (not defined $lastPayDate) {
print STDERR "\"$file\": \"$ticket\": Skipped: payment $prevPayNum was not made yet"; print STDERR "\"$entry\": \"$ticket\": Skipped: payment $prevPayNum was not made yet";
if ($pass) { if ($pass) {
print STDERR ".\n"; print STDERR ".\n";
} else { } else {
@ -229,69 +325,67 @@ while (my $file = readdir $dh) {
} }
my $expectVal = 'payment-' . $PAYMENT_NUMBER . "-approved"; my $expectVal = 'payment-' . $PAYMENT_NUMBER . "-approved";
if ($completedInternshipField eq $expectVal and $PAYMENT_NUMBER != 1) { if ($completedInternshipField eq $expectVal and $PAYMENT_NUMBER != 1) {
print STDERR "\"$file\": \"$ticket\": $PAYMENT_NUMBER PAYMENT-DONE: Skipped: completed-internship is ", print STDERR "\"$entry\": \"$ticket\": $PAYMENT_NUMBER PAYMENT-DONE: Skipped: completed-internship is ",
"\"$completedInternshipField\" which indicates this payment round is in process.\n"; "\"$completedInternshipField\" which indicates this payment round is in process.\n";
next; next;
} }
$expectVal = 'payment-' . $prevPayNum . "-approved" if $PAYMENT_NUMBER != 1; $expectVal = 'payment-' . $prevPayNum . "-approved" if $PAYMENT_NUMBER != 1;
if ($prevPayNum > 0 and $completedInternshipField ne $expectVal) { if ($prevPayNum > 0 and $completedInternshipField ne $expectVal) {
print STDERR "\"$file\": \"$ticket\": Skipped: completed-internship field was ", print STDERR "\"$entry\": \"$ticket\": Skipped: completed-internship field was ",
"\"$completedInternshipField\" instead of \"$expectVal\".\n"; "\"$completedInternshipField\" instead of \"$expectVal\".\n";
next; next;
} }
my(%links) = GetLinksForTicket($ticket); my(%links) = GetLinksForTicket($ticket);
if ($VERBOSE > 5) { if ($VERBOSE > 5) {
use Data::Dumper; use Data::Dumper;
print STDERR "\"$file\": \"$ticket\": Found the following links: " , Data::Dumper->Dump([\%links]), "\n"; print STDERR "\"$entry\": \"$ticket\": Found the following links: " , Data::Dumper->Dump([\%links]), "\n";
} }
my $taxTicket = FindTaxTicketFromList(@{$links{DependsOn}}); my $taxTicket = FindTaxTicketFromList(@{$links{DependsOn}});
if (not defined $taxTicket) { if (not defined $taxTicket) {
print STDERR "\"$file\": \"$ticket\": Skipped: no tax ticket found.\n"; print STDERR "\"$entry\": \"$ticket\": Skipped: no tax ticket found.\n";
next; next;
} }
my $reimbursementTicket = FindReimbursementTicketFromList($ROUND, @{$links{Members}}); my $reimbursementTicket = FindReimbursementTicketFromList($ROUND, @{$links{Members}});
if (not defined $reimbursementTicket) { if (not defined $reimbursementTicket) {
print STDERR "\"$file\": \"$ticket\": Skipped: no reimbursement ticket found.\n"; print STDERR "\"$entry\": \"$ticket\": Skipped: no reimbursement ticket found.\n";
next; next;
} }
print STDERR "\"$file\": \"$ticket\": found a tax ticket of \"$taxTicket\"\n" if ($VERBOSE > 5); print STDERR "\"$entry\": \"$ticket\": found a tax ticket of \"$taxTicket\"\n" if ($VERBOSE > 5);
my $taxTicketStatus = GetStatusFromTicket($taxTicket); my $taxTicketStatus = GetStatusFromTicket($taxTicket);
if ($taxTicketStatus ne "resolved") { if ($taxTicketStatus ne "resolved") {
print STDERR "\"$file\": \"$ticket\": TAX-TICKET-PENDING: \"$taxTicket\": Skipped: ", print STDERR "\"$entry\": \"$ticket\": TAX-TICKET-PENDING: \"$taxTicket\": Skipped: ",
"tax ticket is in status \"$taxTicketStatus\" instead of \"resolved\"\n"; "tax ticket is in status \"$taxTicketStatus\" instead of \"resolved\"\n";
next; next;
} }
my $mainTicketStatus = GetStatusFromTicket($ticket); my $mainTicketStatus = GetStatusFromTicket($ticket);
if ($mainTicketStatus ne "needs-project-ok") { if ($mainTicketStatus ne "needs-project-ok") {
print STDERR "\"$file\": \"$ticket\": PREV-PAYMENT-INCOMPLETE: Skipped: ", print STDERR "\"$entry\": \"$ticket\": PREV-PAYMENT-INCOMPLETE: Skipped: ",
"ticket is in status \"$mainTicketStatus\" instead of \"needs-project-ok\"\n"; "ticket is in status \"$mainTicketStatus\" instead of \"needs-project-ok\"\n";
next; next;
} }
my $ticketNum = $ticket; $ticketNum =~ s%^.*ticket/(\d+).*$%$1%; my $ticketNum = $ticket; $ticketNum =~ s%^.*ticket/(\d+).*$%$1%;
my %paymentVals; my %paymentVals;
if ($PAYMENT_NUMBER >= 2) {
open(my $logFH, "-|", $RT_CMD, "show", $ticketNum); open(my $logFH, "-|", $RT_CMD, "show", $ticketNum);
while (my $line = <$logFH>) { while (my $line = <$logFH>) {
# Note that this will take the last one used, since rt log gives ticket traffic IN ORDER. # Note that this will take the last one used, since rt log gives ticket traffic IN ORDER.
if ($line =~ /^\s*([^:]+)\s*:(\s*.+)$/) { if ($line =~ /^\s*([^:]+)\s*:\s*(.+)$/) {
my($key, $val) = ($1, $2); my($key, $val) = ($1, $2);
$paymentVals{$key} = $val if $key =~ /(CONTRACTED NAME|PAYMENT NAME|PAYMENT METHOD)/i; $paymentVals{$key} = $val if $key =~ /(CONTRACTED NAME|PAYMENT NAME|PAYMENT METHOD)/i;
print STDERR "\"$file\": \"$ticket\": rt show $ticketNum line match: $key $val for $line" if ($VERBOSE > 7); print STDERR "\"$entry\": \"$ticket\": rt show $ticketNum line match: $key $val for $line" if ($VERBOSE > 7);
} }
} }
close $logFH; close $logFH;
}
print STDERR "\"$file\": \"$ticket\": processing to payment $PAYMENT_NUMBER state... "; print STDERR "\"$entry\": \"$ticket\": processing to payment $PAYMENT_NUMBER state... ";
my $successString = ($pass) ? "success" : "failed"; my $successString = ($pass) ? "success" : "failed";
my $repositoryFile = File::Spec->catfile($PAYMENT_DIR, $mentorDate . "_" . $entity . '_' . $successString . '-report.mbox'); my $repositoryFile = File::Spec->catfile($PAYMENT_DIR, $mentorDate . "_" . $entity . '_' . $successString . '-report.mbox');
my $approvalTag = $repositoryFile; my $approvalTag = $repositoryFile;
if ($PAYMENT_NUMBER == 1) { if ($PAYMENT_NUMBER == 1) {
$approvalTag = " ;Approval: $OVERRIDE_APPROVAL_TAG"; $approvalTag = " ;Approval: $OVERRIDE_APPROVAL_TAG";
unlink(File::Spec->catfile($PAYMENT_DIR, $file));
} else { } else {
$approvalTag =~ s%^.*(Projects/Outreachy/.*)$%$1%; $approvalTag =~ s%^.*(Projects/Outreachy/.*)$%$1%;
$approvalTag = " ;Approval: $approvalTag"; $approvalTag = " ;Approval: $approvalTag";
rename(File::Spec->catfile($PAYMENT_DIR, $file), $repositoryFile); rename(File::Spec->catfile($PAYMENT_DIR, $entry), $repositoryFile);
system($SVN_CMD, "add", $repositoryFile); system($SVN_CMD, "add", $repositoryFile);
} }
open(my $rtCorrespondFH, "|-", $RT_CMD, 'correspond', $ticket, '-m', '-'); open(my $rtCorrespondFH, "|-", $RT_CMD, 'correspond', $ticket, '-m', '-');
@ -330,13 +424,13 @@ while (my $file = readdir $dh) {
$contractName =~ s/^\s*//; $contractName =~ s/\s*$//; $contractName =~ s/^\s*//; $contractName =~ s/\s*$//;
open(my $paymentValsFH, ">", File::Spec->catfile($PAYMENT_DIR, "payment-values.txt")); open(my $paymentValsFH, ">", File::Spec->catfile($PAYMENT_DIR, "payment-values.txt"));
print "OUTREACHY INTERNSHIP PAYMENT $PAYMENT_NUMBER "; print $paymentValsFH "OUTREACHY INTERNSHIP PAYMENT $PAYMENT_NUMBER\n";
foreach my $key (keys %paymentVals) { foreach my $key (keys %paymentVals) {
print $paymentValsFH sprintf(" %20s", $key), "$paymentVals{$key}\n"; print $paymentValsFH sprintf(" %20s: ", $key), "$paymentVals{$key}\n";
} }
print $paymentValsFH sprintf(" %20s", 'TOTAL AMOUNT'), "$rightA\n\n LEDGER ENTRY:\n\n"; print $paymentValsFH sprintf(" %20s", 'TOTAL AMOUNT'), "$rightA\n\n LEDGER ENTRY:\n";
my $ledgerEntryFile = File::Spec->catfile($PAYMENT_DIR, "entry.ledger") my $ledgerEntryFile = File::Spec->catfile($PAYMENT_DIR, "entry.ledger");
open(my $ledgerEntryFH, ">>", $ledgerEntryFile); open(my $ledgerEntryFH, ">>", $ledgerEntryFile);
my $ledgerEntryStr = <<LEDGER_ENTRY my $ledgerEntryStr = <<LEDGER_ENTRY
@ -349,14 +443,44 @@ LEDGER_ENTRY
; ;
print $ledgerEntryFH $ledgerEntryStr; print $ledgerEntryFH $ledgerEntryStr;
close $ledgerEntryFH ; close $ledgerEntryFH ;
open(my $ledgerTagConvertFH, "|-", File::Spec->catfile($ENV{CONSERVANCY_REPOSITORY}, open(my $ledgerTagConvertFH, "-|", join(" ", File::Spec->catfile($ENV{CONSERVANCY_REPOSITORY},
'Financial', 'Code', 'ledger-tag-convert.plx') . 'Financial', 'Code', 'ledger-tag-convert.plx') .
'<' . $ledgerEntryFile); '<' . $ledgerEntryFile));
foreach my $line (<$ledgerTagConvertFH>) { foreach my $line (<$ledgerTagConvertFH>) {
print $paymentValsFH $line; print $paymentValsFH " ", $line;
} }
close $ledgerTagConvertFH; close $ledgerTagConvertFH;
close $paymentValsFH; close $paymentValsFH;
# ACTIVATE TRAVEL TICKET AFTER PAYMENT 1
if ($PAYMENT_NUMBER == 1) {
my $travelTicketSpec = FindTravelTicketFromList(@{$links{Members}});
my $travelTicketNum = $travelTicketSpec;
$travelTicketNum =~ s%^.*ticket/(\d+).*$%$1%;
my $travelTicketStatus = GetStatusFromTicket($travelTicketNum);
if ( (not defined $travelTicketSpec) or $travelTicketStatus ne 'needs-project-ok') {
print STDERR "\"$entry\": \"$ticket\": Travel Ticket: \"$travelTicketSpec\": unable to open travel ticket which is in status \"$travelTicketStatus\"\n";
goto NEXT_TICKET;
}
my $found = TravelTicketDeLink($TRAVEL_NOTICE_TICKET, $travelTicketNum);
if ((not defined $found) or (not $found)) {
print STDERR "\"$entry\": \"$ticket\": WARNING: unable to open travel ticket, $travelTicketNum, as it is not linked to $TRAVEL_NOTICE_TICKET... ";
goto NEXT_TICKET;
}
open(my $travelTicketCorrespondFH, "|-", $RT_CMD, 'correspond', $travelTicketNum, '-m', '-');
my @dd;
foreach my $line (@{$internCorrespond{travel}}) {
$line =~ s/FIXME_PAYMENT_NUMBER/$PAYMENT_NUMBER/g;
$line =~ s/FIXME_INVOICE_DATE/$LEDGER_ENTRY_DATE/g;
$line =~ s/FIXME_MENTOR_DATE/$mentorDate/g;
push(@dd, $line);
}
print $travelTicketCorrespondFH @dd;
close $travelTicketCorrespondFH;
system($RT_CMD, "edit", $travelTicketNum, 'set', 'CF.{due-date-from}=budget-expiration', $TRAVEL_TICKET_DUE{$ROUND},
'Status=awaiting-request');
}
} else { } else {
system($RT_CMD, "edit", $ticket, 'set', 'CF.{completed-internship}=unsuccessful'); system($RT_CMD, "edit", $ticket, 'set', 'CF.{completed-internship}=unsuccessful');
if ($PAYMENT_NUMBER == 1) { if ($PAYMENT_NUMBER == 1) {
@ -365,30 +489,22 @@ LEDGER_ENTRY
} else { } else {
system($RT_CMD, "edit", $ticket, 'set', 'Status=entered'); system($RT_CMD, "edit", $ticket, 'set', 'Status=entered');
} }
open(my $delTravelDependsFH, "-|", $RT_CMD, "link", '-d', my $travelTicketSpec = FindTravelTicketFromList(@{$links{Members}});
$reimbursementTicket, 'dependson', $TRAVEL_NOTICE_TICKET); my $travelTicketNum = $travelTicketSpec;
my $found; my $found = TravelTicketDeLink($TRAVEL_NOTICE_TICKET, $travelTicketNum);
while (my $line = <$delTravelDependsFH>) {
if ($line =~ /Link\s+not\s+found/i) {
$found = 0;
} elsif ($line =~ /no\s+longer\s+depends\s+on\s+Ticket/i) {
$found = 1;
}
last if defined $found;
}
close $delTravelDependsFH;
if (not defined $found) { if (not defined $found) {
print STDERR "\"$file\": \"$ticket\": WARNING: unable to determin what to do about Travel ticket, $TRAVEL_NOTICE_TICKET... "; print STDERR "\"$entry\": \"$ticket\": WARNING: unable to determine what to do about Travel ticket, $travelTicketNum, as it is not linked to $TRAVEL_NOTICE_TICKET... ";
} else { } elsif (not $found) {
# This means we already activiated this travel ticket, so we have to explain to the intern # This means we already activiated this travel ticket, so we have to explain to the intern
open(my $travelTicketCorrespondFH, "|-", $RT_CMD, 'correspond', $reimbursementTicket, '-m', '-'); open(my $travelTicketCorrespondFH, "|-", $RT_CMD, 'correspond', $travelTicketNum, '-m', '-');
print $rtCorrespondFH "Previously, you received notice about your travel stipend. Please be advised that due to your failure in your internship, you no longer have a travel stipend budget.\n\n"; print $rtCorrespondFH "Previously, you received notice about your travel stipend. Please be advised that due to your failure in your internship, you no longer have a travel stipend budget.\n\n";
print $rtCorrespondFH @dd;
close $rtCorrespondFH; close $rtCorrespondFH;
} }
system($RT_CMD, "edit", $reimbursementTicket, 'set', 'Status=open'); system($RT_CMD, "edit", $reimbursementTicket, 'set', 'Status=open');
system($RT_CMD, "edit", $reimbursementTicket, 'set', 'Status=rejected'); system($RT_CMD, "edit", $reimbursementTicket, 'set', 'Status=rejected');
system($RT_CMD, "edit", $travelTicketNum, 'set', 'Status=rejected');
} }
NEXT_TICKET:
print STDERR "...done\n"; print STDERR "...done\n";
print STDERR "Waiting? "; print STDERR "Waiting? ";
my $x = <STDIN>; my $x = <STDIN>;