Modified effective dates to be part of the ledger entry, not the transaction. This is the logically correct way, as a transaction is simply a collection of entries which might be anywhere from completely aligned to totally disjoint from one another (more likely the former). As a practical example, consider a move-in invoice, with security deposit (effective immediately with no end date), a prorated rent (effective move-in day through the end of the first month), and first full months rent (effective beginning of next month through the end of next month). There is certainly more work to be done on this, and testing was minimal. It does seem to be functioning though, so I'm checking in.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@256 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -224,6 +224,36 @@ sub datefmt {
|
||||
return sprintf("%04d-%02d-%02d%s", $dt[2], $dt[0], $dt[1], $dt[3] ? ' '.$dt[3] : "");
|
||||
}
|
||||
|
||||
sub dates {
|
||||
my ($type, $dt, $dt_end, $comment, $ledger_id) = @_;
|
||||
|
||||
# Nothing should be stamped before possession
|
||||
my $stamp = $dt;
|
||||
if ($stamp =~ m%^0?[12]/% || ($stamp =~ m%^0?3/(\d+)/% && $1 <= 25)) {
|
||||
$stamp = "3/25/2009 16:00";
|
||||
}
|
||||
|
||||
my $effective_dt = $dt;
|
||||
my $through_dt = $dt_end;
|
||||
|
||||
# Use different dates for security deposits
|
||||
if ($type eq 'charge' && $comment eq 'Security Deposit') {
|
||||
$effective_dt = $newdb{'lookup'}{'ledger'}{$ledger_id}{'lease_date'};
|
||||
$through_dt = undef;
|
||||
}
|
||||
|
||||
# REVISIT <AP>: 20090708
|
||||
# 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') {
|
||||
$effective_dt = undef;
|
||||
$through_dt = undef;
|
||||
}
|
||||
|
||||
return (datefmt($stamp), datefmt($effective_dt), datefmt($through_dt));
|
||||
}
|
||||
|
||||
|
||||
######################################################################
|
||||
######################################################################
|
||||
@@ -854,7 +884,9 @@ $query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.L
|
||||
foreach $row (@{query($sdbh, $query)}) {
|
||||
|
||||
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}
|
||||
= { 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'} };
|
||||
= { 'customer_id' => $newdb{'lookup'}{'tenant'}{$row->{'TenantID'}}{'customer_id'},
|
||||
'lease_date' => $row->{'DateIn'},
|
||||
};
|
||||
|
||||
addRow('leases',
|
||||
{ 'number' => $newdb{'tables'}{'leases'}{'autoid'}+1,
|
||||
@@ -892,9 +924,13 @@ $newdb{'lookup'}{'charge'} = {};
|
||||
$query = "SELECT *, ChargeAmount+TaxAmount AS InvoiceAmount FROM Charges ORDER BY ChargeID";
|
||||
foreach $row (@{query($sdbh, $query)}) {
|
||||
|
||||
my ($stamp, $effective_date, $through_date) =
|
||||
dates('invoice', $row->{'ChargeDate'}, $row->{'EndDate'},
|
||||
$row->{'ChargeDescription'}, $row->{'LedgerID'});
|
||||
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt($row->{'ChargeDate'}),
|
||||
'through_date' => datefmt($row->{'EndDate'}) });
|
||||
{ 'stamp' => $stamp,
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
|
||||
= { 'invoice' =>
|
||||
@@ -914,8 +950,8 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
}
|
||||
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt($row->{'ChargeDate'}),
|
||||
'through_date' => datefmt($row->{'EndDate'}) });
|
||||
{ 'stamp' => $stamp,
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'charge_tx'}
|
||||
= $newdb{'tables'}{'transactions'}{'autoid'};
|
||||
@@ -931,7 +967,9 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
# Create the invoice entry
|
||||
# debit: A/R credit: Invoice
|
||||
addRow('ledger_entries',
|
||||
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'tx'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'debit_ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'credit_ledger_id'},
|
||||
@@ -952,6 +990,10 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
$query = "SELECT * FROM Charges ORDER BY ChargeID";
|
||||
foreach $row (@{query($sdbh, $query)}) {
|
||||
|
||||
my (undef, $effective_date, $through_date) =
|
||||
dates('charge', $row->{'ChargeDate'}, $row->{'EndDate'},
|
||||
$row->{'ChargeDescription'}, $row->{'LedgerID'});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'}
|
||||
= $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'charge_tx'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}
|
||||
@@ -970,7 +1012,9 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
# Add the charge entry
|
||||
# debit: Invoice credit: Rent/LateCharge/Etc
|
||||
addRow('ledger_entries',
|
||||
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_ledger_id'},
|
||||
@@ -1000,7 +1044,9 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
# Add the tax charge entry
|
||||
# debit: Invoice credit: Tax
|
||||
addRow('ledger_entries',
|
||||
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tx'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Tax'}{'ledger_id'},
|
||||
@@ -1069,18 +1115,18 @@ $newdb{'lookup'}{'receipt'} = {};
|
||||
#
|
||||
# RENT TAX INVOICE A/R RECEIPT CASH CHECK
|
||||
# ------- ------- ------- ------- ------- ------- -------
|
||||
# |50 | 50| | | | |
|
||||
# | | 5 5| | | | |
|
||||
# | | |55 55| | | |
|
||||
# |40 | 40| | | | |
|
||||
# | | 4 4| | | | |
|
||||
# | | |44 44| | | |
|
||||
# | | | | |79 | 79|
|
||||
# | | | | |20 20| |
|
||||
# | | | |50 50| | |
|
||||
# | | | | 5 5| | |
|
||||
# | | | |40 40| | |
|
||||
# | | | | 4 4| | |
|
||||
# |50 | 50| | | | | t1a
|
||||
# | | 5 5| | | | | t1a
|
||||
# | | |55 55| | | | t1b
|
||||
# |40 | 40| | | | | t2a
|
||||
# | | 4 4| | | | | t2a
|
||||
# | | |44 44| | | | t2b
|
||||
# | | | | |79 | 79| t3a
|
||||
# | | | | |20 20| | t3a
|
||||
# | | | |50 50| | | t3b
|
||||
# | | | | 5 5| | | t3b
|
||||
# | | | |40 40| | | t3b
|
||||
# | | | | 4 4| | | t3b
|
||||
# | | | | | | |
|
||||
#
|
||||
# There is another possible solution, although it is
|
||||
@@ -1127,18 +1173,21 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
# next;
|
||||
# }
|
||||
|
||||
my ($stamp, $effective_date, $through_date) =
|
||||
dates('receipt', $row->{'ReceiptDate'}, undef);
|
||||
|
||||
if (!$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}) {
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt($row->{'ReceiptDate'}),
|
||||
'through_date' => undef });
|
||||
{ 'stamp' => $stamp,
|
||||
});
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}
|
||||
= {'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'date' => datefmt($row->{'ReceiptDate'}),
|
||||
'date' => $stamp,
|
||||
};
|
||||
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt($row->{'ReceiptDate'}),
|
||||
'through_date' => undef });
|
||||
{ 'stamp' => $stamp,
|
||||
});
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'payment_tx'}
|
||||
= $newdb{'tables'}{'transactions'}{'autoid'};
|
||||
}
|
||||
@@ -1193,7 +1242,9 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
# but it is Money to Receipt instead.
|
||||
# debit: Cash/Check/Etc credit: Receipt
|
||||
addRow('ledger_entries',
|
||||
{ 'monetary_source_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'},
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'},
|
||||
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'},
|
||||
@@ -1216,11 +1267,9 @@ $newdb{'lookup'}{'payment'} = {};
|
||||
$query = "SELECT * FROM Payments ORDER BY PaymentID";
|
||||
foreach $row (@{query($sdbh, $query)})
|
||||
{
|
||||
# addRow('transactions',
|
||||
# { 'stamp' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'date'},
|
||||
# 'through_date' => undef });
|
||||
# $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
|
||||
# = {'tx' => $newdb{'tables'}{'transactions'}{'autoid'} };
|
||||
|
||||
my (undef, $effective_date, $through_date) =
|
||||
dates('payment', $row->{'PaymentDate'}, undef);
|
||||
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
|
||||
= { 'tx' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'payment_tx'} };
|
||||
@@ -1247,7 +1296,9 @@ foreach $row (@{query($sdbh, $query)})
|
||||
# Add the payment entry
|
||||
# debit: Receipt credit: A/R
|
||||
addRow('ledger_entries',
|
||||
{ 'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'tx'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'credit_ledger_id'},
|
||||
|
||||
Reference in New Issue
Block a user