[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4617] branches/1.3
- Subject: SF.net SVN: ledger-smb:[4617] branches/1.3
- From: ..hidden..
- Date: Wed, 28 Mar 2012 10:30:49 +0000
Revision: 4617
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4617&view=rev
Author: einhverfr
Date: 2012-03-28 10:30:49 +0000 (Wed, 28 Mar 2012)
Log Message:
-----------
Early payment discounts for bulk payment interface
Modified Paths:
--------------
branches/1.3/UI/payments/payments_detail.html
branches/1.3/scripts/payment.pl
branches/1.3/sql/modules/Payment.sql
Modified: branches/1.3/UI/payments/payments_detail.html
===================================================================
--- branches/1.3/UI/payments/payments_detail.html 2012-03-28 09:34:12 UTC (rev 4616)
+++ branches/1.3/UI/payments/payments_detail.html 2012-03-28 10:30:49 UTC (rev 4617)
@@ -291,6 +291,7 @@
</th>
<th class="total_due_list"><?lsmb text('Total') ?></th>
<th class="paid_list"><?lsmb text('Paid') ?></th>
+ <th class="discount_list"><?lsmb text('Discount') ?></th>
<th class="net_due_list"><?lsmb text('Net Due') ?> </th>
<th class="to_pay_list"><?lsmb text('To Pay') ?></th>
</tr>
@@ -316,6 +317,8 @@
/>
<td class="paid_list">
<?lsmb i.4 ?></td>
+ <td class="discount_list">
+ <?lsmb i.5 ?></td>
<td class="net_due_list">
<?lsmb i.6 ?>
<?lsmb currency ?></td>
Modified: branches/1.3/scripts/payment.pl
===================================================================
--- branches/1.3/scripts/payment.pl 2012-03-28 09:34:12 UTC (rev 4616)
+++ branches/1.3/scripts/payment.pl 2012-03-28 10:30:49 UTC (rev 4617)
@@ -599,7 +599,8 @@
money => 1);
$invoice->[6] = $payment->format_amount(amount => (
$payment->parse_amount(amount => $invoice->[3])
- - $payment->parse_amount(amount => $invoice->[4])),
+ - $payment->parse_amount(amount => $invoice->[4])
+ - $payment->parse_amount(amount => $invoice->[5])),
money => 1);
$contact_to_pay += $payment->parse_amount(amount => $invoice->[6]);
my $fld = "payment_" . $invoice->[0];
Modified: branches/1.3/sql/modules/Payment.sql
===================================================================
--- branches/1.3/sql/modules/Payment.sql 2012-03-28 09:34:12 UTC (rev 4616)
+++ branches/1.3/sql/modules/Payment.sql 2012-03-28 10:30:49 UTC (rev 4617)
@@ -329,13 +329,13 @@
a.id::text, a.invnumber, a.transdate::text,
a.amount::text, (a.amount - p.due)::text,
(CASE WHEN c.discount_terms
- > extract('days' FROM age(a.transdate))
+ < extract('days' FROM age(a.transdate))
THEN 0
- ELSE (a.amount - coalesce((a.amount - p.due), 0)) * coalesce(c.discount, 0) / 100
+ ELSE (coalesce(p.due, 0) * coalesce(c.discount, 0) / 100)
END)::text,
(coalesce(p.due, 0) -
(CASE WHEN c.discount_terms
- > extract('days' FROM age(a.transdate))
+ < extract('days' FROM age(a.transdate))
THEN 0
ELSE (coalesce(p.due, 0)) * coalesce(c.discount, 0) / 100
END))::text,
@@ -559,6 +559,47 @@
t_voucher_id, in_payment_date, in_source
FROM bulk_payments_in where amount <> 0;
+ -- early payment discounts
+ INSERT INTO acc_trans
+ (trans_id, chart_id, amount, approved,
+ voucher_id, transdate, source)
+ SELECT bpi.id, eca.discount_account_id,
+ amount * t_cash_sign * t_exchangerate/fxrate
+ / (1 - discount::numeric/100)
+ * (discount::numeric/100),
+ CASE WHEN t_voucher_id IS NULL THEN true
+ ELSE false END,
+ t_voucher_id, in_payment_date, in_source
+ FROM bulk_payments_in bpi
+ JOIN (select entity_credit_account, id, transdate FROM ar
+ WHERE in_account_class = 2
+ UNION
+ SELECT entity_credit_account, id, transdate FROM ap
+ WHERE in_account_class = 1) gl ON gl.id = bpi.id
+ JOIN entity_credit_account eca ON gl.entity_credit_account = eca.id
+ WHERE bpi.amount <> 0
+ AND extract('days' from age(gl.transdate)) < eca.discount_terms;
+
+ INSERT INTO acc_trans
+ (trans_id, chart_id, amount, approved,
+ voucher_id, transdate, source)
+ SELECT bpi.id, t_ar_ap_id,
+ amount * t_cash_sign * -1 * t_exchangerate/fxrate
+ / (1 - discount::numeric/100)
+ * (discount::numeric/100),
+ CASE WHEN t_voucher_id IS NULL THEN true
+ ELSE false END,
+ t_voucher_id, in_payment_date, in_source
+ FROM bulk_payments_in bpi
+ JOIN (select entity_credit_account, id, transdate FROM ar
+ WHERE in_account_class = 2
+ UNION
+ SELECT entity_credit_account, id, transdate FROM ap
+ WHERE in_account_class = 1) gl ON gl.id = bpi.id
+ JOIN entity_credit_account eca ON gl.entity_credit_account = eca.id
+ WHERE bpi.amount <> 0
+ AND extract('days' from age(gl.transdate)) < eca.discount_terms;
+
-- Insert ar/ap side
INSERT INTO acc_trans
(trans_id, chart_id, amount, approved,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.