From 513182a6d562ba232229365b2449289e0d1c7a48 Mon Sep 17 00:00:00 2001 From: abijah Date: Thu, 20 Aug 2009 04:08:06 +0000 Subject: [PATCH 001/103] Trunk is now very close to our initial v0.1 offering. Branching to add some final changes before releasing git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@733 97e9348a-65ac-dc4b-aefc-98561f571b83 From f54550216254dae75a80967452aebddf908c0a5a Mon Sep 17 00:00:00 2001 From: abijah Date: Sat, 22 Aug 2009 22:47:41 +0000 Subject: [PATCH 002/103] Changed how sidemenu links work, so that order of execution doesn't have to control ordering of the list. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@734 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 217 +++++++++++++++--- site/controllers/accounts_controller.php | 51 ++-- site/controllers/contacts_controller.php | 22 +- site/controllers/customers_controller.php | 76 +++--- .../controllers/double_entries_controller.php | 13 -- site/controllers/leases_controller.php | 78 +++---- .../controllers/ledger_entries_controller.php | 13 -- site/controllers/ledgers_controller.php | 27 ++- .../statement_entries_controller.php | 35 +-- site/controllers/tenders_controller.php | 31 +-- site/controllers/transactions_controller.php | 70 +++--- site/controllers/units_controller.php | 68 +++--- site/views/elements/sidemenu.ctp | 36 ++- 13 files changed, 416 insertions(+), 321 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index 5ed9976..fd294fd 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -38,53 +38,158 @@ class AppController extends Controller { var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time', 'Grid'); var $components = array('DebugKit.Toolbar'); + var $sidemenu_areas = array('SITE' => false, 'CONTROLLER' => false, 'ACTION' => false); + var $admin_area = 2; + var $dev_area = 3; + function __construct() { $this->params['dev'] = false; $this->params['admin'] = false; parent::__construct(); } - function sideMenuLinks() { - // Stupid Cake... our constructor sets admin/dev, - // but cake stomps it somewhere along the way - // after constructing the CakeError controller. - if ($this->name === 'CakeError') { - $this->params['dev'] = false; - $this->params['admin'] = false; - } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: sideMenuAreaVerify + * - Verifies the validity of the sidemenu area/subarea/priority, + * and ensures the class member is set to appropriately handle it. + */ - $menu = array(); - $menu[] = array('name' => 'Common', 'header' => true); - $menu[] = array('name' => 'Site Map', 'url' => array('controller' => 'maps', 'action' => 'view', 1)); - $menu[] = array('name' => 'Units', 'url' => array('controller' => 'units', 'action' => 'index')); - $menu[] = array('name' => 'Leases', 'url' => array('controller' => 'leases', 'action' => 'index')); - $menu[] = array('name' => 'Customers', 'url' => array('controller' => 'customers', 'action' => 'index')); - $menu[] = array('name' => 'Deposits', 'url' => array('controller' => 'transactions', 'action' => 'deposit')); + function sideMenuAreaVerify(&$area, $subarea, $priority = null) { + $area = strtoupper($area); + if (!array_key_exists($area, $this->sidemenu_areas)) + $this->INTERNAL_ERROR("Sidemenu link '{$area}': Unknown"); + + if ($area == 'SITE') + $name = 'Common'; + elseif ($area == 'CONTROLLER') + $name = Inflector::humanize($this->params['controller']); + elseif ($area == 'ACTION') + $name = Inflector::humanize(Inflector::singularize($this->params['controller'])); + + $subname = $name; + if ($subarea == $this->admin_area) + $subname .= '-Admin'; + elseif ($subarea == $this->dev_area) + $subname .= '-Dev'; + elseif ($subarea > 1) + $subname .= '-' . $subarea; + + if (empty($this->sidemenu_areas[$area])) + $this->sidemenu_areas[$area] = array('name' => $name, 'subarea' => array()); + if (empty($this->sidemenu_areas[$area]['subarea'][$subarea])) + $this->sidemenu_areas[$area]['subarea'][$subarea] + = array('name' => $subname, 'priorities' => array()); + + if (isset($priority) && empty($this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority])) + $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority] + = array(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: sideMenuAreaName + * - Sets the name of the sidemenu area/subarea + */ + + function sideMenuAreaName($name, $area, $subarea = 1) { + $this->sideMenuAreaVerify($area, $subarea); + $this->sidemenu_areas[$area]['subarea'][$subarea]['name'] = $name; + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: addSideMenuLink + * - Adds another link to the sidemenu area/subarea/priority + */ + + function addSideMenuLink($name, $url, $extra, $area, $subarea = 1, $priority = 10) { + $this->sideMenuAreaVerify($area, $subarea); + $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority][] + = array('name' => $name, 'url' => $url) + (empty($extra) ? array() : $extra); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: addDefaultSideMenuLinks + * - Adds the standard links present on all generated pages + */ + + function addDefaultSideMenuLinks() { + + $this->addSideMenuLink('Site Map', + array('controller' => 'maps', 'action' => 'view', 1), null, + 'SITE'); + $this->addSideMenuLink('Units', + array('controller' => 'units', 'action' => 'index'), null, + 'SITE'); + $this->addSideMenuLink('Leases', + array('controller' => 'leases', 'action' => 'index'), null, + 'SITE'); + $this->addSideMenuLink('Customers', + array('controller' => 'customers', 'action' => 'index'), null, + 'SITE'); + $this->addSideMenuLink('Deposits', + array('controller' => 'transactions', 'action' => 'deposit'), null, + 'SITE'); if ($this->params['admin']) { - $menu[] = array('name' => 'Admin', 'header' => true); - $menu[] = array('name' => 'Accounts', 'url' => array('controller' => 'accounts', 'action' => 'index')); - $menu[] = array('name' => 'Contacts', 'url' => array('controller' => 'contacts', 'action' => 'index')); - $menu[] = array('name' => 'Ledgers', 'url' => array('controller' => 'ledgers', 'action' => 'index')); - $menu[] = array('name' => 'Tenders', 'url' => array('controller' => 'tenders', 'action' => 'index')); - $menu[] = array('name' => 'Transactions', 'url' => array('controller' => 'transactions', 'action' => 'index')); - $menu[] = array('name' => 'Ldgr Entries', 'url' => array('controller' => 'ledger_entries', 'action' => 'index')); - $menu[] = array('name' => 'Stmt Entries', 'url' => array('controller' => 'statement_entries', 'action' => 'index')); - $menu[] = array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')); - $menu[] = array('name' => 'Assess Charges', 'url' => array('controller' => 'leases', 'action' => 'assess_all')); + $this->addSideMenuLink('Accounts', + array('controller' => 'accounts', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Contacts', + array('controller' => 'contacts', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Ledgers', + array('controller' => 'ledgers', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Tenders', + array('controller' => 'tenders', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Transactions', + array('controller' => 'transactions', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Ldgr Entries', + array('controller' => 'ledger_entries', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Stmt Entries', + array('controller' => 'statement_entries', 'action' => 'index'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('New Ledgers', + array('controller' => 'accounts', 'action' => 'newledger'), null, + 'SITE', $this->admin_area); + $this->addSideMenuLink('Assess Charges', + array('controller' => 'leases', 'action' => 'assess_all'), null, + 'SITE', $this->admin_area); } if ($this->params['dev']) { - $menu[] = array('name' => 'Development', 'header' => true); - $menu[] = array('name' => 'Un-Nuke', 'url' => '#', 'htmlAttributes' => - array('onclick' => '$(".pr-section").show(); return false;')); - $menu[] = array('name' => 'New Ledgers', 'url' => array('controller' => 'accounts', 'action' => 'newledger')); - //array('name' => 'RESET DATA', 'url' => array('controller' => 'accounts', 'action' => 'reset_data')); + $this->addSideMenuLink('Un-Nuke', + '#', array('htmlAttributes' => + array('onclick' => '$(".pr-section").show(); return false;')), + 'SITE', $this->dev_area); + $this->addSideMenuLink('New Ledgers', + array('controller' => 'accounts', 'action' => 'newledger'), null, + 'SITE', $this->dev_area); + //array('name' => 'RESET DATA', array('controller' => 'accounts', 'action' => 'reset_data')); } - - return $menu; } + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * hook: beforeFilter + * - Called just before the action function + */ + function beforeFilter() { $this->params['dev'] = (!empty($this->params['dev_route'])); @@ -93,12 +198,50 @@ class AppController extends Controller { if (!$this->params['dev']) Configure::write('debug', '0'); + + $this->addDefaultSideMenuLinks(); } + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * hook: beforeRender + * - Called just before rendering the page + */ + function beforeRender() { - $this->set('sidemenu', $this->sideMenuLinks()); + // Stupid Cake... our constructor sets admin/dev, + // but cake stomps it somewhere along the way + // after constructing the CakeError controller. + if ($this->name === 'CakeError') { + $this->params['dev'] = false; + $this->params['admin'] = false; + } + + foreach ($this->sidemenu_areas AS &$area) { + if (empty($area['subarea'])) + continue; + + ksort($area['subarea']); + foreach ($area['subarea'] AS &$subarea) { + if (empty($subarea['priorities'])) + continue; + ksort($subarea['priorities']); + } + } + + //pr($this->sidemenu_areas); + $this->set('sidemenu', $this->sidemenu_areas); } + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * override: redirect + */ + function redirect($url, $status = null, $exit = true) { // OK, since the controller will not be able to // utilize our overriden url function in AppHelper, @@ -127,6 +270,14 @@ class AppController extends Controller { return parent::redirect($url, $status, $exit); } + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: reset_data + * - Development function. TO BE DELETED + */ + function reset_data() { $this->layout = null; $this->autoLayout = false; diff --git a/site/controllers/accounts_controller.php b/site/controllers/accounts_controller.php index 0554f26..0aed7a5 100644 --- a/site/controllers/accounts_controller.php +++ b/site/controllers/accounts_controller.php @@ -4,28 +4,37 @@ class AccountsController extends AppController { var $uses = array('Account', 'LedgerEntry'); - var $sidemenu_links = - array(array('name' => 'Accounts', 'header' => true), - array('name' => 'All', 'url' => array('controller' => 'accounts', 'action' => 'all')), - array('name' => 'Asset', 'url' => array('controller' => 'accounts', 'action' => 'asset')), - array('name' => 'Liability', 'url' => array('controller' => 'accounts', 'action' => 'liability')), - array('name' => 'Equity', 'url' => array('controller' => 'accounts', 'action' => 'equity')), - array('name' => 'Income', 'url' => array('controller' => 'accounts', 'action' => 'income')), - array('name' => 'Expense', 'url' => array('controller' => 'accounts', 'action' => 'expense')), - ); - /************************************************************************** ************************************************************************** ************************************************************************** - * override: sideMenuLinks - * - Generates controller specific links for the side menu + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Asset', + array('controller' => 'accounts', 'action' => 'asset'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Liability', + array('controller' => 'accounts', 'action' => 'liability'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Equity', + array('controller' => 'accounts', 'action' => 'equity'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Income', + array('controller' => 'accounts', 'action' => 'income'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Expense', + array('controller' => 'accounts', 'action' => 'expense'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'accounts', 'action' => 'all'), null, + 'CONTROLLER'); } - + /************************************************************************** ************************************************************************** ************************************************************************** @@ -189,12 +198,12 @@ class AccountsController extends AppController { $stats = $this->Account->stats($id, true); $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)); + $this->addSideMenuLink('New Ledger', + array('action' => 'newledger', $id), null, + 'ACTION'); + $this->addSideMenuLink('Collected', + array('action' => 'collected', $id), null, + 'ACTION'); // Prepare to render $title = 'Account: ' . $account['Account']['name']; diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index ea2e20d..f9cb4e2 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -2,19 +2,7 @@ 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); - } - - /************************************************************************** ************************************************************************** ************************************************************************** @@ -78,13 +66,9 @@ class ContactsController extends AppController { )); // 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->addSideMenuLink('Edit', + array('action' => 'edit', $id), null, + 'ACTION'); // Prepare to render. $title = 'Contact: ' . $contact['Contact']['display_name']; diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index 5244feb..6b47e64 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -1,28 +1,33 @@ '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 + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Current', + array('controller' => 'customers', 'action' => 'current'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Past', + array('controller' => 'customers', 'action' => 'past'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'customers', 'action' => 'all'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Add Customer', + array('controller' => 'customers', 'action' => 'add'), null, + 'CONTROLLER'); + } - + /************************************************************************** ************************************************************************** ************************************************************************** @@ -229,42 +234,35 @@ class CustomersController extends AppController { } // 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->addSideMenuLink('Edit', + array('action' => 'edit', $id), null, + 'ACTION'); - $this->sidemenu_links[] = - array('name' => 'Move-In', - 'url' => array('action' => 'move_in', - $id)); + $this->addSideMenuLink('Move-In', + array('action' => 'move_in', $id), null, + 'ACTION'); /* if ($show_moveout) { */ -/* $this->sidemenu_links[] = */ -/* array('name' => 'Move-Out', */ -/* 'url' => array('action' => 'move_out', */ -/* $id)); */ +/* $this->addSideMenuLink('Move-Out', */ +/* array('action' => 'move_out', $id), null, */ +/* 'ACTION'); */ /* } */ if ($show_payment || $outstanding_balance > 0) - $this->sidemenu_links[] = - array('name' => 'New Receipt', - 'url' => array('action' => 'receipt', - $id)); + $this->addSideMenuLink('New Receipt', + array('action' => 'receipt', $id), null, + 'ACTION'); if (!$show_moveout && $outstanding_balance > 0) - $this->sidemenu_links[] = - array('name' => 'Write-Off', - 'url' => array('action' => 'bad_debt', - $id)); + $this->addSideMenuLink('Write-Off', + array('action' => 'bad_debt', $id), null, + 'ACTION'); if ($outstanding_balance < 0) - $this->sidemenu_links[] = - array('name' => 'Issue Refund', - 'url' => array('action' => 'refund', $id)); + $this->addSideMenuLink('Issue Refund', + array('action' => 'refund', $id), null, + 'ACTION'); // Prepare to render. $title = 'Customer: ' . $customer['Customer']['name']; diff --git a/site/controllers/double_entries_controller.php b/site/controllers/double_entries_controller.php index 42a61a9..1d4f494 100644 --- a/site/controllers/double_entries_controller.php +++ b/site/controllers/double_entries_controller.php @@ -2,20 +2,7 @@ class DoubleEntriesController 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); - } - - /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/site/controllers/leases_controller.php b/site/controllers/leases_controller.php index ed501c7..e109f38 100644 --- a/site/controllers/leases_controller.php +++ b/site/controllers/leases_controller.php @@ -2,26 +2,31 @@ 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' => 'Delinquent', 'url' => array('controller' => 'leases', 'action' => 'delinquent')), - array('name' => 'All', 'url' => array('controller' => 'leases', 'action' => 'all')), - ); - /************************************************************************** ************************************************************************** ************************************************************************** - * override: sideMenuLinks - * - Generates controller specific links for the side menu + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Active', + array('controller' => 'leases', 'action' => 'active'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Closed', + array('controller' => 'leases', 'action' => 'closed'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Delinquent', + array('controller' => 'leases', 'action' => 'delinquent'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'leases', 'action' => 'all'), null, + 'CONTROLLER'); } - + /************************************************************************** ************************************************************************** ************************************************************************** @@ -467,28 +472,21 @@ class LeasesController extends AppController { // yet still have an outstanding balance. This can happen if someone // were to reverse charges, or if a payment should come back NSF. if (!isset($lease['Lease']['close_date']) || $outstanding_balance > 0) { - $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->addSideMenuLink('Move-Out', + array('action' => 'move_out', $id), null, + 'ACTION'); if (!isset($lease['Lease']['close_date'])) - $this->sidemenu_links[] = - array('name' => 'New Invoice', 'url' => array('action' => 'invoice', - $id)); + $this->addSideMenuLink('New Invoice', + array('action' => 'invoice', $id), null, + 'ACTION'); - $this->sidemenu_links[] = - array('name' => 'New Receipt', 'url' => array('controller' => 'customers', - 'action' => 'receipt', - $lease['Customer']['id'])); - -/* if ($outstanding_balance < 0) */ -/* $this->sidemenu_links[] = */ -/* array('name' => 'Transfer Credit to Customer', */ -/* 'url' => array('action' => 'promote_surplus', $id)); */ + $this->addSideMenuLink('New Receipt', + array('controller' => 'customers', + 'action' => 'receipt', + $lease['Customer']['id']), null, + 'ACTION'); // REVISIT : // Not allowing refund to be issued from the lease, as @@ -500,19 +498,19 @@ class LeasesController extends AppController { $this->INTERNAL_ERROR("Should not have a customer lease credit."); /* if ($outstanding_balance < 0) */ -/* $this->sidemenu_links[] = */ -/* array('name' => 'Issue Refund', */ -/* 'url' => array('action' => 'refund', $id)); */ +/* $this->addSideMenuLink('Issue Refund', */ +/* array('action' => 'refund', $id), null, */ +/* 'ACTION'); */ if (isset($lease['Lease']['moveout_date']) && $outstanding_balance > 0) - $this->sidemenu_links[] = - array('name' => 'Write-Off', 'url' => array('action' => 'bad_debt', - $id)); + $this->addSideMenuLink('Write-Off', + array('action' => 'bad_debt', $id), null, + 'ACTION'); if ($this->Lease->closeable($id)) - $this->sidemenu_links[] = - array('name' => 'Close', 'url' => array('action' => 'close', - $id)); + $this->addSideMenuLink('Close', + array('action' => 'close', $id), null, + 'ACTION'); } // Prepare to render diff --git a/site/controllers/ledger_entries_controller.php b/site/controllers/ledger_entries_controller.php index d1e7805..cd7d855 100644 --- a/site/controllers/ledger_entries_controller.php +++ b/site/controllers/ledger_entries_controller.php @@ -2,19 +2,6 @@ class LedgerEntriesController 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); - } - /************************************************************************** ************************************************************************** diff --git a/site/controllers/ledgers_controller.php b/site/controllers/ledgers_controller.php index 5aa073b..eddcfa0 100644 --- a/site/controllers/ledgers_controller.php +++ b/site/controllers/ledgers_controller.php @@ -2,25 +2,28 @@ class LedgersController extends AppController { - var $sidemenu_links = - array(array('name' => 'Ledgers', 'header' => true), - array('name' => 'Current', 'url' => array('controller' => 'ledgers', 'action' => 'current')), - array('name' => 'Closed', 'url' => array('controller' => 'ledgers', 'action' => 'closed')), - array('name' => 'All', 'url' => array('controller' => 'ledgers', 'action' => 'all')), - ); - /************************************************************************** ************************************************************************** ************************************************************************** - * override: sideMenuLinks - * - Generates controller specific links for the side menu + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Current', + array('controller' => 'ledgers', 'action' => 'current'), null + 'CONTROLLER'); + $this->addSideMenuLink('Closed', + array('controller' => 'ledgers', 'action' => 'closed'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'ledgers', 'action' => 'all'), null, + 'CONTROLLER'); } - + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/site/controllers/statement_entries_controller.php b/site/controllers/statement_entries_controller.php index b260699..1fa76fb 100644 --- a/site/controllers/statement_entries_controller.php +++ b/site/controllers/statement_entries_controller.php @@ -2,20 +2,7 @@ class StatementEntriesController 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); - } - - /************************************************************************** ************************************************************************** ************************************************************************** @@ -293,24 +280,16 @@ class StatementEntriesController extends AppController { if (strtoupper($entry['StatementEntry']['type']) === 'CHARGE') { - $reversable = $this->StatementEntry->reversable($id); - // Set up dynamic menu items - if ($reversable || $stats['balance'] > 0) - $this->sidemenu_links[] = - array('name' => 'Operations', 'header' => true); - - if ($reversable) - $this->sidemenu_links[] = - array('name' => 'Reverse', - 'url' => array('action' => 'reverse', - $id)); + if ($this->StatementEntry->reversable($id)) + $this->addSideMenuLink('Reverse', + array('action' => 'reverse', $id), null, + 'ACTION'); if ($stats['balance'] > 0) - $this->sidemenu_links[] = - array('name' => 'Waive Balance', - 'url' => array('action' => 'waive', - $id)); + $this->addSideMenuLink('Waive Balance', + array('action' => 'waive', $id), null, + 'ACTION'); } // Prepare to render. diff --git a/site/controllers/tenders_controller.php b/site/controllers/tenders_controller.php index 8e8be18..c44925a 100644 --- a/site/controllers/tenders_controller.php +++ b/site/controllers/tenders_controller.php @@ -2,20 +2,7 @@ class TendersController 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); - } - - /************************************************************************** ************************************************************************** ************************************************************************** @@ -163,16 +150,11 @@ class TendersController extends AppController { )); - // Set up dynamic menu items - $this->sidemenu_links[] = - array('name' => 'Operations', 'header' => true); - // Watch out for the special "Closing" entries if (!empty($tender['TenderType']['id'])) - $this->sidemenu_links[] = - array('name' => 'Edit', - 'url' => array('action' => 'edit', - $id)); + $this->addSideMenuLink('Edit', + array('action' => 'edit', $id), null, + 'ACTION'); if (!empty($tender['Tender']['deposit_transaction_id']) && empty($tender['Tender']['nsf_transaction_id']) @@ -181,10 +163,9 @@ class TendersController extends AppController { // (or if we're in development mode) && (!empty($tender['TenderType']['data1_name']) || !empty($this->params['dev'])) ) { - $this->sidemenu_links[] = - array('name' => 'NSF', - 'url' => array('action' => 'nsf', - $id)); + $this->addSideMenuLink('NSF', + array('action' => 'nsf', $id), null, + 'ACTION'); } // Prepare to render. diff --git a/site/controllers/transactions_controller.php b/site/controllers/transactions_controller.php index eca9677..12382ca 100644 --- a/site/controllers/transactions_controller.php +++ b/site/controllers/transactions_controller.php @@ -4,26 +4,31 @@ 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')), - array('name' => 'Invoices', 'url' => array('controller' => 'transactions', 'action' => 'invoice')), - array('name' => 'Receipts', 'url' => array('controller' => 'transactions', 'action' => 'receipt')), - array('name' => 'Deposits', 'url' => array('controller' => 'transactions', 'action' => 'deposit')), - ); - /************************************************************************** ************************************************************************** ************************************************************************** - * override: sideMenuLinks - * - Generates controller specific links for the side menu + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Invoices', + array('controller' => 'transactions', 'action' => 'invoice'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Receipts', + array('controller' => 'transactions', 'action' => 'receipt'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Deposits', + array('controller' => 'transactions', 'action' => 'deposit'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'transactions', 'action' => 'all'), null, + 'CONTROLLER'); } - + /************************************************************************** ************************************************************************** ************************************************************************** @@ -36,10 +41,9 @@ class TransactionsController extends AppController { function invoice() { $this->gridView('Invoices'); } function receipt() { $this->gridView('Receipts'); } function deposit() { - $this->sidemenu_links = array - (array('name' => 'Operations', 'header' => true), - array('name' => 'New Deposit', 'url' => array('controller' => 'tenders', - 'action' => 'deposit'))); + $this->addSideMenuLink('New Deposit', + array('controller' => 'tenders', 'action' => 'deposit'), null, + 'ACTION'); $this->gridView('Deposits'); } @@ -410,20 +414,19 @@ class TransactionsController extends AppController { $this->redirect(array('action'=>'index')); } - if ($transaction['Transaction']['type'] === 'DEPOSIT' || $this->params['dev']) { - $this->sidemenu_links[] = - array('name' => 'Operations', 'header' => true); + if ($transaction['Transaction']['type'] === 'DEPOSIT') + $this->addSideMenuLink('View Slip', + array('action' => 'deposit_slip', $id), null, + 'ACTION'); - if ($transaction['Transaction']['type'] === 'DEPOSIT') - $this->sidemenu_links[] = - array('name' => 'View Slip', 'url' => array('action' => 'deposit_slip', $id)); - if ($this->params['dev']) - $this->sidemenu_links[] = - array('name' => 'Destroy', 'url' => array('action' => 'destroy', $id), - 'confirmMessage' => ("This may leave the database in an unstable state." . - " Do NOT do this unless you know what you're doing." . - " Proceed anyway?")); - } + if ($this->params['dev']) + $this->addSideMenuLink('Destroy', + array('action' => 'destroy', $id), + array('confirmMessage' => + "This may leave the database in an unstable state." . + " Do NOT do this unless you know what you're doing." . + " Proceed anyway?"), + 'ACTION', $this->dev_area); // OK, prepare to render. $title = 'Transaction #' . $transaction['Transaction']['id']; @@ -482,10 +485,9 @@ class TransactionsController extends AppController { if ($deposit['Transaction']['amount'] != $deposit_total) $this->INTERNAL_ERROR("Deposit items do not add up to deposit slip total"); - $this->sidemenu_links[] = - array('name' => 'Operations', 'header' => true); - $this->sidemenu_links[] = - array('name' => 'View Transaction', 'url' => array('action' => 'view', $id)); + $this->addSideMenuLink('View', + array('action' => 'view', $id), null, + 'ACTION'); $title = 'Deposit Slip'; $this->set(compact('title', 'deposit')); diff --git a/site/controllers/units_controller.php b/site/controllers/units_controller.php index 50f15a0..cd5c4f9 100644 --- a/site/controllers/units_controller.php +++ b/site/controllers/units_controller.php @@ -2,23 +2,28 @@ 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 + * override: addDefaultSideMenuLinks + * - Adds controller specific default side menu links */ - function sideMenuLinks() { - return array_merge(parent::sideMenuLinks(), $this->sidemenu_links); + + function addDefaultSideMenuLinks() { + parent::addDefaultSideMenuLinks(); + $this->addSideMenuLink('Occupied', + array('controller' => 'units', 'action' => 'occupied'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Vacant', + array('controller' => 'units', 'action' => 'vacant'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Unavailable', + array('controller' => 'units', 'action' => 'unavailable'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'units', 'action' => 'all'), null, + 'CONTROLLER'); } @@ -233,36 +238,35 @@ class UnitsController extends AppController { } // 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->addSideMenuLink('Edit', + array('action' => 'edit', $id), null, + 'ACTION'); if (isset($unit['CurrentLease']['id']) && !isset($unit['CurrentLease']['moveout_date'])) { - $this->sidemenu_links[] = - array('name' => 'Move-Out', 'url' => array('action' => 'move_out', - $id)); + $this->addSideMenuLink('Move-Out', + array('action' => 'move_out', $id), null, + 'ACTION'); } elseif ($this->Unit->available($unit['Unit']['status'])) { - $this->sidemenu_links[] = - array('name' => 'Move-In', 'url' => array('action' => 'move_in', - $id)); + $this->addSideMenuLink('Move-In', + array('action' => 'move_in', $id), null, + 'ACTION'); } else { // Unit is unavailable (dirty, damaged, reserved, business-use, etc) } if (isset($unit['CurrentLease']['id']) && !isset($unit['CurrentLease']['close_date'])) { - $this->sidemenu_links[] = - array('name' => 'New Invoice', 'url' => array('controller' => 'leases', - 'action' => 'invoice', - $unit['CurrentLease']['id'])); - $this->sidemenu_links[] = - array('name' => 'New Receipt', 'url' => array('controller' => 'customers', - 'action' => 'receipt', - $unit['CurrentLease']['customer_id'])); + $this->addSideMenuLink('New Invoice', + array('controller' => 'leases', + 'action' => 'invoice', + $unit['CurrentLease']['id']), null, + 'ACTION'); + $this->addSideMenuLink('New Receipt', + array('controller' => 'customers', + 'action' => 'receipt', + $unit['CurrentLease']['customer_id']), null, + 'ACTION'); } // Prepare to render. diff --git a/site/views/elements/sidemenu.ctp b/site/views/elements/sidemenu.ctp index c1e8958..dca30c9 100644 --- a/site/views/elements/sidemenu.ctp +++ b/site/views/elements/sidemenu.ctp @@ -8,17 +8,29 @@ * @package pmgr */ -foreach ($menu AS $item) { - if (isset($item['header'])) - echo('
' . $item['name'] . '
' . "\n"); - elseif (isset($item['hr'])) - echo('
' . "\n"); - elseif (isset($item['url'])) - echo('
' - . $html->link($item['name'], $item['url'], - isset($item['htmlAttributes']) ? $item['htmlAttributes'] : null, - isset($item['confirmMessage']) ? $item['confirmMessage'] : null, - isset($item['escapeTitle']) ? $item['escapeTitle'] : null) +foreach ($menu AS $area) { + if (empty($area['subarea'])) + continue; - . '
' . "\n"); + foreach ($area['subarea'] AS $subarea) { + if (empty($subarea['priorities'])) + continue; + + echo('
' . $subarea['name'] . '
' . "\n"); + foreach ($subarea['priorities'] AS $priority) { + foreach ($priority AS $item) { + if (isset($item['header'])) + echo('
' . $item['name'] . '
' . "\n"); + elseif (isset($item['hr'])) + echo('
' . "\n"); + elseif (isset($item['url'])) + echo('
' + . $html->link($item['name'], $item['url'], + isset($item['htmlAttributes']) ? $item['htmlAttributes'] : null, + isset($item['confirmMessage']) ? $item['confirmMessage'] : null, + isset($item['escapeTitle']) ? $item['escapeTitle'] : null) + . '
' . "\n"); + } + } + } } From da88975fed22e2c18f9432a1a868f32335188459 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 00:02:53 +0000 Subject: [PATCH 003/103] More work on tidying up the menu items for usability. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@735 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 100 +++++++++++++++---- site/controllers/accounts_controller.php | 36 ++++--- site/controllers/customers_controller.php | 32 +++--- site/controllers/leases_controller.php | 28 +++--- site/controllers/ledgers_controller.php | 22 ++-- site/controllers/transactions_controller.php | 29 +++--- site/controllers/units_controller.php | 27 ++--- 7 files changed, 183 insertions(+), 91 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index fd294fd..50b242a 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -39,8 +39,11 @@ class AppController extends Controller { var $components = array('DebugKit.Toolbar'); var $sidemenu_areas = array('SITE' => false, 'CONTROLLER' => false, 'ACTION' => false); - var $admin_area = 2; - var $dev_area = 3; + var $std_area = 10; + var $new_area = 20; + var $op_area = 30; + var $admin_area = 40; + var $dev_area = 50; function __construct() { $this->params['dev'] = false; @@ -62,27 +65,43 @@ class AppController extends Controller { $this->INTERNAL_ERROR("Sidemenu link '{$area}': Unknown"); if ($area == 'SITE') - $name = 'Common'; + $name = 'Navigation'; elseif ($area == 'CONTROLLER') $name = Inflector::humanize($this->params['controller']); elseif ($area == 'ACTION') $name = Inflector::humanize(Inflector::singularize($this->params['controller'])); + if (empty($this->sidemenu_areas[$area])) + $this->sidemenu_areas[$area] + = array('enable' => true, 'name' => $name, 'subarea' => array()); + + if (empty($subarea)) + return; + $subname = $name; - if ($subarea == $this->admin_area) + if ($subarea == $this->std_area) + $subname .= ''; + elseif ($subarea == $this->op_area) + //$subname .= '-Ops'; + $subname = 'Operations'; + elseif ($subarea == $this->new_area) + //$subname .= '-New'; + $subname = 'Creation'; + elseif ($subarea == $this->admin_area) $subname .= '-Admin'; elseif ($subarea == $this->dev_area) $subname .= '-Dev'; - elseif ($subarea > 1) + else $subname .= '-' . $subarea; - if (empty($this->sidemenu_areas[$area])) - $this->sidemenu_areas[$area] = array('name' => $name, 'subarea' => array()); if (empty($this->sidemenu_areas[$area]['subarea'][$subarea])) - $this->sidemenu_areas[$area]['subarea'][$subarea] - = array('name' => $subname, 'priorities' => array()); + $this->sidemenu_areas[$area]['subarea'][$subarea] + = array('enable' => true, 'name' => $subname, 'priorities' => array()); - if (isset($priority) && empty($this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority])) + if (empty($priority)) + return; + + if (empty($this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority])) $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority] = array(); } @@ -95,9 +114,28 @@ class AppController extends Controller { * - Sets the name of the sidemenu area/subarea */ - function sideMenuAreaName($name, $area, $subarea = 1) { + function sideMenuAreaName($name, $area, $subarea = null) { $this->sideMenuAreaVerify($area, $subarea); - $this->sidemenu_areas[$area]['subarea'][$subarea]['name'] = $name; + if (empty($subarea)) + $this->sidemenu_areas[$area]['name'] = $name; + else + $this->sidemenu_areas[$area]['subarea'][$subarea]['name'] = $name; + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: sideMenuEnable + * - Enables/Disables an area or subarea of the sidemenu + */ + + function sideMenuEnable($area, $subarea = null, $enable = true) { + $this->sideMenuAreaVerify($area, $subarea); + if (isset($subarea)) + $this->sidemenu_areas[$area]['subarea'][$subarea]['enable'] = $enable; + else + $this->sidemenu_areas[$area]['enable'] = $enable; } @@ -108,7 +146,9 @@ class AppController extends Controller { * - Adds another link to the sidemenu area/subarea/priority */ - function addSideMenuLink($name, $url, $extra, $area, $subarea = 1, $priority = 10) { + function addSideMenuLink($name, $url, $extra, $area, $subarea = null, $priority = 10) { + if (empty($subarea)) + $subarea = $this->std_area; $this->sideMenuAreaVerify($area, $subarea); $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority][] = array('name' => $name, 'url' => $url) + (empty($extra) ? array() : $extra); @@ -140,6 +180,26 @@ class AppController extends Controller { array('controller' => 'transactions', 'action' => 'deposit'), null, 'SITE'); +/* $this->addSideMenuLink('Move-In', */ +/* array('controller' => 'customers', 'action' => 'move_in'), null, */ +/* 'SITE', $this->op_area); */ + +/* $this->addSideMenuLink('Move-Out', */ +/* array('controller' => 'customers', 'action' => 'move_out'), null, */ +/* 'SITE', $this->op_area); */ + +/* $this->addSideMenuLink('New Receipt', */ +/* array('controller' => 'customers', 'action' => 'receipt'), null, */ +/* 'SITE', $this->op_area); */ + +/* $this->addSideMenuLink('New Customer', */ +/* array('controller' => 'customers', 'action' => 'add'), null, */ +/* 'SITE', $this->op_area); */ + +/* $this->addSideMenuLink('New Deposit', */ +/* array('controller' => 'tenders', 'action' => 'deposit'), null, */ +/* 'SITE', $this->op_area); */ + if ($this->params['admin']) { $this->addSideMenuLink('Accounts', array('controller' => 'accounts', 'action' => 'index'), null, @@ -162,9 +222,6 @@ class AppController extends Controller { $this->addSideMenuLink('Stmt Entries', array('controller' => 'statement_entries', 'action' => 'index'), null, 'SITE', $this->admin_area); - $this->addSideMenuLink('New Ledgers', - array('controller' => 'accounts', 'action' => 'newledger'), null, - 'SITE', $this->admin_area); $this->addSideMenuLink('Assess Charges', array('controller' => 'leases', 'action' => 'assess_all'), null, 'SITE', $this->admin_area); @@ -180,6 +237,9 @@ class AppController extends Controller { 'SITE', $this->dev_area); //array('name' => 'RESET DATA', array('controller' => 'accounts', 'action' => 'reset_data')); } + + + $this->sideMenuAreaName('Operations', 'SITE', $this->op_area); } @@ -200,6 +260,7 @@ class AppController extends Controller { Configure::write('debug', '0'); $this->addDefaultSideMenuLinks(); + $this->sideMenuEnable('SITE', $this->op_area, false); } @@ -220,11 +281,15 @@ class AppController extends Controller { } foreach ($this->sidemenu_areas AS &$area) { + if (empty($area['enable'])) + $area = array(); if (empty($area['subarea'])) continue; - ksort($area['subarea']); + foreach ($area['subarea'] AS &$subarea) { + if (empty($subarea['enable'])) + $subarea = array(); if (empty($subarea['priorities'])) continue; ksort($subarea['priorities']); @@ -309,6 +374,7 @@ class AppController extends Controller { */ function gridView($title, $action = null, $element = null) { + $this->sideMenuEnable('SITE', $this->op_area); $this->set('title', $title); // The resulting page will contain a grid, which will // use ajax to obtain the actual data for this action diff --git a/site/controllers/accounts_controller.php b/site/controllers/accounts_controller.php index 0aed7a5..ab4f792 100644 --- a/site/controllers/accounts_controller.php +++ b/site/controllers/accounts_controller.php @@ -14,6 +14,25 @@ class AccountsController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: index / asset / liability / equity / income / expense / all + * - Generate a chart of accounts + */ + + function index() { $this->all(); } + function asset() { $this->gridView('Asset Accounts'); } + function liability() { $this->gridView('Liability Accounts'); } + function equity() { $this->gridView('Equity Accounts'); } + function income() { $this->gridView('Income Accounts'); } + function expense() { $this->gridView('Expense Accounts'); } + function all() { $this->gridView('All Accounts', 'all'); } + + function gridView($title, $action = null, $element = null) { $this->addSideMenuLink('Asset', array('controller' => 'accounts', 'action' => 'asset'), null, 'CONTROLLER'); @@ -32,25 +51,10 @@ class AccountsController extends AppController { $this->addSideMenuLink('All', array('controller' => 'accounts', 'action' => 'all'), null, 'CONTROLLER'); + parent::gridView($title, $action, $element); } - /************************************************************************** - ************************************************************************** - ************************************************************************** - * action: index / asset / liability / equity / income / expense / all - * - Generate a chart of accounts - */ - - function index() { $this->all(); } - function asset() { $this->gridView('Asset Accounts'); } - function liability() { $this->gridView('Liability Accounts'); } - function equity() { $this->gridView('Equity Accounts'); } - function income() { $this->gridView('Income Accounts'); } - function expense() { $this->gridView('Expense Accounts'); } - function all() { $this->gridView('All Accounts', 'all'); } - - /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index 6b47e64..b5d423c 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -12,19 +12,6 @@ class CustomersController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); - $this->addSideMenuLink('Current', - array('controller' => 'customers', 'action' => 'current'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Past', - array('controller' => 'customers', 'action' => 'past'), null, - 'CONTROLLER'); - $this->addSideMenuLink('All', - array('controller' => 'customers', 'action' => 'all'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Add Customer', - array('controller' => 'customers', 'action' => 'add'), null, - 'CONTROLLER'); - } @@ -40,6 +27,25 @@ class CustomersController extends AppController { function past() { $this->gridView('Past Tenants'); } function all() { $this->gridView('All Customers'); } + function gridView($title, $action = null, $element = null) { + $this->addSideMenuLink('Current', + array('controller' => 'customers', 'action' => 'current'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Past', + array('controller' => 'customers', 'action' => 'past'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'customers', 'action' => 'all'), null, + 'CONTROLLER'); + + $this->sideMenuAreaName('Creation', 'ACTION', $this->new_area); + $this->addSideMenuLink('New Customer', + array('controller' => 'customers', 'action' => 'add'), null, + 'ACTION', $this->new_area); + + parent::gridView($title, $action, $element); + } + /************************************************************************** ************************************************************************** diff --git a/site/controllers/leases_controller.php b/site/controllers/leases_controller.php index e109f38..9891624 100644 --- a/site/controllers/leases_controller.php +++ b/site/controllers/leases_controller.php @@ -12,18 +12,6 @@ class LeasesController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); - $this->addSideMenuLink('Active', - array('controller' => 'leases', 'action' => 'active'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Closed', - array('controller' => 'leases', 'action' => 'closed'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Delinquent', - array('controller' => 'leases', 'action' => 'delinquent'), null, - 'CONTROLLER'); - $this->addSideMenuLink('All', - array('controller' => 'leases', 'action' => 'all'), null, - 'CONTROLLER'); } @@ -40,6 +28,22 @@ class LeasesController extends AppController { function closed() { $this->gridView('Closed Leases'); } function all() { $this->gridView('All Leases', 'all'); } + function gridView($title, $action = null, $element = null) { + $this->addSideMenuLink('Active', + array('controller' => 'leases', 'action' => 'active'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Closed', + array('controller' => 'leases', 'action' => 'closed'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Delinquent', + array('controller' => 'leases', 'action' => 'delinquent'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'leases', 'action' => 'all'), null, + 'CONTROLLER'); + parent::gridView($title, $action, $element); + } + /************************************************************************** ************************************************************************** diff --git a/site/controllers/ledgers_controller.php b/site/controllers/ledgers_controller.php index eddcfa0..4d90571 100644 --- a/site/controllers/ledgers_controller.php +++ b/site/controllers/ledgers_controller.php @@ -12,15 +12,6 @@ class LedgersController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); - $this->addSideMenuLink('Current', - array('controller' => 'ledgers', 'action' => 'current'), null - 'CONTROLLER'); - $this->addSideMenuLink('Closed', - array('controller' => 'ledgers', 'action' => 'closed'), null, - 'CONTROLLER'); - $this->addSideMenuLink('All', - array('controller' => 'ledgers', 'action' => 'all'), null, - 'CONTROLLER'); } @@ -36,6 +27,19 @@ class LedgersController extends AppController { function closed() { $this->gridView('Closed Ledgers'); } function all() { $this->gridView('All Ledgers', 'all'); } + function gridView($title, $action = null, $element = null) { + $this->addSideMenuLink('Current', + array('controller' => 'ledgers', 'action' => 'current'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Closed', + array('controller' => 'ledgers', 'action' => 'closed'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'ledgers', 'action' => 'all'), null, + 'CONTROLLER'); + parent::gridView($title, $action, $element); + } + /************************************************************************** ************************************************************************** diff --git a/site/controllers/transactions_controller.php b/site/controllers/transactions_controller.php index 12382ca..0ea74b9 100644 --- a/site/controllers/transactions_controller.php +++ b/site/controllers/transactions_controller.php @@ -14,18 +14,6 @@ class TransactionsController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); - $this->addSideMenuLink('Invoices', - array('controller' => 'transactions', 'action' => 'invoice'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Receipts', - array('controller' => 'transactions', 'action' => 'receipt'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Deposits', - array('controller' => 'transactions', 'action' => 'deposit'), null, - 'CONTROLLER'); - $this->addSideMenuLink('All', - array('controller' => 'transactions', 'action' => 'all'), null, - 'CONTROLLER'); } @@ -41,12 +29,29 @@ class TransactionsController extends AppController { function invoice() { $this->gridView('Invoices'); } function receipt() { $this->gridView('Receipts'); } function deposit() { + if (empty($this->params['admin'])) + $this->sideMenuEnable('CONTROLLER', $this->std_area, false); $this->addSideMenuLink('New Deposit', array('controller' => 'tenders', 'action' => 'deposit'), null, 'ACTION'); $this->gridView('Deposits'); } + function gridView($title, $action = null, $element = null) { + $this->addSideMenuLink('Invoices', + array('controller' => 'transactions', 'action' => 'invoice'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Receipts', + array('controller' => 'transactions', 'action' => 'receipt'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Deposits', + array('controller' => 'transactions', 'action' => 'deposit'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'transactions', 'action' => 'all'), null, + 'CONTROLLER'); + parent::gridView($title, $action, $element); + } /************************************************************************** ************************************************************************** diff --git a/site/controllers/units_controller.php b/site/controllers/units_controller.php index cd5c4f9..9fc9a03 100644 --- a/site/controllers/units_controller.php +++ b/site/controllers/units_controller.php @@ -12,18 +12,6 @@ class UnitsController extends AppController { function addDefaultSideMenuLinks() { parent::addDefaultSideMenuLinks(); - $this->addSideMenuLink('Occupied', - array('controller' => 'units', 'action' => 'occupied'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Vacant', - array('controller' => 'units', 'action' => 'vacant'), null, - 'CONTROLLER'); - $this->addSideMenuLink('Unavailable', - array('controller' => 'units', 'action' => 'unavailable'), null, - 'CONTROLLER'); - $this->addSideMenuLink('All', - array('controller' => 'units', 'action' => 'all'), null, - 'CONTROLLER'); } @@ -40,6 +28,21 @@ class UnitsController extends AppController { function occupied() { $this->gridView('Occupied Units'); } function all() { $this->gridView('All Units', 'all'); } + function gridView($title, $action = null, $element = null) { + $this->addSideMenuLink('Occupied', + array('controller' => 'units', 'action' => 'occupied'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Vacant', + array('controller' => 'units', 'action' => 'vacant'), null, + 'CONTROLLER'); + $this->addSideMenuLink('Unavailable', + array('controller' => 'units', 'action' => 'unavailable'), null, + 'CONTROLLER'); + $this->addSideMenuLink('All', + array('controller' => 'units', 'action' => 'all'), null, + 'CONTROLLER'); + parent::gridView($title, $action, $element); + } /************************************************************************** ************************************************************************** From 86b0c14edaa22317469fe993b84c339f7e09ed57 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 00:16:04 +0000 Subject: [PATCH 004/103] Eliminated the ID field from the grids, wherever feasible. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@736 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/ledgers_controller.php | 2 +- site/views/elements/accounts.ctp | 3 +- site/views/elements/contacts.ctp | 3 +- site/views/elements/customers.ctp | 3 +- site/views/elements/double_entries.ctp | 116 ------------------------ site/views/elements/ledgers.ctp | 2 +- site/views/elements/maps.ctp | 3 +- site/views/elements/tenders.ctp | 1 - site/views/elements/units.ctp | 3 +- 9 files changed, 7 insertions(+), 129 deletions(-) delete mode 100644 site/views/elements/double_entries.ctp diff --git a/site/controllers/ledgers_controller.php b/site/controllers/ledgers_controller.php index 4d90571..13b46cd 100644 --- a/site/controllers/ledgers_controller.php +++ b/site/controllers/ledgers_controller.php @@ -113,7 +113,7 @@ class LedgersController extends AppController { } function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { - $links['Ledger'] = array('id_sequence'); + $links['Ledger'] = array('name'); $links['Account'] = array('name'); return parent::gridDataPostProcessLinks($params, $model, $records, $links); } diff --git a/site/views/elements/accounts.ctp b/site/views/elements/accounts.ctp index 6396a73..bb6d4c8 100644 --- a/site/views/elements/accounts.ctp +++ b/site/views/elements/accounts.ctp @@ -2,7 +2,6 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'Account.id', 'formatter' => 'id'); $cols['Name'] = array('index' => 'Account.name', 'formatter' => 'longname'); $cols['Type'] = array('index' => 'Account.type', 'formatter' => 'enum'); $cols['Entries'] = array('index' => 'entries', 'formatter' => 'number'); @@ -15,7 +14,7 @@ $cols['Comment'] = array('index' => 'Account.comment', 'formatter' => 'comment $grid ->columns($cols) ->sortField('Name') -->defaultFields(array('ID', 'Name')) +->defaultFields(array('Name')) ->searchFields(array('Name')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array('Comment'))); diff --git a/site/views/elements/contacts.ctp b/site/views/elements/contacts.ctp index 6b41c25..92c36a7 100644 --- a/site/views/elements/contacts.ctp +++ b/site/views/elements/contacts.ctp @@ -2,7 +2,6 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'Contact.id', 'formatter' => 'id'); $cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'name'); $cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'name'); $cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname'); @@ -14,7 +13,7 @@ $cols['Comment'] = array('index' => 'Contact.comment', 'formatter' = $grid ->columns($cols) ->sortField('Last Name') -->defaultFields(array('ID', 'Last Name', 'First Name')) +->defaultFields(array('Last Name', 'First Name')) ->searchFields(array('Last Name', 'First Name', 'Company')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array('Type', 'Active', 'Comment'))); diff --git a/site/views/elements/customers.ctp b/site/views/elements/customers.ctp index 0e25850..b0d2702 100644 --- a/site/views/elements/customers.ctp +++ b/site/views/elements/customers.ctp @@ -2,7 +2,6 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'Customer.id', 'formatter' => 'id'); $cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum'); $cols['Name'] = array('index' => 'Customer.name', 'formatter' => 'longname'); $cols['Last Name'] = array('index' => 'PrimaryContact.last_name', 'formatter' => 'name'); @@ -20,7 +19,7 @@ if (!isset($config['filter']['Contact.id'])) $grid ->columns($cols) ->sortField('Name') -->defaultFields(array('ID', 'Name')) +->defaultFields(array('Name')) ->searchFields(array('Name', 'Last Name', 'First Name')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array('Comment'))); diff --git a/site/views/elements/double_entries.ctp b/site/views/elements/double_entries.ctp deleted file mode 100644 index fe2c5a4..0000000 --- a/site/views/elements/double_entries.ctp +++ /dev/null @@ -1,116 +0,0 @@ - 'Transaction.id', 'formatter' => 'id'); -$cols['Entry'] = array('index' => 'LedgerEntry.id', 'formatter' => 'id'); - -$cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); -$cols['Effective'] = array('index' => 'LedgerEntry.effective_date', 'formatter' => 'date'); -$cols['Through'] = array('index' => 'LedgerEntry.through_date', 'formatter' => 'date'); - -$cols['Account'] = array('index' => 'Account.name', 'formatter' => 'name'); -$cols['Debit Account'] = array('index' => 'DebitAccount.name', 'formatter' => 'name'); -$cols['Credit Account'] = array('index' => 'CreditAccount.name', 'formatter' => 'name'); - -$cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname'); -$cols['Lease'] = array('index' => 'Lease.number', 'formatter' => 'id'); -$cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'name'); - -$cols['Source'] = array('index' => 'MonetarySource.name', 'formatter' => 'name'); -$cols['Comment'] = array('index' => 'LedgerEntry.comment', 'formatter' => 'comment', 'width'=>150); - -$cols['Amount'] = array('index' => 'LedgerEntry.amount', 'formatter' => 'currency'); -$cols['Debit'] = array('index' => 'debit', 'formatter' => 'currency'); -$cols['Credit'] = array('index' => 'credit', 'formatter' => 'currency'); - -$cols['Last Payment'] = array('index' => 'last_paid', 'formatter' => 'date'); -$cols['Applied'] = array('index' => "applied", 'formatter' => 'currency'); -$cols['Sub-Total'] = array('index' => 'subtotal-LedgerEntry.amount', 'formatter' => 'currency', 'sortable' => false); - - -if (isset($transaction_id) || isset($reconcile_id)) - $grid->invalidFields('Transaction'); - -if (!isset($collected_account_id)) - $grid->invalidFields('Last Payment'); - -if (isset($account_ftype) || isset($ledger_id) || isset($account_id) || isset($ar_account) || isset($customer_id)) - $grid->invalidFields(array('Debit Account', 'Credit Account')); -else - $grid->invalidFields('Account'); - -if (isset($no_account) || $group_by_tx || isset($collected_account_id)) - $grid->invalidFields(array('Account', 'Debit Account', 'Credit Account')); - -if (isset($ledger_id) || isset($account_id) || isset($ar_account) || isset($customer_id)) { - $grid->invalidFields('Amount'); - $cols['Sub-Total']['index'] = 'subtotal-balance'; -} else { - $grid->invalidFields(array('Debit', 'Credit')); - $cols['Sub-Total']['index'] = 'subtotal-LedgerEntry.amount'; -} - -// group_by_tx SHOULD wipe out Customer, but the reality -// is that it works good at the present, so we'll leave it. -if (isset($lease_id) || isset($customer_id)) - $grid->invalidFields(array('Customer')); - -if (isset($lease_id) || $group_by_tx) - $grid->invalidFields(array('Lease', 'Unit')); - -if (!isset($reconcile_id) && !isset($collected_account_id)) - $grid->invalidFields('Applied'); -else - $cols['Sub-Total']['index'] = 'subtotal-applied'; - -if (isset($account_ftype) || isset($collected_account_id)) - $grid->invalidFields('Sub-Total'); - - -// Now that columns are defined, establish basic grid parameters -$grid -->columns($cols) -->sortField('Date') -->defaultFields(array('Entry', 'Date', 'Amount', 'Credit', 'Debit')); - - -if (!isset($config['rows']) && !isset($collected_account_id)) { - $config['action'] = 'ledger'; - $grid->limit(50); -} - -if (isset($reconcile_id)) { - $config['action'] = 'reconcile'; - $grid->customData(compact('reconcile_id'))->limit(20); -} - -if (isset($collected_account_id)) { - $config['action'] = 'collected'; - $account_id = $collected_account_id; - $grid->limit(50); - $grid->sortField('Last Payment'); -} - -if (isset($entry_ids)) - $grid->id_list($entry_ids); - -// Set up search fields if requested by caller -if (isset($searchfields)) - $grid->searchFields(array('Customer', 'Unit')); - -// Include custom data -$grid->customData(compact('ledger_id', 'account_id', 'ar_account', - 'account_type', 'account_ftype', 'monetary_source_id', - 'customer_id', 'lease_id', 'transaction_id', 'group_by_tx')); - -// Render the grid -$grid -->render($this, isset($config) ? $config : null, - array('Transaction', 'Entry', 'Date', 'Effective', 'Last Payment', - 'Account', 'Debit Account', 'Credit Account', - 'Customer', 'Unit', - 'Comment', - 'Amount', 'Debit', 'Credit', - 'Applied', 'Sub-Total') - ); diff --git a/site/views/elements/ledgers.ctp b/site/views/elements/ledgers.ctp index d20ce13..e3ed4b0 100644 --- a/site/views/elements/ledgers.ctp +++ b/site/views/elements/ledgers.ctp @@ -2,7 +2,7 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'id_sequence', 'formatter' => 'id'); +$cols['ID'] = array('index' => 'id_sequence', 'formatter' => 'id', 'hidden' => true); $cols['Name'] = array('index' => 'Ledger.name', 'formatter' => 'name'); $cols['Account'] = array('index' => 'Account.name', 'formatter' => 'longname'); $cols['Open Date'] = array('index' => 'PriorCloseTransaction.stamp', 'formatter' => 'date'); diff --git a/site/views/elements/maps.ctp b/site/views/elements/maps.ctp index 4b467c1..71a13b3 100644 --- a/site/views/elements/maps.ctp +++ b/site/views/elements/maps.ctp @@ -2,7 +2,6 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'Map.id', 'formatter' => 'id'); $cols['Name'] = array('index' => 'Map.name', 'formatter' => 'longname'); $cols['Site Area'] = array('index' => 'SiteArea.name', 'formatter' => 'longname'); $cols['Width'] = array('index' => 'Map.width', 'formatter' => 'number'); @@ -13,7 +12,7 @@ $cols['Comment'] = array('index' => 'Map.comment', 'formatter' => 'comment $grid ->columns($cols) ->sortField('Name') -->defaultFields(array('ID', 'Name')) +->defaultFields(array('Name')) ->searchFields(array('Name')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array())); diff --git a/site/views/elements/tenders.ctp b/site/views/elements/tenders.ctp index e78f20f..312551b 100644 --- a/site/views/elements/tenders.ctp +++ b/site/views/elements/tenders.ctp @@ -2,7 +2,6 @@ // Define the table columns $cols = array(); -//$cols['ID'] = array('index' => 'Tender.id', 'formatter' => 'id'); $cols['Date'] = array('index' => 'Transaction.stamp', 'formatter' => 'date'); $cols['Customer'] = array('index' => 'Customer.name', 'formatter' => 'longname'); $cols['Item'] = array('index' => 'Tender.name', 'formatter' => 'longname'); diff --git a/site/views/elements/units.ctp b/site/views/elements/units.ctp index b5b5220..9ede8e6 100644 --- a/site/views/elements/units.ctp +++ b/site/views/elements/units.ctp @@ -4,7 +4,6 @@ $cols = array(); $cols['Sort'] = array('index' => 'Unit.sort_order', 'hidden' => true); $cols['Walk'] = array('index' => 'Unit.walk_order', 'formatter' => 'number'); -$cols['ID'] = array('index' => 'Unit.id', 'formatter' => 'id'); $cols['Unit'] = array('index' => 'Unit.name', 'formatter' => 'shortname'); $cols['Size'] = array('index' => 'UnitSize.name', 'formatter' => 'shortname'); $cols['Rent'] = array('index' => 'Unit.rent', 'formatter' => 'currency'); @@ -17,7 +16,7 @@ $cols['Comment'] = array('index' => 'Unit.comment', 'formatter' => 'comment'); $grid ->columns($cols) ->sortField('Sort') -->defaultFields(array('Sort', 'ID', 'Unit')) +->defaultFields(array('Sort', 'Unit')) ->searchFields(array('Unit', 'Size', 'Status')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array('Walk', 'Deposit', 'Comment'))); From 24e208bf1779b1802aec5e0e4bf701af99bc7697 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 00:38:18 +0000 Subject: [PATCH 005/103] More cleanup to hide ID from the user except where ID is intended to be the externally visible identification method (like transactions and ledger/statement entries). git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@737 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/ledgers_controller.php | 15 ++-- .../statement_entries_controller.php | 2 +- site/views/accounts/view.ctp | 1 - site/views/double_entries/view.ctp | 79 +++---------------- site/views/elements/ledgers.ctp | 7 +- site/views/leases/view.ctp | 1 - site/views/ledgers/view.ctp | 2 - site/views/statement_entries/view.ctp | 2 +- site/views/tenders/view.ctp | 3 +- 9 files changed, 22 insertions(+), 90 deletions(-) diff --git a/site/controllers/ledgers_controller.php b/site/controllers/ledgers_controller.php index 13b46cd..7ab3e6a 100644 --- a/site/controllers/ledgers_controller.php +++ b/site/controllers/ledgers_controller.php @@ -97,17 +97,14 @@ class LedgersController extends AppController { } function gridDataOrder(&$params, &$model, $index, $direction) { - $id_sequence = false; - if ($index === 'id_sequence') { - $id_sequence = true; - $index = 'Ledger.account_id'; - } - $order = parent::gridDataOrder($params, $model, $index, $direction); - if ($id_sequence) { - $order[] = 'Ledger.sequence ' . $direction; - } + // After sorting by whatever the user wants, add these + // defaults into the sort mechanism. If we're already + // sorting by one of them, it will only be redundant, + // and should cause no harm (possible a longer query?) + $order[] = 'Account.name ' . $direction; + $order[] = 'Ledger.sequence ' . $direction; return $order; } diff --git a/site/controllers/statement_entries_controller.php b/site/controllers/statement_entries_controller.php index 1fa76fb..2682bea 100644 --- a/site/controllers/statement_entries_controller.php +++ b/site/controllers/statement_entries_controller.php @@ -255,7 +255,7 @@ class StatementEntriesController extends AppController { ('Transaction' => array('fields' => array('id', 'type', 'stamp')), 'Account' => array('id', 'name', 'type'), 'Customer' => array('fields' => array('id', 'name')), - 'Lease' => array('fields' => array('id')), + 'Lease' => array('fields' => array('id', 'number')), ), 'conditions' => array(array('StatementEntry.id' => $id), diff --git a/site/views/accounts/view.ctp b/site/views/accounts/view.ctp index 897ab78..a5d7377 100644 --- a/site/views/accounts/view.ctp +++ b/site/views/accounts/view.ctp @@ -16,7 +16,6 @@ if (isset($account['Account'])) $account = $account['Account']; $rows = array(); -$rows[] = array('ID', $account['id']); $rows[] = array('Name', $account['name']); $rows[] = array('Type', $account['type']); $rows[] = array('External Name', $account['external_name']); diff --git a/site/views/double_entries/view.ctp b/site/views/double_entries/view.ctp index 0d1bb44..112a513 100644 --- a/site/views/double_entries/view.ctp +++ b/site/views/double_entries/view.ctp @@ -1,50 +1,17 @@ ' . "\n"; +echo '
' . "\n"; -// The two entry ids, debit and credit, are actually individual +// The two entries, debit and credit, are actually individual // entries in separate accounts (each make up one of the two -// entries required for "double entry"). This, when we provide -// reconcile information, we're really providing reconcile info -// for two independent accounts. The reconciling entries, -// therefore, are those on the opposite side of the ledger in -// each account. For example, assume this "double" entry is -// -// debit: A/R credit: Cash amount: 55 -// -// Then, our accounts might look like: -// -// RENT TAX A/R CASH BANK -// ------- ------- ------- ------- ------- -// |20 | 20| | | <-- Unrelated -// | | |20 20| | <-- Unrelated -// | | | | | -// |50 | 50| | | <-- Rent paid by this entry -// | |5 5| | | <-- Tax paid by this entry -// | | |55 55| | <-- THIS ENTRY -// | | | | | -// | | | |75 75| <-- Deposit includes this entry -// | | | | | -// -// In this case, we're looking to provide reconcile information -// of A/R for (the credit side of) this entry, and also of Cash -// (for the debit side). Taking the accounts as individual -// entries, instead of the "double entry" representation in the -// database, we're actually providing information on the two -// A/R entries, 50 & 5, which are both debits, i.e. opposite -// entries to the credit of A/R. The cash account entry -// reconciles against the credit of 75. Again, this is the -// opposite entry to the debit of Cash. -// -// Thus, for our debit_ledger_id, we're reconciling against -// credits, and for our credit_ledger_id, against debits. +// entries required for "double entry"). /********************************************************************** ********************************************************************** ********************************************************************** ********************************************************************** - * LedgerEntry Detail Main Section + * DoubleEntry Detail Main Section */ $transaction = $entry['Transaction']; @@ -55,7 +22,6 @@ $entries = array('debit' => $entry['DebitEntry'], $entry = $entry['DoubleEntry']; $rows = array(); -$rows[] = array('ID', $entry['id']); $rows[] = array('Transaction', $html->link('#'.$transaction['id'], array('controller' => 'transactions', 'action' => 'view', @@ -64,41 +30,17 @@ $rows[] = array('Timestamp', FormatHelper::datetime($transaction['stamp'] $rows[] = array('Comment', $entry['comment']); echo $this->element('table', - array('class' => 'item ledger-entry detail', - 'caption' => 'Double Ledger Entry Detail', + array('class' => 'item double-entry detail', + 'caption' => 'Double Ledger Entry', 'rows' => $rows, 'column_class' => array('field', 'value'))); + /********************************************************************** - * LedgerEntry Info Box + * Debit/Credit Entries */ -/* echo '
' . "\n"; */ -/* foreach ($ledgers AS $type => $ledger) { */ -/* //pr($ledger); */ -/* if (!$ledger['Account']['trackable']) */ -/* continue; */ - -/* $applied_caption = "Transfers applied"; */ -/* $remaining_caption = "Unapplied amount"; */ - -/* $rows = array(); */ -/* $rows[] = array($applied_caption, */ -/* FormatHelper::currency($stats[$type]['amount_reconciled'])); */ -/* $rows[] = array($remaining_caption, */ -/* FormatHelper::currency($stats[$type]['amount_remaining'])); */ -/* echo $this->element('table', */ -/* array('class' => 'item summary', */ -/* 'caption' => "{$ledger['Account']['name']} Ledger Entry", */ -/* 'rows' => $rows, */ -/* 'column_class' => array('field', 'value'), */ -/* //'suppress_alternate_rows' => true, */ -/* )); */ -/* } */ - -/* echo '
' . "\n"; */ - echo ('
' . "\n"); foreach ($ledgers AS $type => $ledger) { $rows = array(); @@ -118,8 +60,7 @@ foreach ($ledgers AS $type => $ledger) { array('controller' => 'accounts', 'action' => 'view', $ledger['Account']['id']))); - $rows[] = array('Ledger', $html->link('#' . $ledger['Account']['id'] - . '-' . $ledger['sequence'], + $rows[] = array('Ledger', $html->link('#' . $ledger['sequence'], array('controller' => 'ledgers', 'action' => 'view', $ledger['id']))); @@ -128,7 +69,7 @@ foreach ($ledgers AS $type => $ledger) { echo $this->element('table', array('class' => array('item', $type, 'detail'), - 'caption' => ucfirst($type) . ' Ledger Entry', + 'caption' => ucfirst($type) . ' Entry', 'rows' => $rows, 'column_class' => array('field', 'value'))); } diff --git a/site/views/elements/ledgers.ctp b/site/views/elements/ledgers.ctp index e3ed4b0..e83695c 100644 --- a/site/views/elements/ledgers.ctp +++ b/site/views/elements/ledgers.ctp @@ -2,9 +2,8 @@ // Define the table columns $cols = array(); -$cols['ID'] = array('index' => 'id_sequence', 'formatter' => 'id', 'hidden' => true); -$cols['Name'] = array('index' => 'Ledger.name', 'formatter' => 'name'); $cols['Account'] = array('index' => 'Account.name', 'formatter' => 'longname'); +$cols['Sequence'] = array('index' => 'Ledger.sequence', 'formatter' => 'id'); $cols['Open Date'] = array('index' => 'PriorCloseTransaction.stamp', 'formatter' => 'date'); $cols['Close Date'] = array('index' => 'CloseTransaction.stamp', 'formatter' => 'date'); $cols['Comment'] = array('index' => 'Ledger.comment', 'formatter' => 'comment'); @@ -16,8 +15,8 @@ $cols['Balance'] = array('index' => 'balance', 'formatter' => 'c // Render the grid $grid ->columns($cols) -->sortField('ID', 'ASC') -->defaultFields(array('ID', 'Name', 'Account')) +->sortField('Account') +->defaultFields(array('Account', 'Sequence')) ->searchFields(array('Account', 'Comment')) ->render($this, isset($config) ? $config : null, array_diff(array_keys($cols), array('Open Date', 'Comment'))); diff --git a/site/views/leases/view.ctp b/site/views/leases/view.ctp index b68767c..fbdaeb7 100644 --- a/site/views/leases/view.ctp +++ b/site/views/leases/view.ctp @@ -18,7 +18,6 @@ if (isset($lease['Lease'])) $rows = array(); -$rows[] = array('ID', $lease['id']); $rows[] = array('Number', $lease['number']); $rows[] = array('Lease Type', $lease_type['name']); $rows[] = array('Unit', $html->link($unit['name'], diff --git a/site/views/ledgers/view.ctp b/site/views/ledgers/view.ctp index a8a00f5..8622ed6 100644 --- a/site/views/ledgers/view.ctp +++ b/site/views/ledgers/view.ctp @@ -16,8 +16,6 @@ if (isset($ledger['Ledger'])) $ledger = $ledger['Ledger']; $rows = array(); -$rows[] = array('ID', $ledger['id']); -$rows[] = array('Name', $ledger['name']); $rows[] = array('Account', $html->link($account['name'], array('controller' => 'accounts', 'action' => 'view', diff --git a/site/views/statement_entries/view.ctp b/site/views/statement_entries/view.ctp index 2a325c0..9f38323 100644 --- a/site/views/statement_entries/view.ctp +++ b/site/views/statement_entries/view.ctp @@ -40,7 +40,7 @@ $rows[] = array('Customer', (isset($customer['name']) $customer['id'])) : null)); $rows[] = array('Lease', (isset($lease['id']) - ? $html->link('#'.$lease['id'], + ? $html->link('#'.$lease['number'], array('controller' => 'leases', 'action' => 'view', $lease['id'])) diff --git a/site/views/tenders/view.ctp b/site/views/tenders/view.ctp index 335fccc..2b7e7c1 100644 --- a/site/views/tenders/view.ctp +++ b/site/views/tenders/view.ctp @@ -16,14 +16,13 @@ $transaction = $entry['Transaction']; $tender = $tender['Tender']; $rows = array(); -$rows[] = array('ID', $tender['id']); +$rows[] = array('Item', $tender['name']); $rows[] = array('Received', FormatHelper::date($transaction['stamp'])); $rows[] = array('Customer', $html->link($customer['name'], array('controller' => 'customers', 'action' => 'view', $customer['id']))); $rows[] = array('Amount', FormatHelper::currency($entry['amount'])); -$rows[] = array('Item', $tender['name']); $rows[] = array('Type', $ttype['name']); /* $rows[] = array('Type', $html->link($ttype['name'], */ /* array('controller' => 'tender_types', */ From 9a819c72a815f5913bf413dfd62307222797d981 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 00:54:22 +0000 Subject: [PATCH 006/103] Tidied up where we show transaction ids vs. statement/ledger entry ids git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@738 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/customers/view.ctp | 3 ++- site/views/elements/ledger_entries.ctp | 3 ++- site/views/elements/statement_entries.ctp | 2 +- site/views/leases/view.ctp | 3 ++- site/views/statement_entries/view.ctp | 1 - 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/site/views/customers/view.ctp b/site/views/customers/view.ctp index 19e468f..a96d9b7 100644 --- a/site/views/customers/view.ctp +++ b/site/views/customers/view.ctp @@ -107,7 +107,8 @@ echo $this->element('ledger_entries', array 'Tender.id !=' => null, //'Account.id !=' => '-AR-' ), - 'exclude' => array('Account', 'Cr/Dr'), + 'include' => array('Transaction'), + 'exclude' => array('Entry', 'Account', 'Cr/Dr'), 'sort_column' => 'Date', 'sort_order' => 'DESC', ))); diff --git a/site/views/elements/ledger_entries.ctp b/site/views/elements/ledger_entries.ctp index d41c7d2..2924b1e 100644 --- a/site/views/elements/ledger_entries.ctp +++ b/site/views/elements/ledger_entries.ctp @@ -26,5 +26,6 @@ $grid ->defaultFields(array('Entry', 'Date', 'Amount')) ->searchFields(array('Customer', 'Unit')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array('Debit', 'Credit', 'Balance', 'Sub-Total', 'Comment'))); + array_diff(array_keys($cols), array('Transaction', 'Debit', 'Credit', + 'Balance', 'Sub-Total', 'Comment'))); diff --git a/site/views/elements/statement_entries.ctp b/site/views/elements/statement_entries.ctp index 67fafd8..f094838 100644 --- a/site/views/elements/statement_entries.ctp +++ b/site/views/elements/statement_entries.ctp @@ -42,7 +42,7 @@ $grid ->defaultFields(array('Entry', 'Date', 'Charge', 'Payment')) ->searchFields(array('Customer', 'Unit')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array('Through', 'Lease', + array_diff(array_keys($cols), array('Transaction', 'Through', 'Lease', 'Amount', 'Applied', 'Balance', 'Sub-Total', 'Comment'))); diff --git a/site/views/leases/view.ctp b/site/views/leases/view.ctp index fbdaeb7..8f7b265 100644 --- a/site/views/leases/view.ctp +++ b/site/views/leases/view.ctp @@ -107,7 +107,8 @@ echo $this->element('ledger_entries', array 'Tender.id !=' => null, //'Account.id !=' => '-AR-' ), - 'exclude' => array('Account', 'Cr/Dr'), + 'include' => array('Transaction'), + 'exclude' => array('Entry', 'Account', 'Cr/Dr'), 'sort_column' => 'Date', 'sort_order' => 'DESC', ))); diff --git a/site/views/statement_entries/view.ctp b/site/views/statement_entries/view.ctp index 9f38323..1e030a3 100644 --- a/site/views/statement_entries/view.ctp +++ b/site/views/statement_entries/view.ctp @@ -115,7 +115,6 @@ echo $this->element('statement_entries', array 'config' => array ('caption' => $applied_caption, //'filter' => array('id' => $entry['id']), - 'exclude' => array('Transaction'), ))); From 1d921358a8fc0a10801d0f17b5210dfc0c8c032f Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 01:02:28 +0000 Subject: [PATCH 007/103] Changed statement/ledger entries to defaultly sort by date in descending order. For small lists, ascending order is more logical, but for larger lists, this buries the most relevant items at the very back. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@739 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/customers/view.ctp | 6 ++---- site/views/elements/ledger_entries.ctp | 2 +- site/views/elements/statement_entries.ctp | 2 +- site/views/leases/view.ctp | 4 ---- site/views/units/view.ctp | 4 ++-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/site/views/customers/view.ctp b/site/views/customers/view.ctp index a96d9b7..8a0bb48 100644 --- a/site/views/customers/view.ctp +++ b/site/views/customers/view.ctp @@ -75,6 +75,8 @@ echo $this->element('leases', array ('caption' => 'Lease History', 'filter' => array('Customer.id' => $customer['Customer']['id']), 'exclude' => array('Customer'), + 'sort_column' => 'Move-In', + 'sort_order' => 'DESC', ))); @@ -89,8 +91,6 @@ echo $this->element('statement_entries', array 'filter' => array('Customer.id' => $customer['Customer']['id'], 'type !=' => 'VOID'), 'exclude' => array('Customer'), - 'sort_column' => 'Effective', - 'sort_order' => 'DESC', ))); @@ -109,8 +109,6 @@ echo $this->element('ledger_entries', array ), 'include' => array('Transaction'), 'exclude' => array('Entry', 'Account', 'Cr/Dr'), - 'sort_column' => 'Date', - 'sort_order' => 'DESC', ))); diff --git a/site/views/elements/ledger_entries.ctp b/site/views/elements/ledger_entries.ctp index 2924b1e..1ccd3ac 100644 --- a/site/views/elements/ledger_entries.ctp +++ b/site/views/elements/ledger_entries.ctp @@ -22,7 +22,7 @@ $cols['Sub-Total'] = array('index' => 'subtotal-balance', 'formatter' => $grid ->limit(50) ->columns($cols) -->sortField('Date') +->sortField('Date', 'DESC') ->defaultFields(array('Entry', 'Date', 'Amount')) ->searchFields(array('Customer', 'Unit')) ->render($this, isset($config) ? $config : null, diff --git a/site/views/elements/statement_entries.ctp b/site/views/elements/statement_entries.ctp index f094838..f97b2aa 100644 --- a/site/views/elements/statement_entries.ctp +++ b/site/views/elements/statement_entries.ctp @@ -38,7 +38,7 @@ $grid->customData(compact('statement_entry_id')); // Render the grid $grid ->columns($cols) -->sortField('Date') +->sortField('Date', 'DESC') ->defaultFields(array('Entry', 'Date', 'Charge', 'Payment')) ->searchFields(array('Customer', 'Unit')) ->render($this, isset($config) ? $config : null, diff --git a/site/views/leases/view.ctp b/site/views/leases/view.ctp index 8f7b265..cca4f79 100644 --- a/site/views/leases/view.ctp +++ b/site/views/leases/view.ctp @@ -89,8 +89,6 @@ echo $this->element('statement_entries', array 'filter' => array('Lease.id' => $lease['id']), 'include' => array('Through'), 'exclude' => array('Customer', 'Lease', 'Unit'), - 'sort_column' => 'Effective', - 'sort_order' => 'DESC', ))); @@ -109,8 +107,6 @@ echo $this->element('ledger_entries', array ), 'include' => array('Transaction'), 'exclude' => array('Entry', 'Account', 'Cr/Dr'), - 'sort_column' => 'Date', - 'sort_order' => 'DESC', ))); diff --git a/site/views/units/view.ctp b/site/views/units/view.ctp index 7c644a0..469366a 100644 --- a/site/views/units/view.ctp +++ b/site/views/units/view.ctp @@ -68,6 +68,8 @@ echo $this->element('leases', array ('caption' => 'Lease History', 'filter' => array('Unit.id' => $unit['id']), 'exclude' => array('Unit'), + 'sort_column' => 'Move-In', + 'sort_order' => 'DESC', ))); @@ -87,8 +89,6 @@ if (isset($current_lease['id'])) { 'filter' => array('Lease.id' => $current_lease['id']), 'include' => array('Through'), 'exclude' => array('Customer', 'Lease', 'Unit'), - 'sort_column' => 'Effective', - 'sort_order' => 'DESC', ))); } From 2d3b962fe197866cd1b6826b2e74c16705b0afc9 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 01:08:30 +0000 Subject: [PATCH 008/103] Removing, or at least phasing out the ledger name field. Account name is always needed and nearby, so ledger name is just confusing. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@740 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/transactions_controller.php | 2 +- site/views/accounts/view.ctp | 5 ++--- site/views/ledger_entries/view.ctp | 2 +- site/views/transactions/view.ctp | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/site/controllers/transactions_controller.php b/site/controllers/transactions_controller.php index 0ea74b9..e80085c 100644 --- a/site/controllers/transactions_controller.php +++ b/site/controllers/transactions_controller.php @@ -398,7 +398,7 @@ class TransactionsController extends AppController { array('contain' => array(// Models 'Account(id,name)', - 'Ledger(id,name)', + 'Ledger(id,sequence)', 'NsfTender(id,name)', ), 'conditions' => array(array('Transaction.id' => $id), diff --git a/site/views/accounts/view.ctp b/site/views/accounts/view.ctp index a5d7377..6ced628 100644 --- a/site/views/accounts/view.ctp +++ b/site/views/accounts/view.ctp @@ -77,9 +77,8 @@ echo $this->element('ledger_entries', array (// Grid configuration 'config' => array ('grid_div_id' => 'ledger-ledger-entry-list', - 'caption' => ("Current Ledger: " . - "(". $current_ledger['name'] .")"), - 'filter' => array('Ledger.id' => $current_ledger['id']), + 'caption' => "Current Ledger: #{$current_ledger['sequence']}", + 'filter' => array('Ledger.id' => $current_ledger['id']), 'exclude' => array('Account', 'Amount', 'Cr/Dr', 'Balance', empty($account['receipts']) ? 'Tender' : null), 'include' => array('Debit', 'Credit', 'Sub-Total'), diff --git a/site/views/ledger_entries/view.ctp b/site/views/ledger_entries/view.ctp index 5e23907..90efa2c 100644 --- a/site/views/ledger_entries/view.ctp +++ b/site/views/ledger_entries/view.ctp @@ -33,7 +33,7 @@ $rows[] = array('Account', $html->link($account['name'], array('controller' => 'accounts', 'action' => 'view', $account['id']))); -$rows[] = array('Ledger', $html->link($ledger['name'], +$rows[] = array('Ledger', $html->link('#' . $ledger['sequence'], array('controller' => 'ledgers', 'action' => 'view', $ledger['id']))); diff --git a/site/views/transactions/view.ctp b/site/views/transactions/view.ctp index e6f1835..f2fc83b 100644 --- a/site/views/transactions/view.ctp +++ b/site/views/transactions/view.ctp @@ -25,7 +25,7 @@ $rows[] = array('Account', $html->link($account['name'], array('controller' => 'accounts', 'action' => 'view', $account['id']))); -$rows[] = array('Ledger', $html->link($ledger['name'], +$rows[] = array('Ledger', $html->link('#' . $ledger['sequence'], array('controller' => 'ledgers', 'action' => 'view', $ledger['id']))); From 4e1ffd14b4d84e2940f9e6ca4f01c01e4b902a50 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 04:16:43 +0000 Subject: [PATCH 009/103] Fixed the links and sorting for the contacts grid git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@741 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/contacts_controller.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index f9cb4e2..8d24e38 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -25,17 +25,19 @@ class ContactsController extends AppController { function gridDataOrder(&$params, &$model, $index, $direction) { $order = parent::gridDataOrder($params, $model, $index, $direction); - if ($index === 'Contact.last_name') { - $order[] = 'Contact.first_name ' . $direction; - } - if ($index === 'Contact.first_name') { - $order[] = 'Contact.last_name ' . $direction; - } + + // After sorting by whatever the user wants, add these + // defaults into the sort mechanism. If we're already + // sorting by one of them, it will only be redundant, + // and should cause no harm (possible a longer query?) + $order[] = 'Contact.last_name ' . $direction; + $order[] = 'Contact.first_name ' . $direction; + return $order; } function gridDataPostProcessLinks(&$params, &$model, &$records, $links) { - $links['Contact'] = array('id'); + $links['Contact'] = array('last_name', 'first_name'); return parent::gridDataPostProcessLinks($params, $model, $records, $links); } From 65c3f28484a87c031f9499c30c17754eb4d46361 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 14:39:15 +0000 Subject: [PATCH 010/103] Removed the sitelink script, which is of no use since the database now contains additional data. Modified the build script to rebuild the database from the last saved data set. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@743 97e9348a-65ac-dc4b-aefc-98561f571b83 --- build.cmd | 2 +- scripts/sitelink2pmgr.pl | 1603 -------------------------------------- 2 files changed, 1 insertion(+), 1604 deletions(-) delete mode 100644 scripts/sitelink2pmgr.pl diff --git a/build.cmd b/build.cmd index 8967c4e..5e84573 100644 --- a/build.cmd +++ b/build.cmd @@ -1,3 +1,3 @@ @echo off -%~dp0\scripts\sitelink2pmgr.pl %~dp0\db\schema.sql %~dp0db\vss.mdb %* +mysql --user=pmgr --password=pmgruser < %~dp0\db\property_manager.sql echo Done! diff --git a/scripts/sitelink2pmgr.pl b/scripts/sitelink2pmgr.pl deleted file mode 100644 index 13d222a..0000000 --- a/scripts/sitelink2pmgr.pl +++ /dev/null @@ -1,1603 +0,0 @@ -#perl -w -use strict; -use DBI; -use Data::Dumper; -use File::Copy; - -my $closing_one_transaction = 0; -my $work_from_scratch = 1; - -# Internally adjust all numbers coming from the database to -# be in inches. Not necessary to go to this detail, but the -# actual units used is irrelevant, provided everything is to -# scale, and this factor ensures that any fractional units -# become whole (e.g. 7.5 "feet" becomes 90 "units") -my $internal_adjustment_factor = 12; - -my $schema_file = shift || die("Must specify schema file\n"); -my $slink_file = shift || die("Must specify sitelink file\n"); - -my $slink_file = ";Data Source=$slink_file"; -my $slink_pass = ";Jet OLEDB:Database Password=2web"; -my $sdsn="Provider=Microsoft.Jet.OLEDB.4.0$slink_pass$slink_file"; -my $sdbh = DBI->connect("dbi:ADO:$sdsn", undef, undef, {PrintError => 1, - RaiseError => 1}); - -# Connect to the database. -my($hostname, $database, $user, $password) = ('localhost', - 'property_manager', - 'pmgr', 'pmgruser'); - -$database = shift if @ARGV; -$user = shift if @ARGV; -$password = shift if @ARGV; - -print "Connecting to $database as $user\n"; -my $db_handle = DBI->connect("DBI:mysql:database=$database;host=$hostname", - $user, $password, - {'PrintError' => 1, - 'RaiseError' => 0}); - - -$SIG{__DIE__} = \&Die; - -my ($query, $result, $nrows, $row); -my (%newdb) = ( 'schema' => [], - 'tables' => {}, - 'ids' => {}, - 'lookup' => {'state' => { 1=>'AK', 14=>'ID', 48=>'WA' }} ); - - -###################################################################### -###################################################################### -## Die - -sub Die { - my @text = @_; - warn "----------------------------------------------------------\n"; - warn "FATAL ERROR: @text\n"; - my $count = 0; - { - my ($package, $filename, $line, $sub) = caller($count); - last unless defined $line; - warn sprintf("%02i %5i %-35s %-20s\n", $count++, $line, $sub, - $filename); - redo; - } - exit 1; -} - - -###################################################################### -###################################################################### -## addRow - -sub addRow { - my ($table, $cols, $noid) = @_; - die unless $table; - die unless ref($cols) eq 'HASH'; - - die "Table `$table` is unknown!" - unless defined $newdb{'tables'}{$table}; - - my $id; - if ($noid) { - $id = $cols->{'id'}; - } - - if (!defined $id) { - $id = ++$newdb{'tables'}{$table}{'autoid'}; - } - - $cols->{'id'} = $id - unless ($noid); - - # For debug purposes - my $line = (caller())[2]; - $cols->{'--LINE--'} = "addRow called from line: $line"; - - $newdb{'tables'}{$table}{'rows'}[$id] = $cols; - return $id; -} - - -###################################################################### -###################################################################### -## updateRow - -sub updateRow { - my ($table, $id, $cols) = @_; - die unless $table; - die unless $id; - die unless ref($cols) eq 'HASH'; - - die "Table `$table` is unknown!" - unless defined $newdb{'tables'}{$table}; - - die "Table `$table` : ID `$id` does not exist!" - unless $newdb{'tables'}{$table}{'rows'}[$id]; - - # For debug purposes - my $line = (caller())[2]; - $cols->{'--UPDATE-LINE--'} = [] unless $cols->{'--UPDATE-LINE--'}; - push(@{$cols->{'--UPDATE-LINE--'}}, "updateRow called from line: $line"); - - #$newdb{'tables'}{$table}{'rows'}[$id] = $cols; - return $id; -} - - -###################################################################### -###################################################################### -## query - -sub query { - my ($dbh, $sql, $data, $ignore) = @_; - #print("$sql\n\n"); #return [ { 'id' => 7 } ]; - #print("$sql\n\n") if $sql =~ /^\s*UPDATE/i; - #return 1 unless $sql =~ /^\s*SELECT/i; - - my ($sth, $result); - if ($sql =~ /^\s*SELECT/i) { - $sth = $dbh->prepare($sql); - $sth->execute(); - $result = $sth->fetchall_arrayref({}); - } else { - $result = $dbh->do($sql); - } - - if (!$result && !$ignore) { - print STDERR "SQL Query FAILED:\n"; - print STDERR "$sql\n\n"; - print STDERR Dumper $data - if defined $data; - die; - } - return ($sth, $result); -} - - -###################################################################### -###################################################################### -## executeSchema - -sub executeSchema { - foreach (@{$newdb{'schema'}}) { - query($db_handle, $_); - } - - foreach my $table (values %{$newdb{'tables'}}) { - foreach (@{$table->{'schema'}}) { - query($db_handle, $_); - } - } -} - - -###################################################################### -###################################################################### -## buildTables - -sub buildTables { - foreach my $table_name (sort keys %{$newdb{'tables'}}) { - my $table = $newdb{'tables'}{$table_name}; - my $count = 0; - foreach (@{$table->{'rows'}}) { - next unless defined $_; - ++$count; - } - - printf("%-30s : %d rows\n", $table->{'name'}, $count); - - foreach (@{$table->{'rows'}}) { - next unless defined $_; - - my %row = %$_; - delete $row{'--LINE--'}; - - my $query; - $query = "INSERT INTO " . $table->{'name'}; - $query .= " (" . join(", ", map({"`$_`"} keys(%row))) . ")"; - $query .= " VALUES (" . join(", ", map({s/'/''/g if defined $_; - defined $_ - ? (/^\w+\(.*\)$/ - ? $_ - : "'$_'" ) - : "NULL" } - values(%row))) . ")"; - query($db_handle, $query, $_); - } - } -} - - -###################################################################### -###################################################################### -## helper functions - -sub sizeCode { - my ($width, $depth) = @_; - return "YARD" - if ($width == 12 && $depth == 40); - return "APARTMENT" - if ($width == 20 && $depth == 30); - return sprintf("%02dx%02d", $width, $depth); -} - -sub datefmt { - my ($dt) = @_; - return undef unless $dt; - my @dt = split(/\/|\s/, $dt); - #print("$dt : " . sprintf("%04d-%02d-%02d", $dt[2], $dt[0], $dt[1]) . "\n"); - return sprintf("%04d-%02d-%02d%s", $dt[2], $dt[0], $dt[1], $dt[3] ? ' '.$dt[3] : ""); -} - -sub dates { - my ($type, $dt, $dt_end, $comment, $ledger_id) = @_; - - # Nothing should be stamped before possession - my $stamp = $dt; - if ($stamp =~ m%^0?[12]/% || ($stamp =~ m%^0?3/(\d+)/% && $1 <= 25)) { - $stamp = "3/25/2009 16:00"; - } - - my $effective_dt = $dt; - my $through_dt = $dt_end; - - # Use different dates for security deposits - if ($type eq 'charge' && $comment eq 'Security Deposit') { - $effective_dt = $newdb{'lookup'}{'ledger'}{$ledger_id}{'lease_date'}; - $through_dt = undef; - } - - # REVISIT : 20090708 - # Do we want to have effective dates on invoices? - # Do we want to have effective dates for payments? - # The Receipt already has an effective date. - if ($type eq 'invoice') { - $effective_dt = undef; - $through_dt = undef; - } - - return (datefmt($stamp), datefmt($effective_dt), datefmt($through_dt)); -} - - -###################################################################### -###################################################################### -###################################################################### -###################################################################### -## BUILD THE DATABASE - -open(SCHEMA, "<$schema_file") || die ("Can't open schema ($!)\n"); -my $schema_query = ""; -my $table; -while () { - next if /^\s*--/; - if (/DROP\s+TABLE\s.*`?(pmgr_(\w+))/i) { - $table = $2; - $newdb{'tables'}{$table} = { 'name' => $1, - 'schema' => [], - 'autoid' => 0, - 'rows' => [] }; - } - - $schema_query .= $_; - if (/;\s*$/) { - $schema_query =~ s/^\s+//; - $schema_query =~ s/\s*;\s*$//; - if (!$table) { - push(@{$newdb{'schema'}}, $schema_query); - } else { - push(@{$newdb{'tables'}{$table}{'schema'}}, $schema_query); - } - $schema_query = ""; - } -} -close(SCHEMA); - -executeSchema(); - - -################################################################# -## Test Contact - -addRow('contacts', { - 'first_name' => 'Abijah', -# 'middle_name' => 'M', - 'last_name' => 'Perkins' }); - -addRow('contact_addresses', { - 'address' => '1324 N Liberty Lake Rd\nPMB 263', - 'city' => 'Liberty Lake', - 'state' => 'WA', - 'postcode' => '99019', - 'country' => 'USA' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'}, - 'method' => 'ADDRESS', - 'type' => 'MAIN', - 'preference' => 'PRIMARY' }, - 1); - -addRow('contact_addresses', { - 'address' => '5221 W Myrtlewood Ct', - 'city' => 'Spokane', - 'state' => 'WA', - 'postcode' => '99208', - 'country' => 'USA' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'}, - 'method' => 'ADDRESS', - 'type' => 'HOME', - 'preference' => 'ALTERNATE' }, - 1); - -# addRow('contact_addresses', -# { 'address' => 'PO Box 69', -# 'city' => 'Granger', -# 'state' => 'WA', -# 'postcode' => '98932', -# 'country' => 'USA' }); -# addRow('contacts_methods', -# { 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, -# 'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'}, -# 'method' => 'ADDRESS', -# 'type' => 'HOME', -# 'preference' => 'ALTERNATE' }, -# 1); - -addRow('contact_phones', { - 'type' => 'MOBILE', - 'phone' => '5098445573' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'MAIN', - 'preference' => 'PRIMARY' }, - 1); - -addRow('contact_phones', { - 'type' => 'MOBILE', - 'phone' => '5098445973' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'MAIN', - 'preference' => 'ALTERNATE' }, - 1); - -addRow('contact_phones', { - 'type' => 'VIRTUAL', - 'phone' => '5095901112' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'BUSINESS', - 'preference' => 'WORK' }, - 1); - -# addRow('contact_phones', -# { 'type' => 'LANDLINE', -# 'phone' => '5098541491' }); -# addRow('contacts_methods', -# { 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, -# 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, -# 'method' => 'PHONE', -# 'type' => 'HOME', -# 'preference' => 'ALTERNATE' }, -# 1); - -addRow('contact_phones', { - 'type' => 'VIRTUAL', - 'phone' => '8774488664' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'BUSINESS', - 'preference' => 'WORK' }, - 1); - -addRow('contact_phones', { - 'type' => 'FAX', - 'phone' => '8662960131' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'BUSINESS', - 'preference' => 'WORK' }, - 1); - -addRow('contact_emails', { - 'email' => 'abijah\@PerkinsHouse.com' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_emails'}{'autoid'}, - 'method' => 'EMAIL', - 'type' => 'HOME', - 'preference' => 'PRIMARY' }, - 1); - -addRow('contact_emails', { - 'email' => 'abijah\@PerkinsREI.com' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_emails'}{'autoid'}, - 'method' => 'EMAIL', - 'type' => 'HOME', - 'preference' => 'WORK' }, - 1); - -addRow('contact_emails', { - 'email' => 'abijah\@ValleyStorage.info' }); -addRow('contacts_methods', { - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'}, - 'method_id' => $newdb{'tables'}{'contact_emails'}{'autoid'}, - 'method' => 'EMAIL', - 'type' => 'BUSINESS', - 'preference' => 'WORK' }, - 1); - - -################################################################# -## GROUPS - -addRow('groups', { - 'code' => 'Owner', - 'name' => 'Owner Group' }); -addRow('group_permissions', { - 'group_id' => $newdb{'tables'}{'groups'}{'autoid'}, - 'name' => 'EVERYTHING', - 'access' => 'FORCED' }, - 1); - - -################################################################# -## USERS - -addRow('users', { - 'code' => 'AP', - 'login' => 'abijah', - 'contact_id' => $newdb{'tables'}{'contacts'}{'autoid'} }); - - -################################################################# -## SITES - -addRow('sites', { - 'code' => 'VSS', - 'name' => 'Valley Storage' }); - -addRow('site_memberships', { - 'site_id' => $newdb{'tables'}{'sites'}{'autoid'}, - 'user_id' => $newdb{'tables'}{'users'}{'autoid'}, - 'group_id' => $newdb{'tables'}{'groups'}{'autoid'} }, - 1); - -addRow('site_areas', { - 'site_id' => $newdb{'tables'}{'sites'}{'autoid'}, - 'code' => 'Main', - 'name' => 'Main Facility Area' }); - - -################################################################# -## LEASES - -addRow('lease_types', { - 'code' => 'SL', - 'name' => 'Storage Lease' }); - - -################################################################# -## LEDGERS - -$newdb{'lookup'}{'account'} = {}; - -$query = "SELECT * FROM pmgr_accounts"; -$result = query($db_handle, $query); -foreach $row (@$result) { - addRow('ledgers', { - 'account_id' => $row->{'id'}, - 'name' => $row->{'id'} . '-1', - 'comment' => undef }); - - $newdb{'lookup'}{'account'}{$row->{'name'}} - = {'account_id' => $row->{'id'}, - 'ledger_id' => $newdb{'tables'}{'ledgers'}{'autoid'} }; - - if ((!defined $newdb{'tables'}{'accounts'}{'autoid'}) || - $row->{'id'} > $newdb{'tables'}{'accounts'}{'autoid'}) { - $newdb{'tables'}{'accounts'}{'autoid'} = $row->{'id'}; - } -} - -# For compatibility, while deciding on account names -if (!defined $newdb{'lookup'}{'account'}{'Cash'}) { - $newdb{'lookup'}{'account'}{'Cash'} - = $newdb{'lookup'}{'account'}{'Till'}; -} - -$newdb{'lookup'}{'charge_type'} = {}; -$newdb{'lookup'}{'charge_type'}{'Rent'} = - $newdb{'lookup'}{'account'}{'Rent'}; -$newdb{'lookup'}{'charge_type'}{'Late Fee'} = - $newdb{'lookup'}{'account'}{'Late Charge'}; -$newdb{'lookup'}{'charge_type'}{'Security Deposit'} = - $newdb{'lookup'}{'account'}{'Security Deposit'}; - - -################################################################# -## MONETARY TYPES - -$newdb{'lookup'}{'tender_type'} = {}; - -foreach my $tender_name ('Cash', 'Check', 'Money Order', 'ACH', - 'Concession', # REVISIT : 20090723 Do we really want this?? - #'Debit Card', 'Credit Card', - ) { - my ($tillable, $fields) = (0, 0); - my ($name1, $name2, $name3, $name4); - my ($name_field) = ('id'); - - $tillable = 1 - if ($tender_name =~ /^Cash|Check|Money Order$/); - - ($name1, $name_field) = ('Check Number', 'data1') - if ($tender_name eq 'Check'); - - ($name1, $name_field) = ('Money Order Number', 'data1') - if ($tender_name eq 'Money Order'); - - ($name1, $name2, $name3, $name_field) = ('Routing Number', 'Account Number', 'Batch Number', 'data3') - if ($tender_name eq 'ACH'); - - ($name1, $name2) = ('Debit Card Number', 'Expiration Date') - if ($tender_name eq 'Debit Card'); - - ($name1, $name2, $name3) = ('Debit Card Number', 'Expiration Date', 'Billing Zip Code') - if ($tender_name eq 'Credit Card'); - - addRow('tender_types', { - 'name' => $tender_name, - 'account_id' => $newdb{'lookup'}{'account'}{$tender_name}{'account_id'}, - 'deposit_account_id' => $newdb{'lookup'}{'account'}{'Bank'}{'account_id'}, - 'tillable' => $tillable, - 'auto_deposit' => ($tender_name eq 'ACH') ? 1 : 0, - 'data1_name' => $name1, - 'data2_name' => $name2, - 'data3_name' => $name3, - 'data4_name' => $name4, - 'naming_field' => $name_field, - }); - - $newdb{'lookup'}{'tender_type'}{$tender_name} - = { 'tender_type_id' => $newdb{'tables'}{'tender_types'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{$tender_name}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{$tender_name}{'ledger_id'}, - }; -} - - -################################################################# -## MONETARY - -$newdb{'lookup'}{'payment_type'} = {}; - -# SITELINK PAYMENT TYPE CODES -my %SITELINK_ACCOUNT_TYPE = -( 1 => 'Cash', - 2 => 'Check', - 3 => 'Money Order', - 4 => 'ACH', - 12 => 'Concession', -); - -foreach my $account_type (keys(%SITELINK_ACCOUNT_TYPE)) { - my $payment_name = $SITELINK_ACCOUNT_TYPE{$account_type}; - my ($ttid, $aid, $lid); - - if (defined $newdb{'lookup'}{'tender_type'}{$payment_name}) { - ($ttid, $aid, $lid) = ( $newdb{'lookup'}{'tender_type'}{$payment_name}{'tender_type_id'}, - $newdb{'lookup'}{'tender_type'}{$payment_name}{'account_id'}, - $newdb{'lookup'}{'tender_type'}{$payment_name}{'ledger_id'} ); - } - else { - ($ttid, $aid, $lid) = ( undef, - $newdb{'lookup'}{'account'}{$payment_name}{'account_id'}, - $newdb{'lookup'}{'account'}{$payment_name}{'ledger_id'} ); - } - - $newdb{'lookup'}{'payment_type'}{$account_type} - = { 'name' => $payment_name, - 'tender_type_id' => $ttid, - 'account_id' => $aid, - 'ledger_id' => $lid, - }; -} - - -################################################################# -## SPECIAL CASE FOR CLOSING - -$newdb{'lookup'}{'_closing'} -= { 'name' => 'Closing', - 'stamp' => (dates('receipt', '01/01/01'))[0], - 'amount' => 0, - 'tender_type_id' => undef, - 'debit_account_id' => $newdb{'lookup'}{'account'}{'Closing'}{'account_id'}, - 'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Closing'}{'ledger_id'}, - 'credit_account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'}, - 'credit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}, -}; - - - -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -## -## UNITS -## - -my @unit_sort_order = - qw( - A01 A02 A03 A04 A05 A06 - B01 B02 B03 B04 B05 B06 B07 - C01 C02 C03 C04 C05 C06 C07 C08 C09 - 10 11 12 13 14 15 16 17 18 19 22 23 24 25 26 27 28 29 - 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 - D01 D02 D03 D04 D05 D06 D07 D08 D09 D10 D11 - APT - Y01 Y02 Y03 Y04 Y05 Y06 Y07 Y08 Y09 Y10 - ); -my $unit_sort_order = 0; -my %unit_sort_order; -foreach (@unit_sort_order) { - $unit_sort_order += 1; # use 100 for later insertion - $unit_sort_order{$_} = $unit_sort_order; -} - -my @unit_walk_order = - qw( - 19 18 17 16 15 14 13 12 11 10 - C01 C02 C03 C04 C05 C06 C07 C08 C09 - APT - 38 37 36 35 34 33 32 31 30 29 28 - B01 B02 B03 B04 B05 B06 B07 - A01 A02 A03 A04 A05 A06 - 27 26 25 24 23 22 - D11 D10 D09 D08 D07 D06 D05 D04 D03 D02 D01 - 45 44 43 42 41 40 39 - Y01 Y02 Y03 Y04 Y05 Y06 Y07 Y08 Y09 Y10 - ); -my $unit_walk_order = 0; -my %unit_walk_order; -foreach (@unit_walk_order) { - $unit_walk_order += 1; # use 100 for later insertion - $unit_walk_order{$_} = $unit_walk_order; -} - -###################################################################### -## Unit Types - -$newdb{'lookup'}{'unit_type'} = {}; - -$query = "SELECT * FROM UnitType ORDER BY TypeID"; -foreach $row (@{query($sdbh, $query)}) { - addRow('unit_types', { - 'code' => 'xxx', - 'name' => $row->{'UnitType'} }); - $newdb{'lookup'}{'unit_type'}{$row->{'TypeID'}} = - $newdb{'tables'}{'unit_types'}{'autoid'}; -} - -###################################################################### -## Unit Sizes - -$newdb{'lookup'}{'unit_size'} = {}; - -$query = "SELECT * FROM UnitInfo WHERE UnitID <> 'POS\$' ORDER BY UnitID"; -foreach $row (@{query($sdbh, $query)}) { - my $sz = sizeCode($row->{'Width'}, $row->{'Depth'}); - next if defined $newdb{'lookup'}{'unit_size'}{$sz}; - - addRow('unit_sizes', { - 'unit_type_id' => $row->{'Type'}, - 'code' => $sz, - 'name' => $sz, - 'width' => $internal_adjustment_factor * $row->{'Width'}, - 'depth' => $internal_adjustment_factor * $row->{'Depth'}, - 'deposit' => $row->{'StdSecDep'}, - 'rent' => $row->{'StdRent'} }); - - $newdb{'lookup'}{'unit_size'}{$sz} - = { 'id' => $newdb{'tables'}{'unit_sizes'}{'autoid'}, - 'rent' => $row->{'StdRent'}, - 'dep' => $row->{'StdSecDep'} }; -} - -###################################################################### -## Units - -$newdb{'lookup'}{'unit'} = {}; - -foreach $row (@{query($sdbh, $query)}) { - my $sz = sizeCode($row->{'Width'}, $row->{'Depth'}); - my $szid = $newdb{'lookup'}{'unit_size'}{$sz}{'id'}; - - addRow('units', { - 'unit_size_id' => $szid, - 'code' => $row->{'UnitID'}, - 'name' => $row->{'UnitID'}, - 'status' => $row->{'Rented'} ?'OCCUPIED' :($row->{'Rentable'} ?'VACANT' :'UNAVAILABLE'), - 'sort_order' => $unit_sort_order{$row->{'UnitID'}}, - 'walk_order' => $unit_walk_order{$row->{'UnitID'}}, - 'deposit' => $row->{'StdSecDep'}, - 'rent' => $row->{'StdRent'} }); - - $newdb{'lookup'}{'unit'}{$row->{'UnitID'}} - = { 'id' => $newdb{'tables'}{'units'}{'autoid'} }; -} - - -###################################################################### -## Map - -my %info = ('extents' => {}, 'units' => {}); - -# Get the overall site limits -$query = "SELECT MIN(M.Top) AS mintop, MIN(M.Left) AS minlft,"; -$query .= " MAX(M.Top + IIF(M.reverseWL, U.Width, U.Depth)) AS bot,"; -$query .= " MAX(M.Left + IIF(M.reverseWL, U.Depth, U.Width)) AS rgt"; -$query .= ' FROM UnitInfo U INNER JOIN mapUnitsV2 M ON M.unitID = U.UnitID'; -$result = query($sdbh, $query); - -# Fetch and verify the result -my $row = shift(@$result); -die("MIN query failed!") unless $row; - -# Compute the actual boundaries, adjusting for a (0,0) origin -my $top_adjustment = 0 - $row->{'mintop'}; -my $left_adjustment = 0 - $row->{'minlft'}; -$info{'extents'}{'top'} = 0; -$info{'extents'}{'left'} = 0; -$info{'extents'}{'bottom'} = $internal_adjustment_factor * ($top_adjustment + $row->{'bot'} + 0); -$info{'extents'}{'right'} = $internal_adjustment_factor * ($left_adjustment + $row->{'rgt'} + 0); - -addRow('maps', { - 'name' => 'Main Facility Map', - 'site_area_id' => $newdb{'tables'}{'site_areas'}{'autoid'}, - 'width' => $info{'extents'}{'right'} - $info{'extents'}{'left'}, - 'depth' => $info{'extents'}{'bottom'} - $info{'extents'}{'top'} }); - -# Get list of units and positions -$query = "SELECT U.UnitID, U.UnitID as name,"; -$query .= " ($top_adjustment + M.Top) AS pt_t,"; -$query .= " ($left_adjustment + M.Left) AS pt_l,"; -$query .= " IIF(M.reverseWL, U.Depth, U.Width) AS Width,"; -$query .= " IIF(M.reverseWL, U.Width, U.Depth) AS Depth,"; -$query .= " M.reverseWL, U.Rented, U.Rentable"; -$query .= " FROM UnitInfo U INNER JOIN mapUnitsV2 M ON M.unitID = U.UnitID"; - -# Go through each one, calculating the map location -foreach $row (@{query($sdbh, $query)}) { - addRow('maps_units', { - 'map_id' => $newdb{'tables'}{'maps'}{'autoid'}, - 'unit_id' => $newdb{'lookup'}{'unit'}{$row->{'UnitID'}}{'id'}, - 'pt_top' => $internal_adjustment_factor * ($row->{'pt_t'}), - 'pt_left' => $internal_adjustment_factor * ($row->{'pt_l'}), - 'transpose' => $row->{'reverseWL'} }); -} - - -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -## -## TENANTS -## - - -###################################################################### -## Tenants - -$newdb{'lookup'}{'tenant'} = {}; - -$query = "SELECT * FROM TenantInfo WHERE FirstName <> 'POS' ORDER BY TenantID"; -foreach $row (@{query($sdbh, $query)}) { - - $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}} - = { 'name' => "$row->{'LastName'}, $row->{'FirstName'}" }; - - addRow('contacts', { - 'first_name' => $row->{'FirstName'}, - 'middle_name' => $row->{'MiddleName'}, - 'last_name' => $row->{'LastName'}, - 'id_local' => $row->{'IDNum'} || undef, - 'id_local_state' => $row->{'IDNum'} ? $newdb{'lookup'}{'state'}{$row->{'DLStateID'}} : undef }); - - $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'} = - $newdb{'tables'}{'contacts'}{'autoid'}; - - addRow('customers', { - 'name' => "$row->{'LastName'}, $row->{'FirstName'}", - 'primary_contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, - }); - - $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} = - $newdb{'tables'}{'customers'}{'autoid'}; - - addRow('contacts_customers', { - 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'}, - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, - 'type' => 'TENANT' }, - 1); - - if ($row->{'City'}) { - addRow('contact_addresses', { - 'address' => $row->{'HomeAddress'} . ($row->{'HomeAddr2'} ? "\n".$row->{'HomeAddr2'} : "") || undef, - 'city' => $row->{'City'}, - 'state' => $newdb{'lookup'}{'state'}{$row->{'StateID'}}, - 'postcode' => $row->{'Zip'} || undef, - 'country' => 'USA' }); - addRow('contacts_methods', { - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, - 'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'}, - 'method' => 'ADDRESS', - 'type' => 'HOME', - 'preference' => 'PRIMARY' }, - 1); - } - - foreach ({'type' => 'LANDLINE', 'preference' => 'PRIMARY', 'phone' => $row->{'Phone'}}, - {'type' => 'LANDLINE', 'preference' => 'WORK', - 'phone' => $row->{'BusinessPhone'}, 'ext' => $row->{'BusinessExt'}}, - {'type' => 'FAX', 'preference' => 'PRIMARY', 'phone' => $row->{'FAX'}}, - {'type' => 'PAGER', 'preference' => 'PRIMARY', 'phone' => $row->{'Pager'}}, - {'type' => 'MOBILE', 'preference' => 'ALTERNATE', 'phone' => $row->{'CellPhone'}}) - { - if ($_->{'phone'}) { - addRow('contact_phones', { - 'type' => $_->{'type'}, - 'phone' => $_->{'phone'}, - 'ext' => $_->{'ext'} }); - addRow('contacts_methods', { - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'MAIN', - 'preference' => $_->{'preference'} }, - 1); - } - } - - if ($row->{'Email'}) { - addRow('contact_emails', { - 'email' => $row->{'Email'} }); - addRow('contacts_methods', { - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'id'}, - 'method_id' => $newdb{'tables'}{'contact_emails'}{'autoid'}, - 'method' => 'EMAIL', - 'type' => 'MAIN', - 'preference' => 'PRIMARY' }, - 1); - } - - next unless $row->{'AltFirstName'} || $row->{'AltLastName'} || $row->{'AltAddress'} || $row->{'AltPhone'}; - - addRow('contacts', { - 'first_name' => $row->{'AltFirstName'} || undef, - 'middle_name' => $row->{'AltMI'} || undef, - 'last_name' => $row->{'AltLastName'} || undef }); - - $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'} = - $newdb{'tables'}{'contacts'}{'autoid'}; - - addRow('contacts_customers', { - 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'}, - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'}, - 'type' => 'ALTERNATE' }, - 1); - - if ($row->{'AltCity'}) { - addRow('contact_addresses', { - 'address' => $row->{'AltAddress'} . ($row->{'AltAddr2'} ? "\n".$row->{'AltAddr2'} : ""), - 'city' => $row->{'AltCity'}, - 'state' => $newdb{'lookup'}{'state'}{$row->{'AltStateID'}}, - 'postcode' => $row->{'AltZip'}, - 'country' => 'USA' }); - addRow('contacts_methods', { - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'}, - 'method_id' => $newdb{'tables'}{'contact_addresses'}{'autoid'}, - 'method' => 'ADDRESS', - 'type' => 'MAIN', - 'preference' => 'PRIMARY' }, - 1); - } - - if ($row->{'AltPhone'}) { - addRow('contact_phones', { - 'type' => 'LANDLINE', - 'phone' => $row->{'AltPhone'}, - 'ext' => undef }); - addRow('contacts_methods', { - 'contact_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'alt'}, - 'method_id' => $newdb{'tables'}{'contact_phones'}{'autoid'}, - 'method' => 'PHONE', - 'type' => 'MAIN', - 'preference' => 'PRIMARY' }, - 1); - } -} - - -###################################################################### -## Tenant Leases - -$newdb{'lookup'}{'ledger'} = {}; - -$query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' ORDER BY L.DateIn"; -foreach $row (@{query($sdbh, $query)}) { - - $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}} - = { 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'}, - 'lease_date' => $row->{'DateIn'}, - }; - - addRow('leases', { - 'number' => $newdb{'tables'}{'leases'}{'autoid'}+1, - #'number' => $row->{'LedgerID'}, - 'lease_type_id' => $newdb{'tables'}{'lease_types'}{'autoid'}, - 'unit_id' => $newdb{'lookup'}{'unit'}{$row->{'UnitID'}}{'id'}, - 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'}, - 'lease_date' => datefmt($row->{'DateIn'}), - 'movein_date' => datefmt($row->{'DateIn'}), - 'moveout_date' => datefmt($row->{'DateOut'}), - #'close_date' => datefmt($row->{'DateClosed'}), - 'rent' => $row->{'Rent'}, - #'comment' => "LedgerID: $row->{'LedgerID'}", - }); - - $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} = - $newdb{'tables'}{'leases'}{'autoid'}; -} - - - -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -## -## INVOICES -## - -###################################################################### -## Invoices - -$newdb{'lookup'}{'charge'} = {}; - -$query = "SELECT *, ChargeAmount+TaxAmount AS InvoiceAmount FROM Charges ORDER BY ChargeID"; -foreach $row (@{query($sdbh, $query)}) { - - my ($stamp, $effective_date, $through_date) = - dates('invoice', $row->{'ChargeDate'}, $row->{'EndDate'}, - $row->{'ChargeDescription'}, $row->{'LedgerID'}); - - addRow('transactions', { - 'type' => 'INVOICE', - 'stamp' => $stamp, - 'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'}, - 'account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}, - 'crdr' => 'DEBIT', - #'amount' => $row->{'InvoiceAmount'}, - #'comment' => "Invoice Transaction", - }); - - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}} - = { 'invoice' => {'id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'amount' => $row->{'InvoiceAmount'} }, - }; - - # Charges are the only way we have to figure out security - # deposit requirements for a lease. So, if we encounter - # a security deposit charge, update the lease to reflect. - if ($row->{'ChargeDescription'} eq 'Security Deposit') { - $newdb{'tables'}{'leases'}{'rows'}[ - $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} - ]{'deposit'} = $row->{'ChargeAmount'}; - } - -} - - -###################################################################### -## Charges - -$query = "SELECT * FROM Charges ORDER BY ChargeID"; -foreach $row (@{query($sdbh, $query)}) { - - my (undef, $effective_date, $through_date) = - dates('charge', $row->{'ChargeDate'}, $row->{'EndDate'}, - $row->{'ChargeDescription'}, $row->{'LedgerID'}); - - # Fix Brenda Harmon bug - $row->{'ChargeAmount'} = 50 - if ($row->{'ChargeID'} == 19); - - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'} - = $row->{'ChargeAmount'}; - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'} - = $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'}, - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'} - = $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'}; - - # Charge must credit the Charge ledger... - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_account_id'} - = $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'account_id'}; - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_ledger_id'} - = $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'ledger_id'}; - - # ...and debit the A/R ledger. - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_account_id'} - = $newdb{'lookup'}{'account'}{'A/R'}{'account_id'}; - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'} - = $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}; - - # debit: A/R credit: Rent/LateCharge/Etc - foreach ('debit', 'credit') { - my $CRDR = $_; - $CRDR =~ tr/a-z/A-Z/; - addRow('ledger_entries', { - 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'}, - 'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_account_id'}, - 'ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_ledger_id'}, - 'crdr' => $CRDR, - 'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}, - #'comment' => "$_ Ledger Entry: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}", - }); - - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_entry_id'} - = $newdb{'tables'}{'ledger_entries'}{'autoid'}; - } - - addRow('double_entries', { - #'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'}, - 'debit_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_entry_id'}, - 'credit_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_entry_id'}, - #'comment' => "Double Entry: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}", - }); - - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'double_entry_id'} - = $newdb{'tables'}{'double_entries'}{'autoid'}; - - # Add the Charge Statement Entry - addRow('statement_entries', { - 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'}, - 'type' => 'CHARGE', - 'effective_date' => $effective_date, - 'through_date' => $through_date, - 'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}, - 'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}, - 'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_account_id'}, - 'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}, - #'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}", - }); - - $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'} - = $newdb{'tables'}{'statement_entries'}{'autoid'}; - - next unless $row->{'TaxAmount'}; - -# # Add the tax charge entry -# # debit: Invoice credit: Tax -# addRow('ledger_entries', -# { 'effective_date' => $effective_date, -# 'through_date' => $through_date, -# 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'}, -# 'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'}, -# 'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Tax'}{'ledger_id'}, -# 'amount' => $row->{'TaxAmount'}, -# #'comment' => "Tax for ChargeID:$row->{'ChargeID'}", -# }); - -# $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_ledger_entry_id'} -# = $newdb{'tables'}{'ledger_entries'}{'autoid'}; -} - - -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -###################################################################### -## -## RECEIPTS -## - -###################################################################### -## Receipts - -$newdb{'lookup'}{'receipt'} = {}; - -# Sitelink splits one physical payment into multiple "payments" to match each charge. -# The solution here is kludgy, but for our cases at least, it brings those pseudo-payments -# back into a single one. This presumes there is only one PaymentType per receipt. -$query = - "SELECT R.ReceiptNum, R.ReceiptDate, P.PaymentType, P.CheckNum, SUM(P.PaymentAmount) AS ReceiptAmount" . - " FROM Receipts R, Payments P" . - " WHERE P.ReceiptNum = R.ReceiptNum" . - " GROUP BY R.ReceiptNum, R.ReceiptDate, P.PaymentType, P.CheckNum" . - " ORDER BY R.ReceiptNum, P.PaymentType"; - -# print Dumper query($sdbh, $query); -# exit; - -foreach $row (@{query($sdbh, $query)}) { - -# if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}) { -# next; -# } - - my ($stamp, $effective_date, $through_date) = - dates('receipt', $row->{'ReceiptDate'}, undef); - - if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}) { - print Dumper $newdb{'lookup'}{'receipt'}; - print Dumper $row; - die "REALLY?"; - } - - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}} - = { 'date' => $stamp, - 'effective_date' => $effective_date, - 'through_date' => $through_date, - 'amount' => $row->{'ReceiptAmount'}, - }; - - if ($stamp eq $newdb{'lookup'}{'_closing'}{'stamp'}) { - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'} - = $newdb{'lookup'}{'_closing'}{'name'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_type_id'} - = $newdb{'lookup'}{'_closing'}{'tender_type_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'} - = $newdb{'lookup'}{'_closing'}{'debit_account_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_ledger_id'} - = $newdb{'lookup'}{'_closing'}{'debit_ledger_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_account_id'} - = $newdb{'lookup'}{'_closing'}{'credit_account_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'} - = $newdb{'lookup'}{'_closing'}{'credit_ledger_id'}; - - $newdb{'lookup'}{'_closing'}{'amount'} += - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'amount'}; - - if ($newdb{'lookup'}{'_closing'}{'transaction_id'}) { - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'} = - $newdb{'lookup'}{'_closing'}{'transaction_id'}; - next; - } - } - else { - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'} - = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'name'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_type_id'} - = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'tender_type_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'} - = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'account_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_ledger_id'} - = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'ledger_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_account_id'} - = $newdb{'lookup'}{'account'}{'A/R'}{'account_id'}; - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'} - = $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'}; - - if ($SITELINK_ACCOUNT_TYPE{$row->{'PaymentType'}} eq 'Check') { - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'} - = $row->{'CheckNum'}; - } - } - - addRow('transactions', { - 'type' => 'RECEIPT', - 'stamp' => $stamp, - 'customer_id' => undef, # Must be set later - 'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_account_id'}, - 'ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'}, - 'crdr' => 'CREDIT', - #'comment' => "Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}", - }); - - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'} - = $newdb{'tables'}{'transactions'}{'autoid'}; - - # Receipt must debit the "money" asset (bank, cash, check, etc)... - # ...and credit the A/R ledger - # (These were set above, based on whether part of closing or not) - - foreach ('debit', 'credit') { - my $CRDR = $_; - $CRDR =~ tr/a-z/A-Z/; - addRow('ledger_entries', { - 'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}, - 'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_account_id'}, - 'ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_ledger_id'}, - 'crdr' => $CRDR, - 'amount' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'amount'}, - #'comment' => "$_ Entry Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}", - }); - - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_entry_id'} - = $newdb{'tables'}{'ledger_entries'}{'autoid'}; - } - - addRow('double_entries', { - #'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}, - - 'debit_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'}, - 'credit_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_entry_id'}, - #'comment' => "Double Entry: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}", - }); - - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'} - = $newdb{'tables'}{'double_entries'}{'autoid'}; - - # Add the physical payment - addRow('tenders', { - 'ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'}, - 'name' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}, - 'tender_type_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_type_id'}, - 'data1' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'}, - #'comment' => "Physical Payment: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}", - }); - - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_id'} - = $newdb{'tables'}{'tenders'}{'autoid'}; - - - # Special case for closing - if ($closing_one_transaction && $stamp eq $newdb{'lookup'}{'_closing'}{'stamp'}) { - $newdb{'lookup'}{'_closing'}{'transaction_id'} = - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}; - $newdb{'lookup'}{'_closing'}{'debit_entry_id'} = - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'}; - $newdb{'lookup'}{'_closing'}{'credit_entry_id'} = - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_entry_id'}; - $newdb{'lookup'}{'_closing'}{'tender_id'} = - $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_id'}; - } - -} - - - -###################################################################### -## Payments to Charges assignments - -$newdb{'lookup'}{'payment'} = {}; - -$query = "SELECT * FROM Payments ORDER BY PaymentID"; -foreach $row (@{query($sdbh, $query)}) -{ - my (undef, $effective_date, $through_date) = - dates('payment', $row->{'PaymentDate'}); - - # Figure out how much of the charge can be reconciled - my $charge_amount = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}; - my $payment_amount = $row->{'PaymentAmount'}; - - my $reconcile_amount = ($charge_amount < $payment_amount) ? $charge_amount : $payment_amount; - - $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}} - = { 'receipt_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}, - 'tender_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'tender_id'}, -# 'effective_date' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'effective_date'}, -# 'effective_date' => $effective_date; -# 'through_date' => $through_date; - 'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}, - 'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}, - 'amount' => $reconcile_amount, - - 'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'}, - }; - - # Update the receipt & tender customer_id, now that we have payment info - $newdb{'tables'}{'transactions'}{'rows'}[ - $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'} - ]{'customer_id'} = $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'}; - $newdb{'tables'}{'tenders'}{'rows'}[ - $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'tender_id'} - ]{'customer_id'} = $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'}; - - # Use the Memo as our comment, if it exists - my $comment = $row->{'Memo'} - #|| "Payment: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}; Charge: $row->{'ChargeID'}" - ; - - # Add the Payment Statement Entry - addRow('statement_entries', { - 'transaction_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'}, - 'type' => 'DISBURSEMENT', -# 'effective_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'effective_date'}, -# 'through_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'through_date'}, - 'effective_date' => $effective_date, - 'through_date' => $through_date, - 'customer_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'customer_id'}, - 'lease_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'lease_id'}, - 'account_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'account_id'}, - 'amount' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'}, - 'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'}, - 'comment' => $comment, - }); - - $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'} - = $newdb{'tables'}{'statement_entries'}{'autoid'}; -} - - -###################################################################### -## Special case - Fix the entries for our closing transaction - -if ($newdb{'lookup'}{'_closing'}{'debit_entry_id'}) { - $newdb{'tables'}{'ledger_entries'}{'rows'}[ - $newdb{'lookup'}{'_closing'}{'debit_entry_id'} - ]{'amount'} = $newdb{'lookup'}{'_closing'}{'amount'}; -} -if ($newdb{'lookup'}{'_closing'}{'credit_entry_id'}) { - $newdb{'tables'}{'ledger_entries'}{'rows'}[ - $newdb{'lookup'}{'_closing'}{'credit_entry_id'} - ]{'amount'} = $newdb{'lookup'}{'_closing'}{'amount'}; -} - - -###################################################################### -## Special case - Equities / Loans / Petty Cash - -my ($stamp, $effective_date, $through_date); - -print("Set up Petty Cash...\n"); - -# Add the first loan -# debit: Equity credit: Loan -addRow('transactions', { - 'type' => 'TRANSFER', - 'stamp' => datefmt('03/25/2009 16:00'), - 'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'comment' => "HTP Loan #1", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'amount' => 5000, - 'comment' => "Equity: HTP Loan #1", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'}, - 'crdr' => 'CREDIT', - 'amount' => 5000, - 'comment' => "Loan: HTP Loan #1", - }); -addRow('double_entries', { - 'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1, - 'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}, - }); - -# Add the second loan -# debit: Equity credit: Loan -addRow('transactions', { - 'type' => 'TRANSFER', - 'stamp' => datefmt('04/01/2009 16:00'), - 'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'comment' => "HTP Loan #2", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'amount' => 1000, - 'comment' => "Equity: HTP Loan #2", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'}, - 'crdr' => 'CREDIT', - 'amount' => 1000, - 'comment' => "Loan: HTP Loan #2", - }); -addRow('double_entries', { - 'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1, - 'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}, - }); - - -# Cheat for now, using equity for Petty Cash -# debit: Petty Cash credit: Equity -addRow('transactions', { - 'type' => 'TRANSFER', - 'stamp' => datefmt('03/25/2009 16:00'), - 'account_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'comment' => "Petty Cash Funding", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'}, - 'crdr' => 'DEBIT', - 'amount' => 750, - 'comment' => "Petty Cash: Petty Cash Funding", - }); -addRow('ledger_entries', { - 'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'}, - 'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'}, - 'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'}, - 'crdr' => 'CREDIT', - 'amount' => 750, - 'comment' => "Equity: Petty Cash Funding", - }); -addRow('double_entries', { - 'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1, - 'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}, - }); - - -###################################################################### -## Debug ... work from scratch -if ($work_from_scratch) { - # delete $newdb{'tables'}{'contacts'}{'rows'}; - # delete $newdb{'tables'}{'contacts_methods'}{'rows'}; - # delete $newdb{'tables'}{'contacts_addresses'}{'rows'}; - # delete $newdb{'tables'}{'contacts_emails'}{'rows'}; - # delete $newdb{'tables'}{'contacts_phones'}{'rows'}; - delete $newdb{'tables'}{'contacts_customers'}{'rows'}; - delete $newdb{'tables'}{'customers'}{'rows'}; - delete $newdb{'tables'}{'double_entries'}{'rows'}; - delete $newdb{'tables'}{'leases'}{'rows'}; - delete $newdb{'tables'}{'ledger_entries'}{'rows'}; - delete $newdb{'tables'}{'statement_entries'}{'rows'}; - delete $newdb{'tables'}{'tenders'}{'rows'}; - delete $newdb{'tables'}{'transactions'}{'rows'}; - - foreach (@{$newdb{'tables'}{'units'}{'rows'}}) { - $_->{'status'} = 'VACANT' - if defined $_ && ($_->{'status'} =~ /^(OCCUPIED)$/ || $_->{'name'} =~ /^Y/); - } -} - - -###################################################################### -## Build the Database - -$Data::Dumper::Sortkeys = 1; -# print Dumper \%newdb; -# exit; - -buildTables(); - - -###################################################################### -## Special cases - Name corrections -print("Special Cases...\n"); -$query = - "UPDATE pmgr_contacts" . - " SET first_name = 'Krystan'" . - " WHERE first_name = 'Kristan' AND last_name = 'Mancini'"; -query($db_handle, $query); -$query = - "UPDATE pmgr_customers" . - " SET name = 'Mancini, Krystan'" . - " WHERE name = 'Mancini, Kristan'"; -query($db_handle, $query); -$query = - "UPDATE pmgr_contacts" . - " SET first_name = NULL, last_name = NULL, company_name = 'Valley Bible Church'" . - " WHERE first_name = 'VBC' AND last_name = 'Tenant'"; -query($db_handle, $query); -$query = - "UPDATE pmgr_customers" . - " SET name = 'Valley Bible Church'" . - " WHERE name = 'Tenant, VBC'"; -query($db_handle, $query); - - -###################################################################### -## Contact Display Names - -print("Set Contact Display Names...\n"); - -$query = - "UPDATE pmgr_contacts". - " SET display_name =" . - " IF(first_name IS NOT NULL AND last_name IS NOT NULL," . - " CONCAT(last_name, ', ', first_name)," . - " IF(first_name IS NOT NULL, first_name, last_name))"; -query($db_handle, $query); - - -###################################################################### -## Unit Lease Assignments - -print("Set Current Leases...\n"); - -$query = "UPDATE pmgr_units U, pmgr_leases L - SET U.`current_lease_id` = L.id - WHERE L.unit_id = U.id AND L.close_date IS NULL"; -query($db_handle, $query); - -# All current_lease_counts will be zero at the moment, since -# everything was just created. This will update any customers -# that have ever leased anything. -$query = "UPDATE pmgr_customers C, - (SELECT L.customer_id, - SUM(IF(L.close_date IS NULL, 1, 0)) AS current, - SUM(IF(L.close_date IS NULL, 0, 1)) AS closed - FROM pmgr_leases L - GROUP BY L.customer_id) AS X - SET C.`lease_count` = X.current + X.closed, - C.`current_lease_count` = X.current, - C.`past_lease_count` = X.closed - WHERE X.customer_id = C.id"; -query($db_handle, $query); - - -###################################################################### -## Invoice/Receipt totals - -print("Set Invoice/Receipt Totals...\n"); - -$query = "UPDATE pmgr_transactions T, pmgr_ledger_entries E - SET T.`amount` = COALESCE(T.`amount`,0) + E.amount - WHERE E.transaction_id = T.id AND E.account_id = T.account_id"; -query($db_handle, $query); - - -###################################################################### -## Tender Names - -print("Set Tender Names...\n"); - -$query = "UPDATE pmgr_tenders T, pmgr_tender_types TT - SET T.`name` = CONCAT(T.`name`, ' #', - IF(T.tender_type_id IN (2,3), T.data1, T.id)) - WHERE T.tender_type_id IS NULL OR TT.id = T.tender_type_id"; -query($db_handle, $query); - - -###################################################################### -## Invoice date fixes - -# print("Fix Invoice Dates...\n"); - -# $query = "UPDATE pmgr_transactions T, pmgr_statement_entries E -# SET T.`stamp` = -# WHERE E.transaction_id = T.id AND E.account_id = T.account_id"; -# query($db_handle, $query); - From 11be0ff9cbd6b06e5620b95e5902446ab3c5c520 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 18:30:17 +0000 Subject: [PATCH 011/103] Modified the menu to use the accordion widget, which is slick and allows it to match the current theme. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@745 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/elements/sidemenu.ctp | 35 +++++++++++++++++++++++++------- site/webroot/css/sidemenu.css | 35 ++++++++------------------------ 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/site/views/elements/sidemenu.ctp b/site/views/elements/sidemenu.ctp index dca30c9..2bc94be 100644 --- a/site/views/elements/sidemenu.ctp +++ b/site/views/elements/sidemenu.ctp @@ -8,6 +8,11 @@ * @package pmgr */ +// REVISIT : 20090823 +// Add way to slide the entire menu off the page + +echo('
' . "\n"); + foreach ($menu AS $area) { if (empty($area['subarea'])) continue; @@ -16,21 +21,37 @@ foreach ($menu AS $area) { if (empty($subarea['priorities'])) continue; - echo('
' . $subarea['name'] . '
' . "\n"); + echo('

' . $subarea['name'] . "

\n"); + echo('
' . "\n"); foreach ($subarea['priorities'] AS $priority) { foreach ($priority AS $item) { - if (isset($item['header'])) - echo('
' . $item['name'] . '
' . "\n"); - elseif (isset($item['hr'])) - echo('
' . "\n"); - elseif (isset($item['url'])) - echo('
' + if (isset($item['url'])) { + echo('
' . $html->link($item['name'], $item['url'], isset($item['htmlAttributes']) ? $item['htmlAttributes'] : null, isset($item['confirmMessage']) ? $item['confirmMessage'] : null, isset($item['escapeTitle']) ? $item['escapeTitle'] : null) . '
' . "\n"); + } } } + echo('
' . "\n"); } } + +echo('
' . "\n"); +?> + + diff --git a/site/webroot/css/sidemenu.css b/site/webroot/css/sidemenu.css index c141e61..5ef0cd2 100644 --- a/site/webroot/css/sidemenu.css +++ b/site/webroot/css/sidemenu.css @@ -3,32 +3,8 @@ * Side Menu Layout */ -td#sidecolumn { width: 10em; background: lightblue; text-align: left; } - -td#sidecolumn .header , -td#sidecolumn .item { white-space : nowrap; } - - -/************************************************************ - ************************************************************ - * Menu Headers - */ - -td#sidecolumn .header { margin-top: 0.4em; - background: blue; - color: white; - font-weight: bold; - } - - - -/************************************************************ - ************************************************************ - * Menu Separators - */ - -td#sidecolumn hr { margin-top: 0.4em; margin-bottom: 0.3em; } - +td#sidecolumn { width: 12em; text-align: left; } +#sidemenu { height: 20em; } /************************************************************ @@ -36,5 +12,10 @@ td#sidecolumn hr { margin-top: 0.4em; margin-bottom: 0.3em; } * Menu Items */ -td#sidecolumn .item { padding-left: 0.6em; } +.sidemenu-header, .sidemenu-item { white-space : nowrap; } + + +#sidemenu.ui-accordion .ui-accordion-header .ui-icon { left: .2em; } +#sidemenu.ui-accordion .ui-accordion-header { padding: 0 0.5em 0 1.1em; } +#sidemenu.ui-accordion .ui-accordion-content { padding: 0 0.5em 0 1.1em; } From 89d7f22e4a47fbac3ece2c542208dd5670c27848 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 19:23:12 +0000 Subject: [PATCH 012/103] Small tweak to prevent the render error when looking at a debug grid query. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@749 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index 50b242a..4481d0f 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -511,6 +511,7 @@ class AppController extends Controller { $xml = preg_replace("//", ">", $xml); echo ("\n
\n$xml\n
\n"); + $this->render_empty(); } } @@ -1019,9 +1020,8 @@ class AppController extends Controller { } function gridDataOutputHeader(&$params, &$model) { - if (!$params['debug']) { + if (!$params['debug']) header("Content-type: text/xml;charset=utf-8"); - } } function gridDataOutputXMLHeader(&$params, &$model) { From 5ad28c809b2da4224f0ce46a299ccfa18a03f170 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 19:23:49 +0000 Subject: [PATCH 013/103] Fixed the relationship field for customer and contact grids. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@750 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/contacts_controller.php | 13 +++++++++ site/controllers/customers_controller.php | 34 +++++++++++++++-------- site/views/contacts/view.ctp | 1 + site/views/customers/view.ctp | 2 +- site/views/elements/contacts.ctp | 13 ++++----- site/views/elements/customers.ctp | 7 +---- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index 8d24e38..10cd928 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -23,6 +23,19 @@ class ContactsController extends AppController { * to jqGrid. */ + function gridDataFilterTablesConfig(&$params, &$model, $table) { + $config = parent::gridDataFilterTablesConfig($params, $model, $table); + + // Special case for Customer; We need the Contact/Customer relationship + if ($table == 'Customer') + $config = array('fields' => array('ContactsCustomer.type', + 'ContactsCustomer.active'), + 'conditions' => array('ContactsCustomer.active' => true), + ); + + return $config; + } + function gridDataOrder(&$params, &$model, $index, $direction) { $order = parent::gridDataOrder($params, $model, $index, $direction); diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index b5d423c..fca37d9 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -92,19 +92,29 @@ class CustomersController extends AppController { return $conditions; } - function gridDataOrder(&$params, &$model, $index, $direction) { - $order = array(); - $order[] = parent::gridDataOrder($params, $model, $index, $direction); + function gridDataFilterTablesConfig(&$params, &$model, $table) { + $config = parent::gridDataFilterTablesConfig($params, $model, $table); - if ($index !== 'PrimaryContact.last_name') - $order[] = parent::gridDataOrder($params, $model, - 'PrimaryContact.last_name', $direction); - if ($index !== 'PrimaryContact.first_name') - $order[] = parent::gridDataOrder($params, $model, - 'PrimaryContact.first_name', $direction); - if ($index !== 'Customer.id') - $order[] = parent::gridDataOrder($params, $model, - 'Customer.id', $direction); + // Special case for Contact; We need the Contact/Customer relationship + if ($table == 'Contact') + $config = array('fields' => array('ContactsCustomer.type', + 'ContactsCustomer.active'), + 'conditions' => array('ContactsCustomer.active' => true), + ); + + return $config; + } + + function gridDataOrder(&$params, &$model, $index, $direction) { + $order = parent::gridDataOrder($params, $model, $index, $direction); + + // After sorting by whatever the user wants, add these + // defaults into the sort mechanism. If we're already + // sorting by one of them, it will only be redundant, + // and should cause no harm (possible a longer query?) + $order[] = 'PrimaryContact.last_name ' . $direction; + $order[] = 'PrimaryContact.first_name ' . $direction; + $order[] = 'Customer.id ' . $direction; return $order; } diff --git a/site/views/contacts/view.ctp b/site/views/contacts/view.ctp index 0803999..55ac199 100644 --- a/site/views/contacts/view.ctp +++ b/site/views/contacts/view.ctp @@ -135,6 +135,7 @@ echo $this->element('customers', array 'config' => array ('caption' => 'Related Customers', 'filter' => array('Contact.id' => $contact['id']), + 'include' => array('Relationship'), ))); diff --git a/site/views/customers/view.ctp b/site/views/customers/view.ctp index 8a0bb48..a5d9456 100644 --- a/site/views/customers/view.ctp +++ b/site/views/customers/view.ctp @@ -61,7 +61,7 @@ echo $this->element('contacts', array 'config' => array ('caption' => 'Customer Contacts', 'filter' => array('Customer.id' => $customer['Customer']['id']), - 'include' => array('Type', 'Active'), + 'include' => array('Relationship'), ))); diff --git a/site/views/elements/contacts.ctp b/site/views/elements/contacts.ctp index 92c36a7..7267642 100644 --- a/site/views/elements/contacts.ctp +++ b/site/views/elements/contacts.ctp @@ -2,12 +2,11 @@ // Define the table columns $cols = array(); -$cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'name'); -$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'name'); -$cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname'); -$cols['Type'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum'); -$cols['Active'] = array('index' => 'ContactsCustomer.active', 'formatter' => 'enum'); -$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment'); +$cols['Relationship'] = array('index' => 'ContactsCustomer.type', 'formatter' => 'enum'); +$cols['Last Name'] = array('index' => 'Contact.last_name', 'formatter' => 'longname'); +$cols['First Name'] = array('index' => 'Contact.first_name', 'formatter' => 'longname'); +$cols['Company'] = array('index' => 'Contact.company_name', 'formatter' => 'longname'); +$cols['Comment'] = array('index' => 'Contact.comment', 'formatter' => 'comment'); // Render the grid $grid @@ -16,4 +15,4 @@ $grid ->defaultFields(array('Last Name', 'First Name')) ->searchFields(array('Last Name', 'First Name', 'Company')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array('Type', 'Active', 'Comment'))); + array_diff(array_keys($cols), array('Relationship', 'Comment'))); diff --git a/site/views/elements/customers.ctp b/site/views/elements/customers.ctp index b0d2702..2dbfb86 100644 --- a/site/views/elements/customers.ctp +++ b/site/views/elements/customers.ctp @@ -10,11 +10,6 @@ $cols['Leases'] = array('index' => 'current_lease_count', 'formatt $cols['Balance'] = array('index' => 'balance', 'formatter' => 'currency'); $cols['Comment'] = array('index' => 'Customer.comment', 'formatter' => 'comment'); - -// Certain fields are only valid with a particular context -if (!isset($config['filter']['Contact.id'])) - $grid->invalidFields('Relationship'); - // Render the grid $grid ->columns($cols) @@ -22,4 +17,4 @@ $grid ->defaultFields(array('Name')) ->searchFields(array('Name', 'Last Name', 'First Name')) ->render($this, isset($config) ? $config : null, - array_diff(array_keys($cols), array('Comment'))); + array_diff(array_keys($cols), array('Relationship', 'Comment'))); From a9410b1351fc1ed01b863b438e351686b1639a4a Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 20:23:13 +0000 Subject: [PATCH 014/103] Moved 'New Deposit' to the correct menu section git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@751 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/transactions_controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/controllers/transactions_controller.php b/site/controllers/transactions_controller.php index e80085c..93130f2 100644 --- a/site/controllers/transactions_controller.php +++ b/site/controllers/transactions_controller.php @@ -33,7 +33,7 @@ class TransactionsController extends AppController { $this->sideMenuEnable('CONTROLLER', $this->std_area, false); $this->addSideMenuLink('New Deposit', array('controller' => 'tenders', 'action' => 'deposit'), null, - 'ACTION'); + 'ACTION', $this->new_area); $this->gridView('Deposits'); } From ee9ff354b22348f4727fb32afd9ce8b41dc53446 Mon Sep 17 00:00:00 2001 From: abijah Date: Sun, 23 Aug 2009 20:23:44 +0000 Subject: [PATCH 015/103] Added functionality to pre-activate a specific area/subarea of the menu. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@752 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/app_controller.php | 66 ++++++++++++++++++++++---------- site/views/elements/sidemenu.ctp | 27 ++++++++++--- 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/site/app_controller.php b/site/app_controller.php index 4481d0f..ea4b9a1 100644 --- a/site/app_controller.php +++ b/site/app_controller.php @@ -38,7 +38,7 @@ class AppController extends Controller { var $helpers = array('Html', 'Form', 'Javascript', 'Format', 'Time', 'Grid'); var $components = array('DebugKit.Toolbar'); - var $sidemenu_areas = array('SITE' => false, 'CONTROLLER' => false, 'ACTION' => false); + var $sidemenu = array('areas' => array('SITE' => false, 'CONTROLLER' => false, 'ACTION' => false)); var $std_area = 10; var $new_area = 20; var $op_area = 30; @@ -61,7 +61,7 @@ class AppController extends Controller { function sideMenuAreaVerify(&$area, $subarea, $priority = null) { $area = strtoupper($area); - if (!array_key_exists($area, $this->sidemenu_areas)) + if (!array_key_exists($area, $this->sidemenu['areas'])) $this->INTERNAL_ERROR("Sidemenu link '{$area}': Unknown"); if ($area == 'SITE') @@ -71,9 +71,9 @@ class AppController extends Controller { elseif ($area == 'ACTION') $name = Inflector::humanize(Inflector::singularize($this->params['controller'])); - if (empty($this->sidemenu_areas[$area])) - $this->sidemenu_areas[$area] - = array('enable' => true, 'name' => $name, 'subarea' => array()); + if (empty($this->sidemenu['areas'][$area])) + $this->sidemenu['areas'][$area] + = array('enable' => true, 'name' => $name, 'subareas' => array()); if (empty($subarea)) return; @@ -94,15 +94,15 @@ class AppController extends Controller { else $subname .= '-' . $subarea; - if (empty($this->sidemenu_areas[$area]['subarea'][$subarea])) - $this->sidemenu_areas[$area]['subarea'][$subarea] + if (empty($this->sidemenu['areas'][$area]['subareas'][$subarea])) + $this->sidemenu['areas'][$area]['subareas'][$subarea] = array('enable' => true, 'name' => $subname, 'priorities' => array()); if (empty($priority)) return; - if (empty($this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority])) - $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority] + if (empty($this->sidemenu['areas'][$area]['subareas'][$subarea]['priorities'][$priority])) + $this->sidemenu['areas'][$area]['subareas'][$subarea]['priorities'][$priority] = array(); } @@ -117,9 +117,22 @@ class AppController extends Controller { function sideMenuAreaName($name, $area, $subarea = null) { $this->sideMenuAreaVerify($area, $subarea); if (empty($subarea)) - $this->sidemenu_areas[$area]['name'] = $name; + $this->sidemenu['areas'][$area]['name'] = $name; else - $this->sidemenu_areas[$area]['subarea'][$subarea]['name'] = $name; + $this->sidemenu['areas'][$area]['subareas'][$subarea]['name'] = $name; + } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: sideMenuAreaActivate + * - Sets the selected area/subarea to be active when the + * page is first loaded. + */ + + function sideMenuAreaActivate($area, $subarea = null) { + $this->sidemenu['active'] = compact('area', 'subarea'); } @@ -133,9 +146,9 @@ class AppController extends Controller { function sideMenuEnable($area, $subarea = null, $enable = true) { $this->sideMenuAreaVerify($area, $subarea); if (isset($subarea)) - $this->sidemenu_areas[$area]['subarea'][$subarea]['enable'] = $enable; + $this->sidemenu['areas'][$area]['subareas'][$subarea]['enable'] = $enable; else - $this->sidemenu_areas[$area]['enable'] = $enable; + $this->sidemenu['areas'][$area]['enable'] = $enable; } @@ -150,7 +163,7 @@ class AppController extends Controller { if (empty($subarea)) $subarea = $this->std_area; $this->sideMenuAreaVerify($area, $subarea); - $this->sidemenu_areas[$area]['subarea'][$subarea]['priorities'][$priority][] + $this->sidemenu['areas'][$area]['subareas'][$subarea]['priorities'][$priority][] = array('name' => $name, 'url' => $url) + (empty($extra) ? array() : $extra); } @@ -280,24 +293,36 @@ class AppController extends Controller { $this->params['admin'] = false; } - foreach ($this->sidemenu_areas AS &$area) { + foreach ($this->sidemenu['areas'] AS &$area) { if (empty($area['enable'])) $area = array(); - if (empty($area['subarea'])) + if (empty($area['subareas'])) continue; - ksort($area['subarea']); + ksort($area['subareas']); - foreach ($area['subarea'] AS &$subarea) { + foreach ($area['subareas'] AS &$subarea) { if (empty($subarea['enable'])) $subarea = array(); if (empty($subarea['priorities'])) continue; ksort($subarea['priorities']); } + unset($subarea); + } + unset($area); + + // Activate a default section (unless already specified) + foreach (array_reverse($this->sidemenu['areas']) AS $area_name => $area) { + if (empty($area)) + continue; + + if (empty($this->sidemenu['active']) || + empty($this->sidemenu['areas'][$this->sidemenu['active']['area']])) + $this->sideMenuAreaActivate($area_name); } - //pr($this->sidemenu_areas); - $this->set('sidemenu', $this->sidemenu_areas); + //pr($this->sidemenu); + $this->set('sidemenu', $this->sidemenu); } @@ -375,6 +400,7 @@ class AppController extends Controller { function gridView($title, $action = null, $element = null) { $this->sideMenuEnable('SITE', $this->op_area); + $this->sideMenuAreaActivate('CONTROLLER'); $this->set('title', $title); // The resulting page will contain a grid, which will // use ajax to obtain the actual data for this action diff --git a/site/views/elements/sidemenu.ctp b/site/views/elements/sidemenu.ctp index 2bc94be..3273cca 100644 --- a/site/views/elements/sidemenu.ctp +++ b/site/views/elements/sidemenu.ctp @@ -13,15 +13,29 @@ echo('
' . "\n"); -foreach ($menu AS $area) { - if (empty($area['subarea'])) +$section = 0; +$active_section = null; +foreach ($menu['areas'] AS $area_name => $area) { + if (empty($area['subareas'])) continue; - foreach ($area['subarea'] AS $subarea) { + foreach ($area['subareas'] AS $subarea_name => $subarea) { if (empty($subarea['priorities'])) continue; - echo('

' . $subarea['name'] . "

\n"); + if (!isset($active_section) && + !empty($menu['active']['area']) && $area_name == $menu['active']['area'] && + (empty($menu['active']['subarea']) || $subarea_name == $menu['active']['subarea'])) + $active_section = $section; + + ++$section; + + echo('' . + $subarea['name'] . + "\n"); + echo('
' . "\n"); foreach ($subarea['priorities'] AS $priority) { foreach ($priority AS $item) { @@ -40,13 +54,16 @@ foreach ($menu AS $area) { } echo('
' . "\n"); +//pr(compact('section', 'active_section')); + ?> @@ -247,8 +296,12 @@ echo($this->element array('class' => 'item customer detail', 'caption' => isset($this->data['Customer']) ? 'Edit Customer' : 'New Customer', 'fields' => array - ('name' => true, - 'comment' => true, + ('name' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => ("Optional: If this field is left blank, the" . + " customer name will be set to the name of" . + " the primary contact, below.")), + 'comment' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => 'Optional: Comments about this customer.'), ))) . "\n"); echo $form->submit(isset($this->data['Customer']) ? 'Update' : 'Add New Customer') . "\n"; diff --git a/site/views/elements/form_table.ctp b/site/views/elements/form_table.ctp index 7394f83..e8a8ab6 100644 --- a/site/views/elements/form_table.ctp +++ b/site/views/elements/form_table.ctp @@ -32,8 +32,8 @@ foreach ($fields AS $field => $config) { $include_after = true; } - -$column_class = array(); +if (empty($column_class)) + $column_class = array(); if ($include_before) $column_class[] = 'before'; $column_class[] = 'field'; @@ -79,7 +79,13 @@ foreach ($fields AS $field => $config) { $cells[] = null; } - $name = $config['name']; + if (empty($config['opts']['label'])) + $name = $form->label($field, $config['name'], + empty($config['label_attributes']) + ? null : $config['label_attributes']); + else + $name = $config['name']; + if (isset($config['with_name_before'])) $name = $config['with_name_before'] . $name; elseif (isset($with_name_before)) diff --git a/site/views/elements/table.ctp b/site/views/elements/table.ctp index aef240a..3af46a8 100644 --- a/site/views/elements/table.ctp +++ b/site/views/elements/table.ctp @@ -52,8 +52,8 @@ if (isset($rows) && is_array($rows) && count($rows)) { foreach ($rows AS $r => &$row) { foreach ($row AS $c => $col) { - $cell_class = implode(" ", array_merge(isset( $row_class[$r]) ? $row_class[$r] : array(), - isset($column_class[$c]) ? $column_class[$c] : array())); + $cell_class = implode(" ", array_merge(empty( $row_class[$r]) ? array() : $row_class[$r], + empty($column_class[$c]) ? array() : $column_class[$c])); if ($cell_class) $row[$c] = array($col, array('class' => $cell_class)); } @@ -65,11 +65,11 @@ if (isset($rows) && is_array($rows) && count($rows)) { // OK, output the table HTML echo('' . "\n"); - if (isset($caption)) + if (!empty($caption)) echo(' ' . $caption . '' . "\n"); if (isset($headers) && is_array($headers)) { diff --git a/site/webroot/css/layout.css b/site/webroot/css/layout.css index d6392af..047e071 100644 --- a/site/webroot/css/layout.css +++ b/site/webroot/css/layout.css @@ -46,7 +46,7 @@ span.fmt-age.delinquent { color: #f00; } table.item th , table.item td { padding: 0.1em 0.4em 0.1em 0.4em; } -table.item td { white-space: nowrap; } +table.item td.name { white-space: nowrap; } /* table.item { border-spacing: 0 0; /\*IE*\/border-collapse: collapse; empty-cells: show } */ table.item { border-spacing: 0 0; empty-cells: show } table.item { border:1px solid #ccc; @@ -122,6 +122,11 @@ div.detail.supporting { clear : both; .edit table.detail { width : 80%; float : none; } +table.item td { vertical-align: top; } +.edit .item td.field .required { color: #33f } +.edit .item td.field .recommended { color: #35d } +.edit .item td.field .recommended.empty { color: #f5d } +.edit .item td.field .required.empty { color: #f33 } /************************************************************ From 73eeba04fe782c950eba424bc2415df5d4f14acc Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 24 Aug 2009 06:53:51 +0000 Subject: [PATCH 017/103] As with last checkin for customer, we now have special coloration for required fields, as well as blank required fields. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@754 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/views/contacts/edit.ctp | 117 +++++++++++++++++++++++++--------- site/views/customers/edit.ctp | 2 +- 2 files changed, 89 insertions(+), 30 deletions(-) diff --git a/site/views/contacts/edit.ctp b/site/views/contacts/edit.ctp index 163af2f..3d1fc26 100644 --- a/site/views/contacts/edit.ctp +++ b/site/views/contacts/edit.ctp @@ -45,6 +45,7 @@ function contactMethodDiv($obj, $type, $legend, $values = null) { ' CLASS="'.$type.'-method-%{id}-source" ' . "\n" . ' ID="'.$type.'-method-%{id}-source-'.$stype.'"' . "\n" . ' VALUE="'.$stype.'"' . "\n" . + ($stype == 'new' ? ' CHECKED' . "\n" : '') . ' />' . "\n" . ' ' . "\n" . ' '; @@ -76,21 +77,30 @@ function contactMethodDiv($obj, $type, $legend, $values = null) { 'fields' => array ( 'preference' => array - ('opts' => array + ('label_attributes' => array('class' => 'required'), + 'opts' => array ('options' => $obj->varstore['methodPreferences'], 'selected' => (isset($values) ? $values['ContactsMethod']['preference'] : null), - )), + ), + 'after' => "Intended purpose for using this method of communication.", + ), 'type' => array - ('opts' => array + ('label_attributes' => array('class' => 'required'), + 'opts' => array ('options' => $obj->varstore['methodTypes'], 'selected' => (isset($values) ? $values['ContactsMethod']['type'] : null), - )), + ), + 'after' => "How / Where this communication reaches the contact.", + ), 'comment' => array - ('opts' => array + ('label_attributes' => array('class' => 'optional empty'), + 'opts' => array ('value' => (isset($values) ? $values['ContactsMethod']['comment'] : null), - )), + ), + 'after' => "Optional: Comments on how this form of communication relates to the contact.", + ), ))) . "\n" . @@ -113,16 +123,23 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { if ($type === 'phone') { if ($stype === 'existing') { $fields = array - ('id' => array('name' => 'Phone/Ext', + ('id' => array('label_attributes' => array('class' => 'required empty'), + 'name' => 'Phone/Ext', 'opts' => array('options' => $obj->varstore['contactPhones'])), ); } elseif ($stype === 'new') { $fields = array - ('type' => array('opts' => array('options' => $obj->varstore['phoneTypes'])), - 'phone' => true, - 'ext' => array('name' => "Extension"), - 'comment' => true, + ('type' => array('label_attributes' => array('class' => 'required'), + 'opts' => array('options' => $obj->varstore['phoneTypes']), + 'after' => "Physical type of the phone."), + 'phone' => array('label_attributes' => array('class' => 'required empty'), + 'after' => "Required: Phone number."), + 'ext' => array('name' => "Extension", + 'label_attributes' => array('class' => 'optional empty'), + 'after' => "Optional: Extension number."), + 'comment' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => "Optional: Comments about this phone number."), ); } elseif ($stype === 'show') { @@ -149,12 +166,19 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { } elseif ($stype === 'new') { $fields = array - ('address' => true, - 'city' => true, - 'state' => true, - 'postcode' => array('name' => 'Zip Code'), - 'country' => true, - 'comment' => true, + ('address' => array('label_attributes' => array('class' => 'required empty'), + 'after' => "Required: First line of mailing address."), + 'city' => array('label_attributes' => array('class' => 'required empty'), + 'after' => "Required."), + 'state' => array('label_attributes' => array('class' => 'required empty'), + 'after' => "Required."), + 'postcode' => array('name' => 'Zip Code', + 'label_attributes' => array('class' => 'required empty'), + 'after' => "Required."), + 'country' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => "Optional: USA is presumed."), + 'comment' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => "Optional: Comments about this mailing address."), ); } elseif ($stype === 'show') { @@ -177,13 +201,16 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { if ($stype === 'existing') { $fields = array ('id' => array('name' => 'Email', + 'label_attributes' => array('class' => 'required'), 'opts' => array('options' => $obj->varstore['contactEmails'])), ); } elseif ($stype === 'new') { $fields = array - ('email' => true, - 'comment' => true, + ('email' => array('label_attributes' => array('class' => 'required empty'), + 'after' => "Required: E-mail address."), + 'comment' => array('label_attributes' => array('class' => 'optional empty'), + 'after' => "Optional: Comments about this email address."), ); } elseif ($stype === 'show') { @@ -204,7 +231,7 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { '