'Transactions', 'header' => true), array('name' => 'All', 'url' => array('controller' => 'transactions', 'action' => 'all')), ); /************************************************************************** ************************************************************************** ************************************************************************** * override: sideMenuLinks * - Generates controller specific links for the side menu */ function sideMenuLinks() { return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); } /************************************************************************** ************************************************************************** ************************************************************************** * action: index / all * - Generate a listing of transactions */ function index() { $this->all(); } function all() { $this->jqGridView('All Transactions', 'all'); } /************************************************************************** ************************************************************************** ************************************************************************** * virtuals: jqGridData * - With the application controller handling the jqGridData action, * these virtual functions ensure that the correct data is passed * to jqGrid. */ function jqGridRecordLinks(&$params, &$model, &$records, $links) { $links['Transaction'] = array('id'); return parent::jqGridRecordLinks($params, $model, $records, $links); } /************************************************************************** ************************************************************************** ************************************************************************** * action: view * - Displays information about a specific transaction */ function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Item.', true)); $this->redirect(array('action'=>'index')); } $transaction = $this->Transaction->find ('first', array('contain' => array(// Models 'LedgerEntry' => array('fields' => array('LedgerEntry.id', 'LedgerEntry.amount', 'LedgerEntry.comment'), //Models 'DebitLedger' => array ('fields' => array('DebitLedger.id', 'DebitLedger.sequence'), 'Account' => array ('fields' => array('Account.id', 'Account.name')), ), 'CreditLedger' => array ('fields' => array('CreditLedger.id', 'CreditLedger.sequence'), 'Account' => array ('fields' => array('Account.id', 'Account.name')), ), ), ), 'conditions' => array('Transaction.id' => $id), )); // Figure out the transaction total $total = 0; foreach($transaction['LedgerEntry'] AS $entry) $total += $entry['amount']; // OK, prepare to render. $title = 'Transaction #' . $transaction['Transaction']['id']; $this->set(compact('transaction', 'title', 'total')); } /************************************************************************** ************************************************************************** ************************************************************************** * action: postReceipt * - handles the creation of a payment receipt */ function postReceipt() { $this->autoRender = false; if (!$this->RequestHandler->isPost()) { echo('

THIS IS NOT A POST FOR SOME REASON

'); return; } //pr(array('thisdata' => $this->data)); if (isset($this->data['customer_id'])) { $C = new Customer(); $C->recursive = -1; $customer = $C->find ('first', array('contain' => array('Account.CurrentLedger.id'), 'fields' => false, 'conditions' => array('Customer.id', $this->data['customer_id']), )); $ledger_id = $customer['Account']['CurrentLedger']['id']; } else { // Payment by Unit, Lease, etc $ledger_id = 0; } $amount = 0; foreach ($this->data['LedgerEntry'] AS &$entry) { $reconciled = $C->reconcileNewLedgerEntry($this->data['customer_id'], 'credit', $entry['amount']); pr(compact('entry', 'reconciled')); foreach ($reconciled['debit']['entry'] AS $rec) { $entry['DebitReconciliationLedgerEntry'] = array('amount' => $rec['applied'], //'debit_ledger_entry_id' 'credit_ledger_entry_id' => $rec['id'] ); } $amount += isset($entry['amount']) ? $entry['amount'] : 0; $entry['debit_ledger_id'] = 6; // Cash/Payments $entry['credit_ledger_id'] = $ledger_id; } pr($this->data); $T = new Transaction(); $T->create(); if ($T->saveAll($this->data, array( 'validate' => false, //'fieldList' => array(), //'callbacks' => true, ))) { $tid = $T->id; $this->Session->setFlash(__("New Transaction Created ($tid)!", true)); //$this->redirect(array('action'=>'view', $mid)); } else { $this->autoRender = false; pr(array('checkpoint' => "saveAll failed")); } pr($T->data); $C = new Customer(); $LE = new LedgerEntry(); /* $reconciled = $C->reconcileNewLedgerEntry($this->data['customer_id'], */ /* 'credit', */ /* $amount); */ /* pr(compact('amount', 'unreconciled', 'reconciled')); */ /* return; */ foreach ($this->data['LedgerEntry'] AS &$entry) { $reconciled = $C->reconcileNewLedgerEntry($this->data['customer_id'], 'credit', $entry['amount']); pr(compact('entry', 'reconciled')); continue; foreach ($reconciled['debit']['entry'] AS $rec) { $data = array('LedgerEntry' => array('DebitReconciliationLedgerEntry' => array('amount' => $rec['applied'], //'debit_ledger_entry_id' 'credit_ledger_entry_id' => $rec['id'] ), ), ); //'DebitReconciliationLedgerEntry' => array( //pr(compact('amount', 'unreconciled', 'reconciled')); } } } function saveTest() { $data = array( /* 'Customer' => array */ /* ('id' => 7, */ /* ), */ 'LedgerEntry' => array ( '0' => array( 'amount' => 100, 'debit_ledger_id' => 1, 'credit_ledger_id' => 2, 'MonetarySource' => array('name' => 'testmoney', 'monetary_type_id' => 2), ), '1' => array( 'amount' => 101, 'debit_ledger_id' => 1, 'credit_ledger_id' => 2, 'MonetarySource' => array('name' => 'testmoney2', 'monetary_type_id' => 2), ), ), 'Transaction' => array ( 'stamp' => '06/18/2009', 'comment' => 'no comment', ), ); $data = /* array( */ /* 'LedgerEntry' => array */ /* ( */ /* '0' => */ array( 'amount' => 100, 'debit_ledger_id' => 1, 'credit_ledger_id' => 2, 'transaction_id' => 1, 'DebitReconciliationLedgerEntry' => array('amount' => 44, //'debit_ledger_entry_id' 'credit_ledger_entry_id' => 17, ), /* ), */ /* ), */ ); //$M = new Transaction(); $M = new LedgerEntry(); $M->create(); $retval = $M->saveAll($data, array( 'validate' => false, 'fieldList' => array(), 'callbacks' => true, )); $mid = $M->id; pr(compact('retval', 'mid')); if ($mid) { $this->Session->setFlash(__("New Transaction Created ($mid)!", true)); //$this->redirect(array('action'=>'view', $mid)); } else { $this->autoRender = false; pr(array('checkpoint' => "saveAll failed")); } /* $LE = new LedgerEntry(); */ /* $LE->create(); */ /* $ret = $LE->save($data, */ /* array( */ /* 'validate' => false, */ /* 'fieldList' => array(), */ /* 'callbacks' => true, */ /* )); */ /* $leid = $LE->id; */ /* pr(array('checkpoint' => "New Ledger Entry", */ /* compact('leid', 'ret'))); */ //pr($LE); } }