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