This rework is nowhere near complete, but there are certain things that are falling in place, and worth capturing. I started a branch for just this purpose of being able to check in intermediate work.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@352 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-19 23:35:25 +00:00
parent af0c10f6a6
commit 3d262fd4db
24 changed files with 2401 additions and 1373 deletions

View File

@@ -1,17 +1,17 @@
<?php
class Transaction extends AppModel {
var $name = 'Transaction';
var $validate = array(
'stamp' => array('date')
);
var $belongsTo = array(
'Customer',
'Lease',
);
var $hasMany = array(
'LedgerEntry',
'DoubleEntry',
);
@@ -19,7 +19,7 @@ class Transaction extends AppModel {
**************************************************************************
**************************************************************************
* function: addInvoice
* - Adds a new invoice transaction
* - Adds a new invoice invoice
*/
function addInvoice($data, $customer_id, $lease_id = null) {
@@ -31,32 +31,31 @@ class Transaction extends AppModel {
// Assume this will succeed
$ret = true;
// Establish the key invoice parameters
$invoice = array_intersect_key($data, array('Invoice'=>1));
$invoice['type'] = 'INVOICE';
// Determine the total charges on the invoice
$grand_total = 0;
foreach ($data['LedgerEntry'] AS $entry)
$grand_total += $entry['amount'];
$invoice['amount'] = 0;
foreach ($data['DoubleEntry'] AS $entry)
$invoice['amount'] += $entry['amount'];
// Go through the entered charges
$invoice_transaction = array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1));
foreach ($data['LedgerEntry'] AS $entry) {
foreach ($data['DoubleEntry'] AS $entry) {
//pr(compact('entry'));
// Create the receipt entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a payment.
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
($invoice_transaction,
array_intersect_key($entry, array('MonetarySource'=>1))
+ array_intersect_key($entry, array('account_id'=>1)),
$ids = $this->DoubleEntry->Ledger->Account->postDoubleEntry
($invoice,
array('debit_ledger_id' => $A->currentLedgerID($A->accountReceivableAccountID()),
'credit_ledger_id' => $A->currentLedgerID($entry['account_id']),
'customer_id' => $customer_id,
'lease_id' => $lease_id)
+ $entry
'credit_ledger_id' => $A->currentLedgerID($entry['account_id'])
) + $entry
);
if ($ids['error'])
$ret = false;
$invoice_transaction = array_intersect_key($ids, array('transaction_id'=>1));
$invoice = array_intersect_key($ids, array('invoice_id'=>1));
}
return $ret;
@@ -67,7 +66,7 @@ class Transaction extends AppModel {
**************************************************************************
**************************************************************************
* function: addReceipt
* - Adds a new receipt transaction
* - Adds a new receipt
*/
function addReceipt($data, $customer_id, $lease_id = null) {
@@ -77,32 +76,40 @@ class Transaction extends AppModel {
// Assume this will succeed
$ret = true;
// Go through the entered payments
$receipt_transaction = array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1));
foreach ($data['LedgerEntry'] AS $entry) {
// Create the receipt entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a payment.
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
($receipt_transaction,
array_intersect_key($entry, array('MonetarySource'=>1))
+ array_intersect_key($entry, array('account_id'=>1)),
array('debit_ledger_id' => $A->currentLedgerID($entry['account_id']),
'credit_ledger_id' => $A->currentLedgerID($A->receiptAccountID()),
'customer_id' => $customer_id,
'lease_id' => $lease_id)
+ $entry,
'receipt');
// Establish the key receipt parameters
$receipt = array_intersect_key($data, array('stamp'=>1, 'type'=>1, 'name'=>1, 'amount'=>1,
'data1'=>1, 'data2'=>1, 'data3'=>1, 'data4'=>1));
$receipt['type'] = 'RECEIPT';
// Determine the total charges on the receipt
$receipt['amount'] = 0;
foreach ($data['DoubleEntry'] AS $entry)
$receipt['amount'] += $entry['amount'];
// Go through the entered charges
foreach ($data['DoubleEntry'] AS $entry) {
// Create the receipt entry, and reconcile the credit side
// of the double-entry (which should be A/R) as a receipt.
$ids = $this->DoubleEntry->Ledger->Account->postDoubleEntry
($receipt,
array('debit_ledger_id' => $A->currentLedgerID($entry['account_id']),
'credit_ledger_id' => $A->currentLedgerID($A->receiptAccountID())
) + $entry,
array('debit' => 'receipt',
'credit' => $reconcile)
);
if ($ids['error'])
$ret = false;
$receipt_transaction = array_intersect_key($ids,
array('transaction_id'=>1,
'split_transaction_id'=>1));
$receipt = array_intersect_key($ids,
array('receipt_id'=>1,
'split_receipt_id'=>1));
}
return $ret;
}
}
?>