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