Many bug fixes, found while entering real facility data. Most are quite minor, although there was a functionality change to assignCredits, to support concessions without assigning them to anything other than rent. I've found that there is a glaring problem with charge reversals, which don't work correctly with the collected report. Of course, we're deleting prior disbursements, which obviously needs to be rectified.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@540 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-12 09:37:49 +00:00
parent e33741f579
commit f9ff27cad4
14 changed files with 119 additions and 137 deletions

View File

@@ -52,7 +52,7 @@ class AppController extends Controller {
array('onclick' => '$(".pr-section").show(); return false;')), array('onclick' => '$(".pr-section").show(); return false;')),
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')), array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')), array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')),
//array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')), array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')),
//array('name' => 'RESET DATA', 'url' => array('controller' => 'accounts', 'action' => 'reset_data')), //array('name' => 'RESET DATA', 'url' => array('controller' => 'accounts', 'action' => 'reset_data')),
); );
} }

View File

@@ -171,9 +171,7 @@ class LeasesController extends AppController {
$this->Lease->moveOut($this->data['Lease']['id'], $this->Lease->moveOut($this->data['Lease']['id'],
'VACANT', 'VACANT',
$this->data['Lease']['moveout_date'], $this->data['Lease']['moveout_date']
//true // Close this lease, if able
false
); );
$this->redirect($this->data['redirect']); $this->redirect($this->data['redirect']);
@@ -418,9 +416,11 @@ class LeasesController extends AppController {
function assess_rent($date = null) { function assess_rent($date = null) {
$this->Lease->assessMonthlyRentAll($date); $this->Lease->assessMonthlyRentAll($date);
$this->redirect(array('action'=>'index'));
} }
function assess_late($date = null) { function assess_late($date = null) {
$this->Lease->assessMonthlyLateAll($date); $this->Lease->assessMonthlyLateAll($date);
$this->redirect(array('action'=>'index'));
} }

View File

@@ -349,8 +349,6 @@ class TransactionsController extends AppController {
die("<H1>REFUND FAILED</H1>"); die("<H1>REFUND FAILED</H1>");
} }
$this->render('/fake');
// Return to viewing the lease/customer // Return to viewing the lease/customer
if (empty($data['Lease']['id'])) if (empty($data['Lease']['id']))
$this->redirect(array('controller' => 'customers', $this->redirect(array('controller' => 'customers',
@@ -388,7 +386,9 @@ class TransactionsController extends AppController {
'conditions' => array(array('Transaction.id' => $id), 'conditions' => array(array('Transaction.id' => $id),
// REVISIT <AP>: 20090811 // REVISIT <AP>: 20090811
// No security issues have been worked out yet // No security issues have been worked out yet
array('Account.level >=' => 5), array('OR' =>
array(array('Account.level >=' => 5),
array('Account.id' => null))),
), ),
)); ));

View File

@@ -256,13 +256,13 @@ class UnitsController extends AppController {
if (isset($unit['CurrentLease']['id']) && if (isset($unit['CurrentLease']['id']) &&
!isset($unit['CurrentLease']['close_date'])) { !isset($unit['CurrentLease']['close_date'])) {
$this->sidemenu_links[] = $this->sidemenu_links[] =
array('name' => 'Charge', 'url' => array('controller' => 'leases', array('name' => 'New Invoice', 'url' => array('controller' => 'leases',
'action' => 'invoice', 'action' => 'invoice',
$unit['CurrentLease']['id'])); $unit['CurrentLease']['id']));
$this->sidemenu_links[] = $this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('controller' => 'customers', array('name' => 'New Receipt', 'url' => array('controller' => 'customers',
'action' => 'receipt', 'action' => 'receipt',
$unit['CurrentLease']['customer_id'])); $unit['CurrentLease']['customer_id']));
} }
// Prepare to render. // Prepare to render.

View File

@@ -142,10 +142,8 @@ class Customer extends AppModel {
continue; continue;
$I = new Contact(); $I = new Contact();
$I->create(); if (!$I->saveContact(null, array('Contact' => $contact)))
if (!$I->save($contact, false)) {
return false; return false;
}
$contact['id'] = $I->id; $contact['id'] = $I->id;
} }

View File

@@ -610,7 +610,7 @@ class Lease extends AppModel {
*/ */
function moveOut($id, $status = 'VACANT', function moveOut($id, $status = 'VACANT',
$stamp = null, $close = false) $stamp = null, $close = true)
{ {
$this->prEnter(compact('id', 'status', 'stamp', 'close')); $this->prEnter(compact('id', 'status', 'stamp', 'close'));

View File

@@ -252,7 +252,7 @@ class StatementEntry extends AppModel {
null, null,
null, null,
$tx['customer_id'], $tx['customer_id'],
$tx['lease_id'] null
); );
$this->pr(21, compact('result')); $this->pr(21, compact('result'));
$ret['assigned'][] = $result; $ret['assigned'][] = $result;
@@ -396,10 +396,11 @@ class StatementEntry extends AppModel {
// First, find all known credits, unless this call is to make // First, find all known credits, unless this call is to make
// credit adjustments to a specific charge // credit adjustments to a specific charge
// REVISIT <AP>: 20090806 if (empty($receipt_id)) {
// If the theory below is correct, we should only search for
// explicit credits if we don't have a receipt_id if (!empty($charge_ids))
if (empty($charge_ids)) { INTERNAL_ERROR("Charge IDs, yet no corresponding receipt");
$lquery = $query; $lquery = $query;
$lquery['conditions'][] = array('StatementEntry.type' => 'SURPLUS'); $lquery['conditions'][] = array('StatementEntry.type' => 'SURPLUS');
// REVISIT <AP>: 20090804 // REVISIT <AP>: 20090804
@@ -424,13 +425,7 @@ class StatementEntry extends AppModel {
"Credits Established"); "Credits Established");
} }
else { else {
if (empty($receipt_id)) // Next, establish credit from the newly added receipt
INTERNAL_ERROR("Can't make adjustments to a charge without a receipt ID.");
}
// Next, establish credit from the newly added receipt
$receipt_credit = null;
if (!empty($receipt_id)) {
$lquery = $lquery =
array('link' => array('link' =>
array('StatementEntry', array('StatementEntry',
@@ -447,13 +442,13 @@ class StatementEntry extends AppModel {
if (!$receipt_credit) if (!$receipt_credit)
INTERNAL_ERROR("Unable to locate receipt."); INTERNAL_ERROR("Unable to locate receipt.");
//$reconciled = $this->reconciledEntries($id);
$stats = $this->Transaction->stats($receipt_id); $stats = $this->Transaction->stats($receipt_id);
$receipt_credit['balance'] = $receipt_credit['balance'] =
$receipt_credit['Transaction']['amount'] - $stats['Disbursement']['total']; $receipt_credit['Transaction']['amount'] - $stats['Disbursement']['total'];
$this->pr(18, compact('receipt_credit'), $receipt_credit['receipt'] = true;
$credits = array($receipt_credit);
$this->pr(18, compact('credits'),
"Receipt Credit Added"); "Receipt Credit Added");
} }
@@ -476,44 +471,22 @@ class StatementEntry extends AppModel {
$this->pr(18, compact('dtype', 'entries'), "Outstanding Debit Entries"); $this->pr(18, compact('dtype', 'entries'), "Outstanding Debit Entries");
} }
// Initialize our list of used credits
$used_credits = array();
// REVISIT <AP>: 20090806
// Testing a theory. We should never have
// explicit credits, as well as a new receipt,
// and yet have outstanding charges.
if (!empty($credits) && !empty($receipt_credit) && !empty($charges))
INTERNAL_ERROR("Explicit credits that haven't already been applied.");
// Work through all unpaid charges, applying disbursements as we go // Work through all unpaid charges, applying disbursements as we go
foreach ($charges AS $charge) { foreach ($charges AS $charge) {
$this->pr(20, compact('charge'), $this->pr(20, compact('charge'),
'Process Charge'); 'Process Charge');
// Check that we have available credits.
// Technically, this isn't necessary, since the loop
// will handle everything just fine. However, this
// just saves extra processing if/when there is no
// means to resolve a charge anyway.
if (empty($credits) && empty($receipt_credit['balance'])) {
$this->pr(17, 'No more available credits');
break;
}
$charge['balance'] = $charge['StatementEntry']['balance']; $charge['balance'] = $charge['StatementEntry']['balance'];
while ($charge['balance'] > 0 &&
(!empty($credits) || !empty($receipt_credit['balance']))) {
$this->pr(20, compact('charge'), // Use explicit credits before using the new receipt credit
'Attempt Charge Reconciliation'); foreach ($credits AS &$credit) {
if (empty($charge['balance']))
break;
if ($charge['balance'] < 0)
INTERNAL_ERROR("Negative Charge Balance");
// Use explicit credits before using implicit credits if (empty($credit['receipt'])) {
// (Not sure it matters though). // Explicit Credit
if (!empty($credits)) {
// Peel off the first credit available
$credit =& $credits[0];
$disbursement_date = $credit['StatementEntry']['effective_date']; $disbursement_date = $credit['StatementEntry']['effective_date'];
$disbursement_transaction_id = $credit['StatementEntry']['transaction_id']; $disbursement_transaction_id = $credit['StatementEntry']['transaction_id'];
$disbursement_account_id = $credit['StatementEntry']['account_id']; $disbursement_account_id = $credit['StatementEntry']['account_id'];
@@ -521,16 +494,29 @@ class StatementEntry extends AppModel {
if (!isset($credit['balance'])) if (!isset($credit['balance']))
$credit['balance'] = $credit['StatementEntry']['amount']; $credit['balance'] = $credit['StatementEntry']['amount'];
} }
elseif (!empty($receipt_credit['balance'])) { else {
// Use our only receipt credit // Receipt Credit
$credit =& $receipt_credit;
$disbursement_date = $credit['Transaction']['stamp']; $disbursement_date = $credit['Transaction']['stamp'];
$disbursement_transaction_id = $credit['Transaction']['id']; $disbursement_transaction_id = $credit['Transaction']['id'];
$disbursement_account_id = $credit['LedgerEntry']['account_id']; $disbursement_account_id = $credit['LedgerEntry']['account_id'];
} }
else {
die("HOW DID WE GET HERE WITH NO SURPLUS?"); if (empty($credit['balance']))
} continue;
if ($credit['balance'] < 0)
INTERNAL_ERROR("Negative Credit Balance");
$this->pr(20, compact('charge'),
'Attempt Charge Reconciliation');
// REVISIT <AP>: 20090811
// Need to come up with a better strategy for handling
// concessions. For now, just restricting concessions
// to apply only towards rent will resolve the most
// predominant (or only) needed usage case.
if ($disbursement_account_id == $this->Account->concessionAccountID() &&
$charge['StatementEntry']['account_id'] != $this->Account->rentAccountID())
continue;
// Set the disbursement amount to the maximum amount // Set the disbursement amount to the maximum amount
// possible without exceeding the charge or credit balance // possible without exceeding the charge or credit balance
@@ -543,15 +529,7 @@ class StatementEntry extends AppModel {
$this->pr(20, compact('credit'), $this->pr(20, compact('credit'),
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') . ($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
(!empty($credits) ? ' Credit' : ' Receipt')); (empty($credit['receipt']) ? ' Credit' : ' Receipt'));
if ($credit['balance'] < 0)
die("HOW DID WE END UP WITH NEGATIVE SURPLUS BALANCE?");
// If we've exhausted the credit, get it out of the
// available credit pool (but keep track of it for later).
if ($credit['balance'] <= 0 && !empty($credits))
$used_credits[] = array_shift($credits);
// Add a disbursement that uses the available credit to pay the charge // Add a disbursement that uses the available credit to pay the charge
$disbursement = array('type' => $disbursement_type, $disbursement = array('type' => $disbursement_type,
@@ -581,67 +559,69 @@ class StatementEntry extends AppModel {
if ($charge['balance'] <= 0) if ($charge['balance'] <= 0)
$this->pr(20, 'Fully Paid Charge'); $this->pr(20, 'Fully Paid Charge');
} }
} }
// Partially used credits must be added to the used list $this->pr(18, compact('credits'),
if (isset($credits[0]['applied'])) 'Disbursements complete');
$used_credits[] = array_shift($credits);
$this->pr(18, compact('credits', 'used_credits', 'receipt_credit'),
'Disbursements added');
// Clean up any explicit credits that have been used // Clean up any explicit credits that have been used
foreach ($used_credits AS $credit) { foreach ($credits AS $credit) {
if ($credit['balance'] > 0) { if (empty($credit['receipt'])) {
$this->pr(20, compact('credit'), // Explicit Credit
'Update Credit Entry'); if (empty($credit['applied']))
continue;
$this->id = $credit['StatementEntry']['id']; if ($credit['balance'] > 0) {
$this->saveField('amount', $credit['balance']); $this->pr(20, compact('credit'),
'Update Credit Entry');
$this->id = $credit['StatementEntry']['id'];
$this->saveField('amount', $credit['balance']);
}
else {
$this->pr(20, compact('credit'),
'Delete Exhausted Credit Entry');
$this->del($credit['StatementEntry']['id'], false);
}
} }
else { else {
$this->pr(20, compact('credit'), // Receipt Credit
'Delete Exhausted Credit Entry'); if (empty($credit['balance']))
continue;
$this->del($credit['StatementEntry']['id'], false); // Convert non-exhausted receipt credit to an explicit one
} $explicit_credit = $this->find
} ('first', array('contain' => false,
'conditions' =>
array(array('transaction_id' => $credit['Transaction']['id']),
array('type' => 'SURPLUS')),
));
// Convert non-exhausted receipt credit to an explicit one if (empty($explicit_credit)) {
if (!empty($receipt_credit['balance'])) { $this->pr(18, compact('credit'),
$credit =& $receipt_credit; 'Create Explicit Credit');
$explicit_credit = $this->find $result = $this->addStatementEntry
('first', array('contain' => false, (array('type' => 'SURPLUS',
'conditions' => 'account_id' => $credit['LedgerEntry']['account_id'],
array(array('transaction_id' => $credit['Transaction']['id']), 'amount' => $credit['balance'],
array('type' => 'SURPLUS')), 'effective_date' => $credit['Transaction']['stamp'],
)); 'transaction_id' => $credit['Transaction']['id'],
'customer_id' => $customer_id,
if (empty($explicit_credit)) { 'lease_id' => $lease_id,
$this->pr(18, compact('credit'), ));
'Create Explicit Credit'); $ret['Credit'] = $result;
if ($result['error'])
$result = $this->addStatementEntry $ret['error'] = true;
(array('type' => 'SURPLUS', }
'account_id' => $credit['LedgerEntry']['account_id'], else {
'amount' => $credit['balance'], $this->pr(18, compact('explicit_credit', 'credit'),
'effective_date' => $credit['Transaction']['stamp'], 'Update Explicit Credit');
'transaction_id' => $credit['Transaction']['id'], $EC = new StatementEntry();
'customer_id' => $customer_id, $EC->id = $explicit_credit['StatementEntry']['id'];
'lease_id' => $lease_id, $EC->saveField('amount', $credit['balance']);
)); }
$ret['Credit'] = $result;
if ($result['error'])
$ret['error'] = true;
}
else {
$this->pr(18, compact('explicit_credit', 'credit'),
'Update Explicit Credit');
$EC = new StatementEntry();
$EC->id = $explicit_credit['StatementEntry']['id'];
$EC->saveField('amount', $credit['balance']);
} }
} }

View File

@@ -21,7 +21,7 @@ class Tender extends AppModel {
* - Performs any work needed before the save occurs * - Performs any work needed before the save occurs
*/ */
function afterSave() { function afterSave($created) {
// Come up with a (not necessarily unique) name for the tender. // Come up with a (not necessarily unique) name for the tender.
// For checks & money orders, this will be based on the check // For checks & money orders, this will be based on the check
// number. For other types of tender, we'll just use the // number. For other types of tender, we'll just use the
@@ -45,7 +45,7 @@ class Tender extends AppModel {
if ($newname !== $this->field('name')) if ($newname !== $this->field('name'))
$this->saveField('name', $newname); $this->saveField('name', $newname);
return parent::afterSave(); return parent::afterSave($created);
} }

View File

@@ -685,6 +685,7 @@ class Transaction extends AppModel {
// with the customer statement (charges, disbursements, credits, etc). // with the customer statement (charges, disbursements, credits, etc).
$bounce_result = $this->addDeposit $bounce_result = $this->addDeposit
(array('Transaction' => array('stamp' => $stamp, (array('Transaction' => array('stamp' => $stamp,
'type' => 'WITHDRAWAL',
'crdr' => 'CREDIT'), 'crdr' => 'CREDIT'),
'Entry' => array(array('tender_id' => null, 'Entry' => array(array('tender_id' => null,
'account_id' => $this->Account->nsfAccountID(), 'account_id' => $this->Account->nsfAccountID(),

View File

@@ -315,7 +315,7 @@ echo $this->element('statement_entries', array
'grid_setup' => array('hiddengrid' => true), 'grid_setup' => array('hiddengrid' => true),
'caption' => '<SPAN id="receipt-charges-caption"></SPAN>', 'caption' => '<SPAN id="receipt-charges-caption"></SPAN>',
'action' => 'idlist', 'action' => 'idlist',
'exclude' => array('Customer', 'Unit', 'Type', 'Debit', 'Credit'), 'exclude' => array('Customer', 'Type', 'Debit', 'Credit'),
'include' => array('Applied', 'Balance'), 'include' => array('Applied', 'Balance'),
'remap' => array('Applied' => 'Paid'), 'remap' => array('Applied' => 'Paid'),
'limit' => 8, 'limit' => 8,

View File

@@ -71,7 +71,7 @@ function showResponse(responseText, statusText) {
} }
// get a clean slate // get a clean slate
//resetForm(); resetForm();
} }
else { else {
$('#results').html('<H2>Failed to save invoice!</H2>'); $('#results').html('<H2>Failed to save invoice!</H2>');
@@ -331,6 +331,7 @@ Configure::write('debug', '0');
' value="<?php echo date('m/d/Y', $movein['time']); ?>">'); ' value="<?php echo date('m/d/Y', $movein['time']); ?>">');
$("#TransactionComment").val('Move-In Charges'); $("#TransactionComment").val('Move-In Charges');
<?php if (!empty($movein['deposit'])): ?>
id = addChargeSource(false); id = addChargeSource(false);
$('#Entry'+id+'Form').removeCol(2); $('#Entry'+id+'Form').removeCol(2);
$('#Entry'+id+'Form input, #Entry'+id+'Form select').attr('disabled', true); $('#Entry'+id+'Form input, #Entry'+id+'Form select').attr('disabled', true);
@@ -351,7 +352,7 @@ Configure::write('debug', '0');
' value="<?php echo FormatHelper::currency($movein['deposit']); ?>">'); ' value="<?php echo FormatHelper::currency($movein['deposit']); ?>">');
//$('#Entry'+id+'Comment').val('Move-In Security Deposit'); //$('#Entry'+id+'Comment').val('Move-In Security Deposit');
$('#Entry'+id+'Comment').removeAttr('disabled'); $('#Entry'+id+'Comment').removeAttr('disabled');
<?php endif; ?>
id = addChargeSource(false); id = addChargeSource(false);
$('#Entry'+id+'Form').removeCol(2); $('#Entry'+id+'Form').removeCol(2);
@@ -376,8 +377,7 @@ Configure::write('debug', '0');
('<input type="hidden"' + ('<input type="hidden"' +
' name="data[Entry]['+id+'][amount]"' + ' name="data[Entry]['+id+'][amount]"' +
' value="<?php echo FormatHelper::currency($movein['prorated_rent']); ?>">'); ' value="<?php echo FormatHelper::currency($movein['prorated_rent']); ?>">');
$('#Entry'+id+'Comment').val('Move-In Rent' $('#Entry'+id+'Comment').val("<?php echo($movein['prorated'] ? 'Move-In Rent (Prorated)' : ''); ?>");
<?php if ($movein['prorated']) echo "+ ' (Prorated)'" ?>);
$('#Entry'+id+'Comment').removeAttr('disabled'); $('#Entry'+id+'Comment').removeAttr('disabled');
<?php endif; ?> <?php endif; ?>

View File

@@ -128,7 +128,7 @@ if ($move_type !== 'out') {
), ),
'include' => array('Deposit'), 'include' => array('Deposit'),
'exclude' => array('Balance'), 'exclude' => array('Balance'),
'action' => 'unoccupied', 'action' => 'vacant',
'nolinks' => true, 'nolinks' => true,
'limit' => 10, 'limit' => 10,
))); )));

View File

@@ -30,7 +30,8 @@ foreach ($depositTypes AS $type) {
'separator' => '<BR>', 'separator' => '<BR>',
'onclick' => "switchSelection({$type['id']})", 'onclick' => "switchSelection({$type['id']})",
'legend' => false, 'legend' => false,
'value' => $type['stats']['undeposited'] > 0 ? 'all' : 'none', // REVISIT <AP>: 20080811; Make opt-in, or opt-out?
'value' => $type['stats']['undeposited'] > 0 ? 'none' : 'none',
'disabled' => $type['stats']['undeposited'] <= 0, 'disabled' => $type['stats']['undeposited'] <= 0,
'options' => $radioOptions, 'options' => $radioOptions,
)); ));

View File

@@ -87,6 +87,8 @@ if (isset($current_lease['id'])) {
'filter' => array('Lease.id' => $current_lease['id']), 'filter' => array('Lease.id' => $current_lease['id']),
'include' => array('Through'), 'include' => array('Through'),
'exclude' => array('Customer', 'Lease', 'Unit'), 'exclude' => array('Customer', 'Lease', 'Unit'),
'sort_column' => 'Effective',
'sort_order' => 'DESC',
))); )));
} }