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