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:
abijah
2009-06-10 02:27:03 +00:00
parent 374843aeee
commit 190a9259d4
2 changed files with 64 additions and 45 deletions

View File

@@ -145,17 +145,25 @@ sub executeSchema {
sub buildTables {
foreach my $table (values %{$newdb{'tables'}}) {
printf(STDERR "%-30s : %d rows\n", $table->{'name'}, int(@{$table->{'rows'}}));
foreach (@{$table->{'rows'}}) {
next unless defined $_;
next unless defined $_;
my %row = %$_;
delete $row{'--LINE--'};
my %row = %$_;
delete $row{'--LINE--'};
my $query;
$query = "INSERT INTO " . $table->{'name'};
$query .= " (" . join(", ", map({"`$_`"} keys(%row))) . ")";
$query .= " VALUES (" . join(", ", map({s/'/''/g if defined $_; defined $_ ? "'$_'" : "NULL"} values(%row))) . ")";
query($db_handle, $query, $_);
my $query;
$query = "INSERT INTO " . $table->{'name'};
$query .= " (" . join(", ", map({"`$_`"} keys(%row))) . ")";
$query .= " VALUES (" . join(", ", map({s/'/''/g if defined $_;
defined $_
? (/^\w+\(.*\)$/
? $_
: "'$_'" )
: "NULL" }
values(%row))) . ")";
query($db_handle, $query, $_);
}
}
}
@@ -425,6 +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',
'comment' => undef });
@@ -648,15 +657,19 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} =
$newdb{'tables'}{'contacts'}{'autoid'};
# Every customer gets their own ledger
# Every customer gets their own account
addRow('accounts',
{ 'type' => 'ASSET',
'name' => 'Customer: ' . $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'},
'comment' => undef });
'name' => ('Account: 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'},
'name' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ' Ledger',
'comment' => 'Ledger for Customer Account #' . $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'} =
$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";
foreach $row (@{query($sdbh, $query)}) {
# Every lease gets its own ledger
# Every lease gets its own account
addRow('accounts',
{ 'type' => 'ASSET',
'name' => 'Lease: #' . ($newdb{'tables'}{'leases'}{'autoid'}+1),
'comment' => undef });
'name' => ('Account: Lease #' . ($newdb{'tables'}{'leases'}{'autoid'}+1)
. ' ('.$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'} . ')'),
'comment' => undef });
#'comment' => 'For lease related transaction, NOT personal charges!' });
addRow('ledgers',
{ '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'} . ')',
'comment' => 'Ledger for Customer Account #' . $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} });
'comment' => undef });
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
= { 'cust' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'cust'},
@@ -836,8 +852,7 @@ foreach $row (@{query($sdbh, $query)}) {
addRow('transactions',
{ 'stamp' => datefmt($row->{'ChargeDate'}),
'through_date' => datefmt($row->{'EndDate'}),
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust'} });
'through_date' => datefmt($row->{'EndDate'}) });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
= { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
@@ -888,8 +903,7 @@ foreach $row (@{query($sdbh, $query)}) {
addRow('transactions',
{ 'stamp' => datefmt($row->{'ReceiptDate'}),
'through_date' => undef,
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'cust'} });
'through_date' => undef });
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}
= {'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
@@ -1030,8 +1044,10 @@ $newdb{'ids'}{'ledger'}{'Cash-Old'} =
addRow('ledgers',
{ 'account_id' => $newdb{'lookup'}{'account'}{'Cash'}{'account'},
'name' => 'Fake Cash Ledger',
'comment' => 'Fake ledger for testing' });
'open_stamp' => 'NOW()',
'sequence' => 2,
'name' => 'Fake Cash Ledger',
'comment' => 'Fake ledger for testing' });
$newdb{'lookup'}{'account'}{'Cash'}{'ledger'} =
$newdb{'tables'}{'ledgers'}{'autoid'};
@@ -1046,8 +1062,7 @@ foreach $row (@{$newdb{'tables'}{'ledger_entries'}{'rows'}}) {
}
addRow('transactions',
{ 'customer_id' => 0,
'stamp' => '2009-05-10' });
{ 'stamp' => '2009-05-10' });
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
@@ -1059,7 +1074,7 @@ addRow('ledger_entries',
'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'}]{'close_stamp'} = 'NOW()';
foreach my $ir ('invoice', 'receipt') {
foreach my $tx (@{$fake{$ir}}) {
@@ -1069,7 +1084,6 @@ foreach my $ir ('invoice', 'receipt') {
{ 'id' => $tx->{'id'},
'stamp' => $tx->{'date'},
'through_date' => $tx->{'thru'},
'customer_id' => $fake{'custid'},
'comment' => "Fake $ir" },
1);