Umstellung der Benutzerverwaltung von Dateien im Verzeichnis "users" auf die Verwendu...
[kivitendo-erp.git] / bin / mozilla / am.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::Auth;
35 use SL::AM;
36 use SL::CA;
37 use SL::Form;
38 use SL::User;
39 use SL::USTVA;
40 use SL::Iconv;
41 use CGI::Ajax;
42 use CGI;
43
44 use Data::Dumper;
45
46 1;
47
48 require "bin/mozilla/common.pl";
49
50 # end of main
51
52 sub add      { call_sub("add_$form->{type}"); }
53 sub delete   { call_sub("delete_$form->{type}"); }
54 sub save     { call_sub("save_$form->{type}"); }
55 sub edit     { call_sub("edit_$form->{type}"); }
56 sub continue { call_sub($form->{"nextsub"}); }
57
58 sub add_account {
59   $lxdebug->enter_sub();
60
61   $auth->assert('config');
62
63   $form->{title}     = "Add";
64   $form->{charttype} = "A";
65   AM->get_account(\%myconfig, \%$form);
66
67   $form->{callback} = "am.pl?action=list_account" unless $form->{callback};
68
69   &account_header;
70   &form_footer;
71
72   $lxdebug->leave_sub();
73 }
74
75 sub edit_account {
76   $lxdebug->enter_sub();
77
78   $auth->assert('config');
79
80   $form->{title} = "Edit";
81   AM->get_account(\%myconfig, \%$form);
82
83   foreach my $item (split(/:/, $form->{link})) {
84     $form->{$item} = "checked";
85   }
86
87   &account_header;
88   &form_footer;
89
90   $lxdebug->leave_sub();
91 }
92
93 sub account_header {
94   $lxdebug->enter_sub();
95
96   $auth->assert('config');
97
98   if ( $form->{action} eq 'edit_account') {
99     $form->{account_exists} = '1';
100   } 
101   
102   $form->{title} = $locale->text("$form->{title} Account");
103
104   $form->{"$form->{charttype}_checked"} = "checked";
105   $form->{"$form->{category}_checked"}  = "checked";
106
107   $form->{select_tax} = "";
108
109   my @tax_report_pos = USTVA->report_variables({
110       myconfig   => \%myconfig, 
111       form       => $form, 
112       type       => '', 
113       attribute  => 'position',
114       calc       => '',
115   });
116
117   if (@{ $form->{TAXKEY} }) {
118     foreach my $item (@{ $form->{TAXKEY} }) {
119       $item->{rate} = $item->{rate} * 100 . '%';
120     }
121
122     # Fill in empty row for new Taxkey
123     $newtaxkey_ref = {
124       id             => '',
125       chart_id       => '',
126       accno          => '',
127       tax_id         => '',
128       taxdescription => '',
129       rate           => '',
130       taxkey_id      => '',
131       pos_ustva      => '',
132       startdate      => '',
133     };
134
135     push @{ $form->{ACCOUNT_TAXKEYS} }, $newtaxkey_ref;
136
137     my $i = 0;
138     foreach my $taxkey_used (@{ $form->{ACCOUNT_TAXKEYS} } ) {
139
140       # Fill in a runningnumber
141       $form->{ACCOUNT_TAXKEYS}[$i]{runningnumber} = $i;
142
143       # Fill in the Taxkeys as select options
144       foreach my $item (@{ $form->{TAXKEY} }) {
145         if ($item->{id} == $taxkey_used->{tax_id}) {
146           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
147             qq|<option value="$item->{id}" selected="selected">|
148             . sprintf("%.2d", $item->{taxkey}) 
149             . qq|. $item->{taxdescription} ($item->{rate}) |
150             . $locale->text('Tax-o-matic Account') 
151             . qq|: $item->{chart_accno}\n|;
152         } 
153         else {
154           $form->{ACCOUNT_TAXKEYS}[$i]{selecttaxkey} .=
155             qq|<option value="$item->{id}">|
156             . sprintf("%.2d", $item->{taxkey}) 
157             . qq|. $item->{taxdescription} ($item->{rate}) |
158             . $locale->text('Tax-o-matic Account')
159             . qq|: $item->{chart_accno}\n|;
160         }
161
162       }
163       
164       # Fill in the USTVA Numbers as select options
165       foreach my $item ( '', sort({ $a cmp $b } @tax_report_pos) ) {
166         if ($item eq ''){
167           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="" selected="selected">-\n|;
168         } 
169         elsif ( $item eq $taxkey_used->{pos_ustva} ) {
170           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item" selected="selected">$item\n|;
171         }
172         else {
173           $form->{ACCOUNT_TAXKEYS}[$i]{select_tax} .= qq|<option value="$item">$item\n|;
174         }
175
176       }      
177
178       $i++;
179     }
180   }
181
182   # Newaccount Folgekonto 
183   if (@{ $form->{NEWACCOUNT} }) {
184     if (!$form->{new_chart_valid}) {
185       $form->{selectnewaccount} = qq|<option value=""> |. $locale->text('None') .q|</option>|;
186     }
187     foreach $item (@{ $form->{NEWACCOUNT} }) {
188       if ($item->{id} == $form->{new_chart_id}) {
189         $form->{selectnewaccount} .=
190           qq|<option value="$item->{id}" selected>$item->{accno}--$item->{description}</option>|;
191       } elsif (!$form->{new_chart_valid}) {
192         $form->{selectnewaccount} .=
193           qq|<option value="$item->{id}">$item->{accno}--$item->{description}</option>|;
194       }
195
196     }
197   }
198
199   $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
200   %eur = (1  => "Umsatzerlöse",
201           2  => "sonstige Erlöse",
202           3  => "Privatanteile",
203           4  => "Zinserträge",
204           5  => "Ausserordentliche Erträge",
205           6  => "Vereinnahmte Umsatzst.",
206           7  => "Umsatzsteuererstattungen",
207           8  => "Wareneingänge",
208           9  => "Löhne und Gehälter",
209           10 => "Gesetzl. sozialer Aufw.",
210           11 => "Mieten",
211           12 => "Gas, Strom, Wasser",
212           13 => "Instandhaltung",
213           14 => "Steuern, Versich., Beiträge",
214           15 => "Kfz-Steuern",
215           16 => "Kfz-Versicherungen",
216           17 => "Sonst. Fahrtkosten",
217           18 => "Werbe- und Reisekosten",
218           19 => "Instandhaltung u. Werkzeuge",
219           20 => "Fachzeitschriften, Bücher",
220           21 => "Miete für Einrichtungen",
221           22 => "Rechts- und Beratungskosten",
222           23 => "Bürobedarf, Porto, Telefon",
223           24 => "Sonstige Aufwendungen",
224           25 => "Abschreibungen auf Anlagever.",
225           26 => "Abschreibungen auf GWG",
226           27 => "Vorsteuer",
227           28 => "Umsatzsteuerzahlungen",
228           29 => "Zinsaufwand",
229           30 => "Ausserordentlicher Aufwand",
230           31 => "Betriebliche Steuern");
231   foreach $item (sort({ $a <=> $b } keys(%eur))) {
232     my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item}));
233     if ($item == $form->{pos_eur}) {
234       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
235     } else {
236       $select_eur .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
237     }
238
239   }
240
241   $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
242
243   %bwapos = (1  => 'Umsatzerlöse',
244              2  => 'Best.Verdg.FE/UE',
245              3  => 'Aktiv.Eigenleistung',
246              4  => 'Mat./Wareneinkauf',
247              5  => 'So.betr.Erlöse',
248              10 => 'Personalkosten',
249              11 => 'Raumkosten',
250              12 => 'Betriebl.Steuern',
251              13 => 'Vers./Beiträge',
252              14 => 'Kfz.Kosten o.St.',
253              15 => 'Werbe-Reisek.',
254              16 => 'Kosten Warenabgabe',
255              17 => 'Abschreibungen',
256              18 => 'Rep./instandhlt.',
257              19 => 'Übrige Steuern',
258              20 => 'Sonst.Kosten',
259              30 => 'Zinsauwand',
260              31 => 'Sonst.neutr.Aufw.',
261              32 => 'Zinserträge',
262              33 => 'Sonst.neutr.Ertrag',
263              34 => 'Verr.kalk.Kosten',
264              35 => 'Steuern Eink.u.Ertr.');
265   foreach $item (sort({ $a <=> $b } keys %bwapos)) {
266     my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item}));
267     if ($item == $form->{pos_bwa}) {
268       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
269     } else {
270       $select_bwa .= qq|<option value="$item">|. sprintf("%.2d", $item) .qq|. $text\n|;
271     }
272
273   }
274
275 # Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
276   $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
277   foreach $item ((1, 2, 3, 4)) {
278     if ($item == $form->{pos_bilanz}) {
279       $select_bilanz .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|.\n|;
280     } else {
281       $select_bilanz .= qq|<option value=$item>|. sprintf("%.2d", $item) .qq|.\n|;
282     }
283
284   }
285
286   # this is for our parser only! Do not remove.
287   # type=submit $locale->text('Add Account')
288   # type=submit $locale->text('Edit Account')
289   
290   $form->{type} = "account";
291
292   # preselections category
293  
294   $select_category = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
295
296   %category = (
297       'A'  => $locale->text('Asset'),
298       'L'  => $locale->text('Liability'),
299       'Q'  => $locale->text('Equity'),
300       'I'  => $locale->text('Revenue'),      
301       'E'  => $locale->text('Expense'),
302       'C'  => $locale->text('Costs'),
303   );
304   foreach $item ( sort({ $a <=> $b } keys %category) ) {
305     if ($item eq $form->{category}) {
306       $select_category .= qq|<option value="$item" selected="selected">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
307     } else {
308       $select_category .= qq|<option value="$item">$category{$item} (|. sprintf("%s", $item) .qq|)\n|;
309     }
310
311   }
312   
313   # preselection chart type
314   my $select_charttype = q{};
315
316   my %charttype = (
317       'A'  => $locale->text('Account'),
318       'H'  => $locale->text('Header'),
319   );
320   
321   foreach $item ( sort({ $a <=> $b } keys %charttype) ) {
322     if ($item eq $form->{charttype}) {
323       $select_charttype .= qq|<option value="$item" selected="selected">$charttype{$item}\n|;
324
325     } else {
326       $select_charttype .= qq|<option value="$item">$charttype{$item}\n|;
327     }
328
329   }
330
331   my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":"";
332   
333   $form->header();
334   
335   my $parameters_ref = {
336     ChartTypeIsAccount         => $ChartTypeIsAccount,
337     select_category            => $select_category,
338     select_charttype           => $select_charttype,
339     newaccount                 => $newaccount,
340     checked                    => $checked,
341     select_bwa                 => $select_bwa,
342     select_bilanz              => $select_bilanz,
343     select_eur                 => $select_eur,
344   };
345   
346   # Ausgabe des Templates
347   print($form->parse_html_template('am/edit_accounts', $parameters_ref));
348
349
350   $lxdebug->leave_sub();
351 }
352
353 sub form_footer {
354   $lxdebug->enter_sub();
355
356   $auth->assert('config');
357
358   print qq|
359
360 <input name=callback type=hidden value="| . H($form->{callback}) . qq|">
361
362 <br>|;
363   if ((!$form->{id}) || ($form->{id} && $form->{orphaned}) || (($form->{type} eq "account") && (!$form->{new_chart_valid}))) {
364     print qq|
365 <input type=submit class=submit name=action value="|
366     . $locale->text('Save') . qq|">
367 |;
368 }
369
370   if ($form->{id} && $form->{orphaned}) {
371     print qq|<input type=submit class=submit name=action value="|
372       . $locale->text('Delete') . qq|">|;
373   }
374
375   print qq|
376 </form>
377
378 </body>
379 </html>
380 |;
381
382   $lxdebug->leave_sub();
383 }
384
385 sub save_account {
386   $lxdebug->enter_sub();
387
388   $auth->assert('config');
389
390   $form->isblank("accno",       $locale->text('Account Number missing!'));
391   $form->isblank("description", $locale->text('Account Description missing!'));
392   
393   if ($form->{charttype} eq 'A'){
394     $form->isblank("category",  $locale->text('Account Type missing!'));
395   }
396
397   $form->redirect($locale->text('Account saved!'))
398     if (AM->save_account(\%myconfig, \%$form));
399   $form->error($locale->text('Cannot save account!'));
400
401   $lxdebug->leave_sub();
402 }
403
404 sub list_account {
405   $lxdebug->enter_sub();
406
407   $auth->assert('config');
408
409   $form->{callback}     = build_std_url('action=list_account');
410   my $link_edit_account = build_std_url('action=edit_account', 'callback');
411
412   CA->all_accounts(\%myconfig, \%$form);
413
414   foreach $ca (@{ $form->{CA} }) {
415
416     $ca->{debit}  = "";
417     $ca->{credit} = "";
418
419     if ($ca->{amount} > 0) {
420       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2);
421     }
422     if ($ca->{amount} < 0) {
423       $ca->{debit} = $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2);
424     }
425     $ca->{heading}   = ( $ca->{charttype} eq 'H' ) ? 1:''; 
426     $ca->{link_edit_account} = $link_edit_account . '&id=' . E($ca->{id});
427   }
428   
429   # Ajax 
430   my $pjx = new CGI::Ajax('list_account_details' => build_std_url('action=list_account_details'));
431
432   # Eneable AJAX debuging
433   #$pjx->DEBUG(1);
434   #$pjx->JSDEBUG(1);
435     
436   push(@ { $form->{AJAX} }, $pjx);
437
438   $form->{stylesheets} = "list_accounts.css";
439   $form->{title}       = $locale->text('Chart of Accounts');
440
441   $form->header;
442   
443   
444   my $parameters_ref = {
445   #   hidden_variables                => $_hidden_variables_ref,
446   };
447   
448   # Ausgabe des Templates
449   print($form->parse_html_template('am/list_accounts', $parameters_ref));
450   
451   $lxdebug->leave_sub();
452
453 }
454
455
456 sub list_account_details {
457 # Ajax Funktion aus list_account_details
458   $lxdebug->enter_sub();
459
460   $auth->assert('config');
461
462   my $chart_id = $form->{args};
463
464   CA->all_accounts(\%myconfig, \%$form, $chart_id);
465
466   foreach $ca (@{ $form->{CA} }) {
467
468     $ca->{debit}  = "&nbsp;";
469     $ca->{credit} = "&nbsp;";
470
471     if ($ca->{amount} > 0) {
472       $ca->{credit} =
473         $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
474     }
475     if ($ca->{amount} < 0) {
476       $ca->{debit} =
477         $form->format_amount(\%myconfig, -1 * $ca->{amount}, 2, "&nbsp;");
478     }
479
480     my @links = split( q{:}, $ca->{link});
481
482     $ca->{link} = q{};
483
484     foreach my $link (@links){
485       $link =    ( $link eq 'AR')             ? $locale->text('Account Link AR')
486                : ( $link eq 'AP')             ? $locale->text('Account Link AP')
487                : ( $link eq 'IC')             ? $locale->text('Account Link IC')
488                : ( $link eq 'AR_amount' )     ? $locale->text('Account Link AR_amount')
489                : ( $link eq 'AR_paid' )       ? $locale->text('Account Link AR_paid')
490                : ( $link eq 'AR_tax' )        ? $locale->text('Account Link AR_tax')
491                : ( $link eq 'AP_amount' )     ? $locale->text('Account Link AP_amount')
492                : ( $link eq 'AP_paid' )       ? $locale->text('Account Link AP_paid')
493                : ( $link eq 'AP_tax' )        ? $locale->text('Account Link AP_tax')
494                : ( $link eq 'IC_sale' )       ? $locale->text('Account Link IC_sale')
495                : ( $link eq 'IC_cogs' )       ? $locale->text('Account Link IC_cogs')
496                : ( $link eq 'IC_taxpart' )    ? $locale->text('Account Link IC_taxpart')
497                : ( $link eq 'IC_income' )     ? $locale->text('Account Link IC_income')
498                : ( $link eq 'IC_expense' )    ? $locale->text('Account Link IC_expense')
499                : ( $link eq 'IC_taxservice' ) ? $locale->text('Account Link IC_taxservice')
500 #               : ( $link eq 'CT_tax' )        ? $locale->text('Account Link CT_tax')
501                : $locale->text('Unknown Link') . ': ' . $link;
502       $ca->{link} .= ($link ne '') ?  "[$link] ":'';
503     }
504
505     $ca->{category} = ($ca->{category} eq 'A') ? $locale->text('Account Category A')
506                     : ($ca->{category} eq 'E') ? $locale->text('Account Category E')
507                     : ($ca->{category} eq 'L') ? $locale->text('Account Category L')
508                     : ($ca->{category} eq 'I') ? $locale->text('Account Category I')
509                     : ($ca->{category} eq 'Q') ? $locale->text('Account Category Q')
510                     : ($ca->{category} eq 'C') ? $locale->text('Account Category C')
511                     : ($ca->{category} eq 'G') ? $locale->text('Account Category G')
512                     : $locale->text('Unknown Category') . ': ' . $ca->{category};
513   }
514
515   $form->{title} = $locale->text('Chart of Accounts');
516   $form->header();
517
518   print $form->parse_html_template('am/list_account_details');
519
520   $lxdebug->leave_sub();
521
522 }
523
524 sub delete_account {
525   $lxdebug->enter_sub();
526
527   $auth->assert('config');
528
529   $form->{title} = $locale->text('Delete Account');
530
531   foreach $id (
532     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
533     ) {
534     if ($form->{id} == $form->{$id}) {
535       $form->error($locale->text('Cannot delete default account!'));
536     }
537   }
538
539   $form->redirect($locale->text('Account deleted!'))
540     if (AM->delete_account(\%myconfig, \%$form));
541   $form->error($locale->text('Cannot delete account!'));
542
543   $lxdebug->leave_sub();
544 }
545
546 sub add_department {
547   $lxdebug->enter_sub();
548
549   $auth->assert('config');
550
551   $form->{title} = "Add";
552   $form->{role}  = "P";
553
554   $form->{callback} = "am.pl?action=add_department" unless $form->{callback};
555
556   &department_header;
557   &form_footer;
558
559   $lxdebug->leave_sub();
560 }
561
562 sub edit_department {
563   $lxdebug->enter_sub();
564
565   $auth->assert('config');
566
567   $form->{title} = "Edit";
568
569   AM->get_department(\%myconfig, \%$form);
570
571   &department_header;
572   &form_footer;
573
574   $lxdebug->leave_sub();
575 }
576
577 sub list_department {
578   $lxdebug->enter_sub();
579
580   $auth->assert('config');
581
582   AM->departments(\%myconfig, \%$form);
583
584   $form->{callback} = "am.pl?action=list_department";
585
586   $callback = $form->escape($form->{callback});
587
588   $form->{title} = $locale->text('Departments');
589
590   @column_index = qw(description cost profit);
591
592   $column_header{description} =
593       qq|<th class=listheading width=90%>|
594     . $locale->text('Description')
595     . qq|</th>|;
596   $column_header{cost} =
597       qq|<th class=listheading nowrap>|
598     . $locale->text('Cost Center')
599     . qq|</th>|;
600   $column_header{profit} =
601       qq|<th class=listheading nowrap>|
602     . $locale->text('Profit Center')
603     . qq|</th>|;
604
605   $form->header;
606
607   print qq|
608 <body>
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 class=listheading>
619 |;
620
621   map { print "$column_header{$_}\n" } @column_index;
622
623   print qq|
624         </tr>
625 |;
626
627   foreach $ref (@{ $form->{ALL} }) {
628
629     $i++;
630     $i %= 2;
631
632     print qq|
633         <tr valign=top class=listrow$i>
634 |;
635
636     $costcenter   = ($ref->{role} eq "C") ? "X" : "";
637     $profitcenter = ($ref->{role} eq "P") ? "X" : "";
638
639     $column_data{description} =
640       qq|<td><a href="am.pl?action=edit_department&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
641     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
642     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
643
644     map { print "$column_data{$_}\n" } @column_index;
645
646     print qq|
647         </tr>
648 |;
649   }
650
651   print qq|
652       </table>
653     </td>
654   </tr>
655   <tr>
656   <td><hr size=3 noshade></td>
657   </tr>
658 </table>
659
660 <br>
661 <form method=post action=am.pl>
662
663 <input name=callback type=hidden value="$form->{callback}">
664
665 <input type=hidden name=type value=department>
666
667 <input class=submit type=submit name=action value="|
668     . $locale->text('Add') . qq|">
669
670   </form>
671
672   </body>
673   </html>
674 |;
675
676   $lxdebug->leave_sub();
677 }
678
679 sub department_header {
680   $lxdebug->enter_sub();
681
682   $auth->assert('config');
683
684   $form->{title} = $locale->text("$form->{title} Department");
685
686   # $locale->text('Add Department')
687   # $locale->text('Edit Department')
688
689   $form->{description} =~ s/\"/&quot;/g;
690
691   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
692     $description =
693       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
694   } else {
695     $description =
696       qq|<input name=description size=60 value="$form->{description}">|;
697   }
698
699   $costcenter   = "checked" if $form->{role} eq "C";
700   $profitcenter = "checked" if $form->{role} eq "P";
701
702   $form->header;
703
704   print qq|
705 <body>
706
707 <form method=post action=am.pl>
708
709 <input type=hidden name=id value=$form->{id}>
710 <input type=hidden name=type value=department>
711
712 <table width=100%>
713   <tr>
714     <th class=listtop colspan=2>$form->{title}</th>
715   </tr>
716   <tr height="5"></tr>
717   <tr>
718     <th align=right>| . $locale->text('Description') . qq|</th>
719     <td>$description</td>
720   </tr>
721   <tr>
722     <td></td>
723     <td><input type=radio style=radio name=role value="C" $costcenter> |
724     . $locale->text('Cost Center') . qq|
725         <input type=radio style=radio name=role value="P" $profitcenter> |
726     . $locale->text('Profit Center') . qq|
727     </td>
728   <tr>
729     <td colspan=2><hr size=3 noshade></td>
730   </tr>
731 </table>
732 |;
733
734   $lxdebug->leave_sub();
735 }
736
737 sub save_department {
738   $lxdebug->enter_sub();
739
740   $auth->assert('config');
741
742   $form->isblank("description", $locale->text('Description missing!'));
743   AM->save_department(\%myconfig, \%$form);
744   $form->redirect($locale->text('Department saved!'));
745
746   $lxdebug->leave_sub();
747 }
748
749 sub delete_department {
750   $lxdebug->enter_sub();
751
752   $auth->assert('config');
753
754   AM->delete_department(\%myconfig, \%$form);
755   $form->redirect($locale->text('Department deleted!'));
756
757   $lxdebug->leave_sub();
758 }
759
760 sub add_lead {
761   $lxdebug->enter_sub();
762
763   $auth->assert('config');
764
765   $form->{title} = "Add";
766
767   $form->{callback} = "am.pl?action=add_lead" unless $form->{callback};
768
769   &lead_header;
770   &form_footer;
771
772   $lxdebug->leave_sub();
773 }
774
775 sub edit_lead {
776   $lxdebug->enter_sub();
777
778   $auth->assert('config');
779
780   $form->{title} = "Edit";
781
782   AM->get_lead(\%myconfig, \%$form);
783
784   &lead_header;
785
786   $form->{orphaned} = 1;
787   &form_footer;
788
789   $lxdebug->leave_sub();
790 }
791
792 sub list_lead {
793   $lxdebug->enter_sub();
794
795   $auth->assert('config');
796
797   AM->lead(\%myconfig, \%$form);
798
799   $form->{callback} = "am.pl?action=list_lead";
800
801   $callback = $form->escape($form->{callback});
802
803   $form->{title} = $locale->text('Lead');
804
805   @column_index = qw(description cost profit);
806
807   $column_header{description} =
808       qq|<th class=listheading width=100%>|
809     . $locale->text('Description')
810     . qq|</th>|;
811
812   $form->header;
813
814   print qq|
815 <body>
816
817 <table width=100%>
818   <tr>
819     <th class=listtop>$form->{title}</th>
820   </tr>
821   <tr height="5"></tr>
822   <tr class=listheading>
823 |;
824
825   map { print "$column_header{$_}\n" } @column_index;
826
827   print qq|
828         </tr>
829 |;
830
831   foreach $ref (@{ $form->{ALL} }) {
832
833     $i++;
834     $i %= 2;
835
836     print qq|
837         <tr valign=top class=listrow$i>
838 |;
839
840         $lead = $ref->{lead};
841         
842     $column_data{description} = qq|<td><a href="am.pl?action=edit_lead&id=$ref->{id}&callback=$callback">$ref->{lead}</td>|;
843
844     map { print "$column_data{$_}\n" } @column_index;
845
846     print qq|
847         </tr>
848 |;
849   }
850
851   print qq|
852   <tr>
853   <td><hr size=3 noshade></td>
854   </tr>
855 </table>
856
857 <br>
858 <form method=post action=am.pl>
859
860 <input name=callback type=hidden value="$form->{callback}">
861
862 <input type=hidden name=type value=lead>
863
864 <input class=submit type=submit name=action value="|
865     . $locale->text('Add') . qq|">
866
867   </form>
868
869   </body>
870   </html>
871 |;
872
873   $lxdebug->leave_sub();
874 }
875
876 sub lead_header {
877   $lxdebug->enter_sub();
878
879   $auth->assert('config');
880
881   $form->{title} = $locale->text("$form->{title} Lead");
882
883   # $locale->text('Add Lead')
884   # $locale->text('Edit Lead')
885
886   $form->{description} =~ s/\"/&quot;/g;
887
888   $description =
889       qq|<input name=description size=50 value="$form->{lead}">|;
890
891   $form->header;
892
893   print qq|
894 <body>
895
896 <form method=post action=am.pl>
897
898 <input type=hidden name=id value=$form->{id}>
899 <input type=hidden name=type value=lead>
900
901 <table width=100%>
902   <tr>
903     <th class=listtop colspan=2>$form->{title}</th>
904   </tr>
905   <tr height="5"></tr>
906   <tr>
907     <th align=right>| . $locale->text('Description') . qq|</th>
908     <td>$description</td>
909   </tr>
910     <td colspan=2><hr size=3 noshade></td>
911   </tr>
912 </table>
913 |;
914
915   $lxdebug->leave_sub();
916 }
917
918 sub save_lead {
919   $lxdebug->enter_sub();
920
921   $auth->assert('config');
922
923   $form->isblank("description", $locale->text('Description missing!'));
924   AM->save_lead(\%myconfig, \%$form);
925   $form->redirect($locale->text('lead saved!'));
926
927   $lxdebug->leave_sub();
928 }
929
930 sub delete_lead {
931   $lxdebug->enter_sub();
932
933   $auth->assert('config');
934
935   AM->delete_lead(\%myconfig, \%$form);
936   $form->redirect($locale->text('lead deleted!'));
937
938   $lxdebug->leave_sub();
939 }
940
941 sub add_business {
942   $lxdebug->enter_sub();
943
944   $auth->assert('config');
945
946   $form->{title} = "Add";
947
948   $form->{callback} = "am.pl?action=add_business" unless $form->{callback};
949
950   &business_header;
951   &form_footer;
952
953   $lxdebug->leave_sub();
954 }
955
956 sub edit_business {
957   $lxdebug->enter_sub();
958
959   $form->{title} = "Edit";
960
961   AM->get_business(\%myconfig, \%$form);
962
963   &business_header;
964
965   $form->{orphaned} = 1;
966   &form_footer;
967
968   $lxdebug->leave_sub();
969 }
970
971 sub list_business {
972   $lxdebug->enter_sub();
973
974   $auth->assert('config');
975
976   AM->business(\%myconfig, \%$form);
977
978   $form->{callback} = "am.pl?action=list_business";
979
980   $callback = $form->escape($form->{callback});
981
982   $form->{title} = $locale->text('Type of Business');
983
984   @column_index = qw(description discount customernumberinit);
985
986   $column_header{description} =
987       qq|<th class=listheading width=60%>|
988     . $locale->text('Description')
989     . qq|</th>|;
990   $column_header{discount} =
991       qq|<th class=listheading width=10%>|
992     . $locale->text('Discount')
993     . qq| %</th>|;
994   $column_header{customernumberinit} =
995       qq|<th class=listheading>|
996     . $locale->text('Customernumberinit')
997     . qq|</th>|;
998
999   $form->header;
1000
1001   print qq|
1002 <body>
1003
1004 <table width=100%>
1005   <tr>
1006     <th class=listtop>$form->{title}</th>
1007   </tr>
1008   <tr height="5"></tr>
1009   <tr>
1010     <td>
1011       <table width=100%>
1012         <tr class=listheading>
1013 |;
1014
1015   map { print "$column_header{$_}\n" } @column_index;
1016
1017   print qq|
1018         </tr>
1019 |;
1020
1021   foreach $ref (@{ $form->{ALL} }) {
1022
1023     $i++;
1024     $i %= 2;
1025
1026     print qq|
1027         <tr valign=top class=listrow$i>
1028 |;
1029
1030     $discount =
1031       $form->format_amount(\%myconfig, $ref->{discount} * 100);
1032     $description =
1033       $ref->{description};
1034     $column_data{description} = qq|<td><a href="am.pl?action=edit_business&id=$ref->{id}&callback=$callback">$description</td>|;
1035     $column_data{discount}           = qq|<td align=right>$discount</td>|;
1036     $column_data{customernumberinit} =
1037       qq|<td align=right>$ref->{customernumberinit}</td>|;
1038
1039     map { print "$column_data{$_}\n" } @column_index;
1040
1041     print qq|
1042         </tr>
1043 |;
1044   }
1045
1046   print qq|
1047       </table>
1048     </td>
1049   </tr>
1050   <tr>
1051   <td><hr size=3 noshade></td>
1052   </tr>
1053 </table>
1054
1055 <br>
1056 <form method=post action=am.pl>
1057
1058 <input name=callback type=hidden value="$form->{callback}">
1059
1060 <input type=hidden name=type value=business>
1061
1062 <input class=submit type=submit name=action value="|
1063     . $locale->text('Add') . qq|">
1064
1065   </form>
1066
1067   </body>
1068   </html>
1069 |;
1070
1071   $lxdebug->leave_sub();
1072 }
1073
1074 sub business_header {
1075   $lxdebug->enter_sub();
1076
1077   $auth->assert('config');
1078
1079   $form->{title}    = $locale->text("$form->{title} Business");
1080
1081   # $locale->text('Add Business')
1082   # $locale->text('Edit Business')
1083
1084   $form->{description} =~ s/\"/&quot;/g;
1085   $form->{discount} =
1086     $form->format_amount(\%myconfig, $form->{discount} * 100);
1087
1088   $form->header;
1089
1090   print qq|
1091 <body>
1092
1093 <form method=post action=am.pl>
1094
1095 <input type=hidden name=id value=$form->{id}>
1096 <input type=hidden name=type value=business>
1097
1098 <table width=100%>
1099   <tr>
1100     <th class=listtop colspan=2>$form->{title}</th>
1101   </tr>
1102   <tr height="5"></tr>
1103   <tr>
1104     <th align=right>| . $locale->text('Type of Business') . qq|</th>
1105     <td><input name=description size=30 value="$form->{description}"></td>
1106   <tr>
1107   <tr>
1108     <th align=right>| . $locale->text('Discount') . qq| %</th>
1109     <td><input name=discount size=5 value=$form->{discount}></td>
1110   </tr>
1111   <tr>
1112     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
1113     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
1114   </tr>
1115   <td colspan=2><hr size=3 noshade></td>
1116   </tr>
1117 </table>
1118 |;
1119
1120   $lxdebug->leave_sub();
1121 }
1122
1123 sub save_business {
1124   $lxdebug->enter_sub();
1125
1126   $auth->assert('config');
1127
1128   $form->isblank("description", $locale->text('Description missing!'));
1129   $form->{discount} = $form->parse_amount(\%myconfig, $form->{discount}) / 100;
1130   AM->save_business(\%myconfig, \%$form);
1131   $form->redirect($locale->text('Business saved!'));
1132
1133   $lxdebug->leave_sub();
1134 }
1135
1136 sub delete_business {
1137   $lxdebug->enter_sub();
1138
1139   $auth->assert('config');
1140
1141   AM->delete_business(\%myconfig, \%$form);
1142   $form->redirect($locale->text('Business deleted!'));
1143
1144   $lxdebug->leave_sub();
1145 }
1146
1147 sub add_language {
1148   $lxdebug->enter_sub();
1149
1150   $auth->assert('config');
1151
1152   $form->{title} = "Add";
1153
1154   $form->{callback} = "am.pl?action=add_language" unless $form->{callback};
1155
1156   &language_header;
1157   &form_footer;
1158
1159   $lxdebug->leave_sub();
1160 }
1161
1162 sub edit_language {
1163   $lxdebug->enter_sub();
1164
1165   $auth->assert('config');
1166
1167   $form->{title} = "Edit";
1168
1169   AM->get_language(\%myconfig, \%$form);
1170
1171   &language_header;
1172
1173   $form->{orphaned} = 1;
1174   &form_footer;
1175
1176   $lxdebug->leave_sub();
1177 }
1178
1179 sub list_language {
1180   $lxdebug->enter_sub();
1181
1182   $auth->assert('config');
1183
1184   AM->language(\%myconfig, \%$form);
1185
1186   $form->{callback} = "am.pl?action=list_language";
1187
1188   $callback = $form->escape($form->{callback});
1189
1190   $form->{title} = $locale->text('Languages');
1191
1192   @column_index = qw(description template_code article_code output_numberformat output_dateformat output_longdates);
1193
1194   $column_header{description} =
1195       qq|<th class=listheading width=60%>|
1196     . $locale->text('Description')
1197     . qq|</th>|;
1198   $column_header{template_code} =
1199       qq|<th class=listheading width=10%>|
1200     . $locale->text('Template Code')
1201     . qq|</th>|;
1202   $column_header{article_code} =
1203       qq|<th class=listheading>|
1204     . $locale->text('Article Code')
1205     . qq|</th>|;
1206   $column_header{output_numberformat} =
1207       qq|<th class=listheading>|
1208     . $locale->text('Number Format')
1209     . qq|</th>|;
1210   $column_header{output_dateformat} =
1211       qq|<th class=listheading>|
1212     . $locale->text('Date Format')
1213     . qq|</th>|;
1214   $column_header{output_longdates} =
1215       qq|<th class=listheading>|
1216     . $locale->text('Long Dates')
1217     . qq|</th>|;
1218
1219   $form->header;
1220
1221   print qq|
1222 <body>
1223
1224 <table width=100%>
1225   <tr>
1226     <th class=listtop>$form->{title}</th>
1227   </tr>
1228   <tr height="5"></tr>
1229   <tr>
1230     <td>
1231       <table width=100%>
1232         <tr class=listheading>
1233 |;
1234
1235   map { print "$column_header{$_}\n" } @column_index;
1236
1237   print qq|
1238         </tr>
1239 |;
1240
1241   foreach $ref (@{ $form->{ALL} }) {
1242
1243     $i++;
1244     $i %= 2;
1245
1246     print qq|
1247         <tr valign=top class=listrow$i>
1248 |;
1249
1250
1251     $column_data{description} =
1252       qq|<td><a href="am.pl?action=edit_language&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1253     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
1254     $column_data{article_code} =
1255       qq|<td align=right>$ref->{article_code}</td>|;
1256     $column_data{output_numberformat} =
1257       "<td nowrap>" .
1258       ($ref->{output_numberformat} ? $ref->{output_numberformat} :
1259        $locale->text("use program settings")) .
1260       "</td>";
1261     $column_data{output_dateformat} =
1262       "<td nowrap>" .
1263       ($ref->{output_dateformat} ? $ref->{output_dateformat} :
1264        $locale->text("use program settings")) .
1265       "</td>";
1266     $column_data{output_longdates} =
1267       "<td nowrap>" .
1268       ($ref->{output_longdates} ? $locale->text("Yes") : $locale->text("No")) .
1269       "</td>";
1270
1271     map { print "$column_data{$_}\n" } @column_index;
1272
1273     print qq|
1274         </tr>
1275 |;
1276   }
1277
1278   print qq|
1279       </table>
1280     </td>
1281   </tr>
1282   <tr>
1283   <td><hr size=3 noshade></td>
1284   </tr>
1285 </table>
1286
1287 <br>
1288 <form method=post action=am.pl>
1289
1290 <input name=callback type=hidden value="$form->{callback}">
1291
1292 <input type=hidden name=type value=language>
1293
1294 <input class=submit type=submit name=action value="|
1295     . $locale->text('Add') . qq|">
1296
1297   </form>
1298
1299   </body>
1300   </html>
1301 |;
1302
1303   $lxdebug->leave_sub();
1304 }
1305
1306 sub language_header {
1307   $lxdebug->enter_sub();
1308
1309   $auth->assert('config');
1310
1311   $form->{title}    = $locale->text("$form->{title} Language");
1312
1313   # $locale->text('Add Language')
1314   # $locale->text('Edit Language')
1315
1316   $form->{description} =~ s/\"/&quot;/g;
1317   $form->{template_code} =~ s/\"/&quot;/g;
1318   $form->{article_code} =~ s/\"/&quot;/g;
1319
1320
1321   $form->header;
1322
1323   my $numberformat =
1324     qq|<option value="">| . $locale->text("use program settings") .
1325     qq|</option>|;
1326   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
1327     $numberformat .=
1328       ($item eq $form->{output_numberformat})
1329       ? "<option selected>$item"
1330       : "<option>$item"
1331       . "</option>";
1332   }
1333
1334   my $dateformat =
1335     qq|<option value="">| . $locale->text("use program settings") .
1336     qq|</option>|;
1337   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1338     $dateformat .=
1339       ($item eq $form->{output_dateformat})
1340       ? "<option selected>$item"
1341       : "<option>$item"
1342       . "</option>";
1343   }
1344
1345   print qq|
1346 <body>
1347
1348 <form method=post action=am.pl>
1349
1350 <input type=hidden name=id value=$form->{id}>
1351 <input type=hidden name=type value=language>
1352
1353 <table width=100%>
1354   <tr>
1355     <th class=listtop colspan=2>$form->{title}</th>
1356   </tr>
1357   <tr height="5"></tr>
1358   <tr>
1359     <th align=right>| . $locale->text('Language') . qq|</th>
1360     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1361   <tr>
1362   <tr>
1363     <th align=right>| . $locale->text('Template Code') . qq|</th>
1364     <td><input name=template_code size=5 value="| . $form->quote($form->{template_code}) . qq|"></td>
1365   </tr>
1366   <tr>
1367     <th align=right>| . $locale->text('Article Code') . qq|</th>
1368     <td><input name=article_code size=10 value="| . $form->quote($form->{article_code}) . qq|"></td>
1369   </tr>
1370   <tr>
1371     <th align=right>| . $locale->text('Number Format') . qq|</th>
1372     <td><select name="output_numberformat">$numberformat</select></td>
1373   </tr>
1374   <tr>
1375     <th align=right>| . $locale->text('Date Format') . qq|</th>
1376     <td><select name="output_dateformat">$dateformat</select></td>
1377   </tr>
1378   <tr>
1379     <th align=right>| . $locale->text('Long Dates') . qq|</th>
1380     <td><input type="radio" name="output_longdates" value="1"| .
1381     ($form->{output_longdates} ? " checked" : "") .
1382     qq|>| . $locale->text("Yes") .
1383     qq|<input type="radio" name="output_longdates" value="0"| .
1384     ($form->{output_longdates} ? "" : " checked") .
1385     qq|>| . $locale->text("No") .
1386     qq|</td>
1387   </tr>
1388   <td colspan=2><hr size=3 noshade></td>
1389   </tr>
1390 </table>
1391 |;
1392
1393   $lxdebug->leave_sub();
1394 }
1395
1396 sub save_language {
1397   $lxdebug->enter_sub();
1398
1399   $auth->assert('config');
1400
1401   $form->isblank("description", $locale->text('Language missing!'));
1402   $form->isblank("template_code", $locale->text('Template Code missing!'));
1403   $form->isblank("article_code", $locale->text('Article Code missing!'));
1404   AM->save_language(\%myconfig, \%$form);
1405   $form->redirect($locale->text('Language saved!'));
1406
1407   $lxdebug->leave_sub();
1408 }
1409
1410 sub delete_language {
1411   $lxdebug->enter_sub();
1412
1413   $auth->assert('config');
1414
1415   AM->delete_language(\%myconfig, \%$form);
1416   $form->redirect($locale->text('Language deleted!'));
1417
1418   $lxdebug->leave_sub();
1419 }
1420
1421
1422 sub add_buchungsgruppe {
1423   $lxdebug->enter_sub();
1424
1425   $auth->assert('config');
1426
1427   # $locale->text("Add Buchungsgruppe")
1428   # $locale->text("Edit Buchungsgruppe")
1429   $form->{title} = "Add";
1430
1431   $form->{callback} = "am.pl?action=add_buchungsgruppe" unless $form->{callback};
1432
1433   AM->get_buchungsgruppe(\%myconfig, \%$form);
1434   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1435   for (my $i = 0; 4 > $i; $i++) {
1436     map({ $form->{"${_}_accno_id_$i"} = $form->{"std_${_}_accno_id"}; }
1437         qw(income expense));
1438   }
1439
1440   &buchungsgruppe_header;
1441   &form_footer;
1442
1443   $lxdebug->leave_sub();
1444 }
1445
1446 sub edit_buchungsgruppe {
1447   $lxdebug->enter_sub();
1448
1449   $auth->assert('config');
1450
1451   $form->{title} = "Edit";
1452
1453   AM->get_buchungsgruppe(\%myconfig, \%$form);
1454
1455   &buchungsgruppe_header;
1456
1457   &form_footer;
1458
1459   $lxdebug->leave_sub();
1460 }
1461
1462 sub list_buchungsgruppe {
1463   $lxdebug->enter_sub();
1464
1465   $auth->assert('config');
1466
1467   AM->buchungsgruppe(\%myconfig, \%$form);
1468
1469   $form->{callback} = "am.pl?action=list_buchungsgruppe";
1470
1471   $callback = $form->escape($form->{callback});
1472
1473   $form->{title} = $locale->text('Buchungsgruppen');
1474
1475   @column_index = qw(up down description inventory_accno
1476                      income_accno_0 expense_accno_0
1477                      income_accno_1 expense_accno_1
1478                      income_accno_2 expense_accno_2
1479                      income_accno_3 expense_accno_3 );
1480
1481   $column_header{up} =
1482       qq|<th class="listheading" width="16">|
1483     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1484     . qq|</th>|;
1485   $column_header{down} =
1486       qq|<th class="listheading" width="16">|
1487     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1488     . qq|</th>|;
1489   $column_header{description} =
1490       qq|<th class="listheading" width="40%">|
1491     . $locale->text('Description')
1492     . qq|</th>|;
1493   $column_header{inventory_accno} =
1494       qq|<th class=listheading>|
1495     . $locale->text('Bestandskonto')
1496     . qq|</th>|;
1497   $column_header{income_accno_0} =
1498       qq|<th class=listheading>|
1499     . $locale->text('National Revenues')
1500     . qq|</th>|;
1501   $column_header{expense_accno_0} =
1502       qq|<th class=listheading>|
1503     . $locale->text('National Expenses')
1504     . qq|</th>|;
1505   $column_header{income_accno_1} =
1506       qq|<th class=listheading>|
1507     . $locale->text('Revenues EU with UStId')
1508     . qq|</th>|;
1509   $column_header{expense_accno_1} =
1510       qq|<th class=listheading>|
1511     . $locale->text('Expenses EU with UStId')
1512     . qq|</th>|;
1513   $column_header{income_accno_2} =
1514       qq|<th class=listheading>|
1515     . $locale->text('Revenues EU without UStId')
1516     . qq|</th>|;
1517   $column_header{expense_accno_2} =
1518       qq|<th class=listheading>|
1519     . $locale->text('Expenses EU without UStId')
1520     . qq|</th>|;
1521   $column_header{income_accno_3} =
1522       qq|<th class=listheading>|
1523     . $locale->text('Foreign Revenues')
1524     . qq|</th>|;
1525   $column_header{expense_accno_3} =
1526       qq|<th class=listheading>|
1527     . $locale->text('Foreign Expenses')
1528     . qq|</th>|;
1529   $form->header;
1530
1531   print qq|
1532 <body>
1533
1534 <table width=100%>
1535   <tr>
1536     <th class=listtop>$form->{title}</th>
1537   </tr>
1538   <tr height="5"></tr>
1539   <tr>
1540     <td>
1541       <table width=100%>
1542         <tr class=listheading>
1543 |;
1544
1545   map { print "$column_header{$_}\n" } @column_index;
1546
1547   print qq|
1548         </tr>
1549 |;
1550
1551   my $swap_link = qq|am.pl?action=swap_buchungsgruppen&|;
1552
1553   my $row = 0;
1554   foreach $ref (@{ $form->{ALL} }) {
1555
1556     $i++;
1557     $i %= 2;
1558
1559     print qq|
1560         <tr valign=top class=listrow$i>
1561 |;
1562
1563     if ($row) {
1564       my $pref = $form->{ALL}->[$row - 1];
1565       $column_data{up} =
1566         qq|<td align="center" valign="center" width="16">| .
1567         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1568         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1569         qq|</a></td>|;
1570     } else {
1571       $column_data{up} = qq|<td width="16">&nbsp;</td>|;
1572     }
1573
1574     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1575       $column_data{down} = qq|<td width="16">&nbsp;</td>|;
1576     } else {
1577       my $nref = $form->{ALL}->[$row + 1];
1578       $column_data{down} =
1579         qq|<td align="center" valign="center" width="16">| .
1580         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1581         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1582         qq|</a></td>|;
1583     }
1584
1585     $column_data{description} = qq|<td><a href="am.pl?action=edit_buchungsgruppe&id=$ref->{id}&callback=$callback">$ref->{description}</td>|;
1586     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
1587     $column_data{income_accno_0} =
1588       qq|<td align=right>$ref->{income_accno_0}</td>|;
1589     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1590     $column_data{income_accno_1} =
1591       qq|<td align=right>$ref->{income_accno_1}</td>|;
1592     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1593     $column_data{income_accno_2} =
1594       qq|<td align=right>$ref->{income_accno_2}</td>|;
1595     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1596     $column_data{income_accno_3} =
1597       qq|<td align=right>$ref->{income_accno_3}</td>|;
1598     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1599
1600     map { print "$column_data{$_}\n" } @column_index;
1601
1602     print qq|
1603         </tr>
1604 |;
1605
1606     $row++;
1607   }
1608
1609   print qq|
1610       </table>
1611     </td>
1612   </tr>
1613   <tr>
1614   <td><hr size=3 noshade></td>
1615   </tr>
1616 </table>
1617
1618 <br>
1619 <form method=post action=am.pl>
1620
1621 <input name=callback type=hidden value="$form->{callback}">
1622
1623 <input type=hidden name=type value=buchungsgruppe>
1624
1625 <input class=submit type=submit name=action value="|
1626     . $locale->text('Add') . qq|">
1627
1628   </form>
1629
1630   </body>
1631   </html>
1632 |;
1633
1634   $lxdebug->leave_sub();
1635 }
1636
1637 sub buchungsgruppe_header {
1638   $lxdebug->enter_sub();
1639
1640   $auth->assert('config');
1641
1642   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
1643
1644   # $locale->text('Add Accounting Group')
1645   # $locale->text('Edit Accounting Group')
1646
1647   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1648   my %acc_type_map = (
1649     "IC" => $acc_inventory,
1650     "IC_income" => $acc_income,
1651     "IC_sale" => $acc_income,
1652     "IC_expense" => $acc_expense,
1653     "IC_cogs" => $acc_expense,
1654     );
1655
1656   foreach $key (keys(%acc_type_map)) {
1657     foreach $ref (@{ $form->{IC_links}{$key} }) {
1658       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1659     }
1660   }
1661
1662   foreach my $type (qw(IC IC_income IC_expense)) {
1663     $form->{"select$type"} =
1664       join("",
1665            map({ "<option value=$_->{id} $_->{selected}>" .
1666                    "$_->{accno}--" . H($_->{description}) . "</option>" }
1667                sort({ $a->{"accno"} cmp $b->{"accno"} }
1668                     values(%{$acc_type_map{$type}}))));
1669   }
1670
1671   if ($form->{id}) {
1672     $form->{selectIC} =~ s/selected//g;
1673     $form->{selectIC} =~ s/ value=\Q$form->{inventory_accno_id}\E/  value=$form->{inventory_accno_id} selected/;
1674     $form->{selectIC_income} =~ s/selected//g;
1675     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_0}\E/  value=$form->{income_accno_id_0} selected/;
1676     $form->{selectIC_expense} =~ s/selected//g;
1677     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_0}\E/  value=$form->{expense_accno_id_0} selected/;
1678   }
1679
1680   if (!$eur) {
1681     $linkaccounts = qq|
1682                <tr>
1683                 <th align=right>| . $locale->text('Inventory') . qq|</th>
1684                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1685                 <input name=selectIC type=hidden value="$form->{selectIC}">
1686               </tr>|;
1687   } else {
1688     $linkaccounts = qq|
1689                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1690   }
1691
1692
1693   $linkaccounts .= qq|
1694               <tr>
1695                 <th align=right>| . $locale->text('National Revenues') . qq|</th>
1696                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1697               </tr>
1698               <tr>
1699                 <th align=right>| . $locale->text('National Expenses') . qq|</th>
1700                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1701               </tr>|;
1702   if ($form->{id}) {
1703     $form->{selectIC_income} =~ s/selected//g;
1704     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_1}\E/  value=$form->{income_accno_id_1} selected/;
1705     $form->{selectIC_expense} =~ s/selected//g;
1706     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_1}\E/  value=$form->{expense_accno_id_1} selected/;
1707   }
1708   $linkaccounts .= qq|        <tr>
1709                 <th align=right>| . $locale->text('Revenues EU with UStId') . qq|</th>
1710                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1711               </tr>
1712               <tr>
1713                 <th align=right>| . $locale->text('Expenses EU with UStId') . qq|</th>
1714                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1715               </tr>|;
1716
1717   if ($form->{id}) {
1718     $form->{selectIC_income} =~ s/selected//g;
1719     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_2}\E/  value=$form->{income_accno_id_2} selected/;
1720     $form->{selectIC_expense} =~ s/selected//g;
1721     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_2}\E/  value=$form->{expense_accno_id_2} selected/;
1722   }
1723
1724   $linkaccounts .= qq|        <tr>
1725                 <th align=right>| . $locale->text('Revenues EU without UStId') . qq|</th>
1726                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1727               </tr>
1728               <tr>
1729                 <th align=right>| . $locale->text('Expenses EU without UStId') . qq|</th>
1730                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1731               </tr>|;
1732
1733   if ($form->{id}) {
1734     $form->{selectIC_income} =~ s/selected//g;
1735     $form->{selectIC_income} =~ s/ value=\Q$form->{income_accno_id_3}\E/  value=$form->{income_accno_id_3} selected/;
1736     $form->{selectIC_expense} =~ s/selected//g;
1737     $form->{selectIC_expense} =~ s/ value=\Q$form->{expense_accno_id_3}\E/  value=$form->{expense_accno_id_3} selected/;
1738   }
1739
1740   $linkaccounts .= qq|        <tr>
1741                 <th align=right>| . $locale->text('Foreign Revenues') . qq|</th>
1742                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1743               </tr>
1744               <tr>
1745                 <th align=right>| . $locale->text('Foreign Expenses') . qq|</th>
1746                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1747               </tr>
1748 |;
1749
1750
1751   $form->header;
1752
1753   print qq|
1754 <body>
1755
1756 <form method=post action=am.pl>
1757
1758 <input type=hidden name=id value=$form->{id}>
1759 <input type=hidden name=type value=buchungsgruppe>
1760
1761 <table width=100%>
1762   <tr>
1763     <th class=listtop colspan=2>$form->{title}</th>
1764   </tr>
1765   <tr height="5"></tr>
1766   <tr>
1767     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
1768     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
1769   <tr>
1770   $linkaccounts
1771   <td colspan=2><hr size=3 noshade></td>
1772   </tr>
1773 </table>
1774 |;
1775
1776   $lxdebug->leave_sub();
1777 }
1778
1779 sub save_buchungsgruppe {
1780   $lxdebug->enter_sub();
1781
1782   $auth->assert('config');
1783
1784   $form->isblank("description", $locale->text('Description missing!'));
1785
1786   AM->save_buchungsgruppe(\%myconfig, \%$form);
1787   $form->redirect($locale->text('Accounting Group saved!'));
1788
1789   $lxdebug->leave_sub();
1790 }
1791
1792 sub delete_buchungsgruppe {
1793   $lxdebug->enter_sub();
1794
1795   $auth->assert('config');
1796
1797   AM->delete_buchungsgruppe(\%myconfig, \%$form);
1798   $form->redirect($locale->text('Accounting Group deleted!'));
1799
1800   $lxdebug->leave_sub();
1801 }
1802
1803 sub swap_buchungsgruppen {
1804   $lxdebug->enter_sub();
1805
1806   $auth->assert('config');
1807
1808   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
1809   list_buchungsgruppe();
1810
1811   $lxdebug->leave_sub();
1812 }
1813
1814
1815 sub add_printer {
1816   $lxdebug->enter_sub();
1817
1818   $auth->assert('config');
1819
1820   $form->{title} = "Add";
1821
1822   $form->{callback} = "am.pl?action=add_printer" unless $form->{callback};
1823
1824   &printer_header;
1825   &form_footer;
1826
1827   $lxdebug->leave_sub();
1828 }
1829
1830 sub edit_printer {
1831   $lxdebug->enter_sub();
1832
1833   $auth->assert('config');
1834
1835   $form->{title} = "Edit";
1836
1837   AM->get_printer(\%myconfig, \%$form);
1838
1839   &printer_header;
1840
1841   $form->{orphaned} = 1;
1842   &form_footer;
1843
1844   $lxdebug->leave_sub();
1845 }
1846
1847 sub list_printer {
1848   $lxdebug->enter_sub();
1849
1850   $auth->assert('config');
1851
1852   AM->printer(\%myconfig, \%$form);
1853
1854   $form->{callback} = "am.pl?action=list_printer";
1855
1856   $callback = $form->escape($form->{callback});
1857
1858   $form->{title} = $locale->text('Printer');
1859
1860   @column_index = qw(printer_description printer_command template_code);
1861
1862   $column_header{printer_description} =
1863       qq|<th class=listheading width=60%>|
1864     . $locale->text('Printer Description')
1865     . qq|</th>|;
1866   $column_header{printer_command} =
1867       qq|<th class=listheading width=10%>|
1868     . $locale->text('Printer Command')
1869     . qq|</th>|;
1870   $column_header{template_code} =
1871       qq|<th class=listheading>|
1872     . $locale->text('Template Code')
1873     . qq|</th>|;
1874
1875   $form->header;
1876
1877   print qq|
1878 <body>
1879
1880 <table width=100%>
1881   <tr>
1882     <th class=listtop>$form->{title}</th>
1883   </tr>
1884   <tr height="5"></tr>
1885   <tr>
1886     <td>
1887       <table width=100%>
1888         <tr class=listheading>
1889 |;
1890
1891   map { print "$column_header{$_}\n" } @column_index;
1892
1893   print qq|
1894         </tr>
1895 |;
1896
1897   foreach $ref (@{ $form->{ALL} }) {
1898
1899     $i++;
1900     $i %= 2;
1901
1902     print qq|
1903         <tr valign=top class=listrow$i>
1904 |;
1905
1906
1907     $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}"</td>|;
1908     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
1909     $column_data{template_code} =
1910       qq|<td align=right>$ref->{template_code}</td>|;
1911
1912     map { print "$column_data{$_}\n" } @column_index;
1913
1914     print qq|
1915         </tr>
1916 |;
1917   }
1918
1919   print qq|
1920       </table>
1921     </td>
1922   </tr>
1923   <tr>
1924   <td><hr size=3 noshade></td>
1925   </tr>
1926 </table>
1927
1928 <br>
1929 <form method=post action=am.pl>
1930
1931 <input name=callback type=hidden value="$form->{callback}">
1932
1933 <input type=hidden name=type value=printer>
1934
1935 <input class=submit type=submit name=action value="|
1936     . $locale->text('Add') . qq|">
1937
1938   </form>
1939
1940   </body>
1941   </html>
1942 |;
1943
1944   $lxdebug->leave_sub();
1945 }
1946
1947 sub printer_header {
1948   $lxdebug->enter_sub();
1949
1950   $auth->assert('config');
1951
1952   $form->{title}    = $locale->text("$form->{title} Printer");
1953
1954   # $locale->text('Add Printer')
1955   # $locale->text('Edit Printer')
1956
1957   $form->{printer_description} =~ s/\"/&quot;/g;
1958   $form->{template_code} =~ s/\"/&quot;/g;
1959   $form->{printer_command} =~ s/\"/&quot;/g;
1960
1961
1962   $form->header;
1963
1964   print qq|
1965 <body>
1966
1967 <form method=post action=am.pl>
1968
1969 <input type=hidden name=id value=$form->{id}>
1970 <input type=hidden name=type value=printer>
1971
1972 <table width=100%>
1973   <tr>
1974     <th class=listtop colspan=2>$form->{title}</th>
1975   </tr>
1976   <tr height="5"></tr>
1977   <tr>
1978     <th align=right>| . $locale->text('Printer') . qq|</th>
1979     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
1980   <tr>
1981   <tr>
1982     <th align=right>| . $locale->text('Printer Command') . qq|</th>
1983     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
1984   </tr>
1985   <tr>
1986     <th align=right>| . $locale->text('Template Code') . qq|</th>
1987     <td><input name=template_code size=5 value="$form->{template_code}"></td>
1988   </tr>
1989   <td colspan=2><hr size=3 noshade></td>
1990   </tr>
1991 </table>
1992 |;
1993
1994   $lxdebug->leave_sub();
1995 }
1996
1997 sub save_printer {
1998   $lxdebug->enter_sub();
1999
2000   $auth->assert('config');
2001
2002   $form->isblank("printer_description", $locale->text('Description missing!'));
2003   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
2004   AM->save_printer(\%myconfig, \%$form);
2005   $form->redirect($locale->text('Printer saved!'));
2006
2007   $lxdebug->leave_sub();
2008 }
2009
2010 sub delete_printer {
2011   $lxdebug->enter_sub();
2012
2013   $auth->assert('config');
2014
2015   AM->delete_printer(\%myconfig, \%$form);
2016   $form->redirect($locale->text('Printer deleted!'));
2017
2018   $lxdebug->leave_sub();
2019 }
2020
2021 sub add_payment {
2022   $lxdebug->enter_sub();
2023
2024   $auth->assert('config');
2025
2026   $form->{title} = "Add";
2027
2028   $form->{callback} = "am.pl?action=add_payment" unless $form->{callback};
2029
2030   $form->{terms_netto} = 0;
2031   $form->{terms_skonto} = 0;
2032   $form->{percent_skonto} = 0;
2033   my @languages = AM->language(\%myconfig, $form, 1);
2034   map({ $_->{"language"} = $_->{"description"};
2035         $_->{"language_id"} = $_->{"id"}; } @languages);
2036   $form->{"TRANSLATION"} = \@languages;
2037   &payment_header;
2038   &form_footer;
2039
2040   $lxdebug->leave_sub();
2041 }
2042
2043 sub edit_payment {
2044   $lxdebug->enter_sub();
2045
2046   $auth->assert('config');
2047
2048   $form->{title} = "Edit";
2049
2050   AM->get_payment(\%myconfig, $form);
2051   $form->{percent_skonto} =
2052     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
2053
2054   &payment_header;
2055
2056   $form->{orphaned} = 1;
2057   &form_footer;
2058
2059   $lxdebug->leave_sub();
2060 }
2061
2062 sub list_payment {
2063   $lxdebug->enter_sub();
2064
2065   $auth->assert('config');
2066
2067   AM->payment(\%myconfig, \%$form);
2068
2069   $form->{callback} = build_std_url("action=list_payment");
2070
2071   $callback = $form->escape($form->{callback});
2072
2073   $form->{title} = $locale->text('Payment Terms');
2074
2075   @column_index = qw(up down description description_long terms_netto
2076                      terms_skonto percent_skonto);
2077
2078   $column_header{up} =
2079       qq|<th class="listheading" align="center" valign="center" width="16">|
2080     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
2081     . qq|</th>|;
2082   $column_header{down} =
2083       qq|<th class="listheading" align="center" valign="center" width="16">|
2084     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
2085     . qq|</th>|;
2086   $column_header{description} =
2087       qq|<th class=listheading>|
2088     . $locale->text('Description')
2089     . qq|</th>|;
2090   $column_header{description_long} =
2091       qq|<th class=listheading>|
2092     . $locale->text('Long Description')
2093     . qq|</th>|;
2094   $column_header{terms_netto} =
2095       qq|<th class=listheading>|
2096     . $locale->text('Netto Terms')
2097     . qq|</th>|;
2098   $column_header{terms_skonto} =
2099       qq|<th class=listheading>|
2100     . $locale->text('Skonto Terms')
2101     . qq|</th>|;
2102   $column_header{percent_skonto} =
2103       qq|<th class=listheading>|
2104     . $locale->text('Skonto')
2105     . qq| %</th>|;
2106
2107   $form->header;
2108
2109   print qq|
2110 <body>
2111
2112 <table width=100%>
2113   <tr>
2114     <th class=listtop>$form->{title}</th>
2115   </tr>
2116   <tr height="5"></tr>
2117   <tr>
2118     <td>
2119       <table width=100%>
2120         <tr class=listheading>
2121 |;
2122
2123   map { print "$column_header{$_}\n" } @column_index;
2124
2125   print qq|
2126         </tr>
2127 |;
2128
2129   my $swap_link = build_std_url("action=swap_payment_terms");
2130
2131   my $row = 0;
2132   foreach $ref (@{ $form->{ALL} }) {
2133
2134     $i++;
2135     $i %= 2;
2136
2137     print qq|
2138         <tr valign=top class=listrow$i>
2139 |;
2140
2141     if ($row) {
2142       my $pref = $form->{ALL}->[$row - 1];
2143       $column_data{up} =
2144         qq|<td align="center" valign="center" width="16">| .
2145         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
2146         qq|<img border="0" src="image/up.png" alt="| . $locale->text("up") . qq|">| .
2147         qq|</a></td>|;
2148     } else {
2149       $column_data{up} = qq|<td width="16">&nbsp;</td>|;
2150     }
2151
2152     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
2153       $column_data{down} = qq|<td width="16">&nbsp;</td>|;
2154     } else {
2155       my $nref = $form->{ALL}->[$row + 1];
2156       $column_data{down} =
2157         qq|<td align="center" valign="center" width="16">| .
2158         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
2159         qq|<img border="0" src="image/down.png" alt="| . $locale->text("down") . qq|">| .
2160         qq|</a></td>|;
2161     }
2162
2163     $column_data{description} =
2164       qq|<td><a href="| .
2165       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
2166       qq|">| . H($ref->{description}) . qq|</a></td>|;
2167     $column_data{description_long} =
2168       qq|<td>| . H($ref->{description_long}) . qq|</td>|;
2169     $column_data{terms_netto} =
2170       qq|<td align=right>$ref->{terms_netto}</td>|;
2171     $column_data{terms_skonto} =
2172       qq|<td align=right>$ref->{terms_skonto}</td>|;
2173     $column_data{percent_skonto} =
2174       qq|<td align=right>| .
2175       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
2176       qq|%</td>|;
2177     map { print "$column_data{$_}\n" } @column_index;
2178
2179     print qq|
2180         </tr>
2181 |;
2182     $row++;
2183   }
2184
2185   print qq|
2186       </table>
2187     </td>
2188   </tr>
2189   <tr>
2190   <td><hr size=3 noshade></td>
2191   </tr>
2192 </table>
2193
2194 <br>
2195 <form method=post action=am.pl>
2196
2197 <input name=callback type=hidden value="$form->{callback}">
2198
2199 <input type=hidden name=type value=payment>
2200
2201 <input class=submit type=submit name=action value="|
2202     . $locale->text('Add') . qq|">
2203
2204   </form>
2205
2206   </body>
2207   </html>
2208 |;
2209
2210   $lxdebug->leave_sub();
2211 }
2212
2213 sub payment_header {
2214   $lxdebug->enter_sub();
2215
2216   $auth->assert('config');
2217
2218   $form->{title}    = $locale->text("$form->{title} Payment Terms");
2219
2220   # $locale->text('Add Payment Terms')
2221   # $locale->text('Edit Payment Terms')
2222
2223   $form->{description} =~ s/\"/&quot;/g;
2224
2225
2226
2227   $form->header;
2228
2229   print qq|
2230 <body>
2231
2232 <form method=post action=am.pl>
2233
2234 <input type=hidden name=id value=$form->{id}>
2235 <input type=hidden name=type value=payment>
2236
2237 <table width=100%>
2238   <tr>
2239     <th class=listtop colspan=2>$form->{title}</th>
2240   </tr>
2241   <tr height="5"></tr>
2242   <tr>
2243     <th align=right>| . $locale->text('Description') . qq|</th>
2244     <td><input name=description size=30 value="$form->{description}"></td>
2245   <tr>
2246   <tr>
2247     <th align=right>| . $locale->text('Long Description') . qq|</th>
2248     <td><input name=description_long size=50 value="$form->{description_long}"></td>
2249   </tr>
2250 |;
2251
2252   foreach my $language (@{ $form->{"TRANSLATION"} }) {
2253     print qq|
2254   <tr>
2255     <th align="right">| .
2256     sprintf($locale->text('Translation (%s)'),
2257             $language->{"language"})
2258     . qq|</th>
2259     <td><input name="description_long_$language->{language_id}" size="50"
2260          value="| . Q($language->{"description_long"}) . qq|"></td>
2261   </tr>
2262 |;
2263   }
2264
2265   print qq|
2266   <tr>
2267     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
2268     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
2269   </tr>
2270   <tr>
2271     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
2272     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
2273   </tr>  
2274   <tr>
2275     <th align=right>| . $locale->text('Skonto') . qq| %</th>
2276     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
2277   </tr> 
2278   <td colspan=2><hr size=3 noshade></td>
2279   </tr>
2280 </table>
2281
2282 <p>| . $locale->text("You can use the following strings in the long " .
2283                      "description and all translations. They will be " .
2284                      "replaced by their actual values by Lx-Office " .
2285                      "before they're output.")
2286 . qq|</p>
2287
2288 <ul>
2289   <li>| . $locale->text("&lt;%netto_date%&gt; -- Date the payment is due in " .
2290                         "full")
2291 . qq|</li>
2292   <li>| . $locale->text("&lt;%skonto_date%&gt; -- Date the payment is due " .
2293                         "with discount")
2294 . qq|</li>
2295   <li>| . $locale->text("&lt;%skonto_amount%&gt; -- The deductible amount")
2296 . qq|</li>
2297   <li>| . $locale->text("&lt;%total%&gt; -- Amount payable")
2298 . qq|</li>
2299   <li>| . $locale->text("&lt;%total_wo_skonto%&gt; -- Amount payable less discount")
2300 . qq|</li>
2301   <li>| . $locale->text("&lt;%invtotal%&gt; -- Invoice total")
2302 . qq|</li>
2303   <li>| . $locale->text("&lt;%invtotal_wo_skonto%&gt; -- Invoice total less discount")
2304 . qq|</li>
2305   <li>| . $locale->text("&lt;%currency%&gt; -- The selected currency")
2306 . qq|</li>
2307   <li>| . $locale->text("&lt;%terms_netto%&gt; -- The number of days for " .
2308                         "full payment")
2309 . qq|</li>
2310   <li>| . $locale->text("&lt;%account_number%&gt; -- Your account number")
2311 . qq|</li>
2312   <li>| . $locale->text("&lt;%bank%&gt; -- Your bank")
2313 . qq|</li>
2314   <li>| . $locale->text("&lt;%bank_code%&gt; -- Your bank code")
2315 . qq|</li>
2316 </ul>|;
2317
2318   $lxdebug->leave_sub();
2319 }
2320
2321 sub save_payment {
2322   $lxdebug->enter_sub();
2323
2324   $auth->assert('config');
2325
2326   $form->isblank("description", $locale->text('Description missing!'));
2327   $form->{"percent_skonto"} =
2328     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
2329   AM->save_payment(\%myconfig, \%$form);
2330   $form->redirect($locale->text('Payment Terms saved!'));
2331
2332   $lxdebug->leave_sub();
2333 }
2334
2335 sub delete_payment {
2336   $lxdebug->enter_sub();
2337
2338   $auth->assert('config');
2339
2340   AM->delete_payment(\%myconfig, \%$form);
2341   $form->redirect($locale->text('Payment terms deleted!'));
2342
2343   $lxdebug->leave_sub();
2344 }
2345
2346 sub swap_payment_terms {
2347   $lxdebug->enter_sub();
2348
2349   $auth->assert('config');
2350
2351   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
2352   list_payment();
2353
2354   $lxdebug->leave_sub();
2355 }
2356
2357 sub edit_defaults {
2358   $lxdebug->enter_sub();
2359
2360   # get defaults for account numbers and last numbers
2361   AM->defaultaccounts(\%myconfig, \%$form);
2362
2363   map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
2364
2365   foreach $key (keys %{ $form->{IC} }) {
2366     foreach $accno (sort keys %{ $form->{IC}->{$key} }) {
2367       my $array = "ACCNOS_" . uc($key);
2368       $form->{$array} ||= [];
2369
2370       my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
2371       push @{ $form->{$array} }, {
2372         'name'     => $value,
2373         'value'    => $value,
2374         'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
2375       };
2376     }
2377   }
2378
2379   $form->{title} = $locale->text('Ranges of numbers and default accounts');
2380
2381   $form->header();
2382   print $form->parse_html_template('am/edit_defaults');
2383
2384   $lxdebug->leave_sub();
2385 }
2386
2387 sub save_defaults {
2388   $lxdebug->enter_sub();
2389
2390   AM->save_defaults();
2391
2392   $form->redirect($locale->text('Defaults saved.'));
2393
2394   $lxdebug->leave_sub();
2395 }
2396
2397 sub _build_cfg_options {
2398   my $idx   = shift;
2399   my $array = uc($idx) . 'S';
2400
2401   $form->{$array} = [];
2402   foreach my $item (@_) {
2403     push @{ $form->{$array} }, {
2404       'name'     => $item,
2405       'value'    => $item,
2406       'selected' => $item eq $myconfig{$idx},
2407     };
2408   }
2409 }
2410
2411 sub config {
2412   $lxdebug->enter_sub();
2413
2414   _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
2415   _build_cfg_options('numberformat', qw(1,000.00 1000.00 1.000,00 1000,00));
2416
2417   @formats = ();
2418   if ($opendocument_templates && $openofficeorg_writer_bin &&
2419       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
2420     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
2421                      "value" => "opendocument_pdf" });
2422   }
2423   if ($latex_templates) {
2424     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
2425   }
2426   push(@formats, { "name" => "HTML", "value" => "html" });
2427   if ($latex_templates) {
2428     push(@formats, { "name" => $locale->text("Postscript"),
2429                      "value" => "postscript" });
2430   }
2431   if ($opendocument_templates) {
2432     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
2433                      "value" => "opendocument" });
2434   }
2435
2436   if (!$myconfig{"template_format"}) {
2437     $myconfig{"template_format"} = "pdf";
2438   }
2439   $form->{TEMPLATE_FORMATS} = [];
2440   foreach $item (@formats) {
2441     push @{ $form->{TEMPLATE_FORMATS} }, {
2442       'name'     => $item->{name},
2443       'value'    => $item->{value},
2444       'selected' => $item->{value} eq $myconfig{template_format},
2445     };
2446   }
2447
2448   if (!$myconfig{"default_media"}) {
2449     $myconfig{"default_media"} = "screen";
2450   }
2451
2452   my %selected = ($myconfig{"default_media"} => "selected");
2453   $form->{MEDIA} = [
2454     { 'name' => $locale->text('Screen'),  'value' => 'screen',  'selected' => $selected{screen}, },
2455     { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
2456     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
2457     ];
2458
2459   AM->printer(\%myconfig, $form);
2460
2461   $form->{PRINTERS} = [];
2462   foreach my $printer (@{$form->{"ALL"}}) {
2463     push @{ $form->{PRINTERS} }, {
2464       'name'     => $printer->{printer_description},
2465       'value'    => $printer->{id},
2466       'selected' => $printer->{id} == $myconfig{default_printer_id},
2467     };
2468   }
2469
2470   %countrycodes = User->country_codes;
2471
2472   $countrycodes{""} = "American English";
2473   $form->{COUNTRYCODES} = [];
2474   foreach $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
2475     push @{ $form->{COUNTRYCODES} }, {
2476       'name'     => $countrycodes{$countrycode},
2477       'value'    => $countrycode,
2478       'selected' => $countrycode eq $myconfig{countrycode},
2479     };
2480   }
2481
2482   $form->{STYLESHEETS} = [];
2483   foreach $item (qw(lx-office-erp.css Win2000.css)) {
2484     push @{ $form->{STYLESHEETS} }, {
2485       'name'     => $item,
2486       'value'    => $item,
2487       'selected' => $item eq $myconfig{stylesheet},
2488     };
2489   }
2490
2491   $myconfig{show_form_details}              = 1 unless (defined($myconfig{show_form_details}));
2492   $form->{"menustyle_$myconfig{menustyle}"} = 1;
2493   $form->{CAN_CHANGE_PASSWORD}              = $auth->can_change_password();
2494
2495   $form->{title}                            = $locale->text('Edit Preferences for #1', $form->{login});
2496
2497   $form->header();
2498   print $form->parse_html_template('am/config');
2499
2500   $lxdebug->leave_sub();
2501 }
2502
2503 sub save_preferences {
2504   $lxdebug->enter_sub();
2505
2506   $form->{stylesheet} = $form->{usestylesheet};
2507
2508   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, $webdav));
2509   $form->error($locale->text('Cannot save preferences!'));
2510
2511   $lxdebug->leave_sub();
2512 }
2513
2514 sub audit_control {
2515   $lxdebug->enter_sub();
2516
2517   $auth->assert('config');
2518
2519   $form->{title} = $locale->text('Audit Control');
2520
2521   AM->closedto(\%myconfig, \%$form);
2522
2523   if ($form->{revtrans}) {
2524     $checked{Y} = "checked";
2525   } else {
2526     $checked{N} = "checked";
2527   }
2528
2529   $form->header;
2530
2531   print qq|
2532 <body>
2533
2534 <form method=post action=am.pl>
2535
2536 <table width=100%>
2537   <tr><th class=listtop>$form->{title}</th></tr>
2538   <tr height="5"></tr>
2539   <tr>
2540     <td>
2541       <table>
2542         <tr>
2543           <td>|
2544     . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
2545           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
2546     . $locale->text('Yes')
2547     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
2548     . $locale->text('No')
2549     . qq|</td>
2550         </tr>
2551         <tr>
2552           <th>| . $locale->text('Close Books up to') . qq|</th>
2553           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
2554         </tr>
2555       </table>
2556     </td>
2557   </tr>
2558 </table>
2559
2560 <hr size=3 noshade>
2561
2562 <br>
2563 <input type=hidden name=nextsub value=doclose>
2564
2565 <input type=submit class=submit name=action value="|
2566     . $locale->text('Continue') . qq|">
2567
2568 </form>
2569
2570 </body>
2571 </html>
2572 |;
2573
2574   $lxdebug->leave_sub();
2575 }
2576
2577 sub doclose {
2578   $lxdebug->enter_sub();
2579
2580   $auth->assert('config');
2581
2582   AM->closebooks(\%myconfig, \%$form);
2583
2584   if ($form->{revtrans}) {
2585     $form->redirect(
2586                  $locale->text('Transaction reversal enforced for all dates'));
2587   } else {
2588     if ($form->{closedto}) {
2589       $form->redirect(
2590                      $locale->text('Transaction reversal enforced up to') . " "
2591                        . $locale->date(\%myconfig, $form->{closedto}, 1));
2592     } else {
2593       $form->redirect($locale->text('Books are open'));
2594     }
2595   }
2596
2597   $lxdebug->leave_sub();
2598 }
2599
2600 sub edit_units {
2601   $lxdebug->enter_sub();
2602
2603   $auth->assert('config');
2604
2605   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
2606   AM->units_in_use(\%myconfig, $form, $units);
2607   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
2608
2609   @languages = AM->language(\%myconfig, $form, 1);
2610
2611   @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
2612
2613   my $i = 1;
2614   foreach (@unit_list) {
2615     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
2616     $_->{"UNITLANGUAGES"} = [];
2617     foreach my $lang (@languages) {
2618       push(@{ $_->{"UNITLANGUAGES"} },
2619            { "idx" => $i,
2620              "unit" => $_->{"name"},
2621              "language_id" => $lang->{"id"},
2622              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
2623              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
2624            });
2625     }
2626     $i++;
2627   }
2628
2629   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
2630   $ddbox = AM->unit_select_data($units, undef, 1);
2631
2632   my $updownlink = build_std_url("action=swap_units", "unit_type");
2633
2634   $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
2635   $form->header();
2636   print($form->parse_html_template("am/edit_units",
2637                                    { "UNITS"               => \@unit_list,
2638                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
2639                                      "LANGUAGES"           => \@languages,
2640                                      "updownlink"          => $updownlink }));
2641
2642   $lxdebug->leave_sub();
2643 }
2644
2645 sub add_unit {
2646   $lxdebug->enter_sub();
2647
2648   $auth->assert('config');
2649
2650   $form->isblank("new_name", $locale->text("The name is missing."));
2651   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
2652   $all_units = AM->retrieve_units(\%myconfig, $form);
2653   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
2654
2655   my ($base_unit, $factor);
2656   if ($form->{"new_base_unit"}) {
2657     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
2658
2659     $form->isblank("new_factor", $locale->text("The factor is missing."));
2660     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
2661     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
2662     $base_unit = $form->{"new_base_unit"};
2663   }
2664
2665   my @languages;
2666   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
2667     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
2668     push(@languages, { "id" => $lang->{"id"},
2669                        "localized" => $form->{"new_localized_$lang->{id}"},
2670                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
2671          });
2672   }
2673
2674   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages);
2675
2676   $form->{"saved_message"} = $locale->text("The unit has been saved.");
2677
2678   edit_units();
2679
2680   $lxdebug->leave_sub();
2681 }
2682
2683 sub set_unit_languages {
2684   $lxdebug->enter_sub();
2685
2686   $auth->assert('config');
2687
2688   my ($unit, $languages, $idx) = @_;
2689
2690   $unit->{"LANGUAGES"} = [];
2691
2692   foreach my $lang (@{$languages}) {
2693     push(@{ $unit->{"LANGUAGES"} },
2694          { "id" => $lang->{"id"},
2695            "localized" => $form->{"localized_${idx}_$lang->{id}"},
2696            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
2697          });
2698   }
2699
2700   $lxdebug->leave_sub();
2701 }
2702
2703 sub save_unit {
2704   $lxdebug->enter_sub();
2705
2706   $auth->assert('config');
2707
2708   $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
2709   AM->units_in_use(\%myconfig, $form, $old_units);
2710
2711   @languages = AM->language(\%myconfig, $form, 1);
2712
2713   $new_units = {};
2714   @delete_units = ();
2715   foreach $i (1..($form->{"rowcount"} * 1)) {
2716     $old_unit = $old_units->{$form->{"old_name_$i"}};
2717     if (!$old_unit) {
2718       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
2719     }
2720
2721     if ($form->{"unchangeable_$i"}) {
2722       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
2723       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
2724       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
2725       next;
2726     }
2727
2728     if ($old_unit->{"in_use"}) {
2729       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
2730     }
2731
2732     if ($form->{"delete_$i"}) {
2733       push(@delete_units, $old_unit->{"name"});
2734       next;
2735     }
2736
2737     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
2738
2739     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
2740     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
2741     $new_units->{$form->{"name_$i"}} = \%h;
2742     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
2743     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
2744   }
2745
2746   foreach $unit (values(%{$new_units})) {
2747     next unless ($unit->{"old_name"});
2748     if ($unit->{"base_unit"}) {
2749       $form->show_generic_error(sprintf($locale->text("The base unit does not exist or it is about to be deleted in row %d."), $unit->{"row"}))
2750         unless (defined($new_units->{$unit->{"base_unit"}}));
2751       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
2752       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
2753     } else {
2754       $unit->{"base_unit"} = undef;
2755       $unit->{"factor"} = undef;
2756     }
2757   }
2758
2759   foreach $unit (values(%{$new_units})) {
2760     next if ($unit->{"unchanged_unit"});
2761
2762     map({ $_->{"seen"} = 0; } values(%{$new_units}));
2763     $new_unit = $unit;
2764     while ($new_unit->{"base_unit"}) {
2765       $new_unit->{"seen"} = 1;
2766       $new_unit = $new_units->{$new_unit->{"base_unit"}};
2767       if ($new_unit->{"seen"}) {
2768         $form->show_generic_error(sprintf($locale->text("The base unit relations must not contain loops (e.g. by saying that unit A's base unit is B, " .
2769                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
2770       }
2771     }
2772   }
2773
2774   AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
2775
2776   $form->{"saved_message"} = $locale->text("The units have been saved.");
2777
2778   edit_units();
2779
2780   $lxdebug->leave_sub();
2781 }
2782
2783 sub show_history_search {
2784         $lxdebug->enter_sub();
2785         
2786   $auth->assert('config');
2787
2788         $form->{title} = $locale->text("History Search");
2789     $form->header();
2790     
2791     print $form->parse_html_template("common/search_history");
2792         
2793         $lxdebug->leave_sub();
2794 }
2795
2796 sub show_am_history {
2797         $lxdebug->enter_sub();
2798
2799   $auth->assert('config');
2800
2801         my %search = ( "Artikelnummer" => "parts",
2802                                    "Kundennummer"  => "customer",
2803                                    "Lieferantennummer" => "vendor",
2804                                    "Projektnummer" => "project",
2805                                    "Buchungsnummer" => "oe",
2806                                    "Eingangsrechnungnummer" => "ap",
2807                                    "Ausgangsrechnungnummer" => "ar",
2808            "Mahnungsnummer" => "dunning"
2809                 );
2810         my %searchNo = ( "Artikelnummer" => "partnumber",
2811                                      "Kundennummer"  => "customernumber",
2812                                      "Lieferantennummer" => "vendornumber",
2813                                      "Projektnummer" => "projectnummer",
2814                                      "Buchungsnummer" => "ordnumber",
2815                                      "Eingangsrechnungnummer" => "invnumber",
2816                                      "Ausgangsrechnungnummer" => "invnumber",
2817              "Mahnungsnummer" => "dunning_id"
2818                 );
2819         
2820         my $restriction;
2821         my $tempNo = 0;
2822         foreach(split(/\,/, $form->{einschraenkungen})) {
2823                 if($tempNo == 0) {
2824                         $restriction .= " AND addition = '" . $_ . "'";
2825                         $tempNo = 1;
2826                 } 
2827                 else {
2828                         $restriction .= " OR addition = '" . $_ . "'";
2829                 }
2830         }
2831         $restriction .= (($form->{transdate} ne "" && $form->{reqdate} ne "") 
2832                                                 ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|' AND st.itime::date <= '| . $form->{reqdate} . qq|'|
2833                                                 : (($form->{transdate} ne "" && $form->{reqdate} eq "") 
2834                                                         ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|'|
2835                                                         : ($form->{transdate} eq "" && $form->{reqdate} ne "") 
2836                                                                 ? qq| AND st.itime::date <= '| . $form->{reqdate} . qq|'|
2837                                                                 : ""
2838                                                         )
2839                                                 );
2840   $restriction .= ($form->{mitarbeiter} eq "" ? "" 
2841           : ($form->{mitarbeiter} =~ /^[0-9]*$/  
2842             ? " AND employee_id = " . $form->{mitarbeiter} 
2843             : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
2844   
2845         my $dbh = $form->dbconnect(\%myconfig);
2846         my $query = qq|SELECT trans_id AS id FROM history_erp | . 
2847                 ($form->{'searchid'} ? 
2848                   qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'| : 
2849                   qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
2850
2851   my $sth = $dbh->prepare($query);
2852         
2853         $sth->execute() || $form->dberror($query);
2854   
2855   $form->{title} = $locale->text("History Search");
2856         $form->header();
2857         
2858   my $i = 1;
2859   my $daten = qq||;
2860   while(my $hash_ref = $sth->fetchrow_hashref()){
2861     if($i) {
2862       $daten .= $hash_ref->{id};
2863       $i = 0;
2864     }
2865     else {
2866       $daten .= " OR trans_id = " . $hash_ref->{id};
2867     }
2868   }
2869   
2870   my ($sort, $sortby) = split(/\-\-/, $form->{order});
2871   $sort =~ s/.*\.(.*)$/$1/;
2872
2873         print $form->parse_html_template("common/show_history", 
2874     {"DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
2875      "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
2876      "NONEWWINDOW" => 1,
2877      uc($sort) => 1,
2878      uc($sort)."BY" => $sortby
2879     });
2880         $dbh->disconnect();
2881   $lxdebug->leave_sub();
2882 }
2883
2884 sub get_employee_id {
2885         $lxdebug->enter_sub();
2886
2887   $auth->assert('config');
2888
2889         my $query = qq|SELECT id FROM employee WHERE name = '| . $_[0] . qq|'|;
2890         my $sth = $_[1]->prepare($query);
2891         $sth->execute() || $form->dberror($query);
2892         my $return = $sth->fetch();
2893         $sth->finish();
2894         return ${$return}[0];
2895         $lxdebug->leave_sub();
2896 }
2897
2898 sub swap_units {
2899   $lxdebug->enter_sub();
2900
2901   $auth->assert('config');
2902
2903   my $dir = $form->{"dir"} eq "down" ? "down" : "up";
2904   my $unit_type = $form->{"unit_type"} eq "dimension" ?
2905     "dimension" : "service";
2906   AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type);
2907
2908   edit_units();
2909
2910   $lxdebug->leave_sub();
2911 }
2912
2913 sub add_tax {
2914   $lxdebug->enter_sub();
2915
2916   $auth->assert('config');
2917
2918   $form->{title} =  $locale->text('Add');
2919
2920   $form->{callback} ||= "am.pl?action=add_tax";
2921
2922   _get_taxaccount_selection();
2923
2924   $form->header();
2925   
2926   my $parameters_ref = {
2927 #    ChartTypeIsAccount         => $ChartTypeIsAccount,
2928   };
2929   
2930   # Ausgabe des Templates
2931   print($form->parse_html_template('am/edit_tax', $parameters_ref));
2932
2933   $lxdebug->leave_sub();
2934 }
2935
2936 sub edit_tax {
2937   $lxdebug->enter_sub();
2938
2939   $auth->assert('config');
2940
2941   $form->{title} =  $locale->text('Edit');
2942
2943   AM->get_tax(\%myconfig, \%$form);
2944   _get_taxaccount_selection();
2945
2946   $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
2947
2948   $form->header();
2949   
2950   my $parameters_ref = {
2951   };
2952   
2953   # Ausgabe des Templates
2954   print($form->parse_html_template('am/edit_tax', $parameters_ref));
2955
2956   $lxdebug->leave_sub();
2957 }
2958
2959 sub list_tax {
2960   $lxdebug->enter_sub();
2961
2962   $auth->assert('config');
2963
2964   AM->taxes(\%myconfig, \%$form);
2965
2966   map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
2967
2968   $form->{callback} = build_std_url('action=list_tax');
2969
2970   $form->{title} = $locale->text('Tax-O-Matic');
2971
2972   $form->header();
2973   
2974   # Ausgabe des Templates
2975   print($form->parse_html_template('am/list_tax', $parameters_ref));
2976
2977   $lxdebug->leave_sub();
2978 }
2979
2980 sub _get_taxaccount_selection{
2981   $lxdebug->enter_sub();
2982
2983   $auth->assert('config');
2984
2985   AM->get_tax_accounts(\%myconfig, \%$form);
2986
2987   map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
2988
2989   $lxdebug->leave_sub();
2990 }
2991
2992 sub save_tax {
2993   $lxdebug->enter_sub();
2994
2995   $auth->assert('config');
2996
2997   $form->isblank("rate", $locale->text('Taxrate missing!'));
2998   $form->isblank("taxdescription", $locale->text('Taxdescription  missing!'));
2999   $form->isblank("taxkey", $locale->text('Taxkey  missing!'));
3000
3001   $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
3002
3003   if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
3004     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
3005   }
3006
3007   if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
3008     $form->error($locale->text('Tax Percent is a number between 0 and 100'));
3009   }  
3010
3011   AM->save_tax(\%myconfig, \%$form);
3012   $form->redirect($locale->text('Tax saved!'));
3013
3014   $lxdebug->leave_sub();
3015 }
3016
3017 sub delete_tax {
3018   $lxdebug->enter_sub();
3019
3020   $auth->assert('config');
3021
3022   AM->delete_tax(\%myconfig, \%$form);
3023   $form->redirect($locale->text('Tax deleted!'));
3024
3025   $lxdebug->leave_sub();
3026 }
3027
3028 sub add_price_factor {
3029   $lxdebug->enter_sub();
3030
3031   $auth->assert('config');
3032
3033   $form->{title}      = $locale->text('Add Price Factor');
3034   $form->{callback} ||= build_std_url('action=add_price_factor');
3035   $form->{fokus}      = 'description';
3036
3037   $form->header();
3038   print $form->parse_html_template('am/edit_price_factor');
3039
3040   $lxdebug->leave_sub();
3041 }
3042
3043 sub edit_price_factor {
3044   $lxdebug->enter_sub();
3045
3046   $auth->assert('config');
3047
3048   $form->{title}      = $locale->text('Edit Price Factor');
3049   $form->{callback} ||= build_std_url('action=add_price_factor');
3050   $form->{fokus}      = 'description';
3051
3052   AM->get_price_factor(\%myconfig, $form);
3053
3054   $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
3055
3056   $form->header();
3057   print $form->parse_html_template('am/edit_price_factor');
3058
3059   $lxdebug->leave_sub();
3060 }
3061
3062 sub list_price_factors {
3063   $lxdebug->enter_sub();
3064
3065   $auth->assert('config');
3066
3067   AM->get_all_price_factors(\%myconfig, \%$form);
3068
3069   my $previous;
3070   foreach my $current (@{ $form->{PRICE_FACTORS} }) {
3071     if ($previous) {
3072       $previous->{next_id}    = $current->{id};
3073       $current->{previous_id} = $previous->{id};
3074     }
3075
3076     $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
3077
3078     $previous = $current;
3079   }
3080
3081   $form->{callback} = build_std_url('action=list_price_factors');
3082   $form->{title}    = $locale->text('Price Factors');
3083   $form->{url_base} = build_std_url('callback');
3084
3085   $form->header();
3086   print $form->parse_html_template('am/list_price_factors');
3087
3088   $lxdebug->leave_sub();
3089 }
3090
3091 sub save_price_factor {
3092   $lxdebug->enter_sub();
3093
3094   $auth->assert('config');
3095
3096   $form->isblank("description", $locale->text('Description missing!'));
3097   $form->isblank("factor", $locale->text('Factor missing!'));
3098
3099   $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
3100
3101   AM->save_price_factor(\%myconfig, $form);
3102
3103   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
3104
3105   $form->redirect($locale->text('Price factor saved!'));
3106
3107   $lxdebug->leave_sub();
3108 }
3109
3110 sub delete_price_factor {
3111   $lxdebug->enter_sub();
3112
3113   $auth->assert('config');
3114
3115   AM->delete_price_factor(\%myconfig, \%$form);
3116
3117   $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
3118
3119   $form->redirect($locale->text('Price factor deleted!'));
3120
3121   $lxdebug->leave_sub();
3122 }
3123
3124 sub swap_price_factors {
3125   $lxdebug->enter_sub();
3126
3127   $auth->assert('config');
3128
3129   AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
3130   list_price_factors();
3131
3132   $lxdebug->leave_sub();
3133 }
3134