epic-ts
[kivitendo-erp.git] / 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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # partsgroup, pricegroup administration
31 #
32 #======================================================================
33
34 use SL::PE;
35
36 require "bin/mozilla/common.pl";
37
38 use strict;
39
40 1;
41
42 # end of main
43
44 sub add {
45   $::lxdebug->enter_sub;
46   $::auth->assert('config');
47
48   $::form->{title} = "Add";
49   $::form->{callback} ||= "$::form->{script}?action=add&type=$::form->{type}";
50
51   call_sub("form_$::form->{type}");
52
53   $::lxdebug->leave_sub;
54 }
55
56 sub edit {
57   $::lxdebug->enter_sub;
58   $::auth->assert('config');
59
60   $::form->{title} = "Edit";
61
62   if ($::form->{type} eq 'partsgroup') {
63     PE->get_partsgroup(\%::myconfig, $::form);
64   }
65   if ($::form->{type} eq 'pricegroup') {
66     PE->get_pricegroup(\%::myconfig, $::form);
67   }
68   call_sub("form_$::form->{type}");
69
70   $::lxdebug->leave_sub;
71 }
72
73 sub search {
74   $::lxdebug->enter_sub;
75   $::auth->assert('config');
76
77   $::form->header;
78   print $::form->parse_html_template('pe/search', {
79     is_pricegroup => $::form->{type} eq 'pricegroup',
80   });
81
82   $::lxdebug->leave_sub;
83 }
84
85 sub save {
86   $::lxdebug->enter_sub;
87   $::auth->assert('config');
88
89   if ($::form->{type} eq 'partsgroup') {
90     $::form->isblank("partsgroup", $::locale->text('Group missing!'));
91     PE->save_partsgroup(\%::myconfig, $::form);
92     $::form->redirect($::locale->text('Group saved!'));
93   }
94
95   # choice pricegroup and save
96   if ($::form->{type} eq 'pricegroup') {
97     $::form->isblank("pricegroup", $::locale->text('Pricegroup missing!'));
98     PE->save_pricegroup(\%::myconfig, $::form);
99     $::form->redirect($::locale->text('Pricegroup saved!'));
100   }
101   # saving the history
102   if(!exists $::form->{addition} && $::form->{id} ne "") {
103     $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber};
104     $::form->{addition} = "SAVED";
105     $::form->save_history;
106   }
107   # /saving the history
108
109   $::lxdebug->leave_sub;
110 }
111
112 sub delete {
113   $::lxdebug->enter_sub;
114   $::auth->assert('config');
115
116   PE->delete_tuple(\%::myconfig, $::form);
117
118   if ($::form->{type} eq 'partsgroup') {
119     $::form->redirect($::locale->text('Group deleted!'));
120   }
121   if ($::form->{type} eq 'pricegroup') {
122     $::form->redirect($::locale->text('Pricegroup deleted!'));
123   }
124   # saving the history
125   if(!exists $::form->{addition}) {
126     $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber};
127     $::form->{addition} = "DELETED";
128     $::form->save_history;
129   }
130   # /saving the history
131   $::lxdebug->leave_sub;
132 }
133
134 sub continue { call_sub($::form->{nextsub}); }
135
136 sub partsgroup_report {
137   $::lxdebug->enter_sub;
138   $::auth->assert('config');
139
140   $::form->{$_} = $::form->unescape($::form->{$_}) for qw(partsgroup);
141   PE->partsgroups(\%::myconfig, $::form);
142
143   my $callback = build_std_url("action=partsgroup_report", qw(type status));
144
145   my $option = '';
146   $option .= $::locale->text('All')      if $::form->{status} eq 'all';
147   $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned';
148
149   if ($::form->{partsgroup}) {
150     $callback .= "&partsgroup=$::form->{partsgroup}";
151     $option   .= ", " . $::locale->text('Group') . " : $::form->{partsgroup}";
152   }
153
154   # escape callback
155   $::form->{callback} = $callback;
156
157   $::form->header;
158   print $::form->parse_html_template('pe/partsgroup_report', {
159     option   => $option,
160     callback => $callback,
161     editlink => build_std_url('action=edit', qw(type status callback)),
162   });
163
164   $::lxdebug->leave_sub;
165 }
166
167 sub form_partsgroup {
168   $::lxdebug->enter_sub;
169   $::auth->assert('config');
170
171   # $locale->text('Add Group')
172   # $locale->text('Edit Group')
173   $::form->{title} = $::locale->text("$::form->{title} Group");
174
175   $::form->header;
176   print $::form->parse_html_template('pe/partsgroup_form');
177
178   $::lxdebug->leave_sub;
179 }
180
181 sub pricegroup_report {
182   $::lxdebug->enter_sub;
183   $::auth->assert('config');
184
185   $::form->{$_} = $::form->unescape($::form->{$_}) for qw(pricegroup);
186   PE->pricegroups(\%::myconfig, $::form);
187
188   my $callback = build_std_url('action=pricegroup_report', qw(type status));
189
190   my $option = '';
191   $option .= $::locale->text('All')      if $::form->{status} eq 'all';
192   $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned';
193
194   if ($::form->{pricegroup}) {
195     $callback .= "&pricegroup=$::form->{pricegroup}";
196     $option   .= ", " . $::locale->text('Pricegroup') . " : $::form->{pricegroup}";
197   }
198
199   # escape callback
200   $::form->{callback} = $callback;
201
202   $::form->header;
203   print $::form->parse_html_template('pe/pricegroup_report', {
204     option   => $option,
205     callback => $callback,
206     editlink => build_std_url('action=edit', qw(type status callback)),
207   });
208
209   $::lxdebug->leave_sub;
210 }
211
212 sub form_pricegroup {
213   $::lxdebug->enter_sub;
214   $::auth->assert('config');
215
216   # $locale->text('Add Pricegroup')
217   # $locale->text('Edit Pricegroup')
218   $::form->{title} = $::locale->text("$::form->{title} Pricegroup");
219
220   $::form->header;
221   print $::form->parse_html_template('pe/pricegroup_form');
222
223   $::lxdebug->leave_sub;
224 }