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 #======================================================================
38 $main::lxdebug->enter_sub();
40 my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
42 my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
43 my ($paymentaccno) = split /--/, $form->{account};
45 my $vc_id = "$form->{vc}_id";
48 $uid .= $form->{login};
50 # add AR/AP header transaction with a payment
51 $query = qq|INSERT INTO $form->{arap} (invnumber, employee_id)
52 VALUES ('$uid', (SELECT e.id FROM employee e
53 WHERE e.login = '$form->{login}'))|;
54 $dbh->do($query) || $form->dberror($query);
56 $query = qq|SELECT a.id FROM $form->{arap} a
57 WHERE a.invnumber = '$uid'|;
58 $sth = $dbh->prepare($query);
59 $sth->execute || $form->dberror($query);
61 ($uid) = $sth->fetchrow_array;
64 my $invnumber = ($form->{invnumber}) ? $form->{invnumber} : $uid;
65 $query = qq|UPDATE $form->{arap} set
66 invnumber = '$invnumber',
67 $vc_id = $form->{"$form->{vc}_id"},
68 transdate = '$form->{datepaid}',
69 datepaid = '$form->{datepaid}',
70 duedate = '$form->{datepaid}',
74 curr = '$form->{currency}',
75 department_id = $form->{department_id}
77 $dbh->do($query) || $form->dberror($query);
80 ($accno) = split /--/, $form->{ $form->{ARAP} };
82 $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount)
83 VALUES ($uid, (SELECT c.id FROM chart c
84 WHERE c.accno = '$accno'),
85 '$form->{datepaid}', $fxamount * $ml)|;
86 $dbh->do($query) || $form->dberror($query);
89 $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
91 VALUES ($uid, (SELECT c.id FROM chart c
92 WHERE c.accno = '$paymentaccno'),
93 '$form->{datepaid}', $amount * $ml * -1,
94 '$form->{source}', '$form->{memo}')|;
95 $dbh->do($query) || $form->dberror($query);
97 # add exchangerate difference
98 if ($fxamount != $amount) {
99 $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
100 amount, cleared, fx_transaction)
101 VALUES ($uid, (SELECT c.id FROM chart c
102 WHERE c.accno = '$paymentaccno'),
103 '$form->{datepaid}', ($fxamount - $amount) * $ml * -1,
105 $dbh->do($query) || $form->dberror($query);
108 $main::lxdebug->leave_sub();