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