Added income/expense summing.
This commit is contained in:
parent
8ac2e9d3c6
commit
7279413a22
1 changed files with 26 additions and 3 deletions
|
@ -59,7 +59,7 @@ while (my $fundLine = <LEDGER_FUNDS>) {
|
||||||
unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
||||||
my($account, $amount) = ($1, $2);
|
my($account, $amount) = ($1, $2);
|
||||||
$amount = ParseNumber($amount);
|
$amount = ParseNumber($amount);
|
||||||
$account =~ s/^\s+Funds:Restricted://; $account =~ s/\s+$//;
|
$account =~ s/^\s*Funds:Restricted://; $account =~ s/\s+$//;
|
||||||
$funds{$account}{ending} = $amount;
|
$funds{$account}{ending} = $amount;
|
||||||
}
|
}
|
||||||
close LEDGER_FUNDS;
|
close LEDGER_FUNDS;
|
||||||
|
@ -77,21 +77,44 @@ while (my $fundLine = <LEDGER_FUNDS>) {
|
||||||
unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
unless $fundLine =~ /^\s*([^\$]+)\s+\$\s*\s*([\d\.\,]+)/;
|
||||||
my($account, $amount) = ($1, $2);
|
my($account, $amount) = ($1, $2);
|
||||||
$amount = ParseNumber($amount);
|
$amount = ParseNumber($amount);
|
||||||
$account =~ s/^\s+Funds:Restricted://; $account =~ s/\s+$//;
|
$account =~ s/^\s*Funds:Restricted://; $account =~ s/\s+$//;
|
||||||
$funds{$account}{starting} = $amount;
|
$funds{$account}{starting} = $amount;
|
||||||
}
|
}
|
||||||
close LEDGER_FUNDS;
|
close LEDGER_FUNDS;
|
||||||
|
|
||||||
|
|
||||||
foreach my $fund (keys %funds) {
|
foreach my $fund (keys %funds) {
|
||||||
$funds{$fund}{starting} = $ZERO if not defined $funds{$fund}{starting};
|
$funds{$fund}{starting} = $ZERO if not defined $funds{$fund}{starting};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ledgerOptions = (@mainLedgerOptions,
|
||||||
|
'--wide-register-format', "%-.70A %22.108t\n", '-w', '-s',
|
||||||
|
'-b', $startDate, '-e', $endDate, 'reg');
|
||||||
|
|
||||||
|
foreach my $type ('Income', 'Expenses') {
|
||||||
|
foreach my $fund (keys %funds) {
|
||||||
|
open(LEDGER_INCOME, "-|", $LEDGER_CMD, @ledgerOptions, "^${type}:$fund")
|
||||||
|
or die "Unable to run $LEDGER_CMD for funds: $!";
|
||||||
|
$funds{$fund}{$type} = $ZERO;
|
||||||
|
while (my $line = <LEDGER_INCOME>) {
|
||||||
|
die "Unable to parse output line from $type line command: $line"
|
||||||
|
unless $line =~ /^\s*([^\$]+)\s+\$\s*\s*([\-\d\.\,]+)/;
|
||||||
|
my($account, $amount) = ($1, $2);
|
||||||
|
$amount = ParseNumber($amount);
|
||||||
|
$funds{$fund}{$type} += $amount;
|
||||||
|
}
|
||||||
|
close LEDGER_INCOME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $format = "%-${ACCT_WIDTH}.${ACCT_WIDTH}s \$%11.2f \$%11.2f\n";
|
my $format = "%-${ACCT_WIDTH}.${ACCT_WIDTH}s \$%11.2f \$%11.2f\n";
|
||||||
my($totDeb, $totCred) = ($ZERO, $ZERO);
|
my($totDeb, $totCred) = ($ZERO, $ZERO);
|
||||||
|
|
||||||
foreach my $fund (sort keys %funds) {
|
foreach my $fund (sort keys %funds) {
|
||||||
print "Fund: $fund\n";
|
print "Fund: $fund\n";
|
||||||
print " Balance as of $startDate: ", sprintf("\$%11.2f\n", $funds{$fund}{starting});
|
print " Balance as of $startDate: ", sprintf("\$%11.2f\n\n", $funds{$fund}{starting});
|
||||||
|
print " Income during period: ", sprintf("\$%11.2f\n", $funds{$fund}{Income});
|
||||||
|
print " Expenses during period: ", sprintf("\$%11.2f\n", $funds{$fund}{Expenses});
|
||||||
print " Balance as of $endDate: ", sprintf("\$%11.2f\n", $funds{$fund}{ending});
|
print " Balance as of $endDate: ", sprintf("\$%11.2f\n", $funds{$fund}{ending});
|
||||||
print "\n\n";
|
print "\n\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue