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