array('numeric'), 'name' => array('notempty'), ); var $belongsTo = array( 'Account', ); var $hasMany = array( 'CurrentLease' => array( 'className' => 'Lease', 'conditions' => 'CurrentLease.close_date IS NULL', ), 'Lease', 'Transaction', ); var $hasAndBelongsToMany = array( 'Contact', ); /************************************************************************** ************************************************************************** ************************************************************************** * function: findSecurityDeposits * - Returns an array of security deposit entries */ function findSecurityDeposits($id, $link = null) { /* pr(array('function' => 'Customer::findSecurityDeposits', */ /* 'args' => compact('id', 'link'), */ /* )); */ $this->Behaviors->attach('Containable'); $customer = $this->find('first', array('contain' => array('Lease' => array('fields' => array('id'))), 'fields' => array('account_id'), 'conditions' => array(array('Customer.id' => $id)))); $this->Behaviors->detach('Containable'); $entries = $this->Account->findLedgerEntriesRelatedToAccount ($customer['Customer']['account_id'], $this->Account->securityDepositAccountID(), true, null, $link); foreach ($customer['Lease'] AS $lease) { $ledger_entries = $this->Lease->findSecurityDeposits($lease['id'], $link); $this->statsMerge($entries['summary'], $ledger_entries['summary']); $entries['Entries'] = array_merge($entries['Entries'], $ledger_entries['Entries']); } /* pr(array('function' => 'Customer::findSecurityDeposits', */ /* 'args' => compact('id', 'link'), */ /* 'vars' => compact('customer'), */ /* 'return' => compact('entries'), */ /* )); */ return $entries; } /************************************************************************** ************************************************************************** ************************************************************************** * function: stats * - Returns summary data from the requested customer. */ function stats($id = null) { if (!$id) return null; // Get the basic information necessary $this->Behaviors->attach('Containable'); $customer = $this->find('first', array('contain' => array('Account' => array ('fields' => array('Account.id')), 'Lease' => array ('fields' => array('Lease.id')) ), 'conditions' => array (array('Customer.id' => $id)))); $this->Behaviors->detach('Containable'); // Get stats from the customer account, and each lease $stats['Account'] = $this->Account->stats($customer['Account']['id']); foreach ($customer['Lease'] AS $lease) { $this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id'])); } // Merge the stats from both the customer specific account, as // well as the leases. This will provide current customer standing. $this->statsMerge($stats, $stats['Account']['Ledger']); $this->statsMerge($stats, $stats['Lease']['Account']['Ledger']); return $stats; } } ?>