Took some of the new learnings from invoice generation and put into receipt generations. Also moved some shared functions to pmgr.js, and renamed things for consistency.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@239 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-07 02:55:55 +00:00
parent 8491d81496
commit 807dc48375
7 changed files with 189 additions and 217 deletions

View File

@@ -251,7 +251,7 @@ class CustomersController extends AppController {
if ($show_payment) {
$this->sidemenu_links[] =
array('name' => 'Payment',
'url' => array('action' => 'payment',
'url' => array('action' => 'receipt',
$id));
}
@@ -352,11 +352,11 @@ class CustomersController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: payment
* - Sets up the payment entry page for the given customer.
* action: receipt
* - Sets up the receipt entry page for the given customer.
*/
function payment($id = null) {
function receipt($id = null) {
/* if (!$id) { */
/* $this->Session->setFlash(__('Invalid Item.', true)); */
/* $this->redirect(array('action'=>'index')); */
@@ -379,7 +379,7 @@ class CustomersController extends AppController {
$charges = array('balance' => 0, 'entry' => array());
}
$title = 'Payment Entry';
$title = ($customer['name'] . ': Payment Entry');
$this->set(compact('customer', 'charges', 'title'));
}

View File

@@ -169,11 +169,11 @@ class LeasesController extends AppController {
/**************************************************************************
**************************************************************************
**************************************************************************
* action: assess
* - Assesses charges to the lease
* action: invoice
* - Sets up the invoice entry page for the given customer.
*/
function assess($id = null, $type = null) {
function invoice($id = null, $type = null) {
$lease = $this->Lease->find
('first', array
@@ -209,7 +209,7 @@ class LeasesController extends AppController {
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
$lease['Unit']['name'] . ': ' .
$lease['Customer']['name'] . ': Assess Charges');
$lease['Customer']['name'] . ': Charge Entry');
$this->set(compact('title', 'lease', 'charge'));
}
@@ -255,11 +255,11 @@ class LeasesController extends AppController {
array('name' => 'Operations', 'header' => true);
$this->sidemenu_links[] =
array('name' => 'Assess Rent', 'url' => array('action' => 'assess',
array('name' => 'Assess Rent', 'url' => array('action' => 'invoice',
$id, 'rent'));
$this->sidemenu_links[] =
array('name' => 'Assess Late Charge', 'url' => array('action' => 'assess',
array('name' => 'Assess Late Charge', 'url' => array('action' => 'invoice',
$id, 'late'));
if (!isset($lease['Lease']['moveout_date'])) {
@@ -270,7 +270,7 @@ class LeasesController extends AppController {
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('controller' => 'customers',
'action' => 'payment',
'action' => 'receipt',
$lease['Customer']['id']));
}

View File

@@ -140,7 +140,7 @@ class TransactionsController extends AppController {
}
if (!$this->Transaction->addReceipt($this->data,
$this->data['customer_id'])) {
$this->data['Customer']['id'])) {
$this->Session->setFlash("RECEIPT FAILED", true);
// REVISIT <AP> 20090706:
// Until we can work out the session problems,

View File

@@ -222,8 +222,9 @@ class UnitsController extends AppController {
if (isset($unit['CurrentLease']['id']) &&
!isset($unit['CurrentLease']['close_date'])) {
$this->sidemenu_links[] =
array('name' => 'Payment', 'url' => array('action' => 'payment',
$id));
array('name' => 'Payment', 'url' => array('controller' => 'customers',
'action' => 'receipt',
$unit['CurrentLease']['customer_id']));
}
// Prepare to render.

View File

@@ -1,47 +1,6 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="payment input">
<?php
; // Editor alignment
/**********************************************************************
**********************************************************************
**********************************************************************
**********************************************************************
* Transaction Detail Main Section
*/
/* $rows = array(array('ID', $transaction['Transaction']['id']), */
/* array('Timestamp', FormatHelper::datetime($transaction['Transaction']['stamp'])), */
/* array('Through', FormatHelper::date($transaction['Transaction']['through_date'])), */
/* array('Due', FormatHelper::date($transaction['Transaction']['due_date'])), */
/* array('Comment', $transaction['Transaction']['comment'])); */
/* echo $this->element('table', */
/* array('class' => 'item transaction detail', */
/* 'caption' => 'Transaction Detail', */
/* 'rows' => $rows, */
/* 'column_class' => array('field', 'value'))); */
/**********************************************************************
* Transaction Info Box
*/
?>
<!--
<DIV CLASS="infobox">
<DIV CLASS="summary grand total">
Total: <?php /*echo FormatHelper::currency($total);*/ ?>
</DIV>
</DIV>
-->
<div class="receipt input">
<?php
; // Editor alignment
@@ -49,7 +8,7 @@
**********************************************************************
**********************************************************************
**********************************************************************
*
* Grid Setup / Javascript
*/
$grid_setup = array();
@@ -62,6 +21,10 @@ $grid_setup['onSelectRow'] = array
'function(ids) { if (ids != null) { onRowSelect("#"+$(this).attr("id"), ids); } }'
);
$grid_setup['onHeaderClick'] = array
('--special' =>
'function(gridstate) { onGridState("#"+$(this).attr("id"), gridstate); }'
);
// Customer
// Outstanding balance
@@ -93,11 +56,8 @@ $grid_setup['onSelectRow'] = array
//timeout: 3000,
};
// get a clean slate
resetPaymentForm();
// bind form using 'ajaxForm'
$('#payment-form').ajaxForm(options);
$('#receipt-form').ajaxForm(options);
});
// pre-submit callback
@@ -132,7 +92,7 @@ $grid_setup['onSelectRow'] = array
if (statusText == 'success') {
// get a clean slate
//resetPaymentForm();
//resetForm();
}
else {
alert('not successful??');
@@ -142,27 +102,20 @@ $grid_setup['onSelectRow'] = array
$('#response-debug').html('<PRE>'+dump(statusText)+'</PRE>');
}
// Reset payment fields
function resetPaymentForm() {
// Get a clean slate for our payments
// Reset the form
function resetForm() {
$('#payment-entry-id').val(0);
$('#payments').html('');
$('#payment-id').val(0);
addPaymentSource(false);
datepickerNow();
}
function datepickerNow() {
now = new Date();
$("#datepicker").val($.datepicker.formatDate('mm/dd/yy', now)
+ ' '
+ (now.getHours() < 10 ? '0' : '')
+ now.getHours() + ':'
+ (now.getMinutes() < 10 ? '0' : '')
+ now.getMinutes());
$("#receipt-customer-id").html("INTERNAL ERROR");
$("#receipt-customer-name").html("INTERNAL ERROR");
addPaymentSource(false);
datepickerNow('TransactionStamp');
}
function addPaymentSource(flash) {
addDiv('payment-id', 'payment', 'payments', flash,
addDiv('payment-entry-id', 'payment', 'payments', flash,
// HTML section
'<FIELDSET CLASS="payment subset">' +
'<LEGEND>Payment #%{id} (%{remove})</LEGEND>' +
@@ -312,7 +265,6 @@ function updateChargesGrid(idlist, balance) {
function updateCharges(id) {
var url = '<?php echo ($html->url(array("controller" => $this->params["controller"],
"action" => "unreconciled"))); ?>';
//url += '/'+$("#customer-id").val();
url += '/'+id;
$.ajax({
@@ -331,21 +283,43 @@ function updateCharges(id) {
});
}
function onRowSelect(grid_id, cust_id) {
function onRowSelect(grid_id, customer_id) {
// Set the customer id that will be returned with the form
$("#customer-id").val(cust_id);
$("#customer-id").val(customer_id);
// Get the customer name from the grid
$("#payment_customer").html($(grid_id).getCell(cust_id, "Customer-name"));
// Get the item names from the grid
$("#receipt-customer-id").html($(grid_id).getCell(customer_id, 'Customer-id'));
$("#receipt-customer-name").html($(grid_id).getCell(customer_id, 'Customer-name'));
// Replace that with just the text portion of the hyperlink
$("#payment_customer").html($("#payment_customer a").html());
// Make sure the redirect is up to date, if necessary
if ($("#redirectController").val() == 'customers')
$("#redirect0").val(customer_id);
// Hide the "no customer" message and show the current customer
$("#no_customer").hide();
$("#current_customer").show();
$("#no-customer").hide();
$("#current-customer").show();
updateCharges(cust_id);
// Update the charges grid to reflect this customer
updateCharges(customer_id);
// Collapse the grid now that the user has selected
$("#customers-list .HeaderButton").click();
}
function onGridState(grid_id, state) {
if (state == 'visible') {
$("#no-customer").hide();
$("#current-customer").hide();
}
else {
if ($("#customer-id").val() > 0) {
$("#current-customer").show();
$("#no-customer").hide();
} else {
$("#current-customer").hide();
$("#no-customer").show();
}
}
}
--></script>
@@ -356,11 +330,24 @@ function onRowSelect(grid_id, cust_id) {
echo $this->element('customers',
array('grid_div_id' => 'customers-list',
'grid_div_class' => 'text-below',
'caption' => ('<A HREF="#" ONCLICK="$(\'#customers-list .HeaderButton\').click();'.
' return false;">Select Customer</A>'),
'grid_setup' => $grid_setup,
'nolinks' => true,
'limit' => 10,
));
echo ('<H2>' .
'<SPAN id="current-customer" style="display:none">' .
'Customer <SPAN id="receipt-customer-id"></SPAN>' .
': <SPAN id="receipt-customer-name"></SPAN>' .
'</SPAN>' .
'<SPAN id="no-customer" style="display:none">' .
'Please select customer' .
'</SPAN>' .
'</H2>' . "\n");
echo $this->element('ledger_entries',
array('grid_div_id' => 'charge-entries',
'caption' => 'Outstanding Charges',
@@ -369,107 +356,72 @@ echo $this->element('ledger_entries',
'limit' => 8,
));
echo ('<H2>' .
'<SPAN id="current_customer" style="display:'.(isset($customer['id'])?"inline":"none").'">' .
'Enter new receipt for ' .
'<SPAN id="payment_customer">' . (isset($customer['name']) ? $customer['name'] : "") . '</SPAN>' .
'</SPAN>' .
'<SPAN id="no_customer" style="display:'.(isset($customer['id'])?"none":"inline").'">' .
'Please select customer' .
'</SPAN>' .
'</H2>' . "\n");
echo $form->create(null, array('id' => 'payment-form',
echo $form->create(null, array('id' => 'receipt-form',
'url' => array('controller' => 'transactions',
'action' => 'postReceipt')));
/***************************************************
* Post data should look like this:
*
* data => Array
* (
* [Transaction] => Array
* (
* stamp => <Transaction Time Stamp>
* through_date => <Transaction Through Date, if any>
* due_date => <Transaction Due Date, if any>
* comment => <Transaction Comment>
* )
*
* [LedgerEntry] => Array
* (
* [0] => Array
* (
* name => <NOT TO INCLUDE??>
* amount => <Payment Amount>
* debit_ledger_id => <ID of the debit account's current ledger>
* credit_ledger_id => <ID of the debit account's current ledger>
* comment => <Ledger Entry Comment>
*
* [MonetarySource] => Array
* (
* name => <Name (may be useless parameter)>
* monetary_type_id => <Monetary Type ID>
* comment => <Monetary Source Comment>
* )
*
* REVISIT: Reconciliations will be tricker.
* )
*
* )
*
* )
*
***************************************************/
echo $form->input("id",
array('id' => 'customer-id',
'type' => 'hidden',
'value' => 0));
echo $this->element('form_table',
array('class' => "item receipt transaction entry",
//'with_name_after' => ':',
'field_prefix' => 'Transaction',
'fields' => array
("stamp" => array('opts' => array('type' => 'text'),
'between' => '<A HREF="#" ONCLICK="datepickerNow(\'TransactionStamp\'); return false;">Now</A>',
),
"comment" => array('opts' => array('size' => 50),
),
)));
echo $form->submit('Generate Receipt') . "\n";
?>
<input type="hidden" id="customer-id" name="data[customer_id]" value="<?php echo $customer['id']; ?>">
<fieldset CLASS="payment superset">
<legend>Payments</legend>
<input type="hidden" id="payment-id" value="0">
<input type="hidden" id="payment-entry-id" value="0">
<div id="payments"></div>
<fieldset> <legend>
<a href="#" onClick="addPaymentSource(true); return false;">Add Another Payment</a>
</legend> </fieldset>
</fieldset>
<?php
<?php echo $form->end('Generate Receipt'); ?>
echo 'Date: <input id="datepicker" name="data[Transaction][stamp]" type="text" />';
echo ' <A HREF="#" ONCLICK="datepickerNow(); return false;">Now</A><BR>' . "\n";
echo 'Comment: <input id="comment" name="data[Transaction][comment]" type="text" SIZE=80 /><BR>' . "\n";
echo $form->end('Post Payment');
//echo '</DIV>' . "\n"; // End of the dialog DIV
?>
<?php
/* <button id="post-payment" class="ui-button ui-state-default ui-corner-all">Create Payment</button> */
?>
<?php /* echo '</DIV>' . "\n"; // End of the dialog DIV */ ?>
<div><H4>Request</H4><div id="request-debug"></div></div>
<div><H4>Response</H4><div id="response-debug"></div></div>
<div><H4>Output</H4><div id="output-debug"></div></div>
<?php
?>
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker({ constrainInput: true,
$("#TransactionStamp")
.attr('autocomplete', 'off')
.datepicker({ constrainInput: true,
numberOfMonths: [1, 1],
showCurrentAtPos: 0,
dateFormat: 'mm/dd/yy' })
//.datepicker('setDate', '+0');
;
dateFormat: 'mm/dd/yy' });
<?php if (isset($customer['id'])) { ?>
resetForm();
<?php if (isset($customer['id'])): ?>
$("#customer-id").val(<?php echo $customer['id']; ?>);
$("#receipt-customer-id").html("<?php echo '#'.$customer['id']; ?>");
$("#receipt-customer-name").html("<?php echo $customer['name']; ?>");
updateChargesCaption("<?php echo $customer['name']; ?>",
<?php echo $charges['balance']; ?>);
<?php } ?>
<?php echo $charges['balance']; ?>
);
onGridState(null, 'hidden');
<?php else: ?>
onGridState(null, 'visible');
<?php endif; ?>
/* $("#dialog").dialog({ */

View File

@@ -1,6 +1,6 @@
<?php /* -*- mode:PHP -*- */ ?>
<div class="assess input">
<div class="invoice input">
<?php
; // Editor alignment
@@ -8,7 +8,7 @@
**********************************************************************
**********************************************************************
**********************************************************************
*
* Grid Setup / Javascript
*/
$lease_grid_setup = array();
@@ -32,56 +32,27 @@ $lease_grid_setup['onHeaderClick'] = array
// Reset the form
function resetForm() {
$("#lease-entry-id").val(0);
$("#lease-lease").html("INTERNAL ERROR");
$("#charge-entry-id").val(0);
$("#invoice-lease").html("INTERNAL ERROR");
$("#invoice-unit").html("INTERNAL ERROR");
$("#invoice-customer").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) {
// 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')
);
// Get the item names from the grid
$("#invoice-lease").html($(grid_id).getCell(lease_id, 'Lease-number'));
$("#invoice-unit").html($(grid_id).getCell(lease_id, 'Unit-name'));
$("#invoice-customer").html($(grid_id).getCell(lease_id, 'Customer-name'));
// Make sure the redirect is up to date, if necessary
if ($("#redirectController").val() == 'leases')
$("#redirect0").val(lease_id);
@@ -89,6 +60,7 @@ function onRowSelect(grid_id, lease_id) {
$("#no-lease").hide();
$("#current-lease").show();
// Collapse the grid now that the user has selected
$("#leases-list .HeaderButton").click();
}
@@ -124,12 +96,17 @@ echo $this->element('leases',
));
echo ('<H2>' .
'<SPAN id="current-lease">Lease: <SPAN id="lease-lease"></SPAN></SPAN>' .
'<SPAN id="no-lease">Please select lease</SPAN>' .
'<SPAN id="current-lease" style="display:none">' .
'Lease <SPAN id="invoice-lease"></SPAN>' . ' / ' .
'Unit: <SPAN id="invoice-unit"></SPAN>' . ' / ' .
'Customer: <SPAN id="invoice-customer"></SPAN>' .
'</SPAN>' .
'<SPAN id="no-lease" style="display:none">' .
'Please select lease' .
'</SPAN>' .
'</H2>' . "\n");
echo $form->create(null, array('id' => 'assess-form',
echo $form->create(null, array('id' => 'invoice-form',
'url' => array('controller' => 'transactions',
'action' => 'postInvoice')));
@@ -139,7 +116,7 @@ echo $form->input("Lease.id",
'value' => 0));
echo $this->element('form_table',
array('class' => "item assess entry",
array('class' => "item invoice transaction entry",
//'with_name_after' => ':',
'field_prefix' => 'Transaction',
'fields' => array
@@ -159,7 +136,7 @@ echo $this->element('form_table',
echo ('<BR>' . "\n");
echo $this->element('form_table',
array('class' => "item assess entry",
array('class' => "item invoice ledger-entry entry",
//'with_name_after' => ':',
'field_prefix' => 'LedgerEntry.0',
'fields' => array
@@ -192,7 +169,7 @@ foreach ($redirect AS $name => $value) {
'value' => $value,
));
}
echo $form->end('Assess Charge');
echo $form->end('Generate Invoice');
?>
@@ -216,12 +193,12 @@ echo $form->end('Assess Charge');
<?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();
$("#invoice-lease").html("<?php echo '#'.$lease['Lease']['number']; ?>");
$("#invoice-unit").html("<?php echo $lease['Unit']['name']; ?>");
$("#invoice-customer").html("<?php echo $lease['Customer']['name']; ?>");
onGridState(null, 'hidden');
<?php else: ?>
$("#current-lease").hide();
$("#no-lease").hide();
onGridState(null, 'visible');
<?php endif; ?>
});
--></script>

View File

@@ -139,6 +139,48 @@ function fmtCurrency(amount) {
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
// Datepicker helpers
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);
}
// REVISIT <AP>: 20090617
// I would rather use XML to pass from JS to PHP, but at the
// moment things were working just fine with serialize, and