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