Merge in from pre_0.1 branch
git-svn-id: file:///svn-source/pmgr/trunk/site@847 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -188,8 +188,7 @@ class Account extends AppModel {
|
||||
function relatedAccounts($attribute, $extra = null) {
|
||||
$this->cacheQueries = true;
|
||||
$accounts = $this->find('all', array
|
||||
('contain' => array('CurrentLedger'),
|
||||
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||
('fields' => array('Account.id', 'Account.name'),
|
||||
'conditions' => array('Account.'.$attribute => true),
|
||||
'order' => array('Account.name'),
|
||||
) + (isset($extra) ? $extra : array())
|
||||
@@ -213,21 +212,10 @@ class Account extends AppModel {
|
||||
* - Returns an array of accounts suitable for activity xxx
|
||||
*/
|
||||
|
||||
function invoiceAccounts() {
|
||||
return $this->relatedAccounts('invoices', array('order' => 'name'));
|
||||
}
|
||||
|
||||
function receiptAccounts() {
|
||||
return $this->relatedAccounts('receipts', array('order' => 'name'));
|
||||
}
|
||||
|
||||
function depositAccounts() {
|
||||
return $this->relatedAccounts('deposits', array('order' => 'name'));
|
||||
}
|
||||
|
||||
function refundAccounts() {
|
||||
return $this->relatedAccounts('refunds', array('order' => 'name'));
|
||||
}
|
||||
function invoiceAccounts() { return $this->relatedAccounts('invoices'); }
|
||||
function receiptAccounts() { return $this->relatedAccounts('receipts'); }
|
||||
function depositAccounts() { return $this->relatedAccounts('deposits'); }
|
||||
function refundAccounts() { return $this->relatedAccounts('refunds'); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
@@ -41,14 +41,15 @@ class Contact extends AppModel {
|
||||
function saveContact($id, $data) {
|
||||
|
||||
// Establish a display name if not already given
|
||||
if (!$data['Contact']['display_name'])
|
||||
if (!$data['Contact']['display_name'] &&
|
||||
$data['Contact']['first_name'] && $data['Contact']['last_name'])
|
||||
$data['Contact']['display_name'] =
|
||||
(($data['Contact']['first_name'] &&
|
||||
$data['Contact']['last_name'])
|
||||
? $data['Contact']['last_name'] . ', ' . $data['Contact']['first_name']
|
||||
: ($data['Contact']['first_name']
|
||||
? $data['Contact']['first_name']
|
||||
: $data['Contact']['last_name']));
|
||||
$data['Contact']['last_name'] . ', ' . $data['Contact']['first_name'];
|
||||
|
||||
foreach (array('last_name', 'first_name', 'company_name') AS $fld) {
|
||||
if (!$data['Contact']['display_name'] && $data['Contact'][$fld])
|
||||
$data['Contact']['display_name'] = $data['Contact'][$fld];
|
||||
}
|
||||
|
||||
// Save the contact data
|
||||
$this->create();
|
||||
|
||||
@@ -54,17 +54,19 @@ class Customer extends AppModel {
|
||||
* function: leaseIds
|
||||
* - Returns the lease IDs for the given customer
|
||||
*/
|
||||
function leaseIds($id) {
|
||||
function leaseIds($id, $current = false) {
|
||||
$Lease = $current ? 'CurrentLease' : 'Lease';
|
||||
|
||||
$this->cacheQueries = true;
|
||||
$customer = $this->find('first',
|
||||
array('contain' =>
|
||||
array('Lease' => array('fields' => array('id'))),
|
||||
array($Lease => array('fields' => array('id'))),
|
||||
'fields' => array(),
|
||||
'conditions' => array(array('Customer.id' => $id))));
|
||||
$this->cacheQueries = false;
|
||||
|
||||
$ids = array();
|
||||
foreach ($customer['Lease'] AS $lease)
|
||||
foreach ($customer[$Lease] AS $lease)
|
||||
$ids[] = $lease['id'];
|
||||
|
||||
return $ids;
|
||||
|
||||
21
models/default_option.php
Normal file
21
models/default_option.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
class DefaultOption extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('OptionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($name = null) {
|
||||
$this->prEnter(compact('name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['DefaultOption'] = array();
|
||||
$query['link']['DefaultOption']['type'] = 'INNER';
|
||||
$query['link']['DefaultOption']['fields'] = array();
|
||||
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
21
models/default_permission.php
Normal file
21
models/default_permission.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
class DefaultPermission extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('PermissionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($name = null) {
|
||||
$this->prEnter(compact('name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['DefaultPermission'] = array();
|
||||
$query['link']['DefaultPermission']['type'] = 'INNER';
|
||||
$query['link']['DefaultPermission']['fields'] = array();
|
||||
return $this->prReturn($this->PermissionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
38
models/group.php
Normal file
38
models/group.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
class Group extends AppModel {
|
||||
|
||||
var $hasMany =
|
||||
array('GroupOption',
|
||||
'Membership',
|
||||
);
|
||||
|
||||
var $knows =
|
||||
array('User',
|
||||
'Site',
|
||||
);
|
||||
|
||||
static $current_group_ids;
|
||||
function currentGroupIds() {
|
||||
if (empty(self::$current_group_ids))
|
||||
self::$current_group_ids = $this->groupIds();
|
||||
|
||||
if (empty(self::$current_group_ids))
|
||||
// We must force a stop here, since this is typically
|
||||
// called very early on, and so will cause a recursive
|
||||
// crash as we try to render the internal error and
|
||||
// again stumble on this problem.
|
||||
$this->INTERNAL_ERROR('INVALID MEMBERSHIP', 0, true);
|
||||
|
||||
return self::$current_group_ids;
|
||||
}
|
||||
|
||||
function groupIds($user_id = null, $site_id = null) {
|
||||
if (empty($user_id))
|
||||
$user_id = $this->User->currentUserId();
|
||||
if (empty($site_id))
|
||||
$site_id = $this->Site->currentSiteId();
|
||||
|
||||
return $this->Membership->memberGroups($user_id, $site_id);
|
||||
}
|
||||
|
||||
}
|
||||
25
models/group_option.php
Normal file
25
models/group_option.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
class GroupOption extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Group',
|
||||
'OptionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($ids, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['GroupOption'] = array();
|
||||
$query['link']['GroupOption']['fields'] = array();
|
||||
$query['link']['GroupOption']['Group'] = array();
|
||||
$query['link']['GroupOption']['Group']['fields'] = array();
|
||||
$query['conditions'][] = array('Group.id' => $ids);
|
||||
$query['order'][] = 'Group.rank';
|
||||
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
25
models/group_permission.php
Normal file
25
models/group_permission.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
class GroupPermission extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Group',
|
||||
'PermissionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($ids, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['GroupPermission'] = array();
|
||||
$query['link']['GroupPermission']['fields'] = array();
|
||||
$query['link']['GroupPermission']['Group'] = array();
|
||||
$query['link']['GroupPermission']['Group']['fields'] = array();
|
||||
$query['conditions'][] = array('Group.id' => $ids);
|
||||
$query['order'][] = 'Group.rank';
|
||||
return $this->prReturn($this->PermissionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
37
models/membership.php
Normal file
37
models/membership.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
class Membership extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('User',
|
||||
'Site',
|
||||
'Group'
|
||||
);
|
||||
|
||||
function memberGroups($user_id, $site_id) {
|
||||
$this->prEnter(compact('user_id', 'site_id'));
|
||||
|
||||
$this->cacheQueries = true;
|
||||
$groups = $this->find('all', array
|
||||
('recursive' => -1,
|
||||
'fields' => array('group_id'),
|
||||
'conditions' => array(array('user_id' => $user_id),
|
||||
array('site_id' => $site_id)),
|
||||
));
|
||||
$this->cacheQueries = false;
|
||||
|
||||
if (empty($groups))
|
||||
return $this->prReturn(null);
|
||||
|
||||
$group_ids = array();
|
||||
foreach ($groups AS $group)
|
||||
$group_ids[] = $group['Membership']['group_id'];
|
||||
|
||||
return $this->prReturn($group_ids);
|
||||
}
|
||||
|
||||
function memberOf($user_id, $site_id) {
|
||||
$groups = $this->memberGroups($user_id, $site_id);
|
||||
return (!empty($groups));
|
||||
}
|
||||
|
||||
}
|
||||
76
models/option.php
Normal file
76
models/option.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
class Option extends AppModel {
|
||||
|
||||
var $hasMany =
|
||||
array('OptionValue',
|
||||
);
|
||||
|
||||
var $knows =
|
||||
array('User', 'Site', 'Group');
|
||||
|
||||
|
||||
static $option_set = array();
|
||||
|
||||
function getAll($name, $force = false) {
|
||||
/* $this->prClassLevel(30); */
|
||||
/* //$this->OptionValue->prClassLevel(30); */
|
||||
/* $this->Group->Membership->prClassLevel(30); */
|
||||
/* $this->OptionValue->SiteOption->prClassLevel(30); */
|
||||
/* $this->OptionValue->UserOption->prClassLevel(30); */
|
||||
/* $this->OptionValue->GroupOption->prClassLevel(30); */
|
||||
/* $this->OptionValue->DefaultOption->prClassLevel(30); */
|
||||
$this->prEnter(compact('name'));
|
||||
|
||||
if (!empty(self::$option_set[$name]) && !$force)
|
||||
return $this->prReturn(self::$option_set[$name]);
|
||||
|
||||
self::$option_set[$name] = array();
|
||||
|
||||
$site_id = $this->Site->currentSiteId();
|
||||
$user_id = $this->User->currentUserId();
|
||||
$group_ids = $this->Group->currentGroupIds();
|
||||
|
||||
/* $site_id = 2; */
|
||||
/* $user_id = 4; */
|
||||
/* $group_ids = $this->Group->groupIds($user_id, $site_id); */
|
||||
|
||||
if (!empty($site_id))
|
||||
self::$option_set[$name] =
|
||||
array_merge(self::$option_set[$name],
|
||||
$this->OptionValue->SiteOption->values($site_id, $name));
|
||||
|
||||
if (!empty($user_id))
|
||||
self::$option_set[$name] =
|
||||
array_merge(self::$option_set[$name],
|
||||
$this->OptionValue->UserOption->values($user_id, $name));
|
||||
|
||||
if (!empty($group_ids))
|
||||
self::$option_set[$name] =
|
||||
array_merge(self::$option_set[$name],
|
||||
$this->OptionValue->GroupOption->values($group_ids, $name));
|
||||
|
||||
self::$option_set[$name] =
|
||||
array_merge(self::$option_set[$name],
|
||||
$this->OptionValue->DefaultOption->values($name));
|
||||
|
||||
return $this->prReturn(self::$option_set[$name]);
|
||||
}
|
||||
|
||||
function get($name) {
|
||||
$this->prEnter(compact('name'));
|
||||
$values = $this->getAll($name);
|
||||
if (empty($values))
|
||||
return null;
|
||||
return $this->prReturn($values[0]);
|
||||
}
|
||||
|
||||
function enabled($name) {
|
||||
$val = $this->get($name);
|
||||
return (!empty($val));
|
||||
}
|
||||
|
||||
function disabled($name) {
|
||||
return (!$this->enabled($name));
|
||||
}
|
||||
|
||||
}
|
||||
35
models/option_value.php
Normal file
35
models/option_value.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
class OptionValue extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Option',
|
||||
);
|
||||
|
||||
var $hasMany =
|
||||
array('UserOption',
|
||||
'SiteOption',
|
||||
'GroupOption',
|
||||
'DefaultOption',
|
||||
);
|
||||
|
||||
function values($name = null, $query = null) {
|
||||
$this->prEnter(compact('name', 'query'));
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['Option'] = array();
|
||||
|
||||
if (!empty($name)) {
|
||||
$query['conditions'][] = array('Option.name' => $name);
|
||||
$query['link']['Option']['fields'] = array();
|
||||
}
|
||||
|
||||
$this->cacheQueries = true;
|
||||
$values = array();
|
||||
foreach ($this->find('all', $query) AS $result)
|
||||
$values[] = $result['OptionValue']['value'];
|
||||
$this->cacheQueries = false;
|
||||
|
||||
return $this->prReturn($values);
|
||||
}
|
||||
|
||||
}
|
||||
105
models/permission.php
Normal file
105
models/permission.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
class Permission extends AppModel {
|
||||
|
||||
var $hasMany =
|
||||
array('PermissionValue',
|
||||
);
|
||||
|
||||
var $knows =
|
||||
array('User', 'Site', 'Group');
|
||||
|
||||
static $permission_set = array();
|
||||
|
||||
function getAll($name, $force = false) {
|
||||
/* $this->prClassLevel(30); */
|
||||
/* $this->PermissionValue->prClassLevel(30); */
|
||||
/* $this->Group->Membership->prClassLevel(30); */
|
||||
/* $this->PermissionValue->SitePermission->prClassLevel(30); */
|
||||
/* $this->PermissionValue->UserPermission->prClassLevel(30); */
|
||||
/* $this->PermissionValue->GroupPermission->prClassLevel(30); */
|
||||
/* $this->PermissionValue->DefaultPermission->prClassLevel(30); */
|
||||
$this->prEnter(compact('name'));
|
||||
|
||||
if (!empty(self::$permission_set[$name]) && !$force)
|
||||
return $this->prReturn(self::$permission_set[$name]);
|
||||
|
||||
self::$permission_set[$name] = array();
|
||||
|
||||
$site_id = $this->Site->currentSiteId();
|
||||
$user_id = $this->User->currentUserId();
|
||||
$group_ids = $this->Group->currentGroupIds();
|
||||
|
||||
/* $site_id = 1; */
|
||||
/* $user_id = 2; */
|
||||
/* $group_ids = $this->Group->groupIds($user_id, $site_id); */
|
||||
|
||||
if (empty($group_ids)) {
|
||||
self::$permission_set[$name][$name][] = array('access' => 'DENY', 'level' => null);
|
||||
$site_id = null;
|
||||
$user_id = null;
|
||||
}
|
||||
|
||||
if (!empty($site_id))
|
||||
self::$permission_set[$name] =
|
||||
array_merge(self::$permission_set[$name],
|
||||
$this->PermissionValue->SitePermission->values($site_id, $name));
|
||||
|
||||
if (!empty($user_id))
|
||||
self::$permission_set[$name] =
|
||||
array_merge(self::$permission_set[$name],
|
||||
$this->PermissionValue->UserPermission->values($user_id, $name));
|
||||
|
||||
if (!empty($group_ids)) {
|
||||
self::$permission_set[$name] =
|
||||
array_merge(self::$permission_set[$name],
|
||||
$this->PermissionValue->GroupPermission->values($group_ids, $name));
|
||||
|
||||
self::$permission_set[$name] =
|
||||
array_merge(self::$permission_set[$name],
|
||||
$this->PermissionValue->DefaultPermission->values($name));
|
||||
|
||||
self::$permission_set[$name][] = array('access' => 'ALLOW', 'level' => null);
|
||||
}
|
||||
|
||||
return $this->prReturn(self::$permission_set[$name]);
|
||||
}
|
||||
|
||||
function get($name) {
|
||||
$this->prEnter(compact('name'));
|
||||
|
||||
// REVISIT <AP>: 20090827
|
||||
// This is a pretty crappy algorithm. How do we decide whether DENY really
|
||||
// means DENY, or whether an ALLOW has priority.
|
||||
// Oh well, it works for now...
|
||||
|
||||
$values = $this->getAll($name);
|
||||
$result = array_shift($values);
|
||||
|
||||
foreach ($values AS $value)
|
||||
if (empty($result['level']) || (!empty($value['level']) && $value['level'] < $result['level']))
|
||||
$result['level'] = $value['level'];
|
||||
|
||||
if ($result['access'] !== 'ALLOW')
|
||||
$result['level'] = 9999999;
|
||||
|
||||
return $this->prReturn($result);
|
||||
}
|
||||
|
||||
function allow($name) {
|
||||
$this->prEnter(compact('name'));
|
||||
$result = $this->get($name);
|
||||
return $this->prReturn($result['access'] === 'ALLOW');
|
||||
}
|
||||
|
||||
function deny($name) {
|
||||
$this->prEnter(compact('name'));
|
||||
return $this->prReturn(!$this->allow($name));
|
||||
}
|
||||
|
||||
function level($name) {
|
||||
$this->prEnter(compact('name'));
|
||||
$result = $this->get($name);
|
||||
return $this->prReturn($result['level']);
|
||||
}
|
||||
|
||||
}
|
||||
36
models/permission_value.php
Normal file
36
models/permission_value.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
class PermissionValue extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Permission',
|
||||
);
|
||||
|
||||
var $hasMany =
|
||||
array('UserPermission',
|
||||
'SitePermission',
|
||||
'GroupPermission',
|
||||
'DefaultPermission',
|
||||
);
|
||||
|
||||
function values($name = null, $query = null) {
|
||||
$this->prEnter(compact('name', 'query'));
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['Permission'] = array();
|
||||
|
||||
if (!empty($name)) {
|
||||
$query['conditions'][] = array('Permission.name' => $name);
|
||||
$query['link']['Permission']['fields'] = array();
|
||||
}
|
||||
|
||||
$this->cacheQueries = true;
|
||||
$values = array();
|
||||
foreach ($this->find('all', $query) AS $result)
|
||||
$values[] = array('access' => $result['PermissionValue']['access'],
|
||||
'level' => $result['PermissionValue']['level']);
|
||||
$this->cacheQueries = false;
|
||||
|
||||
return $this->prReturn($values);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,37 @@
|
||||
<?php
|
||||
class Site extends AppModel {
|
||||
|
||||
var $name = 'Site';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'name' => array('notempty')
|
||||
);
|
||||
var $hasMany =
|
||||
array('SiteArea',
|
||||
'SiteOption',
|
||||
'Membership',
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'SiteArea',
|
||||
'SiteOption',
|
||||
);
|
||||
static $current_site_id;
|
||||
|
||||
function currentSiteId() {
|
||||
if (!empty(self::$current_site_id))
|
||||
return self::$current_site_id;
|
||||
|
||||
// REVISIT <AP>: 20090827
|
||||
// Must get the actual site
|
||||
$code = 'VSS';
|
||||
|
||||
$site = $this->find
|
||||
('first',
|
||||
array('recursive' => -1,
|
||||
'conditions' => compact('code')));
|
||||
|
||||
if (!empty($site['Site']['id']))
|
||||
self::$current_site_id = $site['Site']['id'];
|
||||
else
|
||||
// We must force a stop here, since this is typically
|
||||
// called very early on, and so will cause a recursive
|
||||
// crash as we try to render the internal error and
|
||||
// again stumble on this problem.
|
||||
$this->INTERNAL_ERROR('UNKNOWN SITE', 0, true);
|
||||
|
||||
return self::$current_site_id;
|
||||
}
|
||||
}
|
||||
?>
|
||||
24
models/site_option.php
Normal file
24
models/site_option.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class SiteOption extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Site',
|
||||
'OptionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($id, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['SiteOption'] = array();
|
||||
$query['link']['SiteOption']['fields'] = array();
|
||||
$query['link']['SiteOption']['Site'] = array();
|
||||
$query['link']['SiteOption']['Site']['fields'] = array();
|
||||
$query['conditions'][] = array('Site.id' => $id);
|
||||
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
24
models/site_permission.php
Normal file
24
models/site_permission.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class SitePermission extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('Site',
|
||||
'PermissionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($id, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['SitePermission'] = array();
|
||||
$query['link']['SitePermission']['fields'] = array();
|
||||
$query['link']['SitePermission']['Site'] = array();
|
||||
$query['link']['SitePermission']['Site']['fields'] = array();
|
||||
$query['conditions'][] = array('Site.id' => $id);
|
||||
return $this->prReturn($this->PermissionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -350,10 +350,14 @@ class Transaction extends AppModel {
|
||||
if (isset($ids['transaction_id']))
|
||||
$ids['deposit_id'] = $ids['transaction_id'];
|
||||
|
||||
if (!empty($ids['deposit_id']) && !empty($control['update_tender'])) {
|
||||
$this->pr(21, array_intersect_key($ids, array('deposit_id'=>1))
|
||||
+ array_intersect_key($data['control'], array('update_tender'=>1)));
|
||||
|
||||
if (!empty($ids['deposit_id']) && !empty($data['control']['update_tender'])) {
|
||||
$this->pr(21, compact('tender_groups'));
|
||||
foreach ($tender_groups AS $group => $tender_ids) {
|
||||
$entry_id = $ids['entries'][$group]['DoubleEntry']['Entry2']['ledger_entry_id'];
|
||||
$this->pr(10, compact('group', 'tender_ids', 'entry_id'));
|
||||
$this->pr(19, compact('group', 'tender_ids', 'entry_id'));
|
||||
$this->LedgerEntry->Tender->updateAll
|
||||
(array('Tender.deposit_transaction_id' => $ids['deposit_id'],
|
||||
'Tender.deposit_ledger_entry_id' => $entry_id),
|
||||
@@ -530,6 +534,8 @@ class Transaction extends AppModel {
|
||||
(in_array($transaction['type'], array('INVOICE', 'RECEIPT'))
|
||||
&& empty($transaction['customer_id']))
|
||||
) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Transaction verification failed');
|
||||
return $this->prReturn(false);
|
||||
}
|
||||
|
||||
@@ -545,6 +551,8 @@ class Transaction extends AppModel {
|
||||
}
|
||||
if (!empty($se) &&
|
||||
!$this->StatementEntry->verifyStatementEntry($se)) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Transaction entry verification failed');
|
||||
return $this->prReturn(false);
|
||||
}
|
||||
}
|
||||
@@ -584,8 +592,11 @@ class Transaction extends AppModel {
|
||||
|
||||
// Save transaction to the database
|
||||
$this->create();
|
||||
if (!$this->save($transaction))
|
||||
if (!$this->save($transaction)) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Failed to save Transaction');
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
}
|
||||
$ret['transaction_id'] = $transaction['id'] = $this->id;
|
||||
|
||||
// Add the entries
|
||||
@@ -661,6 +672,11 @@ class Transaction extends AppModel {
|
||||
if (!empty($transaction['customer_id'])) {
|
||||
$this->Customer->update($transaction['customer_id']);
|
||||
}
|
||||
|
||||
if (!empty($ret['error']))
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Failed to save Transaction');
|
||||
|
||||
return $this->prReturn($ret);
|
||||
}
|
||||
|
||||
@@ -681,8 +697,11 @@ class Transaction extends AppModel {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries', 'split'));
|
||||
|
||||
// Verify that we have a transaction
|
||||
if (empty($transaction['id']))
|
||||
if (empty($transaction['id'])) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Invalid Transaction ID for adding entries');
|
||||
return $this->prReturn(array('error' => true));
|
||||
}
|
||||
|
||||
// If the entries are not already split, do so now.
|
||||
if ($split) {
|
||||
@@ -742,6 +761,10 @@ class Transaction extends AppModel {
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($ret['error']))
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Failed to save Transaction Entries');
|
||||
|
||||
return $this->prReturn($ret);
|
||||
}
|
||||
|
||||
@@ -762,8 +785,11 @@ class Transaction extends AppModel {
|
||||
|
||||
// Verify that we have a transaction and entries
|
||||
if (empty($transaction) ||
|
||||
(empty($entries) && empty($control['allow_no_entries'])))
|
||||
(empty($entries) && empty($control['allow_no_entries']))) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Split Entries failed to validate');
|
||||
return $this->prReturn(array('error' => true));
|
||||
}
|
||||
|
||||
// set ledger ID as the current ledger of the specified account
|
||||
if (empty($transaction['ledger_id']))
|
||||
@@ -972,8 +998,11 @@ class Transaction extends AppModel {
|
||||
));
|
||||
|
||||
$this->pr(20, compact('nsf_ledger_entry'));
|
||||
if (!$nsf_ledger_entry)
|
||||
if (!$nsf_ledger_entry) {
|
||||
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
|
||||
$this->INTERNAL_ERROR('Failed to locate NSF ledger entry');
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
}
|
||||
|
||||
// Build a transaction to adjust all of the statement entries
|
||||
$rollback =
|
||||
|
||||
@@ -87,6 +87,23 @@ class Unit extends AppModel {
|
||||
return $this->prReturn(true);
|
||||
}
|
||||
|
||||
function locked($enum) {
|
||||
return $this->statusCheck($enum, 'LOCKED', false, null, false);
|
||||
}
|
||||
|
||||
function conditionLocked() {
|
||||
//return array('Unit.status' => 'LOCKED');
|
||||
return ('Unit.status >= ' . $this->statusValue('LOCKED'));
|
||||
}
|
||||
|
||||
function liened($enum) {
|
||||
return $this->statusCheck($enum, 'LIENED', false, null, false);
|
||||
}
|
||||
|
||||
function conditionLiened() {
|
||||
return ('Unit.status >= ' . $this->statusValue('LIENED'));
|
||||
}
|
||||
|
||||
function occupied($enum) {
|
||||
return $this->statusCheck($enum, 'OCCUPIED', false, null, false);
|
||||
}
|
||||
@@ -115,6 +132,7 @@ class Unit extends AppModel {
|
||||
}
|
||||
|
||||
function available($enum) { return $this->vacant($enum); }
|
||||
function conditionAvailable() { return $this->conditionVacant($enum); }
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
|
||||
@@ -1,25 +1,64 @@
|
||||
<?php
|
||||
class UnitSize extends AppModel {
|
||||
|
||||
var $name = 'UnitSize';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'unit_type_id' => array('numeric'),
|
||||
'code' => array('notempty'),
|
||||
'name' => array('notempty'),
|
||||
'width' => array('numeric'),
|
||||
'depth' => array('numeric'),
|
||||
'deposit' => array('money'),
|
||||
'amount' => array('money')
|
||||
);
|
||||
var $belongsTo =
|
||||
array(
|
||||
'UnitType',
|
||||
);
|
||||
|
||||
var $belongsTo = array(
|
||||
'UnitType',
|
||||
);
|
||||
var $hasMany =
|
||||
array(
|
||||
'Unit',
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'Unit',
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: stats
|
||||
* - Returns summary data from the requested unit size.
|
||||
*/
|
||||
|
||||
function stats($id = null) {
|
||||
$this->prEnter(compact('id'));
|
||||
|
||||
// Right now, we only work with id not null
|
||||
if (!$id)
|
||||
return null;
|
||||
|
||||
$stats = array();
|
||||
|
||||
// Get the total number of units this size
|
||||
$stats['all'] =
|
||||
$this->find('count',
|
||||
array('link' => array('Unit'),
|
||||
'conditions' => array(array('UnitSize.id' => $id)),
|
||||
));
|
||||
|
||||
// Get numbers for units in the various states
|
||||
foreach (array('unavailable', 'vacant', 'occupied', 'locked', 'liened') AS $status) {
|
||||
$statusfunc = 'condition' . ucfirst($status);
|
||||
$stats[$status] =
|
||||
$this->find('count',
|
||||
array('link' => array('Unit'),
|
||||
'conditions' => array(array('UnitSize.id' => $id),
|
||||
$this->Unit->{$statusfunc}()),
|
||||
));
|
||||
}
|
||||
|
||||
// Count up each unit by physical status
|
||||
foreach
|
||||
($this->find('all',
|
||||
array('link' => array('Unit' => array('fields' => array())),
|
||||
'fields' => array('Unit.status', 'COUNT(Unit.id) AS total'),
|
||||
'conditions' => array(array('UnitSize.id' => $id)),
|
||||
'group' => 'Unit.status',
|
||||
)) AS $status) {
|
||||
$stats['status'][$status['Unit']['status']] = $status[0]['total'];
|
||||
}
|
||||
|
||||
// Return the collection
|
||||
return $this->prReturn($stats);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,16 +1,50 @@
|
||||
<?php
|
||||
class UnitType extends AppModel {
|
||||
|
||||
var $name = 'UnitType';
|
||||
var $validate = array(
|
||||
'id' => array('numeric'),
|
||||
'code' => array('notempty'),
|
||||
'name' => array('notempty')
|
||||
);
|
||||
var $hasMany =
|
||||
array(
|
||||
'UnitSize',
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'UnitSize',
|
||||
);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: relatedTypes
|
||||
* - Returns an array of types related by similar attributes
|
||||
*/
|
||||
|
||||
function relatedTypes($attribute, $extra = null) {
|
||||
$this->cacheQueries = true;
|
||||
$types = $this->find('all', array
|
||||
('fields' => array('UnitType.id', 'UnitType.name'),
|
||||
'conditions' => array('UnitType.'.$attribute => true),
|
||||
'order' => array('UnitType.name'),
|
||||
) + (isset($extra) ? $extra : array())
|
||||
);
|
||||
$this->cacheQueries = false;
|
||||
|
||||
// Rearrange to be of the form (id => name)
|
||||
$rel_types = array();
|
||||
foreach ($types AS $type) {
|
||||
$rel_types[$type['UnitType']['id']] = $type['UnitType']['name'];
|
||||
}
|
||||
|
||||
return $rel_types;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: xxxTypes
|
||||
* - Returns an array of types suitable for activity xxx
|
||||
*/
|
||||
|
||||
function residentialTypes() { return $this->relatedTypes('residential'); }
|
||||
function enclosedTypes() { return $this->relatedTypes('enclosed'); }
|
||||
function climateTypes() { return $this->relatedTypes('climate'); }
|
||||
function outdoorTypes() { return $this->relatedTypes('outdoor'); }
|
||||
function coveredTypes() { return $this->relatedTypes('covered'); }
|
||||
|
||||
}
|
||||
?>
|
||||
39
models/user.php
Normal file
39
models/user.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
class User extends AppModel {
|
||||
|
||||
var $hasMany =
|
||||
array('UserOption',
|
||||
'Membership',
|
||||
);
|
||||
|
||||
static $current_user_id;
|
||||
|
||||
function currentUser() {
|
||||
if (!empty($_SERVER['REMOTE_USER']))
|
||||
return $_SERVER['REMOTE_USER'];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function currentUserId() {
|
||||
if (!empty(self::$current_user_id))
|
||||
return self::$current_user_id;
|
||||
|
||||
$user = $this->find
|
||||
('first',
|
||||
array('recursive' => -1,
|
||||
'conditions' => array('login' => $this->currentUser())));
|
||||
|
||||
if (!empty($user['User']['id']))
|
||||
self::$current_user_id = $user['User']['id'];
|
||||
else
|
||||
// We must force a stop here, since this is typically
|
||||
// called very early on, and so will cause a recursive
|
||||
// crash as we try to render the internal error and
|
||||
// again stumble on this problem.
|
||||
$this->INTERNAL_ERROR('UNKNOWN USER', 0, true);
|
||||
|
||||
return self::$current_user_id;
|
||||
}
|
||||
|
||||
}
|
||||
24
models/user_option.php
Normal file
24
models/user_option.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class UserOption extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('User',
|
||||
'OptionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($id, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['UserOption'] = array();
|
||||
$query['link']['UserOption']['fields'] = array();
|
||||
$query['link']['UserOption']['User'] = array();
|
||||
$query['link']['UserOption']['User']['fields'] = array();
|
||||
$query['conditions'][] = array('User.id' => $id);
|
||||
return $this->prReturn($this->OptionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
24
models/user_permission.php
Normal file
24
models/user_permission.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class UserPermission extends AppModel {
|
||||
|
||||
var $belongsTo =
|
||||
array('User',
|
||||
'PermissionValue',
|
||||
);
|
||||
|
||||
|
||||
function values($id, $name = null) {
|
||||
$this->prEnter(compact('id', 'name'));
|
||||
|
||||
$query = array();
|
||||
$this->queryInit($query);
|
||||
|
||||
$query['link']['UserPermission'] = array();
|
||||
$query['link']['UserPermission']['fields'] = array();
|
||||
$query['link']['UserPermission']['User'] = array();
|
||||
$query['link']['UserPermission']['User']['fields'] = array();
|
||||
$query['conditions'][] = array('User.id' => $id);
|
||||
return $this->prReturn($this->PermissionValue->values($name, $query));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user