First pass at entering charges for a lease. This works, but does not have the ability to add multiple charges, and does not mirror the payment method, which is ajax based.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@231 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -40,6 +40,7 @@ class AppModel extends Model {
|
||||
|
||||
var $actsAs = array('Containable', 'Linkable');
|
||||
var $useNullForEmpty = true;
|
||||
var $dateFields = array();
|
||||
|
||||
/**
|
||||
* Get Enum Values
|
||||
@@ -155,6 +156,17 @@ class AppModel extends Model {
|
||||
// override the behavior, or set useNullForEmpty to false.
|
||||
if ($this->useNullForEmpty)
|
||||
$this->recursive_array_replace("/^\s*$/", null, $this->data);
|
||||
|
||||
foreach ($this->dateFields AS $field) {
|
||||
/* if(isset($this->data['Transaction']['stamp']) && */
|
||||
/* $this->data['Transaction']['stamp'] !== 'CURRENT_TIMESTAMP') { */
|
||||
/* $this->data['Transaction']['stamp'] = */
|
||||
/* $this->dateFormatBeforeSave($this->data['Transaction']['stamp']); */
|
||||
/* } */
|
||||
/* else { */
|
||||
/* $this->data['Transaction']['stamp'] = null; */
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class LeasesController extends AppController {
|
||||
function move_out($id = null) {
|
||||
if ($this->data) {
|
||||
// Handle the move out based on the data given
|
||||
pr($this->data);
|
||||
//pr($this->data);
|
||||
|
||||
$this->Lease->moveOut($this->data['Lease']['id']);
|
||||
$this->redirect($this->data['redirect']);
|
||||
@@ -166,6 +166,58 @@ class LeasesController extends AppController {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: assess
|
||||
* - Assesses charges to the lease
|
||||
*/
|
||||
|
||||
function assess($id = null, $type = null) {
|
||||
if ($this->data) {
|
||||
// Assess the charges based on the given data
|
||||
pr($this->data);
|
||||
|
||||
$this->Lease->addCharge($this->data['Lease']['id'], $this->data['Charge']);
|
||||
//$this->redirect($this->data['redirect']);
|
||||
$this->render('/empty');
|
||||
return;
|
||||
}
|
||||
|
||||
$lease = $this->Lease->find
|
||||
('first', array
|
||||
('contain' => array
|
||||
(// Models
|
||||
'Unit' =>
|
||||
array('order' => array('sort_order'),
|
||||
'fields' => array('id', 'name'),
|
||||
),
|
||||
|
||||
'Customer' =>
|
||||
array('fields' => array('id', 'name'),
|
||||
),
|
||||
),
|
||||
|
||||
'conditions' => array(array('Lease.id' => $id),
|
||||
array('Lease.close_date' => null),
|
||||
),
|
||||
));
|
||||
|
||||
$charge['type'] = $type;
|
||||
if ($type == 'rent')
|
||||
$charge['amount'] = $lease['Lease']['rent'];
|
||||
else
|
||||
// REVISIT <AP> 20090705:
|
||||
// Of course, the late charge should come from the late_schedule
|
||||
$charge['amount'] = 10.00;
|
||||
|
||||
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||
$lease['Unit']['name'] . ': ' .
|
||||
$lease['Customer']['name'] . ': Assess Charges');
|
||||
$this->set(compact('title', 'lease', 'charge'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -206,6 +258,14 @@ class LeasesController extends AppController {
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Operations', 'header' => true);
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Assess Rent', 'url' => array('action' => 'assess',
|
||||
$id, 'rent'));
|
||||
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Assess Late Charge', 'url' => array('action' => 'assess',
|
||||
$id, 'late'));
|
||||
|
||||
if (!isset($lease['Lease']['moveout_date'])) {
|
||||
$this->sidemenu_links[] =
|
||||
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
|
||||
|
||||
@@ -95,6 +95,165 @@ class TransactionsController extends AppController {
|
||||
$this->set(compact('transaction', 'title', 'total'));
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* action: postInvoice
|
||||
* - handles the creation of a charge invoice
|
||||
*/
|
||||
|
||||
function postInvoice() {
|
||||
if (!$this->RequestHandler->isPost()) {
|
||||
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
||||
return;
|
||||
}
|
||||
|
||||
pr($this->data);
|
||||
|
||||
/* $this->layout = null; */
|
||||
/* $this->autoLayout = false; */
|
||||
/* $this->autoRender = false; */
|
||||
/* Configure::write('debug', '0'); */
|
||||
|
||||
// Sanitize the transaction data
|
||||
if (!$this->data['Transaction']['comment'])
|
||||
$this->data['Transaction']['comment'] = null;
|
||||
|
||||
if(empty($this->data['Transaction']['stamp'])) {
|
||||
die("Time/Date not valid");
|
||||
}
|
||||
pr($this->data['Transaction']);
|
||||
|
||||
// Create some models for convenience
|
||||
$A = new Account();
|
||||
$C = new Customer();
|
||||
$L = new Lease();
|
||||
|
||||
$L->recursive = -1;
|
||||
$lease = $L->read(null, $this->data['Lease']['id']);
|
||||
|
||||
// Create a transaction for the invoice
|
||||
$invoice_transaction = new Transaction();
|
||||
$invoice_transaction->create();
|
||||
if (!$invoice_transaction->save($this->data['Transaction'],
|
||||
array('validate' => false,
|
||||
))) {
|
||||
pr(array('checkpoint' => "invoice transaction save failed"));
|
||||
return;
|
||||
die("Unknown Database Failure");
|
||||
}
|
||||
pr("New Transaction Created ({$invoice_transaction->id})!");
|
||||
$invoice_transaction->read();
|
||||
pr($invoice_transaction->data);
|
||||
|
||||
// Create a transaction for the A/R
|
||||
$ar_transaction = new Transaction();
|
||||
$ar_transaction->create();
|
||||
if (!$ar_transaction->save($this->data['Transaction'],
|
||||
array('validate' => false,
|
||||
))) {
|
||||
pr(array('checkpoint' => "A/R transaction save failed"));
|
||||
die("Unknown Database Failure");
|
||||
}
|
||||
pr("New Transaction Created ({$ar_transaction->id})!");
|
||||
$ar_transaction->read();
|
||||
pr($ar_transaction->data);
|
||||
|
||||
// Go through the entered charges
|
||||
$grand_total = 0;
|
||||
foreach ($this->data['LedgerEntry'] AS &$entry) {
|
||||
pr(compact('entry'));
|
||||
|
||||
// Invoice Transaction
|
||||
// debit: Invoice credit: Charge
|
||||
$entry['transaction_id'] = $invoice_transaction->id;
|
||||
|
||||
// Invoice must debit the "invoice" asset...
|
||||
$entry['debit_ledger_id']
|
||||
= $A->currentLedgerID($A->invoiceAccountID());
|
||||
|
||||
// ...and credit the charge ledger
|
||||
// REVISIT <AP> 20090706
|
||||
// The charge page should have a list of all income types
|
||||
// and thus the field _should_ contain a valid account
|
||||
// name. At the moment, however, I'm still cobbling things
|
||||
// together, and only have two types.
|
||||
/* $entry['credit_ledger_id'] */
|
||||
/* = $A->currentLedgerID($A->nameToID($entry['charge_account'])); */
|
||||
if ($entry['charge_type'] === 'rent') {
|
||||
$entry['credit_ledger_id']
|
||||
= $A->currentLedgerID($A->rentAccountID());
|
||||
} elseif ($entry['charge_type'] === 'late') {
|
||||
$entry['credit_ledger_id']
|
||||
= $A->currentLedgerID($A->lateChargeAccountID());
|
||||
} else {
|
||||
die("Invalid charge account");
|
||||
}
|
||||
|
||||
$entry['customer_id']
|
||||
= $lease['Lease']['customer_id'];
|
||||
$entry['lease_id']
|
||||
= $lease['Lease']['id'];
|
||||
|
||||
// Create it
|
||||
$invoice_entry = new LedgerEntry();
|
||||
$invoice_entry->create();
|
||||
if (!$invoice_entry->save($entry, false)) {
|
||||
pr(array('checkpoint' => "invoice entry saveAll failed"));
|
||||
die("Unknown Database Failure");
|
||||
}
|
||||
pr("New Invoice LedgerEntry Created ({$invoice_entry->id})!");
|
||||
$invoice_entry->read();
|
||||
pr($invoice_entry->data);
|
||||
|
||||
$grand_total += $entry['amount'];
|
||||
}
|
||||
|
||||
// Create an account receivable entry
|
||||
// debit: A/R credit: Invoice
|
||||
$ar_entry_data = array
|
||||
('debit_ledger_id' => $A->currentLedgerID($A->accountReceivableAccountID()),
|
||||
'credit_ledger_id' => $A->currentLedgerID($A->invoiceAccountID()),
|
||||
'transaction_id' => $ar_transaction->id,
|
||||
'amount' => $grand_total,
|
||||
'lease_id' => $lease['Lease']['id'],
|
||||
'customer_id' => $lease['Lease']['customer_id'],
|
||||
);
|
||||
|
||||
// Create a new A/R entry from the data
|
||||
$ar_entry = new LedgerEntry();
|
||||
$ar_entry->create();
|
||||
if (!$ar_entry->save($ar_entry_data, false)) {
|
||||
pr(array('checkpoint' => "ar entry save failed"));
|
||||
die("Unknown Database Failure");
|
||||
}
|
||||
pr("New A/R LedgerEntry Created ({$ar_entry->id})!");
|
||||
$ar_entry->read();
|
||||
pr($ar_entry->data);
|
||||
|
||||
// Reconcile the Invoice account. Our two entries look like:
|
||||
// debit: Invoice credit: Charge
|
||||
// debit: A/R credit: Invoice
|
||||
// Since this is from the perspective of the Invoice account,
|
||||
// the credit entry is the Invoice<->A/R, and the debit
|
||||
// entry is the actual invoice ledger entry.
|
||||
$R = new Reconciliation();
|
||||
$R->create();
|
||||
if (!$R->save(array('debit_ledger_entry_id' => $invoice_entry->id,
|
||||
'credit_ledger_entry_id' => $ar_entry->id,
|
||||
'amount' => $grand_total), false)) {
|
||||
pr(array('checkpoint' => "invoice reconcile save failed"));
|
||||
die("Unknown Database Failure");
|
||||
}
|
||||
pr("New Invoice Reconciliation Created ({$R->id})!");
|
||||
$R->read();
|
||||
pr($R->data);
|
||||
|
||||
$this->render('/empty');
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -94,6 +94,7 @@ class Account extends AppModel {
|
||||
|
||||
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
|
||||
function rentAccountID() { return $this->nameToID('Rent'); }
|
||||
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
||||
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
||||
|
||||
@@ -266,6 +266,19 @@ class Lease extends AppModel {
|
||||
$this->Unit->updateStatus($this->data['Lease']['unit_id'], $status);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: addCharge
|
||||
* - Adds an additional charge to the lease
|
||||
*/
|
||||
|
||||
function addCharge($id, $charge) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -25,7 +25,7 @@ class Transaction extends AppModel {
|
||||
$this->data['Transaction']['stamp'] = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
return parent::beforeSave();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ foreach ($fields AS $field => $config) {
|
||||
if (!isset($config['opts']))
|
||||
$config['opts'] = null;
|
||||
|
||||
if (isset($field_prefix) && !isset($config['no_prefix']))
|
||||
if (isset($config['prefix']) && !isset($config['no_prefix']))
|
||||
$field = $config['prefix'] . '.' . $field;
|
||||
elseif (isset($field_prefix) && !isset($config['no_prefix']))
|
||||
$field = $field_prefix . '.' . $field;
|
||||
|
||||
$config['opts']['label'] = false;
|
||||
|
||||
155
site/views/leases/assess.ctp
Normal file
155
site/views/leases/assess.ctp
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php /* -*- mode:PHP -*- */ ?>
|
||||
|
||||
<div class="assess input">
|
||||
<?php
|
||||
; // Editor alignment
|
||||
|
||||
/**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
**********************************************************************
|
||||
*
|
||||
*/
|
||||
|
||||
$lease_grid_setup = array();
|
||||
|
||||
if (isset($lease['Lease']['id']))
|
||||
$lease_grid_setup['hiddengrid'] = true;
|
||||
|
||||
$lease_grid_setup['onSelectRow'] = array
|
||||
('--special' =>
|
||||
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
|
||||
);
|
||||
|
||||
$lease_grid_setup['onHeaderClick'] = array
|
||||
('--special' =>
|
||||
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
|
||||
);
|
||||
|
||||
?>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
|
||||
// Reset the form
|
||||
function resetForm() {
|
||||
$("#lease-entry-id").val(0);
|
||||
$("#lease-lease").html("INTERNAL ERROR");
|
||||
}
|
||||
|
||||
function onRowSelect(grid_id, lease_id) {
|
||||
// Set the item id that will be returned with the form
|
||||
$("#lease-id").val(lease_id);
|
||||
|
||||
// Get the item name from the grid
|
||||
$("#lease-lease").html('Lease '
|
||||
+ $(grid_id).getCell(lease_id, 'Lease-number')
|
||||
+ ' / Unit '
|
||||
+ $(grid_id).getCell(lease_id, 'Unit-name')
|
||||
);
|
||||
|
||||
// Hide the "no lease" message and show the current lease
|
||||
$("#no-lease").hide();
|
||||
$("#current-lease").show();
|
||||
|
||||
$("#leases-list .HeaderButton").click();
|
||||
}
|
||||
|
||||
function onGridState(grid_id, state) {
|
||||
if (state == 'visible') {
|
||||
$("#no-lease").hide();
|
||||
$("#current-lease").hide();
|
||||
}
|
||||
else {
|
||||
if ($("#lease-id").val() > 0) {
|
||||
$("#current-lease").show();
|
||||
$("#no-lease").hide();
|
||||
} else {
|
||||
$("#current-lease").hide();
|
||||
$("#no-lease").show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--></script>
|
||||
|
||||
<?php
|
||||
; // align
|
||||
|
||||
echo $this->element('leases',
|
||||
array('grid_div_id' => 'leases-list',
|
||||
'grid_div_class' => 'text-below',
|
||||
'caption' => ('<A HREF="#" ONCLICK="$(\'#leases-list .HeaderButton\').click();'.
|
||||
' return false;">Select Lease</A>'),
|
||||
'grid_setup' => $lease_grid_setup,
|
||||
'nolinks' => true,
|
||||
'limit' => 10,
|
||||
));
|
||||
|
||||
echo ('<H2>' .
|
||||
'<SPAN id="current-lease">Lease: <SPAN id="lease-lease"></SPAN></SPAN>' .
|
||||
'<SPAN id="no-lease">Please select lease</SPAN>' .
|
||||
'</H2>' . "\n");
|
||||
|
||||
|
||||
echo $form->create(null, array('id' => 'assess-form',
|
||||
'url' => array('controller' => 'transactions',
|
||||
'action' => 'postInvoice')));
|
||||
|
||||
echo $form->input("Lease.id",
|
||||
array('id' => 'lease-id',
|
||||
'type' => 'hidden',
|
||||
'value' => 0));
|
||||
|
||||
echo $this->element('form_table',
|
||||
array('class' => "item assess entry",
|
||||
'field_prefix' => 'Transaction',
|
||||
'fields' => array
|
||||
("stamp" => array('opts' => array('id' => 'charge_date',
|
||||
'type' => 'text')),
|
||||
"through_date" => array('opts' => array('id' => 'through_date',
|
||||
'type' => 'text')),
|
||||
"charge_type" => array('prefix' => 'LedgerEntry.0',
|
||||
'opts' =>
|
||||
array('options' =>
|
||||
array('rent' => 'Rent',
|
||||
'late' => 'Late Charge'),
|
||||
'value' => $charge['type'])),
|
||||
"amount" => array('prefix' => 'LedgerEntry.0',
|
||||
'opts' =>
|
||||
array('value' => $charge['amount'])),
|
||||
"comment" => array('opts' => array('size' => 50)),
|
||||
)));
|
||||
|
||||
echo $form->end('Assess Charge');
|
||||
|
||||
?>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
$(document).ready(function(){
|
||||
$("#charge_date").datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' })
|
||||
.datepicker('setDate', '+0');
|
||||
|
||||
$("#through_date").datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' })
|
||||
;
|
||||
|
||||
resetForm();
|
||||
|
||||
<?php if (isset($lease['Lease']['id'])): ?>
|
||||
$("#lease-id").val(<?php echo $lease['Lease']['id']; ?>);
|
||||
$("#lease-lease").html("<?php echo 'Lease #' . $lease['Lease']['number'] . ' / Unit ' . $lease['Unit']['name']; ?>");
|
||||
$("#current-lease").show();
|
||||
$("#no-lease").hide();
|
||||
<?php else: ?>
|
||||
$("#current-lease").hide();
|
||||
$("#no-lease").hide();
|
||||
<?php endif; ?>
|
||||
});
|
||||
--></script>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user