Files
pmgr/site/models/transaction.php
abijah 93ebc450fe Making progress. Much still to do, but there are hints of functionality finally returning so I'm snapshotting.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@360 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-07-21 10:23:52 +00:00

112 lines
3.3 KiB
PHP

<?php
class Transaction extends AppModel {
var $belongsTo = array(
'Account',
'Ledger',
);
var $hasMany = array(
'LedgerEntry',
'StatementEntry',
);
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addInvoice
* - Adds a new invoice invoice
*/
function addInvoice($data, $customer_id, $lease_id = null) {
// Create some models for convenience
$A = new Account();
//pr(compact('data', 'customer_id', 'lease_id'));
// 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
$invoice['amount'] = 0;
foreach ($data['LedgerEntry'] AS $entry)
$invoice['amount'] += $entry['amount'];
// Go through the entered charges
foreach ($data['LedgerEntry'] 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,
array('debit_ledger_id' => $A->currentLedgerID($A->accountReceivableAccountID()),
'credit_ledger_id' => $A->currentLedgerID($entry['account_id'])
) + $entry
);
if ($ids['error'])
$ret = false;
$invoice = array_intersect_key($ids, array('invoice_id'=>1));
}
return $ret;
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: addReceipt
* - Adds a new receipt
*/
function addReceipt($data, $customer_id, $lease_id = null) {
// Create some models for convenience
$A = new Account();
// Assume this will succeed
$ret = true;
// 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['LedgerEntry'] AS $entry)
$receipt['amount'] += $entry['amount'];
// Go through the entered charges
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 receipt.
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
($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 = array_intersect_key($ids,
array('receipt_id'=>1,
'split_receipt_id'=>1));
}
return $ret;
}
}
?>