Implemented a mechanism to track customer overpayments (credits). Also implemented a reconciling algorithm, matching payments to charges. Preliminary testing seems to show that it works well. More thorough testing required.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@392 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-27 04:18:38 +00:00
parent 68fe787209
commit 3dc751c863
5 changed files with 253 additions and 17 deletions

View File

@@ -1032,6 +1032,23 @@ foreach $row (@{query($sdbh, $query)}) {
dates('charge', $row->{'ChargeDate'}, $row->{'EndDate'},
$row->{'ChargeDescription'}, $row->{'LedgerID'});
# Fix Brenda Harmon bug
$row->{'ChargeAmount'} = 50
if ($row->{'ChargeID'} == 19);
# # REVISIT <AP>: 20090726
# # Temporary testing of customer credits
# $row->{'ChargeAmount'} = 49
# if ($row->{'ChargeID'} == 19);
# #next if $row->{'ChargeID'} == 3777;
# #next if $row->{'ChargeID'} == 3838;
# $row->{'ChargeAmount'} = .80
# if $row->{'ChargeID'} == 3777;
# $row->{'ChargeAmount'} = .15
# if $row->{'ChargeID'} == 3838;
# # END REVISIT <AP>: 20090726
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}
= $row->{'ChargeAmount'};
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}
@@ -1215,6 +1232,7 @@ foreach $row (@{query($sdbh, $query)}) {
'account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'crdr' => 'CREDIT',
'comment' => "Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}
@@ -1286,7 +1304,28 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'payment'} = {};
$query = "SELECT * FROM Payments ORDER BY PaymentID";
foreach $row (@{query($sdbh, $query)})
foreach $row (@{query($sdbh, $query)},
## Special case - Fix sitelink Brenda Harmon bug
( 0 ?
{ 'PaymentDate' => '4/1/2009 05:01',
'ReceiptNum' => 10,
'PaymentType' => 2,
'PaymentID' => 99991,
'ChargeID' => 3777,
'PaymentAmount' => 1,
'Memo' => 'Utilized credit left by $1 overpayment',
} : ()),
( 0 ?
{ 'PaymentDate' => '4/1/2009 05:01',
'ReceiptNum' => 10,
'PaymentType' => 2,
'PaymentID' => 99991,
'ChargeID' => 19,
'PaymentAmount' => 1.00,
'entry_type' => 'CREDIT',
'Memo' => 'Overpayment left $1 credit',
} : ()),
)
{
my (undef, $effective_date, $through_date) =
dates('payment', $row->{'PaymentDate'});
@@ -1302,13 +1341,18 @@ foreach $row (@{query($sdbh, $query)})
# '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'},
'lease_id' => ($row->{'entry_type'} eq 'CREDIT'
? 0
: $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'}}{'credit_account_id'},
};
$row->{'ChargeID'} = undef
if $row->{'entry_type'} eq 'CREDIT';
# Update the receipt customer_id, now that we have payment info
$newdb{'tables'}{'transactions'}{'rows'}[
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'}
@@ -1316,11 +1360,12 @@ foreach $row (@{query($sdbh, $query)})
# Use the Memo as our comment, if it exists
my $comment = $row->{'Memo'} || "Payment: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}";
$comment = "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' => 'PAYMENT',
'type' => $row->{'entry_type'} || 'PAYMENT',
# 'effective_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'effective_date'},
# 'through_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'through_date'},
'effective_date' => $effective_date,
@@ -1353,16 +1398,6 @@ if ($newdb{'lookup'}{'_closing'}{'credit_entry_id'}) {
}
######################################################################
## Special cases - Fix sitelink Brenda Harmon bug
# print("Special Cases - Fix Brenda Harmon...\n");
# $query =
# "UPDATE pmgr_contacts" .
# " SET first_name = 'Krystan'" .
# " WHERE first_name = 'Kristan' AND last_name = 'Mancini'";
# query($db_handle, $query);
######################################################################
## Special case - Equities / Loans / Petty Cash