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