Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 19fb04d1

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID 19fb04d1cfad224a0f0c4c3b88494b4605fc6d4e
  • Vorgänger 9c785acd
  • Nachfolger df41380a

SL/PE.pm und bin/mozilla/pe.pl entfernt

Unterschiede anzeigen:

SL/PE.pm
1
#=====================================================================
2
# LX-Office ERP
3
# Copyright (C) 2004
4
# Based on SQL-Ledger Version 2.1.9
5
# Web http://www.lx-office.org
6
#
7
#=====================================================================
8
# SQL-Ledger Accounting
9
# Copyright (C) 1998-2002
10
#
11
#  Author: Dieter Simader
12
#   Email: dsimader@sql-ledger.org
13
#     Web: http://www.sql-ledger.org
14
#
15
#  Contributors:
16
#
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.
21
#
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., 51 Franklin Street, Fifth Floor, Boston,
29
# MA 02110-1335, USA.
30
#======================================================================
31
#
32
# Partsgroups and pricegroups
33
#
34
#======================================================================
35

  
36
package PE;
37

  
38
use Data::Dumper;
39

  
40
use SL::DBUtils;
41
use SL::DB;
42

  
43
use strict;
44

  
45
sub partsgroups {
46
  $main::lxdebug->enter_sub();
47

  
48
  my ($self, $myconfig, $form) = @_;
49

  
50
  # connect to database
51
  my $dbh = SL::DB->client->dbh;
52

  
53
  my ($where, @values);
54

  
55
  if ($form->{partsgroup}) {
56
    $where .= qq| AND partsgroup ILIKE ?|;
57
    push(@values, like($form->{partsgroup}));
58
  }
59

  
60
  if ($form->{status} eq 'orphaned') {
61
    $where .=
62
      qq| AND id NOT IN | .
63
      qq|  (SELECT DISTINCT partsgroup_id FROM parts | .
64
      qq|   WHERE NOT partsgroup_id ISNULL | .
65
      qq| UNION | .
66
      qq|   SELECT DISTINCT partsgroup_id FROM custom_variable_config_partsgroups | .
67
      qq|   WHERE NOT partsgroup_id ISNULL) |;
68
  }
69

  
70
  substr($where, 0, 4) = "WHERE " if ($where);
71

  
72
  my $sortorder = $form->{sort} ? $form->{sort} : "partsgroup";
73
  $sortorder =~ s/[^a-z_]//g;
74

  
75
  my $query =
76
    qq|SELECT id, partsgroup FROM partsgroup | .
77
    $where .
78
    qq|ORDER BY $sortorder|;
79

  
80
  $form->{item_list} = selectall_hashref_query($form, $dbh, $query, @values);
81

  
82
  $main::lxdebug->leave_sub();
83

  
84
  return scalar(@{ $form->{item_list} });
85
}
86

  
87
sub save_partsgroup {
88
  $main::lxdebug->enter_sub();
89

  
90
  my ($self, $myconfig, $form) = @_;
91

  
92
  # connect to database
93
  my $dbh = SL::DB->client->dbh;
94

  
95
  $form->{discount} /= 100;
96

  
97
  my @values = ($form->{partsgroup});
98
  my $query;
99

  
100
  if ($form->{id}) {
101
    $query = qq|UPDATE partsgroup SET partsgroup = ? WHERE id = ?|;
102
    push(@values, $form->{id});
103
  } else {
104
    $query = qq|INSERT INTO partsgroup (partsgroup) VALUES (?)|;
105
  }
106
  do_query($form, $dbh, $query, @values);
107

  
108
  $main::lxdebug->leave_sub();
109
}
110

  
111
sub get_partsgroup {
112
  $main::lxdebug->enter_sub();
113

  
114
  my ($self, $myconfig, $form) = @_;
115

  
116
  # connect to database
117
  my $dbh = SL::DB->client->dbh;
118

  
119
  my $query =
120
    qq|SELECT pg.*, | .
121
    qq|(SELECT COUNT(*) FROM parts WHERE partsgroup_id = ?) = 0 AS orphaned | .
122
    qq|FROM partsgroup pg | .
123
    qq|WHERE pg.id = ?|;
124
  my $sth = prepare_execute_query($form, $dbh, $query, $form->{id},
125
                                  $form->{id});
126
  my $ref = $sth->fetchrow_hashref("NAME_lc");
127

  
128
  map({ $form->{$_} = $ref->{$_} } keys(%{$ref}));
129
  $sth->finish;
130

  
131
  # also not orphaned if partsgroup is selected for a cvar filter
132
  if ($form->{orphaned}) {
133
    my $cvar_count = scalar( @{ SL::DB::PartsGroup->new(id => $form->{id})->custom_variable_configs } );
134
    $form->{orphaned} = !$cvar_count;
135
  }
136

  
137
  $main::lxdebug->leave_sub();
138
}
139

  
140
sub delete_tuple {
141
  $main::lxdebug->enter_sub();
142

  
143
  my ($self, $myconfig, $form) = @_;
144

  
145
  # connect to database
146
  SL::DB->client->with_transaction(sub {
147
    my $dbh = SL::DB->client->dbh;
148

  
149
    my $table = $form->{type} eq "pricegroup" ? "pricegroup" : "partsgroup";
150

  
151
    my $query = qq|DELETE FROM $table WHERE id = ?|;
152
    do_query($form, $dbh, $query, $form->{id});
153
    1;
154
  }) or do { die SL::DB->client->error };
155

  
156
  $main::lxdebug->leave_sub();
157
}
158

  
159
##########################
160
# get pricegroups from database
161
#
162
sub pricegroups {
163
  $main::lxdebug->enter_sub();
164

  
165
  my ($self, $myconfig, $form) = @_;
166

  
167
  # connect to database
168
  my $dbh = SL::DB->client->dbh;
169

  
170
  my ($where, @values);
171

  
172
  if ($form->{pricegroup}) {
173
    $where .= qq| AND pricegroup ILIKE ?|;
174
    push(@values, like($form->{pricegroup}));
175
  }
176

  
177
  if ($form->{status} eq 'orphaned') {
178
    my $first = 1;
179

  
180
    $where .= qq| AND id NOT IN (|;
181
    foreach my $table (qw(invoice orderitems prices)) {
182
      $where .= "UNION " unless ($first);
183
      $first = 0;
184
      $where .=
185
        qq|SELECT DISTINCT pricegroup_id FROM $table | .
186
        qq|WHERE NOT pricegroup_id ISNULL |;
187
    }
188
    $where .= qq|) |;
189
  }
190

  
191
  substr($where, 0, 4) = "WHERE " if ($where);
192

  
193
  my $sortorder = $form->{sort} ? $form->{sort} : "pricegroup";
194
  $sortorder =~ s/[^a-z_]//g;
195

  
196
  my $query =
197
    qq|SELECT id, pricegroup FROM pricegroup | .
198
    $where .
199
    qq|ORDER BY $sortorder|;
200

  
201
  $form->{item_list} = selectall_hashref_query($form, $dbh, $query, @values);
202

  
203
  $main::lxdebug->leave_sub();
204

  
205
  return scalar(@{ $form->{item_list} });
206
}
207

  
208
########################
209
# save pricegruop to database
210
#
211
sub save_pricegroup {
212
  $main::lxdebug->enter_sub();
213

  
214
  my ($self, $myconfig, $form) = @_;
215

  
216
  SL::DB->client->with_transaction(sub {
217
    my $dbh = SL::DB->client->dbh;
218
    my $query;
219

  
220
    $form->{discount} /= 100;
221

  
222
    my @values = ($form->{pricegroup});
223

  
224
    if ($form->{id}) {
225
      $query = qq|UPDATE pricegroup SET pricegroup = ? WHERE id = ? |;
226
      push(@values, $form->{id});
227
    } else {
228
      $query = qq|INSERT INTO pricegroup (pricegroup) VALUES (?)|;
229
    }
230
    do_query($form, $dbh, $query, @values);
231
    1;
232
  }) or do { die SL::DB->client->error };
233

  
234
  $main::lxdebug->leave_sub();
235
}
236

  
237
############################
238
# get one pricegroup from database
239
#
240
sub get_pricegroup {
241
  $main::lxdebug->enter_sub();
242

  
243
  my ($self, $myconfig, $form) = @_;
244

  
245
  # connect to database
246
  my $dbh = SL::DB->client->dbh;
247

  
248
  my $query = qq|SELECT id, pricegroup FROM pricegroup WHERE id = ?|;
249
  my $sth = prepare_execute_query($form, $dbh, $query, $form->{id});
250
  my $ref = $sth->fetchrow_hashref("NAME_lc");
251

  
252
  map({ $form->{$_} = $ref->{$_} } keys(%{$ref}));
253

  
254
  $sth->finish;
255

  
256
  my $first = 1;
257

  
258
  my @values = ();
259
  $query = qq|SELECT |;
260
  foreach my $table (qw(invoice orderitems prices)) {
261
    $query .= " + " unless ($first);
262
    $first = 0;
263
    $query .= qq|(SELECT COUNT(*) FROM $table WHERE pricegroup_id = ?) |;
264
    push(@values, $form->{id});
265
  }
266

  
267
  ($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values);
268
  $form->{orphaned} = !$form->{orphaned};
269

  
270
  $main::lxdebug->leave_sub();
271
}
272

  
273
1;
274

  
bin/mozilla/ap.pl
40 40
use SL::FU;
41 41
use SL::IR;
42 42
use SL::IS;
43
use SL::PE;
44 43
use SL::ReportGenerator;
45 44
use SL::DB::Default;
46 45
use SL::DB::PurchaseInvoice;
bin/mozilla/ar.pl
39 39
use SL::AR;
40 40
use SL::FU;
41 41
use SL::IS;
42
use SL::PE;
43 42
use SL::DB::Default;
44 43
use SL::DB::Invoice;
45 44
use SL::ReportGenerator;
bin/mozilla/dn.pl
35 35
use POSIX qw(strftime);
36 36

  
37 37
use SL::IS;
38
use SL::PE;
39 38
use SL::DN;
40 39
use SL::DB::Dunning;
41 40
use SL::Helper::Flash qw(flash);
bin/mozilla/gl.pl
41 41
use SL::FU;
42 42
use SL::GL;
43 43
use SL::IS;
44
use SL::PE;
45 44
use SL::ReportGenerator;
46 45
use SL::DBUtils qw(selectrow_query selectall_hashref_query);
47 46

  
bin/mozilla/io.pl
104 104
# $locale->text('Nov')
105 105
# $locale->text('Dec')
106 106
use SL::IS;
107
use SL::PE;
108 107
use SL::AM;
109 108
use Data::Dumper;
110 109

  
bin/mozilla/ir.pl
35 35
use SL::FU;
36 36
use SL::IR;
37 37
use SL::IS;
38
use SL::PE;
39 38
use SL::DB::Default;
40 39
use SL::DB::PurchaseInvoice;
41 40
use List::Util qw(max sum);
bin/mozilla/is.pl
34 34

  
35 35
use SL::FU;
36 36
use SL::IS;
37
use SL::PE;
38 37
use SL::OE;
39 38
use SL::MoreCommon qw(restore_form save_form);
40 39
use Data::Dumper;
bin/mozilla/oe.pl
43 43
use SL::IR;
44 44
use SL::IS;
45 45
use SL::MoreCommon qw(ary_diff restore_form save_form);
46
use SL::PE;
47 46
use SL::ReportGenerator;
48 47
use List::MoreUtils qw(uniq any none);
49 48
use List::Util qw(min max reduce sum);
bin/mozilla/pe.pl
1
#=====================================================================
2
# LX-Office ERP
3
# Copyright (C) 2004
4
# Based on SQL-Ledger Version 2.1.9
5
# Web http://www.lx-office.org
6
#
7
#=====================================================================
8
# SQL-Ledger Accounting
9
# Copyright (c) 1998-2002
10
#
11
#  Author: Dieter Simader
12
#   Email: dsimader@sql-ledger.org
13
#     Web: http://www.sql-ledger.org
14
#
15
#
16
# This program is free software; you can redistribute it and/or modify
17
# it under the terms of the GNU General Public License as published by
18
# the Free Software Foundation; either version 2 of the License, or
19
# (at your option) any later version.
20
#
21
# This program is distributed in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28
# MA 02110-1335, USA.
29
#======================================================================
30
#
31
# partsgroup administration
32
#
33
#======================================================================
34

  
35
use SL::PE;
36

  
37
require "bin/mozilla/common.pl";
38

  
39
use strict;
40

  
41
1;
42

  
43
# end of main
44

  
45
sub add {
46
  $::lxdebug->enter_sub;
47
  $::auth->assert('config');
48

  
49
  $::form->{title} = "Add";
50
  $::form->{callback} ||= "$::form->{script}?action=add&type=$::form->{type}";
51

  
52
  call_sub("form_$::form->{type}");
53

  
54
  $::lxdebug->leave_sub;
55
}
56

  
57
sub edit {
58
  $::lxdebug->enter_sub;
59
  $::auth->assert('config');
60

  
61
  $::form->{title} = "Edit";
62

  
63
  if ($::form->{type} eq 'partsgroup') {
64
    PE->get_partsgroup(\%::myconfig, $::form);
65
  }
66
  call_sub("form_$::form->{type}");
67

  
68
  $::lxdebug->leave_sub;
69
}
70

  
71
sub search {
72
  $::lxdebug->enter_sub;
73
  $::auth->assert('config');
74

  
75
  $::form->header;
76
  print $::form->parse_html_template('pe/search', {
77
    is_pricegroup => $::form->{type} eq 'pricegroup',
78
  });
79

  
80
  $::lxdebug->leave_sub;
81
}
82

  
83
sub save {
84
  $::lxdebug->enter_sub;
85
  $::auth->assert('config');
86

  
87
  if ($::form->{type} eq 'partsgroup') {
88
    $::form->isblank("partsgroup", $::locale->text('Group missing!'));
89
    PE->save_partsgroup(\%::myconfig, $::form);
90
    $::form->redirect($::locale->text('Group saved!'));
91
  }
92

  
93
  # saving the history
94
  if(!exists $::form->{addition} && $::form->{id} ne "") {
95
    $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber};
96
    $::form->{addition} = "SAVED";
97
    $::form->save_history;
98
  }
99
  # /saving the history
100

  
101
  $::lxdebug->leave_sub;
102
}
103

  
104
sub delete {
105
  $::lxdebug->enter_sub;
106
  $::auth->assert('config');
107

  
108
  PE->delete_tuple(\%::myconfig, $::form);
109

  
110
  if ($::form->{type} eq 'partsgroup') {
111
    $::form->redirect($::locale->text('Group deleted!'));
112
  }
113
  $::lxdebug->leave_sub;
114
}
115

  
116
sub continue { call_sub($::form->{nextsub}); }
117

  
118
sub partsgroup_report {
119
  $::lxdebug->enter_sub;
120
  $::auth->assert('config');
121

  
122
  $::form->{$_} = $::form->unescape($::form->{$_}) for qw(partsgroup);
123
  PE->partsgroups(\%::myconfig, $::form);
124

  
125
  my $callback = build_std_url("action=partsgroup_report", qw(type status));
126

  
127
  my $option = '';
128
  $option .= $::locale->text('All')      if $::form->{status} eq 'all';
129
  $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned';
130

  
131
  if ($::form->{partsgroup}) {
132
    $callback .= "&partsgroup=$::form->{partsgroup}";
133
    $option   .= ", " . $::locale->text('Group') . " : $::form->{partsgroup}";
134
  }
135

  
136
  # escape callback
137
  $::form->{callback} = $callback;
138

  
139
  $::form->header;
140
  print $::form->parse_html_template('pe/partsgroup_report', {
141
    option   => $option,
142
    callback => $callback,
143
    editlink => build_std_url('action=edit', qw(type status callback)),
144
  });
145

  
146
  $::lxdebug->leave_sub;
147
}
148

  
149
sub form_partsgroup {
150
  $::lxdebug->enter_sub;
151
  $::auth->assert('config');
152

  
153
  # $locale->text('Add Group')
154
  # $locale->text('Edit Group')
155
  $::form->{title} = $::locale->text("$::form->{title} Group");
156

  
157
  $::form->header;
158
  print $::form->parse_html_template('pe/partsgroup_form');
159

  
160
  $::lxdebug->leave_sub;
161
}
bin/mozilla/rp.pl
41 41
use SL::DB::Default;
42 42
use SL::DB::Project;
43 43
use SL::DB::Customer;
44
use SL::PE;
45 44
use SL::RP;
46 45
use SL::Iconv;
47 46
use SL::ReportGenerator;
bin/mozilla/ustva.pl
41 41
use List::Util qw(first);
42 42

  
43 43
use SL::DB::Default;
44
use SL::PE;
45 44
use SL::RP;
46 45
use SL::USTVA;
47 46
use SL::User;

Auch abrufbar als: Unified diff