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 #======================================================================
 
  38   $main::lxdebug->enter_sub();
 
  40   my ($self, $myconfig, $form) = @_;
 
  43   my $dbh = $form->dbconnect($myconfig);
 
  45   my $query = qq|SELECT c.accno, c.description
 
  47                  WHERE c.link LIKE '%_paid%'
 
  48                  AND (c.category = 'A' OR c.category = 'L')
 
  50   my $sth = $dbh->prepare($query);
 
  51   $sth->execute || $form->dberror($query);
 
  53   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
  54     push @{ $form->{PR} }, $ref;
 
  59   $main::lxdebug->leave_sub();
 
  62 sub payment_transactions {
 
  63   $main::lxdebug->enter_sub();
 
  65   my ($self, $myconfig, $form) = @_;
 
  67   # connect to database, turn AutoCommit off
 
  68   my $dbh = $form->dbconnect_noauto($myconfig);
 
  73   if ($form->{fromdate}) {
 
  74     $query = qq|SELECT sum(a.amount),
 
  75                      (SELECT DISTINCT c2.category FROM chart c2
 
  76                       WHERE c2accno = '$form->{accno}') AS category
 
  78                 JOIN chart c ON (c.id = a.chart_id)
 
  79                 WHERE a.transdate < date '$form->{fromdate}'
 
  81                 AND c.accno = '$form->{accno}'
 
  84     $query = qq|SELECT sum(a.amount),
 
  85                      (SELECT DISTINCT c2.category FROM chart c2
 
  86                       WHERE c2.accno = '$form->{accno}') AS category
 
  88                 JOIN chart c ON (c.id = a.chart_id)
 
  90                 AND c.accno = '$form->{accno}'
 
  94   $sth = $dbh->prepare($query);
 
  95   $sth->execute || $form->dberror($query);
 
  97   ($form->{beginningbalance}, $form->{category}) = $sth->fetchrow_array;
 
 101   my %oid = ('Pg'     => 'ac.oid',
 
 102              'Oracle' => 'ac.rowid');
 
 104   $query = qq|SELECT c.name, ac.source, ac.transdate, ac.cleared,
 
 105               ac.fx_transaction, ac.amount, a.id,
 
 106               $oid{$myconfig->{dbdriver}} AS oid
 
 107               FROM customer c, acc_trans ac, ar a, chart ch
 
 108               WHERE c.id = a.customer_id
 
 109 --            AND NOT ac.fx_transaction
 
 111               AND ac.trans_id = a.id
 
 112               AND ac.chart_id = ch.id
 
 113               AND ch.accno = '$form->{accno}'
 
 116   $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
 
 117   $query .= " AND ac.transdate <= '$form->{todate}'"   if $form->{todate};
 
 122               SELECT v.name, ac.source, ac.transdate, ac.cleared,
 
 123               ac.fx_transaction, ac.amount, a.id,
 
 124               $oid{$myconfig->{dbdriver}} AS oid
 
 125               FROM vendor v, acc_trans ac, ap a, chart ch
 
 126               WHERE v.id = a.vendor_id
 
 127 --            AND NOT ac.fx_transaction
 
 129               AND ac.trans_id = a.id
 
 130               AND ac.chart_id = ch.id
 
 131               AND ch.accno = '$form->{accno}'
 
 134   $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
 
 135   $query .= " AND ac.transdate <= '$form->{todate}'"   if $form->{todate};
 
 140               SELECT g.description, ac.source, ac.transdate, ac.cleared,
 
 141               ac.fx_transaction, ac.amount, g.id,
 
 142               $oid{$myconfig->{dbdriver}} AS oid
 
 143               FROM gl g, acc_trans ac, chart ch
 
 144               WHERE g.id = ac.trans_id
 
 145 --            AND NOT ac.fx_transaction
 
 147               AND ac.trans_id = g.id
 
 148               AND ac.chart_id = ch.id
 
 149               AND ch.accno = '$form->{accno}'
 
 152   $query .= " AND ac.transdate >= '$form->{fromdate}'" if $form->{fromdate};
 
 153   $query .= " AND ac.transdate <= '$form->{todate}'"   if $form->{todate};
 
 155   $query .= " ORDER BY 3,7,8";
 
 157   $sth = $dbh->prepare($query);
 
 158   $sth->execute || $form->dberror($query);
 
 160   while (my $pr = $sth->fetchrow_hashref(NAME_lc)) {
 
 161     push @{ $form->{PR} }, $pr;
 
 167   $main::lxdebug->leave_sub();
 
 171   $main::lxdebug->enter_sub();
 
 173   my ($self, $myconfig, $form) = @_;
 
 175   # connect to database
 
 176   my $dbh = $form->dbconnect($myconfig);
 
 179   my %oid = ('Pg'     => 'oid',
 
 180              'Oracle' => 'rowid');
 
 183   for $i (1 .. $form->{rowcount}) {
 
 184     if ($form->{"cleared_$i"}) {
 
 185       $query = qq|UPDATE acc_trans SET cleared = '1'
 
 186                   WHERE $oid{$myconfig->{dbdriver}} = $form->{"oid_$i"}|;
 
 187       $dbh->do($query) || $form->dberror($query);
 
 189       # clear fx_transaction
 
 190       if ($form->{"fxoid_$i"}) {
 
 191         $query = qq|UPDATE acc_trans SET cleared = '1'
 
 192                     WHERE $oid{$myconfig->{dbdriver}} = $form->{"fxoid_$i"}|;
 
 193         $dbh->do($query) || $form->dberror($query);
 
 200   $main::lxdebug->leave_sub();