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