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 # Account reconciliation routines
33 #======================================================================
39 $main::lxdebug->enter_sub();
41 my ($self, $myconfig, $form) = @_;
44 my $dbh = $form->dbconnect($myconfig);
46 my $query = qq|SELECT c.accno, c.description
48 WHERE c.link LIKE '%_paid%'
49 AND (c.category = 'A' OR c.category = 'L')
51 my $sth = $dbh->prepare($query);
52 $sth->execute || $form->dberror($query);
54 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
55 push @{ $form->{PR} }, $ref;
60 $main::lxdebug->leave_sub();
64 sub payment_transactions {
65 $main::lxdebug->enter_sub();
67 my ($self, $myconfig, $form) = @_;
69 # connect to database, turn AutoCommit off
70 my $dbh = $form->dbconnect_noauto($myconfig);
75 if ($form->{fromdate}) {
76 $query = qq|SELECT sum(a.amount),
77 (SELECT DISTINCT c2.category FROM chart c2
78 WHERE c2accno = '$form->{accno}') AS category
80 JOIN chart c ON (c.id = a.chart_id)
81 WHERE a.transdate < date '$form->{fromdate}'
83 AND c.accno = '$form->{accno}'
86 $query = qq|SELECT sum(a.amount),
87 (SELECT DISTINCT c2.category FROM chart c2
88 WHERE c2.accno = '$form->{accno}') AS category
90 JOIN chart c ON (c.id = a.chart_id)
92 AND c.accno = '$form->{accno}'
96 $sth = $dbh->prepare($query);
97 $sth->execute || $form->dberror($query);
99 ($form->{beginningbalance}, $form->{category}) = $sth->fetchrow_array;
103 my %oid = ( 'Pg' => 'ac.oid',
104 'Oracle' => 'ac.rowid');
106 $query = qq|SELECT c.name, ac.source, ac.transdate, ac.cleared,
107 ac.fx_transaction, ac.amount, a.id,
108 $oid{$myconfig->{dbdriver}} AS oid
109 FROM customer c, acc_trans ac, ar a, chart ch
110 WHERE c.id = a.customer_id
111 -- AND NOT ac.fx_transaction
113 AND ac.trans_id = a.id
114 AND ac.chart_id = ch.id
115 AND ch.accno = '$form->{accno}'
118 $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
119 $query .= " AND ac.transdate <= '$form->{todate}'" if $form->{todate};
125 SELECT v.name, ac.source, ac.transdate, ac.cleared,
126 ac.fx_transaction, ac.amount, a.id,
127 $oid{$myconfig->{dbdriver}} AS oid
128 FROM vendor v, acc_trans ac, ap a, chart ch
129 WHERE v.id = a.vendor_id
130 -- AND NOT ac.fx_transaction
132 AND ac.trans_id = a.id
133 AND ac.chart_id = ch.id
134 AND ch.accno = '$form->{accno}'
137 $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
138 $query .= " AND ac.transdate <= '$form->{todate}'" if $form->{todate};
143 SELECT g.description, ac.source, ac.transdate, ac.cleared,
144 ac.fx_transaction, ac.amount, g.id,
145 $oid{$myconfig->{dbdriver}} AS oid
146 FROM gl g, acc_trans ac, chart ch
147 WHERE g.id = ac.trans_id
148 -- AND NOT ac.fx_transaction
150 AND ac.trans_id = g.id
151 AND ac.chart_id = ch.id
152 AND ch.accno = '$form->{accno}'
155 $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
156 $query .= " AND ac.transdate <= '$form->{todate}'" if $form->{todate};
158 $query .= " ORDER BY 3,7,8";
160 $sth = $dbh->prepare($query);
161 $sth->execute || $form->dberror($query);
163 while (my $pr = $sth->fetchrow_hashref(NAME_lc)) {
164 push @{ $form->{PR} }, $pr;
170 $main::lxdebug->leave_sub();
175 $main::lxdebug->enter_sub();
177 my ($self, $myconfig, $form) = @_;
179 # connect to database
180 my $dbh = $form->dbconnect($myconfig);
183 my %oid = ( 'Pg' => 'oid',
184 'Oracle' => 'rowid');
187 for $i (1 .. $form->{rowcount}) {
188 if ($form->{"cleared_$i"}) {
189 $query = qq|UPDATE acc_trans SET cleared = '1'
190 WHERE $oid{$myconfig->{dbdriver}} = $form->{"oid_$i"}|;
191 $dbh->do($query) || $form->dberror($query);
193 # clear fx_transaction
194 if ($form->{"fxoid_$i"}) {
195 $query = qq|UPDATE acc_trans SET cleared = '1'
196 WHERE $oid{$myconfig->{dbdriver}} = $form->{"fxoid_$i"}|;
197 $dbh->do($query) || $form->dberror($query);
204 $main::lxdebug->leave_sub();