array('date') ); var $belongsTo = array( 'Customer', 'Lease', ); var $hasMany = array( 'DoubleEntry', ); /************************************************************************** ************************************************************************** ************************************************************************** * 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['DoubleEntry'] AS $entry) $invoice['amount'] += $entry['amount']; // Go through the entered charges 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->DoubleEntry->Ledger->Account->postDoubleEntry ($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['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 = array_intersect_key($ids, array('receipt_id'=>1, 'split_receipt_id'=>1)); } return $ret; } } ?>