Modified tenders to use a tender_type_id, not only for the ability to dynamically add types later, but primarily so that a type could be associated with an account, instead of hardcoding it in the application. With this, I changed several of the account field names, but they shouldn't be in too heavy use in the application.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@376 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
103
db/schema.sql
103
db/schema.sql
@@ -842,12 +842,11 @@ CREATE TABLE `pmgr_accounts` (
|
||||
-- For LIABILITY, EQUITY, and INCOME, the opposite
|
||||
-- is true, with reconciliations posted, under
|
||||
-- normal circumstances, when a debit occurs.
|
||||
`trackable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
|
||||
`tillable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Does manager collect by hand?
|
||||
`depositable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Does this account receive deposits?
|
||||
`chargeable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for charges?
|
||||
`payable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for payments?
|
||||
`refundable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for refunds?
|
||||
-- `trackable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
|
||||
`deposits` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for deposits?
|
||||
`charges` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for charges?
|
||||
`payments` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for payments?
|
||||
`refunds` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, -- Can be used for refunds?
|
||||
|
||||
-- Security Level
|
||||
`level` INT UNSIGNED DEFAULT 10,
|
||||
@@ -874,33 +873,34 @@ INSERT INTO `pmgr_accounts` (`type`, `name`)
|
||||
-- us identify how serious the NSF situation is.
|
||||
('ASSET', 'NSF' ),
|
||||
('LIABILITY', 'A/P' );
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `tillable`, `payable`, `refundable`)
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `payments`, `refunds`)
|
||||
VALUES
|
||||
('ASSET', 'Cash', 1, 1, 1),
|
||||
('ASSET', 'Check', 1, 1, 0),
|
||||
('ASSET', 'Money Order', 1, 1, 0),
|
||||
('ASSET', 'ACH', 0, 1, 0),
|
||||
('EXPENSE', 'Concession', 0, 1, 0);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `refundable`, `depositable`)
|
||||
('ASSET', 'Cash', 1, 1),
|
||||
('ASSET', 'Check', 1, 0),
|
||||
('ASSET', 'Money Order', 1, 0),
|
||||
('ASSET', 'ACH', 1, 0),
|
||||
('ASSET', 'Closing', 0, 0), -- REVISIT <AP>: Temporary
|
||||
('EXPENSE', 'Concession', 1, 0);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `refunds`, `deposits`)
|
||||
VALUES
|
||||
-- REVISIT <AP>: 20090710 : We probably don't really want petty cash depositable.
|
||||
-- This is just for testing our deposit code
|
||||
('ASSET', 'Petty Cash', 1, 1);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `chargeable`, `trackable`)
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `charges`)
|
||||
VALUES
|
||||
('LIABILITY', 'Tax', 1, 1),
|
||||
('LIABILITY', 'Security Deposit', 1, 1),
|
||||
('INCOME', 'Rent', 1, 0),
|
||||
('INCOME', 'Late Charge', 1, 0),
|
||||
('INCOME', 'NSF Charge', 1, 0),
|
||||
('INCOME', 'Damage', 1, 0);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `depositable`, `refundable`, `trackable`)
|
||||
('LIABILITY', 'Tax', 1),
|
||||
('LIABILITY', 'Security Deposit', 1),
|
||||
('INCOME', 'Rent', 1),
|
||||
('INCOME', 'Late Charge', 1),
|
||||
('INCOME', 'NSF Charge', 1),
|
||||
('INCOME', 'Damage', 1);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `deposits`, `refunds`)
|
||||
VALUES
|
||||
('ASSET', 'Bank', 1, 1, 0);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`, `trackable`)
|
||||
('ASSET', 'Bank', 1, 1);
|
||||
INSERT INTO `pmgr_accounts` (`type`, `name`)
|
||||
VALUES
|
||||
('EXPENSE', 'Bad Debt', 0),
|
||||
('EXPENSE', 'Maintenance', 0);
|
||||
('EXPENSE', 'Bad Debt' ),
|
||||
('EXPENSE', 'Maintenance' );
|
||||
UNLOCK TABLES;
|
||||
|
||||
|
||||
@@ -1113,6 +1113,45 @@ CREATE TABLE `pmgr_statement_entries` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_tender_types
|
||||
|
||||
DROP TABLE IF EXISTS `pmgr_tender_types`;
|
||||
CREATE TABLE `pmgr_tender_types` (
|
||||
`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 legal tender name.
|
||||
`name` VARCHAR(80) NOT NULL,
|
||||
|
||||
-- Does this form of legal tender actually change hands?
|
||||
-- If so, then it's tillable. Examples include cash,
|
||||
-- checks, and money orders. Things that are not tillable
|
||||
-- include credit cards, debit cards, and ACH transfers.
|
||||
`tillable` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
|
||||
|
||||
-- How many data fields are required/used by this type.
|
||||
-- Not the most robust of solutions, especially since
|
||||
-- it requires (or strongly implicates) that all fields
|
||||
-- be of the same type (ugh). A more complete solution
|
||||
-- would be for each type to have its own table of data
|
||||
-- and to have that table specified here. However, this
|
||||
-- is MUCH simpler, and works for now.
|
||||
`data_fields` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
|
||||
-- When we accept legal tender of this form, where does
|
||||
-- it go? Each type of legal tender can specify an
|
||||
-- account, either distinct or non-distinct from others
|
||||
`account_id` INT(10) UNSIGNED NOT NULL,
|
||||
|
||||
|
||||
`comment` VARCHAR(255) DEFAULT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
-- ----------------------------------------------------------------------
|
||||
-- TABLE pmgr_tenders
|
||||
@@ -1125,18 +1164,8 @@ CREATE TABLE `pmgr_tenders` (
|
||||
-- for example, 'Check #1234' as the legal tender 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,
|
||||
-- The type of this legal tender
|
||||
`tender_type_id` INT(10) UNSIGNED DEFAULT NULL,
|
||||
|
||||
-- REVISIT <AP>: 20090605
|
||||
-- Check Number;
|
||||
|
||||
@@ -510,7 +510,6 @@ foreach $row (@$result) {
|
||||
|
||||
$newdb{'lookup'}{'account'}{$row->{'name'}}
|
||||
= {'account_id' => $row->{'id'},
|
||||
'tillable' => $row->{'tillable'},
|
||||
'ledger_id' => $newdb{'tables'}{'ledgers'}{'autoid'} };
|
||||
|
||||
if ((!defined $newdb{'tables'}{'accounts'}{'autoid'}) ||
|
||||
@@ -534,21 +533,91 @@ $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',
|
||||
#'Debit Card', 'Credit Card',
|
||||
) {
|
||||
my ($tillable, $fields) = (0, 0);
|
||||
|
||||
$tillable = 1
|
||||
if ($tender_name =~ /^Cash|Check|Money Order$/);
|
||||
|
||||
$fields = 1 # Check / Money Order Number
|
||||
if ($tender_name =~ /^Check|Money Order$/);
|
||||
|
||||
$fields = 2 # Routing Number, Account Number
|
||||
if ($tender_name =~ /^ACH$/);
|
||||
|
||||
$fields = 3 # Card Number, Expiration, Billing Zip
|
||||
if ($tender_name =~ / Card$/);
|
||||
|
||||
addRow('tender_types', {
|
||||
'name' => $tender_name,
|
||||
'account_id' => $newdb{'lookup'}{'account'}{$tender_name}{'account_id'},
|
||||
'tillable' => $tillable,
|
||||
'data_fields' => $fields,
|
||||
});
|
||||
$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'} = {};
|
||||
$newdb{'lookup'}{'payment_type'}{1}
|
||||
= { 'name' => 'Cash', 'account_name' => 'Cash' };
|
||||
$newdb{'lookup'}{'payment_type'}{2}
|
||||
= { 'name' => 'Check', 'account_name' => 'Check' };
|
||||
$newdb{'lookup'}{'payment_type'}{3}
|
||||
= { 'name' => 'Money Order', 'account_name' => 'Money Order' };
|
||||
$newdb{'lookup'}{'payment_type'}{4}
|
||||
= { 'name' => 'ACH', 'account_name' => 'Bank' };
|
||||
$newdb{'lookup'}{'payment_type'}{12}
|
||||
= { 'name' => 'Concession', 'account_name' => 'Concession' };
|
||||
|
||||
# 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',
|
||||
'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'},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1083,19 +1152,25 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
|
||||
if ($row->{'ReceiptDate'} =~ m%3/25/2009%) {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
|
||||
= 'Closing';
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'account_name'}
|
||||
= 'Bank';
|
||||
= $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'};
|
||||
}
|
||||
else {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
|
||||
= $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'name'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'}
|
||||
= $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'account_name'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'account_name'}
|
||||
= $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'account_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'};
|
||||
|
||||
if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'} eq 'Check') {
|
||||
if ($SITELINK_ACCOUNT_TYPE{$row->{'PaymentType'}} == 'Check') {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
|
||||
= 'Check #' . $row->{'CheckNum'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'}
|
||||
@@ -1103,10 +1178,6 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
}
|
||||
}
|
||||
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'} = undef
|
||||
if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'}
|
||||
== 'Concession');
|
||||
|
||||
addRow('transactions', {
|
||||
'type' => 'RECEIPT',
|
||||
'stamp' => $stamp,
|
||||
@@ -1120,14 +1191,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
= $newdb{'tables'}{'transactions'}{'autoid'};
|
||||
|
||||
# Receipt must debit the "money" asset (bank, cash, check, etc)...
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'}
|
||||
= $newdb{'lookup'}{'account'}{
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'account_name'}
|
||||
}{'account_id'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_ledger_id'}
|
||||
= $newdb{'lookup'}{'account'}{
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'account_name'}
|
||||
}{'ledger_id'};
|
||||
# (This was set above, based on whether part of closing or not)
|
||||
|
||||
# ...and credit the A/R ledger
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_account_id'}
|
||||
@@ -1167,7 +1231,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
addRow('tenders', {
|
||||
'ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'},
|
||||
'name' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'},
|
||||
'type' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'},
|
||||
'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'}",
|
||||
});
|
||||
@@ -1410,4 +1474,3 @@ $query = "UPDATE pmgr_transactions T, pmgr_ledger_entries E
|
||||
WHERE E.transaction_id = T.id AND E.account_id = T.account_id";
|
||||
query($db_handle, $query);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user