More changes to how accounts/ledgers/transactions are all handled.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@78 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -632,6 +632,8 @@ CREATE TABLE `pmgr_customers` (
|
|||||||
`name` VARCHAR(80) NOT NULL,
|
`name` VARCHAR(80) NOT NULL,
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
|
`account_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@@ -689,6 +691,7 @@ CREATE TABLE `pmgr_leases` (
|
|||||||
`lease_type_id` INT(10) UNSIGNED NOT NULL,
|
`lease_type_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`unit_id` INT(10) UNSIGNED NOT NULL,
|
`unit_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`customer_id` INT(10) UNSIGNED NOT NULL,
|
`customer_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
`account_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`late_schedule_id` INT(10) UNSIGNED DEFAULT NULL,
|
`late_schedule_id` INT(10) UNSIGNED DEFAULT NULL,
|
||||||
|
|
||||||
`lease_date` DATE NOT NULL,
|
`lease_date` DATE NOT NULL,
|
||||||
@@ -832,17 +835,17 @@ CREATE TABLE `pmgr_accounts` (
|
|||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
LOCK TABLES `pmgr_accounts` WRITE;
|
LOCK TABLES `pmgr_accounts` WRITE;
|
||||||
INSERT INTO `pmgr_accounts` (`id`, `type`, `name`)
|
INSERT INTO `pmgr_accounts` (`type`, `name`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'ASSET', 'A/R'),
|
('ASSET', 'A/R'),
|
||||||
(2, 'LIABILITY', 'A/P'),
|
('LIABILITY', 'A/P'),
|
||||||
(3, 'LIABILITY', 'Tax'),
|
('LIABILITY', 'Tax'),
|
||||||
(4, 'LIABILITY', 'Customer Credit'),
|
('LIABILITY', 'Customer Credit'),
|
||||||
(5, 'ASSET', 'Bank'),
|
('ASSET', 'Bank'),
|
||||||
(6, 'ASSET', 'Cash'),
|
('ASSET', 'Cash'),
|
||||||
(7, 'LIABILITY', 'Security Deposit'),
|
('LIABILITY', 'Security Deposit'),
|
||||||
(8, 'INCOME', 'Rent'),
|
('INCOME', 'Rent'),
|
||||||
(9, 'INCOME', 'Late Charge');
|
('INCOME', 'Late Charge');
|
||||||
UNLOCK TABLES;
|
UNLOCK TABLES;
|
||||||
|
|
||||||
|
|
||||||
@@ -882,9 +885,18 @@ CREATE TABLE `pmgr_ledgers` (
|
|||||||
-- this particular ledger is valid and so on.
|
-- this particular ledger is valid and so on.
|
||||||
|
|
||||||
`name` VARCHAR(80) DEFAULT NULL,
|
`name` VARCHAR(80) DEFAULT NULL,
|
||||||
|
`sequence` INT(10) UNSIGNED DEFAULT 1,
|
||||||
`account_id` INT(10) UNSIGNED NOT NULL,
|
`account_id` INT(10) UNSIGNED NOT NULL,
|
||||||
`closed` INT UNSIGNED DEFAULT 0,
|
`closed` INT UNSIGNED DEFAULT 0,
|
||||||
|
|
||||||
|
-- REVISIT <AP>: 20090607
|
||||||
|
-- Probably, a single close should have the ability to close
|
||||||
|
-- many different account ledgers. For now, just timestamping.
|
||||||
|
-- `close_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
|
||||||
|
`open_stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`close_stamp` DATETIME DEFAULT NULL,
|
||||||
|
|
||||||
`comment` VARCHAR(255) DEFAULT NULL,
|
`comment` VARCHAR(255) DEFAULT NULL,
|
||||||
|
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
@@ -903,13 +915,6 @@ CREATE TABLE `pmgr_transactions` (
|
|||||||
`through_date` DATE DEFAULT NULL,
|
`through_date` DATE DEFAULT NULL,
|
||||||
`due_date` DATE DEFAULT NULL,
|
`due_date` DATE DEFAULT NULL,
|
||||||
|
|
||||||
-- REVISIT <AP>: 20090604
|
|
||||||
-- It really seems this is too restrictive. One tenant
|
|
||||||
-- should be able to, within a single transaction, pay
|
|
||||||
-- for their own charges and another tenant's as well.
|
|
||||||
-- customer_id may need to move to ledger_entries
|
|
||||||
`customer_id` INT(10) UNSIGNED NOT NULL,
|
|
||||||
|
|
||||||
-- REVISIT <AP>: 20090604
|
-- REVISIT <AP>: 20090604
|
||||||
-- How should we track which charges have been paid?
|
-- How should we track which charges have been paid?
|
||||||
-- `related_transaction_id` INT(10) UNSIGNED NOT NULL,
|
-- `related_transaction_id` INT(10) UNSIGNED NOT NULL,
|
||||||
|
|||||||
@@ -145,17 +145,25 @@ sub executeSchema {
|
|||||||
|
|
||||||
sub buildTables {
|
sub buildTables {
|
||||||
foreach my $table (values %{$newdb{'tables'}}) {
|
foreach my $table (values %{$newdb{'tables'}}) {
|
||||||
|
printf(STDERR "%-30s : %d rows\n", $table->{'name'}, int(@{$table->{'rows'}}));
|
||||||
|
|
||||||
foreach (@{$table->{'rows'}}) {
|
foreach (@{$table->{'rows'}}) {
|
||||||
next unless defined $_;
|
next unless defined $_;
|
||||||
|
|
||||||
my %row = %$_;
|
my %row = %$_;
|
||||||
delete $row{'--LINE--'};
|
delete $row{'--LINE--'};
|
||||||
|
|
||||||
my $query;
|
my $query;
|
||||||
$query = "INSERT INTO " . $table->{'name'};
|
$query = "INSERT INTO " . $table->{'name'};
|
||||||
$query .= " (" . join(", ", map({"`$_`"} keys(%row))) . ")";
|
$query .= " (" . join(", ", map({"`$_`"} keys(%row))) . ")";
|
||||||
$query .= " VALUES (" . join(", ", map({s/'/''/g if defined $_; defined $_ ? "'$_'" : "NULL"} values(%row))) . ")";
|
$query .= " VALUES (" . join(", ", map({s/'/''/g if defined $_;
|
||||||
query($db_handle, $query, $_);
|
defined $_
|
||||||
|
? (/^\w+\(.*\)$/
|
||||||
|
? $_
|
||||||
|
: "'$_'" )
|
||||||
|
: "NULL" }
|
||||||
|
values(%row))) . ")";
|
||||||
|
query($db_handle, $query, $_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -425,6 +433,7 @@ $result = query($db_handle, $query);
|
|||||||
foreach $row (@$result) {
|
foreach $row (@$result) {
|
||||||
addRow('ledgers',
|
addRow('ledgers',
|
||||||
{ 'account_id' => $row->{'id'},
|
{ 'account_id' => $row->{'id'},
|
||||||
|
'open_stamp' => '2009-01-01',
|
||||||
'name' => $row->{'name'} . ' Ledger',
|
'name' => $row->{'name'} . ' Ledger',
|
||||||
'comment' => undef });
|
'comment' => undef });
|
||||||
|
|
||||||
@@ -648,15 +657,19 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} =
|
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} =
|
||||||
$newdb{'tables'}{'contacts'}{'autoid'};
|
$newdb{'tables'}{'contacts'}{'autoid'};
|
||||||
|
|
||||||
# Every customer gets their own ledger
|
# Every customer gets their own account
|
||||||
addRow('accounts',
|
addRow('accounts',
|
||||||
{ 'type' => 'ASSET',
|
{ 'type' => 'ASSET',
|
||||||
'name' => 'Customer: ' . $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'},
|
'name' => ('Account: Customer #' . ($newdb{'tables'}{'customers'}{'autoid'}+1) .
|
||||||
'comment' => undef });
|
' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')'),
|
||||||
|
'comment' => undef });
|
||||||
|
#'comment' => 'For direct customer transaction, NOT lease charges!' });
|
||||||
addRow('ledgers',
|
addRow('ledgers',
|
||||||
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
|
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
|
||||||
'name' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ' Ledger',
|
'open_stamp' => '2009-01-01',
|
||||||
'comment' => 'Ledger for Customer Account #' . $newdb{'tables'}{'accounts'}{'autoid'} });
|
'name' => 'Ledger: Customer #' . ($newdb{'tables'}{'customers'}{'autoid'}+1)
|
||||||
|
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')',
|
||||||
|
'comment' => undef });
|
||||||
|
|
||||||
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account'} =
|
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account'} =
|
||||||
$newdb{'tables'}{'accounts'}{'autoid'};
|
$newdb{'tables'}{'accounts'}{'autoid'};
|
||||||
@@ -782,16 +795,19 @@ $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)}) {
|
||||||
|
|
||||||
# Every lease gets its own ledger
|
# Every lease gets its own account
|
||||||
addRow('accounts',
|
addRow('accounts',
|
||||||
{ 'type' => 'ASSET',
|
{ 'type' => 'ASSET',
|
||||||
'name' => 'Lease: #' . ($newdb{'tables'}{'leases'}{'autoid'}+1),
|
'name' => ('Account: Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
|
||||||
'comment' => undef });
|
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')'),
|
||||||
|
'comment' => undef });
|
||||||
|
#'comment' => 'For lease related transaction, NOT personal charges!' });
|
||||||
addRow('ledgers',
|
addRow('ledgers',
|
||||||
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
|
{ 'account_id' => $newdb{'tables'}{'accounts'}{'autoid'},
|
||||||
'name' => 'Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
|
'open_stamp' => datefmt($row->{'DateIn'}),
|
||||||
|
'name' => 'Ledger: Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
|
||||||
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')',
|
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')',
|
||||||
'comment' => 'Ledger for Customer Account #' . $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} });
|
'comment' => undef });
|
||||||
|
|
||||||
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
|
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
|
||||||
= { 'cust' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'cust'},
|
= { 'cust' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'cust'},
|
||||||
@@ -836,8 +852,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
|
|
||||||
addRow('transactions',
|
addRow('transactions',
|
||||||
{ 'stamp' => datefmt($row->{'ChargeDate'}),
|
{ 'stamp' => datefmt($row->{'ChargeDate'}),
|
||||||
'through_date' => datefmt($row->{'EndDate'}),
|
'through_date' => datefmt($row->{'EndDate'}) });
|
||||||
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust'} });
|
|
||||||
|
|
||||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
|
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
|
||||||
= { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
= { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||||
@@ -888,8 +903,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
|||||||
|
|
||||||
addRow('transactions',
|
addRow('transactions',
|
||||||
{ 'stamp' => datefmt($row->{'ReceiptDate'}),
|
{ 'stamp' => datefmt($row->{'ReceiptDate'}),
|
||||||
'through_date' => undef,
|
'through_date' => undef });
|
||||||
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust'} });
|
|
||||||
|
|
||||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}
|
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}
|
||||||
= {'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
= {'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||||
@@ -1030,8 +1044,10 @@ $newdb{'ids'}{'ledger'}{'Cash-Old'} =
|
|||||||
|
|
||||||
addRow('ledgers',
|
addRow('ledgers',
|
||||||
{ 'account_id' => $newdb{'lookup'}{'account'}{'Cash'}{'account'},
|
{ 'account_id' => $newdb{'lookup'}{'account'}{'Cash'}{'account'},
|
||||||
'name' => 'Fake Cash Ledger',
|
'open_stamp' => 'NOW()',
|
||||||
'comment' => 'Fake ledger for testing' });
|
'sequence' => 2,
|
||||||
|
'name' => 'Fake Cash Ledger',
|
||||||
|
'comment' => 'Fake ledger for testing' });
|
||||||
|
|
||||||
$newdb{'lookup'}{'account'}{'Cash'}{'ledger'} =
|
$newdb{'lookup'}{'account'}{'Cash'}{'ledger'} =
|
||||||
$newdb{'tables'}{'ledgers'}{'autoid'};
|
$newdb{'tables'}{'ledgers'}{'autoid'};
|
||||||
@@ -1046,8 +1062,7 @@ foreach $row (@{$newdb{'tables'}{'ledger_entries'}{'rows'}}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRow('transactions',
|
addRow('transactions',
|
||||||
{ 'customer_id' => 0,
|
{ 'stamp' => '2009-05-10' });
|
||||||
'stamp' => '2009-05-10' });
|
|
||||||
|
|
||||||
addRow('ledger_entries',
|
addRow('ledger_entries',
|
||||||
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||||
@@ -1059,7 +1074,7 @@ addRow('ledger_entries',
|
|||||||
'comment' => "Carrying forward old ledger balance onto new ledger" });
|
'comment' => "Carrying forward old ledger balance onto new ledger" });
|
||||||
|
|
||||||
$newdb{'tables'}{'ledgers'}{'rows'}[$newdb{'ids'}{'ledger'}{'Cash-Old'}]{'closed'} = 1;
|
$newdb{'tables'}{'ledgers'}{'rows'}[$newdb{'ids'}{'ledger'}{'Cash-Old'}]{'closed'} = 1;
|
||||||
|
$newdb{'tables'}{'ledgers'}{'rows'}[$newdb{'ids'}{'ledger'}{'Cash-Old'}]{'close_stamp'} = 'NOW()';
|
||||||
|
|
||||||
foreach my $ir ('invoice', 'receipt') {
|
foreach my $ir ('invoice', 'receipt') {
|
||||||
foreach my $tx (@{$fake{$ir}}) {
|
foreach my $tx (@{$fake{$ir}}) {
|
||||||
@@ -1069,7 +1084,6 @@ foreach my $ir ('invoice', 'receipt') {
|
|||||||
{ 'id' => $tx->{'id'},
|
{ 'id' => $tx->{'id'},
|
||||||
'stamp' => $tx->{'date'},
|
'stamp' => $tx->{'date'},
|
||||||
'through_date' => $tx->{'thru'},
|
'through_date' => $tx->{'thru'},
|
||||||
'customer_id' => $fake{'custid'},
|
|
||||||
'comment' => "Fake $ir" },
|
'comment' => "Fake $ir" },
|
||||||
1);
|
1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user