Compare commits
300 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 115c82cd21 | |||
| 331e235e77 | |||
| d0dfd8657c | |||
| 4d4bebc3d3 | |||
| ae04aafaca | |||
| fcb23d12a5 | |||
| dd7da1489d | |||
| 85cc6d7c6a | |||
| e457f87c42 | |||
| e8d12882cc | |||
| 8f2b43239d | |||
| 51d786ab8b | |||
| 6f4519fe56 | |||
| 69adfd900c | |||
| 33ba912a7e | |||
| c4942b922b | |||
| 2588fd6a91 | |||
| 3baa199fda | |||
| 68a10e783b | |||
| 34e3251240 | |||
| 01aa2d1697 | |||
| 69b3cf3ed3 | |||
| 3551ad0603 | |||
| f960349e0f | |||
| 4ad4033e4f | |||
| 00cff7bb3a | |||
| 3ffa3c81bb | |||
| 886a63773e | |||
| dc79667dca | |||
| 8039495e18 | |||
| 46417de2b8 | |||
| 14ab0975ac | |||
| 06bf383707 | |||
| e29c2ba927 | |||
| cec4fb4fdd | |||
| d5c80a65b3 | |||
| 0c0033d1f5 | |||
| d683895413 | |||
| f7b81ec615 | |||
| aa36213698 | |||
| ad3d1c92bf | |||
| fa17e319e0 | |||
| b96a8f01da | |||
| 62b27ec255 | |||
| 30292bb4f5 | |||
| 0d3403032c | |||
| 42dda55643 | |||
| b9a67fa8e1 | |||
| 6c89536073 | |||
| 43382f4ab1 | |||
| b79df98d36 | |||
| 99904f22bb | |||
| bcbe3767e3 | |||
| ba82eabcbc | |||
| e15f053c5c | |||
| 0c8035b402 | |||
| 55413590a2 | |||
| 99a787bba6 | |||
| fb29380ac5 | |||
| 37beb8b436 | |||
| 0e1b0c111e | |||
| 7483f6ed2c | |||
| a45fd6879d | |||
| 09090d1b3c | |||
| dbd914ff78 | |||
| 222758b20f | |||
| 233b08df59 | |||
| 849077bb9a | |||
| c01c67161e | |||
| 75c44d1b3a | |||
| 2aeb069297 | |||
| 21534c28d8 | |||
| 5f0c2463e3 | |||
| 7e0d8a9da2 | |||
| 4d123b63f0 | |||
| a88f5829ce | |||
| 5c29200428 | |||
| 33fa8e732c | |||
| 6c62d66068 | |||
| 4e2b073110 | |||
| abd166cb98 | |||
| cb627b8ec7 | |||
| c455b383f5 | |||
| ba36729485 | |||
| 011c05d098 | |||
| aa2e647199 | |||
| 472d2d7166 | |||
| 9ea397ff8f | |||
| 9c65d408fa | |||
| ae85ed7907 | |||
| 019b97fe53 | |||
| ae442db01f | |||
| 65e3c99ae9 | |||
| d4ceca3aeb | |||
| 4ea8f1ae42 | |||
| c1b402bd72 | |||
| ca0ddcbc29 | |||
| 5f8ae73049 | |||
| 66e2647c05 | |||
| 81e415e5bd | |||
| 85756975ae | |||
| 58d3cbf66b | |||
| 850d15eb50 | |||
| 280c5dae55 | |||
| 50e7f58d35 | |||
| 47104919f2 | |||
| 4dac7a7f0c | |||
| d51c29bc91 | |||
| 8237ca1f9d | |||
| 87f0d3217a | |||
| fbd43fbbb2 | |||
| 826874b2a5 | |||
| eab49091ae | |||
| e150237fd8 | |||
| 207808d6d5 | |||
| dc787bd9e7 | |||
| 61af7693cd | |||
| 24245e24f1 | |||
| ae276d310a | |||
| 0f9bafab31 | |||
| 41aa3f81a8 | |||
| bb78a85d1b | |||
| 90604bf672 | |||
| bb5c44f19f | |||
| 6c656b07c3 | |||
| 5f82404a4f | |||
| 9bb957aff4 | |||
| b335378edb | |||
| 3a1fb00527 | |||
| 6adf7e2358 | |||
| 99504c6de5 | |||
| e060c16252 | |||
| ed673de22f | |||
| dfe61cbc2a | |||
| b5d7ecc269 | |||
| 5fa166e881 | |||
| ea1ad4764f | |||
| dfe20e7ef9 | |||
| 3550bf775c | |||
| 5558079dcc | |||
| 18e1f4986a | |||
| 4b6da6cffa | |||
| 9fea9c79f3 | |||
| 10f71a1fe3 | |||
| 73eacdbcf2 | |||
| 009ea6b44d | |||
| 7ea002850a | |||
| eee3d45c5d | |||
| de93c7545b | |||
| e00e10bbb5 | |||
| 3953e1dbf3 | |||
| 788cbde710 | |||
| 4a064df594 | |||
| c048d44972 | |||
| f6d6659d2a | |||
| 19cee7290f | |||
| 3c067f6586 | |||
| f7bcfef665 | |||
| d06f34de9a | |||
| d5388e7767 | |||
| 5a88f29600 | |||
| 8dd64f60bc | |||
| de2319e93d | |||
| 1fbc452581 | |||
| 65acd0e181 | |||
| f5bb9bac83 | |||
| 45ae013e99 | |||
| 16126b7b6e | |||
| fdd3fe2641 | |||
| c340c25eee | |||
| b8de98917a | |||
| d6c7fbb735 | |||
| 5dd3efa12f | |||
| cb02b9e1e0 | |||
| 212c982851 | |||
| 0aa94b8fe5 | |||
| 76e9b7590f | |||
| af405a44d5 | |||
| 1f9772e926 | |||
| b1a0437117 | |||
| 8db9b90157 | |||
| 33b7d3d67d | |||
| 57c73eafdb | |||
| 30b3185473 | |||
| e9dd1366bc | |||
| 7ee461d993 | |||
| 365b2295af | |||
| dfb0d90246 | |||
| af32d88605 | |||
| c9c06a9fb4 | |||
| c3139220ee | |||
| 68273302cb | |||
| abd45244e1 | |||
| e3b838d62a | |||
| 5fd7483ac1 | |||
| 274ed13644 | |||
| 4537174873 | |||
| 3c5a31aaff | |||
| fd155aaaeb | |||
| 284765e06a | |||
| 352e3487cc | |||
| b02695631e | |||
| b6317d3ee9 | |||
| 2cbd5da8ee | |||
| 960ac108b8 | |||
| 0133c85c01 | |||
| 92d8387e8c | |||
| 67d640b1a0 | |||
| ddf4d5cb29 | |||
| 2143960ce9 | |||
| 06a4a25be8 | |||
| 25677ffa5e | |||
| f06d831329 | |||
| eefc0d7bce | |||
| 046ffba340 | |||
| cf0da7d3c2 | |||
| 95181f4718 | |||
| 447c6a8376 | |||
| 54291b4467 | |||
| 94c78ccb2a | |||
| 323c88a669 | |||
| 3fb680e20f | |||
| cbdd198be5 | |||
| 8cdf061fca | |||
| 5e321888d5 | |||
| d45481b770 | |||
| ff5c7260f8 | |||
| e2f623b7ee | |||
| b47bb9d46e | |||
| 9cf245d030 | |||
| 8bce19d8c4 | |||
| ab766c2dc5 | |||
| 4a53ebd70b | |||
| ce735cad3f | |||
| ef3b5f3022 | |||
| 73ea4fa86c | |||
| 806f732de6 | |||
| b78834f7d6 | |||
| a0274b4d89 | |||
| 970b2ad202 | |||
| e0d9edc4a8 | |||
| ffd1b64580 | |||
| 3dcd83229b | |||
| ebc4a42ae9 | |||
| f08884f326 | |||
| e740cc859b | |||
| f12a95f3b9 | |||
| 677458e942 | |||
| ce24abc812 | |||
| 1ead830ad6 | |||
| 0848ab5055 | |||
| 52c72b08b2 | |||
| fc71c058fb | |||
| dd5402d2f1 | |||
| f473a91870 | |||
| cdd274adf7 | |||
| 8ea0822ed1 | |||
| 492e70b2f6 | |||
| abff728a37 | |||
| b8c4257f95 | |||
| 5f715cc076 | |||
| f40dc205f9 | |||
| feaabd29d9 | |||
| f48e7d8907 | |||
| 991b5a3317 | |||
| 68585a0b30 | |||
| a9a570d666 | |||
| 15c4b96a2a | |||
| ce252f2e70 | |||
| 4b857ff11f | |||
| 6661d26c76 | |||
| b409bf09d1 | |||
| b488054106 | |||
| 59398cb3f0 | |||
| 1145d293b2 | |||
| 2feb7f60a4 | |||
| bd6cc37d4a | |||
| 8dae1ccf84 | |||
| 50449205b4 | |||
| 77c038e880 | |||
| 44bdb384f5 | |||
| 2b135b0e66 | |||
| 23ec1b6b20 | |||
| 8f4f3c054e | |||
| 1249854514 | |||
| 7805e4d229 | |||
| 54c7287ee4 | |||
| bcec2a9891 | |||
| e772ff8755 | |||
| 3288969b0d | |||
| d268b6fe7e | |||
| e9b31d964c | |||
| 47d362750e | |||
| 47af64aefe | |||
| 1ca704157b | |||
| 8a3be97d41 | |||
| 05a4ee38f0 | |||
| 0e68fea04b | |||
| a9f47d73ba | |||
| 5b5e478bd0 |
@@ -35,7 +35,7 @@
|
|||||||
* @subpackage cake.app
|
* @subpackage cake.app
|
||||||
*/
|
*/
|
||||||
class AppController extends Controller {
|
class AppController extends Controller {
|
||||||
var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time');
|
var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time', 'Grid');
|
||||||
var $components = array('DebugKit.Toolbar');
|
var $components = array('DebugKit.Toolbar');
|
||||||
|
|
||||||
function sideMenuLinks() {
|
function sideMenuLinks() {
|
||||||
@@ -45,9 +45,12 @@ class AppController extends Controller {
|
|||||||
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
|
array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')),
|
||||||
array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')),
|
array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')),
|
||||||
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
|
array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')),
|
||||||
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
|
||||||
array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')),
|
array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')),
|
||||||
|
array('name' => 'Debug', 'header' => true),
|
||||||
|
array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')),
|
||||||
array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')),
|
array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')),
|
||||||
|
array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')),
|
||||||
|
array('name' => 'RESET DATA', 'url' => array('controller' => 'accounts', 'action' => 'reset_data')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +58,28 @@ class AppController extends Controller {
|
|||||||
$this->set('sidemenu', $this->sideMenuLinks());
|
$this->set('sidemenu', $this->sideMenuLinks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reset_data() {
|
||||||
|
$this->layout = null;
|
||||||
|
$this->autoLayout = false;
|
||||||
|
$this->autoRender = false;
|
||||||
|
Configure::write('debug', '0');
|
||||||
|
$script = $_SERVER['DOCUMENT_ROOT'] . '/pmgr/build.cmd';
|
||||||
|
echo "<P>" . date('r') . "\n";
|
||||||
|
//echo "<P>Script: $script" . "\n";
|
||||||
|
$db = & $this->Account->getDataSource();
|
||||||
|
$script .= ' "' . $db->config['database'] . '"';
|
||||||
|
$script .= ' "' . $db->config['login'] . '"';
|
||||||
|
$script .= ' "' . $db->config['password'] . '"';
|
||||||
|
$handle = popen($script . ' 2>&1', 'r');
|
||||||
|
//echo "<P>Handle: $handle; " . gettype($handle) . "\n";
|
||||||
|
echo "<P><PRE>\n";
|
||||||
|
while (($read = fread($handle, 2096))) {
|
||||||
|
echo $read;
|
||||||
|
}
|
||||||
|
echo "</PRE>\n";
|
||||||
|
pclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -63,12 +88,12 @@ class AppController extends Controller {
|
|||||||
* - called by function to create an index listing
|
* - called by function to create an index listing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function jqGridView($title, $action = null) {
|
function jqGridView($title, $action = null, $element = null) {
|
||||||
$this->set('title', $title);
|
$this->set('title', $title);
|
||||||
// The resulting page will contain a jqGrid, which will
|
// The resulting page will contain a jqGrid, which will
|
||||||
// use ajax to obtain the actual data for this action
|
// use ajax to obtain the actual data for this action
|
||||||
$this->set('action', $action ? $action : $this->params['action']);
|
$this->set('action', $action ? $action : $this->params['action']);
|
||||||
$this->render('/elements/' . $this->params['controller']);
|
$this->render('/elements/' . ($element ? $element : $this->params['controller']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@@ -93,7 +118,11 @@ class AppController extends Controller {
|
|||||||
// Establish the basic query and conditions
|
// Establish the basic query and conditions
|
||||||
$query = array_intersect_key($this->jqGridDataCountTables($params, $model),
|
$query = array_intersect_key($this->jqGridDataCountTables($params, $model),
|
||||||
array('link'=>1, 'contain'=>1));
|
array('link'=>1, 'contain'=>1));
|
||||||
$query['conditions'] = $this->jqGridDataConditions($params, $model);
|
$query['conditions'] = $this->jqGridDataCountConditions($params, $model);
|
||||||
|
$query['group'] = $this->jqGridDataCountGroup($params, $model);
|
||||||
|
|
||||||
|
// DEBUG PURPOSES ONLY!
|
||||||
|
$params['count_query'] = $query;
|
||||||
|
|
||||||
// Get the number of records prior to pagination
|
// Get the number of records prior to pagination
|
||||||
$count = $this->jqGridDataRecordCount($params, $model, $query);
|
$count = $this->jqGridDataRecordCount($params, $model, $query);
|
||||||
@@ -119,15 +148,15 @@ class AppController extends Controller {
|
|||||||
$query['fields'] = $this->jqGridDataFields($params, $model);
|
$query['fields'] = $this->jqGridDataFields($params, $model);
|
||||||
$results = $this->jqGridDataRecords($params, $model, $query);
|
$results = $this->jqGridDataRecords($params, $model, $query);
|
||||||
|
|
||||||
|
// DEBUG PURPOSES ONLY!
|
||||||
|
$params['query'] = $query;
|
||||||
|
|
||||||
// Post process the records
|
// Post process the records
|
||||||
$this->jqGridRecordsPostProcess($params, $model, $results);
|
$this->jqGridRecordsPostProcess($params, $model, $results);
|
||||||
|
|
||||||
// Add in any needed hyperlinks
|
// Add in any needed hyperlinks
|
||||||
$this->jqGridRecordLinks($params, $model, $results, array());
|
$this->jqGridRecordLinks($params, $model, $results, array());
|
||||||
|
|
||||||
// DEBUG PURPOSES ONLY!
|
|
||||||
$params['query'] = $query;
|
|
||||||
|
|
||||||
// Finally, dump out the data
|
// Finally, dump out the data
|
||||||
$this->jqGridDataOutputHeader($params, $model);
|
$this->jqGridDataOutputHeader($params, $model);
|
||||||
echo "<?xml version='1.0' encoding='utf-8'?>\n";
|
echo "<?xml version='1.0' encoding='utf-8'?>\n";
|
||||||
@@ -206,6 +235,10 @@ class AppController extends Controller {
|
|||||||
return array('contain' => false);
|
return array('contain' => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridDataCountConditions(&$params, &$model) {
|
||||||
|
return $this->jqGridDataConditions($params, $model);
|
||||||
|
}
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
$searches = array();
|
$searches = array();
|
||||||
|
|
||||||
@@ -261,6 +294,10 @@ class AppController extends Controller {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function jqGridDataCountGroup(&$params, &$model) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
function jqGridDataGroup(&$params, &$model) {
|
function jqGridDataGroup(&$params, &$model) {
|
||||||
return $model->alias.'.'.$model->primaryKey;
|
return $model->alias.'.'.$model->primaryKey;
|
||||||
}
|
}
|
||||||
@@ -285,6 +322,14 @@ class AppController extends Controller {
|
|||||||
$model_alias = $model->alias;
|
$model_alias = $model->alias;
|
||||||
$id = $model->primaryKey;
|
$id = $model->primaryKey;
|
||||||
|
|
||||||
|
$subtotals = array();
|
||||||
|
foreach ($params['fields'] AS $field) {
|
||||||
|
if (preg_match('/subtotal-(.*)$/', $field, $matches))
|
||||||
|
$subtotals[] = array('field' => $matches[1],
|
||||||
|
'name' => $field,
|
||||||
|
'amount' => 0);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($records AS &$record) {
|
foreach ($records AS &$record) {
|
||||||
$record['jqGrid_id'] = $record[$model_alias][$id];
|
$record['jqGrid_id'] = $record[$model_alias][$id];
|
||||||
// Add the calculated fields (if any), to the model fields
|
// Add the calculated fields (if any), to the model fields
|
||||||
@@ -292,6 +337,19 @@ class AppController extends Controller {
|
|||||||
$record[$model_alias] += $record[0];
|
$record[$model_alias] += $record[0];
|
||||||
unset($record[0]);
|
unset($record[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($subtotals AS &$subtotal) {
|
||||||
|
$field = $subtotal['field'];
|
||||||
|
if (preg_match("/\./", $field)) {
|
||||||
|
list($tbl, $col) = explode(".", $field);
|
||||||
|
$record['subtotal-'.$tbl][$col] =
|
||||||
|
($subtotal['amount'] += $record[$tbl][$col]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$record[$model->alias]['subtotal-'.$field] =
|
||||||
|
($subtotal['amount'] += $record[$model->alias][$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG PURPOSES ONLY!
|
// DEBUG PURPOSES ONLY!
|
||||||
@@ -299,6 +357,10 @@ class AppController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
// Don't create any links if ordered not to.
|
||||||
|
if (isset($params['nolinks']))
|
||||||
|
return;
|
||||||
|
|
||||||
foreach ($links AS $table => $fields) {
|
foreach ($links AS $table => $fields) {
|
||||||
$special = array('controller', 'id');
|
$special = array('controller', 'id');
|
||||||
$controller = Inflector::pluralize(Inflector::underscore($table));
|
$controller = Inflector::pluralize(Inflector::underscore($table));
|
||||||
@@ -341,6 +403,11 @@ class AppController extends Controller {
|
|||||||
echo " <page>$page</page>\n";
|
echo " <page>$page</page>\n";
|
||||||
echo " <total>$total</total>\n";
|
echo " <total>$total</total>\n";
|
||||||
echo " <records>$records</records>\n";
|
echo " <records>$records</records>\n";
|
||||||
|
|
||||||
|
if (isset($params['userdata'])) {
|
||||||
|
foreach ($params['userdata'] AS $field => $value)
|
||||||
|
echo ' <userdata name="'.$field.'">' . "{$value}</userdata>\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataOutputRecords(&$params, &$model, &$records) {
|
function jqGridDataOutputRecords(&$params, &$model, &$records) {
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
class AppModel extends Model {
|
class AppModel extends Model {
|
||||||
|
|
||||||
var $actsAs = array('Containable', 'Linkable');
|
var $actsAs = array('Containable', 'Linkable');
|
||||||
|
var $useNullForEmpty = true;
|
||||||
|
var $formatDateFields = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Enum Values
|
* Get Enum Values
|
||||||
@@ -47,13 +49,15 @@ class AppModel extends Model {
|
|||||||
*
|
*
|
||||||
* Gets the enum values for MySQL 4 and 5 to use in selectTag()
|
* Gets the enum values for MySQL 4 and 5 to use in selectTag()
|
||||||
*/
|
*/
|
||||||
function getEnumValues($columnName=null, $respectDefault=false)
|
function getEnumValues($columnName=null, $tableName=null)
|
||||||
{
|
{
|
||||||
if ($columnName==null) { return array(); } //no field specified
|
if ($columnName==null) { return array(); } //no field specified
|
||||||
|
|
||||||
//Get the name of the table
|
if (!isset($tableName)) {
|
||||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
//Get the name of the table
|
||||||
$tableName = $db->fullTableName($this, false);
|
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
|
$tableName = $db->fullTableName($this, false);
|
||||||
|
}
|
||||||
|
|
||||||
//Get the values for the specified column (database and version specific, needs testing)
|
//Get the values for the specified column (database and version specific, needs testing)
|
||||||
$result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'");
|
$result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'");
|
||||||
@@ -72,12 +76,33 @@ class AppModel extends Model {
|
|||||||
|
|
||||||
//Get the values
|
//Get the values
|
||||||
return array_flip(array_merge(array(''), // MySQL sets 0 to be the empty string
|
return array_flip(array_merge(array(''), // MySQL sets 0 to be the empty string
|
||||||
explode("','", preg_replace("/(enum)\('(.+?)'\)/","\\2", $types))
|
explode("','", strtoupper(preg_replace("/(enum)\('(.+?)'\)/","\\2", $types)))
|
||||||
));
|
));
|
||||||
} //end getEnumValues
|
} //end getEnumValues
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: nameToID
|
||||||
|
* - Returns the ID of the named item
|
||||||
|
*/
|
||||||
|
function nameToID($name) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$item = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'conditions' => compact('name'),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
if ($item) {
|
||||||
|
$item = current($item);
|
||||||
|
return $item['id'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -111,6 +136,60 @@ class AppModel extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function recursive_array_replace($find, $replace, &$data) {
|
||||||
|
if (!isset($data))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (is_array($data)) {
|
||||||
|
foreach ($data as $key => &$value) {
|
||||||
|
$this->recursive_array_replace($find, $replace, $value);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($replace))
|
||||||
|
$data = preg_replace($find, $replace, $data);
|
||||||
|
elseif (preg_match($find, $data))
|
||||||
|
$data = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function beforeSave() {
|
||||||
|
/* pr(array('class' => $this->name, */
|
||||||
|
/* 'alias' => $this->alias, */
|
||||||
|
/* 'function' => 'AppModel::beforeSave')); */
|
||||||
|
|
||||||
|
// Replace all empty strings with NULL.
|
||||||
|
// If a particular model doesn't like this, they'll have to
|
||||||
|
// override the behavior, or set useNullForEmpty to false.
|
||||||
|
if ($this->useNullForEmpty)
|
||||||
|
$this->recursive_array_replace("/^\s*$/", null, $this->data);
|
||||||
|
|
||||||
|
if ($this->formatDateFields) {
|
||||||
|
$alias = $this->alias;
|
||||||
|
|
||||||
|
foreach ($this->_schema AS $field => $info) {
|
||||||
|
if ($info['type'] == 'date' || $info['type'] == 'timestamp') {
|
||||||
|
if (isset($this->data[$alias][$field])) {
|
||||||
|
/* pr("Fix Date for '$alias'.'$field'; current value = " . */
|
||||||
|
/* "'{$this->data[$alias][$field]}'"); */
|
||||||
|
if ($this->data[$alias][$field] === 'CURRENT_TIMESTAMP')
|
||||||
|
// Seems CakePHP is broken for the default timestamp.
|
||||||
|
// It tries to automagically set the value to CURRENT_TIMESTAMP
|
||||||
|
// which is wholly rejected by MySQL. Just put it back to NULL
|
||||||
|
// and let the SQL engine deal with the defaults... it's not
|
||||||
|
// Cake's place to do this anyway :-/
|
||||||
|
$this->data[$alias][$field] = null;
|
||||||
|
else
|
||||||
|
$this->data[$alias][$field] =
|
||||||
|
$this->dateFormatBeforeSave($this->data[$alias][$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -119,7 +198,16 @@ class AppModel extends Model {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function dateFormatBeforeSave($dateString) {
|
function dateFormatBeforeSave($dateString) {
|
||||||
return date('Y-m-d', strtotime($dateString));
|
/* $time = ''; */
|
||||||
|
/* if (preg_match('/(\d+(:\d+))/', $dateString, $match)) */
|
||||||
|
/* $time = ' '.$match[1]; */
|
||||||
|
/* $dateString = preg_replace('/(\d+(:\d+))/', '', $dateString); */
|
||||||
|
/* return date('Y-m-d', strtotime($dateString)) . $time; */
|
||||||
|
|
||||||
|
if (preg_match('/:/', $dateString))
|
||||||
|
return date('Y-m-d H:i:s', strtotime($dateString));
|
||||||
|
else
|
||||||
|
return date('Y-m-d', strtotime($dateString));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
@echo off
|
|
||||||
%~dp0\scripts\sitelink2pmgr.pl %~dp0\db\schema.sql %~dp0db\vss.mdb > NUL
|
|
||||||
echo Done!
|
|
||||||
@@ -26,14 +26,12 @@
|
|||||||
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
* Here, we are connecting '/' (base path) to our site map.
|
||||||
* its action called 'display', and we pass a param to select the view file
|
* It's hardcoded to map #1, but at some point we'll implement
|
||||||
* to use (in this case, /app/views/pages/home.ctp)...
|
* a login mechanism and the default path will be to log on instead.
|
||||||
*/
|
*/
|
||||||
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
Router::connect('/', array('controller' => 'maps', 'action' => 'view', '1'));
|
||||||
/**
|
|
||||||
* ...and connect the rest of 'Pages' controller's urls.
|
|
||||||
*/
|
|
||||||
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
|
||||||
?>
|
?>
|
||||||
@@ -12,6 +12,7 @@ class AccountsController extends AppController {
|
|||||||
array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')),
|
array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')),
|
||||||
array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')),
|
array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')),
|
||||||
array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')),
|
array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')),
|
||||||
|
array('name' => 'Bank Deposit', 'url' => array('controller' => 'accounts', 'action' => 'deposit')),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -119,6 +120,126 @@ class AccountsController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: newledger
|
||||||
|
* - Close the current account ledger and create a new one,
|
||||||
|
* carrying forward any balance if necessary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function newledger($id = null) {
|
||||||
|
if (!$this->Account->closeCurrentLedger($id)) {
|
||||||
|
$this->Session->setFlash(__('Unable to create new Ledger.', true));
|
||||||
|
}
|
||||||
|
if ($id)
|
||||||
|
$this->redirect(array('action'=>'view', $id));
|
||||||
|
else
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: collected
|
||||||
|
* - Displays the items actually collected for the period
|
||||||
|
* e.g. How much was collected in rent from 4/1/09 - 5/1/09
|
||||||
|
*/
|
||||||
|
function collected($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$payment_accounts = $this->Account->collectableAccounts();
|
||||||
|
//$payment_accounts[$this->Account->nameToID('Bank')] = 'Bank';
|
||||||
|
$default_accounts = array_diff_key($payment_accounts,
|
||||||
|
array($this->Account->concessionAccountID() => 1));
|
||||||
|
$this->set(compact('payment_accounts', 'default_accounts'));
|
||||||
|
|
||||||
|
$this->Account->recursive = -1;
|
||||||
|
$account = $this->Account->read(null, $id);
|
||||||
|
$account = $account['Account'];
|
||||||
|
|
||||||
|
$title = ($account['name'] . ': Collected Report');
|
||||||
|
$this->set(compact('account', 'title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: deposit
|
||||||
|
* - Prepares the books for a bank deposit
|
||||||
|
*/
|
||||||
|
function deposit() {
|
||||||
|
if ($this->data) {
|
||||||
|
// Action the close based on provided data
|
||||||
|
//pr($this->data);
|
||||||
|
|
||||||
|
// Get data about each closed ledger.
|
||||||
|
$deposit = array('total' => 0, 'ledgers' => array());
|
||||||
|
foreach ($this->data['Tillable']['Ledger'] AS $ledger_id => $ledger) {
|
||||||
|
if (!$ledger['checked'])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$ledger_entries =
|
||||||
|
$this->Account->Ledger->find
|
||||||
|
('all',
|
||||||
|
array('link' => array
|
||||||
|
('Account' =>
|
||||||
|
array('fields' => array('name')),
|
||||||
|
|
||||||
|
'LedgerEntry' =>
|
||||||
|
array('fields' => array('id', 'amount'),
|
||||||
|
|
||||||
|
'MonetarySource' =>
|
||||||
|
array('fields' => array('name')),
|
||||||
|
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('name')),
|
||||||
|
|
||||||
|
//'Transaction' =>
|
||||||
|
//array('fields' => array('stamp')),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'fields' => false,
|
||||||
|
'conditions' => array(array('Ledger.id' => $ledger_id),
|
||||||
|
array('LedgerEntry.id IS NOT NULL'),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$deposit['total'] += $ledger['amount'];
|
||||||
|
$deposit['ledgers'][] = array('id' => $ledger_id,
|
||||||
|
'name' => $ledger['account_name'],
|
||||||
|
'total' => $ledger['amount'],
|
||||||
|
'entries' => $ledger_entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the accounting work necessary to close the
|
||||||
|
// monetary ledgers and deposit into the bank account.
|
||||||
|
$this->Account->closeAndDeposit($deposit['ledgers'], $this->data['Deposit']['Account']['id']);
|
||||||
|
|
||||||
|
$title = 'Account: Deposit Slip';
|
||||||
|
$this->set(compact('title', 'deposit'));
|
||||||
|
$this->render('deposit_slip');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare a close page...
|
||||||
|
$tillable_account = $this->Account->relatedAccounts('tillable');
|
||||||
|
$depositable_account = $this->Account->relatedAccounts('depositable');
|
||||||
|
|
||||||
|
foreach ($tillable_account AS &$acct) {
|
||||||
|
$acct['Account']['stats'] = $this->Account->stats($acct['Account']['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = 'Account: Prepare Deposit';
|
||||||
|
$this->set(compact('title', 'tillable_account', 'depositable_account'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -141,7 +262,8 @@ class AccountsController extends AppController {
|
|||||||
array('fields' => array('id', 'sequence')),
|
array('fields' => array('id', 'sequence')),
|
||||||
|
|
||||||
'Ledger' =>
|
'Ledger' =>
|
||||||
array('order' => array('Ledger.open_stamp' => 'DESC')),
|
array('Close' => array
|
||||||
|
('order' => array('Close.stamp' => 'DESC'))),
|
||||||
),
|
),
|
||||||
'conditions' => array(array('Account.id' => $id)),
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
)
|
)
|
||||||
@@ -160,8 +282,16 @@ class AccountsController extends AppController {
|
|||||||
$stats = $this->Account->stats($id, true);
|
$stats = $this->Account->stats($id, true);
|
||||||
$stats = $stats['Ledger'];
|
$stats = $stats['Ledger'];
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'New Ledger', 'url' => array('action' => 'newledger', $id));
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Collected', 'url' => array('action' => 'collected', $id));
|
||||||
|
|
||||||
// Prepare to render
|
// Prepare to render
|
||||||
$title = 'Account: ' . $account['Account']['name'];
|
$title = 'Account: ' . $account['Account']['name'];
|
||||||
$this->set(compact('account', 'title', 'stats'));
|
$this->set(compact('account', 'title', 'stats'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ContactsController extends AppController {
|
||||||
|
|
||||||
|
var $sidemenu_links = array();
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* 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 contacts
|
||||||
|
*/
|
||||||
|
|
||||||
|
function index() { $this->all(); }
|
||||||
|
function all() { $this->jqGridView('All Contacts', 'all'); }
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* virtuals: jqGridData
|
||||||
|
* - With the application controller handling the jqGridData action,
|
||||||
|
* these virtual functions ensure that the correct data is passed
|
||||||
|
* to jqGrid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||||
|
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||||
|
if ($index === 'Contact.last_name') {
|
||||||
|
$order[] = 'Contact.first_name ' . $direction;
|
||||||
|
}
|
||||||
|
if ($index === 'Contact.first_name') {
|
||||||
|
$order[] = 'Contact.last_name ' . $direction;
|
||||||
|
}
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Contact'] = array('id');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: view
|
||||||
|
* - Displays information about a specific contact
|
||||||
|
*/
|
||||||
|
|
||||||
|
function view($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact = $this->Contact->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'ContactPhone',
|
||||||
|
'ContactEmail',
|
||||||
|
'ContactAddress',
|
||||||
|
'Customer'),
|
||||||
|
|
||||||
|
'conditions' => array('Contact.id' => $id),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Edit',
|
||||||
|
'url' => array('action' => 'edit',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
$title = 'Contact: ' . $contact['Contact']['display_name'];
|
||||||
|
$this->set(compact('contact', 'title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: edit
|
||||||
|
*/
|
||||||
|
|
||||||
|
function edit($id = null, $customer_id = null) {
|
||||||
|
if (isset($this->data)) {
|
||||||
|
|
||||||
|
if (isset($this->params['form']['cancel'])) {
|
||||||
|
if (isset($this->data['Contact']['id']))
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
||||||
|
/* else */
|
||||||
|
/* $this->redirect(array('controller' => 'customers', */
|
||||||
|
/* 'action'=>'add', $this->data['Customer']['id'])); */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Go through each contact method and strip the bogus ID if new
|
||||||
|
foreach (array_intersect_key($this->data,
|
||||||
|
array('ContactPhone'=>1,
|
||||||
|
'ContactAddress'=>1,
|
||||||
|
'ContactEmail'=>1)) AS $type => $arr) {
|
||||||
|
foreach ($arr AS $idx => $item) {
|
||||||
|
if (isset($item['source']) && $item['source'] === 'new')
|
||||||
|
unset($this->data[$type][$idx]['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the contact and all associated data
|
||||||
|
$this->Contact->saveContact($this->data['Contact']['id'], $this->data);
|
||||||
|
|
||||||
|
// Now that the work is done, let the user view the updated contact
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Contact']['id']));
|
||||||
|
//$this->render('/empty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$this->data = $this->Contact->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'ContactPhone',
|
||||||
|
'ContactEmail',
|
||||||
|
'ContactAddress',
|
||||||
|
'Customer'),
|
||||||
|
|
||||||
|
'conditions' => array('Contact.id' => $id),
|
||||||
|
));
|
||||||
|
|
||||||
|
$title = 'Contact: ' . $this->data['Contact']['display_name'] . " : Edit";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$title = "Enter New Contact";
|
||||||
|
$this->data = array('ContactPhone' => array(),
|
||||||
|
'ContactAddress' => array(),
|
||||||
|
'ContactEmail' => array());
|
||||||
|
}
|
||||||
|
|
||||||
|
$phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type'));
|
||||||
|
unset($phone_types[0]);
|
||||||
|
// REVISIT <AP> 20090705
|
||||||
|
// Use this to have a mixed case enum
|
||||||
|
// array_map('ucfirst', array_map('strtolower', $phone_types))
|
||||||
|
$phone_types = array_combine($phone_types, $phone_types);
|
||||||
|
$this->set(compact('phone_types'));
|
||||||
|
|
||||||
|
$method_types = array_flip($this->Contact->getEnumValues
|
||||||
|
('type',
|
||||||
|
$this->Contact->tablePrefix . 'contacts_methods'));
|
||||||
|
unset($method_types[0]);
|
||||||
|
$method_types = array_combine($method_types, $method_types);
|
||||||
|
$this->set(compact('method_types'));
|
||||||
|
|
||||||
|
$method_preferences = array_flip($this->Contact->getEnumValues
|
||||||
|
('preference',
|
||||||
|
$this->Contact->tablePrefix . 'contacts_methods'));
|
||||||
|
unset($method_preferences[0]);
|
||||||
|
$method_preferences = array_combine($method_preferences, $method_preferences);
|
||||||
|
$this->set(compact('method_preferences'));
|
||||||
|
|
||||||
|
$contact_phones = $this->Contact->ContactPhone->phoneList();
|
||||||
|
$this->set(compact('contact_phones'));
|
||||||
|
|
||||||
|
$contact_addresses = $this->Contact->ContactAddress->addressList();
|
||||||
|
$this->set(compact('contact_addresses'));
|
||||||
|
|
||||||
|
$contact_emails = $this->Contact->ContactEmail->emailList();
|
||||||
|
$this->set(compact('contact_emails'));
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
//pr($this->data);
|
||||||
|
$this->set(compact('title'));
|
||||||
|
$this->render('edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: add
|
||||||
|
* - Adds a new contact
|
||||||
|
*/
|
||||||
|
|
||||||
|
function add($customer_id = null) {
|
||||||
|
$this->edit(null, $customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,485 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CustomersController extends AppController {
|
||||||
|
var $sidemenu_links =
|
||||||
|
array(array('name' => 'Customers', 'header' => true),
|
||||||
|
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
||||||
|
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
||||||
|
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
||||||
|
array('name' => 'Add Customer', 'url' => array('controller' => 'customers', 'action' => 'add')),
|
||||||
|
);
|
||||||
|
|
||||||
|
//var $components = array('RequestHandler');
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* override: sideMenuLinks
|
||||||
|
* - Generates controller specific links for the side menu
|
||||||
|
*/
|
||||||
|
function sideMenuLinks() {
|
||||||
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: index / current / past / all
|
||||||
|
* - Creates a list of customers
|
||||||
|
*/
|
||||||
|
|
||||||
|
function index() { $this->current(); }
|
||||||
|
function current() { $this->jqGridView('Current Tenants', 'current'); }
|
||||||
|
function past() { $this->jqGridView('Past Tenants'); }
|
||||||
|
function all() { $this->jqGridView('All Customers'); }
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* virtuals: jqGridData
|
||||||
|
* - With the application controller handling the jqGridData action,
|
||||||
|
* these virtual functions ensure that the correct data is passed
|
||||||
|
* to jqGrid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function jqGridDataSetup(&$params) {
|
||||||
|
parent::jqGridDataSetup($params);
|
||||||
|
if (!isset($params['action']))
|
||||||
|
$params['action'] = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataCountTables(&$params, &$model) {
|
||||||
|
return array
|
||||||
|
('link' =>
|
||||||
|
array(// Models
|
||||||
|
'PrimaryContact',
|
||||||
|
'CurrentLease' => array('fields' => array()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataTables(&$params, &$model) {
|
||||||
|
$link = $this->jqGridDataCountTables($params, $model);
|
||||||
|
$link['link']['LedgerEntry'] = array('fields' => array());
|
||||||
|
$link['link']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||||
|
$link['link']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
|
||||||
|
// INNER JOIN would be great, as it would ensure we're only looking
|
||||||
|
// at the ledger entries that we truly want. However, this also
|
||||||
|
// removes from the query any units that do not yet have a ledger
|
||||||
|
// entry in A/R. A solution would be to INNER JOIN these tables,
|
||||||
|
// and LEFT JOIN it to the rest. Grouping of JOINs, however, is
|
||||||
|
// implemented with the 'joins' tag, and is not available through
|
||||||
|
// the Linkable behavior interface.
|
||||||
|
//$link['link']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||||
|
$link['link']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||||
|
= array('Account.id' =>
|
||||||
|
$this->Customer->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataFields(&$params, &$model) {
|
||||||
|
$db = &$model->getDataSource();
|
||||||
|
$fields = $db->fields($model, $model->alias);
|
||||||
|
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
|
||||||
|
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||||
|
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||||
|
" 1, -1))" .
|
||||||
|
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||||
|
" AS 'balance'");
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
|
$conditions = parent::jqGridDataConditions($params, $model);
|
||||||
|
|
||||||
|
if ($params['action'] === 'current') {
|
||||||
|
$conditions[] = 'CurrentLease.id IS NOT NULL';
|
||||||
|
}
|
||||||
|
elseif ($params['action'] === 'past') {
|
||||||
|
$conditions[] = 'CurrentLease.id IS NULL';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||||
|
$order = array();
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||||
|
|
||||||
|
if ($index !== 'PrimaryContact.last_name')
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model,
|
||||||
|
'PrimaryContact.last_name', $direction);
|
||||||
|
if ($index !== 'PrimaryContact.first_name')
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model,
|
||||||
|
'PrimaryContact.first_name', $direction);
|
||||||
|
if ($index !== 'Customer.id')
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model,
|
||||||
|
'Customer.id', $direction);
|
||||||
|
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataRecordCount(&$params, &$model, $query) {
|
||||||
|
|
||||||
|
// We don't have a good way to use the query to obtain
|
||||||
|
// our count. The problem is that we're relying on the
|
||||||
|
// group by for the query, which will destroy the count,
|
||||||
|
// whether we omit the group by or leave it in.
|
||||||
|
// So, build a fresh query for counting.
|
||||||
|
|
||||||
|
$query['conditions'] = parent::jqGridDataConditions($params, $model);
|
||||||
|
|
||||||
|
$count = $model->find('count',
|
||||||
|
array_merge(array('link' => array_diff_key($query['link'],
|
||||||
|
array('CurrentLease'=>1))),
|
||||||
|
array_diff_key($query, array('link'=>1))));
|
||||||
|
|
||||||
|
if ($params['action'] === 'all')
|
||||||
|
return $count;
|
||||||
|
|
||||||
|
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
||||||
|
$count_past = $model->find('count', $query);
|
||||||
|
|
||||||
|
// Since we can't easily count 'current' directly, we
|
||||||
|
// can quickly derive it since 'current' customers
|
||||||
|
// are mutually exclusive to 'past' customers.
|
||||||
|
if ($params['action'] == 'current')
|
||||||
|
$count = $count - $count_past;
|
||||||
|
elseif ($params['action'] == 'past') {
|
||||||
|
$count = $count_past;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataRecords(&$params, &$model, $query) {
|
||||||
|
$customers = parent::jqGridDataRecords($params, $model, $query);
|
||||||
|
|
||||||
|
// Get the balance on each customer.
|
||||||
|
foreach ($customers AS &$customer) {
|
||||||
|
$stats = $this->Customer->stats($customer['Customer']['id']);
|
||||||
|
$customer['Customer']['balance'] = $stats['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $customers;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Customer'] = array('name');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_in
|
||||||
|
* - Sets up the move-in page for the given customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_in($id = null) {
|
||||||
|
$customer = array();
|
||||||
|
$unit = array();
|
||||||
|
|
||||||
|
if (isset($id)) {
|
||||||
|
$this->Customer->recursive = -1;
|
||||||
|
$customer = current($this->Customer->read(null, $id));
|
||||||
|
}
|
||||||
|
$this->set(compact('customer', 'unit'));
|
||||||
|
|
||||||
|
$title = 'Customer Move-In';
|
||||||
|
$this->set(compact('title'));
|
||||||
|
$this->render('/leases/move');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_out
|
||||||
|
* - prepare to move a customer out of one of their units
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_out($id) {
|
||||||
|
|
||||||
|
$customer = $this->Customer->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'Lease' =>
|
||||||
|
array('conditions' => array('Lease.moveout_date' => null),
|
||||||
|
// Models
|
||||||
|
'Unit' =>
|
||||||
|
array('order' => array('sort_order'),
|
||||||
|
'fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array('Customer.id' => $id),
|
||||||
|
));
|
||||||
|
$this->set('customer', $lease['Customer']);
|
||||||
|
$this->set('unit', array());
|
||||||
|
|
||||||
|
$redirect = array('controller' => 'customers',
|
||||||
|
'action' => 'view',
|
||||||
|
$id);
|
||||||
|
|
||||||
|
$title = $customer['Customer']['name'] . ': Prepare Move-Out';
|
||||||
|
$this->set(compact('title', 'customer', 'redirect'));
|
||||||
|
$this->render('/leases/move');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: view
|
||||||
|
* - Displays information about a specific customer
|
||||||
|
*/
|
||||||
|
|
||||||
|
function view($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer = $this->Customer->details($id);
|
||||||
|
|
||||||
|
$outstanding_balance = $customer['stats']['balance'];
|
||||||
|
$outstanding_deposit = $customer['deposits']['summary']['balance'];
|
||||||
|
|
||||||
|
// Figure out if this customer has any non-closed leases
|
||||||
|
$show_moveout = false;
|
||||||
|
$show_payment = false;
|
||||||
|
foreach ($customer['Lease'] AS $lease) {
|
||||||
|
if (!isset($lease['close_date']))
|
||||||
|
$show_payment = true;
|
||||||
|
if (!isset($lease['moveout_date']))
|
||||||
|
$show_moveout = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Edit',
|
||||||
|
'url' => array('action' => 'edit',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Move-In',
|
||||||
|
'url' => array('action' => 'move_in',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
/* if ($show_moveout) { */
|
||||||
|
/* $this->sidemenu_links[] = */
|
||||||
|
/* array('name' => 'Move-Out', */
|
||||||
|
/* 'url' => array('action' => 'move_out', */
|
||||||
|
/* $id)); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
if ($show_payment) {
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Payment',
|
||||||
|
'url' => array('action' => 'receipt',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
$title = 'Customer: ' . $customer['Customer']['name'];
|
||||||
|
$this->set(compact('customer', 'title',
|
||||||
|
'outstanding_balance',
|
||||||
|
'outstanding_deposit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: edit
|
||||||
|
* - Edit customer information
|
||||||
|
*/
|
||||||
|
|
||||||
|
function edit($id = null) {
|
||||||
|
if (isset($this->data)) {
|
||||||
|
// Check to see if the operation was cancelled.
|
||||||
|
if (isset($this->params['form']['cancel'])) {
|
||||||
|
if (isset($this->data['Customer']['id']))
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Customer']['id']));
|
||||||
|
else
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we have at least one contact
|
||||||
|
if (!isset($this->data['Contact']) || count($this->data['Contact']) == 0) {
|
||||||
|
$this->Session->setFlash("MUST SPECIFY AT LEAST ONE CONTACT", true);
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Customer']['id']));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there is a primary contact
|
||||||
|
if (!isset($this->data['Customer']['primary_contact_entry'])) {
|
||||||
|
$this->Session->setFlash("MUST SPECIFY A PRIMARY CONTACT", true);
|
||||||
|
$this->redirect(array('action'=>'view', $this->data['Customer']['id']));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Go through each customer and strip the bogus ID if new
|
||||||
|
foreach ($this->data['Contact'] AS &$contact) {
|
||||||
|
if (isset($contact['source']) && $contact['source'] === 'new')
|
||||||
|
unset($contact['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the customer and all associated data
|
||||||
|
if (!$this->Customer->saveCustomer($this->data['Customer']['id'],
|
||||||
|
$this->data,
|
||||||
|
$this->data['Customer']['primary_contact_entry'])) {
|
||||||
|
$this->Session->setFlash("CUSTOMER SAVE FAILED", true);
|
||||||
|
pr("CUSTOMER SAVE FAILED");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If existing customer, then view it. Otherwise, since
|
||||||
|
// this is a new customer, go to the move in screen.
|
||||||
|
if ($this->data['Customer']['id'])
|
||||||
|
$this->redirect(array('action'=>'view', $this->Customer->id));
|
||||||
|
else
|
||||||
|
$this->redirect(array('action'=>'move_in', $this->Customer->id));
|
||||||
|
|
||||||
|
// For debugging, only if the redirects above have been
|
||||||
|
// commented out, otherwise this section isn't reached.
|
||||||
|
$this->render('/empty');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$this->data = $this->Customer->details($id);
|
||||||
|
$title = 'Customer: ' . $this->data['Customer']['name'] . " : Edit";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$title = "Enter New Customer";
|
||||||
|
$this->data = array('Contact' => array(), 'PrimaryContact' => null);
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact_types = array_flip($this->Customer->ContactsCustomer->getEnumValues('type'));
|
||||||
|
unset($contact_types[0]);
|
||||||
|
$contact_types = array_combine($contact_types, $contact_types);
|
||||||
|
$this->set(compact('contact_types'));
|
||||||
|
|
||||||
|
$contacts = $this->Customer->Contact->contactList();
|
||||||
|
$this->set(compact('contacts'));
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
//pr($this->data);
|
||||||
|
$this->set(compact('title'));
|
||||||
|
$this->render('edit');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: add
|
||||||
|
* - Add a new customer
|
||||||
|
*/
|
||||||
|
|
||||||
|
function add() {
|
||||||
|
$this->edit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: receipt
|
||||||
|
* - Sets up the receipt entry page for the given customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function receipt($id = null) {
|
||||||
|
if (isset($id)) {
|
||||||
|
$this->Customer->recursive = -1;
|
||||||
|
$customer = $this->Customer->read(null, $id);
|
||||||
|
$customer = $customer['Customer'];
|
||||||
|
$unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
|
||||||
|
$charges = $unreconciled['debit'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$customer = null;
|
||||||
|
$charges = array('balance' => 0, 'entry' => array());
|
||||||
|
}
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
$payment_accounts = $A->paymentAccounts();
|
||||||
|
$default_account = $A->cashAccountID();
|
||||||
|
$this->set(compact('payment_accounts', 'default_account'));
|
||||||
|
|
||||||
|
$title = ($customer['name'] . ': Payment Entry');
|
||||||
|
$this->set(compact('customer', 'charges', 'title'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: refund
|
||||||
|
* - Refunds customer charges
|
||||||
|
*/
|
||||||
|
|
||||||
|
function refund() {
|
||||||
|
$entries = $this->Customer->LedgerEntry->find
|
||||||
|
('all', array
|
||||||
|
('contain' => false,
|
||||||
|
'conditions' => array('LedgerEntry.id' =>
|
||||||
|
//array(199,200,201)
|
||||||
|
61
|
||||||
|
),
|
||||||
|
));
|
||||||
|
pr(compact('entries'));
|
||||||
|
|
||||||
|
$this->Customer->LedgerEntry->reverse($entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: unreconciledEntries
|
||||||
|
* - returns the list of unreconciled entries
|
||||||
|
*/
|
||||||
|
|
||||||
|
function unreconciled($id) {
|
||||||
|
|
||||||
|
//$this->layout = 'ajax';
|
||||||
|
$this->layout = null;
|
||||||
|
$this->autoLayout = false;
|
||||||
|
$this->autoRender = false;
|
||||||
|
Configure::write('debug', '0');
|
||||||
|
header("Content-type: text/xml;charset=utf-8");
|
||||||
|
|
||||||
|
App::import('Helper', 'Xml');
|
||||||
|
$xml = new XmlHelper();
|
||||||
|
|
||||||
|
// Find the unreconciled entries, then manipulate the structure
|
||||||
|
// slightly to accomodate the format necessary for XML Helper.
|
||||||
|
$unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
|
||||||
|
$unreconciled = array('entries' =>
|
||||||
|
array_intersect_key($unreconciled['debit'],
|
||||||
|
array('entry'=>1, 'balance'=>1)));
|
||||||
|
|
||||||
|
// XML Helper will dump an empty tag if the array is empty
|
||||||
|
if (!count($unreconciled['entries']['entry']))
|
||||||
|
unset($unreconciled['entries']['entry']);
|
||||||
|
|
||||||
|
pr($unreconciled);
|
||||||
|
//$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount);
|
||||||
|
|
||||||
|
$opts = array();
|
||||||
|
//$opts['format'] = 'tags';
|
||||||
|
echo $xml->header();
|
||||||
|
echo $xml->serialize($unreconciled, $opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,507 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class LeasesController extends AppController {
|
||||||
|
|
||||||
|
var $sidemenu_links =
|
||||||
|
array(array('name' => 'Leases', 'header' => true),
|
||||||
|
array('name' => 'Active', 'url' => array('controller' => 'leases', 'action' => 'active')),
|
||||||
|
array('name' => 'Closed', 'url' => array('controller' => 'leases', 'action' => 'closed')),
|
||||||
|
array('name' => 'All', 'url' => array('controller' => 'leases', 'action' => 'all')),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* override: sideMenuLinks
|
||||||
|
* - Generates controller specific links for the side menu
|
||||||
|
*/
|
||||||
|
function sideMenuLinks() {
|
||||||
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: index / active / closed / all
|
||||||
|
* - Generate a listing of leases
|
||||||
|
*/
|
||||||
|
|
||||||
|
function index() { $this->all(); }
|
||||||
|
function active() { $this->jqGridView('Active Leases'); }
|
||||||
|
function closed() { $this->jqGridView('Closed Leases'); }
|
||||||
|
function all() { $this->jqGridView('All Leases', 'all'); }
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* virtuals: jqGridData
|
||||||
|
* - With the application controller handling the jqGridData action,
|
||||||
|
* these virtual functions ensure that the correct data is passed
|
||||||
|
* to jqGrid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function jqGridDataSetup(&$params) {
|
||||||
|
parent::jqGridDataSetup($params);
|
||||||
|
if (!isset($params['action']))
|
||||||
|
$params['action'] = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataCountTables(&$params, &$model) {
|
||||||
|
return array
|
||||||
|
('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')),
|
||||||
|
'Customer' => array('fields' => array('Customer.id', 'Customer.name'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataTables(&$params, &$model) {
|
||||||
|
$link = $this->jqGridDataCountTables($params, $model);
|
||||||
|
$link['link']['LedgerEntry'] = array('fields' => array());
|
||||||
|
$link['link']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||||
|
$link['link']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
|
||||||
|
// INNER JOIN would be great, as it would ensure we're only looking
|
||||||
|
// at the ledger entries that we truly want. However, this also
|
||||||
|
// removes from the query any leases that do not yet have a ledger
|
||||||
|
// entry in A/R. A solution would be to INNER JOIN these tables,
|
||||||
|
// and LEFT JOIN it to the rest. Grouping of JOINs, however, is
|
||||||
|
// implemented with the 'joins' tag, and is not available through
|
||||||
|
// the Linkable behavior interface.
|
||||||
|
//$link['link']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||||
|
$link['link']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||||
|
= array('Account.id' =>
|
||||||
|
$this->Lease->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataFields(&$params, &$model) {
|
||||||
|
$db = &$model->getDataSource();
|
||||||
|
$fields = $db->fields($model, $model->alias);
|
||||||
|
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||||
|
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||||
|
" 1, -1))" .
|
||||||
|
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||||
|
" AS 'balance'");
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
|
$conditions = parent::jqGridDataConditions($params, $model);
|
||||||
|
|
||||||
|
if ($params['action'] === 'active') {
|
||||||
|
$conditions[] = 'Lease.close_date IS NULL';
|
||||||
|
}
|
||||||
|
elseif ($params['action'] === 'closed') {
|
||||||
|
$conditions[] = 'Lease.close_date IS NOT NULL';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||||
|
// Do not sort by number, which is type varchar and
|
||||||
|
// sorts on an ascii basis. Sort by ID instead.
|
||||||
|
if ($index === 'Lease.number')
|
||||||
|
$index = 'Lease.id';
|
||||||
|
|
||||||
|
// Instead of sorting by name, sort by defined order
|
||||||
|
if ($index === 'Unit.name')
|
||||||
|
$index = 'Unit.sort_order';
|
||||||
|
|
||||||
|
$order = array();
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||||
|
|
||||||
|
// If sorting by anything other than id/number
|
||||||
|
// add sorting by id as a secondary condition.
|
||||||
|
if ($index !== 'Lease.id' && $index !== 'Lease.number')
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model,
|
||||||
|
'Lease.id', $direction);
|
||||||
|
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* function jqGridRecordsPostProcess(&$params, &$model, &$records) { */
|
||||||
|
/* foreach ($records AS &$record) { */
|
||||||
|
/* $record['Lease']['through_date'] */
|
||||||
|
/* = $this->Lease->rentChargeThrough($record['Lease']['id']); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* parent::jqGridRecordsPostProcess($params, $model, $records); */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Lease'] = array('number');
|
||||||
|
$links['Unit'] = array('name');
|
||||||
|
$links['Customer'] = array('name');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_in
|
||||||
|
* - execute a move in on a new lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_in() {
|
||||||
|
if (!$this->data)
|
||||||
|
die("Should have some data");
|
||||||
|
|
||||||
|
// Handle the move in based on the data given
|
||||||
|
//pr(array('Move-in data', $this->data));
|
||||||
|
|
||||||
|
$lid = $this->Lease->moveIn($this->data['Lease']['customer_id'],
|
||||||
|
$this->data['Lease']['unit_id'],
|
||||||
|
null, null,
|
||||||
|
$this->data['Lease']['movein_date'],
|
||||||
|
$this->data['Lease']['comment']
|
||||||
|
);
|
||||||
|
|
||||||
|
// Since this is a new lease, go to the invoice
|
||||||
|
// screen so we can start assessing charges.
|
||||||
|
$this->redirect(array('action'=>'invoice', $lid));
|
||||||
|
|
||||||
|
// For debugging, only if the redirect above have been
|
||||||
|
// commented out, otherwise this section isn't reached.
|
||||||
|
$this->render('/empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_out
|
||||||
|
* - prepare or execute a move out on a specific lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_out($id = null) {
|
||||||
|
if ($this->data) {
|
||||||
|
// Handle the move out based on the data given
|
||||||
|
//pr($this->data);
|
||||||
|
|
||||||
|
$this->Lease->moveOut($this->data['Lease']['id'],
|
||||||
|
'VACANT',
|
||||||
|
$this->data['Lease']['moveout_date'],
|
||||||
|
//true // Close this lease, if able
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->redirect($this->data['redirect']);
|
||||||
|
$this->autoRender = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($id))
|
||||||
|
die("Oh Nooooo!!");
|
||||||
|
|
||||||
|
$lease = $this->Lease->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'Unit' =>
|
||||||
|
array('order' => array('sort_order'),
|
||||||
|
'fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Lease.close_date' => null),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
$this->set('customer', $lease['Customer']);
|
||||||
|
$this->set('unit', $lease['Unit']);
|
||||||
|
$this->set('lease', $lease['Lease']);
|
||||||
|
|
||||||
|
$redirect = array('controller' => 'leases',
|
||||||
|
'action' => 'view',
|
||||||
|
$id);
|
||||||
|
|
||||||
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||||
|
$lease['Unit']['name'] . ': ' .
|
||||||
|
$lease['Customer']['name'] . ': Prepare Move-Out');
|
||||||
|
$this->set(compact('title', 'redirect'));
|
||||||
|
$this->render('/leases/move');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: apply_deposit
|
||||||
|
* - Applies the security deposit to charges. This is much
|
||||||
|
* like a receipt, but it's separated to keep it simple and
|
||||||
|
* to prevent feature overload on the receipt page.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function apply_deposit($id) {
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
$lease = $this->Lease->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'Unit' =>
|
||||||
|
array('order' => array('sort_order'),
|
||||||
|
'fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Lease.close_date' => null),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// Get the lease balance, part of lease stats
|
||||||
|
$this->Lease->statsMerge($lease['Lease'],
|
||||||
|
array('stats' => $this->Lease->stats($id)));
|
||||||
|
|
||||||
|
// Determine the lease security deposit
|
||||||
|
$deposit = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||||
|
$this->set(compact('deposit'));
|
||||||
|
$this->set('customer', $lease['Customer']);
|
||||||
|
$this->set('unit', $lease['Unit']);
|
||||||
|
$this->set('lease', $lease['Lease']);
|
||||||
|
$this->set('account', array('id' => $A->securityDepositAccountID()));
|
||||||
|
|
||||||
|
/* $redirect = array('controller' => 'leases', */
|
||||||
|
/* 'action' => 'view', */
|
||||||
|
/* $id); */
|
||||||
|
|
||||||
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||||
|
$lease['Unit']['name'] . ': ' .
|
||||||
|
$lease['Customer']['name'] . ': Utilize Security Deposit');
|
||||||
|
$this->set(compact('title', 'redirect'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: bad_debt
|
||||||
|
* - Writes off remaining charges on a lease.
|
||||||
|
* REVISIT <AP>: 20090710
|
||||||
|
* Should this be a customer function? What customer
|
||||||
|
* would have only one lease that results in bad debt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function bad_debt($id) {
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
$lease = $this->Lease->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'Unit' =>
|
||||||
|
array('order' => array('sort_order'),
|
||||||
|
'fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Lease.close_date' => null),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
// Get the lease balance, part of lease stats
|
||||||
|
$this->Lease->statsMerge($lease['Lease'],
|
||||||
|
array('stats' => $this->Lease->stats($id)));
|
||||||
|
|
||||||
|
// Determine the lease security deposit
|
||||||
|
$deposit = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||||
|
if ($deposit['summary']['balance'] > 0)
|
||||||
|
die("Still have un-utilized security deposit");
|
||||||
|
|
||||||
|
$this->set('customer', $lease['Customer']);
|
||||||
|
$this->set('unit', $lease['Unit']);
|
||||||
|
$this->set('lease', $lease['Lease']);
|
||||||
|
$this->set('account', array('id' => $A->badDebtAccountID()));
|
||||||
|
|
||||||
|
/* $redirect = array('controller' => 'leases', */
|
||||||
|
/* 'action' => 'view', */
|
||||||
|
/* $id); */
|
||||||
|
|
||||||
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||||
|
$lease['Unit']['name'] . ': ' .
|
||||||
|
$lease['Customer']['name'] . ': Write Off Bad Debt');
|
||||||
|
$this->set(compact('title', 'redirect'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: refund
|
||||||
|
* - Provides user with a refund
|
||||||
|
* REVISIT <AP>: 20090710
|
||||||
|
* Should this be a customer function?
|
||||||
|
*/
|
||||||
|
|
||||||
|
function refund($id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: close
|
||||||
|
* - Closes a lease to any further action
|
||||||
|
*/
|
||||||
|
|
||||||
|
function close($id) {
|
||||||
|
// REVISIT <AP>: 20090708
|
||||||
|
// We should probably seek confirmation first...
|
||||||
|
$this->Lease->close($id);
|
||||||
|
$this->redirect(array('action'=>'view', $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: invoice
|
||||||
|
* - Sets up the invoice entry page for the given customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function invoice($id = null, $type = null) {
|
||||||
|
|
||||||
|
$lease = $this->Lease->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'Unit' =>
|
||||||
|
array('order' => array('sort_order'),
|
||||||
|
'fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Lease.close_date' => null),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
$charge_accounts = $A->chargeAccounts();
|
||||||
|
$default_account = $A->rentAccountID();
|
||||||
|
$this->set(compact('charge_accounts', 'default_account'));
|
||||||
|
|
||||||
|
// REVISIT <AP> 20090705:
|
||||||
|
// Of course, the late charge should come from the late_schedule
|
||||||
|
$default_rent = $lease['Lease']['rent'];
|
||||||
|
$default_late = 10;
|
||||||
|
$this->set(compact('default_rent', 'default_late'));
|
||||||
|
|
||||||
|
$title = ('Lease #' . $lease['Lease']['number'] . ': ' .
|
||||||
|
$lease['Unit']['name'] . ': ' .
|
||||||
|
$lease['Customer']['name'] . ': Charge Entry');
|
||||||
|
$this->set(compact('title', 'lease', 'charge'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: view
|
||||||
|
* - Displays information about a specific lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function view($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get details about the lease and its ledgers (no ledger entries yet)
|
||||||
|
$lease = $this->Lease->find
|
||||||
|
('first',
|
||||||
|
array('contain' =>
|
||||||
|
array(// Models
|
||||||
|
'LeaseType',
|
||||||
|
'Unit',
|
||||||
|
'Customer',
|
||||||
|
),
|
||||||
|
'conditions' => array(array('Lease.id' => $id)),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$lease['Lease']['paid_through'] = $this->Lease->rentPaidThrough($id);
|
||||||
|
|
||||||
|
|
||||||
|
$this->set('charge_gaps', $this->Lease->rentChargeGaps($id));
|
||||||
|
$this->set('charge_through', $this->Lease->rentChargeThrough($id));
|
||||||
|
|
||||||
|
// Obtain the overall lease balance
|
||||||
|
$this->Lease->statsMerge($lease['Lease'],
|
||||||
|
array('stats' => $this->Lease->stats($id)));
|
||||||
|
$outstanding_balance = $lease['Lease']['stats']['balance'];
|
||||||
|
|
||||||
|
// Determine the lease security deposit
|
||||||
|
$deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
||||||
|
$outstanding_deposit = $deposits['summary']['balance'];
|
||||||
|
|
||||||
|
// Set up dynamic menu items
|
||||||
|
if (!isset($lease['Lease']['close_date'])) {
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
if (!isset($lease['Lease']['moveout_date']))
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Charges', 'url' => array('action' => 'invoice',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Payments', 'url' => array('controller' => 'customers',
|
||||||
|
'action' => 'receipt',
|
||||||
|
$lease['Customer']['id']));
|
||||||
|
|
||||||
|
if (isset($lease['Lease']['moveout_date']) && $outstanding_deposit > 0 && $outstanding_balance > 0)
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Apply Deposit', 'url' => array('action' => 'apply_deposit',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
if (isset($lease['Lease']['moveout_date']) &&
|
||||||
|
$outstanding_balance <= 0 &&
|
||||||
|
($outstanding_deposit - $outstanding_balance) > 0)
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Issue Refund', 'url' => array('action' => 'refund',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
if (isset($lease['Lease']['moveout_date']) && $outstanding_deposit == 0 && $outstanding_balance > 0)
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Write-Off', 'url' => array('action' => 'bad_debt',
|
||||||
|
$id));
|
||||||
|
|
||||||
|
if ($this->Lease->closeable($id))
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Close', 'url' => array('action' => 'close',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare to render
|
||||||
|
$title = 'Lease: #' . $lease['Lease']['id'];
|
||||||
|
$this->set(compact('lease', 'title',
|
||||||
|
'outstanding_deposit',
|
||||||
|
'outstanding_balance'));
|
||||||
|
}
|
||||||
|
}
|
||||||
+194
-94
@@ -33,7 +33,7 @@ class LedgerEntriesController extends AppController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataCountTables(&$params, &$model) {
|
function jqGridDataTables(&$params, &$model) {
|
||||||
$link =
|
$link =
|
||||||
array(// Models
|
array(// Models
|
||||||
'Transaction' =>
|
'Transaction' =>
|
||||||
@@ -79,6 +79,51 @@ class LedgerEntriesController extends AppController {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
elseif ($params['action'] === 'collected') {
|
||||||
|
// Income / Receipt / Money
|
||||||
|
// debit: A/R credit: Income <-- this entry
|
||||||
|
// debit: Receipt credit: A/R <-- ReceiptLedgerEntry, below
|
||||||
|
// debit: Money credit: Receipt <-- MoneyLedgerEntry, below
|
||||||
|
|
||||||
|
$link['CreditLedger'] =
|
||||||
|
array('fields' => 'sequence',
|
||||||
|
'Account' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// We're searching for the Receipt<->A/R entries,
|
||||||
|
// which are debits on the A/R account. Find the
|
||||||
|
// reconciling entries to that A/R debit.
|
||||||
|
$link['DebitReconciliationLedgerEntry'] =
|
||||||
|
array('alias' => 'ReceiptLedgerEntry',
|
||||||
|
|
||||||
|
'Transaction' =>
|
||||||
|
array('alias' => 'ReceiptTransaction'),
|
||||||
|
|
||||||
|
// Credit Ledger should be A/R;
|
||||||
|
// Debit Ledger should be Receipt
|
||||||
|
'DebitLedger' =>
|
||||||
|
array('alias' => 'ReceiptLedger',
|
||||||
|
'Account' => array('alias' => 'ReceiptAccount'),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Finally, the Money (Cash/Check/etc) Entry is the one
|
||||||
|
// which reconciles our ReceiptLedgerEntry debit
|
||||||
|
'DebitReconciliationLedgerEntry' =>
|
||||||
|
array('alias' => 'MoneyLedgerEntry',
|
||||||
|
'linkalias' => 'MoneyLedgerEntryR',
|
||||||
|
|
||||||
|
// Credit Ledger should be Receipt;
|
||||||
|
// Debit Ledger should be our Money Account
|
||||||
|
'DebitLedger' =>
|
||||||
|
array('alias' => 'MoneyLedger',
|
||||||
|
'Account' =>
|
||||||
|
array('alias' => 'MoneyAccount'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$link['DebitLedger'] =
|
$link['DebitLedger'] =
|
||||||
array('fields' => array('id', 'sequence'),
|
array('fields' => array('id', 'sequence'),
|
||||||
@@ -95,13 +140,8 @@ class LedgerEntriesController extends AppController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['account_id']) || isset($params['custom']['lease_id'])) {
|
if (isset($params['custom']['account_id'])) {
|
||||||
if (isset($params['custom']['account_id']))
|
$account_id = $params['custom']['account_id'];
|
||||||
$account_id = $params['custom']['account_id'];
|
|
||||||
else
|
|
||||||
$account_id =
|
|
||||||
$this->LedgerEntry->DebitLedger->Account->accountReceivableAccountID();
|
|
||||||
|
|
||||||
$link['Ledger'] =
|
$link['Ledger'] =
|
||||||
array('fields' => array('id', 'sequence'),
|
array('fields' => array('id', 'sequence'),
|
||||||
'conditions' => ("Ledger.id = IF(DebitLedger.account_id = $account_id," .
|
'conditions' => ("Ledger.id = IF(DebitLedger.account_id = $account_id," .
|
||||||
@@ -113,57 +153,18 @@ class LedgerEntriesController extends AppController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['lease_id'])) {
|
|
||||||
$account_id = $params['custom']['lease_id'];
|
|
||||||
$link['Transaction']['ReconciledLedgerEntry'] =
|
|
||||||
array('fields' => array('id', 'Reconciliation.amount', 'Reconciliation.type'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($params['custom']['reconcile_id'])) {
|
if (isset($params['custom']['reconcile_id'])) {
|
||||||
$ftype = $params['custom']['account_ftype'];
|
$ftype = $params['custom']['account_ftype'];
|
||||||
$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
||||||
$link['ReconcilingTransaction'] =
|
$ftype = ucfirst($ftype);
|
||||||
array('fields' => array('Reconciliation.amount'),
|
$link[$ftype.'ReconciliationLedgerEntry'] =
|
||||||
'conditions' => array('Reconciliation.type' => $ftype),
|
array('fields' => array('Reconciliation.amount'));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array('link' => $link);
|
return array('link' => $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
|
||||||
return $this->jqGridDataCountTables($params, $model);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataFields(&$params, &$model) {
|
function jqGridDataFields(&$params, &$model) {
|
||||||
if (isset($params['custom']['lease_id'])) {
|
|
||||||
$account_id =
|
|
||||||
$this->LedgerEntry->DebitLedger->Account->accountReceivableAccountID();
|
|
||||||
|
|
||||||
$fields = array('id', 'name', 'comment', 'amount');
|
|
||||||
$fields[] = ("IF(DebitLedger.account_id = $account_id," .
|
|
||||||
" SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
|
||||||
" LedgerEntry.amount," .
|
|
||||||
" ReconciledLedgerEntry.amount))," .
|
|
||||||
" NULL) AS debit");
|
|
||||||
$fields[] = ("IF(CreditLedger.account_id = $account_id," .
|
|
||||||
" SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
|
||||||
" LedgerEntry.amount," .
|
|
||||||
" ReconciledLedgerEntry.amount))," .
|
|
||||||
" NULL) AS credit");
|
|
||||||
|
|
||||||
$Account = new Account();
|
|
||||||
$account_ftype = ucfirst($Account->fundamentalType($account_id));
|
|
||||||
$fields[] = ("(IF({$account_ftype}Ledger.account_id = $account_id, 1, -1)" .
|
|
||||||
" * SUM(IF(ReconciledLedgerEntry.amount IS NULL," .
|
|
||||||
" LedgerEntry.amount," .
|
|
||||||
" ReconciledLedgerEntry.amount)))" .
|
|
||||||
" AS balance");
|
|
||||||
|
|
||||||
return $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
$ledger_id = (isset($params['custom']['ledger_id'])
|
$ledger_id = (isset($params['custom']['ledger_id'])
|
||||||
? $params['custom']['ledger_id']
|
? $params['custom']['ledger_id']
|
||||||
: null);
|
: null);
|
||||||
@@ -174,7 +175,15 @@ class LedgerEntriesController extends AppController {
|
|||||||
? $params['custom']['account_type']
|
? $params['custom']['account_type']
|
||||||
: null);
|
: null);
|
||||||
|
|
||||||
return $model->ledgerContextFields2($ledger_id, $account_id, $account_type);
|
$fields = $model->ledgerContextFields2($ledger_id, $account_id, $account_type);
|
||||||
|
|
||||||
|
if (count(array_intersect($params['fields'], array('applied'))) == 1)
|
||||||
|
$fields[] = 'SUM(Reconciliation.amount) AS applied';
|
||||||
|
|
||||||
|
if ($params['action'] === 'collected')
|
||||||
|
$fields[] = 'MAX(ReceiptTransaction.stamp) AS last_paid';
|
||||||
|
|
||||||
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
@@ -187,16 +196,37 @@ class LedgerEntriesController extends AppController {
|
|||||||
|
|
||||||
$conditions = parent::jqGridDataConditions($params, $model);
|
$conditions = parent::jqGridDataConditions($params, $model);
|
||||||
|
|
||||||
if ($params['action'] === 'ledger' && isset($ledger_id)) {
|
if ($params['action'] === 'collected') {
|
||||||
$conditions[] = $model->ledgerContextConditions($ledger_id, $account_type);
|
extract($params['custom']);
|
||||||
|
|
||||||
|
if (isset($collected_account_id))
|
||||||
|
$conditions[] = array('Account.id' => $params['custom']['collected_account_id']);
|
||||||
|
else
|
||||||
|
die("INTERNAL ERROR: COLLECTED ACCOUNT ID NOT SET");
|
||||||
|
|
||||||
|
if (!empty($collected_from_date))
|
||||||
|
$conditions[]
|
||||||
|
= array('ReceiptTransaction.stamp >=' =>
|
||||||
|
$this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_from_date));
|
||||||
|
|
||||||
|
if (!empty($collected_through_date))
|
||||||
|
$conditions[]
|
||||||
|
= array('ReceiptTransaction.stamp <=' =>
|
||||||
|
$this->LedgerEntry->Transaction->dateFormatBeforeSave($collected_through_date . ' 23:59:59'));
|
||||||
|
|
||||||
|
if (isset($collected_payment_accounts))
|
||||||
|
$conditions[] = array('MoneyAccount.id' => $collected_payment_accounts);
|
||||||
|
else
|
||||||
|
$conditions[] = array('NOT' => array(array('MoneyAccount.id' => null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($params['action'] === 'ledger') {
|
||||||
|
$conditions[] = $model->ledgerContextConditions($ledger_id, $account_type);
|
||||||
|
}
|
||||||
if (isset($params['custom']['reconcile_id'])) {
|
if (isset($params['custom']['reconcile_id'])) {
|
||||||
$ftype = $params['custom']['account_ftype'];
|
$ftype = $params['custom']['account_ftype'];
|
||||||
//$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
//$ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
||||||
//$link['ReconcilingTransaction']['conditions'][] = array('Reconciliation.type' => $ftype);
|
$conditions[] = array('Reconciliation.'.$ftype.'_ledger_entry_id' => $params['custom']['reconcile_id']);
|
||||||
$conditions[] = array('Reconciliation.ledger_entry_id' => $params['custom']['reconcile_id']);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['account_id'])) {
|
if (isset($params['custom']['account_id'])) {
|
||||||
@@ -204,22 +234,46 @@ class LedgerEntriesController extends AppController {
|
|||||||
array('OR' =>
|
array('OR' =>
|
||||||
array(array('CreditAccount.id' => $params['custom']['account_id']),
|
array(array('CreditAccount.id' => $params['custom']['account_id']),
|
||||||
array('DebitAccount.id' => $params['custom']['account_id'])));
|
array('DebitAccount.id' => $params['custom']['account_id'])));
|
||||||
/* $conditions[] = */
|
|
||||||
/* array('Account.id' => $params['custom']['account_id']); */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['customer_id'])) {
|
if (isset($params['custom']['customer_id'])) {
|
||||||
$conditions[] =
|
$conditions[] =
|
||||||
array('Customer.id' => $params['custom']['customer_id']);
|
array('Customer.id' => $params['custom']['customer_id']);
|
||||||
|
|
||||||
|
/* $Account = new Account(); */
|
||||||
|
/* if (isset($params['custom']['account_ftype']) || */
|
||||||
|
/* isset($params['custom']['ledger_id'])) { */
|
||||||
|
/* $conditions[] = */
|
||||||
|
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* 'Account.id' => $Account->receiptAccountID())); */
|
||||||
|
/* } else { */
|
||||||
|
/* $conditions[] = */
|
||||||
|
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
|
||||||
|
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
|
||||||
|
/* )); */
|
||||||
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['lease_id'])) {
|
if (isset($params['custom']['lease_id'])) {
|
||||||
$conditions[] =
|
$conditions[] =
|
||||||
array('OR' => array
|
array('Lease.id' => $params['custom']['lease_id']);
|
||||||
(array('Lease.id' => $params['custom']['lease_id']),
|
|
||||||
array('ReconciledLedgerEntry.lease_id' => $params['custom']['lease_id']),
|
/* $Account = new Account(); */
|
||||||
));
|
/* if (isset($params['custom']['account_ftype']) || */
|
||||||
|
/* isset($params['custom']['ledger_id'])) { */
|
||||||
|
/* $conditions[] = */
|
||||||
|
/* array('OR' => array('Account.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* 'Account.id' => $Account->receiptAccountID())); */
|
||||||
|
/* } else { */
|
||||||
|
/* $conditions[] = */
|
||||||
|
/* array('OR' => array('DebitAccount.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* //'CreditAccount.id' => $Account->invoiceAccountID(), */
|
||||||
|
/* //'DebitAccount.id' => $Account->receiptAccountID(), */
|
||||||
|
/* 'CreditAccount.id' => $Account->receiptAccountID(), */
|
||||||
|
/* )); */
|
||||||
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['custom']['transaction_id'])) {
|
if (isset($params['custom']['transaction_id'])) {
|
||||||
@@ -227,6 +281,11 @@ class LedgerEntriesController extends AppController {
|
|||||||
array('Transaction.id' => $params['custom']['transaction_id']);
|
array('Transaction.id' => $params['custom']['transaction_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($params['custom']['monetary_source_id'])) {
|
||||||
|
$conditions[] =
|
||||||
|
array('MonetarySource.id' => $params['custom']['monetary_source_id']);
|
||||||
|
}
|
||||||
|
|
||||||
return $conditions;
|
return $conditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,10 +303,10 @@ class LedgerEntriesController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataGroup(&$params, &$model) {
|
function jqGridDataGroup(&$params, &$model) {
|
||||||
if (isset($params['custom']['notxgroup']))
|
if (isset($params['custom']['group_by_tx']) && $params['custom']['group_by_tx'])
|
||||||
return parent::jqGridDataGroup($params, $model);
|
return $model->alias.'.transaction_id';
|
||||||
|
|
||||||
return $model->alias.'.transaction_id';
|
return parent::jqGridDataGroup($params, $model);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||||
@@ -262,30 +321,28 @@ class LedgerEntriesController extends AppController {
|
|||||||
return $order;
|
return $order;
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridRecordsPostProcess(&$params, &$model, &$records) {
|
function jqGridDataRecords(&$params, &$model, $query) {
|
||||||
parent::jqGridRecordsPostProcess($params, $model, $records);
|
if ($params['action'] === 'collected') {
|
||||||
|
$tquery = array_diff_key($query, array('fields'=>1,'group'=>1,'limit'=>1,'order'=>1));
|
||||||
|
$tquery['fields'] = array('SUM(Reconciliation.amount) AS applied');
|
||||||
|
$total = $model->find('first', $tquery);
|
||||||
|
|
||||||
$subtotal = 0;
|
$params['userdata']['total'] = $total[0]['applied'];
|
||||||
foreach ($records AS &$record) {
|
|
||||||
$amount = (isset($record['LedgerEntry']['balance'])
|
|
||||||
? $record['LedgerEntry']['balance']
|
|
||||||
: $record['LedgerEntry']['amount']);
|
|
||||||
$record['LedgerEntry']['subtotal'] = ($subtotal += $amount);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
// Experiment to minimize columns by putting the monetary source
|
|
||||||
// as the Account, when available
|
|
||||||
if ($record['MonetarySource']['name'])
|
|
||||||
$record['Account']['name'] = $record['MonetarySource']['name'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return parent::jqGridDataRecords($params, $model, $query);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataOutputRecordCell(&$params, &$model, &$record, $field, $data) {
|
|
||||||
/* if ($field === 'CreditAccount.name') { */
|
|
||||||
/* $data .= '-OK'; */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
parent::jqGridDataOutputRecordCell($params, $model, $record, $field, $data);
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: reverse the ledger entry
|
||||||
|
*/
|
||||||
|
|
||||||
|
function reverse($id) {
|
||||||
|
$this->LedgerEntry->reverse($id);
|
||||||
|
$this->redirect(array('action'=>'view', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -307,7 +364,6 @@ class LedgerEntriesController extends AppController {
|
|||||||
('first',
|
('first',
|
||||||
array('contain' => array('MonetarySource.id',
|
array('contain' => array('MonetarySource.id',
|
||||||
'MonetarySource.name',
|
'MonetarySource.name',
|
||||||
'MonetarySource.MonetaryType.id',
|
|
||||||
'Transaction.id',
|
'Transaction.id',
|
||||||
'Transaction.stamp',
|
'Transaction.stamp',
|
||||||
'DebitLedger.id',
|
'DebitLedger.id',
|
||||||
@@ -321,9 +377,7 @@ class LedgerEntriesController extends AppController {
|
|||||||
'Lease.id',
|
'Lease.id',
|
||||||
),
|
),
|
||||||
|
|
||||||
'fields' => array('LedgerEntry.id',
|
'fields' => array('LedgerEntry.*'),
|
||||||
'LedgerEntry.amount',
|
|
||||||
'LedgerEntry.comment'),
|
|
||||||
|
|
||||||
'conditions' => array('LedgerEntry.id' => $id),
|
'conditions' => array('LedgerEntry.id' => $id),
|
||||||
));
|
));
|
||||||
@@ -340,6 +394,9 @@ class LedgerEntriesController extends AppController {
|
|||||||
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
|
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
|
||||||
'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']),
|
'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']),
|
||||||
));
|
));
|
||||||
|
$entry['DebitLedger']['Account']['ftype'] =
|
||||||
|
$this->LedgerEntry->DebitLedger->Account
|
||||||
|
->fundamentalType($entry['DebitLedger']['Account']['type']);
|
||||||
|
|
||||||
// Get the Account from CreditLedger
|
// Get the Account from CreditLedger
|
||||||
$entry['CreditLedger'] += $this->LedgerEntry->CreditLedger->Account->find
|
$entry['CreditLedger'] += $this->LedgerEntry->CreditLedger->Account->find
|
||||||
@@ -348,20 +405,63 @@ class LedgerEntriesController extends AppController {
|
|||||||
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
|
'fields' => array('Account.id', 'Account.name', 'Account.type', 'Account.trackable'),
|
||||||
'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']),
|
'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']),
|
||||||
));
|
));
|
||||||
|
$entry['CreditLedger']['Account']['ftype'] =
|
||||||
|
$this->LedgerEntry->CreditLedger->Account
|
||||||
|
->fundamentalType($entry['CreditLedger']['Account']['type']);
|
||||||
|
|
||||||
// Get the reconciliation balances for this ledger entry
|
// Get the reconciliation balances for this ledger entry
|
||||||
$stats = $this->LedgerEntry->stats($id);
|
$stats = $this->LedgerEntry->stats($id);
|
||||||
|
$stats['debit']['amount_reconciled'] = $stats['debit_amount_reconciled'];
|
||||||
|
$stats['credit']['amount_reconciled'] = $stats['credit_amount_reconciled'];
|
||||||
if ($entry['DebitLedger']['Account']['trackable'])
|
if ($entry['DebitLedger']['Account']['trackable'])
|
||||||
$stats['debit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['debit_amount_reconciled'];
|
$stats['debit']['amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['debit']['amount_reconciled'];
|
||||||
if ($entry['CreditLedger']['Account']['trackable'])
|
if ($entry['CreditLedger']['Account']['trackable'])
|
||||||
$stats['credit_amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['credit_amount_reconciled'];
|
$stats['credit']['amount_remaining'] = $entry['LedgerEntry']['amount'] - $stats['credit']['amount_reconciled'];
|
||||||
//pr($stats);
|
//pr($stats);
|
||||||
|
|
||||||
$reconciled = $this->LedgerEntry->findReconcilingTransactions($id);
|
$reconciled = $this->LedgerEntry->findReconciledLedgerEntries($id);
|
||||||
//pr(compact('reconciled'));
|
//pr($reconciled);
|
||||||
|
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090711
|
||||||
|
// It's not clear whether we should be able to reverse charges that have
|
||||||
|
// already been paid/cleared/reconciled. Certainly, that will be the
|
||||||
|
// case when someone has pre-paid and then moves out early. However, this
|
||||||
|
// will work well for items accidentally charged but not yet paid for.
|
||||||
|
if ((!$entry['DebitLedger']['Account']['trackable'] ||
|
||||||
|
$stats['debit']['amount_reconciled'] == 0) &&
|
||||||
|
(!$entry['CreditLedger']['Account']['trackable'] ||
|
||||||
|
$stats['credit']['amount_reconciled'] == 0)
|
||||||
|
|
||||||
|
&& 0
|
||||||
|
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Undo',
|
||||||
|
'url' => array('action' => 'reverse',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->LedgerEntry->Ledger->Account->type
|
||||||
|
($entry['CreditLedger']['Account']['id']) == 'INCOME')
|
||||||
|
{
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Reverse',
|
||||||
|
'url' => array('action' => 'reverse',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare to render.
|
// Prepare to render.
|
||||||
$title = "Ledger Entry #{$entry['LedgerEntry']['id']}";
|
$title = "Double Ledger Entry #{$entry['LedgerEntry']['id']}";
|
||||||
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
$this->set(compact('entry', 'title', 'reconciled', 'stats'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@ class LedgersController extends AppController {
|
|||||||
array(// Models
|
array(// Models
|
||||||
'Account',
|
'Account',
|
||||||
'LedgerEntry',
|
'LedgerEntry',
|
||||||
|
'Close',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -53,6 +53,7 @@ class MapsController extends AppController {
|
|||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
$this->set('info', $this->mapInfo($id, $requested_width));
|
$this->set('info', $this->mapInfo($id, $requested_width));
|
||||||
|
$this->set('title', "Site Map");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -150,22 +151,6 @@ class MapsController extends AppController {
|
|||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary function
|
|
||||||
function unitStatusList() {
|
|
||||||
return
|
|
||||||
array('DELETED' => array(),
|
|
||||||
'DAMAGED' => array(),
|
|
||||||
'COMPANY' => array(),
|
|
||||||
'UNAVAILABLE' => array(),
|
|
||||||
'RESERVED' => array(),
|
|
||||||
'DIRTY' => array(),
|
|
||||||
'VACANT' => array(),
|
|
||||||
'OCCUPIED' => array(),
|
|
||||||
'LATE' => array(),
|
|
||||||
'LOCKED' => array(),
|
|
||||||
'LIENED' => array(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -175,9 +160,10 @@ class MapsController extends AppController {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function legend($id = null, $requested_width = 400) {
|
function legend($id = null, $requested_width = 400) {
|
||||||
$status = $this->unitStatusList();
|
$status = $this->Map->Unit->activeStatusEnums();
|
||||||
$cols = 6;
|
//pr($status);
|
||||||
$rows = (int)((count($status) + $cols - 1) / $cols);
|
$rows = 2;
|
||||||
|
$cols = (int)((count($status) + $rows - 1) / $rows);
|
||||||
|
|
||||||
$info = array('units' => array());
|
$info = array('units' => array());
|
||||||
|
|
||||||
@@ -205,7 +191,7 @@ class MapsController extends AppController {
|
|||||||
$item_width *= $screen_adjustment_factor;
|
$item_width *= $screen_adjustment_factor;
|
||||||
$item_depth *= $screen_adjustment_factor;
|
$item_depth *= $screen_adjustment_factor;
|
||||||
|
|
||||||
foreach ($status AS $code => $color) {
|
foreach ($status AS $code => $value) {
|
||||||
$info['units'][] = array('name' => $code,
|
$info['units'][] = array('name' => $code,
|
||||||
'status' => $code,
|
'status' => $code,
|
||||||
'width' => $item_width,
|
'width' => $item_width,
|
||||||
+38
-5
@@ -38,8 +38,7 @@ class MonetarySourcesController extends AppController {
|
|||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
function jqGridDataTables(&$params, &$model) {
|
||||||
return array
|
return array
|
||||||
('link' => array('MonetaryType' => array('fields' => array('MonetaryType.id', 'MonetaryType.name')),
|
('contain' => false,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +48,26 @@ class MonetarySourcesController extends AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: nsf
|
||||||
|
* - Marks a monetary source as having insufficient funds.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function nsf($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>'index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090713
|
||||||
|
// For testing purposes, must be deleted
|
||||||
|
$stamp = '2009-07-09';
|
||||||
|
|
||||||
|
$this->MonetarySource->nsf($id, $stamp);
|
||||||
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -65,11 +84,25 @@ class MonetarySourcesController extends AppController {
|
|||||||
// Get the MonetarySource and related fields
|
// Get the MonetarySource and related fields
|
||||||
$monetary_source = $this->MonetarySource->find
|
$monetary_source = $this->MonetarySource->find
|
||||||
('first', array
|
('first', array
|
||||||
('contain' => array
|
('contain' => false,
|
||||||
('MonetaryType',
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090713
|
||||||
|
// Consider allowing the NSF operation only if the source is used on
|
||||||
|
// a ledger entry that is debited on a "payable" account (perhaps
|
||||||
|
// even restricted to "payable" ASSET accounts), credited on Receipt
|
||||||
|
// (or A/R), and reconciles the credit to an entry that debits on a
|
||||||
|
// "depositable" account.
|
||||||
|
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'NSF',
|
||||||
|
'url' => array('action' => 'nsf',
|
||||||
|
$id));
|
||||||
|
|
||||||
// Prepare to render.
|
// Prepare to render.
|
||||||
$title = "Monetary Source #{$monetary_source['MonetarySource']['id']}";
|
$title = "Monetary Source #{$monetary_source['MonetarySource']['id']}";
|
||||||
$this->set(compact('monetary_source', 'title'));
|
$this->set(compact('monetary_source', 'title'));
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TransactionsController extends AppController {
|
||||||
|
|
||||||
|
var $components = array('RequestHandler');
|
||||||
|
|
||||||
|
var $sidemenu_links =
|
||||||
|
array(array('name' => '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: postInvoice
|
||||||
|
* - handles the creation of a charge invoice
|
||||||
|
*/
|
||||||
|
|
||||||
|
function postInvoice() {
|
||||||
|
if (!$this->RequestHandler->isPost()) {
|
||||||
|
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->Transaction->addInvoice($this->data, null,
|
||||||
|
$this->data['Lease']['id'])) {
|
||||||
|
$this->Session->setFlash("INVOICE FAILED", true);
|
||||||
|
// REVISIT <AP> 20090706:
|
||||||
|
// Until we can work out the session problems,
|
||||||
|
// just die.
|
||||||
|
die("<H1>INVOICE FAILED</H1>");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->layout = null;
|
||||||
|
$this->autoLayout = false;
|
||||||
|
$this->autoRender = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: postReceipt
|
||||||
|
* - handles the creation of a payment receipt
|
||||||
|
*/
|
||||||
|
|
||||||
|
function postReceipt() {
|
||||||
|
if (!$this->RequestHandler->isPost()) {
|
||||||
|
echo('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->data['LedgerEntry'] AS &$entry) {
|
||||||
|
if (!isset($entry['acct'][$entry['account_id']]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$entry['MonetarySource'] = $entry['acct'][$entry['account_id']];
|
||||||
|
}
|
||||||
|
|
||||||
|
pr($this->data);
|
||||||
|
if (!$this->Transaction->addReceipt($this->data,
|
||||||
|
$this->data['Customer']['id'],
|
||||||
|
(isset($this->data['Lease']['id'])
|
||||||
|
? $this->data['Lease']['id']
|
||||||
|
: null ))) {
|
||||||
|
$this->Session->setFlash("RECEIPT FAILED", true);
|
||||||
|
// REVISIT <AP> 20090706:
|
||||||
|
// Until we can work out the session problems,
|
||||||
|
// just die.
|
||||||
|
die("<H1>RECEIPT FAILED</H1>");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->layout = null;
|
||||||
|
$this->autoLayout = false;
|
||||||
|
$this->autoRender = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,278 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class UnitsController extends AppController {
|
||||||
|
|
||||||
|
var $sidemenu_links =
|
||||||
|
array(array('name' => 'Units', 'header' => true),
|
||||||
|
array('name' => 'Occupied', 'url' => array('controller' => 'units', 'action' => 'occupied')),
|
||||||
|
array('name' => 'Vacant', 'url' => array('controller' => 'units', 'action' => 'vacant')),
|
||||||
|
array('name' => 'Unavailable', 'url' => array('controller' => 'units', 'action' => 'unavailable')),
|
||||||
|
array('name' => 'All', 'url' => array('controller' => 'units', 'action' => 'all')),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* override: sideMenuLinks
|
||||||
|
* - Generates controller specific links for the side menu
|
||||||
|
*/
|
||||||
|
function sideMenuLinks() {
|
||||||
|
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: index / unavailable / vacant / occupied / all
|
||||||
|
* - Generate a listing of units
|
||||||
|
*/
|
||||||
|
|
||||||
|
function index() { $this->all(); }
|
||||||
|
function unavailable() { $this->jqGridView('Unavailable Units'); }
|
||||||
|
function vacant() { $this->jqGridView('Vacant Units'); }
|
||||||
|
function occupied() { $this->jqGridView('Occupied Units'); }
|
||||||
|
function all() { $this->jqGridView('All Units', 'all'); }
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* virtuals: jqGridData
|
||||||
|
* - With the application controller handling the jqGridData action,
|
||||||
|
* these virtual functions ensure that the correct data is passed
|
||||||
|
* to jqGrid.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function jqGridDataSetup(&$params) {
|
||||||
|
parent::jqGridDataSetup($params);
|
||||||
|
if (!isset($params['action']))
|
||||||
|
$params['action'] = 'all';
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataCountTables(&$params, &$model) {
|
||||||
|
$link = array
|
||||||
|
('link' =>
|
||||||
|
array(// Models
|
||||||
|
'UnitSize' => array('fields' => array('id', 'name')),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($params['action'] === 'occupied')
|
||||||
|
$link['Lease'] = array('fields' => array(),
|
||||||
|
// Models
|
||||||
|
'Contact' => array('fields' => array('display_name'),
|
||||||
|
//'type' => 'LEFT',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataTables(&$params, &$model) {
|
||||||
|
$link = $this->jqGridDataCountTables($params, $model);
|
||||||
|
$link['link']['CurrentLease']['LedgerEntry'] = array('fields' => array());
|
||||||
|
$link['link']['CurrentLease']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||||
|
$link['link']['CurrentLease']['LedgerEntry']['Ledger']['Account'] = array('fields' => array());
|
||||||
|
// INNER JOIN would be great, as it would ensure we're only looking
|
||||||
|
// at the ledger entries that we truly want. However, this also
|
||||||
|
// removes from the query any leases that do not yet have a ledger
|
||||||
|
// entry in A/R. A solution would be to INNER JOIN these tables,
|
||||||
|
// and LEFT JOIN it to the rest. Grouping of JOINs, however, is
|
||||||
|
// implemented with the 'joins' tag, and is not available through
|
||||||
|
// the Linkable behavior interface.
|
||||||
|
//$link['link']['CurrentLease']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||||
|
$link['link']['CurrentLease']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||||
|
= array('Account.id' =>
|
||||||
|
$this->Unit->CurrentLease->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||||
|
return $link;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataFields(&$params, &$model) {
|
||||||
|
$db = &$model->getDataSource();
|
||||||
|
$fields = $db->fields($model, $model->alias);
|
||||||
|
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
||||||
|
" IF(LedgerEntry.debit_ledger_id = Account.id," .
|
||||||
|
" 1, -1))" .
|
||||||
|
" * LedgerEntry.amount) AS 'balance'");
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataConditions(&$params, &$model) {
|
||||||
|
$conditions = parent::jqGridDataConditions($params, $model);
|
||||||
|
|
||||||
|
if ($params['action'] === 'unavailable') {
|
||||||
|
$conditions[] = $this->Unit->conditionUnavailable();
|
||||||
|
}
|
||||||
|
elseif ($params['action'] === 'vacant') {
|
||||||
|
$conditions[] = $this->Unit->conditionVacant();
|
||||||
|
}
|
||||||
|
elseif ($params['action'] === 'occupied') {
|
||||||
|
$conditions[] = $this->Unit->conditionOccupied();
|
||||||
|
}
|
||||||
|
elseif ($params['action'] === 'unoccupied') {
|
||||||
|
$conditions[] = array('NOT' => array($this->Unit->conditionOccupied()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||||
|
// Instead of sorting by name, sort by defined order
|
||||||
|
if ($index === 'Unit.name')
|
||||||
|
$index = 'Unit.sort_order';
|
||||||
|
|
||||||
|
$order = array();
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||||
|
|
||||||
|
// If sorting by anything other than name (defined order)
|
||||||
|
// add the sort-order as a secondary condition
|
||||||
|
if ($index !== 'Unit.name')
|
||||||
|
$order[] = parent::jqGridDataOrder($params, $model,
|
||||||
|
'Unit.sort_order', $direction);
|
||||||
|
|
||||||
|
return $order;
|
||||||
|
}
|
||||||
|
|
||||||
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
|
$links['Unit'] = array('name');
|
||||||
|
$links['UnitSize'] = array('name');
|
||||||
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_in
|
||||||
|
* - Sets up the move-in page for the given unit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_in($id = null) {
|
||||||
|
$customer = array();
|
||||||
|
$unit = array();
|
||||||
|
|
||||||
|
if (isset($id)) {
|
||||||
|
$this->Unit->recursive = -1;
|
||||||
|
$unit = current($this->Unit->read(null, $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = 'Unit Move-In';
|
||||||
|
$this->set(compact('customer', 'unit', 'title'));
|
||||||
|
$this->render('/leases/move');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: move_out
|
||||||
|
* - prepare or execute a move out on a specific lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function move_out($id) {
|
||||||
|
|
||||||
|
$unit = $this->Unit->find
|
||||||
|
('first', array
|
||||||
|
('contain' => array
|
||||||
|
(// Models
|
||||||
|
'CurrentLease' =>
|
||||||
|
array(//'conditions' => array('Lease.moveout_date' => null),
|
||||||
|
// Models
|
||||||
|
'Customer' =>
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'conditions' => array('Unit.id' => $id),
|
||||||
|
));
|
||||||
|
$this->set('customer', $unit['CurrentLease']['Customer']);
|
||||||
|
$this->set('unit', $unit['Unit']);
|
||||||
|
$this->set('lease', $unit['CurrentLease']);
|
||||||
|
|
||||||
|
$redirect = array('controller' => 'units',
|
||||||
|
'action' => 'view',
|
||||||
|
$id);
|
||||||
|
|
||||||
|
$title = ('Lease #' . $unit['CurrentLease']['number'] . ': ' .
|
||||||
|
$unit['Unit']['name'] . ': ' .
|
||||||
|
$unit['CurrentLease']['Customer']['name'] . ': Prepare Move-Out');
|
||||||
|
$this->set(compact('title', 'redirect'));
|
||||||
|
$this->render('/leases/move');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* action: view
|
||||||
|
* - Displays information about a specific unit
|
||||||
|
*/
|
||||||
|
|
||||||
|
function view($id = null) {
|
||||||
|
if (!$id) {
|
||||||
|
$this->Session->setFlash(__('Invalid Item.', true));
|
||||||
|
$this->redirect(array('action'=>''));
|
||||||
|
}
|
||||||
|
|
||||||
|
$unit = $this->Unit->find
|
||||||
|
('first',
|
||||||
|
array('contain' =>
|
||||||
|
array(// Models
|
||||||
|
'UnitSize',
|
||||||
|
'Lease' => array('Customer'),
|
||||||
|
'CurrentLease' => array('Customer')
|
||||||
|
),
|
||||||
|
'conditions' => array('Unit.id' => $id),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Get the balance on each lease.
|
||||||
|
foreach ($unit['Lease'] AS &$lease) {
|
||||||
|
$stats = $this->Unit->Lease->stats($lease['id']);
|
||||||
|
$lease['balance'] = $stats['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$outstanding_balance = 0;
|
||||||
|
$outstanding_deposit = 0;
|
||||||
|
if (isset($unit['CurrentLease']['id'])) {
|
||||||
|
// Figure out the outstanding balance of the current lease.
|
||||||
|
$stats = $this->Unit->stats($id);
|
||||||
|
$outstanding_balance =
|
||||||
|
$stats['CurrentLease']['balance'];
|
||||||
|
|
||||||
|
// Figure out the total security deposit for the current lease.
|
||||||
|
$deposits = $this->Unit->Lease->findSecurityDeposits($unit['CurrentLease']['id']);
|
||||||
|
$outstanding_deposit = $deposits['summary']['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up dynamic menu items
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Operations', 'header' => true);
|
||||||
|
|
||||||
|
if (isset($unit['CurrentLease']['id']) &&
|
||||||
|
!isset($unit['CurrentLease']['moveout_date'])) {
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Move-Out', 'url' => array('action' => 'move_out',
|
||||||
|
$id));
|
||||||
|
} else {
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Move-In', 'url' => array('action' => 'move_in',
|
||||||
|
$id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($unit['CurrentLease']['id']) &&
|
||||||
|
!isset($unit['CurrentLease']['close_date'])) {
|
||||||
|
$this->sidemenu_links[] =
|
||||||
|
array('name' => 'Payment', 'url' => array('controller' => 'customers',
|
||||||
|
'action' => 'receipt',
|
||||||
|
$unit['CurrentLease']['customer_id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare to render.
|
||||||
|
$title = 'Unit ' . $unit['Unit']['name'];
|
||||||
|
$this->set(compact('unit', 'title',
|
||||||
|
'outstanding_balance',
|
||||||
|
'outstanding_deposit'));
|
||||||
|
}
|
||||||
|
}
|
||||||
-1170
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,850 @@
|
|||||||
|
<?php
|
||||||
|
class Account extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'Account';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'name' => array('notempty'),
|
||||||
|
'external_name' => array('notempty')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasOne = array(
|
||||||
|
'CurrentLedger' => array(
|
||||||
|
'className' => 'Ledger',
|
||||||
|
// REVISIT <AP> 20090702:
|
||||||
|
// I would prefer this statement, which has no
|
||||||
|
// engine specific code. However, it doesn't
|
||||||
|
// work with the Linkable behavior. I need to
|
||||||
|
// look into that, just not right now.
|
||||||
|
//'conditions' => array('CurrentLedger.close_id' => null),
|
||||||
|
'conditions' => array('CurrentLedger.close_id IS NULL'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'Ledger',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: type
|
||||||
|
* - Returns the type of this account
|
||||||
|
*/
|
||||||
|
function type($id) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('type'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
return $account['Account']['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: fundamentalType
|
||||||
|
* - Returns the fundmental type of the account, credit or debit
|
||||||
|
*/
|
||||||
|
function fundamentalType($id_or_type) {
|
||||||
|
if (is_numeric($id_or_type))
|
||||||
|
$type = $this->type($id_or_type);
|
||||||
|
else
|
||||||
|
$type = $id_or_type;
|
||||||
|
|
||||||
|
// Asset and Expense accounts are debit accounts
|
||||||
|
if (in_array(strtoupper($type), array('ASSET', 'EXPENSE')))
|
||||||
|
return 'debit';
|
||||||
|
|
||||||
|
// Otherwise, it's a credit account
|
||||||
|
return 'credit';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: fundamentalOpposite
|
||||||
|
* - Returns the opposite fundmental type of the account, credit or debit
|
||||||
|
*/
|
||||||
|
function fundamentalOpposite($id_or_type) {
|
||||||
|
if (in_array(strtolower($id_or_type), array('credit', 'debit')))
|
||||||
|
$fund = $id_or_type;
|
||||||
|
else
|
||||||
|
$fund = $this->fundamentalType($id_or_type);
|
||||||
|
|
||||||
|
if ($fund == 'debit')
|
||||||
|
return 'credit';
|
||||||
|
|
||||||
|
return 'debit';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: name
|
||||||
|
* - Returns the name of this account
|
||||||
|
*/
|
||||||
|
function name($id) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('recursive' => -1,
|
||||||
|
'fields' => array('name'),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
return $account['Account']['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: Account IDs
|
||||||
|
* - Returns the ID of the desired account
|
||||||
|
*/
|
||||||
|
|
||||||
|
function securityDepositAccountID() { return $this->nameToID('Security Deposit'); }
|
||||||
|
function rentAccountID() { return $this->nameToID('Rent'); }
|
||||||
|
function lateChargeAccountID() { return $this->nameToID('Late Charge'); }
|
||||||
|
function nsfAccountID() { return $this->nameToID('NSF'); }
|
||||||
|
function nsfChargeAccountID() { return $this->nameToID('NSF Charge'); }
|
||||||
|
function taxAccountID() { return $this->nameToID('Tax'); }
|
||||||
|
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||||
|
function cashAccountID() { return $this->nameToID('Cash'); }
|
||||||
|
function checkAccountID() { return $this->nameToID('Check'); }
|
||||||
|
function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
|
||||||
|
function concessionAccountID() { return $this->nameToID('Concession'); }
|
||||||
|
function pettyCashAccountID() { return $this->nameToID('Petty Cash'); }
|
||||||
|
function invoiceAccountID() { return $this->nameToID('Invoice'); }
|
||||||
|
function receiptAccountID() { return $this->nameToID('Receipt'); }
|
||||||
|
function badDebtAccountID() { return $this->nameToID('Bad Debt'); }
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: fundamentalAccounts
|
||||||
|
* - Returns an array of accounts by their fundamental type
|
||||||
|
*/
|
||||||
|
|
||||||
|
function fundamentalAccounts($ftype) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('all', array
|
||||||
|
('contain' => array('CurrentLedger'),
|
||||||
|
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||||
|
'conditions' => array('Account.type' => strtoupper($ftype))
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: relatedAccounts
|
||||||
|
* - Returns an array of accounts related by similar attributes
|
||||||
|
*/
|
||||||
|
|
||||||
|
function relatedAccounts($attribute, $extra = null) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('all', array
|
||||||
|
('contain' => array('CurrentLedger'),
|
||||||
|
'fields' => array('Account.id', 'Account.type', 'Account.name', 'CurrentLedger.id'),
|
||||||
|
'conditions' => array('Account.'.$attribute => true),
|
||||||
|
'order' => array('Account.name'),
|
||||||
|
) + (isset($extra) ? $extra : array())
|
||||||
|
);
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: chargeAccounts
|
||||||
|
* - Returns an array of accounts suitable for charges
|
||||||
|
*/
|
||||||
|
|
||||||
|
function chargeAccounts() {
|
||||||
|
// Get all accounts that support charges
|
||||||
|
$accounts = $this->relatedAccounts('chargeable', array('order' => 'name'));
|
||||||
|
|
||||||
|
// Rearrange to be of the form (id => name)
|
||||||
|
$charge_accounts = array();
|
||||||
|
foreach ($accounts AS $acct) {
|
||||||
|
$charge_accounts[$acct['Account']['id']] = $acct['Account']['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $charge_accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: paymentAccounts
|
||||||
|
* - Returns an array of accounts suitable for payments
|
||||||
|
*/
|
||||||
|
|
||||||
|
function paymentAccounts() {
|
||||||
|
// Get all accounts that support payments
|
||||||
|
$accounts = $this->relatedAccounts('payable', array('order' => 'name'));
|
||||||
|
|
||||||
|
// Rearrange to be of the form (id => name)
|
||||||
|
$payment_accounts = array();
|
||||||
|
foreach ($accounts AS $acct) {
|
||||||
|
$payment_accounts[$acct['Account']['id']] = $acct['Account']['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $payment_accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: collectableAccounts
|
||||||
|
* - Returns an array of accounts suitable to show income collection
|
||||||
|
*/
|
||||||
|
|
||||||
|
function collectableAccounts() {
|
||||||
|
$accounts = $this->paymentAccounts();
|
||||||
|
|
||||||
|
foreach(array($this->nsfAccountID(),
|
||||||
|
$this->securityDepositAccountID())
|
||||||
|
AS $account_id) {
|
||||||
|
$accounts[$account_id] = $this->name($account_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: currentLedgerID
|
||||||
|
* - Returns the current ledger ID of the account
|
||||||
|
*/
|
||||||
|
function currentLedgerID($id) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$item = $this->find('first', array
|
||||||
|
('contain' => 'CurrentLedger',
|
||||||
|
'conditions' => array('Account.id' => $id),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
return $item['CurrentLedger']['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: ledgers
|
||||||
|
* - Returns an array of ledger ids from the given account
|
||||||
|
*/
|
||||||
|
function ledgers($id, $all = false) {
|
||||||
|
if ($all) {
|
||||||
|
$contain = array('Ledger' => array('fields' => array('Ledger.id')));
|
||||||
|
} else {
|
||||||
|
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('first', array
|
||||||
|
('contain' => $contain,
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Account.id' => $id)),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
|
||||||
|
if ($all) {
|
||||||
|
$ledger_ids = array();
|
||||||
|
foreach ($account['Ledger'] AS $ledger)
|
||||||
|
array_push($ledger_ids, $ledger['id']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$ledger_ids = array($account['CurrentLedger']['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::ledgers', */
|
||||||
|
/* 'args' => compact('id', 'all'), */
|
||||||
|
/* 'return' => $ledger_ids)); */
|
||||||
|
|
||||||
|
return $ledger_ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: closeCurrentLedger
|
||||||
|
* - Closes the current account ledger, and opens a new one
|
||||||
|
* with the old balance carried forward.
|
||||||
|
*/
|
||||||
|
function closeCurrentLedger($id = null, $close_id = null) {
|
||||||
|
$contain = array('CurrentLedger' => array('fields' => array('CurrentLedger.id')));
|
||||||
|
|
||||||
|
if (!$close_id) {
|
||||||
|
$close = new Close();
|
||||||
|
$close->create();
|
||||||
|
if (!$close->save(array('stamp' => null), false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$close_id = $close->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$account = $this->find('all', array
|
||||||
|
('contain' => $contain,
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' =>
|
||||||
|
$id ? array(array('Account.id' => $id)) : array()
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
//pr(compact('id', 'account'));
|
||||||
|
|
||||||
|
foreach ($account AS $acct) {
|
||||||
|
if (!$this->Ledger->closeLedger($acct['CurrentLedger']['id'], $close_id))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerEntries
|
||||||
|
* - Returns an array of ledger entries that belong to the given
|
||||||
|
* account, either just from the current ledger, or from all ledgers.
|
||||||
|
*/
|
||||||
|
function findLedgerEntries($id, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$entries = array();
|
||||||
|
foreach ($this->ledgers($id, $all) AS $ledger_id) {
|
||||||
|
$ledger_entries = $this->Ledger->findLedgerEntries
|
||||||
|
($ledger_id, $this->type($id), $cond, $link);
|
||||||
|
$entries = array_merge($entries, $ledger_entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stats = $this->stats($id, $all, $cond);
|
||||||
|
$entries = array('Entries' => $entries,
|
||||||
|
'summary' => $stats['Ledger']);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('stats'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findLedgerEntriesRelatedToAccount
|
||||||
|
* - Returns an array of ledger entries that belong to the given
|
||||||
|
* account, and are related to a specific account, either just from
|
||||||
|
* the current ledger, or from all ledgers.
|
||||||
|
*/
|
||||||
|
function findLedgerEntriesRelatedToAccount($id, $rel_ids, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntriesRelatedToAccount', */
|
||||||
|
/* 'args' => compact('id', 'rel_ids', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
if (!isset($cond))
|
||||||
|
$cond = array();
|
||||||
|
if (!is_array($rel_ids))
|
||||||
|
$rel_ids = array($rel_ids);
|
||||||
|
|
||||||
|
$ledger_ids = array();
|
||||||
|
foreach ($rel_ids AS $rel_id)
|
||||||
|
$ledger_ids = array_merge($ledger_ids, $this->ledgers($rel_id));
|
||||||
|
|
||||||
|
array_push($cond, $this->Ledger->LedgerEntry->conditionEntryAsCreditOrDebit($ledger_ids));
|
||||||
|
$entries = $this->findLedgerEntries($id, $all, $cond, $link);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Account::findLedgerEntriesRelatedToAccount', */
|
||||||
|
/* 'args' => compact('id', 'relid', 'all', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('ledger_ids'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findUnreconciledLedgerEntries
|
||||||
|
* - Returns ledger entries that are not yet reconciled
|
||||||
|
* (such as charges not paid).
|
||||||
|
*/
|
||||||
|
|
||||||
|
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null, $cond = null) {
|
||||||
|
if (!isset($cond))
|
||||||
|
$cond = array();
|
||||||
|
$cond[] = array('Account.id' => $id);
|
||||||
|
|
||||||
|
foreach (($fundamental_type
|
||||||
|
? array($fundamental_type)
|
||||||
|
: array('debit', 'credit')) AS $fund) {
|
||||||
|
$ucfund = ucfirst($fund);
|
||||||
|
$unreconciled[$fund]['entry'] = $this->find
|
||||||
|
('all', array
|
||||||
|
('link' => array
|
||||||
|
('Ledger' => array
|
||||||
|
('fields' => array(),
|
||||||
|
"LedgerEntry" => array
|
||||||
|
('class' => "{$ucfund}LedgerEntry",
|
||||||
|
'fields' => array('id', 'customer_id', 'lease_id', 'amount'),
|
||||||
|
"ReconciliationLedgerEntry" => array
|
||||||
|
('class' => "{$ucfund}ReconciliationLedgerEntry",
|
||||||
|
'fields' => array
|
||||||
|
("COALESCE(SUM(Reconciliation.amount),0) AS 'reconciled'",
|
||||||
|
"LedgerEntry.amount - COALESCE(SUM(Reconciliation.amount),0) AS 'balance'",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'group' => ("LedgerEntry.id" .
|
||||||
|
" HAVING LedgerEntry.amount" .
|
||||||
|
" <> COALESCE(SUM(Reconciliation.amount),0)"),
|
||||||
|
'conditions' => $cond,
|
||||||
|
'fields' => array(),
|
||||||
|
));
|
||||||
|
$balance = 0;
|
||||||
|
foreach ($unreconciled[$fund]['entry'] AS &$entry) {
|
||||||
|
$entry = array_merge(array_diff_key($entry["LedgerEntry"], array(0=>true)),
|
||||||
|
$entry[0]);
|
||||||
|
$balance += $entry['balance'];
|
||||||
|
}
|
||||||
|
$unreconciled[$fund]['balance'] = $balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $unreconciled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: reconcileNewLedgerEntry
|
||||||
|
* - Returns which ledger entries a new credit/debit would
|
||||||
|
* reconcile, and how much.
|
||||||
|
*
|
||||||
|
* - REVISIT <AP> 20090617
|
||||||
|
* This should be subject to different algorithms, such
|
||||||
|
* as apply to oldest charges first, newest first, to fees
|
||||||
|
* before rent, etc. Until we get there, I'll hardcode
|
||||||
|
* whatever algorithm is simplest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function reconcileNewLedgerEntry($id, $fundamental_type, $amount, $cond = null) {
|
||||||
|
$ofund = $this->fundamentalOpposite($fundamental_type);
|
||||||
|
$unreconciled = array($ofund => array('entry'=>array(), 'balance'=>0));
|
||||||
|
$applied = 0;
|
||||||
|
|
||||||
|
// if there is no money in the entry, it can reconcile nothing
|
||||||
|
// don't bother wasting time sifting ledger entries.
|
||||||
|
if ($amount > 0) {
|
||||||
|
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund, $cond);
|
||||||
|
|
||||||
|
foreach ($unreconciled[$ofund]['entry'] AS $i => &$entry) {
|
||||||
|
// Determine if amount is sufficient to cover the entry
|
||||||
|
if ($amount > $entry['balance'])
|
||||||
|
$apply = $entry['balance'];
|
||||||
|
elseif ($amount > 0)
|
||||||
|
$apply = $amount;
|
||||||
|
else {
|
||||||
|
unset($unreconciled[$ofund]['entry'][$i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry['applied'] = $apply;
|
||||||
|
$entry['reconciled'] += $apply;
|
||||||
|
$entry['balance'] -= $apply;
|
||||||
|
$applied += $apply;
|
||||||
|
$amount -= $apply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$unreconciled[$ofund]['unapplied'] = $amount;
|
||||||
|
$unreconciled[$ofund]['applied'] = $applied;
|
||||||
|
$unreconciled[$ofund]['balance'] -= $applied;
|
||||||
|
return $unreconciled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: postLedgerEntry
|
||||||
|
* -
|
||||||
|
* transaction_data
|
||||||
|
* - transaction_id (optional... if set all else is ignored)
|
||||||
|
* - Transaction
|
||||||
|
* - stamp (optional... otherwise NOW is used)
|
||||||
|
* - comment
|
||||||
|
*
|
||||||
|
* monetary_source_data
|
||||||
|
* - monetary_source_id (optional... if set all else is ignored)
|
||||||
|
* - account_name
|
||||||
|
* - MonetarySource
|
||||||
|
* - name
|
||||||
|
*/
|
||||||
|
|
||||||
|
function postLedgerEntry($transaction_data,
|
||||||
|
$monetary_data,
|
||||||
|
$entry_data,
|
||||||
|
$reconcile = null) {
|
||||||
|
//pr(compact('transaction_data', 'monetary_data', 'entry_data', 'reconcile'));
|
||||||
|
|
||||||
|
// Automatically figure out the customer if we have the lease
|
||||||
|
if (isset($entry_data['lease_id']) && !isset($entry_data['customer_id'])) {
|
||||||
|
$L = new Lease();
|
||||||
|
$L->recursive = -1;
|
||||||
|
$lease = $L->read(null, $entry_data['lease_id']);
|
||||||
|
$entry_data['customer_id'] = $lease['Lease']['customer_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($entry_data['lease_id']))
|
||||||
|
$entry_data['lease_id'] = null;
|
||||||
|
|
||||||
|
if (!isset($entry_data['customer_id']))
|
||||||
|
$entry_data['customer_id'] = null;
|
||||||
|
|
||||||
|
// Get the Transaction squared away
|
||||||
|
if (isset($transaction_data['transaction_id'])) {
|
||||||
|
$transaction_data
|
||||||
|
= array_intersect_key($transaction_data,
|
||||||
|
array('transaction_id'=>1,
|
||||||
|
'split_transaction_id'=>1));
|
||||||
|
}
|
||||||
|
elseif (isset($transaction_data['Transaction'])) {
|
||||||
|
$transaction_data
|
||||||
|
= array_intersect_key($transaction_data,
|
||||||
|
array('Transaction'=>1,
|
||||||
|
'split_transaction_id'=>1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$transaction_data = array('Transaction'=>array('stamp' => null));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Get the Monetary Source squared away
|
||||||
|
if (isset($monetary_data)) {
|
||||||
|
if (!isset($monetary_data['monetary_source_id'])) {
|
||||||
|
|
||||||
|
// Convert Account ID to name or vice versa
|
||||||
|
if (isset($monetary_data['account_id'])) {
|
||||||
|
$monetary_data['account_name'] = $this->name($monetary_data['account_id']);
|
||||||
|
} elseif (isset($monetary_data['account_name'])) {
|
||||||
|
$monetary_data['account_id'] = $this->nameToID($monetary_data['account_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($monetary_data['account_id'] == $this->cashAccountID()) {
|
||||||
|
// No distinguishing features of Cash, just
|
||||||
|
// use the shared monetary source
|
||||||
|
$monetary_data['monetary_source_id'] =
|
||||||
|
$this->Ledger->LedgerEntry->MonetarySource->nameToID('Cash');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($monetary_data['monetary_source_id'])) {
|
||||||
|
$monetary_data
|
||||||
|
= array_intersect_key($monetary_data,
|
||||||
|
array('monetary_source_id'=>1));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// The monetary source needs to be unique
|
||||||
|
// Create a new one dedicated to this entry
|
||||||
|
// Give it a fancy name based on the check number
|
||||||
|
$monetary_data['MonetarySource']['name'] = $monetary_data['account_name'];
|
||||||
|
if ($monetary_data['account_name'] === $this->name($this->checkAccountID()) ||
|
||||||
|
$monetary_data['account_name'] === $this->name($this->moneyOrderAccountID())) {
|
||||||
|
$monetary_data['MonetarySource']['name'] .=
|
||||||
|
' #' . $monetary_data['MonetarySource']['data1'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$monetary_data
|
||||||
|
= array_intersect_key($monetary_data,
|
||||||
|
array('MonetarySource'=>1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$monetary_data = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure to clean out any unwanted data from the entry
|
||||||
|
$entry_data
|
||||||
|
= array_diff_key($entry_data,
|
||||||
|
array('transaction_id'=>1, 'Transaction'=>1,
|
||||||
|
'monetary_source_id'=>1, 'MonetarySource'=>1));
|
||||||
|
|
||||||
|
// Then add in the transaction and monetary source data
|
||||||
|
//pr(compact('transaction_data', 'monetary_data', 'entry_data'));
|
||||||
|
if (isset($transaction_data))
|
||||||
|
$entry_data += $transaction_data;
|
||||||
|
if (isset($monetary_data))
|
||||||
|
$entry_data += $monetary_data;
|
||||||
|
|
||||||
|
// Set up the debit ledger id
|
||||||
|
if (!isset($entry_data['debit_ledger_id'])) {
|
||||||
|
$entry_data['debit_ledger_id'] =
|
||||||
|
(isset($entry_data['debit_account_id'])
|
||||||
|
? $this->currentLedgerID($entry_data['debit_account_id'])
|
||||||
|
: (isset($entry_data['debit_account_name'])
|
||||||
|
? $this->currentLedgerID($this->nameToID($entry_data['debit_account_name']))
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the credit ledger id
|
||||||
|
if (!isset($entry_data['credit_ledger_id'])) {
|
||||||
|
$entry_data['credit_ledger_id'] =
|
||||||
|
(isset($entry_data['credit_account_id'])
|
||||||
|
? $this->currentLedgerID($entry_data['credit_account_id'])
|
||||||
|
: (isset($entry_data['credit_account_name'])
|
||||||
|
? $this->currentLedgerID($this->nameToID($entry_data['credit_account_name']))
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pr(array('pre-save', compact('entry_data')));
|
||||||
|
// Create it!
|
||||||
|
$new_entry = new LedgerEntry();
|
||||||
|
$new_entry->create();
|
||||||
|
if (!$new_entry->saveAll($entry_data, array('validate'=>false))) {
|
||||||
|
return array('error' => true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// See if the user has entered some sort of non-array
|
||||||
|
// for the reconcile parameter.
|
||||||
|
if (isset($reconcile) && is_bool($reconcile) && $reconcile) {
|
||||||
|
$reconcile = array('debit' => true, 'credit' => true);
|
||||||
|
}
|
||||||
|
elseif (isset($reconcile) && $reconcile == 'invoice') {
|
||||||
|
$reconcile = array('credit' => 'invoice');
|
||||||
|
}
|
||||||
|
elseif (isset($reconcile) && $reconcile == 'receipt') {
|
||||||
|
$reconcile = array('debit' => 'receipt');
|
||||||
|
}
|
||||||
|
elseif (!isset($reconcile) || !is_array($reconcile)) {
|
||||||
|
$reconcile = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reconcile the new entry... assume we'll have success
|
||||||
|
$err = false;
|
||||||
|
foreach (array_intersect_key($reconcile, array('credit'=>1,'debit'=>1))
|
||||||
|
AS $dc_type => $reconcile_set) {
|
||||||
|
if (!isset($reconcile_set) || (is_bool($reconcile_set) && !$reconcile_set))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ($reconcile_set === 'receipt') {
|
||||||
|
$C = new Customer();
|
||||||
|
$reconciled = $C->reconcileNewLedgerEntry($entry_data['customer_id'],
|
||||||
|
$this->fundamentalOpposite($dc_type),
|
||||||
|
$entry_data['amount']);
|
||||||
|
|
||||||
|
/* pr(array("reconcile receipt", */
|
||||||
|
/* compact('reconciled', 'split_transaction', 'transaction_data'))); */
|
||||||
|
$split_transaction = array_intersect_key($transaction_data,
|
||||||
|
array('Transaction'=>1,
|
||||||
|
'split_transaction_id'=>1));
|
||||||
|
|
||||||
|
if (isset($split_transaction['split_transaction_id']))
|
||||||
|
$split_transaction['transaction_id'] = $split_transaction['split_transaction_id'];
|
||||||
|
|
||||||
|
if (is_array($reconciled) && count($reconciled[$dc_type]['entry'])) {
|
||||||
|
foreach ($reconciled[$dc_type]['entry'] AS $rec) {
|
||||||
|
//pr(compact('rec', 'split_transaction'));
|
||||||
|
if (!$rec['applied'])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Create an entry to handle the splitting of the funds ("Payment")
|
||||||
|
// and reconcile against the new cash/check/etc entry created above,
|
||||||
|
// as well as the A/R account.
|
||||||
|
|
||||||
|
// Payment must debit the Receipt ledger, and credit the A/R ledger
|
||||||
|
// debit: Receipt credit: A/R
|
||||||
|
$ids = $this->postLedgerEntry
|
||||||
|
($split_transaction,
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $this->currentLedgerID($this->receiptAccountID()),
|
||||||
|
'credit_ledger_id' => $this->currentLedgerID($this->accountReceivableAccountID()),
|
||||||
|
'amount' => $rec['applied'],
|
||||||
|
'lease_id' => $rec['lease_id'],
|
||||||
|
'customer_id' => $rec['customer_id'],
|
||||||
|
),
|
||||||
|
array('debit' => array(array('LedgerEntry' => array('id' => $new_entry->id,
|
||||||
|
'amount' => $rec['applied']))),
|
||||||
|
'credit' => array(array('LedgerEntry' => array('id' => $rec['id'],
|
||||||
|
'amount' => $rec['applied']))))
|
||||||
|
);
|
||||||
|
// Keep using the same split transaction for all reconciled entries
|
||||||
|
$split_transaction = array_intersect_key($ids, array('transaction_id'=>1));
|
||||||
|
//pr(compact('ids', 'split_transaction'));
|
||||||
|
}
|
||||||
|
|
||||||
|
//pr("end reconciled is array");
|
||||||
|
}
|
||||||
|
|
||||||
|
//pr("end reconcile receipt");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($reconcile_set)) {
|
||||||
|
//pr("reconcile_set is array");
|
||||||
|
foreach ($reconcile_set AS $reconcile_entry) {
|
||||||
|
if (!isset($reconcile_entry['LedgerEntry']['id']))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$amount = $reconcile_entry['LedgerEntry']['amount'];
|
||||||
|
if (!$amount)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ($dc_type == 'debit') {
|
||||||
|
$debit_ledger_entry_id = $new_entry->id;
|
||||||
|
$credit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$debit_ledger_entry_id = $reconcile_entry['LedgerEntry']['id'];
|
||||||
|
$credit_ledger_entry_id = $new_entry->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$R = new Reconciliation();
|
||||||
|
$R->create();
|
||||||
|
if (!$R->save(compact('amount',
|
||||||
|
'debit_ledger_entry_id',
|
||||||
|
'credit_ledger_entry_id'), false))
|
||||||
|
$err = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_entry->recursive = -1;
|
||||||
|
$new_entry->read();
|
||||||
|
//pr(array('post-save', $entry->data));
|
||||||
|
|
||||||
|
$ret = array
|
||||||
|
('error' => $err,
|
||||||
|
'id' => $new_entry->data['LedgerEntry']['id'],
|
||||||
|
'transaction_id' => $new_entry->data['LedgerEntry']['transaction_id'],
|
||||||
|
'monetary_source_id' => $new_entry->data['LedgerEntry']['monetary_source_id']);
|
||||||
|
|
||||||
|
if (isset($split_transaction['transaction_id']))
|
||||||
|
$ret['split_transaction_id'] = $split_transaction['transaction_id'];
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: closeAndDeposit
|
||||||
|
* - Closes the current set of ledgers, transferring
|
||||||
|
* their balances to specified ledger.
|
||||||
|
*/
|
||||||
|
function closeAndDeposit($set, $deposit_account_id) {
|
||||||
|
|
||||||
|
$close = new Close();
|
||||||
|
$close->create();
|
||||||
|
if (!$close->save(array('stamp' => null, 'comment' => 'Deposit'), false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = array();
|
||||||
|
foreach ($set AS $ledger) {
|
||||||
|
// REVISIT <AP>: 20090710
|
||||||
|
// If the user said to include a ledger in the
|
||||||
|
// set, should we really be excluding it?
|
||||||
|
if ($ledger['total'] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$ids = $this->postLedgerEntry
|
||||||
|
($transaction,
|
||||||
|
null,
|
||||||
|
array('debit_account_id' => $deposit_account_id,
|
||||||
|
'credit_ledger_id' => $ledger['id'],
|
||||||
|
'amount' => $ledger['total']),
|
||||||
|
// Reconcile the account for cash/check/etc,
|
||||||
|
// which is the credit side of this entry.
|
||||||
|
array('credit' => $ledger['entries']));
|
||||||
|
//pr(compact('ids'));
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
die("closeAndDeposit : postLedgerEntry returned error!");
|
||||||
|
|
||||||
|
$transaction = array_intersect_key($ids, array('transaction_id'=>1));
|
||||||
|
|
||||||
|
$this->Ledger->closeLedger($ledger['id'], $close->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested account.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null, $all = false, $cond = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// All old, closed ledgers MUST balance to 0.
|
||||||
|
// However, the user may want the ENTIRE running totals,
|
||||||
|
// (not just the balance), so we may have to query all
|
||||||
|
// ledgers, as dictated by the $all parameter.
|
||||||
|
|
||||||
|
$account = $this->find('first',
|
||||||
|
array('contain' =>
|
||||||
|
($all
|
||||||
|
? array('Ledger' => array
|
||||||
|
('fields' => array('id')))
|
||||||
|
: array('CurrentLedger' => array
|
||||||
|
('fields' => array('id')))
|
||||||
|
),
|
||||||
|
'conditions' => array
|
||||||
|
(array('Account.id' => $id))
|
||||||
|
));
|
||||||
|
|
||||||
|
$stats = array();
|
||||||
|
if ($all) {
|
||||||
|
foreach ($account['Ledger'] AS $ledger)
|
||||||
|
$this->statsMerge($stats['Ledger'],
|
||||||
|
$this->Ledger->stats($ledger['id'], $cond));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$stats['Ledger'] =
|
||||||
|
$this->Ledger->stats($account['CurrentLedger']['id'], $cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
class Close extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'Ledger',
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
class Contact extends AppModel {
|
||||||
|
|
||||||
|
var $displayField = 'display_name';
|
||||||
|
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'display_name' => array('notempty'),
|
||||||
|
'id_federal' => array('ssn'),
|
||||||
|
'id_exp' => array('date')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod',
|
||||||
|
'ContactsCustomer',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasAndBelongsToMany = array(
|
||||||
|
'Customer',
|
||||||
|
'ContactAddress' => array(
|
||||||
|
'joinTable' => 'contacts_methods',
|
||||||
|
'associationForeignKey' => 'method_id',
|
||||||
|
'unique' => true,
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
),
|
||||||
|
'ContactPhone' => array(
|
||||||
|
'joinTable' => 'contacts_methods',
|
||||||
|
'associationForeignKey' => 'method_id',
|
||||||
|
'unique' => true,
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
),
|
||||||
|
'ContactEmail' => array(
|
||||||
|
'joinTable' => 'contacts_methods',
|
||||||
|
'associationForeignKey' => 'method_id',
|
||||||
|
'unique' => true,
|
||||||
|
'conditions' => "method = 'EMAIL'",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: saveContact
|
||||||
|
* - Saves the contact and related data
|
||||||
|
*/
|
||||||
|
|
||||||
|
function saveContact($id, $data) {
|
||||||
|
|
||||||
|
// Establish a display name if not already given
|
||||||
|
if (!$data['Contact']['display_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']));
|
||||||
|
|
||||||
|
// Save the contact data
|
||||||
|
$this->create();
|
||||||
|
if ($id)
|
||||||
|
$this->id = $id;
|
||||||
|
if (!$this->save($data, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$id = $this->id;
|
||||||
|
|
||||||
|
// Remove all associated ContactMethods, as it ensures
|
||||||
|
// any entries deleted by the user actually get deleted
|
||||||
|
// in the system. We'll recreate the needed ones anyway.
|
||||||
|
// REVISIT <AP>: 20090706
|
||||||
|
// Appears that $this->save() is already doing the
|
||||||
|
// delete. I would have thought this would only happen
|
||||||
|
// on a saveAll??
|
||||||
|
/* $this->ContactsMethod->deleteAll */
|
||||||
|
/* (array('contact_id' => $id), false); */
|
||||||
|
|
||||||
|
// At this point, since we've saved data to contact,
|
||||||
|
// we'll proceed forward as much as possible, even
|
||||||
|
// if we encounter an error. For now, we'll assume
|
||||||
|
// the operation will succeed.
|
||||||
|
$ret = true;
|
||||||
|
|
||||||
|
// Iterate each type of contact method, adding them into
|
||||||
|
// the database as needed and associating with this contact.
|
||||||
|
foreach (array('phone', 'address', 'email') AS $type) {
|
||||||
|
$class = 'Contact' . ucfirst($type);
|
||||||
|
$enum = strtoupper($type);
|
||||||
|
|
||||||
|
// Nothing to do if this contact method isn't used
|
||||||
|
if (!isset($data[$class]))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Go through each entry of this contact method
|
||||||
|
foreach ($data[$class] AS &$item) {
|
||||||
|
|
||||||
|
// If the user has entered all new data, we need to
|
||||||
|
// save that as a brand new entry.
|
||||||
|
if (!isset($item['id'])) {
|
||||||
|
$I = new $class();
|
||||||
|
$I->create();
|
||||||
|
if (!$I->save($item, false)) {
|
||||||
|
$ret = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$item['id'] = $I->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the ContactsMethod to reflect the appropriate IDs
|
||||||
|
$item['ContactsMethod']['contact_id'] = $id;
|
||||||
|
$item['ContactsMethod']['method_id'] = $item['id'];
|
||||||
|
$item['ContactsMethod']['method'] = $enum;
|
||||||
|
|
||||||
|
// Save the relationship between contact and phone/email/address
|
||||||
|
$CM = new ContactsMethod();
|
||||||
|
if (!$CM->save($item['ContactsMethod'], false)) {
|
||||||
|
$ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function contactList() {
|
||||||
|
return $this->find('list',
|
||||||
|
array('order' =>
|
||||||
|
//array('last_name', 'first_name', 'middle_name'),
|
||||||
|
array('display_name'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
class ContactAddress extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'ContactAddress';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'postcode' => array('postal')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasAndBelongsToMany = array(
|
||||||
|
'Contact' => array(
|
||||||
|
'className' => 'Contact',
|
||||||
|
'joinTable' => 'contacts_methods',
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'associationForeignKey' => 'contact_id',
|
||||||
|
'unique' => true,
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
function addressList() {
|
||||||
|
$results = $this->find('all',
|
||||||
|
array('contain' => false,
|
||||||
|
'fields' => array('id', 'address', 'city', 'state', 'postcode'),
|
||||||
|
'order' => array('state', 'city', 'postcode', 'address')));
|
||||||
|
|
||||||
|
$list = array();
|
||||||
|
foreach ($results as $key => $val) {
|
||||||
|
$list[$val['ContactAddress']['id']]
|
||||||
|
= preg_replace("/\n/", ", ", $val['ContactAddress']['address'])
|
||||||
|
. ', ' . $val['ContactAddress']['city']
|
||||||
|
. ', ' . $val['ContactAddress']['state']
|
||||||
|
. ' ' . $val['ContactAddress']['postcode']
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
class ContactEmail extends AppModel {
|
class ContactEmail extends AppModel {
|
||||||
|
|
||||||
var $name = 'ContactEmail';
|
var $name = 'ContactEmail';
|
||||||
|
var $displayField = 'email';
|
||||||
var $validate = array(
|
var $validate = array(
|
||||||
'id' => array('numeric'),
|
'id' => array('numeric'),
|
||||||
'email' => array('email')
|
'email' => array('email')
|
||||||
@@ -18,5 +19,9 @@ class ContactEmail extends AppModel {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function emailList() {
|
||||||
|
return $this->find('list');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
class ContactPhone extends AppModel {
|
||||||
|
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
//'type' => array('inlist'),
|
||||||
|
'phone' => array('phone'),
|
||||||
|
'ext' => array('numeric')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'ContactsMethod' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasAndBelongsToMany = array(
|
||||||
|
'Contact' => array(
|
||||||
|
'className' => 'Contact',
|
||||||
|
'joinTable' => 'contacts_methods',
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'associationForeignKey' => 'contact_id',
|
||||||
|
'unique' => true,
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
function phoneList() {
|
||||||
|
$results = $this->find('all',
|
||||||
|
array('contain' => false,
|
||||||
|
'fields' => array('id', 'phone', 'ext'),
|
||||||
|
'order' => array('phone', 'ext')));
|
||||||
|
|
||||||
|
App::Import('Helper', 'Format');
|
||||||
|
$list = array();
|
||||||
|
foreach ($results as $key => $val) {
|
||||||
|
$list[$val['ContactPhone']['id']]
|
||||||
|
= FormatHelper::phone($val['ContactPhone']['phone'],
|
||||||
|
$val['ContactPhone']['ext']);
|
||||||
|
}
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
class ContactsCustomer extends AppModel {
|
||||||
|
var $primaryKey = false;
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'Contact',
|
||||||
|
'Customer',
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
class ContactsMethod extends AppModel {
|
||||||
|
var $primaryKey = false;
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'Contact',
|
||||||
|
'ContactAddress' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'ADDRESS'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
'ContactPhone' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'PHONE'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
'ContactEmail' => array(
|
||||||
|
'foreignKey' => 'method_id',
|
||||||
|
'conditions' => "method = 'EMAIL'",
|
||||||
|
//'unique' => true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -20,9 +20,7 @@ class Customer extends AppModel {
|
|||||||
),
|
),
|
||||||
'Lease',
|
'Lease',
|
||||||
'LedgerEntry',
|
'LedgerEntry',
|
||||||
|
'ContactsCustomer',
|
||||||
// Cheat to get Account set as part of this class
|
|
||||||
'Account',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasAndBelongsToMany = array(
|
var $hasAndBelongsToMany = array(
|
||||||
@@ -86,9 +84,9 @@ class Customer extends AppModel {
|
|||||||
/* 'args' => compact('id', 'link'), */
|
/* 'args' => compact('id', 'link'), */
|
||||||
/* )); */
|
/* )); */
|
||||||
|
|
||||||
$entries = $this->Account->findLedgerEntriesRelatedToAccount
|
$A = new Account();
|
||||||
($this->Account->invoiceAccountID(),
|
$entries = $A->findLedgerEntries
|
||||||
$this->Account->securityDepositAccountID(),
|
($A->securityDepositAccountID(),
|
||||||
true, array('LedgerEntry.customer_id' => $id), $link);
|
true, array('LedgerEntry.customer_id' => $id), $link);
|
||||||
|
|
||||||
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
/* pr(array('function' => 'Customer::findSecurityDeposits', */
|
||||||
@@ -110,8 +108,9 @@ class Customer extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||||
$unreconciled = $this->Account->findUnreconciledLedgerEntries
|
$A = new Account();
|
||||||
($this->Account->accountReceivableAccountID(),
|
$unreconciled = $A->findUnreconciledLedgerEntries
|
||||||
|
($A->accountReceivableAccountID(),
|
||||||
$fundamental_type,
|
$fundamental_type,
|
||||||
array('LedgerEntry.customer_id' => $id));
|
array('LedgerEntry.customer_id' => $id));
|
||||||
|
|
||||||
@@ -134,8 +133,9 @@ class Customer extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
||||||
$reconciled = $this->Account->reconcileNewLedgerEntry
|
$A = new Account();
|
||||||
($this->Account->accountReceivableAccountID(),
|
$reconciled = $A->reconcileNewLedgerEntry
|
||||||
|
($A->accountReceivableAccountID(),
|
||||||
$fundamental_type,
|
$fundamental_type,
|
||||||
$amount,
|
$amount,
|
||||||
array('LedgerEntry.customer_id' => $id));
|
array('LedgerEntry.customer_id' => $id));
|
||||||
@@ -158,7 +158,8 @@ class Customer extends AppModel {
|
|||||||
('contain' => array
|
('contain' => array
|
||||||
(// Models
|
(// Models
|
||||||
'Contact' =>
|
'Contact' =>
|
||||||
array(// Models
|
array('order' => array('Contact.display_name'),
|
||||||
|
// Models
|
||||||
'ContactPhone',
|
'ContactPhone',
|
||||||
'ContactEmail',
|
'ContactEmail',
|
||||||
'ContactAddress',
|
'ContactAddress',
|
||||||
@@ -184,6 +185,82 @@ class Customer extends AppModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: saveCustomer
|
||||||
|
* - Saves the customer and related data
|
||||||
|
*/
|
||||||
|
|
||||||
|
function saveCustomer($id, $data, $primary_contact_entry) {
|
||||||
|
|
||||||
|
// Go through each contact, and create new ones as needed
|
||||||
|
foreach ($data['Contact'] AS &$contact) {
|
||||||
|
if (isset($contact['id']))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$I = new Contact();
|
||||||
|
$I->create();
|
||||||
|
if (!$I->save($contact, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$contact['id'] = $I->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the primary contact ID based on caller selection
|
||||||
|
$data['Customer']['primary_contact_id']
|
||||||
|
= $data['Contact'][$primary_contact_entry]['id'];
|
||||||
|
|
||||||
|
// Provide a default customer name if not specified
|
||||||
|
if (!$data['Customer']['name']) {
|
||||||
|
$this->Contact->recursive = -1;
|
||||||
|
$pcontact = $this->Contact->read(null, $data['Customer']['primary_contact_id']);
|
||||||
|
$data['Customer']['name'] = $pcontact['Contact']['display_name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the customer data
|
||||||
|
$this->create();
|
||||||
|
if ($id)
|
||||||
|
$this->id = $id;
|
||||||
|
if (!$this->save($data, false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$id = $this->id;
|
||||||
|
|
||||||
|
// Remove all associated Customer Contacts, as it ensures
|
||||||
|
// any entries deleted by the user actually get deleted
|
||||||
|
// in the system. We'll recreate the needed ones anyway.
|
||||||
|
// REVISIT <AP>: 20090706
|
||||||
|
// Appears that $this->save() is already doing the
|
||||||
|
// delete. I would have thought this would only happen
|
||||||
|
// on a saveAll??
|
||||||
|
/* $this->ContactsCustomer->deleteAll */
|
||||||
|
/* (array('customer_id' => $id), false); */
|
||||||
|
|
||||||
|
// At this point, since we've saved data to customer,
|
||||||
|
// we'll proceed forward as much as possible, even
|
||||||
|
// if we encounter an error. For now, we'll assume
|
||||||
|
// the operation will succeed.
|
||||||
|
$ret = true;
|
||||||
|
|
||||||
|
// Go through each entry of this customer method
|
||||||
|
foreach ($data['Contact'] AS &$contact) {
|
||||||
|
// Update the ContactsCustomer to reflect the appropriate IDs
|
||||||
|
$contact['ContactsCustomer']['customer_id'] = $id;
|
||||||
|
$contact['ContactsCustomer']['contact_id'] = $contact['id'];
|
||||||
|
|
||||||
|
// Save the relationship between customer and contact
|
||||||
|
$CM = new ContactsCustomer();
|
||||||
|
if (!$CM->save($contact['ContactsCustomer'], false)) {
|
||||||
|
$ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the result
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -195,8 +272,9 @@ class Customer extends AppModel {
|
|||||||
if (!$id)
|
if (!$id)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
$stats = $this->Account->stats($this->Account->accountReceivableAccountID(), true,
|
$A = new Account();
|
||||||
array('LedgerEntry.customer_id' => $id));
|
$stats = $A->stats($A->accountReceivableAccountID(), true,
|
||||||
|
array('LedgerEntry.customer_id' => $id));
|
||||||
|
|
||||||
// Pull to the top level and return
|
// Pull to the top level and return
|
||||||
$stats = $stats['Ledger'];
|
$stats = $stats['Ledger'];
|
||||||
@@ -0,0 +1,506 @@
|
|||||||
|
<?php
|
||||||
|
class Lease extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'Lease';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'number' => array('alphanumeric'),
|
||||||
|
'lease_type_id' => array('numeric'),
|
||||||
|
'unit_id' => array('numeric'),
|
||||||
|
'late_schedule_id' => array('numeric'),
|
||||||
|
'lease_date' => array('date'),
|
||||||
|
'movein_planned_date' => array('date'),
|
||||||
|
'movein_date' => array('date'),
|
||||||
|
'moveout_date' => array('date'),
|
||||||
|
'moveout_planned_date' => array('date'),
|
||||||
|
'notice_given_date' => array('date'),
|
||||||
|
'notice_received_date' => array('date'),
|
||||||
|
'close_date' => array('date'),
|
||||||
|
'deposit' => array('money'),
|
||||||
|
'rent' => array('money'),
|
||||||
|
'next_rent' => array('money'),
|
||||||
|
'next_rent_date' => array('date')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'LeaseType',
|
||||||
|
'Unit',
|
||||||
|
'Customer',
|
||||||
|
'LateSchedule',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'LedgerEntry',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: accountId
|
||||||
|
* - Returns the accountId of the given lease
|
||||||
|
*/
|
||||||
|
function accountId($id) {
|
||||||
|
$A = new Account();
|
||||||
|
return $A->invoiceAccountID();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findAccountEntries
|
||||||
|
* - Returns an array of ledger entries from the account of the given
|
||||||
|
* lease.
|
||||||
|
*/
|
||||||
|
function findAccountEntries($id, $all = false, $cond = null, $link = null) {
|
||||||
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
if (!isset($cond))
|
||||||
|
$cond = array();
|
||||||
|
$cond[] = array('LedgerEntry.lease_id' => $id);
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
$entries = $A->findLedgerEntries($this->accountId($id),
|
||||||
|
$all, $cond, $link);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Lease::findAccountEntries', */
|
||||||
|
/* 'args' => compact('id', 'all', 'cond', 'link'), */
|
||||||
|
/* 'vars' => compact('lease'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findSecurityDeposits
|
||||||
|
* - Returns an array of security deposit entries
|
||||||
|
*/
|
||||||
|
function findSecurityDeposits($id, $link = null) {
|
||||||
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
||||||
|
/* 'args' => compact('id', 'link'), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
$entries = $A->findLedgerEntries
|
||||||
|
($A->securityDepositAccountID(),
|
||||||
|
true, array('LedgerEntry.lease_id' => $id), $link);
|
||||||
|
|
||||||
|
/* pr(array('function' => 'Lease::findSecurityDeposits', */
|
||||||
|
/* 'args' => compact('id', 'link'), */
|
||||||
|
/* 'vars' => compact('lease'), */
|
||||||
|
/* 'return' => compact('entries'), */
|
||||||
|
/* )); */
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findUnreconciledLedgerEntries
|
||||||
|
* - Returns ledger entries that are not yet reconciled
|
||||||
|
* (such as charges not paid).
|
||||||
|
*/
|
||||||
|
|
||||||
|
function findUnreconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||||
|
$A = new Account();
|
||||||
|
return $A->findUnreconciledLedgerEntries
|
||||||
|
($this->accountId($id), $fundamental_type, array('LedgerEntry.lease_id' => $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: reconcileNewLedgerEntry
|
||||||
|
* - Returns which ledger entries a new credit/debit would
|
||||||
|
* reconcile, and how much.
|
||||||
|
*
|
||||||
|
* - REVISIT <AP> 20090617
|
||||||
|
* This should be subject to different algorithms, such
|
||||||
|
* as apply to oldest charges first, newest first, to fees
|
||||||
|
* before rent, etc. Until we get there, I'll hardcode
|
||||||
|
* whatever algorithm is simplest.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
||||||
|
$A = new Account();
|
||||||
|
return $A->reconcileNewLedgerEntry
|
||||||
|
($this->accountId($id), $fundamental_type, $amount, array('LedgerEntry.lease_id' => $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentLastCharges
|
||||||
|
* - Returns a list of rent charges from this lease that
|
||||||
|
* do not have sequential followup charges. Under normal
|
||||||
|
* circumstances, there would only be one entry, which is
|
||||||
|
* the most recent rent charge. However, it's possible
|
||||||
|
* that there are several, indicating a problem with lease.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentLastCharges($id) {
|
||||||
|
$A = new Account();
|
||||||
|
$entries = $this->find
|
||||||
|
('all',
|
||||||
|
array('link' =>
|
||||||
|
array(// Models
|
||||||
|
'LedgerEntry' => array
|
||||||
|
('Ledger' => array
|
||||||
|
('fields' => array(),
|
||||||
|
'Account' => array
|
||||||
|
('fields' => array(),
|
||||||
|
'Ledger' => array
|
||||||
|
('alias' => 'Lx',
|
||||||
|
'fields' => array(),
|
||||||
|
'LedgerEntry' => array
|
||||||
|
('alias' => 'LEx',
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array
|
||||||
|
('LEx.effective_date = DATE_ADD(LedgerEntry.through_date, INTERVAL 1 day)',
|
||||||
|
'LEx.lease_id = LedgerEntry.lease_id',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
),
|
||||||
|
//'fields' => array('id', 'amount', 'effective_date', 'through_date'),
|
||||||
|
'fields' => array(),
|
||||||
|
'conditions' => array(array('Lease.id' => $id),
|
||||||
|
array('Account.id' => $A->rentAccountID()),
|
||||||
|
array('LEx.id' => null),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentChargeGaps
|
||||||
|
* - Checks for gaps in rent charges
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentChargeGaps($id) {
|
||||||
|
$entries = $this->rentLastCharges($id);
|
||||||
|
if ($entries && count($entries) > 1)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentChargeThrough
|
||||||
|
* - Determines the date that rent has been charged through
|
||||||
|
* Returns one of:
|
||||||
|
* null: There are gaps in the charges
|
||||||
|
* false: There are not yet any charges
|
||||||
|
* date: The date rent has been charged through
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentChargeThrough($id) {
|
||||||
|
$entries = $this->rentLastCharges($id);
|
||||||
|
if (!$entries)
|
||||||
|
return false;
|
||||||
|
if (count($entries) != 1)
|
||||||
|
return null;
|
||||||
|
return $entries[0]['LedgerEntry']['through_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: rentPaidThrough
|
||||||
|
* - Determines the date of the first unpaid rent
|
||||||
|
*/
|
||||||
|
|
||||||
|
function rentPaidThrough($id) {
|
||||||
|
|
||||||
|
// Income / Receipt / Money
|
||||||
|
// debit: A/R credit: Income <-- this entry
|
||||||
|
// debit: Receipt credit: A/R <-- ReceiptLedgerEntry, below
|
||||||
|
// debit: Money credit: Receipt <-- MoneyLedgerEntry, below
|
||||||
|
|
||||||
|
$query = array
|
||||||
|
('link' => array
|
||||||
|
(
|
||||||
|
'CreditLedger' =>
|
||||||
|
array('fields' => array(),
|
||||||
|
'Account' =>
|
||||||
|
array('fields' => array(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// We're searching for the Receipt<->A/R entries,
|
||||||
|
// which are debits on the A/R account. Find the
|
||||||
|
// reconciling entries to that A/R debit.
|
||||||
|
'DebitReconciliationLedgerEntry' =>
|
||||||
|
array('alias' => 'ReceiptLedgerEntry',
|
||||||
|
'fields' => array(),
|
||||||
|
|
||||||
|
// Finally, the Money (Cash/Check/etc) Entry is the one
|
||||||
|
// which reconciles our ReceiptLedgerEntry debit
|
||||||
|
'DebitReconciliationLedgerEntry' =>
|
||||||
|
array('alias' => 'MoneyLedgerEntry',
|
||||||
|
'linkalias' => 'MoneyLedgerEntryR',
|
||||||
|
'fields' => array('SUM(COALESCE(MoneyLedgerEntryR.amount,0)) AS paid'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'fields' => array('LedgerEntry.amount',
|
||||||
|
'DATE_SUB(LedgerEntry.effective_date, INTERVAL 1 DAY) AS paid_through',
|
||||||
|
),
|
||||||
|
|
||||||
|
'group' => 'LedgerEntry.id HAVING paid <> LedgerEntry.amount',
|
||||||
|
|
||||||
|
'conditions' => array(array('LedgerEntry.lease_id' => $id),
|
||||||
|
array('Account.id' => $this->LedgerEntry->Ledger->Account->rentAccountID()),
|
||||||
|
),
|
||||||
|
'order' => array('LedgerEntry.effective_date',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$rent = $this->LedgerEntry->find('first', $query);
|
||||||
|
if ($rent)
|
||||||
|
return $rent[0]['paid_through'];
|
||||||
|
|
||||||
|
$query['fields'] = 'LedgerEntry.through_date';
|
||||||
|
$query['order'] = 'LedgerEntry.through_date DESC';
|
||||||
|
$query['group'] = 'LedgerEntry.id';
|
||||||
|
$rent = $this->LedgerEntry->find('first', $query);
|
||||||
|
if ($rent)
|
||||||
|
return $rent['LedgerEntry']['through_date'];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: moveIn
|
||||||
|
* - Moves the specified customer into the specified lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function moveIn($customer_id, $unit_id,
|
||||||
|
$deposit = null, $rent = null,
|
||||||
|
$stamp = null, $comment = null) {
|
||||||
|
|
||||||
|
$lt = $this->LeaseType->find('first',
|
||||||
|
array('conditions' =>
|
||||||
|
array('code' => 'SL')));
|
||||||
|
|
||||||
|
// Use NOW if not given a movein date
|
||||||
|
if (!isset($stamp))
|
||||||
|
$stamp = date('Y-m-d G:i:s');
|
||||||
|
|
||||||
|
if (!$comment)
|
||||||
|
$comment = null;
|
||||||
|
|
||||||
|
if (!isset($deposit) || !isset($rent)) {
|
||||||
|
$rates = $this->Unit->find
|
||||||
|
('first',
|
||||||
|
array('contain' =>
|
||||||
|
array('UnitSize' =>
|
||||||
|
array('deposit', 'rent'),
|
||||||
|
),
|
||||||
|
'fields' => array('deposit', 'rent'),
|
||||||
|
'conditions' => array('Unit.id' => $unit_id),
|
||||||
|
));
|
||||||
|
|
||||||
|
$deposit =
|
||||||
|
(isset($deposit)
|
||||||
|
? $deposit
|
||||||
|
: (isset($rates['Unit']['deposit'])
|
||||||
|
? $rates['Unit']['deposit']
|
||||||
|
: (isset($rates['UnitSize']['deposit'])
|
||||||
|
? $rates['UnitSize']['deposit']
|
||||||
|
: 0)));
|
||||||
|
|
||||||
|
$rent =
|
||||||
|
(isset($rent)
|
||||||
|
? $rent
|
||||||
|
: (isset($rates['Unit']['rent'])
|
||||||
|
? $rates['Unit']['rent']
|
||||||
|
: (isset($rates['UnitSize']['rent'])
|
||||||
|
? $rates['UnitSize']['rent']
|
||||||
|
: 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Save this new lease.
|
||||||
|
$this->create();
|
||||||
|
if (!$this->save(array('lease_type_id' => $lt['LeaseType']['id'],
|
||||||
|
'unit_id' => $unit_id,
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'lease_date' => $stamp,
|
||||||
|
'movein_date' => $stamp,
|
||||||
|
'deposit' => $deposit,
|
||||||
|
'rent' => $rent,
|
||||||
|
'comment' => $comment), false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the lease number to be the same as the lease ID
|
||||||
|
$this->id;
|
||||||
|
$this->saveField('number', $this->id);
|
||||||
|
|
||||||
|
// Update the unit status
|
||||||
|
$this->Unit->updateStatus($unit_id, 'OCCUPIED');
|
||||||
|
|
||||||
|
// REVISIT <AP>: 20090702
|
||||||
|
// We need to assess the security deposit charge,
|
||||||
|
// and probably rent as well. Rent, however, will
|
||||||
|
// require user parameters to indicate whether it
|
||||||
|
// was waived, pro-rated, etc.
|
||||||
|
|
||||||
|
// Return the new lease ID
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: moveOut
|
||||||
|
* - Moves the customer out of the specified lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function moveOut($id, $status = 'VACANT',
|
||||||
|
$stamp = null, $close = false) {
|
||||||
|
// Use NOW if not given a moveout date
|
||||||
|
if (!isset($stamp))
|
||||||
|
$stamp = date('Y-m-d G:i:s');
|
||||||
|
|
||||||
|
// Reset the data
|
||||||
|
$this->create();
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
|
// Set the customer move-out date
|
||||||
|
$this->data['Lease']['moveout_date'] = $stamp;
|
||||||
|
|
||||||
|
// Save it!
|
||||||
|
$this->save($this->data, false);
|
||||||
|
|
||||||
|
// Close the lease, if so requested
|
||||||
|
if ($close)
|
||||||
|
$this->close($id, $stamp);
|
||||||
|
|
||||||
|
// Finally, update the unit status
|
||||||
|
$this->recursive = -1;
|
||||||
|
$this->read();
|
||||||
|
$this->Unit->updateStatus($this->data['Lease']['unit_id'], $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: close
|
||||||
|
* - Closes the lease to further action
|
||||||
|
*/
|
||||||
|
|
||||||
|
function close($id, $stamp = null) {
|
||||||
|
if (!$this->closeable($id))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Reset the data
|
||||||
|
$this->create();
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
|
// Use NOW if not given a moveout date
|
||||||
|
if (!isset($stamp))
|
||||||
|
$stamp = date('Y-m-d G:i:s');
|
||||||
|
|
||||||
|
// Set the close date
|
||||||
|
$this->data['Lease']['close_date'] = $stamp;
|
||||||
|
|
||||||
|
// Save it!
|
||||||
|
$this->save($this->data, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: closeable
|
||||||
|
* - Indicates whether or not the lease can be closed
|
||||||
|
*/
|
||||||
|
|
||||||
|
function closeable($id) {
|
||||||
|
$this->recursive = -1;
|
||||||
|
$this->read(null, $id);
|
||||||
|
|
||||||
|
// We can't close a lease that's still in use
|
||||||
|
if (!isset($this->data['Lease']['moveout_date']))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// We can't close a lease that's already closed
|
||||||
|
if (isset($this->data['Lease']['close_date']))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$deposits = $this->findSecurityDeposits($id);
|
||||||
|
$stats = $this->stats($id);
|
||||||
|
|
||||||
|
// A lease can only be closed if there are no outstanding
|
||||||
|
// security deposits, and if the account balance is zero.
|
||||||
|
if ($deposits['summary']['balance'] != 0 || $stats['balance'] != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Apparently this lease meets all the criteria!
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: addCharge
|
||||||
|
* - Adds an additional charge to the lease
|
||||||
|
*/
|
||||||
|
|
||||||
|
function addCharge($id, $charge) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested lease.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
$stats = $A->stats($A->accountReceivableAccountID(), true,
|
||||||
|
array('LedgerEntry.lease_id' => $id));
|
||||||
|
|
||||||
|
// Pull to the top level and return
|
||||||
|
$stats = $stats['Ledger'];
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -9,6 +9,8 @@ class Ledger extends AppModel {
|
|||||||
|
|
||||||
var $belongsTo = array(
|
var $belongsTo = array(
|
||||||
'Account',
|
'Account',
|
||||||
|
'PriorLedger' => array('className' => 'Ledger'),
|
||||||
|
'Close',
|
||||||
);
|
);
|
||||||
|
|
||||||
var $hasMany = array(
|
var $hasMany = array(
|
||||||
@@ -44,6 +46,94 @@ class Ledger extends AppModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: accountID
|
||||||
|
* - Returns the account ID for the given ledger
|
||||||
|
*/
|
||||||
|
function accountID($id) {
|
||||||
|
$this->cacheQueries = true;
|
||||||
|
$item = $this->find('first', array
|
||||||
|
('contain' => 'Account.id',
|
||||||
|
'conditions' => array('Ledger.id' => $id),
|
||||||
|
));
|
||||||
|
$this->cacheQueries = false;
|
||||||
|
return $item['Account']['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: currentLedgerID
|
||||||
|
* - Returns the current ledger ID of the account for the given ledger.
|
||||||
|
*/
|
||||||
|
function currentLedgerID($id) {
|
||||||
|
return $this->Account->currentLedgerID($this->accountID($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: closeLedger
|
||||||
|
* - Closes the current ledger, and returns a fresh one
|
||||||
|
*/
|
||||||
|
function closeLedger($id, $close_id) {
|
||||||
|
$this->recursive = -1;
|
||||||
|
|
||||||
|
$stamp = date('Y-m-d G:i:s');
|
||||||
|
$this->id = $id;
|
||||||
|
$this->read();
|
||||||
|
$this->data['Ledger']['close_id'] = $close_id;
|
||||||
|
$this->save($this->data, false);
|
||||||
|
|
||||||
|
$stats = $this->stats($id);
|
||||||
|
|
||||||
|
$this->read();
|
||||||
|
$this->data['Ledger']['id'] = null;
|
||||||
|
$this->data['Ledger']['close_id'] = null;
|
||||||
|
$this->data['Ledger']['prior_ledger_id'] = $id;
|
||||||
|
$this->data['Ledger']['comment'] = null;
|
||||||
|
++$this->data['Ledger']['sequence'];
|
||||||
|
$this->id = null;
|
||||||
|
$this->save($this->data, false);
|
||||||
|
//pr($this->data);
|
||||||
|
|
||||||
|
if ($stats['balance'] == 0)
|
||||||
|
return $this->id;
|
||||||
|
|
||||||
|
$this->read();
|
||||||
|
$ftype = $this->Account->fundamentalType($this->data['Ledger']['account_id']);
|
||||||
|
$otype = $this->Account->fundamentalOpposite($ftype);
|
||||||
|
|
||||||
|
// Create a transaction for balance transfer
|
||||||
|
$transaction = new Transaction();
|
||||||
|
$transaction->create();
|
||||||
|
if (!$transaction->save(array(), false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an entry to carry the balance forward
|
||||||
|
$carry_entry_data = array
|
||||||
|
($ftype.'_ledger_id' => $this->id,
|
||||||
|
$otype.'_ledger_id' => $id,
|
||||||
|
'transaction_id' => $transaction->id,
|
||||||
|
'amount' => $stats['balance'],
|
||||||
|
'comment' => "Ledger Balance Forward",
|
||||||
|
);
|
||||||
|
|
||||||
|
$carry_entry = new LedgerEntry();
|
||||||
|
$carry_entry->create();
|
||||||
|
if (!$carry_entry->save($carry_entry_data, false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
@@ -147,7 +237,13 @@ class Ledger extends AppModel {
|
|||||||
|
|
||||||
// The fields are all tucked into the [0] index,
|
// The fields are all tucked into the [0] index,
|
||||||
// and the rest of the array is useless (empty).
|
// and the rest of the array is useless (empty).
|
||||||
return $stats[0];
|
$stats = $stats[0];
|
||||||
|
|
||||||
|
// Make sure we have a non-null balance
|
||||||
|
if (!isset($stats['balance']))
|
||||||
|
$stats['balance'] = 0;
|
||||||
|
|
||||||
|
return $stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,525 @@
|
|||||||
|
<?php
|
||||||
|
class LedgerEntry extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'LedgerEntry';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'transaction_id' => array('numeric'),
|
||||||
|
'amount' => array('money')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'DebitReconciliation' => array(
|
||||||
|
'className' => 'Reconciliation',
|
||||||
|
'foreignKey' => 'debit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
'CreditReconciliation' => array(
|
||||||
|
'className' => 'Reconciliation',
|
||||||
|
'foreignKey' => 'credit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
var $belongsTo = array(
|
||||||
|
'MonetarySource',
|
||||||
|
'Transaction',
|
||||||
|
'Customer',
|
||||||
|
'Lease',
|
||||||
|
|
||||||
|
'DebitLedger' => array(
|
||||||
|
'className' => 'Ledger',
|
||||||
|
'foreignKey' => 'debit_ledger_id',
|
||||||
|
),
|
||||||
|
'CreditLedger' => array(
|
||||||
|
'className' => 'Ledger',
|
||||||
|
'foreignKey' => 'credit_ledger_id',
|
||||||
|
),
|
||||||
|
|
||||||
|
'Ledger' => array(
|
||||||
|
'foreignKey' => false,
|
||||||
|
// conditions will be used when JOINing tables
|
||||||
|
// (such as find with LinkableBehavior)
|
||||||
|
'conditions' => array('OR' =>
|
||||||
|
array('%{MODEL_ALIAS}.debit_ledger_id = Ledger.id',
|
||||||
|
'%{MODEL_ALIAS}.credit_ledger_id = Ledger.id')),
|
||||||
|
|
||||||
|
// finderQuery will be used when tables are put
|
||||||
|
// together across several querys, not with JOIN.
|
||||||
|
// (such as find with ContainableBehavior)
|
||||||
|
'finderQuery' => 'NOT-IMPLEMENTED',
|
||||||
|
|
||||||
|
'counterQuery' => ''
|
||||||
|
),
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasAndBelongsToMany = array(
|
||||||
|
'DebitReconciliationLedgerEntry' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
'joinTable' => 'reconciliations',
|
||||||
|
'foreignKey' => 'credit_ledger_entry_id',
|
||||||
|
'associationForeignKey' => 'debit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
// STUPID CakePHP bug screws up when using Containable
|
||||||
|
// and CLASS contains CLASS. This extra HABTM give the
|
||||||
|
// option of multiple depths on one CLASS, since there
|
||||||
|
// isn't an alias specification for Containable.
|
||||||
|
'DebitReconciliationLedgerEntry2' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
'joinTable' => 'reconciliations',
|
||||||
|
'foreignKey' => 'credit_ledger_entry_id',
|
||||||
|
'associationForeignKey' => 'debit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
'CreditReconciliationLedgerEntry' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
'joinTable' => 'reconciliations',
|
||||||
|
'foreignKey' => 'debit_ledger_entry_id',
|
||||||
|
'associationForeignKey' => 'credit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: conditionEntryAsCreditOrDebit
|
||||||
|
* - returns the condition necessary to match a set of
|
||||||
|
* Ledgers to all related LedgerEntries
|
||||||
|
*/
|
||||||
|
function conditionEntryAsCreditOrDebit($ledger_ids) {
|
||||||
|
return array('OR' =>
|
||||||
|
array(array('debit_ledger_id' => $ledger_ids),
|
||||||
|
array('credit_ledger_id' => $ledger_ids)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: ledgerContext query helpers
|
||||||
|
* - Returns parameters necessary to generate a query which
|
||||||
|
* puts ledger entries into the context of a ledger. Since
|
||||||
|
* debit/credit depends on the account type, it is required
|
||||||
|
* as an argument for each function to avoid having to
|
||||||
|
* query the ledger/account to find it out.
|
||||||
|
*/
|
||||||
|
function ledgerContextFields($ledger_id = null, $account_type = null) {
|
||||||
|
$fields = array('id', 'effective_date', 'through_date',
|
||||||
|
'lease_id', 'customer_id', 'comment', 'amount');
|
||||||
|
|
||||||
|
if (isset($ledger_id)) {
|
||||||
|
$fields[] = ("IF(LedgerEntry.debit_ledger_id = $ledger_id," .
|
||||||
|
" LedgerEntry.amount, NULL) AS debit");
|
||||||
|
$fields[] = ("IF(LedgerEntry.credit_ledger_id = $ledger_id," .
|
||||||
|
" LedgerEntry.amount, NULL) AS credit");
|
||||||
|
|
||||||
|
if (isset($account_type)) {
|
||||||
|
if (in_array($account_type, array('ASSET', 'EXPENSE')))
|
||||||
|
$ledger_type = 'debit';
|
||||||
|
else
|
||||||
|
$ledger_type = 'credit';
|
||||||
|
|
||||||
|
$fields[] = ("(IF(LedgerEntry.{$ledger_type}_ledger_id = $ledger_id," .
|
||||||
|
" 1, -1) * LedgerEntry.amount) AS balance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ledgerContextFields2($ledger_id = null, $account_id = null, $account_type = null) {
|
||||||
|
$fields = array('id', 'effective_date', 'through_date', 'comment', 'amount');
|
||||||
|
|
||||||
|
if (isset($ledger_id)) {
|
||||||
|
$fields[] = ("IF(LedgerEntry.debit_ledger_id = $ledger_id," .
|
||||||
|
" SUM(LedgerEntry.amount), NULL) AS debit");
|
||||||
|
$fields[] = ("IF(LedgerEntry.credit_ledger_id = $ledger_id," .
|
||||||
|
" SUM(LedgerEntry.amount), NULL) AS credit");
|
||||||
|
|
||||||
|
if (isset($account_id) || isset($account_type)) {
|
||||||
|
$Account = new Account();
|
||||||
|
$account_ftype = $Account->fundamentalType($account_id ? $account_id : $account_type);
|
||||||
|
$fields[] = ("(IF(LedgerEntry.{$account_ftype}_ledger_id = $ledger_id," .
|
||||||
|
" 1, -1) * SUM(LedgerEntry.amount)) AS balance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (isset($account_id)) {
|
||||||
|
$fields[] = ("IF(DebitLedger.account_id = $account_id," .
|
||||||
|
" SUM(LedgerEntry.amount), NULL) AS debit");
|
||||||
|
$fields[] = ("IF(CreditLedger.account_id = $account_id," .
|
||||||
|
" SUM(LedgerEntry.amount), NULL) AS credit");
|
||||||
|
|
||||||
|
$Account = new Account();
|
||||||
|
$account_ftype = ucfirst($Account->fundamentalType($account_id));
|
||||||
|
$fields[] = ("(IF({$account_ftype}Ledger.account_id = $account_id," .
|
||||||
|
" 1, -1) * SUM(LedgerEntry.amount)) AS balance");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function ledgerContextConditions($ledger_id, $account_type) {
|
||||||
|
if (isset($ledger_id)) {
|
||||||
|
return array
|
||||||
|
('OR' =>
|
||||||
|
array(array('LedgerEntry.debit_ledger_id' => $ledger_id),
|
||||||
|
array('LedgerEntry.credit_ledger_id' => $ledger_id)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findInLedgerContext
|
||||||
|
* - Returns an array of ledger entries that belong to a given ledger.
|
||||||
|
* There is extra logic to also figure out whether the ledger_entry
|
||||||
|
* amount is either a credit, or a debit, depending on how it was
|
||||||
|
* written into the ledger, as well as whether the amount increases or
|
||||||
|
* decreases the balance depending on the particular account type of
|
||||||
|
* the ledger.
|
||||||
|
*/
|
||||||
|
function findInLedgerContext($ledger_id, $account_type, $cond = null, $link = null) {
|
||||||
|
if (!isset($link))
|
||||||
|
$link = array('Transaction');
|
||||||
|
|
||||||
|
if (!isset($cond))
|
||||||
|
$cond = array();
|
||||||
|
|
||||||
|
$fields = $this->ledgerContextFields($ledger_id, $account_type);
|
||||||
|
$cond[] = $this->ledgerContextConditions($ledger_id, $account_type);
|
||||||
|
$order = array('Transaction.stamp');
|
||||||
|
|
||||||
|
$entries = $this->find
|
||||||
|
('all',
|
||||||
|
array('link' => $link,
|
||||||
|
'fields' => $fields,
|
||||||
|
'conditions' => $cond,
|
||||||
|
'order' => $order,
|
||||||
|
));
|
||||||
|
|
||||||
|
return $entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: findReconciledLedgerEntries
|
||||||
|
* - Returns ledger entries that are reconciled to the given entry.
|
||||||
|
* (such as payments towards a charge).
|
||||||
|
*/
|
||||||
|
|
||||||
|
function findReconciledLedgerEntries($id = null, $fundamental_type = null) {
|
||||||
|
foreach (($fundamental_type
|
||||||
|
? array($fundamental_type)
|
||||||
|
: array('debit', 'credit')) AS $fund) {
|
||||||
|
$ucfund = ucfirst($fund);
|
||||||
|
$reconciled[$fund]['entry'] = $this->find
|
||||||
|
('all', array
|
||||||
|
('link' => array
|
||||||
|
("ReconciliationLedgerEntry" => array
|
||||||
|
('class' => "{$ucfund}ReconciliationLedgerEntry",
|
||||||
|
'fields' => array
|
||||||
|
('id',
|
||||||
|
"COALESCE(SUM(Reconciliation.amount),0) AS 'reconciled'",
|
||||||
|
"LedgerEntry.amount - COALESCE(SUM(Reconciliation.amount),0) AS 'balance'",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'group' => ("ReconciliationLedgerEntry.id"),
|
||||||
|
'conditions' => array('LedgerEntry.id' => $id),
|
||||||
|
'fields' => array(),
|
||||||
|
));
|
||||||
|
//pr($reconciled);
|
||||||
|
$balance = 0;
|
||||||
|
foreach ($reconciled[$fund]['entry'] AS &$entry) {
|
||||||
|
$entry = array_merge($entry["ReconciliationLedgerEntry"], $entry[0]);
|
||||||
|
$balance += $entry['balance'];
|
||||||
|
}
|
||||||
|
$reconciled[$fund]['balance'] = $balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reconciled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: reverse
|
||||||
|
* - Reverses the ledger entry
|
||||||
|
*/
|
||||||
|
|
||||||
|
function reverse1($id, $amount = null, $transaction_id = null, $rec_id = null) {
|
||||||
|
/* pr(array('LedgerEntry::reverse', */
|
||||||
|
/* compact('id', 'amount', 'transaction_id', 'rec_id'))); */
|
||||||
|
|
||||||
|
// Get the LedgerEntry and related fields
|
||||||
|
$entry = $this->find
|
||||||
|
('first',
|
||||||
|
array('contain' => array('MonetarySource.id',
|
||||||
|
'Transaction.id',
|
||||||
|
'DebitLedger.id',
|
||||||
|
'DebitLedger.account_id',
|
||||||
|
'CreditLedger.id',
|
||||||
|
'CreditLedger.account_id',
|
||||||
|
'DebitReconciliationLedgerEntry'
|
||||||
|
/* => */
|
||||||
|
/* array('DebitLedger.id', */
|
||||||
|
/* 'DebitLedger.account_id', */
|
||||||
|
/* 'CreditLedger.id', */
|
||||||
|
/* 'CreditLedger.account_id', */
|
||||||
|
/* ) */
|
||||||
|
,
|
||||||
|
'CreditReconciliationLedgerEntry'
|
||||||
|
/* => */
|
||||||
|
/* array('DebitLedger.id', */
|
||||||
|
/* 'DebitLedger.account_id', */
|
||||||
|
/* 'CreditLedger.id', */
|
||||||
|
/* 'CreditLedger.account_id', */
|
||||||
|
/* ) */
|
||||||
|
,
|
||||||
|
'Customer.id',
|
||||||
|
'Lease.id',
|
||||||
|
),
|
||||||
|
|
||||||
|
'fields' => array('LedgerEntry.*'),
|
||||||
|
|
||||||
|
'conditions' => array(array('LedgerEntry.id' => $id),
|
||||||
|
/* array('NOT' => */
|
||||||
|
/* array('OR' => */
|
||||||
|
/* array(array('DebitReconciliationLedgerEntry.id' => $rec_id), */
|
||||||
|
/* array('CreditReconciliationLedgerEntry.id' => $rec_id), */
|
||||||
|
/* ), */
|
||||||
|
/* ), */
|
||||||
|
/* ), */
|
||||||
|
),
|
||||||
|
));
|
||||||
|
//pr($entry);
|
||||||
|
|
||||||
|
if (!isset($amount))
|
||||||
|
$amount = $entry['LedgerEntry']['amount'];
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
$ids = $this->Ledger->Account->postLedgerEntry
|
||||||
|
(array('transaction_id' => $transaction_id),
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($entry['CreditLedger']['account_id']),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($entry['DebitLedger']['account_id']),
|
||||||
|
'effective_date' => $entry['LedgerEntry']['effective_date'],
|
||||||
|
//'effective_date' => $entry['LedgerEntry']['effective_date'],
|
||||||
|
'amount' => $amount,
|
||||||
|
'lease_id' => $entry['Lease']['id'],
|
||||||
|
'customer_id' => $entry['Customer']['id'],
|
||||||
|
'comment' => "Reversal of Ledger Entry #{$id}",
|
||||||
|
),
|
||||||
|
array('debit' => array(array('LedgerEntry' => array('id' => $entry['LedgerEntry']['id'],
|
||||||
|
'amount' => $amount,
|
||||||
|
))),
|
||||||
|
'credit' => array(array('LedgerEntry' => array('id' => $entry['LedgerEntry']['id'],
|
||||||
|
'amount' => $amount,
|
||||||
|
))),
|
||||||
|
));
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$tid = $ids['transaction_id'];
|
||||||
|
|
||||||
|
pr(compact('entry'));
|
||||||
|
|
||||||
|
foreach (array('Debit', 'Credit') AS $dc_type) {
|
||||||
|
foreach ($entry[$dc_type . 'ReconciliationLedgerEntry'] AS $RLE) {
|
||||||
|
pr(array('checkpoint' => "Reverse $dc_type LE",
|
||||||
|
compact('id', 'rec_id', 'RLE')));
|
||||||
|
if ($RLE['id'] == $rec_id) {
|
||||||
|
pr(array('checkpoint' => "Skipping Reverse $dc_type LE, due to rec_id",
|
||||||
|
compact('id', 'RLE')));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->reverse($RLE['id'], $RLE['Reconciliation']['amount'], $tid, $id))
|
||||||
|
$ids['error'] = true;
|
||||||
|
|
||||||
|
/* $rids = $this->Ledger->Account->postLedgerEntry */
|
||||||
|
/* (array('transaction_id' => $tid), */
|
||||||
|
/* null, */
|
||||||
|
/* array('debit_ledger_id' => $A->currentLedgerID($RLE['CreditLedger']['account_id']), */
|
||||||
|
/* 'credit_ledger_id' => $A->currentLedgerID($RLE['DebitLedger']['account_id']), */
|
||||||
|
/* 'effective_date' => $RLE['effective_date'], */
|
||||||
|
/* //'effective_date' => $RLE['effective_date'], */
|
||||||
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
||||||
|
/* 'lease_id' => $entry['Lease']['id'], */
|
||||||
|
/* 'customer_id' => $entry['Customer']['id'], */
|
||||||
|
/* 'comment' => "Reversal of Ledger Entry #{$RLE['id']}", */
|
||||||
|
/* ), */
|
||||||
|
/* array('debit' => array(array('LedgerEntry' => array('id' => $RLE['id'], */
|
||||||
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
||||||
|
/* ))), */
|
||||||
|
/* 'credit' => array(array('LedgerEntry' => array('id' => $RLE['id'], */
|
||||||
|
/* 'amount' => $RLE['Reconciliation']['amount'], */
|
||||||
|
/* ))), */
|
||||||
|
/* )); */
|
||||||
|
|
||||||
|
/* if ($rids['error']) */
|
||||||
|
/* $ids['error'] = true; */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return $ids['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: reverse
|
||||||
|
* - Reverses the charges
|
||||||
|
*
|
||||||
|
* SAMPLE MOVE IN w/ PRE PAYMENT
|
||||||
|
* DEPOSIT RENT A/R RECEIPT CHECK PETTY BANK
|
||||||
|
* ------- ------- ------- ------- ------- ------- -------
|
||||||
|
* |25 | 25| | | | |
|
||||||
|
* | |20 20| | | | |
|
||||||
|
* | |20 20| | | | |
|
||||||
|
* | |20 20| | | | |
|
||||||
|
* | | |25 25| | | |
|
||||||
|
* | | |20 20| | | |
|
||||||
|
* | | |20 20| | | |
|
||||||
|
* | | |20 20| | | |
|
||||||
|
* | | | |85 85| | |
|
||||||
|
* | | | | |85 | 85|
|
||||||
|
|
||||||
|
* MOVE OUT and REFUND FINAL MONTH
|
||||||
|
* DEPOSIT RENT C/P RECEIPT CHECK PETTY BANK
|
||||||
|
* ------- ------- ------- ------- ------- ------- -------
|
||||||
|
* 25| | |25 | | | | t20 e20a
|
||||||
|
* | 20| |20 | | | | t20 e20b
|
||||||
|
|
||||||
|
* -ONE REFUND CHECK-
|
||||||
|
* | | 25| |25 | | | t30 e30a
|
||||||
|
* | | 20| |20 | | | t30 e30b
|
||||||
|
* | | | 45| | | |45 t40 e40
|
||||||
|
* -OR MULTIPLE-
|
||||||
|
* | | 15| |15 | | | t50a e50a
|
||||||
|
* | | | 15| | |15 | t60a e60a
|
||||||
|
* | | 30| |30 | | | t50b e50b
|
||||||
|
* | | | 30| | | |30 t60b e60b
|
||||||
|
* | | | | | | |
|
||||||
|
|
||||||
|
|
||||||
|
OPTION 1
|
||||||
|
* |-25 | -25| | | | |
|
||||||
|
* | |-20 -20| | | | |
|
||||||
|
* | | |-25 -25| | | |
|
||||||
|
* | | |-20 -20| | | |
|
||||||
|
|
||||||
|
OPTION 2
|
||||||
|
* |-25 | | -25| | | |
|
||||||
|
* | |-20 | -20| | | |
|
||||||
|
* | | | |-15 | -15| |
|
||||||
|
* | | | |-30 | | -30|
|
||||||
|
* | | | | | | |
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function reverse($ledger_entries, $stamp = null) {
|
||||||
|
pr(array('LedgerEntry::reverse',
|
||||||
|
compact('ledger_entries', 'stamp')));
|
||||||
|
|
||||||
|
// If the user only wants to reverse one ID, we'll allow it
|
||||||
|
if (!is_array($ledger_entries))
|
||||||
|
$ledger_entries = $this->find
|
||||||
|
('all', array
|
||||||
|
('contain' => false,
|
||||||
|
'conditions' => array('LedgerEntry.id' => $ledger_entries)));
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
$ar_account_id = $A->accountReceivableAccountID();
|
||||||
|
$receipt_account_id = $A->receiptAccountID();
|
||||||
|
|
||||||
|
$transaction_id = null;
|
||||||
|
foreach ($ledger_entries AS $entry) {
|
||||||
|
$entry = $entry['LedgerEntry'];
|
||||||
|
$amount = -1*$entry['amount'];
|
||||||
|
|
||||||
|
if (isset($entry['credit_account_id']))
|
||||||
|
$refund_account_id = $entry['credit_account_id'];
|
||||||
|
elseif (isset($entry['CreditLedger']['Account']['id']))
|
||||||
|
$refund_account_id = $entry['CreditLedger']['Account']['id'];
|
||||||
|
elseif (isset($entry['credit_ledger_id']))
|
||||||
|
$refund_account_id = $this->Ledger->accountID($entry['credit_ledger_id']);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// post new refund in the income account
|
||||||
|
$ids = $A->postLedgerEntry
|
||||||
|
(array('transaction_id' => $transaction_id),
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($refund_account_id),
|
||||||
|
'effective_date' => $entry['effective_date'],
|
||||||
|
'through_date' => $entry['through_date'],
|
||||||
|
'amount' => $amount,
|
||||||
|
'lease_id' => $entry['lease_id'],
|
||||||
|
'customer_id' => $entry['customer_id'],
|
||||||
|
'comment' => "Refund; Entry #{$entry['id']}",
|
||||||
|
),
|
||||||
|
array('debit' => array
|
||||||
|
(array('LedgerEntry' =>
|
||||||
|
array('id' => $entry['id'],
|
||||||
|
'amount' => $amount))),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
return null;
|
||||||
|
$transaction_id = $ids['transaction_id'];
|
||||||
|
|
||||||
|
pr(array('checkpoint' => 'Posted Refund Ledger Entry',
|
||||||
|
compact('ids', 'amount', 'refund_account_id', 'ar_account_id')));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested ledger entry
|
||||||
|
*/
|
||||||
|
function stats($id) {
|
||||||
|
|
||||||
|
$query = array
|
||||||
|
(
|
||||||
|
'fields' => array("SUM(Reconciliation.amount) AS 'reconciled'"),
|
||||||
|
|
||||||
|
'conditions' => array(isset($cond) ? $cond : array(),
|
||||||
|
array('LedgerEntry.id' => $id)),
|
||||||
|
|
||||||
|
'group' => 'LedgerEntry.id',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get the applied amounts on the debit side
|
||||||
|
$query['link'] =
|
||||||
|
array('DebitReconciliationLedgerEntry' => array('alias' => 'DRLE', 'DRLETransaction' => array('class' => 'Transaction')));
|
||||||
|
$tmpstats = $this->find('first', $query);
|
||||||
|
$stats['debit_amount_reconciled'] = $tmpstats[0]['reconciled'];
|
||||||
|
|
||||||
|
// Get the applied amounts on the credit side
|
||||||
|
$query['link'] =
|
||||||
|
array('CreditReconciliationLedgerEntry' => array('alias' => 'CRLE', 'CRLETransaction' => array('class' => 'Transaction')));
|
||||||
|
$tmpstats = $this->find('first', $query);
|
||||||
|
$stats['credit_amount_reconciled'] = $tmpstats[0]['reconciled'];
|
||||||
|
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,268 @@
|
|||||||
|
<?php
|
||||||
|
class MonetarySource extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'MonetarySource';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'name' => array('notempty'),
|
||||||
|
'tillable' => array('boolean')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'LedgerEntry',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: nsf
|
||||||
|
* - Flags the ledger entry as having insufficient funds
|
||||||
|
* - NOTE: nsf only works if given the monetary source id
|
||||||
|
* to transaction e3, below
|
||||||
|
* - NOTE: In order to show that the rent formerly considered
|
||||||
|
* "collected" is now recognized in reverse, we must
|
||||||
|
* credit A/R with a negative amount in order to
|
||||||
|
* reconcile it against the Rent<->A/R ledger entry.
|
||||||
|
*
|
||||||
|
* FEE RENT A/R RECEIPT CHECK NSF BANK
|
||||||
|
* ------- ------- ------- ------- ------- ------- -------
|
||||||
|
* | |30 30| | | | | t1 e1a : R e2/e7a :
|
||||||
|
* | |20 20| | | | | t1 e1b : R e2/e7b :
|
||||||
|
* | | | | | | |
|
||||||
|
* | | |30 30| | | | t2 e2a : R e3 : R e1a
|
||||||
|
* | | |20 20| | | | t2 e2b : R e3 : R e1b
|
||||||
|
* | | | |50 50| | | t2 e3 : R e4 : R e2
|
||||||
|
* | | | | | | |
|
||||||
|
* | | | | |50 | 50| t3 e4 : : R e3
|
||||||
|
* | | | | | | |
|
||||||
|
* | | | | | |-50 -50| t4 e5 : : R e6
|
||||||
|
* | | | |-50 | -50| | t5 e6 : R e5 : R e7a/e7b
|
||||||
|
* | | |-30 -30| | | | t6 e7a : R e6 : R e1a
|
||||||
|
* | | |-20 -20| | | | t6 e7b : R e6 : R e1b
|
||||||
|
* |35 | 35| | | | | t6 e8
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function nsf($id, $stamp = null) {
|
||||||
|
pr(array('MonetarySource::nsf',
|
||||||
|
compact('id')));
|
||||||
|
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
// Get the LedgerEntries that use this monetary source
|
||||||
|
$source = $this->find
|
||||||
|
('first',
|
||||||
|
array('contain' =>
|
||||||
|
array(/* e3 */
|
||||||
|
'LedgerEntry' =>
|
||||||
|
array('Transaction.id',
|
||||||
|
'MonetarySource.id',
|
||||||
|
'Customer.id',
|
||||||
|
'Lease.id',
|
||||||
|
|
||||||
|
/* e3 debit */
|
||||||
|
'DebitLedger' => /* e.g. CHECK Ledger */
|
||||||
|
array('fields' => array(),
|
||||||
|
|
||||||
|
'Account' => /* e.g. CHECK Account */
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
'conditions' =>
|
||||||
|
array('Account.payable' => 1,
|
||||||
|
'Account.type' => 'ASSET'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
/* e3 credit */
|
||||||
|
'CreditLedger' => /* i.e. RECEIPT Ledger */
|
||||||
|
array('fields' => array('id'),
|
||||||
|
'Account' => /* i.e. RECEIPT Account */
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
'conditions' =>
|
||||||
|
array('Account.id' => $A->receiptAccountID()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
/* e2 */
|
||||||
|
'DebitReconciliationLedgerEntry' =>
|
||||||
|
array(/* e2 credit */
|
||||||
|
'CreditLedger' => /* i.e. A/R Ledger */
|
||||||
|
array('fields' => array(),
|
||||||
|
|
||||||
|
'Account' => /* i.e. A/R Account */
|
||||||
|
array('fields' => array(),
|
||||||
|
'conditions' =>
|
||||||
|
array('Account.id' => $A->accountReceivableAccountID()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
/* e1 */
|
||||||
|
// STUPID CakePHP bug screws up CLASS contains CLASS.
|
||||||
|
// Use the same class, but with different name.
|
||||||
|
'DebitReconciliationLedgerEntry2',
|
||||||
|
),
|
||||||
|
|
||||||
|
/* e4 */
|
||||||
|
'CreditReconciliationLedgerEntry' =>
|
||||||
|
array(/* e4 debit */
|
||||||
|
'DebitLedger' => /* e.g. BANK Ledger */
|
||||||
|
array('fields' => array('id'),
|
||||||
|
'Account' => /* e.g. BANK Account */
|
||||||
|
array('fields' => array('id', 'name'),
|
||||||
|
'conditions' =>
|
||||||
|
array('Account.depositable' => 1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
'conditions' => array(array('MonetarySource.id' => $id)),
|
||||||
|
));
|
||||||
|
pr($source);
|
||||||
|
|
||||||
|
$nsf_account_id = $A->nsfAccountID();
|
||||||
|
$nsf_fee_account_id = $A->nsfChargeAccountID();
|
||||||
|
$ar_account_id = $A->accountReceivableAccountID();
|
||||||
|
$receipt_account_id = $A->receiptAccountID();
|
||||||
|
|
||||||
|
$t4_id = null;
|
||||||
|
$t5_id = null;
|
||||||
|
foreach ($source['LedgerEntry'] AS $e3) {
|
||||||
|
// We expect only a single e4 entry
|
||||||
|
$e4 = $e3['CreditReconciliationLedgerEntry'];
|
||||||
|
if (count($e4) < 1)
|
||||||
|
continue;
|
||||||
|
if (count($e4) > 1)
|
||||||
|
die('Too many e4 entries');
|
||||||
|
|
||||||
|
// Pullup e4 from the single member array
|
||||||
|
$e4 = $e4[0];
|
||||||
|
|
||||||
|
// e3 amount
|
||||||
|
$amount = -$e3['amount'];
|
||||||
|
|
||||||
|
// e4 account
|
||||||
|
$bank_account_id = $e4['DebitLedger']['account_id'];
|
||||||
|
|
||||||
|
// post new e5
|
||||||
|
$e5_ids = $A->postLedgerEntry
|
||||||
|
(array('transaction_id' => $t4_id),
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($bank_account_id),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($nsf_account_id),
|
||||||
|
'effective_date' => $stamp,
|
||||||
|
'amount' => $amount,
|
||||||
|
'lease_id' => $e3['lease_id'],
|
||||||
|
'customer_id' => $e3['customer_id'],
|
||||||
|
'comment' => "NSF Bank Reversal; Monetary Source #{$id}",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($e5_ids['error'])
|
||||||
|
return null;
|
||||||
|
$t4_id = $e5_ids['transaction_id'];
|
||||||
|
|
||||||
|
pr(array('checkpoint' => 'Posted Ledger Entry e5',
|
||||||
|
compact('e5_ids', 'amount')));
|
||||||
|
|
||||||
|
// post new e6... this will be our crossover point
|
||||||
|
// from typical positive entries to negative entries.
|
||||||
|
// Therefore, no reconciliation on this account.
|
||||||
|
$e6_ids = $A->postLedgerEntry
|
||||||
|
(array('transaction_id' => $t5_id),
|
||||||
|
array('monetary_source_id' => $e3['monetary_source_id']),
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($nsf_account_id),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($receipt_account_id),
|
||||||
|
'effective_date' => $stamp,
|
||||||
|
'amount' => $amount,
|
||||||
|
'lease_id' => $e3['lease_id'],
|
||||||
|
'customer_id' => $e3['customer_id'],
|
||||||
|
'comment' => "NSF tracker; Monetary Source #{$id}",
|
||||||
|
),
|
||||||
|
array('debit' => array
|
||||||
|
(array('LedgerEntry' =>
|
||||||
|
array('id' => $e5_ids['id'],
|
||||||
|
'amount' => $amount))),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($e6_ids['error'])
|
||||||
|
return null;
|
||||||
|
$t5_id = $e6_ids['transaction_id'];
|
||||||
|
|
||||||
|
pr(array('checkpoint' => 'Posted Ledger Entry e6',
|
||||||
|
compact('e6_ids', 'amount')));
|
||||||
|
|
||||||
|
$t6_id = null;
|
||||||
|
foreach ($e3['DebitReconciliationLedgerEntry'] AS $e2) {
|
||||||
|
foreach ($e2['DebitReconciliationLedgerEntry2'] AS $e1) {
|
||||||
|
$amount = -1*$e1['Reconciliation']['amount'];
|
||||||
|
|
||||||
|
// post new e7
|
||||||
|
$e7_ids = $A->postLedgerEntry
|
||||||
|
(array('transaction_id' => $t6_id),
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($receipt_account_id),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
||||||
|
'effective_date' => $stamp,
|
||||||
|
'amount' => $amount,
|
||||||
|
'lease_id' => $e1['lease_id'],
|
||||||
|
'customer_id' => $e1['customer_id'],
|
||||||
|
'comment' => "NSF Receipt; Monetary Source #{$id}",
|
||||||
|
),
|
||||||
|
array('debit' => array
|
||||||
|
(array('LedgerEntry' =>
|
||||||
|
array('id' => $e6_ids['id'],
|
||||||
|
'amount' => $amount))),
|
||||||
|
|
||||||
|
'credit' => array
|
||||||
|
(array('LedgerEntry' =>
|
||||||
|
array('id' => $e1['id'],
|
||||||
|
'amount' => $amount))),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($e7_ids['error'])
|
||||||
|
return null;
|
||||||
|
$t6_id = $e7_ids['transaction_id'];
|
||||||
|
|
||||||
|
pr(array('checkpoint' => 'Posted Ledger Entry e7',
|
||||||
|
compact('e7_ids', 'amount')));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cheat for now
|
||||||
|
$customer_id = $source['LedgerEntry'][0]['customer_id'];
|
||||||
|
$lease_id = null;
|
||||||
|
|
||||||
|
// post new e8
|
||||||
|
$e8_ids = $A->postLedgerEntry
|
||||||
|
(array('transaction_id' => $t6_id),
|
||||||
|
null,
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($nsf_fee_account_id),
|
||||||
|
'effective_date' => $stamp,
|
||||||
|
'amount' => 35,
|
||||||
|
'lease_id' => $lease_id,
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'comment' => "NSF Fee; Monetary Source #{$id}",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($e8_ids['error'])
|
||||||
|
return null;
|
||||||
|
|
||||||
|
pr(array('checkpoint' => 'Posted Ledger Entry e8',
|
||||||
|
compact('e8_ids')));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
class Reconciliation extends AppModel {
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'DebitLedgerEntry' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
//'foreignKey' => 'credit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
'CreditLedgerEntry' => array(
|
||||||
|
'className' => 'LedgerEntry',
|
||||||
|
//'foreignKey' => 'credit_ledger_entry_id',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
class Transaction extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'Transaction';
|
||||||
|
|
||||||
|
var $validate = array(
|
||||||
|
'stamp' => array('date')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'LedgerEntry',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: addInvoice
|
||||||
|
* - Adds a new invoice transaction
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Determine the total charges on the invoice
|
||||||
|
$grand_total = 0;
|
||||||
|
foreach ($data['LedgerEntry'] AS $entry)
|
||||||
|
$grand_total += $entry['amount'];
|
||||||
|
|
||||||
|
// Go through the entered charges
|
||||||
|
$invoice_transaction = array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1));
|
||||||
|
foreach ($data['LedgerEntry'] 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->LedgerEntry->Ledger->Account->postLedgerEntry
|
||||||
|
($invoice_transaction,
|
||||||
|
array_intersect_key($entry, array('MonetarySource'=>1))
|
||||||
|
+ array_intersect_key($entry, array('account_id'=>1)),
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($A->accountReceivableAccountID()),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($entry['account_id']),
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'lease_id' => $lease_id)
|
||||||
|
+ $entry
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
$ret = false;
|
||||||
|
|
||||||
|
$invoice_transaction = array_intersect_key($ids, array('transaction_id'=>1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: addReceipt
|
||||||
|
* - Adds a new receipt transaction
|
||||||
|
*/
|
||||||
|
|
||||||
|
function addReceipt($data, $customer_id, $lease_id = null) {
|
||||||
|
// Create some models for convenience
|
||||||
|
$A = new Account();
|
||||||
|
|
||||||
|
// Assume this will succeed
|
||||||
|
$ret = true;
|
||||||
|
|
||||||
|
// Go through the entered payments
|
||||||
|
$receipt_transaction = array_intersect_key($data, array('Transaction'=>1, 'transaction_id'=>1));
|
||||||
|
foreach ($data['LedgerEntry'] AS $entry) {
|
||||||
|
// Create the receipt entry, and reconcile the credit side
|
||||||
|
// of the double-entry (which should be A/R) as a payment.
|
||||||
|
$ids = $this->LedgerEntry->Ledger->Account->postLedgerEntry
|
||||||
|
($receipt_transaction,
|
||||||
|
array_intersect_key($entry, array('MonetarySource'=>1))
|
||||||
|
+ array_intersect_key($entry, array('account_id'=>1)),
|
||||||
|
array('debit_ledger_id' => $A->currentLedgerID($entry['account_id']),
|
||||||
|
'credit_ledger_id' => $A->currentLedgerID($A->receiptAccountID()),
|
||||||
|
'customer_id' => $customer_id,
|
||||||
|
'lease_id' => $lease_id)
|
||||||
|
+ $entry,
|
||||||
|
'receipt');
|
||||||
|
|
||||||
|
if ($ids['error'])
|
||||||
|
$ret = false;
|
||||||
|
|
||||||
|
$receipt_transaction = array_intersect_key($ids,
|
||||||
|
array('transaction_id'=>1,
|
||||||
|
'split_transaction_id'=>1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
class Unit extends AppModel {
|
||||||
|
|
||||||
|
var $name = 'Unit';
|
||||||
|
var $validate = array(
|
||||||
|
'id' => array('numeric'),
|
||||||
|
'unit_size_id' => array('numeric'),
|
||||||
|
'name' => array('notempty'),
|
||||||
|
'sort_order' => array('numeric'),
|
||||||
|
'walk_order' => array('numeric'),
|
||||||
|
'deposit' => array('money'),
|
||||||
|
'amount' => array('money')
|
||||||
|
);
|
||||||
|
|
||||||
|
var $belongsTo = array(
|
||||||
|
'UnitSize',
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasOne = array(
|
||||||
|
'CurrentLease' => array(
|
||||||
|
'className' => 'Lease',
|
||||||
|
'conditions' => 'CurrentLease.moveout_date IS NULL',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
var $hasMany = array(
|
||||||
|
'Lease',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* helpers: status enumerations
|
||||||
|
*/
|
||||||
|
|
||||||
|
function statusEnums() {
|
||||||
|
static $status_enums;
|
||||||
|
if (!isset($status_enums))
|
||||||
|
$status_enums = $this->getEnumValues('status');
|
||||||
|
return $status_enums;
|
||||||
|
}
|
||||||
|
|
||||||
|
function activeStatusEnums() {
|
||||||
|
return array_diff_key($this->statusEnums(), array(''=>1, 'DELETED'=>1));
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusValue($enum) {
|
||||||
|
$enums = $this->statusEnums();
|
||||||
|
return $enums[$enum];
|
||||||
|
}
|
||||||
|
|
||||||
|
function occupiedEnumValue() {
|
||||||
|
return statusValue('OCCUPIED');
|
||||||
|
}
|
||||||
|
|
||||||
|
function conditionOccupied() {
|
||||||
|
return ('Unit.status >= ' . $this->statusValue('OCCUPIED'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function conditionVacant() {
|
||||||
|
return ('Unit.status BETWEEN ' .
|
||||||
|
($this->statusValue('UNAVAILABLE')+1) .
|
||||||
|
' AND ' .
|
||||||
|
($this->statusValue('OCCUPIED')-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
function conditionUnavailable() {
|
||||||
|
return ('Unit.status <= ' . $this->statusValue('UNAVAILABLE'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: updateStatus
|
||||||
|
* - Update the given unit to the given status
|
||||||
|
*/
|
||||||
|
function updateStatus($id, $status) {
|
||||||
|
$this->id = $id;
|
||||||
|
//pr(compact('id', 'status'));
|
||||||
|
$this->saveField('status', $status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
**************************************************************************
|
||||||
|
* function: stats
|
||||||
|
* - Returns summary data from the requested customer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function stats($id = null) {
|
||||||
|
if (!$id)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Get the basic information necessary
|
||||||
|
$unit = $this->find('first',
|
||||||
|
array('contain' => array
|
||||||
|
('Lease' => array
|
||||||
|
('fields' => array('Lease.id')),
|
||||||
|
|
||||||
|
'CurrentLease' => array
|
||||||
|
('fields' => array('CurrentLease.id'))),
|
||||||
|
|
||||||
|
'conditions' => array
|
||||||
|
(array('Unit.id' => $id)),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Get the stats for the current lease
|
||||||
|
$stats['CurrentLease'] = $this->Lease->stats($unit['CurrentLease']['id']);
|
||||||
|
|
||||||
|
// Sum the stats for all leases together
|
||||||
|
foreach ($unit['Lease'] AS $lease) {
|
||||||
|
$this->statsMerge($stats['Lease'], $this->Lease->stats($lease['id']));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the collection
|
||||||
|
return $stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Vendored
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
File diff suppressed because it is too large
Load Diff
@@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class ContactsController extends AppController {
|
|
||||||
|
|
||||||
var $sidemenu_links = array();
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* 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 contacts
|
|
||||||
*/
|
|
||||||
|
|
||||||
function index() { $this->all(); }
|
|
||||||
function all() { $this->jqGridView('All Contacts', 'all'); }
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* virtuals: jqGridData
|
|
||||||
* - With the application controller handling the jqGridData action,
|
|
||||||
* these virtual functions ensure that the correct data is passed
|
|
||||||
* to jqGrid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
|
||||||
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
|
||||||
if ($index === 'Contact.last_name') {
|
|
||||||
$order[] = 'Contact.first_name ' . $direction;
|
|
||||||
}
|
|
||||||
if ($index === 'Contact.first_name') {
|
|
||||||
$order[] = 'Contact.last_name ' . $direction;
|
|
||||||
}
|
|
||||||
return $order;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: view
|
|
||||||
* - Displays information about a specific contact
|
|
||||||
*/
|
|
||||||
|
|
||||||
function view($id = null) {
|
|
||||||
if (!$id) {
|
|
||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
|
||||||
$this->redirect(array('action'=>'index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$contact = $this->Contact->find
|
|
||||||
('first', array
|
|
||||||
('contain' => array
|
|
||||||
(// Models
|
|
||||||
'ContactPhone',
|
|
||||||
'ContactEmail',
|
|
||||||
'ContactAddress',
|
|
||||||
'Customer'),
|
|
||||||
|
|
||||||
'conditions' => array('Contact.id' => $id),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Prepare to render.
|
|
||||||
$title = $contact['Contact']['display_name'];
|
|
||||||
$this->set(compact('contact', 'title'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class CustomersController extends AppController {
|
|
||||||
var $sidemenu_links =
|
|
||||||
array(array('name' => 'Tenants', 'header' => true),
|
|
||||||
array('name' => 'Current', 'url' => array('controller' => 'customers', 'action' => 'current')),
|
|
||||||
array('name' => 'Past', 'url' => array('controller' => 'customers', 'action' => 'past')),
|
|
||||||
array('name' => 'All', 'url' => array('controller' => 'customers', 'action' => 'all')),
|
|
||||||
);
|
|
||||||
|
|
||||||
//var $components = array('RequestHandler');
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* override: sideMenuLinks
|
|
||||||
* - Generates controller specific links for the side menu
|
|
||||||
*/
|
|
||||||
function sideMenuLinks() {
|
|
||||||
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: index / current / past / all
|
|
||||||
* - Creates a list of tenants
|
|
||||||
*/
|
|
||||||
|
|
||||||
function index() { $this->current(); }
|
|
||||||
function current() { $this->jqGridView('Current Tenants'); }
|
|
||||||
function past() { $this->jqGridView('Past Tenants'); }
|
|
||||||
function all() { $this->jqGridView('All Tenants', 'all'); }
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* virtuals: jqGridData
|
|
||||||
* - With the application controller handling the jqGridData action,
|
|
||||||
* these virtual functions ensure that the correct data is passed
|
|
||||||
* to jqGrid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function jqGridDataSetup(&$params) {
|
|
||||||
parent::jqGridDataSetup($params);
|
|
||||||
if (!isset($params['action']))
|
|
||||||
$params['action'] = 'all';
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
|
||||||
return array
|
|
||||||
('link' =>
|
|
||||||
array(// Models
|
|
||||||
'PrimaryContact',
|
|
||||||
'CurrentLease' => array('fields' => array()),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataFields(&$params, &$model) {
|
|
||||||
return array('Customer.*',
|
|
||||||
'COUNT(CurrentLease.id) AS lease_count');
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
|
||||||
$conditions = parent::jqGridDataConditions($params, $model);
|
|
||||||
|
|
||||||
if ($params['action'] === 'current') {
|
|
||||||
$conditions[] = 'CurrentLease.id IS NOT NULL';
|
|
||||||
}
|
|
||||||
elseif ($params['action'] === 'past') {
|
|
||||||
$conditions[] = 'CurrentLease.id IS NULL';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
|
||||||
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
|
||||||
if ($index === 'PrimaryContact.last_name') {
|
|
||||||
$order[] = 'PrimaryContact.first_name ' . $direction;
|
|
||||||
}
|
|
||||||
if ($index === 'PrimaryContact.first_name') {
|
|
||||||
$order[] = 'PrimaryContact.last_name ' . $direction;
|
|
||||||
}
|
|
||||||
return $order;
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataRecordCount(&$params, &$model, $query) {
|
|
||||||
|
|
||||||
// We don't have a good way to use the query to obtain
|
|
||||||
// our count. The problem is that we're relying on the
|
|
||||||
// group by for the query, which will destroy the count,
|
|
||||||
// whether we omit the group by or leave it in.
|
|
||||||
// So, build a fresh query for counting.
|
|
||||||
|
|
||||||
$query['conditions'] = parent::jqGridDataConditions($params, $model);
|
|
||||||
|
|
||||||
$count = $model->find('count',
|
|
||||||
array_merge(array('link' => array_diff_key($query['link'],
|
|
||||||
array('CurrentLease'=>1))),
|
|
||||||
array_diff_key($query, array('link'=>1))));
|
|
||||||
|
|
||||||
if ($params['action'] === 'all')
|
|
||||||
return $count;
|
|
||||||
|
|
||||||
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
|
||||||
$count_past = $model->find('count', $query);
|
|
||||||
|
|
||||||
// Since we can't easily count 'current' directly, we
|
|
||||||
// can quickly derive it since 'current' customers
|
|
||||||
// are mutually exclusive to 'past' customers.
|
|
||||||
if ($params['action'] == 'current')
|
|
||||||
$count = $count - $count_past;
|
|
||||||
elseif ($params['action'] == 'past') {
|
|
||||||
$count = $count_past;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataRecords(&$params, &$model, $query) {
|
|
||||||
$customers = parent::jqGridDataRecords($params, $model, $query);
|
|
||||||
|
|
||||||
// Get the balance on each customer.
|
|
||||||
foreach ($customers AS &$customer) {
|
|
||||||
$stats = $this->Customer->stats($customer['Customer']['id']);
|
|
||||||
$customer['Customer']['balance'] = $stats['balance'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $customers;
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
||||||
$links['Customer'] = array('name');
|
|
||||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: view
|
|
||||||
* - Displays information about a specific customer
|
|
||||||
*/
|
|
||||||
|
|
||||||
function view($id = null) {
|
|
||||||
if (!$id) {
|
|
||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
|
||||||
$this->redirect(array('action'=>'index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$customer = $this->Customer->details($id);
|
|
||||||
|
|
||||||
$outstanding_balance = $customer['stats']['balance'];
|
|
||||||
$outstanding_deposit = $customer['deposits']['summary']['balance'];
|
|
||||||
|
|
||||||
$this->sidemenu_links[] =
|
|
||||||
array('name' => 'Operations', 'header' => true);
|
|
||||||
$this->sidemenu_links[] =
|
|
||||||
array('name' => 'Payment', 'url' => array('action' => 'payment', $id));
|
|
||||||
$this->sidemenu_links[] =
|
|
||||||
array('name' => 'Move-Out', 'url' => array('controller' => 'units', 'action' => 'move-out'));
|
|
||||||
|
|
||||||
// Prepare to render.
|
|
||||||
$title = $customer['Customer']['name'];
|
|
||||||
$this->set(compact('customer', 'title',
|
|
||||||
'outstanding_balance',
|
|
||||||
'outstanding_deposit'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: payment
|
|
||||||
* - Sets up the payment entry page for the given customer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function payment($id = null) {
|
|
||||||
/* if (!$id) { */
|
|
||||||
/* $this->Session->setFlash(__('Invalid Item.', true)); */
|
|
||||||
/* $this->redirect(array('action'=>'index')); */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* if ($this->RequestHandler->isPost()) { */
|
|
||||||
/* pr($this->data); */
|
|
||||||
/* //$this->redirect(array('action'=>'index')); */
|
|
||||||
/* $customer = $this->data; */
|
|
||||||
/* } */
|
|
||||||
if (isset($id)) {
|
|
||||||
$this->Customer->recursive = -1;
|
|
||||||
$customer = $this->Customer->read(null, $id);
|
|
||||||
$customer = $customer['Customer'];
|
|
||||||
$unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
|
|
||||||
$charges = $unreconciled['debit'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$customer = null;
|
|
||||||
$charges = array('balance' => 0, 'entry' => array());
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = 'Payment Entry';
|
|
||||||
$this->set(compact('customer', 'charges', 'title'));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: unreconciledEntries
|
|
||||||
* - returns the list of unreconciled entries
|
|
||||||
*/
|
|
||||||
|
|
||||||
function unreconciled($id) {
|
|
||||||
|
|
||||||
//$this->layout = 'ajax';
|
|
||||||
$this->layout = null;
|
|
||||||
$this->autoLayout = false;
|
|
||||||
$this->autoRender = false;
|
|
||||||
Configure::write('debug', '0');
|
|
||||||
header("Content-type: text/xml;charset=utf-8");
|
|
||||||
|
|
||||||
App::import('Helper', 'Xml');
|
|
||||||
$xml = new XmlHelper();
|
|
||||||
|
|
||||||
// Find the unreconciled entries, then manipulate the structure
|
|
||||||
// slightly to accomodate the format necessary for XML Helper.
|
|
||||||
$unreconciled = $this->Customer->findUnreconciledLedgerEntries($id);
|
|
||||||
$unreconciled = array('entries' =>
|
|
||||||
array_intersect_key($unreconciled['debit'],
|
|
||||||
array('entry'=>1, 'balance'=>1)));
|
|
||||||
|
|
||||||
// XML Helper will dump an empty tag if the array is empty
|
|
||||||
if (!count($unreconciled['entries']['entry']))
|
|
||||||
unset($unreconciled['entries']['entry']);
|
|
||||||
|
|
||||||
pr($unreconciled);
|
|
||||||
//$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount);
|
|
||||||
|
|
||||||
$opts = array();
|
|
||||||
//$opts['format'] = 'tags';
|
|
||||||
echo $xml->header();
|
|
||||||
echo $xml->serialize($unreconciled, $opts);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class LeasesController extends AppController {
|
|
||||||
|
|
||||||
var $sidemenu_links =
|
|
||||||
array(array('name' => 'Leases', 'header' => true),
|
|
||||||
array('name' => 'Active', 'url' => array('controller' => 'leases', 'action' => 'active')),
|
|
||||||
array('name' => 'Closed', 'url' => array('controller' => 'leases', 'action' => 'closed')),
|
|
||||||
array('name' => 'All', 'url' => array('controller' => 'leases', 'action' => 'all')),
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* override: sideMenuLinks
|
|
||||||
* - Generates controller specific links for the side menu
|
|
||||||
*/
|
|
||||||
function sideMenuLinks() {
|
|
||||||
return array_merge(parent::sideMenuLinks(), $this->sidemenu_links);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: index / active / closed / all
|
|
||||||
* - Generate a listing of leases
|
|
||||||
*/
|
|
||||||
|
|
||||||
function index() { $this->all(); }
|
|
||||||
function active() { $this->jqGridView('Active Leases'); }
|
|
||||||
function closed() { $this->jqGridView('Closed Leases'); }
|
|
||||||
function all() { $this->jqGridView('All Leases', 'all'); }
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* virtuals: jqGridData
|
|
||||||
* - With the application controller handling the jqGridData action,
|
|
||||||
* these virtual functions ensure that the correct data is passed
|
|
||||||
* to jqGrid.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function jqGridDataSetup(&$params) {
|
|
||||||
parent::jqGridDataSetup($params);
|
|
||||||
if (!isset($params['action']))
|
|
||||||
$params['action'] = 'all';
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
|
||||||
return array
|
|
||||||
('link' => array('Unit' => array('fields' => array('Unit.id', 'Unit.name')),
|
|
||||||
'Customer' => array('fields' => array('Customer.id', 'Customer.name'))));
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
|
||||||
$conditions = parent::jqGridDataConditions($params, $model);
|
|
||||||
|
|
||||||
if ($params['action'] === 'active') {
|
|
||||||
$conditions[] = 'Lease.close_date IS NULL';
|
|
||||||
}
|
|
||||||
elseif ($params['action'] === 'closed') {
|
|
||||||
$conditions[] = 'Lease.close_date IS NOT NULL';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
|
||||||
$links['Lease'] = array('number');
|
|
||||||
$links['Unit'] = array('name');
|
|
||||||
$links['Customer'] = array('name');
|
|
||||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataRecords(&$params, &$model, $query) {
|
|
||||||
$leases = parent::jqGridDataRecords($params, $model, $query);
|
|
||||||
|
|
||||||
// Get the balance on each lease.
|
|
||||||
foreach ($leases AS &$lease) {
|
|
||||||
$stats = $this->Lease->stats($lease['Lease']['id']);
|
|
||||||
$lease['Lease']['balance'] = $stats['balance'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $leases;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
**************************************************************************
|
|
||||||
* action: view
|
|
||||||
* - Displays information about a specific lease
|
|
||||||
*/
|
|
||||||
|
|
||||||
function view($id = null) {
|
|
||||||
if (!$id) {
|
|
||||||
$this->Session->setFlash(__('Invalid Item.', true));
|
|
||||||
$this->redirect(array('action'=>'index'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get details about the lease and its ledgers (no ledger entries yet)
|
|
||||||
$lease = $this->Lease->find
|
|
||||||
('first',
|
|
||||||
array('contain' =>
|
|
||||||
array(// Models
|
|
||||||
'LeaseType',
|
|
||||||
'Unit',
|
|
||||||
'Customer',
|
|
||||||
),
|
|
||||||
'conditions' => array(array('Lease.id' => $id)),
|
|
||||||
'limit' => 2
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Obtain the overall lease balance
|
|
||||||
$this->Lease->statsMerge($lease['Lease'],
|
|
||||||
array('stats' => $this->Lease->stats($id)));
|
|
||||||
$outstanding_balance = $lease['Lease']['stats']['balance'];
|
|
||||||
|
|
||||||
// Determine the lease security deposit
|
|
||||||
$deposits = $this->Lease->findSecurityDeposits($lease['Lease']['id']);
|
|
||||||
$outstanding_deposit = $deposits['summary']['balance'];
|
|
||||||
|
|
||||||
// Prepare to render
|
|
||||||
$title = 'Lease: #' . $lease['Lease']['id'];
|
|
||||||
$this->set(compact('lease', 'title',
|
|
||||||
'outstanding_deposit',
|
|
||||||
'outstanding_balance'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* SVN FILE: $Id: pages_controller.php 7945 2008-12-19 02:16:01Z gwoo $ */
|
|
||||||
/**
|
|
||||||
* Static content controller.
|
|
||||||
*
|
|
||||||
* This file will render views from views/pages/
|
|
||||||
*
|
|
||||||
* PHP versions 4 and 5
|
|
||||||
*
|
|
||||||
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
|
||||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
||||||
*
|
|
||||||
* Licensed under The MIT License
|
|
||||||
* Redistributions of files must retain the above copyright notice.
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.cake.libs.controller
|
|
||||||
* @since CakePHP(tm) v 0.2.9
|
|
||||||
* @version $Revision: 7945 $
|
|
||||||
* @modifiedby $LastChangedBy: gwoo $
|
|
||||||
* @lastmodified $Date: 2008-12-18 18:16:01 -0800 (Thu, 18 Dec 2008) $
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Static content controller
|
|
||||||
*
|
|
||||||
* Override this controller by placing a copy in controllers directory of an application
|
|
||||||
*
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.cake.libs.controller
|
|
||||||
*/
|
|
||||||
class PagesController extends AppController {
|
|
||||||
/**
|
|
||||||
* Controller name
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $name = 'Pages';
|
|
||||||
/**
|
|
||||||
* Default helper
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $helpers = array('Html');
|
|
||||||
/**
|
|
||||||
* This controller does not use a model
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $uses = array();
|
|
||||||
/**
|
|
||||||
* Displays a view
|
|
||||||
*
|
|
||||||
* @param mixed What page to display
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
function display() {
|
|
||||||
$path = func_get_args();
|
|
||||||
|
|
||||||
$count = count($path);
|
|
||||||
if (!$count) {
|
|
||||||
$this->redirect('/');
|
|
||||||
}
|
|
||||||
$page = $subpage = $title = null;
|
|
||||||
|
|
||||||
if (!empty($path[0])) {
|
|
||||||
$page = $path[0];
|
|
||||||
}
|
|
||||||
if (!empty($path[1])) {
|
|
||||||
$subpage = $path[1];
|
|
||||||
}
|
|
||||||
if (!empty($path[$count - 1])) {
|
|
||||||
$title = Inflector::humanize($path[$count - 1]);
|
|
||||||
}
|
|
||||||
$this->set(compact('page', 'subpage', 'title'));
|
|
||||||
$this->render(join('/', $path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class TransactionsController extends AppController {
|
|
||||||
|
|
||||||
var $components = array('RequestHandler');
|
|
||||||
|
|
||||||
var $sidemenu_links =
|
|
||||||
array(array('name' => '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 jqGridDataSetup(&$params) {
|
|
||||||
parent::jqGridDataSetup($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
|
||||||
$link = array();
|
|
||||||
|
|
||||||
if (isset($params['custom']['reconcile_ledger_entry_id'])) {
|
|
||||||
$ftype = $params['custom']['reconcile_type'];
|
|
||||||
//$ftype = $this->Transaction->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype);
|
|
||||||
$link['ReconciledLedgerEntry'] =
|
|
||||||
array('fields' => array('Reconciliation.amount'),
|
|
||||||
'conditions' => array('Reconciliation.type' => $ftype)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('link' => $link);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataFields(&$params, &$model) {
|
|
||||||
return parent::jqGridDataFields($params, $model);
|
|
||||||
}
|
|
||||||
|
|
||||||
function jqGridDataConditions(&$params, &$model) {
|
|
||||||
$conditions = parent::jqGridDataConditions($params, $model);
|
|
||||||
|
|
||||||
if (isset($params['custom']['reconcile_ledger_entry_id'])) {
|
|
||||||
/* $ftype = $params['custom']['reconcile_type']; */
|
|
||||||
/* $ftype = $this->LedgerEntry->DebitLedger->Account->fundamentalOpposite($ftype); */
|
|
||||||
/* $conditions[] = array('Reconciliation.type' => $ftype); */
|
|
||||||
$conditions[] = array('Reconciliation.ledger_entry_id'
|
|
||||||
=> $params['custom']['reconcile_ledger_entry_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $conditions;
|
|
||||||
}
|
|
||||||
|
|
||||||
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('<H2>THIS IS NOT A POST FOR SOME REASON</H2>');
|
|
||||||
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' => 66,
|
|
||||||
'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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user