Added confirmation page, and more importantly date and comment settings, when reversing a charge.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@598 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -203,11 +203,44 @@ class StatementEntriesController extends AppController {
|
|||||||
* action: reverse the ledger entry
|
* action: reverse the ledger entry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function reverse($id) {
|
function reverse($id = null) {
|
||||||
$this->StatementEntry->reverse($id);
|
if ($this->data) {
|
||||||
|
//pr($this->data); die();
|
||||||
|
|
||||||
|
$this->StatementEntry->reverse
|
||||||
|
($this->data['StatementEntry']['id'],
|
||||||
|
$this->data['Transaction']['stamp'],
|
||||||
|
$this->data['Transaction']['comment']);
|
||||||
|
|
||||||
|
$this->redirect(array('action'=>'view',
|
||||||
|
$this->data['StatementEntry']['id']));
|
||||||
|
$this->INTERNAL_ERROR('SHOULD HAVE REDIRECTED');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->StatementEntry->id = $id;
|
||||||
|
$entry = $this->StatementEntry->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array('Customer', 'Transaction', 'Account'),
|
||||||
|
));
|
||||||
|
|
||||||
|
if (empty($entry)) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('controller' => 'customers',
|
||||||
|
'action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->StatementEntry->reversable($id)) {
|
||||||
|
$this->Session->setFlash(__('Item not reversable.', true));
|
||||||
$this->redirect(array('action'=>'view', $id));
|
$this->redirect(array('action'=>'view', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
$title = ("Charge #{$entry['StatementEntry']['id']}" .
|
||||||
|
" : {$entry['StatementEntry']['amount']}" .
|
||||||
|
" : Reverse");
|
||||||
|
$this->set(compact('entry', 'title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
|||||||
@@ -185,6 +185,9 @@ class StatementEntry extends AppModel {
|
|||||||
function reversable($id) {
|
function reversable($id) {
|
||||||
$this->prEnter(compact('id'));
|
$this->prEnter(compact('id'));
|
||||||
|
|
||||||
|
if (empty($id))
|
||||||
|
return $this->prReturn(false);
|
||||||
|
|
||||||
// Verify the item is an actual charge
|
// Verify the item is an actual charge
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
$charge_type = $this->field('type');
|
$charge_type = $this->field('type');
|
||||||
@@ -205,7 +208,7 @@ class StatementEntry extends AppModel {
|
|||||||
* function: reverse
|
* function: reverse
|
||||||
* - Reverses the charges
|
* - Reverses the charges
|
||||||
*/
|
*/
|
||||||
function reverse($id, $stamp = null) {
|
function reverse($id, $stamp = null, $comment) {
|
||||||
$this->prEnter(compact('id', 'stamp'));
|
$this->prEnter(compact('id', 'stamp'));
|
||||||
|
|
||||||
// Verify the item can be reversed
|
// Verify the item can be reversed
|
||||||
@@ -222,7 +225,7 @@ class StatementEntry extends AppModel {
|
|||||||
|
|
||||||
// Record the reversal transaction
|
// Record the reversal transaction
|
||||||
$result = $this->Transaction->addReversal
|
$result = $this->Transaction->addReversal
|
||||||
($charge, $stamp, 'Charge Reversal');
|
($charge, $stamp, $comment ? $comment : 'Charge Reversal');
|
||||||
|
|
||||||
if (empty($result['error'])) {
|
if (empty($result['error'])) {
|
||||||
// Mark the charge as reversed
|
// Mark the charge as reversed
|
||||||
|
|||||||
74
views/statement_entries/reverse.ctp
Normal file
74
views/statement_entries/reverse.ctp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php /* -*- mode:PHP -*- */
|
||||||
|
|
||||||
|
echo '<div class="reverse input">' . "\n";
|
||||||
|
|
||||||
|
$customer = $entry['Customer'];
|
||||||
|
$transaction = $entry['Transaction'];
|
||||||
|
$account = $entry['Account'];
|
||||||
|
|
||||||
|
if (isset($entry['StatementEntry']))
|
||||||
|
$entry = $entry['StatementEntry'];
|
||||||
|
|
||||||
|
// We're not actually using a grid to select the customer,
|
||||||
|
// but selection-text makes for reasonable formatting
|
||||||
|
echo ('<DIV CLASS="reverse grid-selection-text">' .
|
||||||
|
'<TABLE>' . "\n");
|
||||||
|
|
||||||
|
echo ('<TR><TD style="padding-right: 1em;">' . $customer['name'] . '</TD>' .
|
||||||
|
' <TD>' . '(Customer #' . $customer['id'] . ')' . '</TD>' .
|
||||||
|
'</TR>' . "\n");
|
||||||
|
|
||||||
|
echo ('<TR><TD style="padding-right: 1em;">' . $account['name'] . '</TD>' .
|
||||||
|
' <TD>' . '(StatementEntry #' . $entry['id'] . ')' . '</TD>' .
|
||||||
|
'</TR>' . "\n");
|
||||||
|
|
||||||
|
echo ('<TR><TD style="padding-right: 1em;">Amount:</TD>' .
|
||||||
|
' <TD>' . FormatHelper::currency($entry['amount']) . '</TD>' .
|
||||||
|
'</TR>' . "\n");
|
||||||
|
|
||||||
|
echo ('</TABLE>' .
|
||||||
|
'</DIV>' . "\n");
|
||||||
|
|
||||||
|
|
||||||
|
echo $form->create(null, array('id' => 'reverse-form',
|
||||||
|
'url' => array('action' => 'reverse'))) . "\n";
|
||||||
|
|
||||||
|
echo $form->input("StatementEntry.id",
|
||||||
|
array('type' => 'hidden',
|
||||||
|
'value' => $entry['id'])) . "\n";
|
||||||
|
|
||||||
|
echo $this->element('form_table',
|
||||||
|
array('class' => "item reverse 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),
|
||||||
|
),
|
||||||
|
))) . "\n";
|
||||||
|
|
||||||
|
echo $form->end('Reverse Charge');
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script type="text/javascript"><!--
|
||||||
|
|
||||||
|
// Reset the form
|
||||||
|
function resetForm() {
|
||||||
|
datepickerNow('TransactionStamp');
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
$("#TransactionStamp")
|
||||||
|
.attr('autocomplete', 'off')
|
||||||
|
.datepicker({ constrainInput: true,
|
||||||
|
numberOfMonths: [1, 1],
|
||||||
|
showCurrentAtPos: 0,
|
||||||
|
dateFormat: 'mm/dd/yy' });
|
||||||
|
|
||||||
|
resetForm();
|
||||||
|
});
|
||||||
|
--></script>
|
||||||
|
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user