Charge/Invoice assessment is working fairly well. Still need to accept multiple charges on a single invoice, have client side validation, and post through ajax to allow posting repeated invoices.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@236 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -174,15 +174,6 @@ class LeasesController extends AppController {
|
||||
*/
|
||||
|
||||
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
|
||||
@@ -206,11 +197,16 @@ class LeasesController extends AppController {
|
||||
$charge['type'] = $type;
|
||||
if ($type == 'rent')
|
||||
$charge['amount'] = $lease['Lease']['rent'];
|
||||
else
|
||||
elseif ($type == 'rent')
|
||||
// REVISIT <AP> 20090705:
|
||||
// Of course, the late charge should come from the late_schedule
|
||||
$charge['amount'] = 10.00;
|
||||
|
||||
$redirect = array('controller' => 'leases',
|
||||
'action' => 'view',
|
||||
$id);
|
||||
$this->set(compact('redirect'));
|
||||
|
||||
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||
$lease['Unit']['name'] . ': ' .
|
||||
$lease['Customer']['name'] . ': Assess Charges');
|
||||
|
||||
@@ -109,8 +109,6 @@ class TransactionsController extends AppController {
|
||||
return;
|
||||
}
|
||||
|
||||
pr($this->data);
|
||||
|
||||
/* $this->layout = null; */
|
||||
/* $this->autoLayout = false; */
|
||||
/* $this->autoRender = false; */
|
||||
@@ -123,7 +121,6 @@ class TransactionsController extends AppController {
|
||||
if(empty($this->data['Transaction']['stamp'])) {
|
||||
die("Time/Date not valid");
|
||||
}
|
||||
pr($this->data['Transaction']);
|
||||
|
||||
// Create some models for convenience
|
||||
$A = new Account();
|
||||
@@ -139,13 +136,9 @@ class TransactionsController extends AppController {
|
||||
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();
|
||||
@@ -153,18 +146,13 @@ class TransactionsController extends AppController {
|
||||
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;
|
||||
@@ -200,12 +188,9 @@ class TransactionsController extends AppController {
|
||||
$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'];
|
||||
}
|
||||
@@ -225,12 +210,8 @@ class TransactionsController extends AppController {
|
||||
$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
|
||||
@@ -243,13 +224,13 @@ class TransactionsController extends AppController {
|
||||
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);
|
||||
|
||||
// Comment this out to debug
|
||||
$this->redirect($this->data['redirect']);
|
||||
|
||||
pr($this->data['redirect']);
|
||||
$this->render('/empty');
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,41 @@ $lease_grid_setup['onHeaderClick'] = array
|
||||
function resetForm() {
|
||||
$("#lease-entry-id").val(0);
|
||||
$("#lease-lease").html("INTERNAL ERROR");
|
||||
|
||||
datepickerNow('charge_date');
|
||||
$("#through_date").val('');
|
||||
}
|
||||
|
||||
function datepickerNow(id) {
|
||||
now = new Date();
|
||||
// datepicker seems to squash the time portion,
|
||||
// so we have to pass in a copy of now instead.
|
||||
$("#"+id).datepicker('setDate', new Date(now));
|
||||
$("#"+id).val($("#"+id).val()
|
||||
+ ' '
|
||||
+ (now.getHours() < 10 ? '0' : '')
|
||||
+ now.getHours() + ':'
|
||||
+ (now.getMinutes() < 10 ? '0' : '')
|
||||
+ now.getMinutes());
|
||||
}
|
||||
function datepickerSet(fromid, id, a, b) {
|
||||
if (fromid == null)
|
||||
dt = new Date();
|
||||
else
|
||||
dt = new Date($("#"+fromid).datepicker('getDate'));
|
||||
|
||||
if (a != null)
|
||||
dt.setDate(a);
|
||||
if (b != null)
|
||||
dt.setDate(b);
|
||||
|
||||
$("#"+id).datepicker('setDate', dt);
|
||||
}
|
||||
function datepickerBOM(fromid, id) {
|
||||
datepickerSet(fromid, id, 1);
|
||||
}
|
||||
function datepickerEOM(fromid, id) {
|
||||
datepickerSet(fromid, id, 32, 0);
|
||||
}
|
||||
|
||||
function onRowSelect(grid_id, lease_id) {
|
||||
@@ -47,6 +82,9 @@ function onRowSelect(grid_id, lease_id) {
|
||||
+ $(grid_id).getCell(lease_id, 'Unit-name')
|
||||
);
|
||||
|
||||
if ($("#redirectController").val() == 'leases')
|
||||
$("#redirect0").val(lease_id);
|
||||
|
||||
// Hide the "no lease" message and show the current lease
|
||||
$("#no-lease").hide();
|
||||
$("#current-lease").show();
|
||||
@@ -102,41 +140,77 @@ echo $form->input("Lease.id",
|
||||
|
||||
echo $this->element('form_table',
|
||||
array('class' => "item assess entry",
|
||||
//'with_name_after' => ':',
|
||||
'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' =>
|
||||
("stamp" => array('opts' =>
|
||||
array('id' => 'charge_date',
|
||||
'type' => 'text'),
|
||||
'between' => '<A HREF="#" ONCLICK="datepickerNow(\'charge_date\'); return false;">Now</A>',
|
||||
),
|
||||
"through_date" => array('opts' =>
|
||||
array('id' => 'through_date',
|
||||
'type' => 'text'),
|
||||
'between' => '<A HREF="#" ONCLICK="datepickerEOM(\'charge_date\',\'through_date\'); return false;">EOM</A>',
|
||||
),
|
||||
"comment" => array('opts' => array('size' => 50),
|
||||
),
|
||||
)));
|
||||
|
||||
echo ('<BR>' . "\n");
|
||||
echo $this->element('form_table',
|
||||
array('class' => "item assess entry",
|
||||
//'with_name_after' => ':',
|
||||
'field_prefix' => 'LedgerEntry.0',
|
||||
'fields' => array
|
||||
("charge_type" => array('opts' =>
|
||||
array('options' =>
|
||||
array('rent' => 'Rent',
|
||||
'late' => 'Late Charge'),
|
||||
'value' => $charge['type'])),
|
||||
"amount" => array('prefix' => 'LedgerEntry.0',
|
||||
'opts' =>
|
||||
array('value' => $charge['amount'])),
|
||||
'value' =>
|
||||
(isset($charge['type'])
|
||||
? $charge['type']
|
||||
: null)
|
||||
),
|
||||
),
|
||||
"amount" => array('opts' =>
|
||||
array('value' =>
|
||||
(isset($charge['amount'])
|
||||
? $charge['amount']
|
||||
: null)
|
||||
),
|
||||
),
|
||||
"comment" => array('opts' => array('size' => 50)),
|
||||
)));
|
||||
|
||||
|
||||
// Set up a redirect page. I use lower case 'redirect' here
|
||||
// to avoid the model convention, which starts with upper-case.
|
||||
foreach ($redirect AS $name => $value) {
|
||||
echo $form->input("redirect.$name",
|
||||
array('type' => 'hidden',
|
||||
'value' => $value,
|
||||
));
|
||||
}
|
||||
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');
|
||||
$("#charge_date")
|
||||
.attr('autocomplete', 'off')
|
||||
.datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' });
|
||||
|
||||
$("#through_date").datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' })
|
||||
;
|
||||
$("#through_date")
|
||||
.attr('autocomplete', 'off')
|
||||
.datepicker({ constrainInput: true,
|
||||
numberOfMonths: [1, 1],
|
||||
showCurrentAtPos: 0,
|
||||
dateFormat: 'mm/dd/yy' });
|
||||
|
||||
resetForm();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user