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,cus.customernumber,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 # Bestandteile von Erzeugnissen herausfiltern
66 $where .= " AND i.assemblyitem is not true ";
68 my $sortorder = "cus.name,i.parts_id,ar.transdate";
69 if ($form->{sortby} eq 'artikelsort') {
70 $sortorder = "i.parts_id,cus.name,ar.transdate";
73 if ($form->{customer_id}) {
74 $where .= " AND ar.customer_id = ?";
75 push(@values, $form->{customer_id});
77 if ($form->{customernumber}) {
78 $where .= qq| AND cus.customernumber = ? |;
79 push(@values, $form->{customernumber});
81 if ($form->{partnumber}) {
82 $where .= qq| AND (p.partnumber ILIKE ?)|;
83 push(@values, '%' . $form->{partnumber} . '%');
85 # nimmt man description am Besten aus invoice oder parts?
86 if ($form->{description}) {
87 $where .= qq| AND (i.description ILIKE ?)|;
88 push(@values, '%' . $form->{description} . '%');
90 if ($form->{transdatefrom}) {
91 $where .= " AND ar.transdate >= ?";
92 push(@values, $form->{transdatefrom});
94 if ($form->{transdateto}) {
95 $where .= " AND ar.transdate <= ?";
96 push(@values, $form->{transdateto});
98 if ($form->{department}) {
99 my ($null, $department_id) = split /--/, $form->{department};
100 $where .= " AND ar.department_id = ?";
101 push(@values, $department_id);
103 if ($form->{project_id}) {
105 qq|AND ((ar.globalproject_id = ?) OR EXISTS | .
106 qq| (SELECT * FROM invoice i | .
107 qq| WHERE i.project_id = ? AND i.trans_id = ar.id))|;
108 push(@values, $form->{"project_id"}, $form->{"project_id"});
111 $query .= " WHERE $where ORDER BY $sortorder";
113 my @result = selectall_hashref_query($form, $dbh, $query, @values);
115 $form->{AR} = [ @result ];
117 $main::lxdebug->leave_sub();