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