Definitely not perfect, but the database changes seem to be OK, along with the sitelink script. Certainly workable if not yet complete.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@358 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-21 04:16:54 +00:00
parent ae5d4763f9
commit 59e6379977
2 changed files with 261 additions and 526 deletions

View File

@@ -914,6 +914,9 @@ foreach $row (@{query($sdbh, $query)}) {
addRow('transactions', {
'type' => 'INVOICE',
'stamp' => $stamp,
'account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'crdr' => 'DEBIT',
#'amount' => $row->{'InvoiceAmount'},
#'comment' => "Invoice Transaction",
});
@@ -965,49 +968,47 @@ foreach $row (@{query($sdbh, $query)}) {
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
# debit: A/R credit: Rent/LateCharge/Etc
foreach ('debit', 'credit') {
my $CRDR = $_;
$CRDR =~ tr/a-z/A-Z/;
addRow('ledger_entries', {
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'},
'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_account_id'},
'ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_ledger_id'},
'crdr' => $CRDR,
'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'},
'comment' => "$_ Ledger Entry: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
});
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{$_.'_entry_id'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
}
addRow('double_entries', {
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'},
'effective_date' => $effective_date,
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_ledger_id'},
'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'},
#'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'},
'debit_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_entry_id'},
'credit_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_entry_id'},
'comment' => "Double Entry: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
});
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'double_entry_id'}
= $newdb{'tables'}{'double_entries'}{'autoid'};
# Add the Charge Entry
addRow('entries', {
# Add the Charge Statement Entry
addRow('statement_entries', {
'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'},
'type' => 'CHARGE',
'effective_date' => $effective_date,
'through_date' => $through_date,
'double_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'double_entry_id'},
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_account_id'},
'ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_ledger_id'},
'crdr' => 'CREDIT',
'amount' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'},
'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
});
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry_id'}
= $newdb{'tables'}{'entries'}{'autoid'};
# Add the A/R entry
addRow('entries', {
'type' => 'TRANSFER',
'double_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'double_entry_id'},
'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_account_id'},
'ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'},
'crdr' => 'DEBIT',
'comment' => "Charge A/R: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
});
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ar_entry_id'}
= $newdb{'tables'}{'entries'}{'autoid'};
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}
= $row->{'ChargeAmount'};
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'}
= $newdb{'tables'}{'statement_entries'}{'autoid'};
next unless $row->{'TaxAmount'};
@@ -1043,86 +1044,6 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'receipt'} = {};
############################################################
############################################################
############################################################
# REVISIT <AP> 20090630
# Handling of receipts is all backwards. The way things
# _should_ look if someone provides Cash and Check to pay
# rent & tax for two units (50 on UnitA and 40 UnitB):
#
# RENT TAX INVOICE A/R RECEIPT CASH CHECK
# ------- ------- ------- ------- ------- ------- -------
# |50 | 50| | | | |
# | | 5 5| | | | |
# | | |55 55| | | |
# |40 | 40| | | | |
# | | 4 4| | | | |
# | | |44 44| | | |
# | | | | |79 | 79|
# | | | | |20 20| |
# | | | |99 99| | |
# | | | | | | |
#
# HOWEVER,
# Our current implementation MUST match LedgerEntry to
# LedgerEntry for reconcile purposes. Thus, although there
# is a way to reconcile that $50 was received, there is no
# way to flag the payment as being for UnitA, unless we
# either rely on the charge to determine the fact (a
# solution that has proven very messy), or we add it to
# the reconciliations table. The hope, for simplicity's
# sake, was to ensure there was a single ledger entry in
# A/R for each payment that could correspond to a lease/unit,
# so that no A/R ledger entry ever represented payment for
# more than one lease. However, to do so, our ledgers
# appear like this instead:
#
# RENT TAX INVOICE A/R RECEIPT CASH CHECK
# ------- ------- ------- ------- ------- ------- -------
# |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
# very probably ledger overkill (even invoice/receipt
# already fall into the overkill category).
#
# RENT TAX INVOICE A/R MERGE 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| | |
# | | | |99 99| | | |
# | | | | | | | |
#
# I might opt for this last option, but ultimately, none
# of these are really correct. We need a better solution.
# Until then, I'll go with the easiest.
############################################################
############################################################
############################################################
# Sitelink splits one physical payment into multiple "payments" to match each charge.
# The solution here is kludgy, but for our cases at least, it brings those pseudo-payments
# back into a single one. This presumes there is only one PaymentType per receipt.
@@ -1153,6 +1074,8 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}
= { 'date' => $stamp,
'effective_date' => $effective_date,
'through_date' => $through_date,
'amount' => $row->{'ReceiptAmount'},
};
@@ -1185,6 +1108,9 @@ foreach $row (@{query($sdbh, $query)}) {
addRow('transactions', {
'type' => 'RECEIPT',
'stamp' => $stamp,
'account_id' => $newdb{'lookup'}{'account'}{'A/R'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'},
'crdr' => 'CREDIT',
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}
@@ -1206,48 +1132,45 @@ foreach $row (@{query($sdbh, $query)}) {
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'}
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
# debit: Cash/Check/Etc credit: A/R
foreach ('debit', 'credit') {
my $CRDR = $_;
$CRDR =~ tr/a-z/A-Z/;
addRow('ledger_entries', {
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'},
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_account_id'},
'ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_ledger_id'},
'crdr' => $CRDR,
'amount' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'amount'},
'comment' => "$_ Entry Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{$_.'_entry_id'}
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
}
addRow('double_entries', {
'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'},
'effective_date' => $effective_date,
'customer_id' => undef, # This is set later...
'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'},
'amount' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'amount'},
'comment' => "Double Entry Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
#'transaction_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'},
'debit_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'},
'credit_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_entry_id'},
'comment' => "Double Entry: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'}
= $newdb{'tables'}{'double_entries'}{'autoid'};
# Add the Payment Entry
addRow('entries', {
'type' => 'PAYMENT',
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_account_id'},
'ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_ledger_id'},
'crdr' => 'DEBIT',
'double_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'},
# Add the physical payment
addRow('payments', {
'ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'debit_entry_id'},
'name' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'},
'monetary_type' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'},
'type' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'type'},
'data1' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'},
'comment' => "Receipt: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
'comment' => "Physical Payment: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'entry_id'}
= $newdb{'tables'}{'entries'}{'autoid'};
# Add the A/R Entry
addRow('entries', {
'type' => 'TRANSFER',
'account_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_account_id'},
'ledger_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'},
'crdr' => 'CREDIT',
'double_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'},
'comment' => "Receipt A/R: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}",
});
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ar_entry_id'}
= $newdb{'tables'}{'entries'}{'autoid'};
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'payment_id'}
= $newdb{'tables'}{'payments'}{'autoid'};
}
@@ -1260,49 +1183,40 @@ $newdb{'lookup'}{'payment'} = {};
$query = "SELECT * FROM Payments ORDER BY PaymentID";
foreach $row (@{query($sdbh, $query)})
{
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
= { 'receipt_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'},
'ar_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ar_entry_id'},
'entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'entry_id'},
'amount' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'amount'},
};
# Ensure Payment has the right customer
$newdb{'tables'}{'double_entries'}{'rows'}[
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'}
]{'customer_id'} = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'};
next
if ($newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'reconciled'});
# Figure out how much of the charge can be reconciled
my $charge_amount = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'};
my $payment_amount = $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'};
my $payment_amount = $row->{'PaymentAmount'};
my $reconcile_amount = ($charge_amount < $payment_amount) ? $charge_amount : $payment_amount;
# Reconcile the A/R Account
addRow('reconciliations', {
'debit_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ar_entry_id'},
'credit_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ar_entry_id'},
'amount' => $reconcile_amount,
$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'},
'lease_id' => $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'},
};
my $comment = $row->{'Memo'} || "Payment: $row->{'ReceiptNum'}; Type: $row->{'PaymentType'}";
# Add the Payment Statement Entry
addRow('statement_entries', {
'transaction_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'receipt_id'},
'type' => 'PAYMENT',
'effective_date' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'effective_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'},
'amount' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'},
'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'statement_entry_id'},
'comment' => $comment,
});
# Reconcile the payment to the charge
addRow('charges_payments', {
'charge_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'entry_id'},
'payment_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'entry_id'},
'amount' => $reconcile_amount,
});
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'reconciled'} = 1;
# Update the transaction to use the memo from this payment
if ($row->{'Memo'}) {
my $id = $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'entry_id'};
$newdb{'tables'}{'entries'}{'rows'}[$id]{'comment'} = $row->{'Memo'};
}
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'statement_entry_id'}
= $newdb{'tables'}{'statement_entries'}{'autoid'};
}
@@ -1328,93 +1242,95 @@ print("Set up Petty Cash...\n");
addRow('transactions', {
'type' => 'TRANSFER',
'stamp' => datefmt('03/25/2009 16:00'),
});
addRow('double_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'effective_date' => $effective_date,
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
'amount' => 5000,
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'crdr' => 'DEBIT',
'comment' => "HTP Loan #1",
});
addRow('entries', {
'type' => 'TRANSFER',
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'crdr' => 'DEBIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'amount' => 5000,
'comment' => "Equity: HTP Loan #1",
});
addRow('entries', {
'type' => 'TRANSFER',
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
'crdr' => 'CREDIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'amount' => 5000,
'comment' => "Loan: HTP Loan #1",
});
addRow('double_entries', {
'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1,
'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
});
# Add the second loan
# debit: Equity credit: Loan
addRow('transactions', {
'type' => 'TRANSFER',
'stamp' => datefmt('04/01/2009 16:00'),
});
addRow('double_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'effective_date' => $effective_date,
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
'amount' => 1000,
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'crdr' => 'DEBIT',
'comment' => "HTP Loan #2",
});
addRow('entries', {
'type' => 'TRANSFER',
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'crdr' => 'DEBIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'amount' => 1000,
'comment' => "Equity: HTP Loan #2",
});
addRow('entries', {
'type' => 'TRANSFER',
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
'crdr' => 'CREDIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'amount' => 1000,
'comment' => "Loan: HTP Loan #2",
});
addRow('double_entries', {
'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1,
'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
});
# Cheat for now, using equity for Petty Cash
# debit: Petty Cash credit: Equity
addRow('transactions', {
'type' => 'TRANSFER',
'stamp' => datefmt('03/25/2009 16:00'),
});
addRow('double_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'effective_date' => $effective_date,
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'},
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'amount' => 750,
'comment' => "Petty Cash Funding",
});
addRow('entries', {
'type' => 'TRANSFER',
'account_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'},
'crdr' => 'DEBIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'comment' => "Petty Cash Funding",
});
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'},
'crdr' => 'DEBIT',
'amount' => 750,
'comment' => "Petty Cash: Petty Cash Funding",
});
addRow('entries', {
'type' => 'TRANSFER',
addRow('ledger_entries', {
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
'ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
'crdr' => 'CREDIT',
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
'amount' => 750,
'comment' => "Equity: Petty Cash Funding",
});
addRow('double_entries', {
'debit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'}-1,
'credit_entry_id' => $newdb{'tables'}{'ledger_entries'}{'autoid'},
});
######################################################################
## Build the Database
@@ -1481,9 +1397,9 @@ query($db_handle, $query);
print("Set Invoice/Receipt Totals...\n");
$query = "UPDATE pmgr_transactions T, pmgr_double_entries DE
SET T.`amount` = COALESCE(T.`amount`,0) + DE.amount
WHERE DE.transaction_id = T.id";
$query = "UPDATE pmgr_transactions T, pmgr_ledger_entries E
SET T.`amount` = COALESCE(T.`amount`,0) + E.amount
WHERE E.transaction_id = T.id AND E.account_id = T.account_id";
query($db_handle, $query);