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