Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 08844064

Von Moritz Bunkus vor fast 17 Jahren hinzugefügt

  • ID 0884406403ce36af3484924086527ba689807329
  • Vorgänger 596c6378
  • Nachfolger de41ce6f

Projektverwaltung in eine eigene Datei ausgelagert und auf die Verwendung von Template umgestellt.

Unterschiede anzeigen:

SL/PE.pm
28 28
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 29
#======================================================================
30 30
#
31
# Project module
32
# also used for partsgroups
31
# Partsgroups and pricegroups
33 32
#
34 33
#======================================================================
35 34

  
......
39 38

  
40 39
use SL::DBUtils;
41 40

  
42
sub projects {
43
  $main::lxdebug->enter_sub();
44

  
45
  my ($self, $myconfig, $form) = @_;
46

  
47
  # connect to database
48
  my $dbh = $form->dbconnect($myconfig);
49

  
50
  my ($where, @values);
51

  
52
  foreach my $column (qw(projectnumber description)) {
53
    if ($form->{$column}) {
54
      $where .= qq|AND $column ILIKE ? |;
55
      push(@values, '%' . $form->{$column} . '%');
56
    }
57
  }
58

  
59
  if ($form->{status} eq 'orphaned') {
60
    my %col_prefix = ("ar" => "global", "ap" => "global", "oe" => "global");
61
    my $first = 1;
62

  
63
    $where .= qq|AND id NOT IN (|;
64
    foreach my $table (qw(acc_trans invoice orderitems rmaitems ar ap oe)) {
65
      $where .= "UNION " unless ($first);
66
      $first = 0;
67
      $where .=
68
        qq|SELECT DISTINCT $col_prefix{$table}project_id FROM $table | .
69
        qq|WHERE NOT $col_prefix{$table}project_id ISNULL |;
70
    }
71
    $where .= qq|) |;
72
  }
73

  
74
  if ($form->{active} eq "active") {
75
    $where .= qq|AND active |;
76
  } elsif ($form->{active} eq "inactive") {
77
    $where .= qq|AND NOT active |;
78
  }
79

  
80
  substr($where, 0, 4) = "WHERE " if ($where);
81

  
82
  my $sortorder = $form->{sort} ? $form->{sort} : "projectnumber";
83
  $sortorder =~ s/[^a-z_]//g;
84
  my $query =
85
    qq|SELECT id, projectnumber, description, active | .
86
    qq|FROM project | .
87
    $where .
88
    qq|ORDER BY $sortorder|;
89

  
90
  $form->{project_list} =
91
    selectall_hashref_query($form, $dbh, $query, @values);
92
  $dbh->disconnect;
93

  
94
  $main::lxdebug->leave_sub();
95

  
96
  return scalar(@{ $form->{project_list} });
97
}
98

  
99
sub get_project {
100
  $main::lxdebug->enter_sub();
101

  
102
  my ($self, $myconfig, $form) = @_;
103

  
104
  # connect to database
105
  my $dbh = $form->dbconnect($myconfig);
106

  
107
  my $query =
108
    qq|SELECT * FROM project | .
109
    qq|WHERE id = ?|;
110
	my @values = ($form->{id});
111
  my $sth = $dbh->prepare($query);
112
  $sth->execute(@values) || $form->dberror($query);
113

  
114
  my $ref = $sth->fetchrow_hashref(NAME_lc);
115

  
116
  map { $form->{$_} = $ref->{$_} } keys %$ref;
117

  
118
  $sth->finish;
119

  
120
  # check if it is orphaned
121
  my %col_prefix = ("ar" => "global", "ap" => "global", "oe" => "global");
122
  @values = ();
123
  $query = qq|SELECT |;
124
  my $first = 1;
125
  foreach my $table (qw(acc_trans invoice orderitems rmaitems ar ap oe)) {
126
    $query .= " + " unless ($first);
127
    $first = 0;
128
    $query .=
129
      qq|(SELECT COUNT(*) FROM $table | .
130
      qq| WHERE $col_prefix{$table}project_id = ?) |;
131
    push(@values, $form->{id});
132
  }
133

  
134
  ($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values);
135
  $form->{orphaned} = !$form->{orphaned};
136

  
137
  $dbh->disconnect;
138

  
139
  $main::lxdebug->leave_sub();
140
}
141

  
142
sub save_project {
143
  $main::lxdebug->enter_sub();
144

  
145
  my ($self, $myconfig, $form) = @_;
146

  
147
  # connect to database
148
  my $dbh = $form->dbconnect($myconfig);
149

  
150
  my @values = ($form->{projectnumber}, $form->{description});
151

  
152
  if ($form->{id}) {
153
    $query =
154
      qq|UPDATE project SET projectnumber = ?, description = ?, active = ? | .
155
      qq|WHERE id = ?|;
156
    push(@values, ($form->{active} ? 't' : 'f'), $form->{id});
157
  } else {
158
    $query =
159
      qq|INSERT INTO project (projectnumber, description, active) | .
160
      qq|VALUES (?, ?, 't')|;
161
  }
162
  do_query($form, $dbh, $query, @values);
163

  
164
  $dbh->disconnect;
165

  
166
  $main::lxdebug->leave_sub();
167
}
168

  
169 41
sub partsgroups {
170 42
  $main::lxdebug->enter_sub();
171 43

  
......
265 137
  # connect to database
266 138
  my $dbh = $form->dbconnect($myconfig);
267 139

  
268
  my $table =
269
    $form->{type} eq "project" ? "project" :
270
    $form->{type} eq "pricegroup" ? "pricegroup" :
271
    "partsgroup";
140
  my $table = $form->{type} eq "pricegroup" ? "pricegroup" : "partsgroup";
272 141

  
273 142
  $query = qq|DELETE FROM $table WHERE id = ?|;
274 143
  do_query($form, $dbh, $query, $form->{id});

Auch abrufbar als: Unified diff