Should have checked this as part of the last commit (r152), since it is the DB schema changes necessary to support the reconciliation work. Also, the sitelink script was modified to match.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@153 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-16 21:47:57 +00:00
parent fae90c3fa9
commit 9331b0a412
2 changed files with 107 additions and 31 deletions

View File

@@ -433,8 +433,7 @@ $result = query($db_handle, $query);
foreach $row (@$result) {
addRow('ledgers',
{ 'account_id' => $row->{'id'},
'open_stamp' => '2009-01-01',
'name' => $row->{'name'} . ' Ledger',
'open_stamp' => '2009-01-01',
'comment' => undef });
$newdb{'lookup'}{'account'}{$row->{'name'}}
@@ -660,15 +659,14 @@ foreach $row (@{query($sdbh, $query)}) {
# Every customer gets their own account
addRow('accounts',
{ 'type' => 'ASSET',
'name' => ('Account: Customer #' . ($newdb{'tables'}{'customers'}{'autoid'}+1) .
'trackable' => 1,
'name' => ('Customer #' . ($newdb{'tables'}{'customers'}{'autoid'}+1) .
' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')'),
'comment' => undef });
#'comment' => 'For direct customer transaction, NOT lease charges!' });
addRow('ledgers',
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
'open_stamp' => '2009-01-01',
'name' => 'Ledger: Customer #' . ($newdb{'tables'}{'customers'}{'autoid'}+1)
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')',
'comment' => undef });
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account'} =
@@ -799,15 +797,14 @@ foreach $row (@{query($sdbh, $query)}) {
# Every lease gets its own account
addRow('accounts',
{ 'type' => 'ASSET',
'name' => ('Account: Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
'trackable' => 1,
'name' => ('Lease #' . $row->{'LedgerID'}
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')'),
'comment' => undef });
#'comment' => 'For lease related transaction, NOT personal charges!' });
addRow('ledgers',
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
'open_stamp' => datefmt($row->{'DateIn'}),
'name' => 'Ledger: Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')',
'comment' => undef });
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
@@ -857,7 +854,10 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
= { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
'ledger' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger'} };
'ledger' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger'},
'amount' => $row->{'ChargeAmount'},
'tax_amount' => $row->{'TaxAmount'},
};
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
@@ -867,6 +867,9 @@ foreach $row (@{query($sdbh, $query)}) {
'amount' => $row->{'ChargeAmount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'},
next unless $row->{'TaxAmount'};
addRow('ledger_entries',
@@ -876,6 +879,10 @@ foreach $row (@{query($sdbh, $query)}) {
'credit_ledger_id' => $newdb{'lookup'}{'charge_type'}{'Tax'}{'ledger'},
'amount' => $row->{'TaxAmount'},
'comment' => undef });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_entry'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'},
}
@@ -950,18 +957,29 @@ foreach $row (@{query($sdbh, $query)})
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger'},
'amount' => $row->{'PaymentAmount'},
'comment' => "Receipt: $row->{'ReceiptNum'}; Payment: $row->{'PaymentID'}; Charge: $row->{'ChargeID'}" });
# Map this to the Charge ??
# $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'id'}
# $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'id'}
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
= { 'entry' => $newdb{'tables'}{'ledger_entries'}{'autoid'} };
# Reconcile Payment to the Charge. Since tracking is due to
# the A/R account (Lease Account in this case), credit/debit
# is from the perspective of that account. Namely, the charge
# was the debit to the A/R, and the payment was the credit.
my $reconcile_amount = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'};
$reconcile_amount = $row->{'PaymentAmount'} if $row->{'PaymentAmount'} <= $reconcile_amount;
addRow('reconciliations',
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'},
'credit_ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'entry'},
'amount' => $reconcile_amount,
});
# Update the transaction to use the memo from this payment
if ($row->{'Memo'}) {
my $txid = $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'};
$newdb{'tables'}{'transactions'}{'rows'}[$txid]{'comment'} = $row->{'Memo'};
}
}
@@ -999,12 +1017,16 @@ my %fake =
'receipt' => [ { 'id' => 2000,
'date' => '2009-05-15',
'entry' => [ { 'id' => 2200,
'track' => [ { 'debit'=>2100, 'amount'=>10 },
{ 'debit'=>2110, 'amount'=>5 } ],
'type' => 1,
'amount' => 15 },
{ 'id' => 2201,
'track' => [ { 'debit'=>2110, 'amount'=>10 } ],
'type' => 2,
'amount' => 10 },
{ 'id' => 2202,
'track' => [ { 'debit'=>2110, 'amount'=>5 } ],
'type' => 3,
'amount' => 5 },
],
@@ -1012,9 +1034,11 @@ my %fake =
{ 'id' => 2001,
'date' => '2009-05-18',
'entry' => [ { 'id' => 2210,
'track' => [ { 'debit'=>2110, 'amount'=>30 } ],
'type' => 5,
'amount' => 30 },
{ 'id' => 2211,
'track' => [ { 'debit'=>2110, 'amount'=>20 } ],
'type' => 6,
'amount' => 20 },
],
@@ -1022,17 +1046,23 @@ my %fake =
{ 'id' => 2002,
'date' => '2009-05-22',
'entry' => [ { 'id' => 2220,
'track' => [ { 'debit'=>2110, 'amount'=>10 } ],
'type' => 1,
'amount' => 10 },
{ 'id' => 2221,
'track' => [ { 'debit'=>2110, 'amount'=>5 } ],
'type' => 2,
'amount' => 5 },
{ 'id' => 2222,
'track' => [ { 'debit'=>2110, 'amount'=>15 },
{ 'debit'=>2111, 'amount'=>5 },
{ 'debit'=>2120, 'amount'=>5 } ],
'type' => 7,
'amount' => 20 },
'amount' => 25 },
{ 'id' => 2223,
'track' => [ { 'debit'=>2120, 'amount'=>20 } ],
'type' => 8,
'amount' => 15 },
'amount' => 30 },
],
},
],
@@ -1047,8 +1077,7 @@ addRow('ledgers',
{ 'account_id' => $newdb{'lookup'}{'account'}{'Cash'}{'account'},
'open_stamp' => 'NOW()',
'sequence' => 2,
'name' => 'Fake Cash Ledger',
'comment' => 'Fake ledger for testing' });
'comment' => 'Opened new ledger for testing' });
$newdb{'lookup'}{'account'}{'Cash'}{'ledger'} =
$newdb{'tables'}{'ledgers'}{'autoid'};
@@ -1073,6 +1102,7 @@ addRow('ledger_entries',
'amount' => $balance,
'name' => "Close Out ($newdb{'ids'}{'ledger'}{'Cash-Old'} -> $newdb{'tables'}{'transactions'}{'autoid'})",
'comment' => "Carrying forward old ledger balance onto new ledger" });
# NOTE: no tracking for the Cash account
$newdb{'tables'}{'ledgers'}{'rows'}[$newdb{'ids'}{'ledger'}{'Cash-Old'}]{'closed'} = 1;
$newdb{'tables'}{'ledgers'}{'rows'}[$newdb{'ids'}{'ledger'}{'Cash-Old'}]{'close_stamp'} = 'NOW()';
@@ -1091,10 +1121,22 @@ foreach my $ir ('invoice', 'receipt') {
foreach my $e (@{$tx->{'entry'}}) {
my $dr = ($ir eq 'invoice') ? 'A/R' : 'Cash';
my $cr = ($ir eq 'invoice') ? $e->{'account'} : 'A/R';
my $monetary_source_id;
if (defined $e->{'type'}) {
addRow('monetary_sources',
{ 'monetary_type_id' => $e->{'type'},
'name' => "Money of type " . $e->{'type'},
'comment' => "Fake Money For " . $e->{'id'} });
$monetary_source_id = $newdb{'tables'}{'monetary_sources'}{'autoid'};
}
else {
$monetary_source_id = $newdb{'ids'}{'monetary_source'}{'internal'};
}
addRow('ledger_entries',
{ 'id' => $e->{'id'},
'monetary_source_id' => $e->{'type'} || $newdb{'ids'}{'monetary_source'}{'internal'},
'monetary_source_id' => $monetary_source_id,
'transaction_id' => $tx->{'id'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{$dr}{'ledger'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{$cr}{'ledger'},
@@ -1102,11 +1144,19 @@ foreach my $ir ('invoice', 'receipt') {
'comment' => "Fake $ir entry" },
1);
foreach my $t (@{$e->{'track'}}) {
addRow('reconciliations',
{ 'debit_ledger_entry_id' => $t->{'debit'},
'credit_ledger_entry_id' => $e->{'id'},
'amount' => $t->{'amount'}
});
}
next unless $e->{'tax'};
addRow('ledger_entries',
{ 'id' => $e->{'id'}+1,
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'monetary_source_id' => $monetary_source_id,
'transaction_id' => $tx->{'id'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{$dr}{'ledger'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Tax'}{'ledger'},