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