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