First pass at a charge waiver implementation. It hasn't been tested but for a tiny bit.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@471 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -183,6 +183,18 @@ class StatementEntriesController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: waive the ledger entry
|
||||||
|
*/
|
||||||
|
|
||||||
|
function waive($id) {
|
||||||
|
$this->StatementEntry->waive($id);
|
||||||
|
//$this->redirect(array('action'=>'view', $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -256,6 +268,19 @@ class StatementEntriesController extends AppController {
|
|||||||
else
|
else
|
||||||
$stats = $stats['Payment'];
|
$stats = $stats['Payment'];
|
||||||
|
|
||||||
|
|
||||||
|
if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE' &&
|
||||||
|
$stats['reconciled'] == 0) {
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Waive',
|
||||||
|
'url' => array('action' => 'waive',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare to render.
|
// Prepare to render.
|
||||||
$title = "Statement Entry #{$entry['StatementEntry']['id']}";
|
$title = "Statement Entry #{$entry['StatementEntry']['id']}";
|
||||||
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ class Account extends AppModel {
|
|||||||
function checkAccountID() { return $this->nameToID('Check'); }
|
function checkAccountID() { return $this->nameToID('Check'); }
|
||||||
function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
|
function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
|
||||||
function concessionAccountID() { return $this->nameToID('Concession'); }
|
function concessionAccountID() { return $this->nameToID('Concession'); }
|
||||||
|
function waiverAccountID() { return $this->nameToID('Waiver'); }
|
||||||
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }
|
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }
|
||||||
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||||
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class StatementEntry extends AppModel {
|
|||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
//var $default_log_level = 30;
|
var $default_log_level = 30;
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -106,6 +106,39 @@ class StatementEntry extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: waive
|
||||||
|
* - Waives the charges
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function waive($id, $stamp = null) {
|
||||||
|
$this->prEnter(compact('id', 'stamp'));
|
||||||
|
|
||||||
|
$this->recursive = -1;
|
||||||
|
$charge = $this->read(null, $id);
|
||||||
|
$charge = $charge['StatementEntry'];
|
||||||
|
|
||||||
|
// Build a transaction
|
||||||
|
$waiver = array('Transaction' => array(), 'Entry' => array());
|
||||||
|
$waiver['Transaction']['stamp'] = $stamp;
|
||||||
|
$waiver['Transaction']['comment'] = "Charge Waiver";
|
||||||
|
|
||||||
|
if ($charge['type'] !== 'CHARGE')
|
||||||
|
die("INTERNAL ERROR: WAIVER ITEM IS NOT CHARGE");
|
||||||
|
|
||||||
|
$waiver['Entry'][] =
|
||||||
|
array('amount' => $charge['amount'],
|
||||||
|
'account_id' => $this->Account->waiverAccountID(),
|
||||||
|
'comment' => null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->prReturn($this->Transaction->addWaiver
|
||||||
|
($waiver, $id, $charge['customer_id'], $charge['lease_id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -334,7 +367,7 @@ OPTION 2
|
|||||||
* the user to specify how payments should be applied.
|
* the user to specify how payments should be applied.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function assignCredits($query = null, $receipt_id = null) {
|
function assignCredits($query = null, $receipt_id = null, $charge_ids = null) {
|
||||||
//$this->prFunctionLevel(25);
|
//$this->prFunctionLevel(25);
|
||||||
$this->prEnter( compact('query', 'receipt_id'));
|
$this->prEnter( compact('query', 'receipt_id'));
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
@@ -374,7 +407,12 @@ OPTION 2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now find all unpaid charges
|
// Now find all unpaid charges
|
||||||
|
if (isset($charge_ids)) {
|
||||||
|
$lquery = array('contain' => false,
|
||||||
|
'conditions' => array('StatementEntry.id' => $charge_ids));
|
||||||
|
} else {
|
||||||
$lquery = $query;
|
$lquery = $query;
|
||||||
|
}
|
||||||
$lquery['order'] = 'StatementEntry.effective_date ASC';
|
$lquery['order'] = 'StatementEntry.effective_date ASC';
|
||||||
$charges = $this->reconciledSet('CHARGE', $lquery, true);
|
$charges = $this->reconciledSet('CHARGE', $lquery, true);
|
||||||
$this->pr(18, compact('charges'),
|
$this->pr(18, compact('charges'),
|
||||||
|
|||||||
@@ -51,23 +51,25 @@ class Transaction extends AppModel {
|
|||||||
|
|
||||||
// Establish the transaction as an invoice
|
// Establish the transaction as an invoice
|
||||||
$invoice =& $data['Transaction'];
|
$invoice =& $data['Transaction'];
|
||||||
$invoice['type'] = 'INVOICE';
|
$invoice +=
|
||||||
$invoice['crdr'] = 'DEBIT';
|
array('type' => 'INVOICE',
|
||||||
$invoice['account_id'] = $this->Account->accountReceivableAccountID();
|
'crdr' => 'DEBIT',
|
||||||
$invoice['customer_id'] = $customer_id;
|
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||||
$invoice['lease_id'] = $lease_id;
|
'customer_id' => $customer_id,
|
||||||
|
'lease_id' => $lease_id,
|
||||||
|
);
|
||||||
|
|
||||||
// Go through the statement entries and flag as charges
|
// Go through the statement entries and flag as charges
|
||||||
foreach ($data['Entry'] AS &$entry) {
|
foreach ($data['Entry'] AS &$entry)
|
||||||
$entry['type'] = 'CHARGE';
|
$entry += array('type' => 'CHARGE',
|
||||||
$entry['crdr'] = 'CREDIT';
|
'crdr' => 'CREDIT',
|
||||||
}
|
);
|
||||||
|
|
||||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
||||||
if (isset($ids['transaction_id']))
|
if (isset($ids['transaction_id']))
|
||||||
$ids['invoice_id'] = $ids['transaction_id'];
|
$ids['invoice_id'] = $ids['transaction_id'];
|
||||||
|
|
||||||
return $ids;
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -83,26 +85,30 @@ class Transaction extends AppModel {
|
|||||||
|
|
||||||
// Establish the transaction as a receipt
|
// Establish the transaction as a receipt
|
||||||
$receipt =& $data['Transaction'];
|
$receipt =& $data['Transaction'];
|
||||||
$receipt['type'] = 'RECEIPT';
|
$receipt +=
|
||||||
$receipt['crdr'] = 'CREDIT';
|
array('type' => 'RECEIPT',
|
||||||
$receipt['account_id'] = $this->Account->accountReceivableAccountID();
|
'crdr' => 'CREDIT',
|
||||||
$receipt['customer_id'] = $customer_id;
|
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||||
$receipt['lease_id'] = $lease_id;
|
'customer_id' => $customer_id,
|
||||||
|
'lease_id' => $lease_id,
|
||||||
|
);
|
||||||
|
|
||||||
// Go through the statement entries and flag as payments
|
// Go through the statement entries and flag as payments
|
||||||
foreach ($data['Entry'] AS &$entry) {
|
foreach ($data['Entry'] AS &$entry)
|
||||||
$entry['crdr'] = 'DEBIT';
|
$entry += array('type' => 'PAYMENT', // not used
|
||||||
if (empty($entry['account_id']) && isset($entry['Tender']['tender_type_id'])) {
|
'crdr' => 'DEBIT',
|
||||||
$entry['account_id'] = $this->LedgerEntry->Tender->TenderType->
|
'account_id' =>
|
||||||
accountID($entry['Tender']['tender_type_id']);
|
(isset($entry['Tender']['tender_type_id'])
|
||||||
}
|
? ($this->LedgerEntry->Tender->TenderType->
|
||||||
}
|
accountID($entry['Tender']['tender_type_id']))
|
||||||
|
: null),
|
||||||
|
);
|
||||||
|
|
||||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
||||||
if (isset($ids['transaction_id']))
|
if (isset($ids['transaction_id']))
|
||||||
$ids['receipt_id'] = $ids['transaction_id'];
|
$ids['receipt_id'] = $ids['transaction_id'];
|
||||||
|
|
||||||
return $ids;
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -113,36 +119,22 @@ class Transaction extends AppModel {
|
|||||||
* - Adds a new waiver
|
* - Adds a new waiver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function addWaiver($data, $customer_id, $lease_id = null) {
|
function addWaiver($data, $charge_id, $customer_id, $lease_id = null) {
|
||||||
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
|
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
|
||||||
// REVISIT <AP>: 20090802
|
|
||||||
// Completely un-implemented. Just copied from addReceipt
|
|
||||||
// and search-replace receipt with waiver.
|
|
||||||
return array('error' => true);
|
|
||||||
|
|
||||||
// Establish the transaction as a waiver
|
// Just make sure the entries are marked as waivers...
|
||||||
$waiver =& $data['Transaction'];
|
foreach ($data['Entry'] AS &$entry)
|
||||||
$waiver['type'] = 'RECEIPT';
|
|
||||||
$waiver['crdr'] = 'CREDIT';
|
|
||||||
$waiver['account_id'] = $this->Account->accountReceivableAccountID();
|
|
||||||
$waiver['customer_id'] = $customer_id;
|
|
||||||
$waiver['lease_id'] = $lease_id;
|
|
||||||
|
|
||||||
// Go through the statement entries and flag as payments
|
|
||||||
foreach ($data['Entry'] AS &$entry) {
|
|
||||||
$entry['type'] = 'WAIVE';
|
$entry['type'] = 'WAIVE';
|
||||||
$entry['crdr'] = 'DEBIT';
|
|
||||||
if (empty($entry['account_id']) && isset($entry['Tender']['tender_type_id'])) {
|
|
||||||
$entry['account_id'] = $this->LedgerEntry->Tender->TenderType->
|
|
||||||
accountID($entry['Tender']['tender_type_id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
// ... and the charge statement entry is recorded...
|
||||||
|
$data['Transaction']['charge_entry_id'] = $charge_id;
|
||||||
|
|
||||||
|
// ... and in all other respects this is just a receipt.
|
||||||
|
$ids = $this->addReceipt($data, $customer_id, $lease_id);
|
||||||
if (isset($ids['transaction_id']))
|
if (isset($ids['transaction_id']))
|
||||||
$ids['waiver_id'] = $ids['transaction_id'];
|
$ids['waiver_id'] = $ids['transaction_id'];
|
||||||
|
|
||||||
return $ids;
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -192,7 +184,7 @@ class Transaction extends AppModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ids;
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -249,7 +241,7 @@ class Transaction extends AppModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ids;
|
return $this->prReturn($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -476,6 +468,7 @@ class Transaction extends AppModel {
|
|||||||
$this->create();
|
$this->create();
|
||||||
if (!$this->save($transaction))
|
if (!$this->save($transaction))
|
||||||
return $this->prReturn(array('error' => true) + $ret);
|
return $this->prReturn(array('error' => true) + $ret);
|
||||||
|
$transaction_stamp = $this->field('stamp');
|
||||||
|
|
||||||
// Set up our return ids array
|
// Set up our return ids array
|
||||||
$ret['transaction_id'] = $this->id;
|
$ret['transaction_id'] = $this->id;
|
||||||
@@ -503,6 +496,7 @@ class Transaction extends AppModel {
|
|||||||
|
|
||||||
if (!empty($se)) {
|
if (!empty($se)) {
|
||||||
$se['transaction_id'] = $ret['transaction_id'];
|
$se['transaction_id'] = $ret['transaction_id'];
|
||||||
|
$se += array('effective_date' => $transaction_stamp);
|
||||||
$result = $this->StatementEntry->addStatementEntry($se);
|
$result = $this->StatementEntry->addStatementEntry($se);
|
||||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||||
if ($result['error']) {
|
if ($result['error']) {
|
||||||
@@ -520,7 +514,11 @@ class Transaction extends AppModel {
|
|||||||
'conditions' => array('Customer.id' => $transaction['customer_id'])),
|
'conditions' => array('Customer.id' => $transaction['customer_id'])),
|
||||||
($transaction['type'] == 'RECEIPT'
|
($transaction['type'] == 'RECEIPT'
|
||||||
? $ret['transaction_id']
|
? $ret['transaction_id']
|
||||||
: null));
|
: null),
|
||||||
|
($transaction['type'] == 'RECEIPT' && !empty($transaction['charge_entry_id'])
|
||||||
|
? $transaction['charge_entry_id']
|
||||||
|
: null)
|
||||||
|
);
|
||||||
|
|
||||||
$ret['assigned'] = $result;
|
$ret['assigned'] = $result;
|
||||||
if ($result['error'])
|
if ($result['error'])
|
||||||
|
|||||||
Reference in New Issue
Block a user