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
`name` VARCHAR(80) DEFAULT NULL,
-- A customer gets their own account, although any
-- lease specific charge (rent, late fees, etc) will
-- 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,
-- Statement of charges/payments
`statement_id` INT(10) UNSIGNED NOT NULL,
-- Primary Contact... every customer must have one
-- (and presumably, most customers will _be_ one).
@@ -703,12 +697,13 @@ CREATE TABLE `pmgr_leases` (
-- Allow user to specify their own lease numbers
-- 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,
`unit_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,
`lease_date` DATE NOT NULL,
@@ -997,6 +992,21 @@ CREATE TABLE `pmgr_reconciliations` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ######################################################################
-- ##
-- ## MONETARY
-- ##
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- 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 File::Copy;
my $use_ir = 0;
# Internally adjust all numbers coming from the database to
# be in inches. Not necessary to go to this detail, but the
# actual units used is irrelevant, provided everything is to
@@ -685,6 +683,13 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}
= { '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',
{ 'first_name' => $row->{'FirstName'},
'middle_name' => $row->{'MiddleName'},
@@ -694,15 +699,11 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} =
$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',
{ 'name' => "$row->{'LastName'}, $row->{'FirstName'}",
'primary_contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'},
'account_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account_id'} });
'statement_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'statement_id'},
'primary_contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} });
$newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} =
$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)}) {
$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'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'account_id'};
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'ledger_id'}
= $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'ledger_id'};
# Each lease receives a statement
addRow('statements',
{ 'comment' => ("Statement for Lease #" . $row->{'LedgerID'}) });
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_id'} =
$newdb{'tables'}{'statements'}{'autoid'};
addRow('leases',
{ 'number' => $row->{'LedgerID'},
'statement_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_id'},
'lease_type_id' => $newdb{'tables'}{'lease_types'}{'autoid'},
'unit_id' => $newdb{'lookup'}{'unit'}{$row->{'UnitID'}}{'id'},
'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'},
'account_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'account_id'},
'lease_date' => datefmt($row->{'DateIn'}),
'movein_date' => datefmt($row->{'DateIn'}),
'moveout_date' => datefmt($row->{'DateOut'}),
@@ -841,6 +845,7 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} =
$newdb{'tables'}{'leases'}{'autoid'};
}
@@ -862,102 +867,60 @@ $newdb{'lookup'}{'charge'} = {};
$query = "SELECT * FROM Charges ORDER BY ChargeID";
foreach $row (@{query($sdbh, $query)}) {
my $credit_ledger_id;
my $ledger_entry_id;
addRow('transactions',
{ 'stamp' => datefmt($row->{'ChargeDate'}),
'through_date' => datefmt($row->{'EndDate'}) });
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
= { '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'},
'tax_amount' => $row->{'TaxAmount'},
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'},
'lease_statement_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_statement_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',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => $row->{'ChargeAmount'},
'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',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'ledger_id'},
'amount' => $row->{'ChargeAmount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}" });
foreach ($newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_statement_id'},
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_statement_id'}) {
addRow('statement_entries',
{ 'type' => 'CHARGE',
'statement_id' => $_,
'ledger_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
'amount' => $row->{'ChargeAmount'} });
}
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'}
= $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'};
$credit_ledger_id = $newdb{'lookup'}{'charge_type'}{'Tax'}{'ledger_id'};
if ($use_ir) {
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'amount' => $row->{'TaxAmount'},
'comment' => undef });
$ledger_entry_id = $newdb{'tables'}{'ledger_entries'}{'autoid'};
$credit_ledger_id = $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'};
}
addRow('ledger_entries',
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'},
'credit_ledger_id' => $credit_ledger_id,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'charge_type'}{'Tax'}{'ledger_id'},
'amount' => $row->{'TaxAmount'},
'comment' => undef });
foreach ($newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_statement_id'},
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_statement_id'}) {
addRow('statement_entries',
{ 'type' => 'CHARGE',
'statement_id' => $_,
'ledger_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
'amount' => $row->{'TaxAmount'} });
}
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_entry'}
= $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'}
}{'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
# 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.
@@ -1076,14 +1023,21 @@ foreach $row (@{query($sdbh, $query)})
{ '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'}{'charge'}{$row->{'ChargeID'}}{'ledger_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
#'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'amount' => 0,
'comment' => "Receipt: $row->{'ReceiptNum'}; " });
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
= $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'}[
@@ -1094,6 +1048,16 @@ foreach $row (@{query($sdbh, $query)})
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
]{'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
# payment to reference the true 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'])) {
$conditions[] =
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'])) {
$conditions[] =
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'])) {

View File

@@ -55,7 +55,7 @@ class UnitsController extends AppController {
$link = array
('link' =>
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);
}
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
* - Returns the ID of the named account
* function: Account IDs
* - 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 rentAccountID() { return $this->accountNameToID('Rent'); }
function accountReceivableAccountID() { return $this->accountNameToID('A/R'); }
function invoiceAccountID() { return $this->accountReceivableAccountID(); }
function receiptAccountID() { return $this->accountReceivableAccountID(); }
//function invoiceAccountID() { return $this->accountNameToID('Invoice'); }
//function receiptAccountID() { return $this->accountNameToID('Receipt'); }
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
function rentAccountID() { return $this->nameToID('Rent'); }
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
/**************************************************************************

View File

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

View File

@@ -26,6 +26,7 @@ class Lease extends AppModel {
'LeaseType',
'Unit',
'Customer',
'Statement',
'LateSchedule',
);
@@ -40,13 +41,23 @@ class Lease extends AppModel {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: accountId
* - Returns the accountId of the given lease
* function: accessors
*/
function accountId($id) {
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
*/
function findSecurityDeposits($id, $link = null) {
/* pr(array('function' => 'Lease::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* )); */
$entries = $this->Account->findLedgerEntriesRelatedToAccount
($this->accountId($id),
return $this->Statement->findEntriesRelatedToAccount
($this->statementId($id),
$this->Account->securityDepositAccountID(),
true, array('LedgerEntry.lease_id' => $id), $link);
/* pr(array('function' => 'Lease::findSecurityDeposits', */
/* 'args' => compact('id', 'link'), */
/* 'vars' => compact('lease'), */
/* 'return' => compact('entries'), */
/* )); */
return $entries;
null, $link);
}
@@ -142,16 +142,11 @@ class Lease extends AppModel {
* - Returns summary data from the requested lease.
*/
function stats($id = null) {
function stats($id = null, $cond = null, $link = null) {
if (!$id)
return null;
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
array('LedgerEntry.lease_id' => $id));
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats;
return $this->Statement->stats($this->statementID($id), $cond, $link);
}
}

View File

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

View File

@@ -47,9 +47,6 @@ else {
$cols['Debit Account'] = array('index' => 'DebitAccount.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['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150);

View File

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

View File

@@ -81,12 +81,12 @@ echo $this->element('table',
echo '<div class="infobox">' . "\n";
$rows = array();
if ($debit_ledger['Account']['trackable']) {
$rows[] = array('Debit Amount Reconciled:', FormatHelper::currency($stats['debit_amount_reconciled']));
$rows[] = array('Debit Amount Remaining:', FormatHelper::currency($stats['debit_amount_remaining']));
$rows[] = array('Payments Received:', FormatHelper::currency($stats['debit_amount_reconciled']));
$rows[] = array('Amount Owing:', FormatHelper::currency($stats['debit_amount_remaining']));
}
if ($credit_ledger['Account']['trackable']) {
$rows[] = array('Credit Amount Reconciled:', FormatHelper::currency($stats['credit_amount_reconciled']));
$rows[] = array('Credit Amount Remaining:', FormatHelper::currency($stats['credit_amount_remaining']));
$rows[] = array('Charges Reconciled:', FormatHelper::currency($stats['credit_amount_reconciled']));
$rows[] = array('Unapplied Amount:', FormatHelper::currency($stats['credit_amount_remaining']));
}
echo $this->element('table',
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',
array('caption' => ('Current Lease Account (' .
$unit['CurrentLease']['Customer']['name']
. ')'),
'ar_account' => true,
'lease_id' => $unit['CurrentLease']['id'],
echo $this->element('statement_entries',
array('caption' => ('Current Lease Statement (' .
$unit['CurrentLease']['Customer']['name'] .
')'),
'statement_id' => $unit['CurrentLease']['statement_id']
));