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