pe strict
[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   $main::lxdebug->enter_sub();
46
47   $main::auth->assert('config');
48
49   my $form     = $main::form;
50
51   $form->{title} = "Add";
52
53   # construct callback
54   $form->{callback} =
55     "$form->{script}?action=add&type=$form->{type}"
56     unless $form->{callback};
57
58   call_sub("form_$form->{type}_header");
59   call_sub("form_$form->{type}_footer");
60
61   $main::lxdebug->leave_sub();
62 }
63
64 sub edit {
65   $main::lxdebug->enter_sub();
66
67   $main::auth->assert('config');
68
69   my $form     = $main::form;
70   my %myconfig = %main::myconfig;
71
72   # show history button
73   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
74   #/show hhistory button
75   $form->{title} = "Edit";
76
77   if ($form->{type} eq 'partsgroup') {
78     PE->get_partsgroup(\%myconfig, \%$form);
79   }
80   if ($form->{type} eq 'pricegroup') {
81     PE->get_pricegroup(\%myconfig, \%$form);
82   }
83   call_sub("form_$form->{type}_header");
84   call_sub("form_$form->{type}_footer");
85
86   $main::lxdebug->leave_sub();
87 }
88
89 sub search {
90   $main::lxdebug->enter_sub();
91
92   $main::auth->assert('config');
93
94   my $form     = $main::form;
95   my $locale   = $main::locale;
96
97   my ($report, $sort, $number);
98   if ($form->{type} eq 'partsgroup') {
99     $report        = "partsgroup_report";
100     $sort          = 'partsgroup';
101     $form->{title} = $locale->text('Groups');
102
103     $number = qq|
104         <tr>
105           <th align=right width=1%>| . $locale->text('Group') . qq|</th>
106           <td><input name=partsgroup size=20></td>
107         </tr>
108 |;
109
110   }
111
112   # for pricesgroups
113   if ($form->{type} eq 'pricegroup') {
114     $report        = "pricegroup_report";
115     $sort          = 'pricegroup';
116     $form->{title} = $locale->text('Pricegroup');
117
118     $number = qq|
119         <tr>
120           <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
121           <td><input name=pricegroup size=20></td>
122         </tr>
123 |;
124
125   }
126
127   $form->header;
128
129   print qq|
130 <body>
131
132 <form method=post action=$form->{script}>
133
134 <input type=hidden name=sort value=$sort>
135 <input type=hidden name=type value=$form->{type}>
136
137 <table width=100%>
138   <tr>
139     <th class=listtop>$form->{title}</th>
140   </tr>
141   <tr height="5"></tr>
142   <tr>
143     <td>
144       <table width=100%>
145         $number
146         <tr>
147           <td></td>
148           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
149     . $locale->text('All') . qq|
150           <input name=status class=radio type=radio value=orphaned>&nbsp;|
151     . $locale->text('Orphaned') . qq|</td>
152         </tr>
153       </table>
154     </td>
155   </tr>
156   <tr>
157     <td><hr size=3 noshade></td>
158   </tr>
159 </table>
160
161 <input type=hidden name=nextsub value=$report>
162
163 <br>
164 <input class=submit type=submit name=action value="|
165     . $locale->text('Continue') . qq|">
166 </form>
167
168 </body>
169 </html>
170 |;
171
172   $main::lxdebug->leave_sub();
173 }
174
175 sub save {
176   $main::lxdebug->enter_sub();
177
178   $main::auth->assert('config');
179
180   my $form     = $main::form;
181   my %myconfig = %main::myconfig;
182   my $locale   = $main::locale;
183
184   if ($form->{type} eq 'partsgroup') {
185     $form->isblank("partsgroup", $locale->text('Group missing!'));
186     PE->save_partsgroup(\%myconfig, \%$form);
187     $form->redirect($locale->text('Group saved!'));
188   }
189
190   # choice pricegroup and save
191   if ($form->{type} eq 'pricegroup') {
192     $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
193     PE->save_pricegroup(\%myconfig, \%$form);
194     $form->redirect($locale->text('Pricegroup saved!'));
195   }
196   # saving the history
197   if(!exists $form->{addition} && $form->{id} ne "") {
198     $form->{snumbers} = qq|projectnumber_| . $form->{projectnumber};
199         $form->{addition} = "SAVED";
200         $form->save_history($form->dbconnect(\%myconfig));
201   }
202   # /saving the history
203
204   $main::lxdebug->leave_sub();
205 }
206
207 sub delete {
208   $main::lxdebug->enter_sub();
209
210   $main::auth->assert('config');
211
212   my $form     = $main::form;
213   my %myconfig = %main::myconfig;
214   my $locale   = $main::locale;
215
216   PE->delete_tuple(\%myconfig, \%$form);
217
218   if ($form->{type} eq 'partsgroup') {
219     $form->redirect($locale->text('Group deleted!'));
220   }
221   if ($form->{type} eq 'pricegroup') {
222     $form->redirect($locale->text('Pricegroup deleted!'));
223   }
224   # saving the history
225   if(!exists $form->{addition}) {
226     $form->{snumbers} = qq|projectnumber_| . $form->{projectnumber};
227         $form->{addition} = "DELETED";
228         $form->save_history($form->dbconnect(\%myconfig));
229   }
230   # /saving the history
231   $main::lxdebug->leave_sub();
232 }
233
234 sub continue { call_sub($main::form->{"nextsub"}); }
235
236 sub partsgroup_report {
237   $main::lxdebug->enter_sub();
238
239   $main::auth->assert('config');
240
241   my $form     = $main::form;
242   my %myconfig = %main::myconfig;
243   my $locale   = $main::locale;
244
245   map { $form->{$_} = $form->unescape($form->{$_}) } qw(partsgroup);
246   PE->partsgroups(\%myconfig, \%$form);
247
248   my $callback =
249     "$form->{script}?action=partsgroup_report&type=$form->{type}&status=$form->{status}";
250
251   my ($option);
252   if ($form->{status} eq 'all') {
253     $option = $locale->text('All');
254   }
255   if ($form->{status} eq 'orphaned') {
256     $option .= $locale->text('Orphaned');
257   }
258   if ($form->{partsgroup}) {
259     $callback .= "&partsgroup=$form->{partsgroup}";
260     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
261   }
262
263   my @column_index = $form->sort_columns(qw(partsgroup));
264   my %column_header;
265   $column_header{partsgroup} =
266     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
267
268   $form->{title} = $locale->text('Groups');
269
270   $form->header;
271
272   print qq|
273 <body>
274
275 <table width=100%>
276   <tr>
277     <th class=listtop>$form->{title}</th>
278   </tr>
279   <tr height="5"></tr>
280   <tr>
281     <td>$option</td>
282   </tr>
283   <tr>
284     <td>
285       <table width=100%>
286         <tr class=listheading>
287 |;
288
289   map { print "$column_header{$_}\n" } @column_index;
290
291   print qq|
292         </tr>
293 |;
294
295   # escape callback
296   $form->{callback} = $callback;
297
298   # escape callback for href
299   $callback = $form->escape($callback);
300
301   my ($i, %column_data);
302   foreach my $ref (@{ $form->{item_list} }) {
303
304     $i++;
305     $i %= 2;
306
307     print qq|
308         <tr valign=top class=listrow$i>
309 |;
310
311     $column_data{partsgroup} =
312       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&callback=$callback>$ref->{partsgroup}</td>|;
313     map { print "$column_data{$_}\n" } @column_index;
314
315     print "
316         </tr>
317 ";
318   }
319
320   print qq|
321       </table>
322     </td>
323   </tr>
324   <tr>
325     <td><hr size=3 noshade></td>
326   </tr>
327 </table>
328
329 <br>
330 <form method=post action=$form->{script}>
331
332 <input name=callback type=hidden value="$form->{callback}">
333
334 <input type=hidden name=type value=$form->{type}>
335
336 <input class=submit type=submit name=action value="|
337     . $locale->text('Add') . qq|">
338
339   </form>
340
341 </body>
342 </html>
343 |;
344
345   $main::lxdebug->leave_sub();
346 }
347
348 sub form_partsgroup_header {
349   $main::lxdebug->enter_sub();
350
351   $main::auth->assert('config');
352
353   my $form     = $main::form;
354   my $locale   = $main::locale;
355
356   $form->{title} = $locale->text("$form->{title} Group");
357
358   # $locale->text('Add Group')
359   # $locale->text('Edit Group')
360
361   $form->{partsgroup} =~ s/\"/&quot;/g;
362
363   $form->header;
364
365   print qq|
366 <body>
367
368 <form method=post action=$form->{script}>
369
370 <input type=hidden name=id value=$form->{id}>
371 <input type=hidden name=type value=$form->{type}>
372
373 <table width=100%>
374   <tr>
375     <th class=listtop>$form->{title}</th>
376   </tr>
377   <tr height="5"></tr>
378   <tr>
379     <td>
380       <table width=100%>
381         <tr>
382           <th align=right>| . $locale->text('Group') . qq|</th>
383
384           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
385         </tr>
386       </table>
387     </td>
388   </tr>
389   <tr>
390     <td colspan=2><hr size=3 noshade></td>
391   </tr>
392 </table>
393 |;
394
395   $main::lxdebug->leave_sub();
396 }
397
398 sub form_partsgroup_footer {
399   $main::lxdebug->enter_sub();
400
401   $main::auth->assert('config');
402
403   my $form     = $main::form;
404   my $locale   = $main::locale;
405
406   print qq|
407
408 <input name=callback type=hidden value="$form->{callback}">
409
410 <br><input type=submit class=submit name=action value="|
411     . $locale->text('Save') . qq|">
412 |;
413
414   if ($form->{id} && $form->{orphaned}) {
415     print qq|
416 <input type=submit class=submit name=action value="|
417       . $locale->text('Delete') . qq|">|;
418   }
419
420 # button for saving history
421 print qq|
422         <input type=button onclick=set_history_window(|
423         . $form->{id}
424         . qq|); name=history id=history value=|
425         . $locale->text('history')
426         . qq|>|;
427 # /button for saving history
428   print qq|
429 </form>
430
431 </body>
432 </html>
433 |;
434
435   $main::lxdebug->leave_sub();
436 }
437
438 #################################
439 # get pricesgroups and build up html-code
440 #
441 sub pricegroup_report {
442   $main::lxdebug->enter_sub();
443
444   $main::auth->assert('config');
445
446   my $form     = $main::form;
447   my %myconfig = %main::myconfig;
448   my $locale   = $main::locale;
449
450   map { $form->{$_} = $form->unescape($form->{$_}) } qw(pricegroup);
451   PE->pricegroups(\%myconfig, \%$form);
452
453   my $callback =
454     "$form->{script}?action=pricegroup_report&type=$form->{type}&status=$form->{status}";
455
456   my $option;
457   if ($form->{status} eq 'all') {
458     $option = $locale->text('All');
459   }
460   if ($form->{status} eq 'orphaned') {
461     $option .= $locale->text('Orphaned');
462   }
463   if ($form->{pricegroup}) {
464     $callback .= "&pricegroup=$form->{pricegroup}";
465     $option   .=
466       "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
467   }
468
469   my @column_index = $form->sort_columns(qw(pricegroup));
470   my %column_header;
471   $column_header{pricegroup} =
472       qq|<th class=listheading width=90%>|
473     . $locale->text('Pricegroup')
474     . qq|</th>|;
475
476   $form->{title} = $locale->text('Pricegroup');
477
478   $form->header;
479
480   print qq|
481 <body>
482
483 <table width=100%>
484   <tr>
485     <th class=listtop>$form->{title}</th>
486   </tr>
487   <tr height="5"></tr>
488   <tr>
489     <td>$option</td>
490   </tr>
491   <tr>
492     <td>
493       <table width=100%>
494         <tr class=listheading>
495 |;
496
497   map { print "$column_header{$_}\n" } @column_index;
498
499   print qq|
500         </tr>
501 |;
502
503   # escape callback
504   $form->{callback} = $callback;
505
506   # escape callback for href
507   $callback = $form->escape($callback);
508
509   my ($i, %column_data);
510   foreach my $ref (@{ $form->{item_list} }) {
511
512     $i++;
513     $i %= 2;
514
515     print qq|
516         <tr valign=top class=listrow$i>
517 |;
518     $column_data{pricegroup} =
519       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&callback=$callback>$ref->{pricegroup}</td>|;
520
521     map { print "$column_data{$_}\n" } @column_index;
522
523     print "
524         </tr>
525 ";
526   }
527
528   print qq|
529       </table>
530     </td>
531   </tr>
532   <tr>
533     <td><hr size=3 noshade></td>
534   </tr>
535 </table>
536
537 <br>
538 <form method=post action=$form->{script}>
539
540 <input name=callback type=hidden value="$form->{callback}">
541
542 <input type=hidden name=type value=$form->{type}>
543
544 <input class=submit type=submit name=action value="|
545     . $locale->text('Add') . qq|">
546
547   </form>
548
549 </body>
550 </html>
551 |;
552
553   $main::lxdebug->leave_sub();
554 }
555
556 #######################
557 #build up pricegroup_header
558 #
559 sub form_pricegroup_header {
560   $main::lxdebug->enter_sub();
561
562   $main::auth->assert('config');
563
564   my $form     = $main::form;
565   my $locale   = $main::locale;
566
567   # $locale->text('Add Pricegroup')
568   # $locale->text('Edit Pricegroup')
569
570   $form->{title} = $locale->text("$form->{title} Pricegroup");
571
572   $form->{pricegroup} =~ s/\"/&quot;/g;
573
574   $form->header;
575
576   print qq|
577 <body>
578
579 <form method=post action=$form->{script}>
580
581 <input type=hidden name=id value=$form->{id}>
582 <input type=hidden name=type value=$form->{type}>
583
584 <table width=100%>
585   <tr>
586     <th class=listtop>$form->{title}</th>
587   </tr>
588   <tr height="5"></tr>
589   <tr>
590     <td>
591       <table width=100%>
592         <tr>
593           <th align=right>| . $locale->text('Preisgruppe') . qq|</th>
594           <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
595         </tr>
596       </table>
597     </td>
598   </tr>
599   <tr>
600     <td colspan=2><hr size=3 noshade></td>
601   </tr>
602 </table>
603 |;
604
605   $main::lxdebug->leave_sub();
606 }
607 ######################
608 #build up pricegroup_footer
609 #
610 sub form_pricegroup_footer {
611   $main::lxdebug->enter_sub();
612
613   $main::auth->assert('config');
614
615   my $form     = $main::form;
616   my $locale   = $main::locale;
617
618   print qq|
619
620 <input name=callback type=hidden value="$form->{callback}">
621
622 <br><input type=submit class=submit name=action value="|
623     . $locale->text('Save') . qq|">
624 |;
625
626   if ($form->{id} && $form->{orphaned}) {
627     print qq|
628 <input type=submit class=submit name=action value="|
629       . $locale->text('Delete') . qq|">|;
630   }
631
632 # button for saving history
633 print qq|
634         <input type=button onclick=set_history_window(|
635         . $form->{id}
636         . qq|); name=history id=history value=|
637         . $locale->text('history')
638         . qq|>|;
639 # /button for saving history
640   print qq|
641 </form>
642
643 </body>
644 </html>
645 |;
646
647   $main::lxdebug->leave_sub();
648 }