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