Nowhere near complete, but must snapshot prior to my Boston trip.

git-svn-id: file:///svn-source/pmgr/branches/statements_20090623@184 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-24 17:16:39 +00:00
parent 8cb45ad1d6
commit 6baa7fa6e6
13 changed files with 225 additions and 231 deletions

View File

@@ -633,14 +633,8 @@ CREATE TABLE `pmgr_customers` (
-- If NULL, rely on the contact info exclusively -- If NULL, rely on the contact info exclusively
`name` VARCHAR(80) DEFAULT NULL, `name` VARCHAR(80) DEFAULT NULL,
-- A customer gets their own account, although any -- Statement of charges/payments
-- lease specific charge (rent, late fees, etc) will `statement_id` INT(10) UNSIGNED NOT NULL,
-- be debited against the lease account. This one
-- will be used for non-lease related charges, as
-- well as charges that intentionally span more than
-- one lease (such as one security deposit to cover
-- two or more units).
`account_id` INT(10) UNSIGNED NOT NULL,
-- Primary Contact... every customer must have one -- Primary Contact... every customer must have one
-- (and presumably, most customers will _be_ one). -- (and presumably, most customers will _be_ one).
@@ -703,12 +697,13 @@ CREATE TABLE `pmgr_leases` (
-- Allow user to specify their own lease numbers -- Allow user to specify their own lease numbers
-- If NULL, `id` will be used -- If NULL, `id` will be used
`number` VARCHAR(20) DEFAULT NULL, -- `number` VARCHAR(20) DEFAULT NULL,
`number` INT(10) UNSIGNED DEFAULT NULL,
`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, `statement_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,
@@ -997,6 +992,21 @@ CREATE TABLE `pmgr_reconciliations` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ##
-- ## MONETARY
-- ##
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
-- TABLE pmgr_monetary_sources -- TABLE pmgr_monetary_sources
@@ -1051,6 +1061,59 @@ UNLOCK TABLES;
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ##
-- ## STATEMENTS
-- ##
-- ## Statements are supplementary financial information. They should
-- ## NEVER be used in financial calculations, but rather are secondary
-- ## information, to be created where needed.
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_statements
DROP TABLE IF EXISTS `pmgr_statements`;
CREATE TABLE `pmgr_statements` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_statement_entries
DROP TABLE IF EXISTS `pmgr_statement_entries`;
CREATE TABLE `pmgr_statement_entries` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('CHARGE',
'PAYMENT')
NOT NULL,
`statement_id` INT(10) UNSIGNED NOT NULL,
`ledger_entry_id` INT(10) UNSIGNED NOT NULL,
`amount` FLOAT(12,2) NOT NULL,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ###################################################################### -- ######################################################################
-- ###################################################################### -- ######################################################################

View File

@@ -4,8 +4,6 @@ use DBI;
use Data::Dumper; use Data::Dumper;
use File::Copy; use File::Copy;
my $use_ir = 0;
# Internally adjust all numbers coming from the database to # Internally adjust all numbers coming from the database to
# be in inches. Not necessary to go to this detail, but the # be in inches. Not necessary to go to this detail, but the
# actual units used is irrelevant, provided everything is to # actual units used is irrelevant, provided everything is to
@@ -685,6 +683,13 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}} $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}
= { 'name' => "$row->{'LastName'}, $row->{'FirstName'}" }; = { 'name' => "$row->{'LastName'}, $row->{'FirstName'}" };
# Each tenants receives a statement
addRow('statements',
{ 'comment' => ("Statement for " .
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'name'}) });
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'statement_id'} =
$newdb{'tables'}{'statements'}{'autoid'};
addRow('contacts', addRow('contacts',
{ 'first_name' => $row->{'FirstName'}, { 'first_name' => $row->{'FirstName'},
'middle_name' => $row->{'MiddleName'}, 'middle_name' => $row->{'MiddleName'},
@@ -694,15 +699,11 @@ 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'};
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account_id'} =
$newdb{'lookup'}{'account'}{'A/R'}{'account_id'};
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'ledger_id'} =
$newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
addRow('customers', addRow('customers',
{ 'name' => "$row->{'LastName'}, $row->{'FirstName'}", { 'name' => "$row->{'LastName'}, $row->{'FirstName'}",
'primary_contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, 'statement_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'statement_id'},
'account_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account_id'} }); 'primary_contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} });
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} = $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} =
$newdb{'tables'}{'customers'}{'autoid'}; $newdb{'tables'}{'customers'}{'autoid'};
@@ -820,19 +821,22 @@ $query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.L
foreach $row (@{query($sdbh, $query)}) { foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}} $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
= { 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} }; = { 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'},
'customer_statement_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'statement_id'},
};
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'account_id'} # Each lease receives a statement
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account_id'}; addRow('statements',
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger_id'} { 'comment' => ("Statement for Lease #" . $row->{'LedgerID'}) });
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'ledger_id'}; $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_id'} =
$newdb{'tables'}{'statements'}{'autoid'};
addRow('leases', addRow('leases',
{ 'number' => $row->{'LedgerID'}, { 'number' => $row->{'LedgerID'},
'statement_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_id'},
'lease_type_id' => $newdb{'tables'}{'lease_types'}{'autoid'}, 'lease_type_id' => $newdb{'tables'}{'lease_types'}{'autoid'},
'unit_id' => $newdb{'lookup'}{'unit'}{$row->{'UnitID'}}{'id'}, 'unit_id' => $newdb{'lookup'}{'unit'}{$row->{'UnitID'}}{'id'},
'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'}, 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'},
'account_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'account_id'},
'lease_date' => datefmt($row->{'DateIn'}), 'lease_date' => datefmt($row->{'DateIn'}),
'movein_date' => datefmt($row->{'DateIn'}), 'movein_date' => datefmt($row->{'DateIn'}),
'moveout_date' => datefmt($row->{'DateOut'}), 'moveout_date' => datefmt($row->{'DateOut'}),
@@ -841,6 +845,7 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} = $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} =
$newdb{'tables'}{'leases'}{'autoid'}; $newdb{'tables'}{'leases'}{'autoid'};
} }
@@ -862,102 +867,60 @@ $newdb{'lookup'}{'charge'} = {};
$query = "SELECT * FROM Charges ORDER BY ChargeID"; $query = "SELECT * FROM Charges ORDER BY ChargeID";
foreach $row (@{query($sdbh, $query)}) { foreach $row (@{query($sdbh, $query)}) {
my $credit_ledger_id;
my $ledger_entry_id;
addRow('transactions', addRow('transactions',
{ 'stamp' => datefmt($row->{'ChargeDate'}), { 'stamp' => datefmt($row->{'ChargeDate'}),
'through_date' => datefmt($row->{'EndDate'}) }); 'through_date' => datefmt($row->{'EndDate'}) });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}} $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
= { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'}, = { 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
'ledger_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger_id'},
#'ledger_id' => $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'},
'amount' => $row->{'ChargeAmount'}, 'amount' => $row->{'ChargeAmount'},
'tax_amount' => $row->{'TaxAmount'}, 'tax_amount' => $row->{'TaxAmount'},
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'}, 'lease_statement_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_id'},
'lease_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'}, 'customer_statement_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_statement_id'},
}; };
$credit_ledger_id = $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'ledger_id'};
if ($use_ir) {
addRow('ledger_entries', addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'}, { 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'}, 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'}, 'debit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id, 'credit_ledger_id' => $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'ledger_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => $row->{'ChargeAmount'}, 'amount' => $row->{'ChargeAmount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" }); 'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
$ledger_entry_id = $newdb{'tables'}{'ledger_entries'}{'autoid'};
$credit_ledger_id = $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'};
}
addRow('ledger_entries', foreach ($newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_statement_id'},
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'}, $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_statement_id'}) {
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'}, addRow('statement_entries',
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'}, { 'type' => 'CHARGE',
'credit_ledger_id' => $credit_ledger_id, 'statement_id' => $_,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}, 'ledger_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}, 'amount' => $row->{'ChargeAmount'} });
'amount' => $row->{'ChargeAmount'}, }
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'} $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'}; = $newdb{'tables'}{'ledger_entries'}{'autoid'};
if ($use_ir) {
# Reconcile the invoice account. Since this is from the perspective
# of the invoice, the entry crediting the charge is the debit, and
# the entry debiting A/R is the credit.
addRow('reconciliations',
{ 'debit_ledger_entry_id' => $ledger_entry_id,
'credit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'},
'amount' => $row->{'ChargeAmount'},
});
}
next unless $row->{'TaxAmount'}; next unless $row->{'TaxAmount'};
$credit_ledger_id = $newdb{'lookup'}{'charge_type'}{'Tax'}{'ledger_id'};
if ($use_ir) {
addRow('ledger_entries', addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'}, { 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'}, 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'}, 'debit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id, 'credit_ledger_id' => $newdb{'lookup'}{'charge_type'}{'Tax'}{'ledger_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => $row->{'TaxAmount'}, 'amount' => $row->{'TaxAmount'},
'comment' => undef }); 'comment' => undef });
$ledger_entry_id = $newdb{'tables'}{'ledger_entries'}{'autoid'};
$credit_ledger_id = $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'};
}
addRow('ledger_entries', foreach ($newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_statement_id'},
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'}, $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_statement_id'}) {
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'}, addRow('statement_entries',
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'}, { 'type' => 'CHARGE',
'credit_ledger_id' => $credit_ledger_id, 'statement_id' => $_,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}, 'ledger_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}, 'amount' => $row->{'TaxAmount'} });
'amount' => $row->{'TaxAmount'}, }
'comment' => undef });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_entry'} $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_entry'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'}; = $newdb{'tables'}{'ledger_entries'}{'autoid'};
if ($use_ir) {
# Reconcile the invoice account. Since this is from the perspective
# of the invoice, the entry crediting the charge is the debit, and
# the entry debiting A/R is the credit.
addRow('reconciliations',
{ 'debit_ledger_entry_id' => $ledger_entry_id,
'credit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_entry'},
'amount' => $row->{'TaxAmount'},
});
}
} }
@@ -1052,22 +1015,6 @@ foreach $row (@{query($sdbh, $query)})
$row->{'PaymentID'}}{'account_name'} $row->{'PaymentID'}}{'account_name'}
}{'ledger_id'}; }{'ledger_id'};
if ($use_ir) {
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'},
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Receipt'}{'ledger_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => $row->{'PaymentAmount'},
'comment' => "Receipt: $row->{'ReceiptNum'}; Charge: $row->{'ChargeID'}; Payment: $row->{'PaymentID'}" });
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'}
= $newdb{'lookup'}{'account'}{'Receipt'}{'ledger_id'};
}
# Sitelink splits one physical payment into multiple "payments" to match each charge # Sitelink splits one physical payment into multiple "payments" to match each charge
# This is kludgy, but for our cases at least, brings those pseudo-payments back into # This is kludgy, but for our cases at least, brings those pseudo-payments back into
# a single one. It presumes that there is only one PaymentType per receipt. # a single one. It presumes that there is only one PaymentType per receipt.
@@ -1076,14 +1023,21 @@ foreach $row (@{query($sdbh, $query)})
{ 'monetary_source_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'}, { 'monetary_source_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'},
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'}, 'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'}, 'debit_ledger_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'}, 'credit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
#'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => 0, 'amount' => 0,
'comment' => "Receipt: $row->{'ReceiptNum'}; " }); 'comment' => "Receipt: $row->{'ReceiptNum'}; " });
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'} $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'}; = $newdb{'tables'}{'ledger_entries'}{'autoid'};
addRow('statement_entries',
{ 'type' => 'PAYMENT',
'statement_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_statement_id'},
'ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'},
'amount' => 0 });
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'statement_entry_id'}
= $newdb{'tables'}{'statement_entries'}{'autoid'};
} }
$newdb{'tables'}{'ledger_entries'}{'rows'}[ $newdb{'tables'}{'ledger_entries'}{'rows'}[
@@ -1094,6 +1048,16 @@ foreach $row (@{query($sdbh, $query)})
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'} $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
]{'comment'} .= 'P:'.$row->{'PaymentID'} . '->C:' . $row->{'ChargeID'} . '; '; ]{'comment'} .= 'P:'.$row->{'PaymentID'} . '->C:' . $row->{'ChargeID'} . '; ';
$newdb{'tables'}{'statement_entries'}{'rows'}[
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'statement_entry_id'}
]{'amount'} += $row->{'PaymentAmount'};
addRow('statement_entries',
{ 'type' => 'PAYMENT',
'statement_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_statement_id'},
'ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'},
'amount' => $row->{'PaymentAmount'} });
# OK, now that the receipt is reconciled, update # OK, now that the receipt is reconciled, update
# payment to reference the true ledger_entry_id # payment to reference the true ledger_entry_id
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'} $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'}

View File

@@ -78,6 +78,24 @@ class AppModel extends Model {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: nameToID
* - Returns the ID of the named item
*/
function nameToID($name) {
$this->cacheQueries = true;
$item = $this->find('first', array
('recursive' => -1,
'conditions' => compact('name'),
));
$this->cacheQueries = false;
$item = current($item);
return $item['id'];
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -162,41 +162,11 @@ class LedgerEntriesController extends AppController {
if (isset($params['custom']['customer_id'])) { if (isset($params['custom']['customer_id'])) {
$conditions[] = $conditions[] =
array('Customer.id' => $params['custom']['customer_id']); array('Customer.id' => $params['custom']['customer_id']);
/* $Account = new Account(); */
/* if (isset($params['custom']['account_ftype']) || */
/* isset($params['custom']['ledger_id'])) { */
/* $conditions[] = */
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
/* 'Account.id' => $Account->receiptAccountID())); */
/* } else { */
/* $conditions[] = */
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
/* )); */
/* } */
} }
if (isset($params['custom']['lease_id'])) { if (isset($params['custom']['lease_id'])) {
$conditions[] = $conditions[] =
array('Lease.id' => $params['custom']['lease_id']); array('Lease.id' => $params['custom']['lease_id']);
/* $Account = new Account(); */
/* if (isset($params['custom']['account_ftype']) || */
/* isset($params['custom']['ledger_id'])) { */
/* $conditions[] = */
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
/* 'Account.id' => $Account->receiptAccountID())); */
/* } else { */
/* $conditions[] = */
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
/* )); */
/* } */
} }
if (isset($params['custom']['transaction_id'])) { if (isset($params['custom']['transaction_id'])) {

View File

@@ -55,7 +55,7 @@ class UnitsController extends AppController {
$link = array $link = array
('link' => ('link' =>
array(// Models array(// Models
'UnitSize' => array('fields' => array('name')), 'UnitSize' => array('fields' => array('id', 'name')),
), ),
); );
@@ -93,6 +93,11 @@ class UnitsController extends AppController {
return parent::jqGridDataOrder($params, $model, $index, $direction); return parent::jqGridDataOrder($params, $model, $index, $direction);
} }
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
//$links['UnitSize'] = array('name');
$links['Unit'] = array('name', 'id');
return parent::jqGridRecordLinks($params, $model, $records, $links);
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************

View File

@@ -82,26 +82,13 @@ class Account extends AppModel {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* function: accountNameToID * function: Account IDs
* - Returns the ID of the named account * - Returns the ID of the desired account
*/ */
function accountNameToID($name) {
$this->cacheQueries = true;
$account = $this->find('first', array
('recursive' => -1,
'conditions' => compact('name'),
));
$this->cacheQueries = false;
return $account['Account']['id'];
}
function securityDepositAccountID() { return $this->accountNameToID('Security Deposit'); } function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
function rentAccountID() { return $this->accountNameToID('Rent'); } function rentAccountID() { return $this->nameToID('Rent'); }
function accountReceivableAccountID() { return $this->accountNameToID('A/R'); } function accountReceivableAccountID() { return $this->nameToID('A/R'); }
function invoiceAccountID() { return $this->accountReceivableAccountID(); }
function receiptAccountID() { return $this->accountReceivableAccountID(); }
//function invoiceAccountID() { return $this->accountNameToID('Invoice'); }
//function receiptAccountID() { return $this->accountNameToID('Receipt'); }
/************************************************************************** /**************************************************************************

View File

@@ -8,6 +8,7 @@ class Customer extends AppModel {
); );
var $belongsTo = array( var $belongsTo = array(
'Statement',
'PrimaryContact' => array( 'PrimaryContact' => array(
'className' => 'Contact', 'className' => 'Contact',
), ),
@@ -43,13 +44,26 @@ class Customer extends AppModel {
*/ */
function accountId($id) { function accountId($id) {
$this->cacheQueries = true; $this->cacheQueries = true;
$customer = $this->find('first', $item = $this->find('first',
array('contain' => false, array('contain' => false,
'fields' => array('account_id'), 'fields' => array('account_id'),
'conditions' => array(array('Customer.id' => $id)))); 'conditions' => compact('id')));
$this->cacheQueries = false; $this->cacheQueries = false;
return $customer['Customer']['account_id']; $item = current($item);
return $item['account_id'];
}
function statementID($id) {
$this->cacheQueries = true;
$item = $this->find('first', array
('recursive' => -1,
'conditions' => compact('id'),
));
$this->cacheQueries = false;
$item = current($item);
return $item['statement_id'];
} }
@@ -75,6 +89,7 @@ class Customer extends AppModel {
return $ids; return $ids;
} }
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -82,22 +97,10 @@ class Customer extends AppModel {
* - Returns an array of security deposit entries * - Returns an array of security deposit entries
*/ */
function findSecurityDeposits($id, $link = null) { function findSecurityDeposits($id, $link = null) {
/* pr(array('function' => 'Customer::findSecurityDeposits', */ return $this->Statement->findEntriesRelatedToAccount
/* 'args' => compact('id', 'link'), */ ($this->statementId($id),
/* )); */
$entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->Account->invoiceAccountID(),
$this->Account->securityDepositAccountID(), $this->Account->securityDepositAccountID(),
true, array('LedgerEntry.customer_id' => $id), $link); null, $link);
/* pr(array('function' => 'Customer::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* 'vars' => compact('customer'), */
/* 'return' => compact('entries'), */
/* )); */
return $entries;
} }
@@ -191,16 +194,11 @@ class Customer extends AppModel {
* - Returns summary data from the requested customer. * - Returns summary data from the requested customer.
*/ */
function stats($id = null) { function stats($id = null, $cond = null, $link = null) {
if (!$id) if (!$id)
return null; return null;
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true, return $this->Statement->stats($this->statementID($id), $cond, $link);
array('LedgerEntry.customer_id' => $id));
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats;
} }
} }

View File

@@ -26,6 +26,7 @@ class Lease extends AppModel {
'LeaseType', 'LeaseType',
'Unit', 'Unit',
'Customer', 'Customer',
'Statement',
'LateSchedule', 'LateSchedule',
); );
@@ -40,13 +41,23 @@ class Lease extends AppModel {
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* function: accountId * function: accessors
* - Returns the accountId of the given lease
*/ */
function accountId($id) { function accountId($id) {
return $this->Account->invoiceAccountID(); return $this->Account->invoiceAccountID();
} }
function statementID($id) {
$this->cacheQueries = true;
$item = $this->find('first', array
('recursive' => -1,
'conditions' => compact('id'),
));
$this->cacheQueries = false;
$item = current($item);
return $item['statement_id'];
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
@@ -83,21 +94,10 @@ class Lease extends AppModel {
* - Returns an array of security deposit entries * - Returns an array of security deposit entries
*/ */
function findSecurityDeposits($id, $link = null) { function findSecurityDeposits($id, $link = null) {
/* pr(array('function' => 'Lease::findSecurityDeposits', */ return $this->Statement->findEntriesRelatedToAccount
/* 'args' => compact('id', 'link'), */ ($this->statementId($id),
/* )); */
$entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->accountId($id),
$this->Account->securityDepositAccountID(), $this->Account->securityDepositAccountID(),
true, array('LedgerEntry.lease_id' => $id), $link); null, $link);
/* pr(array('function' => 'Lease::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* 'vars' => compact('lease'), */
/* 'return' => compact('entries'), */
/* )); */
return $entries;
} }
@@ -142,16 +142,11 @@ class Lease extends AppModel {
* - Returns summary data from the requested lease. * - Returns summary data from the requested lease.
*/ */
function stats($id = null) { function stats($id = null, $cond = null, $link = null) {
if (!$id) if (!$id)
return null; return null;
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true, return $this->Statement->stats($this->statementID($id), $cond, $link);
array('LedgerEntry.lease_id' => $id));
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats;
} }
} }

View File

@@ -63,13 +63,12 @@ echo $this->element('leases',
/********************************************************************** /**********************************************************************
* Customer Account History * Customer Statement
*/ */
echo $this->element('ledger_entries', echo $this->element('statement_entries',
array('caption' => 'Account', array('caption' => 'Statement',
'customer_id' => $customer['Customer']['id'], 'statement_id' => $customer['Customer']['statement_id'],
'ar_account' => true,
)); ));

View File

@@ -47,9 +47,6 @@ else {
$cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name'); $cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name');
$cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'name'); $cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'name');
} }
$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname');
$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id');
$cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'name');
$cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name'); $cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name');
$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150); $cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150);

View File

@@ -78,10 +78,9 @@ echo '<div CLASS="detail supporting">' . "\n";
* Lease Account History * Lease Account History
*/ */
echo $this->element('ledger_entries', echo $this->element('statement_entries',
array('caption' => 'Account', array('caption' => 'Statement',
'lease_id' => $lease['id'], 'statement_id' => $lease['statement_id'],
'ar_account' => true,
)); ));

View File

@@ -81,12 +81,12 @@ echo $this->element('table',
echo '<div class="infobox">' . "\n"; echo '<div class="infobox">' . "\n";
$rows = array(); $rows = array();
if ($debit_ledger['Account']['trackable']) { if ($debit_ledger['Account']['trackable']) {
$rows[] = array('Debit Amount Reconciled:', FormatHelper::currency($stats['debit_amount_reconciled'])); $rows[] = array('Payments Received:', FormatHelper::currency($stats['debit_amount_reconciled']));
$rows[] = array('Debit Amount Remaining:', FormatHelper::currency($stats['debit_amount_remaining'])); $rows[] = array('Amount Owing:', FormatHelper::currency($stats['debit_amount_remaining']));
} }
if ($credit_ledger['Account']['trackable']) { if ($credit_ledger['Account']['trackable']) {
$rows[] = array('Credit Amount Reconciled:', FormatHelper::currency($stats['credit_amount_reconciled'])); $rows[] = array('Charges Reconciled:', FormatHelper::currency($stats['credit_amount_reconciled']));
$rows[] = array('Credit Amount Remaining:', FormatHelper::currency($stats['credit_amount_remaining'])); $rows[] = array('Unapplied Amount:', FormatHelper::currency($stats['credit_amount_remaining']));
} }
echo $this->element('table', echo $this->element('table',
array('class' => 'summary', array('class' => 'summary',

View File

@@ -57,15 +57,14 @@ echo $this->element('leases',
/********************************************************************** /**********************************************************************
* Current Tenant Lease Account History * Current Lease Statement History
*/ */
echo $this->element('ledger_entries', echo $this->element('statement_entries',
array('caption' => ('Current Lease Account (' . array('caption' => ('Current Lease Statement (' .
$unit['CurrentLease']['Customer']['name'] $unit['CurrentLease']['Customer']['name'] .
. ')'), ')'),
'ar_account' => true, 'statement_id' => $unit['CurrentLease']['statement_id']
'lease_id' => $unit['CurrentLease']['id'],
)); ));