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