Various changes to support Payment 1

My initial drafting of this script could not support Payment 1 properly, as I
started the script after Payment 1 in 2018-05 round was already done.

These changes, while not yet fully tested, probably should work to handle
Payment 1 tickets.
This commit is contained in:
Bradley M. Kuhn 2019-01-14 09:26:21 -08:00
parent 950d3d374f
commit bf631e8259

View file

@ -15,7 +15,8 @@ our $RT_CMD;
require 'rt-helper.pl';
my($PAYMENT_DIR, $VERBOSE, $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);
###############################################################################
sub LedgerTagFromTicket($$) {
@ -74,13 +75,13 @@ GetOptions("paymentDir=s" => \$PAYMENT_DIR, "verbose=i" => \$VERBOSE, "interacti
"invoiceLine=s" => \$INVOICE_LINE, "internSuccessFile=s", \$INTERN_SUCCESS_FILE,
"internFailFile=s", \$INTERN_FAIL_FILE, 'ledgerEntryDate=s' => \$LEDGER_ENTRY_DATE,
"svnCommand=s" => \$SVN_CMD, "round=s" => \$ROUND,
'overrideApprovalTag=s' => \$OVERRIDE_APPROVAL_TAG,
'travelNoticeTicket=i' => \$TRAVEL_NOTICE_TICKET);
$RT_CMD = '/usr/bin/rt' unless defined $RT_CMD;
$SVN_CMD = '/usr/bin/svn' unless defined $SVN_CMD;
$INTERACTIVE = 0 if not defined $INTERACTIVE;
unless (defined $TRAVEL_NOTICE_TICKET) {
print STDERR "usage: $0 --travelNoticeTicket=<TICKET_NUMBER> option is required and must be an integer\n";
exit 1;
@ -123,6 +124,10 @@ 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";
exit 1;
}
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";
exit 1;
}
$VERBOSE = 0 unless defined $VERBOSE;
opendir(my $dh, $PAYMENT_DIR);
@ -146,10 +151,13 @@ while (my $file = readdir $dh) {
}
}
if (not defined $mentorDate) {
print STDERR "\"$file\": Skipping: Inside that file there is no valid Date: header" ;
next;
if ($PAYMENT_NUMBER == 1) {
$mentorDate = $LEDGER_ENTRY_DATE;
} else {
print STDERR "\"$file\": Skipping: Inside that file there is no valid Date: header" ;
next;
}
}
my(@nameComponents) = split(/\s*-\s*/, $name);
my(@searchTerms);
foreach my $name (@nameComponents) {
@ -188,8 +196,8 @@ while (my $file = readdir $dh) {
next;
}
if ($PAYMENT_NUMBER <= 1) {
print STDERR "Sorry, script does not yet support first payment\n";
if ($PAYMENT_NUMBER < 1 or $PAYMENT_NUMBER > 3) {
print STDERR "Payment number should be between 1 and 3\n";
exit 1;
}
# Check to see if this payment was already made
@ -207,29 +215,30 @@ while (my $file = readdir $dh) {
# Check to see if previous payment was sent payment
my $prevPayNum = $PAYMENT_NUMBER - 1;
my $lastPayDate = PaymentDateByTicket($ticket, $prevPayNum);
if (not defined $lastPayDate) {
print STDERR "\"$file\": \"$ticket\": Skipped: payment $prevPayNum was not made yet";
if ($pass) {
print STDERR ".\n";
} else {
print STDERR "... NOTE: previous payment was not sent; should it be sent now?\n";
if ($prevPayNum > 0) {
my $lastPayDate = PaymentDateByTicket($ticket, $prevPayNum);
if (not defined $lastPayDate) {
print STDERR "\"$file\": \"$ticket\": Skipped: payment $prevPayNum was not made yet";
if ($pass) {
print STDERR ".\n";
} else {
print STDERR "... NOTE: previous payment was not sent; should it be sent now?\n";
}
next;
}
next;
}
my $expectVal = 'payment-' . $PAYMENT_NUMBER . "-approved";
if ($completedInternshipField eq $expectVal) {
if ($completedInternshipField eq $expectVal and $PAYMENT_NUMBER != 1) {
print STDERR "\"$file\": \"$ticket\": $PAYMENT_NUMBER PAYMENT-DONE: Skipped: completed-internship is ",
"\"$completedInternshipField\" which indicates this payment round is in process.\n";
next;
}
$expectVal = 'payment-' . $prevPayNum . "-approved";
if ($completedInternshipField ne $expectVal) {
$expectVal = 'payment-' . $prevPayNum . "-approved" if $PAYMENT_NUMBER != 1;
if ($prevPayNum > 0 and $completedInternshipField ne $expectVal) {
print STDERR "\"$file\": \"$ticket\": Skipped: completed-internship field was ",
"\"$completedInternshipField\" instead of \"$expectVal\".\n";
next;
}
my(%links) = GetLinksForTicket($ticket);
if ($VERBOSE > 5) {
use Data::Dumper;
@ -276,11 +285,15 @@ while (my $file = readdir $dh) {
my $successString = ($pass) ? "success" : "failed";
my $repositoryFile = File::Spec->catfile($PAYMENT_DIR, $mentorDate . "_" . $entity . '_' . $successString . '-report.mbox');
my $approvalTag = $repositoryFile;
$approvalTag =~ s%^.*(Projects/Outreachy/.*)$%$1%;
$approvalTag = " ;Approval: $approvalTag";
rename(File::Spec->catfile($PAYMENT_DIR, $file), $repositoryFile);
system($SVN_CMD, "add", $repositoryFile);
if ($PAYMENT_NUMBER == 1) {
$approvalTag = " ;Approval: $OVERRIDE_APPROVAL_TAG";
unlink(File::Spec->catfile($PAYMENT_DIR, $file));
} else {
$approvalTag =~ s%^.*(Projects/Outreachy/.*)$%$1%;
$approvalTag = " ;Approval: $approvalTag";
rename(File::Spec->catfile($PAYMENT_DIR, $file), $repositoryFile);
system($SVN_CMD, "add", $repositoryFile);
}
open(my $rtCorrespondFH, "|-", $RT_CMD, 'correspond', $ticket, '-m', '-');
my @dd;
foreach my $line (@{$internCorrespond{$successString}}) {
@ -304,7 +317,7 @@ while (my $file = readdir $dh) {
'Status=open');
my($leftA, $rightA);
if ($PAYMENT_NUMBER == 1) {
$leftA = ' $-500.00'; $rightA = ' $500.00';
$leftA = ' $-1,000.00'; $rightA = ' $1,000.00';
} elsif ($PAYMENT_NUMBER == 2) {
$leftA = '$-2,250.00'; $rightA = '$2,250.00';
} elsif ($PAYMENT_NUMBER == 3) {
@ -317,22 +330,33 @@ while (my $file = readdir $dh) {
$contractName =~ s/^\s*//; $contractName =~ s/\s*$//;
open(my $paymentValsFH, ">", File::Spec->catfile($PAYMENT_DIR, "payment-values.txt"));
print "OUTREACHY INTERNSHIP PAYMENT $PAYMENT_NUMBER ";
foreach my $key (keys %paymentVals) {
print $paymentValsFH "$key:$paymentVals{$key}\n";
print $paymentValsFH sprintf(" %20s", $key), "$paymentVals{$key}\n";
}
close $paymentValsFH;
print $paymentValsFH sprintf(" %20s", 'TOTAL AMOUNT'), "$rightA\n\n LEDGER ENTRY:\n\n";
open(my $ledgerEntryFH, ">>", File::Spec->catfile($PAYMENT_DIR, "entry.ledger"));
print $ledgerEntryFH <<LEDGER_ENTRY
my $ledgerEntryFile = File::Spec->catfile($PAYMENT_DIR, "entry.ledger")
open(my $ledgerEntryFH, ">>", $ledgerEntryFile);
my $ledgerEntryStr = <<LEDGER_ENTRY
$LEDGER_ENTRY_DATE $contractName - Outreachy Internship - Round 2018-05 - Payment $PAYMENT_NUMBER
$LEDGER_ENTRY_DATE $contractName - Outreachy Internship - Round 2018-12 - Payment $PAYMENT_NUMBER
@tags ;Invoice: $INVOICE_LINE
$approvalTag
Accrued:Accounts Payable:Outreachy $leftA
Expenses:Outreachy:Internships $rightA
LEDGER_ENTRY
;
close $ledgerEntryFH;
print $ledgerEntryFH $ledgerEntryStr;
close $ledgerEntryFH ;
open(my $ledgerTagConvertFH, "|-", File::Spec->catfile($ENV{CONSERVANCY_REPOSITORY},
'Financial', 'Code', 'ledger-tag-convert.plx') .
'<' . $ledgerEntryFile);
foreach my $line (<$ledgerTagConvertFH>) {
print $paymentValsFH $line;
}
close $ledgerTagConvertFH;
close $paymentValsFH;
} else {
system($RT_CMD, "edit", $ticket, 'set', 'CF.{completed-internship}=unsuccessful');
if ($PAYMENT_NUMBER == 1) {