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:
@@ -838,6 +838,17 @@ CREATE TABLE `pmgr_accounts` (
|
||||
'INCOME',
|
||||
'EXPENSE')
|
||||
NOT NULL DEFAULT 'ASSET',
|
||||
|
||||
-- Accounts Receivable / Accounts Payable
|
||||
-- If this is a trackable account, any credit posted
|
||||
-- to an ASSET OR EXPENSE account should have an
|
||||
-- entry posted to the reconciliations table (unless
|
||||
-- it is a "pre-payment" of sorts, in which case the
|
||||
-- reconciliation will have to wait for the debit).
|
||||
-- For LIABILITY, EQUITY, and INCOME, the opposite
|
||||
-- is true, with reconciliations posted, under
|
||||
-- normal circumstances, when a debit occurs.
|
||||
`trackable` INT UNSIGNED DEFAULT 0,
|
||||
|
||||
-- Security Level
|
||||
`level` INT UNSIGNED DEFAULT 1,
|
||||
@@ -852,17 +863,17 @@ CREATE TABLE `pmgr_accounts` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
LOCK TABLES `pmgr_accounts` WRITE;
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`)
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `trackable`)
|
||||
VALUES
|
||||
('ASSET', 'A/R'),
|
||||
('LIABILITY', 'A/P'),
|
||||
('LIABILITY', 'Tax'),
|
||||
('LIABILITY', 'Customer Credit'),
|
||||
('ASSET', 'Bank'),
|
||||
('ASSET', 'Cash'),
|
||||
('LIABILITY', 'Security Deposit'),
|
||||
('INCOME', 'Rent'),
|
||||
('INCOME', 'Late Charge');
|
||||
('ASSET', 'A/R', 1),
|
||||
('LIABILITY', 'A/P', 1),
|
||||
('LIABILITY', 'Tax', 0),
|
||||
('LIABILITY', 'Customer Credit', 1),
|
||||
('ASSET', 'Bank', 0),
|
||||
('ASSET', 'Cash', 0),
|
||||
('LIABILITY', 'Security Deposit', 1),
|
||||
('INCOME', 'Rent', 0),
|
||||
('INCOME', 'Late Charge', 0);
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
||||
@@ -901,9 +912,8 @@ CREATE TABLE `pmgr_ledgers` (
|
||||
-- to add several parameters indicating the period
|
||||
-- this particular ledger is valid and so on.
|
||||
|
||||
`name` VARCHAR(80) DEFAULT NULL,
|
||||
`sequence` INT(10) UNSIGNED DEFAULT 1,
|
||||
`account_id` INT(10) UNSIGNED NOT NULL,
|
||||
`sequence` INT(10) UNSIGNED DEFAULT 1,
|
||||
`closed` INT UNSIGNED DEFAULT 0,
|
||||
|
||||
-- REVISIT <AP>: 20090607
|
||||
@@ -965,6 +975,22 @@ CREATE TABLE `pmgr_ledger_entries` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_reconciliations
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_reconciliations`;
|
||||
CREATE TABLE `pmgr_reconciliations` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
|
||||
`debit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
|
||||
`credit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
|
||||
`amount` FLOAT(12,2) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_monetary_sources
|
||||
|
||||
@@ -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'},
|
||||
|
||||
Reference in New Issue
Block a user