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 #======================================================================
 
  33 #======================================================================
 
  43 sub invoice_transactions {
 
  44   $main::lxdebug->enter_sub();
 
  46   my ($self, $myconfig, $form) = @_;
 
  49   my $dbh = $form->get_standard_dbh($myconfig);
 
  54     qq|SELECT cus.name,ar.invnumber,ar.id,ar.transdate,p.partnumber,i.parts_id,i.qty,i.price_factor,i.discount,i.description,i.lastcost,i.sellprice,i.marge_total,i.marge_percent,i.unit | .
 
  56     qq|join ar on (i.trans_id = ar.id) | .
 
  57     qq|join parts p on (i.parts_id = p.id) | .
 
  58     qq|join customer cus on (cus.id = ar.customer_id) |;
 
  62   # Stornierte Rechnungen und Stornorechnungen in invoice rausfiltern
 
  63   $where .= " AND ar.storno is not true ";
 
  65   my $sortorder = "cus.name,i.parts_id,ar.transdate";
 
  66   if ($form->{sortby} eq 'artikelsort') {
 
  67     $sortorder = "i.parts_id,cus.name,ar.transdate";
 
  70   if ($form->{customer_id}) {
 
  71     $where .= " AND ar.customer_id = ?";
 
  72     push(@values, $form->{customer_id});
 
  74   if ($form->{partnumber}) {
 
  75     $where .= qq| AND (p.partnumber ILIKE ?)|;
 
  76     push(@values, '%' . $form->{partnumber} . '%');
 
  78   # nimmt man description am Besten aus invoice oder parts?
 
  79   if ($form->{description}) {
 
  80     $where .= qq| AND (i.description ILIKE ?)|;
 
  81     push(@values, '%' . $form->{description} . '%');
 
  83   if ($form->{transdatefrom}) {
 
  84     $where .= " AND ar.transdate >= ?";
 
  85     push(@values, $form->{transdatefrom});
 
  87   if ($form->{transdateto}) {
 
  88     $where .= " AND ar.transdate <= ?";
 
  89     push(@values, $form->{transdateto});
 
  91   if ($form->{department}) {
 
  92     my ($null, $department_id) = split /--/, $form->{department};
 
  93     $where .= " AND ar.department_id = ?";
 
  94     push(@values, $department_id);
 
  96   if ($form->{project_id}) {
 
  98       qq|AND ((ar.globalproject_id = ?) OR EXISTS | .
 
  99       qq|  (SELECT * FROM invoice i | .
 
 100       qq|   WHERE i.project_id = ? AND i.trans_id = ar.id))|;
 
 101     push(@values, $form->{"project_id"}, $form->{"project_id"});
 
 104   $query .= " WHERE $where ORDER BY $sortorder";
 
 106   my @result = selectall_hashref_query($form, $dbh, $query, @values);
 
 108   $form->{AR} = [ @result ];
 
 110   $main::lxdebug->leave_sub();