epic-s6ts
[kivitendo-erp.git] / SL / Chart.pm
1 package SL::Chart;
2
3 use SL::Form;
4 use SL::DBUtils;
5
6 use strict;
7
8 sub list {
9   $main::lxdebug->enter_sub();
10
11   my $self     = shift;
12   my %params   = @_;
13
14   my $myconfig = \%main::myconfig;
15   my $form     = $main::form;
16
17   my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
18
19   my @values   = ();
20   my @where    = ();
21
22   if ($params{link}) {
23     if ($params{link} =~ '%') {
24       push @where,  "c.link LIKE ?";
25       push @values, $params{link};
26
27     } else {
28       push @where,  "(c.link = ?) OR (c.link LIKE ?) OR (c.link LIKE ?) OR (c.link LIKE ?)";
29       push @values, $params{link}, '%:' . $params{link} . ':%', '%:' . $params{link}, $params{link} . ':%';
30     }
31   }
32
33   my $where = scalar @where ? 'WHERE ' . join(' AND ', map { "($_)" } @where) : '';
34
35   my $query =
36     qq|SELECT c.id, c.accno, c.description, c.link
37        FROM chart c
38        $where
39        ORDER BY c.accno|;
40
41   my $charts = selectall_hashref_query($form, $dbh, $query, @values);
42
43   $main::lxdebug->leave_sub();
44
45   return $charts;
46 }
47
48 1;
49