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