5dc9b89ee0395982212e96925b3452a8e19e55fa
[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 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   call_sub("form_$::form->{type}");
66
67   $::lxdebug->leave_sub;
68 }
69
70 sub search {
71   $::lxdebug->enter_sub;
72   $::auth->assert('config');
73
74   $::form->header;
75   print $::form->parse_html_template('pe/search', {
76     is_pricegroup => $::form->{type} eq 'pricegroup',
77   });
78
79   $::lxdebug->leave_sub;
80 }
81
82 sub save {
83   $::lxdebug->enter_sub;
84   $::auth->assert('config');
85
86   if ($::form->{type} eq 'partsgroup') {
87     $::form->isblank("partsgroup", $::locale->text('Group missing!'));
88     PE->save_partsgroup(\%::myconfig, $::form);
89     $::form->redirect($::locale->text('Group saved!'));
90   }
91
92   # saving the history
93   if(!exists $::form->{addition} && $::form->{id} ne "") {
94     $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber};
95     $::form->{addition} = "SAVED";
96     $::form->save_history;
97   }
98   # /saving the history
99
100   $::lxdebug->leave_sub;
101 }
102
103 sub delete {
104   $::lxdebug->enter_sub;
105   $::auth->assert('config');
106
107   PE->delete_tuple(\%::myconfig, $::form);
108
109   if ($::form->{type} eq 'partsgroup') {
110     $::form->redirect($::locale->text('Group deleted!'));
111   }
112   $::lxdebug->leave_sub;
113 }
114
115 sub continue { call_sub($::form->{nextsub}); }
116
117 sub partsgroup_report {
118   $::lxdebug->enter_sub;
119   $::auth->assert('config');
120
121   $::form->{$_} = $::form->unescape($::form->{$_}) for qw(partsgroup);
122   PE->partsgroups(\%::myconfig, $::form);
123
124   my $callback = build_std_url("action=partsgroup_report", qw(type status));
125
126   my $option = '';
127   $option .= $::locale->text('All')      if $::form->{status} eq 'all';
128   $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned';
129
130   if ($::form->{partsgroup}) {
131     $callback .= "&partsgroup=$::form->{partsgroup}";
132     $option   .= ", " . $::locale->text('Group') . " : $::form->{partsgroup}";
133   }
134
135   # escape callback
136   $::form->{callback} = $callback;
137
138   $::form->header;
139   print $::form->parse_html_template('pe/partsgroup_report', {
140     option   => $option,
141     callback => $callback,
142     editlink => build_std_url('action=edit', qw(type status callback)),
143   });
144
145   $::lxdebug->leave_sub;
146 }
147
148 sub form_partsgroup {
149   $::lxdebug->enter_sub;
150   $::auth->assert('config');
151
152   # $locale->text('Add Group')
153   # $locale->text('Edit Group')
154   $::form->{title} = $::locale->text("$::form->{title} Group");
155
156   $::form->header;
157   print $::form->parse_html_template('pe/partsgroup_form');
158
159   $::lxdebug->leave_sub;
160 }