array('date') ); var $belongsTo = array( ); var $hasMany = array( 'LedgerEntry', ); /************************************************************************** ************************************************************************** ************************************************************************** * function: addInvoice * - Adds a new invoice transaction */ 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; // Determine the total charges on the invoice $grand_total = 0; foreach ($data['LedgerEntry'] AS $entry) $grand_total += $entry['amount']; $ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry (array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1)), null, array('debit_ledger_id' => $A->currentLedgerID($A->accountReceivableAccountID()), 'credit_ledger_id' => $A->currentLedgerID($A->invoiceAccountID()), 'customer_id' => $customer_id, 'lease_id' => $lease_id, 'amount' => $grand_total)); $ar_entry_id = $ids['id']; // Go through the entered charges $invoice_transaction = array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1)); 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_transaction, array_intersect_key($entry, array('MonetarySource'=>1)) + array_intersect_key($entry, array('account_id'=>1)), array('debit_ledger_id' => $A->currentLedgerID($A->invoiceAccountID()), 'credit_ledger_id' => $A->currentLedgerID($entry['account_id']), 'customer_id' => $customer_id, 'lease_id' => $lease_id) + $entry, array('debit' => array(array('LedgerEntry' => array('id' => $ar_entry_id, 'amount' => $entry['amount'])))) ); if ($ids['error']) $ret = false; $invoice_transaction = array_intersect_key($ids, array('transaction_id'=>1)); } return $ret; } /************************************************************************** ************************************************************************** ************************************************************************** * function: addReceipt * - Adds a new receipt transaction */ function addReceipt($data, $customer_id, $lease_id = null) { // Create some models for convenience $A = new Account(); // 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'); if ($ids['error']) $ret = false; $receipt_transaction = array_intersect_key($ids, array('transaction_id'=>1)); } return $ret; } } ?>