git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@412 97e9348a-65ac-dc4b-aefc-98561f571b83
116 lines
3.7 KiB
PHP
116 lines
3.7 KiB
PHP
<?php
|
|
class TenderType extends AppModel {
|
|
|
|
var $belongsTo = array(
|
|
'Account',
|
|
);
|
|
|
|
var $hasMany = array(
|
|
'Tender',
|
|
);
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: accountID
|
|
* - Returns the intended account ID for receipt of the given tender
|
|
*/
|
|
|
|
function accountID($id) {
|
|
$this->cacheQueries = true;
|
|
$item = $this->find('first', array
|
|
('contain' => false,
|
|
'conditions' => array('TenderType.id' => $id),
|
|
));
|
|
$this->cacheQueries = false;
|
|
return $item['TenderType']['account_id'];
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: paymentTypes
|
|
* - Returns an array of types that can be used for payments
|
|
*/
|
|
|
|
function paymentTypes($query = null) {
|
|
$this->queryInit($query);
|
|
$query['order'][] = 'name';
|
|
|
|
$this->cacheQueries = true;
|
|
$types = $this->find('all', $query);
|
|
$this->cacheQueries = false;
|
|
|
|
return $types;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: paymentTypes
|
|
* - Returns an array of types that can be deposited
|
|
*/
|
|
|
|
function depositTypes($query = null) {
|
|
$this->queryInit($query);
|
|
$query['order'][] = 'name';
|
|
$query['conditions'][] = array('tillable' => true);
|
|
|
|
$this->cacheQueries = true;
|
|
$types = $this->find('all', $query);
|
|
$this->cacheQueries = false;
|
|
|
|
// Rearrange to be of the form (id => name)
|
|
$result = array();
|
|
foreach ($types AS $type)
|
|
$result[$type['TenderType']['id']] = $type['TenderType']['name'];
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: defaultPaymentType
|
|
* - Returns the ID of the default payment type
|
|
*/
|
|
|
|
function defaultPaymentType() {
|
|
return $this->nameToID('Check');
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
**************************************************************************
|
|
**************************************************************************
|
|
* function: stats
|
|
* - Returns the stats for the given tender type
|
|
*/
|
|
|
|
function stats($id = null, $query = null) {
|
|
if (!$id)
|
|
return null;
|
|
|
|
$this->queryInit($query);
|
|
|
|
if (!isset($query['link']['Tender']))
|
|
$query['link']['Tender'] = array('fields' => array());
|
|
if (!isset($query['link']['Tender']['LedgerEntry']))
|
|
$query['link']['Tender']['LedgerEntry'] = array('fields' => array());
|
|
|
|
$query['fields'][] = "SUM(COALESCE(LedgerEntry.amount,0)) AS 'total'";
|
|
$query['fields'][] = "SUM(IF(deposit_transaction_id IS NULL, COALESCE(LedgerEntry.amount,0), 0)) AS 'undeposited'";
|
|
$query['fields'][] = "SUM(IF(deposit_transaction_id IS NULL, 0, COALESCE(LedgerEntry.amount,0))) AS 'deposited'";
|
|
$query['fields'][] = "SUM(IF(nsf_transaction_id IS NULL, 0, COALESCE(LedgerEntry.amount,0))) AS 'nsf'";
|
|
|
|
$this->id = $id;
|
|
$stats = $this->find('first', $query);
|
|
return $stats[0];
|
|
}
|
|
|
|
}
|