Modified the closing sum to be a single receipt, and a single debit/credit to the ledger of choice (presently Equity). This was mostly a test to check the logic of multiple payments having only a single accounting transaction. It seems to work, but I suspect we'll have trouble when we start to figure out customer account balances, since the receipt has NULL for the customer_id (since it is a receipt for many customers). Depending on the customer balance / reconciliation logic, this may or may not fly.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@379 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-24 03:12:18 +00:00
parent 1e0b96953e
commit 0f00b42d1f

View File

@@ -254,7 +254,7 @@ sub dates {
# 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' || $type eq 'payment') {
if ($type eq 'invoice') {
$effective_dt = undef;
$through_dt = undef;
}
@@ -624,10 +624,11 @@ foreach my $account_type (keys(%SITELINK_ACCOUNT_TYPE)) {
$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'},
'debit_account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'credit_account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
};
@@ -1163,7 +1164,7 @@ foreach $row (@{query($sdbh, $query)}) {
'amount' => $row->{'ReceiptAmount'},
};
if ($row->{'ReceiptDate'} =~ m%3/25/2009%) {
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'}
@@ -1172,6 +1173,19 @@ foreach $row (@{query($sdbh, $query)}) {
= $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'}
@@ -1182,6 +1196,10 @@ foreach $row (@{query($sdbh, $query)}) {
= $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'}} == 'Check') {
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
@@ -1204,14 +1222,8 @@ foreach $row (@{query($sdbh, $query)}) {
= $newdb{'tables'}{'transactions'}{'autoid'};
# Receipt must debit the "money" asset (bank, cash, check, etc)...
# (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'}
= $newdb{'lookup'}{'account'}{'A/R'}{'account_id'};
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'}
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
# (These were set above, based on whether part of closing or not)
foreach ('debit', 'credit') {
my $CRDR = $_;
@@ -1251,6 +1263,20 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'payment_id'}
= $newdb{'tables'}{'tenders'}{'autoid'};
# Special case for closing
if ($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'}}{'payment_id'};
}
}
@@ -1263,6 +1289,9 @@ $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'};
@@ -1271,7 +1300,9 @@ foreach $row (@{query($sdbh, $query)})
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
= { 'receipt_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'},
'effective_date' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'effective_date'},
# '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,
@@ -1291,7 +1322,10 @@ foreach $row (@{query($sdbh, $query)})
addRow('statement_entries', {
'transaction_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'},
'type' => 'PAYMENT',
'effective_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'effective_date'},
# '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'},
@@ -1305,6 +1339,17 @@ foreach $row (@{query($sdbh, $query)})
}
######################################################################
## Special case - Fix the entries for our closing transaction
$newdb{'tables'}{'ledger_entries'}{'rows'}[
$newdb{'lookup'}{'_closing'}{'debit_entry_id'}
]{'amount'} = $newdb{'lookup'}{'_closing'}{'amount'};
$newdb{'tables'}{'ledger_entries'}{'rows'}[
$newdb{'lookup'}{'_closing'}{'credit_entry_id'}
]{'amount'} = $newdb{'lookup'}{'_closing'}{'amount'};
######################################################################
## Special cases - Fix sitelink Brenda Harmon bug
# print("Special Cases - Fix Brenda Harmon...\n");