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:
@@ -51,23 +51,25 @@ class Transaction extends AppModel {
|
||||
|
||||
// Establish the transaction as an invoice
|
||||
$invoice =& $data['Transaction'];
|
||||
$invoice['type'] = 'INVOICE';
|
||||
$invoice['crdr'] = 'DEBIT';
|
||||
$invoice['account_id'] = $this->Account->accountReceivableAccountID();
|
||||
$invoice['customer_id'] = $customer_id;
|
||||
$invoice['lease_id'] = $lease_id;
|
||||
$invoice +=
|
||||
array('type' => 'INVOICE',
|
||||
'crdr' => 'DEBIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'customer_id' => $customer_id,
|
||||
'lease_id' => $lease_id,
|
||||
);
|
||||
|
||||
// Go through the statement entries and flag as charges
|
||||
foreach ($data['Entry'] AS &$entry) {
|
||||
$entry['type'] = 'CHARGE';
|
||||
$entry['crdr'] = 'CREDIT';
|
||||
}
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'CHARGE',
|
||||
'crdr' => 'CREDIT',
|
||||
);
|
||||
|
||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
||||
if (isset($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
|
||||
$receipt =& $data['Transaction'];
|
||||
$receipt['type'] = 'RECEIPT';
|
||||
$receipt['crdr'] = 'CREDIT';
|
||||
$receipt['account_id'] = $this->Account->accountReceivableAccountID();
|
||||
$receipt['customer_id'] = $customer_id;
|
||||
$receipt['lease_id'] = $lease_id;
|
||||
$receipt +=
|
||||
array('type' => 'RECEIPT',
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'customer_id' => $customer_id,
|
||||
'lease_id' => $lease_id,
|
||||
);
|
||||
|
||||
// Go through the statement entries and flag as payments
|
||||
foreach ($data['Entry'] AS &$entry) {
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'PAYMENT', // not used
|
||||
'crdr' => 'DEBIT',
|
||||
'account_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']);
|
||||
if (isset($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
|
||||
*/
|
||||
|
||||
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'));
|
||||
// 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
|
||||
$waiver =& $data['Transaction'];
|
||||
$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) {
|
||||
// Just make sure the entries are marked as waivers...
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$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']))
|
||||
$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();
|
||||
if (!$this->save($transaction))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
$transaction_stamp = $this->field('stamp');
|
||||
|
||||
// Set up our return ids array
|
||||
$ret['transaction_id'] = $this->id;
|
||||
@@ -503,6 +496,7 @@ class Transaction extends AppModel {
|
||||
|
||||
if (!empty($se)) {
|
||||
$se['transaction_id'] = $ret['transaction_id'];
|
||||
$se += array('effective_date' => $transaction_stamp);
|
||||
$result = $this->StatementEntry->addStatementEntry($se);
|
||||
$ret['entries'][$e_index]['StatementEntry'] = $result;
|
||||
if ($result['error']) {
|
||||
@@ -520,7 +514,11 @@ class Transaction extends AppModel {
|
||||
'conditions' => array('Customer.id' => $transaction['customer_id'])),
|
||||
($transaction['type'] == 'RECEIPT'
|
||||
? $ret['transaction_id']
|
||||
: null));
|
||||
: null),
|
||||
($transaction['type'] == 'RECEIPT' && !empty($transaction['charge_entry_id'])
|
||||
? $transaction['charge_entry_id']
|
||||
: null)
|
||||
);
|
||||
|
||||
$ret['assigned'] = $result;
|
||||
if ($result['error'])
|
||||
|
||||
Reference in New Issue
Block a user