First pass at having invoice support multiple charges, just like receipt/payment. It works well, but I know we still need a better solution for income accounts, and it hasn't been robustly tested yet.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@243 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -202,11 +202,6 @@ class LeasesController extends AppController {
|
||||
// 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'] . ': Charge Entry');
|
||||
|
||||
@@ -118,11 +118,9 @@ class TransactionsController extends AppController {
|
||||
die("<H1>INVOICE FAILED</H1>");
|
||||
}
|
||||
|
||||
// Comment this out to debug
|
||||
$this->redirect($this->data['redirect']);
|
||||
|
||||
pr($this->data['redirect']);
|
||||
$this->render('/empty');
|
||||
$this->layout = null;
|
||||
$this->autoLayout = false;
|
||||
$this->autoRender = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,14 +30,79 @@ $lease_grid_setup['onHeaderClick'] = array
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
|
||||
// prepare the form when the DOM is ready
|
||||
$(document).ready(function() {
|
||||
var options = {
|
||||
target: '#output-debug', // target element(s) to be updated with server response
|
||||
beforeSubmit: verifyRequest, // pre-submit callback
|
||||
success: showResponse, // post-submit callback
|
||||
|
||||
// other available options:
|
||||
//url: url, // override for form's 'action' attribute
|
||||
//type: 'get', // 'get' or 'post', override for form's 'method' attribute
|
||||
//dataType: null, // 'xml', 'script', or 'json' (expected server response type)
|
||||
//clearForm: true, // clear all form fields after successful submit
|
||||
//resetForm: true, // reset the form after successful submit
|
||||
|
||||
// $.ajax options can be used here too, for example:
|
||||
//timeout: 3000,
|
||||
};
|
||||
|
||||
// bind form using 'ajaxForm'
|
||||
$('#invoice-form').ajaxForm(options);
|
||||
});
|
||||
|
||||
// pre-submit callback
|
||||
function verifyRequest(formData, jqForm, options) {
|
||||
// formData is an array; here we use $.param to convert it to a string to display it
|
||||
// but the form plugin does this for you automatically when it submits the data
|
||||
//var_dump(formData);
|
||||
//$('#request-debug').html('<PRE>'+dump(formData)+'</PRE>');
|
||||
$('#request-debug').html('Ommitted');
|
||||
//return false;
|
||||
|
||||
$('#response-debug').html('Loading <BLINK>...</BLINK>');
|
||||
$('#output-debug').html('Loading <BLINK>...</BLINK>');
|
||||
|
||||
// here we could return false to prevent the form from being submitted;
|
||||
// returning anything other than false will allow the form submit to continue
|
||||
return true;
|
||||
}
|
||||
|
||||
// post-submit callback
|
||||
function showResponse(responseText, statusText) {
|
||||
// for normal html responses, the first argument to the success callback
|
||||
// is the XMLHttpRequest object's responseText property
|
||||
|
||||
// if the ajaxForm method was passed an Options Object with the dataType
|
||||
// property set to 'xml' then the first argument to the success callback
|
||||
// is the XMLHttpRequest object's responseXML property
|
||||
|
||||
// if the ajaxForm method was passed an Options Object with the dataType
|
||||
// property set to 'json' then the first argument to the success callback
|
||||
// is the json data object returned by the server
|
||||
|
||||
if (statusText == 'success') {
|
||||
// get a clean slate
|
||||
//resetForm();
|
||||
}
|
||||
else {
|
||||
alert('not successful??');
|
||||
}
|
||||
|
||||
|
||||
$('#response-debug').html('<PRE>'+dump(statusText)+'</PRE>');
|
||||
}
|
||||
|
||||
// Reset the form
|
||||
function resetForm() {
|
||||
$("#charge-entry-id").val(0);
|
||||
$("#charge-entry-id").val(1);
|
||||
|
||||
$("#invoice-lease").html("INTERNAL ERROR");
|
||||
$("#invoice-unit").html("INTERNAL ERROR");
|
||||
$("#invoice-customer").html("INTERNAL ERROR");
|
||||
|
||||
addChargeSource(false);
|
||||
datepickerNow('charge_date');
|
||||
$("#through_date").val('');
|
||||
}
|
||||
@@ -52,10 +117,6 @@ function onRowSelect(grid_id, lease_id) {
|
||||
$("#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);
|
||||
|
||||
// Hide the "no lease" message and show the current lease
|
||||
$("#no-lease").hide();
|
||||
$("#current-lease").show();
|
||||
@@ -80,6 +141,51 @@ function onGridState(grid_id, state) {
|
||||
}
|
||||
}
|
||||
|
||||
function addChargeSource(flash) {
|
||||
addDiv('charge-entry-id', 'charge', 'charges', flash,
|
||||
// HTML section
|
||||
'<FIELDSET CLASS="charge subset">' +
|
||||
'<LEGEND>Charge #%{id} (%{remove})</LEGEND>' +
|
||||
|
||||
<?php
|
||||
echo FormatHelper::phpVarToJavascript
|
||||
($this->element('form_table',
|
||||
array('class' => "item invoice ledger-entry entry",
|
||||
//'with_name_after' => ':',
|
||||
'field_prefix' => 'LedgerEntry.%{id}',
|
||||
'fields' => array
|
||||
("charge_type" => array('opts' =>
|
||||
array('options' =>
|
||||
array('rent' => 'Rent',
|
||||
'late' => 'Late Charge',
|
||||
'secd' => 'Security Deposit'),
|
||||
'separator' => ' ',
|
||||
'type' => 'radio',
|
||||
'label' => false,
|
||||
'div' => false,
|
||||
'legend' => false,
|
||||
'value' =>
|
||||
(isset($charge['type'])
|
||||
? $charge['type']
|
||||
: null)
|
||||
),
|
||||
),
|
||||
"amount" => array('opts' =>
|
||||
array('value' =>
|
||||
(isset($charge['amount'])
|
||||
? $charge['amount']
|
||||
: null)
|
||||
),
|
||||
),
|
||||
"comment" => array('opts' => array('size' => 50)),
|
||||
),
|
||||
))) . "+\n";
|
||||
?>
|
||||
|
||||
'</FIELDSET>'
|
||||
);
|
||||
}
|
||||
|
||||
--></script>
|
||||
|
||||
<?php
|
||||
@@ -134,45 +240,24 @@ echo $this->element('form_table',
|
||||
),
|
||||
)));
|
||||
|
||||
echo ('<BR>' . "\n");
|
||||
echo $this->element('form_table',
|
||||
array('class' => "item invoice ledger-entry entry",
|
||||
//'with_name_after' => ':',
|
||||
'field_prefix' => 'LedgerEntry.0',
|
||||
'fields' => array
|
||||
("charge_type" => array('opts' =>
|
||||
array('options' =>
|
||||
array('rent' => 'Rent',
|
||||
'late' => 'Late Charge'),
|
||||
'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('Generate Invoice');
|
||||
|
||||
echo $form->submit('Generate Invoice') . "\n";
|
||||
?>
|
||||
|
||||
<fieldset CLASS="charge superset">
|
||||
<legend>Charges</legend>
|
||||
<input type="hidden" id="charge-entry-id" value="0">
|
||||
<div id="charges"></div>
|
||||
<fieldset> <legend>
|
||||
<a href="#" onClick="addChargeSource(true); return false;">Add Another Charge</a>
|
||||
</legend> </fieldset>
|
||||
</fieldset>
|
||||
|
||||
<?php echo $form->end('Generate Invoice'); ?>
|
||||
|
||||
<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>
|
||||
|
||||
<script type="text/javascript"><!--
|
||||
$(document).ready(function(){
|
||||
$("#charge_date")
|
||||
@@ -204,3 +289,5 @@ echo $form->end('Generate Invoice');
|
||||
--></script>
|
||||
|
||||
</div>
|
||||
|
||||
<a href="#" onClick="$('#debug').html(''); return false;">Clear Debug Output</a>
|
||||
|
||||
Reference in New Issue
Block a user