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 #======================================================================
40 $main::lxdebug->enter_sub();
42 my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
44 my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
45 my ($paymentaccno) = split(/--/, $form->{account});
47 my $vc_id = $form->{vc} eq "customer" ? "customer_id" : "vendor_id";
48 my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
50 my $query = qq|SELECT nextval('glid')|;
51 my ($new_id) = selectrow_query($form, $dbh, $query);
53 # add AR/AP header transaction with a payment
55 qq|INSERT INTO $arap (id, invnumber, employee_id) | .
56 qq|VALUES (?, ?, (SELECT id FROM employee WHERE login = ?))|;
57 my @values = ($new_id, $form->{login}, $form->{login});
58 do_query($form, $dbh, $query, @values);
60 my $invnumber = ($form->{invnumber}) ? $form->{invnumber} : $new_id;
62 qq|UPDATE $arap SET invnumber = ?, $vc_id = ?, transdate = ?, datepaid = ?, | .
63 qq|duedate = ?, netamount = ?, amount = ?, paid = ?, | .
64 qq|curr = ?, department_id = ? | .
66 @values = ($invnumber, $form->{$vc_id},
67 conv_date($form->{datepaid}), conv_date($form->{datepaid}),
68 conv_date($form->{datepaid}), 0, 0, $fxamount, $form->{currency},
69 $form->{department_id}, $new_id);
70 do_query($form, $dbh, $query, @values);
73 ($accno) = split /--/, $form->{ $form->{ARAP} };
76 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount) | .
77 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ? ), ?, ?)|;
78 @values = ($new_id, $accno, conv_date($form->{datepaid}), $fxamount * $ml);
79 do_query($form, $dbh, $query, @values);
83 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, source, memo) | .
84 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
85 @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
86 $amount * $ml * -1, $form->{source}, $form->{memo});
87 do_query($form, $dbh, $query, @values);
89 # add exchangerate difference
90 if ($fxamount != $amount) {
92 qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, cleared, fx_transaction) | .
93 qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
94 @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
95 (($fxamount - $amount) * $ml * -1), 1, 1);
96 do_query($form, $dbh, $query, @values);
99 $main::lxdebug->leave_sub();