Vorlagentyp "packing_list" gibt es nicht mehr
[kivitendo-erp.git] / bin / mozilla / amtemplates.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 # administration
31 #
32 #======================================================================
33
34 use SL::AM;
35 use SL::Form;
36
37 use Data::Dumper;
38
39 use strict;
40
41 1;
42
43 require "bin/mozilla/common.pl";
44
45 # end of main
46
47 sub display {
48   call_sub($main::form->{display_nextsub});
49 }
50
51 sub save {
52   call_sub($main::form->{save_nextsub});
53 }
54
55 sub edit {
56   call_sub($main::form->{edit_nextsub});
57 }
58
59 sub display_template {
60   $main::lxdebug->enter_sub();
61
62   my $form     = $main::form;
63
64   $main::auth->assert('config');
65
66   $form->{edit} = 0;
67   display_template_form();
68
69   $main::lxdebug->leave_sub();
70 }
71
72 sub edit_template {
73   $main::lxdebug->enter_sub();
74
75   my $form     = $main::form;
76
77   $main::auth->assert('config');
78
79   $form->{edit} = 1;
80   display_template_form();
81
82   $main::lxdebug->leave_sub();
83 }
84
85 sub save_template {
86   $main::lxdebug->enter_sub();
87
88   my $form     = $main::form;
89   my %myconfig = %main::myconfig;
90   my $locale   = $main::locale;
91
92   $main::auth->assert('config');
93
94   $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
95
96   my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
97   if (my $error = AM->save_template($filename, $form->{content})) {
98     $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
99   }
100
101   $form->{edit} = 0;
102   display_template_form();
103
104   $main::lxdebug->leave_sub();
105 }
106
107 sub display_template_form {
108   $main::lxdebug->enter_sub();
109
110   my $form     = $main::form;
111   my %myconfig = %main::myconfig;
112   my $locale   = $main::locale;
113
114   $main::auth->assert('config');
115
116   $form->{"formname"} =~ s|.*/||;
117   my $format = $form->{"format"} eq "html" ? "html" : "tex";
118
119   $form->{"title"} = $form->{"type"} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
120   if ($form->{"format"}) {
121       $form->{"title"} = uc($form->{"format"}) . " - " . $form->{"title"};
122   }
123
124   my %options;
125
126   my @hidden = qw(type format);
127
128   if (($form->{"type"} ne "stylesheet") && !$form->{"edit"}) {
129     $options{"SHOW_EDIT_OPTIONS"} = 1;
130
131     #
132     # Setup "formname" selection
133     #
134
135     $form->get_lists("printers" => "ALL_PRINTERS",
136                      "languages" => "ALL_LANGUAGES",
137                      "dunning_configs" => "ALL_DUNNING_CONFIGS");
138
139     my %formname_setup =
140       (
141 #        "balance_sheet"       => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
142         "bin_list"            => $locale->text('Bin List'),
143         "bwa"                 => { "translation" => $locale->text('BWA'), "html" => 1 },
144         "check"               => { "translation" => $locale->text('Check'), "html" => 1 },
145         "credit_note"         => $locale->text('Credit Note'),
146         "income_statement"    => { "translation" => $locale->text('Income Statement'), "html" => 1 },
147         "invoice"             => $locale->text('Invoice'),
148         "pick_list"           => $locale->text('Pick List'),
149         "proforma"            => $locale->text('Proforma Invoice'),
150         "purchase_order"      => $locale->text('Purchase Order'),
151         "receipt"             => { "translation" => $locale->text('Receipt'), "tex" => 1 },
152         "request_quotation"   => $locale->text('RFQ'),
153         "sales_order"         => $locale->text('Confirmation'),
154         "sales_quotation"     => $locale->text('Quotation'),
155         "statement"           => $locale->text('Statement'),
156         "storno_invoice"      => $locale->text('Storno Invoice'),
157         "ustva-2004"          => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
158         "ustva-2005"          => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
159         "ustva-2006"          => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
160         "ustva-2007"          => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
161         "ustva"               => $locale->text("USTVA"),
162       );
163
164     my (@values, $file, $setup);
165
166     while (($file, $setup) = each(%formname_setup)) {
167       next if ref($setup) && !$setup->{$format};
168
169       push(@values,
170            { "value"   => $file,
171              "label"   => ref($setup) ? $setup->{"translation"} : $setup });
172     }
173
174     # "zahlungserinnerung" => $locale->text('Payment Reminder'),
175
176     foreach my $ref (@{ $form->{"ALL_DUNNING_CONFIGS"} }) {
177       next if !$ref->{"template"};
178
179       push(@values,
180            { "value" => $ref->{"template"},
181              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} },
182            { "value" => $ref->{"template"} . "_invoice",
183              "label" => $locale->text('Payment Reminder') . ": " . $ref->{"dunning_description"} . ' (' . $locale->text("Invoice for fees") . ')' });
184     }
185
186     @values = sort({ $a->{"label"} cmp $b->{"label"} } @values);
187
188     $options{FORMNAME} = [ @values ];
189
190     #
191     # Setup "language" selection
192     #
193
194     @values = ();
195
196     foreach my $item (@{ $form->{"ALL_LANGUAGES"} }) {
197       next unless ($item->{"template_code"});
198
199       push(@values,
200            { "value" => "$item->{id}--$item->{template_code}",
201              "label" => $item->{"description"} });
202     }
203
204     $options{LANGUAGE} = [ @values ];
205
206     #
207     # Setup "printer" selection
208     #
209
210     @values = ();
211
212     foreach my $item (@{ $form->{"ALL_PRINTERS"} }) {
213       next unless ($item->{"template_code"});
214
215       push(@values,
216            { "value" => "$item->{id}--$item->{template_code}",
217              "label" => $item->{"printer_description"} });
218     }
219
220     $options{PRINTER} = [ @values ];
221
222   } else {
223     push(@hidden, qw(formname language printer));
224   }
225
226   if ($form->{formname} || ($form->{type} eq "stylesheet")) {
227     $options{"SHOW_CONTENT"} = 1;
228
229     ($options{"filename"}, $options{"display_filename"})
230       = AM->prepare_template_filename(\%myconfig, $form);
231
232     ($options{"content"}, $options{"lines"})
233       = AM->load_template($options{"filename"});
234
235     $options{"CAN_EDIT"} = $form->{"edit"};
236
237     if ($form->{edit}) {
238       $form->{fokus} = "Form.content";
239
240     } else {
241       $options{"content"}                 = "\n\n" if (!$options{"content"});
242       $options{"SHOW_SECOND_EDIT_BUTTON"} = $options{"lines"} > 25;
243     }
244   }
245
246   $options{"HIDDEN"} = [ map(+{ "name" => $_, "value" => $form->{$_} }, @hidden) ];
247
248   $form->header;
249   print($form->parse_html_template("am/edit_templates", \%options));
250
251   $main::lxdebug->leave_sub();
252 }
253
254 1;