Bei Projekten ein Flag "aktiv" hinzugefĆ¼gt.
[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 # project administration
31 # partsgroup administration
32 #
33 #======================================================================
34
35 use SL::PE;
36
37 require "bin/mozilla/common.pl";
38
39 1;
40
41 # end of main
42
43 sub add {
44   $lxdebug->enter_sub();
45
46   $form->{title} = "Add";
47
48   # construct callback
49   $form->{callback} =
50     "$form->{script}?action=add&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}"
51     unless $form->{callback};
52
53   &{"form_$form->{type}_header"};
54   &{"form_$form->{type}_footer"};
55
56   $lxdebug->leave_sub();
57 }
58
59 sub edit {
60   $lxdebug->enter_sub();
61
62   $form->{title} = "Edit";
63
64   if ($form->{type} eq 'project') {
65     PE->get_project(\%myconfig, \%$form);
66   }
67   if ($form->{type} eq 'partsgroup') {
68     PE->get_partsgroup(\%myconfig, \%$form);
69   }
70   if ($form->{type} eq 'pricegroup') {
71     PE->get_pricegroup(\%myconfig, \%$form);
72   }
73   &{"form_$form->{type}_header"};
74   &{"form_$form->{type}_footer"};
75
76   $lxdebug->leave_sub();
77 }
78
79 sub search {
80   $lxdebug->enter_sub();
81
82   if ($form->{type} eq 'project') {
83     $report        = "project_report";
84     $sort          = 'projectnumber';
85     $form->{title} = $locale->text('Projects');
86
87     $number = qq|
88         <tr>
89           <th align=right width=1%>| . $locale->text('Number') . qq|</th>
90           <td>| . $cgi->textfield('-name' => 'projectnumber', '-size' => 20) . qq|</td>
91         </tr>
92         <tr>
93           <th align=right>| . $locale->text('Description') . qq|</th>
94           <td>| . $cgi->textfield('-name' => 'description', '-size' => 60) . qq|</td>
95         </tr>
96   <tr>
97     <th>&nbsp;</th>
98     <td>| .
99     $cgi->radio_group('-name' => 'active', '-default' => 'active',
100                       '-values' => ['active', 'inactive', 'both'],
101                       '-labels' => { 'active' => ' ' . $locale->text("Active"),
102                                      'inactive' => ' ' . $locale->text("Inactive"),
103                                      'both' => ' ' . $locale->text("Both") })
104     . qq|</td>
105   </tr>
106 |;
107
108   }
109   if ($form->{type} eq 'partsgroup') {
110     $report        = "partsgroup_report";
111     $sort          = 'partsgroup';
112     $form->{title} = $locale->text('Groups');
113
114     $number = qq|
115         <tr>
116           <th align=right width=1%>| . $locale->text('Group') . qq|</th>
117           <td><input name=partsgroup size=20></td>
118         </tr>
119 |;
120
121   }
122
123   # for pricesgroups
124   if ($form->{type} eq 'pricegroup') {
125     $report        = "pricegroup_report";
126     $sort          = 'pricegroup';
127     $form->{title} = $locale->text('Pricegroup');
128
129     $number = qq|
130         <tr>
131           <th align=right width=1%>| . $locale->text('Pricegroup') . qq|</th>
132           <td><input name=pricegroup size=20></td>
133         </tr>
134 |;
135
136   }
137
138   $form->header;
139
140   print qq|
141 <body>
142
143 <form method=post action=$form->{script}>
144
145 <input type=hidden name=sort value=$sort>
146 <input type=hidden name=type value=$form->{type}>
147
148 <table width=100%>
149   <tr>
150     <th class=listtop>$form->{title}</th>
151   </tr>
152   <tr height="5"></tr>
153   <tr>
154     <td>
155       <table width=100%>
156         $number
157         <tr>
158           <td></td>
159           <td><input name=status class=radio type=radio value=all checked>&nbsp;|
160     . $locale->text('All') . qq|
161           <input name=status class=radio type=radio value=orphaned>&nbsp;|
162     . $locale->text('Orphaned') . qq|</td>
163         </tr>
164       </table>
165     </td>
166   </tr>
167   <tr>
168     <td><hr size=3 noshade></td>
169   </tr>
170 </table>
171
172 <input type=hidden name=nextsub value=$report>
173
174 <input type=hidden name=path value=$form->{path}>
175 <input type=hidden name=login value=$form->{login}>
176 <input type=hidden name=password value=$form->{password}>
177
178 <br>
179 <input class=submit type=submit name=action value="|
180     . $locale->text('Continue') . qq|">
181 </form>
182
183 </body>
184 </html>
185 |;
186
187   $lxdebug->leave_sub();
188 }
189
190 sub project_report {
191   $lxdebug->enter_sub();
192
193   map { $form->{$_} = $form->unescape($form->{$_}) }
194     (projectnumber, description);
195   PE->projects(\%myconfig, \%$form);
196
197   $callback =
198     "$form->{script}?action=project_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}&active=" .
199     E($form->{active});
200   $href = $callback;
201
202   if ($form->{status} eq 'all') {
203     $option = $locale->text('All');
204   }
205   if ($form->{status} eq 'orphaned') {
206     $option .= $locale->text('Orphaned');
207   }
208   if ($form->{projectnumber}) {
209     $href     .= "&projectnumber=" . $form->escape($form->{projectnumber});
210     $callback .= "&projectnumber=$form->{projectnumber}";
211     $option   .=
212       "\n<br>" . $locale->text('Project') . " : $form->{projectnumber}";
213   }
214   if ($form->{description}) {
215     $href     .= "&description=" . $form->escape($form->{description});
216     $callback .= "&description=$form->{description}";
217     $option   .=
218       "\n<br>" . $locale->text('Description') . " : $form->{description}";
219   }
220
221   @column_index = qw(projectnumber description);
222
223   push(@column_index, "active") if ("both" eq $form->{active});
224
225   $column_header{projectnumber} =
226       qq|<th><a class=listheading href=$href&sort=projectnumber>|
227     . $locale->text('Number')
228     . qq|</a></th>|;
229   $column_header{description} =
230       qq|<th><a class=listheading href=$href&sort=description>|
231     . $locale->text('Description')
232     . qq|</a></th>|;
233   $column_header{active} =
234       qq|<th class="listheading">| . $locale->text('Active') . qq|</th>|;
235
236   $form->{title} = $locale->text('Projects');
237
238   $form->header;
239
240   print qq|
241 <body>
242
243 <table width=100%>
244   <tr>
245     <th class=listtop>$form->{title}</th>
246   </tr>
247   <tr height="5"></tr>
248   <tr>
249     <td>$option</td>
250   </tr>
251   <tr>
252     <td>
253       <table width=100%>
254         <tr class=listheading>
255 |;
256
257   map { print "$column_header{$_}\n" } @column_index;
258
259   print qq|
260         </tr>
261 |;
262
263   # escape callback
264   $form->{callback} = $callback .= "&sort=$form->{sort}";
265
266   # escape callback for href
267   $callback = $form->escape($callback);
268
269   foreach $ref (@{ $form->{project_list} }) {
270
271     $i++;
272     $i %= 2;
273
274     print qq|
275         <tr valign=top class=listrow$i>
276 |;
277
278     $column_data{projectnumber} =
279       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{projectnumber}</td>|;
280     $column_data{description} = qq|<td>$ref->{description}&nbsp;</td>|;
281     $column_data{active} =
282       qq|<td>| .
283       ($ref->{active} ? $locale->text("Yes") : $locale->text("No")) .
284       qq|</td>|;
285
286     map { print "$column_data{$_}\n" } @column_index;
287
288     print "
289         </tr>
290 ";
291   }
292
293   print qq|
294       </table>
295     </td>
296   </tr>
297   <tr>
298     <td><hr size=3 noshade></td>
299   </tr>
300 </table>
301
302 <br>
303 <form method=post action=$form->{script}>
304
305 <input name=callback type=hidden value="$form->{callback}">
306
307 <input type=hidden name=type value=$form->{type}>
308
309 <input type=hidden name=path value=$form->{path}>
310 <input type=hidden name=login value=$form->{login}>
311 <input type=hidden name=password value=$form->{password}>
312
313 <input class=submit type=submit name=action value="|
314     . $locale->text('Add') . qq|">
315
316   </form>
317
318 </body>
319 </html>
320 |;
321
322   $lxdebug->leave_sub();
323 }
324
325 sub form_project_header {
326   $lxdebug->enter_sub();
327
328   $form->{title} = $locale->text("$form->{title} Project");
329
330   # $locale->text('Add Project')
331   # $locale->text('Edit Project')
332
333   $form->{description} =~ s/\"/&quot;/g;
334
335   my $projectnumber =
336     $cgi->textfield('-name' => 'projectnumber', '-size' => 20,
337                     '-default' => $form->{projectnumber});
338
339   my $description;
340   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
341     $description =
342       $cgi->textarea('-name' => 'description', '-rows' => $rows, '-cols' => 60,
343                      '-style' => 'width: 100%', '-wrap' => 'soft',
344                      '-default' => $form->{description});
345   } else {
346     $description =
347       $cgi->textfield('-name' => 'description', '-size' => 60,
348                       '-default' => $form->{description});
349   }
350
351   my $active;
352   if ($form->{id}) {
353     $active =
354       qq|
355   <tr>
356     <th>&nbsp;</th>
357     <td>| .
358       $cgi->radio_group('-name' => 'active',
359                         '-values' => [1, 0],
360                         '-default' => $form->{active} * 1,
361                         '-labels' => { 1 => $locale->text("Active"),
362                                        0 => $locale->text("Inactive") })
363       . qq|</td>
364   </tr>
365 |;
366   }
367
368   $form->header;
369
370   print qq|
371 <body>
372
373 <form method=post action=$form->{script}>
374
375 <input type=hidden name=id value=$form->{id}>
376 <input type=hidden name=type value=project>
377
378 <table width=100%>
379   <tr>
380     <th class=listtop>$form->{title}</th>
381   </tr>
382   <tr height="5"></tr>
383   <tr>
384     <td>
385       <table>
386         <tr>
387           <th align=right>| . $locale->text('Number') . qq|</th>
388           <td>$projectnumber</td>
389         </tr>
390         <tr>
391           <th align=right>| . $locale->text('Description') . qq|</th>
392           <td>$description</td>
393         </tr>
394       $active
395       </table>
396     </td>
397   </tr>
398   <tr>
399     <td colspan=2><hr size=3 noshade></td>
400   </tr>
401 </table>
402 |;
403
404   $lxdebug->leave_sub();
405 }
406
407 sub form_project_footer {
408   $lxdebug->enter_sub();
409
410   print qq|
411
412 <input name=callback type=hidden value="$form->{callback}">
413
414 <input type=hidden name=path value=$form->{path}>
415 <input type=hidden name=login value=$form->{login}>
416 <input type=hidden name=password value=$form->{password}>
417
418 <br><input type=submit class=submit name=action value="|
419     . $locale->text('Save') . qq|">
420 |;
421
422   if ($form->{id} && $form->{orphaned}) {
423     print qq|
424 <input type=submit class=submit name=action value="|
425       . $locale->text('Delete') . qq|">|;
426   }
427
428   print qq|
429 </form>
430
431 </body>
432 </html>
433 |;
434
435   $lxdebug->leave_sub();
436 }
437
438 sub save {
439   $lxdebug->enter_sub();
440
441   if ($form->{type} eq 'project') {
442     $form->isblank("projectnumber", $locale->text('Project Number missing!'));
443     PE->save_project(\%myconfig, \%$form);
444     $form->redirect($locale->text('Project saved!'));
445   }
446   if ($form->{type} eq 'partsgroup') {
447     $form->isblank("partsgroup", $locale->text('Group missing!'));
448     PE->save_partsgroup(\%myconfig, \%$form);
449     $form->redirect($locale->text('Group saved!'));
450   }
451
452   # choice pricegroup and save
453   if ($form->{type} eq 'pricegroup') {
454     $form->isblank("pricegroup", $locale->text('Pricegroup missing!'));
455     PE->save_pricegroup(\%myconfig, \%$form);
456     $form->redirect($locale->text('Pricegroup saved!'));
457   }
458
459   $lxdebug->leave_sub();
460 }
461
462 sub delete {
463   $lxdebug->enter_sub();
464
465   PE->delete_tuple(\%myconfig, \%$form);
466
467   if ($form->{type} eq 'project') {
468     $form->redirect($locale->text('Project deleted!'));
469   }
470   if ($form->{type} eq 'partsgroup') {
471     $form->redirect($locale->text('Group deleted!'));
472   }
473   if ($form->{type} eq 'pricegroup') {
474     $form->redirect($locale->text('Pricegroup deleted!'));
475   }
476
477   $lxdebug->leave_sub();
478 }
479
480 sub continue { &{ $form->{nextsub} } }
481
482 sub partsgroup_report {
483   $lxdebug->enter_sub();
484
485   map { $form->{$_} = $form->unescape($form->{$_}) } (partsgroup);
486   PE->partsgroups(\%myconfig, \%$form);
487
488   $callback =
489     "$form->{script}?action=partsgroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
490
491   if ($form->{status} eq 'all') {
492     $option = $locale->text('All');
493   }
494   if ($form->{status} eq 'orphaned') {
495     $option .= $locale->text('Orphaned');
496   }
497   if ($form->{partsgroup}) {
498     $callback .= "&partsgroup=$form->{partsgroup}";
499     $option   .= "\n<br>" . $locale->text('Group') . " : $form->{partsgroup}";
500   }
501
502   @column_index = $form->sort_columns(qw(partsgroup));
503
504   $column_header{partsgroup} =
505     qq|<th class=listheading width=90%>| . $locale->text('Group') . qq|</th>|;
506
507   $form->{title} = $locale->text('Groups');
508
509   $form->header;
510
511   print qq|
512 <body>
513
514 <table width=100%>
515   <tr>
516     <th class=listtop>$form->{title}</th>
517   </tr>
518   <tr height="5"></tr>
519   <tr>
520     <td>$option</td>
521   </tr>
522   <tr>
523     <td>
524       <table width=100%>
525         <tr class=listheading>
526 |;
527
528   map { print "$column_header{$_}\n" } @column_index;
529
530   print qq|
531         </tr>
532 |;
533
534   # escape callback
535   $form->{callback} = $callback;
536
537   # escape callback for href
538   $callback = $form->escape($callback);
539
540   foreach $ref (@{ $form->{item_list} }) {
541
542     $i++;
543     $i %= 2;
544
545     print qq|
546         <tr valign=top class=listrow$i>
547 |;
548
549     $column_data{partsgroup} =
550       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{partsgroup}</td>|;
551     map { print "$column_data{$_}\n" } @column_index;
552
553     print "
554         </tr>
555 ";
556   }
557
558   print qq|
559       </table>
560     </td>
561   </tr>
562   <tr>
563     <td><hr size=3 noshade></td>
564   </tr>
565 </table>
566
567 <br>
568 <form method=post action=$form->{script}>
569
570 <input name=callback type=hidden value="$form->{callback}">
571
572 <input type=hidden name=type value=$form->{type}>
573
574 <input type=hidden name=path value=$form->{path}>
575 <input type=hidden name=login value=$form->{login}>
576 <input type=hidden name=password value=$form->{password}>
577
578 <input class=submit type=submit name=action value="|
579     . $locale->text('Add') . qq|">
580
581   </form>
582
583 </body>
584 </html>
585 |;
586
587   $lxdebug->leave_sub();
588 }
589
590 sub form_partsgroup_header {
591   $lxdebug->enter_sub();
592
593   $form->{title} = $locale->text("$form->{title} Group");
594
595   # $locale->text('Add Group')
596   # $locale->text('Edit Group')
597
598   $form->{partsgroup} =~ s/\"/&quot;/g;
599
600   $form->header;
601
602   print qq|
603 <body>
604
605 <form method=post action=$form->{script}>
606
607 <input type=hidden name=id value=$form->{id}>
608 <input type=hidden name=type value=$form->{type}>
609
610 <table width=100%>
611   <tr>
612     <th class=listtop>$form->{title}</th>
613   </tr>
614   <tr height="5"></tr>
615   <tr>
616     <td>
617       <table width=100%>
618         <tr>
619           <th align=right>| . $locale->text('Group') . qq|</th>
620
621           <td><input name=partsgroup size=30 value="$form->{partsgroup}"></td>
622         </tr>
623       </table>
624     </td>
625   </tr>
626   <tr>
627     <td colspan=2><hr size=3 noshade></td>
628   </tr>
629 </table>
630 |;
631
632   $lxdebug->leave_sub();
633 }
634
635 sub form_partsgroup_footer {
636   $lxdebug->enter_sub();
637
638   print qq|
639
640 <input name=callback type=hidden value="$form->{callback}">
641
642 <input type=hidden name=path value=$form->{path}>
643 <input type=hidden name=login value=$form->{login}>
644 <input type=hidden name=password value=$form->{password}>
645
646 <br><input type=submit class=submit name=action value="|
647     . $locale->text('Save') . qq|">
648 |;
649
650   if ($form->{id} && $form->{orphaned}) {
651     print qq|
652 <input type=submit class=submit name=action value="|
653       . $locale->text('Delete') . qq|">|;
654   }
655
656   print qq|
657 </form>
658
659 </body>
660 </html>
661 |;
662
663   $lxdebug->leave_sub();
664 }
665
666 #################################
667 # get pricesgroups and build up html-code
668 #
669 sub pricegroup_report {
670   $lxdebug->enter_sub();
671
672   map { $form->{$_} = $form->unescape($form->{$_}) } (pricegroup);
673   PE->pricegroups(\%myconfig, \%$form);
674
675   $callback =
676     "$form->{script}?action=pricegroup_report&type=$form->{type}&path=$form->{path}&login=$form->{login}&password=$form->{password}&status=$form->{status}";
677
678   if ($form->{status} eq 'all') {
679     $option = $locale->text('All');
680   }
681   if ($form->{status} eq 'orphaned') {
682     $option .= $locale->text('Orphaned');
683   }
684   if ($form->{pricegroup}) {
685     $callback .= "&pricegroup=$form->{pricegroup}";
686     $option   .=
687       "\n<br>" . $locale->text('Pricegroup') . " : $form->{pricegroup}";
688   }
689
690   @column_index = $form->sort_columns(qw(pricegroup));
691
692   $column_header{pricegroup} =
693       qq|<th class=listheading width=90%>|
694     . $locale->text('Pricegroup')
695     . qq|</th>|;
696
697   $form->{title} = $locale->text('Pricegroup');
698
699   $form->header;
700
701   print qq|
702 <body>
703
704 <table width=100%>
705   <tr>
706     <th class=listtop>$form->{title}</th>
707   </tr>
708   <tr height="5"></tr>
709   <tr>
710     <td>$option</td>
711   </tr>
712   <tr>
713     <td>
714       <table width=100%>
715         <tr class=listheading>
716 |;
717
718   map { print "$column_header{$_}\n" } @column_index;
719
720   print qq|
721         </tr>
722 |;
723
724   # escape callback
725   $form->{callback} = $callback;
726
727   # escape callback for href
728   $callback = $form->escape($callback);
729
730   foreach $ref (@{ $form->{item_list} }) {
731
732     $i++;
733     $i %= 2;
734
735     print qq|
736         <tr valign=top class=listrow$i>
737 |;
738     $column_data{pricegroup} =
739       qq|<td><a href=$form->{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{pricegroup}</td>|;
740
741     map { print "$column_data{$_}\n" } @column_index;
742
743     print "
744         </tr>
745 ";
746   }
747
748   print qq|
749       </table>
750     </td>
751   </tr>
752   <tr>
753     <td><hr size=3 noshade></td>
754   </tr>
755 </table>
756
757 <br>
758 <form method=post action=$form->{script}>
759
760 <input name=callback type=hidden value="$form->{callback}">
761
762 <input type=hidden name=type value=$form->{type}>
763
764 <input type=hidden name=path value=$form->{path}>
765 <input type=hidden name=login value=$form->{login}>
766 <input type=hidden name=password value=$form->{password}>
767
768 <input class=submit type=submit name=action value="|
769     . $locale->text('Add') . qq|">
770
771   </form>
772
773 </body>
774 </html>
775 |;
776
777   $lxdebug->leave_sub();
778 }
779
780 #######################
781 #build up pricegroup_header
782 #
783 sub form_pricegroup_header {
784   $lxdebug->enter_sub();
785
786   # $locale->text('Add Pricegroup')
787   # $locale->text('Edit Pricegroup')
788
789   $form->{title} = $locale->text("$form->{title} Pricegroup");
790
791   $form->{pricegroup} =~ s/\"/&quot;/g;
792
793   $form->header;
794
795   print qq|
796 <body>
797
798 <form method=post action=$form->{script}>
799
800 <input type=hidden name=id value=$form->{id}>
801 <input type=hidden name=type value=$form->{type}>
802
803 <table width=100%>
804   <tr>
805     <th class=listtop>$form->{title}</th>
806   </tr>
807   <tr height="5"></tr>
808   <tr>
809     <td>
810       <table width=100%>
811         <tr>
812           <th align=right>| . $locale->text('Preisgruppe') . qq|</th>
813           <td><input name=pricegroup size=30 value="$form->{pricegroup}"></td>
814         </tr>
815       </table>
816     </td>
817   </tr>
818   <tr>
819     <td colspan=2><hr size=3 noshade></td>
820   </tr>
821 </table>
822 |;
823
824   $lxdebug->leave_sub();
825 }
826 ######################
827 #build up pricegroup_footer
828 #
829 sub form_pricegroup_footer {
830   $lxdebug->enter_sub();
831
832   print qq|
833
834 <input name=callback type=hidden value="$form->{callback}">
835
836 <input type=hidden name=path value=$form->{path}>
837 <input type=hidden name=login value=$form->{login}>
838 <input type=hidden name=password value=$form->{password}>
839
840 <br><input type=submit class=submit name=action value="|
841     . $locale->text('Save') . qq|">
842 |;
843
844   if ($form->{id} && $form->{orphaned}) {
845     print qq|
846 <input type=submit class=submit name=action value="|
847       . $locale->text('Delete') . qq|">|;
848   }
849
850   print qq|
851 </form>
852
853 </body>
854 </html>
855 |;
856
857   $lxdebug->leave_sub();
858 }