Add balances for permanent (i.e., asset) accounts.
Based on a request from our accountants, I've changed the RUNNING TOTAL field (which is generally useless to accountants anyway) to be a BALANCE amount for starting and ending accounts.
This commit is contained in:
parent
2b237aa3ba
commit
4290a4ec52
1 changed files with 41 additions and 3 deletions
|
|
@ -127,6 +127,34 @@ foreach my $acct ( sort preferredAccountSorting @accounts) {
|
|||
}
|
||||
close(CHART_OUTPUT); die "error writing to chart-of-accounts.txt: $!" unless $? == 0;
|
||||
|
||||
my %commands = (
|
||||
'totalEnd' => [ $LEDGER_CMD, @otherLedgerOpts, '-V', '-X', '$',
|
||||
'-e', $endDate, '-F', '%-.80A %22.108t\n', '-s',
|
||||
'reg' ],
|
||||
'totalBegin' => [ $LEDGER_CMD, @otherLedgerOpts, '-V', '-X', '$',
|
||||
'-e', $beginDate, '-F', '%-.80A %22.108t\n',
|
||||
'-s', 'reg' ]);
|
||||
|
||||
my %balanceData;
|
||||
|
||||
foreach my $id (keys %commands) {
|
||||
my(@command) = @{$commands{$id}};
|
||||
|
||||
open(FILE, "-|", @command) or die "unable to run command ledger command: @command: $!";
|
||||
|
||||
foreach my $line (<FILE>) {
|
||||
die "Unable to parse output line from balance data $id command: $line"
|
||||
unless $line =~ /^\s*([^\$]+)\s+\$\s*([\-\d\.\,]+)/;
|
||||
my($account, $amount) = ($1, $2);
|
||||
$amount = ParseNumber($amount);
|
||||
$account =~ s/\s+$//;
|
||||
next if $account =~ /\<Adjustment\>/ and (abs($amount) <= 0.02);
|
||||
next if $account =~ /^Equity:/; # Stupid auto-account made by ledger.
|
||||
$balanceData{$id}{$account} = $amount;
|
||||
}
|
||||
close FILE;
|
||||
die "unable to run balance data ledger command, @command: $!" unless ($? == 0);
|
||||
}
|
||||
|
||||
open(GL_TEXT_OUT, ">", "general-ledger.txt") or die "unable to write general-ledger.txt: $!";
|
||||
print MANIFEST "general-ledger.txt\n";
|
||||
|
|
@ -147,15 +175,20 @@ foreach my $acct (@sortedAccounts) {
|
|||
}
|
||||
close(GL_TEXT_DATA); die "error reading ledger output for chart of accounts: $!" unless $? == 0;
|
||||
|
||||
print GL_CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$beginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n";
|
||||
print GL_CSV_OUT '"DATE","CHECK NUM","NAME","TRANSACTION AMT","RUNNING TOTAL"';
|
||||
my $formatString = '"%(date)","%C","%P","%t","%T"';
|
||||
print GL_CSV_OUT "\n\"ACCOUNT:\",\"$acct\"\n\"PERIOD START:\",\"$formattedBeginDate\"\n\"PERIOD END:\",\"$formattedEndDate\"\n";
|
||||
print GL_CSV_OUT '"DATE","CHECK NUM","NAME","TRANSACTION AMT","BALANCE"';
|
||||
|
||||
my $formatString = '"%(date)","%C","%P","%t",""';
|
||||
foreach my $tagField (qw/Receipt Invoice Statement Contract PurchaseOrder Approval Check IncomeDistributionAnalysis CurrencyRate/) {
|
||||
print GL_CSV_OUT ',"', $tagField, '"';
|
||||
$formatString .= ',"%(tag(\'' . $tagField . '\'))"';
|
||||
}
|
||||
$formatString .= "\n";
|
||||
print GL_CSV_OUT "\n";
|
||||
if ($acct =~ /^(Assets|Liabilities|Accrued|Unearned Income)/) {
|
||||
$balanceData{totalBegin}{$acct} = $ZERO unless defined $balanceData{totalBegin}{$acct};
|
||||
print GL_CSV_OUT "\"$formattedBeginDate\"", ',"","BALANCE","","$', "$balanceData{totalBegin}{$acct}\"\n";
|
||||
}
|
||||
|
||||
@acctLedgerOpts = ('-V', '-F', $formatString, '-w', '--sort', 'd', '-b', $beginDate, '-e', $endDate, @otherLedgerOpts, 'reg', $acct);
|
||||
open(GL_CSV_DATA, "-|", $LEDGER_CMD, @acctLedgerOpts)
|
||||
|
|
@ -173,6 +206,11 @@ foreach my $acct (@sortedAccounts) {
|
|||
$manifest{$file} = $line;
|
||||
}
|
||||
}
|
||||
if ($acct =~ /^(Assets|Liabilities|Accrued|Unearned Income)/) {
|
||||
$balanceData{totalEnd}{$acct} = $ZERO unless defined $balanceData{totalEnd}{$acct};
|
||||
print GL_CSV_OUT "\"$formattedEndDate\"", ',"","BALANCE","","$', "$balanceData{totalEnd}{$acct}\"\n";
|
||||
}
|
||||
|
||||
close(GL_CSV_DATA); die "error reading ledger output for chart of accounts: $!" unless $? == 0;
|
||||
}
|
||||
close(GL_TEXT_OUT); die "error writing to general-ledger.txt: $!" unless $? == 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue