This rework is nowhere near complete, but there are certain things that are falling in place, and worth capturing. I started a branch for just this purpose of being able to check in intermediate work.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@352 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-19 23:35:25 +00:00
parent e303898a95
commit 6ac0204baf
26 changed files with 3058 additions and 1767 deletions

View File

@@ -869,8 +869,6 @@ INSERT INTO `pmgr_accounts` (`type`, `name`, `level`)
INSERT INTO `pmgr_accounts` (`type`, `name`)
VALUES
('ASSET', 'A/R' ),
('ASSET', 'Invoice' ),
('ASSET', 'Receipt' ),
-- REVISIT <AP>: 20090710 : We don't really need NSF, as it
-- will always run a zero balance. However, it will help
-- us identify how serious the NSF situation is.
@@ -896,9 +894,9 @@ INSERT INTO `pmgr_accounts` (`type`, `name`, `chargeable`, `trackable`)
('INCOME', 'Late Charge', 1, 0),
('INCOME', 'NSF Charge', 1, 0),
('INCOME', 'Damage', 1, 0);
INSERT INTO `pmgr_accounts` (`type`, `name`, `depositable`, `trackable`)
INSERT INTO `pmgr_accounts` (`type`, `name`, `depositable`, `refundable`, `trackable`)
VALUES
('ASSET', 'Bank', 1, 0);
('ASSET', 'Bank', 1, 1, 0);
INSERT INTO `pmgr_accounts` (`type`, `name`, `trackable`)
VALUES
('EXPENSE', 'Bad Debt', 0),
@@ -970,89 +968,139 @@ DROP TABLE IF EXISTS `pmgr_transactions`;
CREATE TABLE `pmgr_transactions` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- `type` ENUM('INVOICE',
-- 'RECEIPT')
-- NOT NULL,
`type` ENUM('INVOICE',
'CREDIT',
'RECEIPT',
'REFUND',
'TRANSFER')
NOT NULL,
`stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- amount is for convenience. It can always be calculated from
-- the associated double entries (and therefore will need to be
-- updated if they should change in any way).
`amount` FLOAT(12,2) DEFAULT NULL,
-- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- `lease_id` INT(10) UNSIGNED DEFAULT NULL,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- -- ----------------------------------------------------------------------
-- -- -- ----------------------------------------------------------------------
-- -- -- TABLE pmgr_charge_details
-- DROP TABLE IF EXISTS `pmgr_charge_details`;
-- CREATE TABLE `pmgr_charge_details` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- -- Through date is used if/when a charge covers a certain time period,
-- -- like rent. A security deposit, for example, would not use the
-- -- through date.
-- `through_date` DATE DEFAULT NULL, -- last day
-- `due_date` DATE DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- -- ----------------------------------------------------------------------
-- -- -- ----------------------------------------------------------------------
-- -- -- TABLE pmgr_payment_details
-- DROP TABLE IF EXISTS `pmgr_payment_details`;
-- CREATE TABLE `pmgr_payment_details` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- -- name may (or may not) be used to clarify in reports
-- -- for example, 'Check #1234' as the payment name.
-- `name` VARCHAR(80) DEFAULT NULL,
-- -- REVISIT <AP>: 20090716
-- -- Type may needs to be another table, so that the user
-- -- can add new types. If so, they will also have to
-- -- specify the required data1/2/3/4 fields.
-- -- For now, this will work.
-- `monetary_type` ENUM('CASH',
-- 'CHECK',
-- 'MONEYORDER',
-- 'ACH',
-- 'DEBITCARD',
-- 'CREDITCARD')
-- DEFAULT NULL,
-- -- REVISIT <AP>: 20090605
-- -- Check Number;
-- -- Routing Number, Account Number;
-- -- Card Number, Expiration Date; CVV2 Code
-- -- etc.
-- -- REVISIT <AP> 20090630
-- -- I _think_ that CVV2 is NEVER supposed to
-- -- be stored ANYWHERE. Merchants agree to
-- -- use it only to verify the transaction and
-- -- then leave no record of it, so that even
-- -- if their security is compromised, no one
-- -- will know the CVV2 code unless they are
-- -- in physical possession of the card.
-- `data1` VARCHAR(80) DEFAULT NULL,
-- `data2` VARCHAR(80) DEFAULT NULL,
-- `data3` VARCHAR(80) DEFAULT NULL,
-- `data4` VARCHAR(80) DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_entries
DROP TABLE IF EXISTS `pmgr_entries`;
CREATE TABLE `pmgr_entries` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`type` ENUM('CHARGE',
'PAYMENT',
'TRANSFER')
NOT NULL,
-- The account of the entry
`account_id` INT(10) UNSIGNED DEFAULT NULL,
`crdr` ENUM('DEBIT',
'CREDIT')
NOT NULL,
-- The actual ledgers where this entry is recorded
`double_entry_id` INT(10) UNSIGNED DEFAULT NULL,
-- Through date is used if/when a charge covers a certain time period,
-- like rent. A security deposit, for example, would not use the
-- through date.
`through_date` DATE DEFAULT NULL, -- last day
`due_date` DATE DEFAULT NULL,
-- REVISIT <AP>: 20090604
-- How should we track which charges have been paid?
-- `related_transaction_id` INT(10) UNSIGNED NOT NULL,
-- `related_entry_id` INT(10) UNSIGNED NOT NULL,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_ledger_entries
DROP TABLE IF EXISTS `pmgr_ledger_entries`;
CREATE TABLE `pmgr_ledger_entries` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- Effective date may be used for a variety of entries
-- charges & payments are not always effective at the
-- time of transaction. Through date, on the other hand,
-- will probably only be relevant for charges, such as
-- rent, which is effective for a range of dates.
`effective_date` DATE DEFAULT NULL, -- first day
`through_date` DATE DEFAULT NULL, -- last day
`monetary_source_id` INT(10) UNSIGNED DEFAULT NULL, -- NULL if internal transfer
`transaction_id` INT(10) UNSIGNED NOT NULL,
`customer_id` INT(10) UNSIGNED DEFAULT NULL,
`lease_id` INT(10) UNSIGNED DEFAULT NULL,
`amount` FLOAT(12,2) NOT NULL,
-- REVISIT <AP>: 20090707
-- Experimental. Considering automatically hooking
-- charges to their invoice. This may help ease the
-- ongoing accounting dilema that we've been having.
-- It might allow us to keep the underlying invoice
-- ledgers without having to expose the user to them.
`root_transaction_id` INT(10) UNSIGNED DEFAULT NULL,
`debit_ledger_id` INT(10) UNSIGNED NOT NULL,
`credit_ledger_id` INT(10) UNSIGNED NOT NULL,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_reconciliations
DROP TABLE IF EXISTS `pmgr_reconciliations`;
CREATE TABLE `pmgr_reconciliations` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`debit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
`credit_ledger_entry_id` INT(10) UNSIGNED NOT NULL,
`amount` FLOAT(12,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_monetary_sources
DROP TABLE IF EXISTS `pmgr_monetary_sources`;
CREATE TABLE `pmgr_monetary_sources` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- name may (or may not) be used to clarify in reports
-- for example, 'Check #1234' as the payment name.
`name` VARCHAR(80) DEFAULT NULL,
-- REVISIT <AP>: 20090716
-- Type may needs to be another table, so that the user
-- can add new types. If so, they will also have to
-- specify the required data1/2/3/4 fields.
-- For now, this will work.
`monetary_type` ENUM('CASH',
'CHECK',
'MONEYORDER',
'ACH',
'DEBITCARD',
'CREDITCARD')
DEFAULT NULL,
-- REVISIT <AP>: 20090605
-- Check Number;
-- Routing Number, Account Number;
@@ -1077,6 +1125,237 @@ CREATE TABLE `pmgr_monetary_sources` (
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_reconciliations
DROP TABLE IF EXISTS `pmgr_reconciliations`;
CREATE TABLE `pmgr_reconciliations` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`debit_entry_id` INT(10) UNSIGNED NOT NULL,
`credit_entry_id` INT(10) UNSIGNED NOT NULL,
`amount` FLOAT(12,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_double_entries
DROP TABLE IF EXISTS `pmgr_double_entries`;
CREATE TABLE `pmgr_double_entries` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`transaction_id` INT(10) UNSIGNED DEFAULT NULL,
-- Effective date is when the charge/payment/transfer actually
-- takes effect (since it may not be at the time of the transaction).
`effective_date` DATE DEFAULT NULL, -- first day
`customer_id` INT(10) UNSIGNED DEFAULT NULL,
`lease_id` INT(10) UNSIGNED DEFAULT NULL,
`debit_ledger_id` INT(10) UNSIGNED NOT NULL,
`credit_ledger_id` INT(10) UNSIGNED NOT NULL,
`amount` FLOAT(12,2) NOT NULL,
`comment` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------------------------------------------------
-- ----------------------------------------------------------------------
-- TABLE pmgr_charges_payments
DROP TABLE IF EXISTS `pmgr_charges_payments`;
CREATE TABLE `pmgr_charges_payments` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- Mark which charge the payment reconciles, and how much was applied
`charge_entry_id` INT(10) UNSIGNED NOT NULL,
`payment_entry_id` INT(10) UNSIGNED NOT NULL,
`amount` FLOAT(12,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_folders
-- --
-- -- It's a dumb name, but at the moment, it's how I'm thinking about
-- -- this all. In the generic, a purchase begins with a purchase order
-- -- from the customer. When you receive it, you grab a new manilla
-- -- folder, drop the purchase order in, and start making the widgets.
-- -- when their ready, you ship them with invoice, and drop a copy of
-- -- the invoice in the folder. When they pay, you generate a receipt,
-- -- and drop a copy in the folder. If the check bounces, you note
-- -- that in the folder, and generate a new NSF fee invoice (which gets
-- -- put into its OWN new folder). When they pay again, you generate
-- -- another receipt and put it into the folder, and this process could
-- -- repeat until the invoice finally gets paid, or you write it off as
-- -- a bad debt, which would be noted, of course, in the folder.
-- DROP TABLE IF EXISTS `pmgr_folders`;
-- CREATE TABLE `pmgr_folders` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- `stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- `comment` VARCHAR(255) DEFAULT NULL,
-- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- `lease_id` INT(10) UNSIGNED DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_invoices
-- DROP TABLE IF EXISTS `pmgr_invoices`;
-- CREATE TABLE `pmgr_invoices` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- `stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- -- amount is for convenience. It can always be calculated from
-- -- the attached ledger entries (and therefore will need to be
-- -- updated if they should change in any way).
-- `amount` FLOAT(12,2) DEFAULT NULL,
-- -- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- -- `lease_id` INT(10) UNSIGNED DEFAULT NULL,
-- -- `folder_id` INT(10) UNSIGNED NOT NULL,
-- `comment` VARCHAR(255) DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_charges
-- DROP TABLE IF EXISTS `pmgr_charges`;
-- CREATE TABLE `pmgr_charges` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- -- Effective date is when the charge actually takes effect
-- -- (since it may not be at the time of the invoice). Through
-- -- date is used if/when a charge covers a certain time period,
-- -- like rent. A security deposit, for example, would not use
-- -- the through date.
-- `effective_date` DATE DEFAULT NULL, -- first day
-- `through_date` DATE DEFAULT NULL, -- last day
-- `due_date` DATE DEFAULT NULL,
-- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- `lease_id` INT(10) UNSIGNED DEFAULT NULL,
-- `amount` FLOAT(12,2) DEFAULT NULL,
-- `comment` VARCHAR(255) DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_payments
-- DROP TABLE IF EXISTS `pmgr_payments`;
-- CREATE TABLE `pmgr_payments` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- `stamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- -- Customer ID ensures that they payment doesn't get lost
-- -- in the system if either a) it's a pre-payment, or
-- -- b) the associated invoice is deleted.
-- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- `amount` FLOAT(12,2) DEFAULT NULL,
-- -- name may (or may not) be used to clarify in reports
-- -- for example, 'Check #1234' as the payment name.
-- `name` VARCHAR(80) DEFAULT NULL,
-- -- REVISIT <AP>: 20090716
-- -- Type may needs to be another table, so that the user
-- -- can add new types. If so, they will also have to
-- -- specify the required data1/2/3/4 fields.
-- -- For now, this will work.
-- `type` ENUM('CASH',
-- 'CHECK',
-- 'MONEYORDER',
-- 'ACH',
-- 'DEBITCARD',
-- 'CREDITCARD')
-- DEFAULT NULL,
-- -- REVISIT <AP>: 20090605
-- -- Check Number;
-- -- Routing Number, Account Number;
-- -- Card Number, Expiration Date; CVV2 Code
-- -- etc.
-- -- REVISIT <AP> 20090630
-- -- I _think_ that CVV2 is NEVER supposed to
-- -- be stored ANYWHERE. Merchants agree to
-- -- use it only to verify the transaction and
-- -- then leave no record of it, so that even
-- -- if their security is compromised, no one
-- -- will know the CVV2 code unless they are
-- -- in physical possession of the card.
-- `data1` VARCHAR(80) DEFAULT NULL,
-- `data2` VARCHAR(80) DEFAULT NULL,
-- `data3` VARCHAR(80) DEFAULT NULL,
-- `data4` VARCHAR(80) DEFAULT NULL,
-- `comment` VARCHAR(255) DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- -- ----------------------------------------------------------------------
-- -- ----------------------------------------------------------------------
-- -- TABLE pmgr_transfers
-- DROP TABLE IF EXISTS `pmgr_transfers`;
-- CREATE TABLE `pmgr_transfers` (
-- `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
-- -- Effective date is when the charge actually takes effect
-- -- (since it may not be at the time of the invoice). Through
-- -- date is used if/when a charge covers a certain time period,
-- -- like rent. A security deposit, for example, would not use
-- -- the through date.
-- `effective_date` DATE DEFAULT NULL, -- first day
-- `through_date` DATE DEFAULT NULL, -- last day
-- `due_date` DATE DEFAULT NULL,
-- `customer_id` INT(10) UNSIGNED DEFAULT NULL,
-- `lease_id` INT(10) UNSIGNED DEFAULT NULL,
-- `amount` FLOAT(12,2) DEFAULT NULL,
-- `comment` VARCHAR(255) DEFAULT NULL,
-- PRIMARY KEY (`id`)
-- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ######################################################################
-- ######################################################################