This rework is nowhere near complete, but there are certain things that are falling in place, and worth capturing. I started a branch for just this purpose of being able to check in intermediate work.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@352 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -549,22 +549,6 @@ $newdb{'lookup'}{'payment_type'}{12}
|
||||
= { 'name' => 'Concession', 'account_name' => 'Concession' };
|
||||
|
||||
|
||||
$newdb{'ids'}{'monetary_source'} = {};
|
||||
$newdb{'ids'}{'monetary_source'}{'internal'} = undef;
|
||||
|
||||
addRow('monetary_sources',
|
||||
{ 'name' => 'Cash',
|
||||
'comment' => 'Monetary source used for any cash transaction' });
|
||||
$newdb{'ids'}{'monetary_source'}{'Cash'} =
|
||||
$newdb{'tables'}{'monetary_sources'}{'autoid'};
|
||||
|
||||
addRow('monetary_sources',
|
||||
{ 'name' => 'Closing',
|
||||
'comment' => 'Credited at the closing table' });
|
||||
$newdb{'ids'}{'monetary_source'}{'Closing'} =
|
||||
$newdb{'tables'}{'monetary_sources'}{'autoid'};
|
||||
|
||||
|
||||
|
||||
|
||||
######################################################################
|
||||
@@ -895,7 +879,9 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
'movein_date' => datefmt($row->{'DateIn'}),
|
||||
'moveout_date' => datefmt($row->{'DateOut'}),
|
||||
'close_date' => datefmt($row->{'DateClosed'}),
|
||||
'rent' => $row->{'Rent'} });
|
||||
'rent' => $row->{'Rent'},
|
||||
'comment' => "LedgerID: $row->{'LedgerID'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'} =
|
||||
$newdb{'tables'}{'leases'}{'autoid'};
|
||||
@@ -910,7 +896,7 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
######################################################################
|
||||
######################################################################
|
||||
##
|
||||
## TRANSACTIONS
|
||||
## INVOICES
|
||||
##
|
||||
|
||||
######################################################################
|
||||
@@ -926,17 +912,16 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
$row->{'ChargeDescription'}, $row->{'LedgerID'});
|
||||
|
||||
addRow('transactions',
|
||||
{ 'stamp' => $stamp,
|
||||
{ 'type' => 'INVOICE',
|
||||
'stamp' => $stamp,
|
||||
#'amount' => $row->{'InvoiceAmount'},
|
||||
#'comment' => "Invoice Transaction",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}
|
||||
= { 'invoice' =>
|
||||
{ 'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'lease_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'},
|
||||
'customer_id' => $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'},
|
||||
'amount' => $row->{'InvoiceAmount'},
|
||||
} };
|
||||
= { 'invoice' => {'id' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'amount' => $row->{'InvoiceAmount'} },
|
||||
};
|
||||
|
||||
# Charges are the only way we have to figure out security
|
||||
# deposit requirements for a lease. So, if we encounter
|
||||
@@ -947,51 +932,6 @@ foreach $row (@{query($sdbh, $query)}) {
|
||||
]{'deposit'} = $row->{'ChargeAmount'};
|
||||
}
|
||||
|
||||
# Invoice must debit the A/R ledger...
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'debit_ledger_id'}
|
||||
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
|
||||
|
||||
if ($use_invoice) {
|
||||
addRow('transactions',
|
||||
{ 'stamp' => $stamp,
|
||||
#'comment' => "Charges Transaction",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'charge_tx'}
|
||||
= $newdb{'tables'}{'transactions'}{'autoid'};
|
||||
|
||||
# ...and credit the Invoice ledger.
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'credit_ledger_id'}
|
||||
= $newdb{'lookup'}{'account'}{'Invoice'}{'ledger_id'};
|
||||
|
||||
# Create the invoice entry
|
||||
# debit: A/R credit: Invoice
|
||||
addRow('ledger_entries',
|
||||
{ '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'},
|
||||
'root_transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'charge_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'},
|
||||
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'customer_id'},
|
||||
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'lease_id'},
|
||||
'amount' => $row->{'InvoiceAmount'},
|
||||
#'comment' => "Invoice: Charge: $row->{'ChargeID'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'ledger_entry_id'}
|
||||
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
}
|
||||
else {
|
||||
# OK, no invoice ledger
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'charge_tx'}
|
||||
= $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'tx'};
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'credit_ledger_id'}
|
||||
= $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'debit_ledger_id'};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1001,97 +941,100 @@ 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'});
|
||||
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'}
|
||||
= $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}
|
||||
= $row->{'ChargeAmount'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'}
|
||||
= $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'customer_id'},
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'}
|
||||
= $newdb{'lookup'}{'ledger'}{$row->{'LedgerID'}}{'lease_id'};
|
||||
|
||||
# Charge must credit the Charge ledger...
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_account_id'}
|
||||
= $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'account_id'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_ledger_id'}
|
||||
= $newdb{'lookup'}{'charge_type'}{$row->{'ChargeDescription'}}{'ledger_id'};
|
||||
|
||||
# ...and debit the Invoice ledger.
|
||||
# ...and debit the A/R ledger.
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_account_id'}
|
||||
= $newdb{'lookup'}{'account'}{'A/R'}{'account_id'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'}
|
||||
= $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'credit_ledger_id'};
|
||||
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
|
||||
|
||||
# Add the charge entry
|
||||
# debit: Invoice credit: Rent/LateCharge/Etc
|
||||
addRow('ledger_entries',
|
||||
{ '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'},
|
||||
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
|
||||
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
|
||||
'amount' => $row->{'ChargeAmount'},
|
||||
#'comment' => "Charge: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
|
||||
# debit: A/R credit: Rent/LateCharge/Etc
|
||||
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'},
|
||||
'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',
|
||||
{ 'type' => 'CHARGE',
|
||||
'through_date' => $through_date,
|
||||
'double_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'double_entry_id'},
|
||||
'account_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'credit_account_id'},
|
||||
'crdr' => 'CREDIT',
|
||||
'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'},
|
||||
'crdr' => 'DEBIT',
|
||||
'comment' => "Charge A/R: $row->{'ChargeID'}; Ledger: $row->{'LedgerID'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'}
|
||||
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ar_entry_id'}
|
||||
= $newdb{'tables'}{'entries'}{'autoid'};
|
||||
|
||||
if ($use_invoice) {
|
||||
# Reconcile the Invoice account. Our two entries look like:
|
||||
# debit: Invoice credit: Rent/LateCharge/Etc
|
||||
# debit: A/R credit: Invoice
|
||||
# Since this is from the perspective of the Invoice account,
|
||||
# the credit entry is the Invoice<->A/R, and the debit
|
||||
# entry is the actual charge ledger entry.
|
||||
addRow('reconciliations',
|
||||
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'},
|
||||
'credit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'ledger_entry_id'},
|
||||
'amount' => $row->{'ChargeAmount'},
|
||||
});
|
||||
}
|
||||
else {
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'ledger_entry_id'}
|
||||
= $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'ledger_entry_id'};
|
||||
}
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'}
|
||||
= $row->{'ChargeAmount'};
|
||||
|
||||
next unless $row->{'TaxAmount'};
|
||||
|
||||
# Add the tax charge entry
|
||||
# debit: Invoice credit: Tax
|
||||
addRow('ledger_entries',
|
||||
{ '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'},
|
||||
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
|
||||
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
|
||||
'amount' => $row->{'TaxAmount'},
|
||||
#'comment' => "Tax for ChargeID:$row->{'ChargeID'}",
|
||||
});
|
||||
# # Add the tax charge entry
|
||||
# # debit: Invoice credit: Tax
|
||||
# addRow('ledger_entries',
|
||||
# { 'effective_date' => $effective_date,
|
||||
# 'through_date' => $through_date,
|
||||
# 'transaction_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'id'},
|
||||
# 'debit_ledger_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'debit_ledger_id'},
|
||||
# 'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Tax'}{'ledger_id'},
|
||||
# 'amount' => $row->{'TaxAmount'},
|
||||
# #'comment' => "Tax for ChargeID:$row->{'ChargeID'}",
|
||||
# });
|
||||
|
||||
$newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_ledger_entry_id'}
|
||||
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
|
||||
if ($use_invoice) {
|
||||
# Reconcile the Invoice account. Our two entries look like:
|
||||
# debit: Invoice credit: Tax
|
||||
# debit: A/R credit: Invoice
|
||||
# Since this is from the perspective of the Invoice account,
|
||||
# the credit entry is the Invoice<->A/R, and the debit
|
||||
# entry is the actual tax ledger entry.
|
||||
addRow('reconciliations',
|
||||
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_ledger_entry_id'},
|
||||
'credit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'ledger_entry_id'},
|
||||
'amount' => $row->{'TaxAmount'},
|
||||
});
|
||||
}
|
||||
# $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'tax_ledger_entry_id'}
|
||||
# = $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
}
|
||||
|
||||
|
||||
######################################################################
|
||||
######################################################################
|
||||
######################################################################
|
||||
######################################################################
|
||||
######################################################################
|
||||
######################################################################
|
||||
##
|
||||
## RECEIPTS
|
||||
##
|
||||
|
||||
######################################################################
|
||||
## Receipts
|
||||
|
||||
@@ -1186,190 +1129,188 @@ $query =
|
||||
" WHERE P.ReceiptNum = R.ReceiptNum" .
|
||||
" GROUP BY R.ReceiptNum, R.ReceiptDate, P.PaymentType, P.CheckNum" .
|
||||
" ORDER BY R.ReceiptNum, P.PaymentType";
|
||||
|
||||
# print Dumper query($sdbh, $query);
|
||||
# exit;
|
||||
|
||||
foreach $row (@{query($sdbh, $query)}) {
|
||||
|
||||
# if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}) {
|
||||
# next;
|
||||
# }
|
||||
|
||||
my ($stamp, $effective_date, $through_date) =
|
||||
dates('receipt', $row->{'ReceiptDate'}, undef);
|
||||
my ($stamp, $effective_date, $through_date) =
|
||||
dates('receipt', $row->{'ReceiptDate'}, undef);
|
||||
|
||||
if (!$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}) {
|
||||
addRow('transactions',
|
||||
{ 'stamp' => $stamp,
|
||||
#'comment' => "Receipt Transaction",
|
||||
});
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}
|
||||
= {'tx' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'date' => $stamp,
|
||||
};
|
||||
|
||||
addRow('transactions',
|
||||
{ 'stamp' => $stamp,
|
||||
#'comment' => "Payment Split Transaction",
|
||||
});
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'payment_tx'}
|
||||
= $newdb{'tables'}{'transactions'}{'autoid'};
|
||||
if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}) {
|
||||
print Dumper $newdb{'lookup'}{'receipt'};
|
||||
print Dumper $row;
|
||||
die "REALLY?";
|
||||
}
|
||||
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}
|
||||
= { 'date' => $stamp,
|
||||
'amount' => $row->{'ReceiptAmount'},
|
||||
};
|
||||
|
||||
if ($row->{'ReceiptDate'} =~ m%3/25/2009%) {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'}
|
||||
= $newdb{'ids'}{'monetary_source'}{'Closing'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
|
||||
= 'Closing';
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'account_name'}
|
||||
= 'Bank';
|
||||
}
|
||||
else {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'}
|
||||
= $newdb{'ids'}{'monetary_source'}{
|
||||
$newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'name'}
|
||||
};
|
||||
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'};
|
||||
}
|
||||
|
||||
# Set up a monetary source for the receipt,
|
||||
if (!$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'}) {
|
||||
my $name = $newdb{'lookup'}{'payment_type'}{$row->{'PaymentType'}}{'name'};
|
||||
my $data1;
|
||||
if ($name eq 'Check') {
|
||||
$name = 'Check #' . $row->{'CheckNum'};
|
||||
$data1 = $row->{'CheckNum'};
|
||||
if ($newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'} eq 'Check') {
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'}
|
||||
= 'Check #' . $row->{'CheckNum'};
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'data1'}
|
||||
= $row->{'CheckNum'};
|
||||
}
|
||||
addRow('monetary_sources',
|
||||
{ 'name' => $name,
|
||||
'data1' => $data1,
|
||||
#'comment' => "Receipt:$row->{'ReceiptNum'}; Payment:$row->{'PaymentType'}; Check:$row->{'CheckNum'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'monetary_source_id'}
|
||||
= $newdb{'tables'}{'monetary_sources'}{'autoid'};
|
||||
}
|
||||
|
||||
$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,
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'receipt_id'}
|
||||
= $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'};
|
||||
|
||||
# ...and credit the Receipt ledger
|
||||
# ...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'}{'Receipt'}{'ledger_id'};
|
||||
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
|
||||
|
||||
# NOTE THE ABOVE LARGE COMMENT BLOCK
|
||||
# The choice of credit/debit ledgers does not mirror the
|
||||
# choices for invoice. This _should_ be A/R to Receipt,
|
||||
# but it is Money to Receipt instead.
|
||||
# debit: Cash/Check/Etc credit: Receipt
|
||||
addRow('ledger_entries',
|
||||
{ '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'},
|
||||
'amount' => $row->{'ReceiptAmount'},
|
||||
#'comment' => "Receipt: $row->{'ReceiptNum'}; ",
|
||||
});
|
||||
# debit: Cash/Check/Etc credit: A/R
|
||||
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'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
|
||||
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
$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'},
|
||||
'crdr' => 'DEBIT',
|
||||
'double_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'double_entry_id'},
|
||||
'name' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'name'},
|
||||
'monetary_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'}",
|
||||
});
|
||||
|
||||
$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'},
|
||||
'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'};
|
||||
}
|
||||
|
||||
|
||||
|
||||
######################################################################
|
||||
## Payments
|
||||
## Payments to Charges assignments
|
||||
|
||||
$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'}, undef);
|
||||
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}
|
||||
= { 'tx' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'payment_tx'} };
|
||||
= { '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'},
|
||||
};
|
||||
|
||||
|
||||
# NOTE THE ABOVE LARGE COMMENT BLOCK
|
||||
# The choice of credit/debit ledgers does not mirror the
|
||||
# choices for charges. This _should_ be Money to Receipt,
|
||||
# but it is A/R to Receipt instead.
|
||||
|
||||
# Ensure Receipt has the right customer
|
||||
$newdb{'tables'}{'ledger_entries'}{'rows'}[
|
||||
$newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'}
|
||||
# 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'};
|
||||
|
||||
# Payment must debit the associated receipt ledger (which should be Receipt)...
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'debit_ledger_id'}
|
||||
= $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'credit_ledger_id'};
|
||||
|
||||
# ...and credit the A/R ledger.
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'credit_ledger_id'}
|
||||
= $newdb{'lookup'}{'account'}{'A/R'}{'ledger_id'};
|
||||
|
||||
# Add the payment entry
|
||||
# debit: Receipt credit: A/R
|
||||
addRow('ledger_entries',
|
||||
{ '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'},
|
||||
'customer_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'customer_id'},
|
||||
'lease_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'lease_id'},
|
||||
'amount' => $row->{'PaymentAmount'},
|
||||
#'comment' => "Split; Receipt: $row->{'ReceiptNum'}; Charge: $row->{'ChargeID'}; Payment: $row->{'PaymentID'}",
|
||||
});
|
||||
|
||||
$newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'}
|
||||
= $newdb{'tables'}{'ledger_entries'}{'autoid'};
|
||||
|
||||
# Reconcile the Receipt account. Our two entries look like:
|
||||
# debit: Cash/Check/Etc credit: Receipt
|
||||
# debit: Receipt credit: A/R
|
||||
# Since this is from the perspective of the Receipt account,
|
||||
# the debit entry is the Receipt<->A/R, and the credit
|
||||
# entry is the actual receipt ledger entry.
|
||||
addRow('reconciliations',
|
||||
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'},
|
||||
'credit_ledger_entry_id' => $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'ledger_entry_id'},
|
||||
'amount' => $row->{'PaymentAmount'},
|
||||
});
|
||||
|
||||
next
|
||||
if ($newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'reconciled'});
|
||||
|
||||
# Figure out how much of the charge can be reconciled
|
||||
my $reconcile_amount = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'amount'};
|
||||
#print Dumper($newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}); exit;
|
||||
$reconcile_amount = $row->{'PaymentAmount'} if $row->{'PaymentAmount'} <= $reconcile_amount;
|
||||
my $charge_amount = $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'amount'};
|
||||
my $payment_amount = $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'amount'};
|
||||
|
||||
# Reconcile the A/R account. Our two entries look like:
|
||||
# debit: Receipt credit: A/R
|
||||
# debit: A/R credit: Invoice
|
||||
# Since this is from the perspective of the A/R account,
|
||||
# the debit entry is the Invoice<->A/R, and the credit
|
||||
# entry is the Receipt<->A/R.
|
||||
my $reconcile_amount = ($charge_amount < $payment_amount) ? $charge_amount : $payment_amount;
|
||||
|
||||
# Reconcile the A/R Account
|
||||
addRow('reconciliations',
|
||||
{ 'debit_ledger_entry_id' => $newdb{'lookup'}{'charge'}{$row->{'ChargeID'}}{'invoice'}{'ledger_entry_id'},
|
||||
'credit_ledger_entry_id' => $newdb{'lookup'}{'payment'}{$row->{'PaymentID'}}{'ledger_entry_id'},
|
||||
'amount' => $reconcile_amount,
|
||||
});
|
||||
{ '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,
|
||||
});
|
||||
|
||||
# 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 $txid = $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{'tx'};
|
||||
$newdb{'tables'}{'transactions'}{'rows'}[$txid]{'comment'} = $row->{'Memo'};
|
||||
my $id = $newdb{'lookup'}{'receipt'}{$row->{'ReceiptNum'}}{$row->{'PaymentType'}}{'entry_id'};
|
||||
$newdb{'tables'}{'entries'}{'rows'}[$id]{'comment'} = $row->{'Memo'};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
######################################################################
|
||||
## 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
|
||||
|
||||
@@ -1380,57 +1321,89 @@ print("Set up Petty Cash...\n");
|
||||
# Add the first loan
|
||||
# debit: Equity credit: Loan
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt('03/25/2009 16:00'),
|
||||
});
|
||||
addRow('ledger_entries',
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
|
||||
'customer_id' => undef,
|
||||
'lease_id' => undef,
|
||||
'amount' => 5000,
|
||||
'comment' => "HTP Loan #1",
|
||||
});
|
||||
{ '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,
|
||||
'comment' => "HTP Loan #1",
|
||||
});
|
||||
addRow('entries',
|
||||
{ 'type' => 'TRANSFER',
|
||||
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
|
||||
'crdr' => 'DEBIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Equity: HTP Loan #1",
|
||||
});
|
||||
addRow('entries',
|
||||
{ 'type' => 'TRANSFER',
|
||||
'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'},
|
||||
'crdr' => 'CREDIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Loan: HTP Loan #1",
|
||||
});
|
||||
|
||||
# Add the second loan
|
||||
# debit: Equity credit: Loan
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt('04/01/2009 16:00'),
|
||||
});
|
||||
addRow('ledger_entries',
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Loan'}{'ledger_id'},
|
||||
'customer_id' => undef,
|
||||
'lease_id' => undef,
|
||||
'amount' => 1000,
|
||||
'comment' => "HTP Loan #2",
|
||||
});
|
||||
{ '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,
|
||||
'comment' => "HTP Loan #2",
|
||||
});
|
||||
addRow('entries',
|
||||
{ 'type' => 'TRANSFER',
|
||||
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
|
||||
'crdr' => 'DEBIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Equity: HTP Loan #2",
|
||||
});
|
||||
addRow('entries',
|
||||
{ 'type' => 'TRANSFER',
|
||||
'account_id' => $newdb{'lookup'}{'account'}{'Loan'}{'account_id'},
|
||||
'crdr' => 'CREDIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Loan: HTP Loan #2",
|
||||
});
|
||||
|
||||
# Cheat for now, using equity for Petty Cash
|
||||
# debit: Petty Cash credit: Equity
|
||||
addRow('transactions',
|
||||
{ 'stamp' => datefmt('03/25/2009 16:00'),
|
||||
});
|
||||
addRow('ledger_entries',
|
||||
{ 'effective_date' => $effective_date,
|
||||
'through_date' => $through_date,
|
||||
'monetary_source_id' => $newdb{'ids'}{'monetary_source'}{'internal'},
|
||||
'transaction_id' => $newdb{'tables'}{'transactions'}{'autoid'},
|
||||
'debit_ledger_id' => $newdb{'lookup'}{'account'}{'Petty Cash'}{'ledger_id'},
|
||||
'credit_ledger_id' => $newdb{'lookup'}{'account'}{'Equity'}{'ledger_id'},
|
||||
'customer_id' => undef,
|
||||
'lease_id' => undef,
|
||||
'amount' => 750,
|
||||
'comment' => "Petty Cash Funding",
|
||||
});
|
||||
|
||||
{ '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'},
|
||||
'crdr' => 'DEBIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Petty Cash: Petty Cash Funding",
|
||||
});
|
||||
addRow('entries',
|
||||
{ 'type' => 'TRANSFER',
|
||||
'account_id' => $newdb{'lookup'}{'account'}{'Equity'}{'account_id'},
|
||||
'crdr' => 'CREDIT',
|
||||
'double_entry_id' => $newdb{'tables'}{'double_entries'}{'autoid'},
|
||||
'comment' => "Equity: Petty Cash Funding",
|
||||
});
|
||||
|
||||
######################################################################
|
||||
## Build the Database
|
||||
@@ -1492,3 +1465,14 @@ $query = "UPDATE pmgr_units U, pmgr_leases L
|
||||
query($db_handle, $query);
|
||||
|
||||
|
||||
######################################################################
|
||||
## Invoice/Receipt totals
|
||||
|
||||
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($db_handle, $query);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user