Design notes for the Monitor Accounts feature:
Created by James A. Pattie
May 14, 2002
Updated: October 1, 2002


This feature will be split into two parts, the user interface and the cron job.

Database changes:
The following entries will need to be made in the config_tb table:
monitorAccountsMailServer = 'ip or name of mail server to use'

The monitor_tb table will be defined as follows:
CREATE TABLE monitor_tb (
  id SERIAL,
  ledger_code varchar NOT NULL,
  xml varchar NOT NULL,
  PRIMARY KEY id
);

The data stored in the xml document - module = 'MonitorAccounts', version = '1.0' will be:
  ledger_code string,
  accounts string,
  emails string,
  users string,
  less_than float,
  greater_than float,
  mode string DEFAULT 'and',
  mail_type string DEFAULT 'html'

The xml document will be parsed using PCXPortal 0.2.00's Portal::XML::ConfigParser module which will return a Portal::XML::ConfigObject module (which is just a hash of the name, value entries in the xml document).

User Interface:
The file Portal::Accounting::Config::Monitor.pm will contain the Account Monitor methods, etc.

The user interface will show the user the entries for the current ledger, the accounts assigned to that ledger, who to email (by selecting from current Portal users and/or specifying email addresses) and what the minimum and maximum values are to check for.  You will have to open each ledger and enter the MonitorAccounts module to work with all ledgers.  This way when we assign users to specific ledgers we are half way done on the validation code.

The admin will be able to globally specify the mail server to use when sending emails via the Mail::Sender package (text and html) through the normal Configuration sub system.  This will require a generic screen to be created and will be accessed in the Monitor.pm module.

Cronjob:
The file /usr/lib/pcx_portal/cron/Accounting/daily/monitor_accounts will be a perl script that does the actual work.

The cron job will get a list of all entries in the monitor_tb and will proceed to do the specified checks for the specified accounts of each entry.  If a match is found for a given condition, then an email will be sent to each person in the emails and users variables alerting them of the condition.

The accounts, users and emails values can be comma seperated lists of accounts, user names or email addresses.

If the less_than value is empty then we will not do the < comparison.
If the greater_than value is empty then we will not do the > comparison.
If both less_than and greater_than are empty then the front end made an error.

mode can be either 'and' or 'or'.  This will provide the ability for the user to specify how they want the comparison done.  The less_than will be compared before greater_than when both are present.  At that point the mode comes into play, otherwise if only one of less_than or greater_than is defined, then we just do the implied check.

Cronjob output:
If a match is found, then each specified user for that check will be emailed informing them via an HTML email if mail_type = 'html':

Ledger | Account | < | > | Actual
-------------------------------------
X            |              Y | 0  |     |  -5.00


The output will be formatted in a table.

Or if the mail_type is 'text' then the output will look like the above but will be formatted with Tabs, etc.

The cron job will by default be symlinked to from the /etc/cron.daily folder (which normally runs at 4am every day).  If the user wants it to run at some other time, all they have to do is delete the symlink and then run (as root) crontab -e and add the times and days of the week, month, etc. that they want the script to run.  They should point to /usr/lib/pcx_portal/cron/Accounting/daily/monitor_accounts.