1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #======================================================================
31 # Overpayment function
32 # used in AR, AP, IS, IR, OE, CP
33 #======================================================================
42 $main::lxdebug->enter_sub();
44 my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
46 my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
47 my ($paymentaccno) = split(/--/, $form->{account});
49 my $vc_id = $form->{vc} eq "customer" ? "customer_id" : "vendor_id";
50 my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
52 my $query = qq|SELECT nextval('glid')|;
53 my ($new_id) = selectrow_query($form, $dbh, $query);
55 # add AR/AP header transaction with a payment
57 qq|INSERT INTO $arap (id, invnumber, employee_id) | .
58 qq|VALUES (?, ?, (SELECT id FROM employee WHERE login = ?))|;
59 my @values = ($new_id, $form->{login}, $form->{login});
60 do_query($form, $dbh, $query, @values);
62 my $invnumber = ($form->{invnumber}) ? $form->{invnumber} : $new_id;
64 qq|UPDATE $arap SET invnumber = ?, $vc_id = ?, transdate = ?, datepaid = ?, | .
65 qq|duedate = ?, netamount = ?, amount = ?, paid = ?, | .
66 qq|curr = ?, department_id = ? | .
68 @values = ($invnumber, $form->{$vc_id},
69 conv_date($form->{datepaid}), conv_date($form->{datepaid}),
70 conv_date($form->{datepaid}), 0, 0, $fxamount, $form->{currency},
71 $form->{department_id}, $new_id);
72 do_query($form, $dbh, $query, @values);
75 my ($accno) = split /--/, $form->{ $form->{ARAP} };
78 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount) | .
79 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ? ), ?, ?)|;
80 @values = ($new_id, $accno, conv_date($form->{datepaid}), $fxamount * $ml);
81 do_query($form, $dbh, $query, @values);
85 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, source, memo) | .
86 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
87 @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
88 $amount * $ml * -1, $form->{source}, $form->{memo});
89 do_query($form, $dbh, $query, @values);
91 # add exchangerate difference
92 if ($fxamount != $amount) {
94 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, cleared, fx_transaction) | .
95 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
96 @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
97 (($fxamount - $amount) * $ml * -1), 1, 1);
98 do_query($form, $dbh, $query, @values);
101 $main::lxdebug->leave_sub();