Experiment to allow payments to trace back to the charge, even if the amount crosses several ledgers. I'd really like to go a different direction.

git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@179 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-22 23:42:13 +00:00
parent bd0bbd768d
commit b9c1a81c3b
2 changed files with 64 additions and 15 deletions

View File

@@ -870,10 +870,11 @@ INSERT INTO `pmgr_accounts` (`type`, `name`, `trackable`)
('LIABILITY', 'Tax', 0), ('LIABILITY', 'Tax', 0),
('LIABILITY', 'Customer Credit', 1), ('LIABILITY', 'Customer Credit', 1),
('ASSET', 'Bank', 0), ('ASSET', 'Bank', 0),
('ASSET', 'Cash', 0), ('ASSET', 'Payment', 0),
('LIABILITY', 'Security Deposit', 1), ('LIABILITY', 'Security Deposit', 1),
('INCOME', 'Rent', 0), ('INCOME', 'Rent', 0),
('INCOME', 'Late Charge', 0); ('INCOME', 'Late Charge', 0),
('EXPENSE', 'Concession', 0);
UNLOCK TABLES; UNLOCK TABLES;
@@ -983,8 +984,9 @@ DROP TABLE IF EXISTS `pmgr_reconciliations`;
CREATE TABLE `pmgr_reconciliations` ( CREATE TABLE `pmgr_reconciliations` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`debit_ledger_entry_id` INT(10) UNSIGNED NOT NULL, `debit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
`credit_ledger_entry_id` INT(10) UNSIGNED NOT NULL, `credit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
`terminal_ledger_entry_id` INT(10) UNSIGNED DEFAULT NULL,
`amount` FLOAT(12,2) NOT NULL, `amount` FLOAT(12,2) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)

View File

@@ -438,6 +438,7 @@ foreach $row (@$result) {
$newdb{'lookup'}{'account'}{$row->{'name'}} $newdb{'lookup'}{'account'}{$row->{'name'}}
= {'account' => $row->{'id'}, = {'account' => $row->{'id'},
'tillable' => $row->{'tillable'},
'ledger' => $newdb{'tables'}{'ledgers'}{'autoid'} }; 'ledger' => $newdb{'tables'}{'ledgers'}{'autoid'} };
if ((!defined $newdb{'tables'}{'accounts'}{'autoid'}) || if ((!defined $newdb{'tables'}{'accounts'}{'autoid'}) ||
@@ -446,6 +447,10 @@ foreach $row (@$result) {
} }
} }
# For compatibility, while deciding on account names
$newdb{'lookup'}{'account'}{'Cash'}
= $newdb{'lookup'}{'account'}{'Payment'};
$newdb{'lookup'}{'charge_type'} = {}; $newdb{'lookup'}{'charge_type'} = {};
$newdb{'lookup'}{'charge_type'}{'Rent'} = $newdb{'lookup'}{'charge_type'}{'Rent'} =
$newdb{'lookup'}{'account'}{'Rent'}; $newdb{'lookup'}{'account'}{'Rent'};
@@ -469,15 +474,15 @@ foreach $row (@$result) {
$newdb{'lookup'}{'payment_type'} = {}; $newdb{'lookup'}{'payment_type'} = {};
$newdb{'lookup'}{'payment_type'}{1} $newdb{'lookup'}{'payment_type'}{1}
= { 'name' => 'Cash', 'id' => $newdb{'lookup'}{'monetary_type'}{'Cash'}{'id'} }; = { 'name' => 'Cash', 'account' => 'Cash', 'monetary_type' => $newdb{'lookup'}{'monetary_type'}{'Cash'} };
$newdb{'lookup'}{'payment_type'}{2} $newdb{'lookup'}{'payment_type'}{2}
= { 'name' => 'Check', 'id' => $newdb{'lookup'}{'monetary_type'}{'Check'}{'id'} }; = { 'name' => 'Check', 'account' => 'Cash', 'monetary_type' => $newdb{'lookup'}{'monetary_type'}{'Check'} };
$newdb{'lookup'}{'payment_type'}{3} $newdb{'lookup'}{'payment_type'}{3}
= { 'name' => 'Money Order', 'id' => $newdb{'lookup'}{'monetary_type'}{'Money Order'}{'id'} }; = { 'name' => 'Money Order', 'account' => 'Cash', 'monetary_type' => $newdb{'lookup'}{'monetary_type'}{'Money Order'} };
$newdb{'lookup'}{'payment_type'}{4} $newdb{'lookup'}{'payment_type'}{4}
= { 'name' => 'ACH', 'id' => $newdb{'lookup'}{'monetary_type'}{'ACH'}{'id'} }; = { 'name' => 'ACH', 'account' => 'Bank', 'monetary_type' => $newdb{'lookup'}{'monetary_type'}{'ACH'} };
$newdb{'lookup'}{'payment_type'}{12} $newdb{'lookup'}{'payment_type'}{12}
= { 'name' => 'Transfer', 'id' => $newdb{'lookup'}{'monetary_type'}{'Other Non-Tillable'}{'id'} }; = { 'name' => 'Concession', 'account' => 'Concession', 'monetary_type' => $newdb{'lookup'}{'monetary_type'}{'Other Non-Tillable'} };
$newdb{'ids'}{'monetary_source'} = {}; $newdb{'ids'}{'monetary_source'} = {};
@@ -794,6 +799,10 @@ $newdb{'lookup'}{'ledger'} = {};
$query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' ORDER BY L.LedgerID"; $query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' ORDER BY L.LedgerID";
foreach $row (@{query($sdbh, $query)}) { foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
= { 'cust' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'cust'} };
if (1) {
# Every lease gets its own account # Every lease gets its own account
addRow('accounts', addRow('accounts',
{ 'type' => 'ASSET', { 'type' => 'ASSET',
@@ -807,10 +816,22 @@ foreach $row (@{query($sdbh, $query)}) {
'open_stamp' => datefmt($row->{'DateIn'}), 'open_stamp' => datefmt($row->{'DateIn'}),
'comment' => undef }); 'comment' => undef });
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}} $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'account'}
= { 'cust' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'cust'}, = $newdb{'tables'}{'accounts'}{'autoid'};
'account' => $newdb{'tables'}{'accounts'}{'autoid'}, $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger'}
'ledger' => $newdb{'tables'}{'ledgers'}{'autoid'} }; = $newdb{'tables'}{'ledgers'}{'autoid'};
}
else {
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'account'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account'};
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'ledger'};
}
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust_account'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account'};
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust_ledger'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'ledger'};
addRow('leases', addRow('leases',
{ 'number' => $row->{'LedgerID'}, { 'number' => $row->{'LedgerID'},
@@ -867,8 +888,30 @@ foreach $row (@{query($sdbh, $query)}) {
'amount' => $row->{'ChargeAmount'}, 'amount' => $row->{'ChargeAmount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" }); 'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
my $debit_entry_id = $newdb{'tables'}{'ledger_entries'}{'autoid'},
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust_ledger'},
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger'},
'amount' => $row->{'ChargeAmount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'terminal'}
= $debit_entry_id;
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'} $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'}, = $newdb{'tables'}{'ledger_entries'}{'autoid'},
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger'}
= $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust_ledger'};
addRow('reconciliations',
{ 'debit_ledger_entry_id' => $debit_entry_id,
'credit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'},
'terminal_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'terminal'},
'amount' => $row->{'ChargeAmount'},
});
next unless $row->{'TaxAmount'}; next unless $row->{'TaxAmount'};
@@ -944,16 +987,18 @@ foreach $row (@{query($sdbh, $query)})
if (!defined $monetary_source_id) { if (!defined $monetary_source_id) {
addRow('monetary_sources', addRow('monetary_sources',
{ 'monetary_type_id' => $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'id'}, { 'monetary_type_id' => $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'monetary_type'}{'id'},
'name' => $row->{'RecdFrom'}, 'name' => $row->{'RecdFrom'},
'comment' => "Payment: $row->{'PaymentID'}; Type: $row->{'PaymentType'}; Check: $row->{'CheckNum'}; $row->{'Memo'}" }); 'comment' => "Payment: $row->{'PaymentID'}; Type: $row->{'PaymentType'}; Check: $row->{'CheckNum'}; $row->{'Memo'}" });
$monetary_source_id = $newdb{'tables'}{'monetary_sources'}{'autoid'}; $monetary_source_id = $newdb{'tables'}{'monetary_sources'}{'autoid'};
} }
my $payment_acct = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'account'};
addRow('ledger_entries', addRow('ledger_entries',
{ 'monetary_source_id' => $monetary_source_id, { 'monetary_source_id' => $monetary_source_id,
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'}, 'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Cash'}{'ledger'}, 'debit_ledger_id' => $newdb{'lookup'}{'account'}{$payment_acct}{'ledger'},
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger'}, 'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger'},
'amount' => $row->{'PaymentAmount'}, 'amount' => $row->{'PaymentAmount'},
'comment' => "Receipt: $row->{'ReceiptNum'}; Payment: $row->{'PaymentID'}; Charge: $row->{'ChargeID'}" }); 'comment' => "Receipt: $row->{'ReceiptNum'}; Payment: $row->{'PaymentID'}; Charge: $row->{'ChargeID'}" });
@@ -971,6 +1016,7 @@ foreach $row (@{query($sdbh, $query)})
addRow('reconciliations', addRow('reconciliations',
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'}, { 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry'},
'credit_ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'entry'}, 'credit_ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'entry'},
'terminal_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'terminal'},
'amount' => $reconcile_amount, 'amount' => $reconcile_amount,
}); });
@@ -1148,6 +1194,7 @@ foreach my $ir ('invoice', 'receipt') {
addRow('reconciliations', addRow('reconciliations',
{ 'debit_ledger_entry_id' => $t->{'debit'}, { 'debit_ledger_entry_id' => $t->{'debit'},
'credit_ledger_entry_id' => $e->{'id'}, 'credit_ledger_entry_id' => $e->{'id'},
'terminal_ledger_entry_id' => $t->{'debit'},
'amount' => $t->{'amount'} 'amount' => $t->{'amount'}
}); });
} }