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