Buchungsgruppen: Bei aktivierter EUR muss das Inventarkonto automatisch ausgewaehlt...
[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   if ($eur) {
1716     $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
1717   }
1718
1719   &buchungsgruppe_header;
1720   &form_footer;
1721
1722   $lxdebug->leave_sub();
1723 }
1724
1725 sub edit_buchungsgruppe {
1726   $lxdebug->enter_sub();
1727
1728   $form->{title} = "Edit";
1729
1730   AM->get_buchungsgruppe(\%myconfig, \%$form);
1731
1732   &buchungsgruppe_header;
1733
1734   &form_footer;
1735
1736   $lxdebug->leave_sub();
1737 }
1738
1739 sub list_buchungsgruppe {
1740   $lxdebug->enter_sub();
1741
1742   AM->buchungsgruppe(\%myconfig, \%$form);
1743
1744   $form->{callback} =
1745     "$form->{script}?action=list_buchungsgruppe&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1746
1747   $callback = $form->escape($form->{callback});
1748
1749   $form->{title} = $locale->text('Buchungsgruppen');
1750
1751   @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 );
1752
1753   $column_header{description} =
1754       qq|<th class=listheading width=60%>|
1755     . $locale->text('Description')
1756     . qq|</th>|;
1757   $column_header{inventory_accno} =
1758       qq|<th class=listheading width=10%>|
1759     . $locale->text('Bestandskonto')
1760     . qq|</th>|;
1761   $column_header{income_accno_0} =
1762       qq|<th class=listheading>|
1763     . $locale->text('Erlöse Inland')
1764     . qq|</th>|;
1765   $column_header{expense_accno_0} =
1766       qq|<th class=listheading>|
1767     . $locale->text('Aufwand Inland')
1768     . qq|</th>|;
1769   $column_header{income_accno_1} =
1770       qq|<th class=listheading>|
1771     . $locale->text('Erlöse EU m. UStId')
1772     . qq|</th>|;
1773   $column_header{expense_accno_1} =
1774       qq|<th class=listheading>|
1775     . $locale->text('Aufwand EU m. UStId')
1776     . qq|</th>|;
1777   $column_header{income_accno_2} =
1778       qq|<th class=listheading>|
1779     . $locale->text('Erlöse EU o. UStId')
1780     . qq|</th>|;
1781   $column_header{expense_accno_2} =
1782       qq|<th class=listheading>|
1783     . $locale->text('Aufwand EU o. UStId')
1784     . qq|</th>|;
1785   $column_header{income_accno_3} =
1786       qq|<th class=listheading>|
1787     . $locale->text('Erlöse Ausland')
1788     . qq|</th>|;
1789   $column_header{expense_accno_3} =
1790       qq|<th class=listheading>|
1791     . $locale->text('Aufwand Ausland')
1792     . qq|</th>|;
1793   $form->header;
1794
1795   print qq|
1796 <body>
1797
1798 <table width=100%>
1799   <tr>
1800     <th class=listtop>$form->{title}</th>
1801   </tr>
1802   <tr height="5"></tr>
1803   <tr>
1804     <td>
1805       <table width=100%>
1806         <tr class=listheading>
1807 |;
1808
1809   map { print "$column_header{$_}\n" } @column_index;
1810
1811   print qq|
1812         </tr>
1813 |;
1814
1815   foreach $ref (@{ $form->{ALL} }) {
1816
1817     $i++;
1818     $i %= 2;
1819
1820     print qq|
1821         <tr valign=top class=listrow$i>
1822 |;
1823
1824
1825     $column_data{description} =
1826       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>|;
1827     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
1828     $column_data{income_accno_0} =
1829       qq|<td align=right>$ref->{income_accno_0}</td>|;
1830     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1831     $column_data{income_accno_1} =
1832       qq|<td align=right>$ref->{income_accno_1}</td>|;
1833     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1834     $column_data{income_accno_2} =
1835       qq|<td align=right>$ref->{income_accno_2}</td>|;
1836     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1837     $column_data{income_accno_3} =
1838       qq|<td align=right>$ref->{income_accno_3}</td>|;
1839     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1840
1841     map { print "$column_data{$_}\n" } @column_index;
1842
1843     print qq|
1844         </tr>
1845 |;
1846   }
1847
1848   print qq|
1849       </table>
1850     </td>
1851   </tr>
1852   <tr>
1853   <td><hr size=3 noshade></td>
1854   </tr>
1855 </table>
1856
1857 <br>
1858 <form method=post action=$form->{script}>
1859
1860 <input name=callback type=hidden value="$form->{callback}">
1861
1862 <input type=hidden name=type value=buchungsgruppe>
1863
1864 <input type=hidden name=path value=$form->{path}>
1865 <input type=hidden name=login value=$form->{login}>
1866 <input type=hidden name=password value=$form->{password}>
1867
1868 <input class=submit type=submit name=action value="|
1869     . $locale->text('Add') . qq|">|;
1870
1871   if ($form->{menubar}) {
1872     require "$form->{path}/menu.pl";
1873     &menubar;
1874   }
1875
1876   print qq|
1877
1878   </form>
1879
1880   </body>
1881   </html>
1882 |;
1883
1884   $lxdebug->leave_sub();
1885 }
1886
1887 sub buchungsgruppe_header {
1888   $lxdebug->enter_sub();
1889
1890   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
1891
1892   # $locale->text('Buchungsgruppe hinzufügen')
1893   # $locale->text('Buchungsgruppe bearbeiten')
1894
1895   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1896   my %acc_type_map = (
1897     "IC" => $acc_inventory,
1898     "IC_income" => $acc_income,
1899     "IC_sale" => $acc_income,
1900     "IC_expense" => $acc_expense,
1901     "IC_cogs" => $acc_expense,
1902     );
1903
1904   foreach $key (keys(%acc_type_map)) {
1905     foreach $ref (@{ $form->{IC_links}{$key} }) {
1906       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1907     }
1908   }
1909
1910   foreach my $type (qw(IC IC_income IC_expense)) {
1911     $form->{"select$type"} =
1912       join("",
1913            map({ "<option value=$_->{id} $_->{selected}>" .
1914                    "$_->{accno}--" . H($_->{description}) . "</option>" }
1915                sort({ $a->{"accno"} cmp $b->{"accno"} }
1916                     values(%{$acc_type_map{$type}}))));
1917   }
1918
1919   if ($form->{id}) {
1920     $form->{selectIC} =~ s/selected//g;
1921     $form->{selectIC} =~ s/ value=$form->{inventory_accno_id}/  value=$form->{inventory_accno_id} selected/;
1922     $form->{selectIC_income} =~ s/selected//g;
1923     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_0}/  value=$form->{income_accno_id_0} selected/;
1924     $form->{selectIC_expense} =~ s/selected//g;
1925     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_0}/  value=$form->{expense_accno_id_0} selected/;
1926   }
1927
1928   if (!$eur) {
1929     $linkaccounts = qq|
1930                <tr>
1931                 <th align=right>| . $locale->text('Inventory') . qq|</th>
1932                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
1933                 <input name=selectIC type=hidden value="$form->{selectIC}">
1934               </tr>|;
1935   } else {
1936     $linkaccounts = qq|
1937                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
1938   }
1939
1940
1941   $linkaccounts .= qq|
1942               <tr>
1943                 <th align=right>| . $locale->text('Erlöse Inland') . qq|</th>
1944                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
1945               </tr>
1946               <tr>
1947                 <th align=right>| . $locale->text('Aufwand Inland') . qq|</th>
1948                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
1949               </tr>|;
1950   if ($form->{id}) {
1951     $form->{selectIC_income} =~ s/selected//g;
1952     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_1}/  value=$form->{income_accno_id_1} selected/;
1953     $form->{selectIC_expense} =~ s/selected//g;
1954     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_1}/  value=$form->{expense_accno_id_1} selected/;
1955   }
1956   $linkaccounts .= qq|        <tr>
1957                 <th align=right>| . $locale->text('Erlöse EU m. UStId') . qq|</th>
1958                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
1959               </tr>
1960               <tr>
1961                 <th align=right>| . $locale->text('Aufwand EU m UStId') . qq|</th>
1962                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
1963               </tr>|;
1964
1965   if ($form->{id}) {
1966     $form->{selectIC_income} =~ s/selected//g;
1967     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_2}/  value=$form->{income_accno_id_2} selected/;
1968     $form->{selectIC_expense} =~ s/selected//g;
1969     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_2}/  value=$form->{expense_accno_id_2} selected/;
1970   }
1971
1972   $linkaccounts .= qq|        <tr>
1973                 <th align=right>| . $locale->text('Erlöse EU o. UStId') . qq|</th>
1974                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
1975               </tr>
1976               <tr>
1977                 <th align=right>| . $locale->text('Aufwand EU o. UStId') . qq|</th>
1978                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
1979               </tr>|;
1980
1981   if ($form->{id}) {
1982     $form->{selectIC_income} =~ s/selected//g;
1983     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_3}/  value=$form->{income_accno_id_3} selected/;
1984     $form->{selectIC_expense} =~ s/selected//g;
1985     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_3}/  value=$form->{expense_accno_id_3} selected/;
1986   }
1987
1988   $linkaccounts .= qq|        <tr>
1989                 <th align=right>| . $locale->text('Erlöse Ausland') . qq|</th>
1990                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
1991               </tr>
1992               <tr>
1993                 <th align=right>| . $locale->text('Aufwand Ausland') . qq|</th>
1994                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
1995               </tr>
1996 |;
1997
1998
1999   $form->header;
2000
2001   print qq|
2002 <body>
2003
2004 <form method=post action=$form->{script}>
2005
2006 <input type=hidden name=id value=$form->{id}>
2007 <input type=hidden name=type value=buchungsgruppe>
2008
2009 <table width=100%>
2010   <tr>
2011     <th class=listtop colspan=2>$form->{title}</th>
2012   </tr>
2013   <tr height="5"></tr>
2014   <tr>
2015     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
2016     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
2017   <tr>
2018   $linkaccounts
2019   <td colspan=2><hr size=3 noshade></td>
2020   </tr>
2021 </table>
2022 |;
2023
2024   $lxdebug->leave_sub();
2025 }
2026
2027 sub save_buchungsgruppe {
2028   $lxdebug->enter_sub();
2029
2030   $form->isblank("description", $locale->text('Description missing!'));
2031
2032   AM->save_buchungsgruppe(\%myconfig, \%$form);
2033   $form->redirect($locale->text('Buchungsgruppe gespeichert!'));
2034
2035   $lxdebug->leave_sub();
2036 }
2037
2038 sub delete_buchungsgruppe {
2039   $lxdebug->enter_sub();
2040
2041   AM->delete_buchungsgruppe(\%myconfig, \%$form);
2042   $form->redirect($locale->text('Buchungsgruppe gelöscht!'));
2043
2044   $lxdebug->leave_sub();
2045 }
2046
2047
2048 sub add_printer {
2049   $lxdebug->enter_sub();
2050
2051   $form->{title} = "Add";
2052
2053   $form->{callback} =
2054     "$form->{script}?action=add_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2055     unless $form->{callback};
2056
2057   &printer_header;
2058   &form_footer;
2059
2060   $lxdebug->leave_sub();
2061 }
2062
2063 sub edit_printer {
2064   $lxdebug->enter_sub();
2065
2066   $form->{title} = "Edit";
2067
2068   AM->get_printer(\%myconfig, \%$form);
2069
2070   &printer_header;
2071
2072   $form->{orphaned} = 1;
2073   &form_footer;
2074
2075   $lxdebug->leave_sub();
2076 }
2077
2078 sub list_printer {
2079   $lxdebug->enter_sub();
2080
2081   AM->printer(\%myconfig, \%$form);
2082
2083   $form->{callback} =
2084     "$form->{script}?action=list_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2085
2086   $callback = $form->escape($form->{callback});
2087
2088   $form->{title} = $locale->text('Printer');
2089
2090   @column_index = qw(printer_description printer_command template_code);
2091
2092   $column_header{printer_description} =
2093       qq|<th class=listheading width=60%>|
2094     . $locale->text('Printer Description')
2095     . qq|</th>|;
2096   $column_header{printer_command} =
2097       qq|<th class=listheading width=10%>|
2098     . $locale->text('Printer Command')
2099     . qq|</th>|;
2100   $column_header{template_code} =
2101       qq|<th class=listheading>|
2102     . $locale->text('Template Code')
2103     . qq|</th>|;
2104
2105   $form->header;
2106
2107   print qq|
2108 <body>
2109
2110 <table width=100%>
2111   <tr>
2112     <th class=listtop>$form->{title}</th>
2113   </tr>
2114   <tr height="5"></tr>
2115   <tr>
2116     <td>
2117       <table width=100%>
2118         <tr class=listheading>
2119 |;
2120
2121   map { print "$column_header{$_}\n" } @column_index;
2122
2123   print qq|
2124         </tr>
2125 |;
2126
2127   foreach $ref (@{ $form->{ALL} }) {
2128
2129     $i++;
2130     $i %= 2;
2131
2132     print qq|
2133         <tr valign=top class=listrow$i>
2134 |;
2135
2136
2137     $column_data{printer_description} =
2138       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>|;
2139     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
2140     $column_data{template_code} =
2141       qq|<td align=right>$ref->{template_code}</td>|;
2142
2143     map { print "$column_data{$_}\n" } @column_index;
2144
2145     print qq|
2146         </tr>
2147 |;
2148   }
2149
2150   print qq|
2151       </table>
2152     </td>
2153   </tr>
2154   <tr>
2155   <td><hr size=3 noshade></td>
2156   </tr>
2157 </table>
2158
2159 <br>
2160 <form method=post action=$form->{script}>
2161
2162 <input name=callback type=hidden value="$form->{callback}">
2163
2164 <input type=hidden name=type value=printer>
2165
2166 <input type=hidden name=path value=$form->{path}>
2167 <input type=hidden name=login value=$form->{login}>
2168 <input type=hidden name=password value=$form->{password}>
2169
2170 <input class=submit type=submit name=action value="|
2171     . $locale->text('Add') . qq|">|;
2172
2173   if ($form->{menubar}) {
2174     require "$form->{path}/menu.pl";
2175     &menubar;
2176   }
2177
2178   print qq|
2179
2180   </form>
2181
2182   </body>
2183   </html>
2184 |;
2185
2186   $lxdebug->leave_sub();
2187 }
2188
2189 sub printer_header {
2190   $lxdebug->enter_sub();
2191
2192   $form->{title}    = $locale->text("$form->{title} Printer");
2193
2194   # $locale->text('Add Printer')
2195   # $locale->text('Edit Printer')
2196
2197   $form->{printer_description} =~ s/\"/&quot;/g;
2198   $form->{template_code} =~ s/\"/&quot;/g;
2199   $form->{printer_command} =~ s/\"/&quot;/g;
2200
2201
2202   $form->header;
2203
2204   print qq|
2205 <body>
2206
2207 <form method=post action=$form->{script}>
2208
2209 <input type=hidden name=id value=$form->{id}>
2210 <input type=hidden name=type value=printer>
2211
2212 <table width=100%>
2213   <tr>
2214     <th class=listtop colspan=2>$form->{title}</th>
2215   </tr>
2216   <tr height="5"></tr>
2217   <tr>
2218     <th align=right>| . $locale->text('Printer') . qq|</th>
2219     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
2220   <tr>
2221   <tr>
2222     <th align=right>| . $locale->text('Printer Command') . qq|</th>
2223     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
2224   </tr>
2225   <tr>
2226     <th align=right>| . $locale->text('Template Code') . qq|</th>
2227     <td><input name=template_code size=5 value="$form->{template_code}"></td>
2228   </tr>
2229   <td colspan=2><hr size=3 noshade></td>
2230   </tr>
2231 </table>
2232 |;
2233
2234   $lxdebug->leave_sub();
2235 }
2236
2237 sub save_printer {
2238   $lxdebug->enter_sub();
2239
2240   $form->isblank("printer_description", $locale->text('Description missing!'));
2241   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
2242   AM->save_printer(\%myconfig, \%$form);
2243   $form->redirect($locale->text('Printer saved!'));
2244
2245   $lxdebug->leave_sub();
2246 }
2247
2248 sub delete_printer {
2249   $lxdebug->enter_sub();
2250
2251   AM->delete_printer(\%myconfig, \%$form);
2252   $form->redirect($locale->text('Printer deleted!'));
2253
2254   $lxdebug->leave_sub();
2255 }
2256
2257
2258 sub add_payment {
2259   $lxdebug->enter_sub();
2260
2261   $form->{title} = "Add";
2262
2263   $form->{callback} =
2264     "$form->{script}?action=add_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2265     unless $form->{callback};
2266
2267   &payment_header;
2268   &form_footer;
2269
2270   $lxdebug->leave_sub();
2271 }
2272
2273 sub edit_payment {
2274   $lxdebug->enter_sub();
2275
2276   $form->{title} = "Edit";
2277
2278   AM->get_payment(\%myconfig, \%$form);
2279
2280   &payment_header;
2281
2282   $form->{orphaned} = 1;
2283   &form_footer;
2284
2285   $lxdebug->leave_sub();
2286 }
2287
2288 sub list_payment {
2289   $lxdebug->enter_sub();
2290
2291   AM->payment(\%myconfig, \%$form);
2292
2293   $form->{callback} =
2294     "$form->{script}?action=list_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2295
2296   $callback = $form->escape($form->{callback});
2297
2298   $form->{title} = $locale->text('Payment Terms');
2299
2300   @column_index = qw(description description_long terms_netto terms_skonto percent_skonto);
2301
2302   $column_header{description} =
2303       qq|<th class=listheading>|
2304     . $locale->text('Description')
2305     . qq|</th>|;
2306   $column_header{description_long} =
2307       qq|<th class=listheading>|
2308     . $locale->text('Long Description')
2309     . qq|</th>|;
2310   $column_header{terms_netto} =
2311       qq|<th class=listheading>|
2312     . $locale->text('Netto Terms')
2313     . qq|</th>|;
2314   $column_header{terms_skonto} =
2315       qq|<th class=listheading>|
2316     . $locale->text('Skonto Terms')
2317     . qq|</th>|;
2318   $column_header{percent_skonto} =
2319       qq|<th class=listheading>|
2320     . $locale->text('Skonto')
2321     . qq| %</th>|;
2322
2323   $form->header;
2324
2325   print qq|
2326 <body>
2327
2328 <table width=100%>
2329   <tr>
2330     <th class=listtop>$form->{title}</th>
2331   </tr>
2332   <tr height="5"></tr>
2333   <tr>
2334     <td>
2335       <table width=100%>
2336         <tr class=listheading>
2337 |;
2338
2339   map { print "$column_header{$_}\n" } @column_index;
2340
2341   print qq|
2342         </tr>
2343 |;
2344
2345   foreach $ref (@{ $form->{ALL} }) {
2346
2347     $i++;
2348     $i %= 2;
2349
2350     print qq|
2351         <tr valign=top class=listrow$i>
2352 |;
2353
2354
2355     $column_data{description} =
2356       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>|;
2357     $column_data{description_long}           = qq|<td align=right>$ref->{description_long}</td>|;
2358     $column_data{terms_netto} =
2359       qq|<td align=right>$ref->{terms_netto}</td>|;
2360     $column_data{terms_skonto} =
2361       qq|<td align=right>$ref->{terms_skonto}</td>|;
2362     $column_data{percent_skonto} =
2363       qq|<td align=right>$ref->{percent_skonto} %</td>|;
2364     map { print "$column_data{$_}\n" } @column_index;
2365
2366     print qq|
2367         </tr>
2368 |;
2369   }
2370
2371   print qq|
2372       </table>
2373     </td>
2374   </tr>
2375   <tr>
2376   <td><hr size=3 noshade></td>
2377   </tr>
2378 </table>
2379
2380 <br>
2381 <form method=post action=$form->{script}>
2382
2383 <input name=callback type=hidden value="$form->{callback}">
2384
2385 <input type=hidden name=type value=business>
2386
2387 <input type=hidden name=path value=$form->{path}>
2388 <input type=hidden name=login value=$form->{login}>
2389 <input type=hidden name=password value=$form->{password}>
2390
2391 <input class=submit type=submit name=action value="|
2392     . $locale->text('Add') . qq|">|;
2393
2394   if ($form->{menubar}) {
2395     require "$form->{path}/menu.pl";
2396     &menubar;
2397   }
2398
2399   print qq|
2400
2401   </form>
2402
2403   </body>
2404   </html>
2405 |;
2406
2407   $lxdebug->leave_sub();
2408 }
2409
2410 sub payment_header {
2411   $lxdebug->enter_sub();
2412
2413   $form->{title}    = $locale->text("$form->{title} Payment Terms");
2414
2415   # $locale->text('Add Payment Terms')
2416   # $locale->text('Edit Payment Terms')
2417
2418   $form->{description} =~ s/\"/&quot;/g;
2419
2420
2421
2422   $form->header;
2423
2424   print qq|
2425 <body>
2426
2427 <form method=post action=$form->{script}>
2428
2429 <input type=hidden name=id value=$form->{id}>
2430 <input type=hidden name=type value=payment>
2431
2432 <table width=100%>
2433   <tr>
2434     <th class=listtop colspan=2>$form->{title}</th>
2435   </tr>
2436   <tr height="5"></tr>
2437   <tr>
2438     <th align=right>| . $locale->text('Description') . qq|</th>
2439     <td><input name=description size=30 value="$form->{description}"></td>
2440   <tr>
2441   <tr>
2442     <th align=right>| . $locale->text('Ranking') . qq|</th>
2443     <td><input name=ranking size=30 value="$form->{ranking}"></td>
2444   <tr>
2445   <tr>
2446     <th align=right>| . $locale->text('Long Description') . qq|</th>
2447     <td><input name=description_long size=50 value="$form->{description_long}"></td>
2448   </tr>
2449   <tr>
2450     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
2451     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
2452   </tr>
2453   <tr>
2454     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
2455     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
2456   </tr>  
2457   <tr>
2458     <th align=right>| . $locale->text('Skonto') . qq| %</th>
2459     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
2460   </tr> 
2461   <td colspan=2><hr size=3 noshade></td>
2462   </tr>
2463 </table>
2464 |;
2465
2466   $lxdebug->leave_sub();
2467 }
2468
2469 sub save_payment {
2470   $lxdebug->enter_sub();
2471
2472   $form->isblank("description", $locale->text('Language missing!'));
2473   AM->save_payment(\%myconfig, \%$form);
2474   $form->redirect($locale->text('Payment Terms saved!'));
2475
2476   $lxdebug->leave_sub();
2477 }
2478
2479 sub delete_payment {
2480   $lxdebug->enter_sub();
2481
2482   AM->delete_payment(\%myconfig, \%$form);
2483   $form->redirect($locale->text('Payment terms deleted!'));
2484
2485   $lxdebug->leave_sub();
2486 }
2487
2488 sub add_sic {
2489   $lxdebug->enter_sub();
2490
2491   $form->{title} = "Add";
2492
2493   $form->{callback} =
2494     "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2495     unless $form->{callback};
2496
2497   &sic_header;
2498   &form_footer;
2499
2500   $lxdebug->leave_sub();
2501 }
2502
2503 sub edit_sic {
2504   $lxdebug->enter_sub();
2505
2506   $form->{title} = "Edit";
2507
2508   AM->get_sic(\%myconfig, \%$form);
2509
2510   &sic_header;
2511
2512   $form->{orphaned} = 1;
2513   &form_footer;
2514
2515   $lxdebug->leave_sub();
2516 }
2517
2518 sub list_sic {
2519   $lxdebug->enter_sub();
2520
2521   AM->sic(\%myconfig, \%$form);
2522
2523   $form->{callback} =
2524     "$form->{script}?action=list_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2525
2526   $callback = $form->escape($form->{callback});
2527
2528   $form->{title} = $locale->text('Standard Industrial Codes');
2529
2530   @column_index = qw(code description);
2531
2532   $column_header{code} =
2533     qq|<th class=listheading>| . $locale->text('Code') . qq|</th>|;
2534   $column_header{description} =
2535     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
2536
2537   $form->header;
2538
2539   print qq|
2540 <body>
2541
2542 <table width=100%>
2543   <tr>
2544     <th class=listtop>$form->{title}</th>
2545   </tr>
2546   <tr height="5"></tr>
2547   <tr>
2548     <td>
2549       <table width=100%>
2550         <tr class=listheading>
2551 |;
2552
2553   map { print "$column_header{$_}\n" } @column_index;
2554
2555   print qq|
2556         </tr>
2557 |;
2558
2559   foreach $ref (@{ $form->{ALL} }) {
2560
2561     $i++;
2562     $i %= 2;
2563
2564     if ($ref->{sictype} eq 'H') {
2565       print qq|
2566         <tr valign=top class=listheading>
2567 |;
2568       $column_data{code} =
2569         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>|;
2570       $column_data{description} = qq|<th>$ref->{description}</th>|;
2571
2572     } else {
2573       print qq|
2574         <tr valign=top class=listrow$i>
2575 |;
2576
2577       $column_data{code} =
2578         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>|;
2579       $column_data{description} = qq|<td>$ref->{description}</td>|;
2580
2581     }
2582
2583     map { print "$column_data{$_}\n" } @column_index;
2584
2585     print qq|
2586         </tr>
2587 |;
2588   }
2589
2590   print qq|
2591       </table>
2592     </td>
2593   </tr>
2594   <tr>
2595   <td><hr size=3 noshade></td>
2596   </tr>
2597 </table>
2598
2599 <br>
2600 <form method=post action=$form->{script}>
2601
2602 <input name=callback type=hidden value="$form->{callback}">
2603
2604 <input type=hidden name=type value=sic>
2605
2606 <input type=hidden name=path value=$form->{path}>
2607 <input type=hidden name=login value=$form->{login}>
2608 <input type=hidden name=password value=$form->{password}>
2609
2610 <input class=submit type=submit name=action value="|
2611     . $locale->text('Add') . qq|">|;
2612
2613   if ($form->{menubar}) {
2614     require "$form->{path}/menu.pl";
2615     &menubar;
2616   }
2617
2618   print qq|
2619   </form>
2620
2621   </body>
2622   </html>
2623 |;
2624
2625   $lxdebug->leave_sub();
2626 }
2627
2628 sub sic_header {
2629   $lxdebug->enter_sub();
2630
2631   $form->{title} = $locale->text("$form->{title} SIC");
2632
2633   # $locale->text('Add SIC')
2634   # $locale->text('Edit SIC')
2635
2636   $form->{code}        =~ s/\"/&quot;/g;
2637   $form->{description} =~ s/\"/&quot;/g;
2638
2639   $checked = ($form->{sictype} eq 'H') ? "checked" : "";
2640
2641   $form->header;
2642
2643   print qq|
2644 <body>
2645
2646 <form method=post action=$form->{script}>
2647
2648 <input type=hidden name=type value=sic>
2649 <input type=hidden name=id value=$form->{code}>
2650
2651 <table width=100%>
2652   <tr>
2653     <th class=listtop colspan=2>$form->{title}</th>
2654   </tr>
2655   <tr height="5"></tr>
2656   <tr>
2657     <th align=right>| . $locale->text('Code') . qq|</th>
2658     <td><input name=code size=10 value=$form->{code}></td>
2659   <tr>
2660   <tr>
2661     <td></td>
2662     <th align=left><input name=sictype type=checkbox style=checkbox value="H" $checked> |
2663     . $locale->text('Heading') . qq|</th>
2664   <tr>
2665   <tr>
2666     <th align=right>| . $locale->text('Description') . qq|</th>
2667     <td><input name=description size=60 value="$form->{description}"></td>
2668   </tr>
2669     <td colspan=2><hr size=3 noshade></td>
2670   </tr>
2671 </table>
2672 |;
2673
2674   $lxdebug->leave_sub();
2675 }
2676
2677 sub save_sic {
2678   $lxdebug->enter_sub();
2679
2680   $form->isblank("code",        $locale->text('Code missing!'));
2681   $form->isblank("description", $locale->text('Description missing!'));
2682   AM->save_sic(\%myconfig, \%$form);
2683   $form->redirect($locale->text('SIC saved!'));
2684
2685   $lxdebug->leave_sub();
2686 }
2687
2688 sub delete_sic {
2689   $lxdebug->enter_sub();
2690
2691   AM->delete_sic(\%myconfig, \%$form);
2692   $form->redirect($locale->text('SIC deleted!'));
2693
2694   $lxdebug->leave_sub();
2695 }
2696
2697 sub display_stylesheet {
2698   $lxdebug->enter_sub();
2699
2700   $form->{file} = "css/$myconfig{stylesheet}";
2701   &display_form;
2702
2703   $lxdebug->leave_sub();
2704 }
2705
2706 sub display_form {
2707   $lxdebug->enter_sub();
2708
2709   $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
2710   $form->{file} =~ s/^\/*//g;
2711   $form->{file} =~ s/$userspath//;
2712
2713   $form->error("$!: $form->{file}") unless -f $form->{file};
2714
2715   AM->load_template(\%$form);
2716
2717   $form->{title} = $form->{file};
2718
2719   # if it is anything but html
2720   if ($form->{file} !~ /\.html$/) {
2721     $form->{body} = "<pre>\n$form->{body}\n</pre>";
2722   }
2723
2724   $form->header;
2725
2726   print qq|
2727 <body>
2728
2729 $form->{body}
2730
2731 <form method=post action=$form->{script}>
2732
2733 <input name=file type=hidden value=$form->{file}>
2734 <input name=type type=hidden value=template>
2735
2736 <input type=hidden name=path value=$form->{path}>
2737 <input type=hidden name=login value=$form->{login}>
2738 <input type=hidden name=password value=$form->{password}>
2739
2740 <input name=action type=submit class=submit value="|
2741     . $locale->text('Edit') . qq|">|;
2742
2743   if ($form->{menubar}) {
2744     require "$form->{path}/menu.pl";
2745     &menubar;
2746   }
2747
2748   print qq|
2749   </form>
2750
2751 </body>
2752 </html>
2753 |;
2754
2755   $lxdebug->leave_sub();
2756 }
2757
2758 sub edit_template {
2759   $lxdebug->enter_sub();
2760
2761   AM->load_template(\%$form);
2762
2763   $form->{title} = $locale->text('Edit Template');
2764
2765   # convert &nbsp to &amp;nbsp;
2766   $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
2767
2768   $form->header;
2769
2770   print qq|
2771 <body>
2772
2773 <form method=post action=$form->{script}>
2774
2775 <input name=file type=hidden value=$form->{file}>
2776 <input name=type type=hidden value=template>
2777
2778 <input type=hidden name=path value=$form->{path}>
2779 <input type=hidden name=login value=$form->{login}>
2780 <input type=hidden name=password value=$form->{password}>
2781
2782 <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}">
2783
2784 <textarea name=body rows=25 cols=70>
2785 $form->{body}
2786 </textarea>
2787
2788 <br>
2789 <input type=submit class=submit name=action value="|
2790     . $locale->text('Save') . qq|">|;
2791
2792   if ($form->{menubar}) {
2793     require "$form->{path}/menu.pl";
2794     &menubar;
2795   }
2796
2797   print q|
2798   </form>
2799
2800
2801 </body>
2802 </html>
2803 |;
2804
2805   $lxdebug->leave_sub();
2806 }
2807
2808 sub save_template {
2809   $lxdebug->enter_sub();
2810
2811   AM->save_template(\%$form);
2812   $form->redirect($locale->text('Template saved!'));
2813
2814   $lxdebug->leave_sub();
2815 }
2816
2817 sub config {
2818   $lxdebug->enter_sub();
2819
2820   # get defaults for account numbers and last numbers
2821   AM->defaultaccounts(\%myconfig, \%$form);
2822
2823   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
2824     $dateformat .=
2825       ($item eq $myconfig{dateformat})
2826       ? "<option selected>$item\n"
2827       : "<option>$item\n";
2828   }
2829
2830   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
2831     $numberformat .=
2832       ($item eq $myconfig{numberformat})
2833       ? "<option selected>$item\n"
2834       : "<option>$item\n";
2835   }
2836
2837   foreach $item (qw(name company address signature)) {
2838     $myconfig{$item} =~ s/\"/&quot;/g;
2839   }
2840
2841   foreach $item (qw(address signature)) {
2842     $myconfig{$item} =~ s/\\n/\r\n/g;
2843   }
2844
2845   %countrycodes = User->country_codes;
2846   $countrycodes = '';
2847   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} }
2848                 keys %countrycodes
2849     ) {
2850     $countrycodes .=
2851       ($myconfig{countrycode} eq $key)
2852       ? "<option selected value=$key>$countrycodes{$key}\n"
2853       : "<option value=$key>$countrycodes{$key}\n";
2854   }
2855   $countrycodes = "<option>American English\n$countrycodes";
2856
2857   # use an other input number format than output numberformat
2858   # look at Form.pm, sub parse_amount
2859   my $in_numberformat = '';
2860   $text1 = qq|value="0">| . $locale->text('equal Outputformat');
2861   $text2 = qq|value="1">| . $locale->text('1000,00 or 1000.00');
2862   @in_nf = ($text1, $text2);
2863   foreach $item (@in_nf) {
2864     $in_numberformat .=
2865       (substr($item, 7, 1) eq $myconfig{in_numberformat})
2866       ? "<option selected $item\n"
2867       : "<option $item\n";
2868   }
2869
2870   foreach $key (keys %{ $form->{IC} }) {
2871     foreach $accno (sort keys %{ $form->{IC}{$key} }) {
2872       $myconfig{$key} .=
2873         ($form->{IC}{$key}{$accno}{id} == $form->{defaults}{$key})
2874         ? "<option selected>$accno--$form->{IC}{$key}{$accno}{description}\n"
2875         : "<option>$accno--$form->{IC}{$key}{$accno}{description}\n";
2876     }
2877   }
2878
2879   opendir CSS, "css/.";
2880   @all = grep /.*\.css$/, readdir CSS;
2881   closedir CSS;
2882
2883   foreach $item (@all) {
2884     if ($item eq $myconfig{stylesheet}) {
2885       $selectstylesheet .= qq|<option selected>$item\n|;
2886     } else {
2887       $selectstylesheet .= qq|<option>$item\n|;
2888     }
2889   }
2890   $selectstylesheet .= "<option>\n";
2891
2892   $form->{title} = $locale->text('Edit Preferences for') . qq| $form->{login}|;
2893
2894   $form->header;
2895
2896   if ($myconfig{menustyle} eq "old") { $oldS = "checked"; }
2897   else { $newS = "checked"; }
2898
2899   print qq|
2900 <body>
2901
2902 <form method=post action=$form->{script}>
2903
2904 <input type=hidden name=old_password value=$myconfig{password}>
2905 <input type=hidden name=type value=preferences>
2906 <input type=hidden name=role value=$myconfig{role}>
2907
2908 <table width=100%>
2909   <tr><th class=listtop>$form->{title}</th></tr>
2910   <tr>
2911     <td>
2912       <table>
2913         <tr>
2914           <th align=right>| . $locale->text('Name') . qq|</th>
2915           <td><input name=name size=15 value="$myconfig{name}"></td>
2916         </tr>
2917         <tr>
2918           <th align=right>| . $locale->text('Password') . qq|</th>
2919           <td><input type=password name=new_password size=10 value=$myconfig{password}></td>
2920         </tr>
2921         <tr>
2922           <th align=right>| . $locale->text('E-mail') . qq|</th>
2923           <td><input name=email size=30 value="$myconfig{email}"></td>
2924         </tr>
2925         <tr valign=top>
2926           <th align=right>| . $locale->text('Signature') . qq|</th>
2927           <td><textarea name=signature rows=3 cols=50>$myconfig{signature}</textarea></td>
2928         </tr>
2929         <tr>
2930           <th align=right>| . $locale->text('Phone') . qq|</th>
2931           <td><input name=tel size=14 value="$myconfig{tel}"></td>
2932         </tr>
2933         <tr>
2934           <th align=right>| . $locale->text('Fax') . qq|</th>
2935           <td><input name=fax size=14 value="$myconfig{fax}"></td>
2936         </tr>
2937         <tr>
2938           <th align=right>| . $locale->text('Company') . qq|</th>
2939           <td><input name=company size=30 value="$myconfig{company}"></td>
2940         </tr>
2941         <tr valign=top>
2942           <th align=right>| . $locale->text('Address') . qq|</th>
2943           <td><textarea name=address rows=4 cols=50>$myconfig{address}</textarea></td>
2944         </tr>
2945         <tr>
2946           <th align=right>| . $locale->text('Date Format') . qq|</th>
2947           <td><select name=dateformat>$dateformat</select></td>
2948         </tr>
2949         <tr>
2950           <th align=right>| . $locale->text('Output Number Format') . qq|</th>
2951           <td><select name=numberformat>$numberformat</select></td>
2952         </tr>
2953         <tr>
2954           <th align=right>| . $locale->text('Input Number Format') . qq|</th>
2955           <td><select name=in_numberformat>$in_numberformat</select></td>
2956         </tr>
2957
2958         <tr>
2959           <th align=right>| . $locale->text('Dropdown Limit') . qq|</th>
2960           <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
2961         </tr>
2962         <tr>
2963           <th align=right>| . $locale->text('Language') . qq|</th>
2964           <td><select name=countrycode>$countrycodes</select></td>
2965         </tr>
2966         <tr>
2967           <th align=right>| . $locale->text('Stylesheet') . qq|</th>
2968           <td><select name=usestylesheet>$selectstylesheet</select></td>
2969         </tr>
2970         <tr>
2971           <th align=right>| . $locale->text('Setup Menu') . qq|</th>
2972           <td><input name=menustyle type=radio class=radio value=neu $newS>&nbsp;New
2973                   <input name=menustyle type=radio class=radio value=old $oldS>&nbsp;Old</td>
2974         </tr>   
2975         <input name=printer type=hidden value="$myconfig{printer}">
2976         <tr class=listheading>
2977           <th colspan=2>&nbsp;</th>
2978         </tr>
2979         <tr>
2980           <th align=right>| . $locale->text('Business Number') . qq|</th>
2981           <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td>
2982         </tr>
2983         <tr>
2984           <td colspan=2>
2985             <table width=100%>
2986               <tr>
2987                 <th align=right>| . $locale->text('Year End') . qq| (mm/dd)</th>
2988                 <td><input name=yearend size=5 value=$form->{defaults}{yearend}></td>
2989                 <th align=right>| . $locale->text('Weight Unit') . qq|</th>
2990                 <td><input name=weightunit size=5 value="$form->{defaults}{weightunit}"></td>
2991               </tr>
2992             </table>
2993           </td>
2994         </tr>
2995         <tr class=listheading>
2996           <th colspan=2>|
2997     . $locale->text('Last Numbers & Default Accounts') . qq|</th>
2998         </tr>
2999         <tr>
3000           <td colspan=2>
3001             <table width=100%>
3002               <tr>
3003                 <th align=right nowrap>| . $locale->text('Inventory Account') . qq|</th>
3004                 <td><select name=inventory_accno>$myconfig{IC}</select></td>
3005               </tr>
3006               <tr>
3007                 <th align=right nowrap>| . $locale->text('Revenue Account') . qq|</th>
3008                 <td><select name=income_accno>$myconfig{IC_income}</select></td>
3009               </tr>
3010               <tr>
3011                 <th align=right nowrap>| . $locale->text('Expense Account') . qq|</th>
3012                 <td><select name=expense_accno>$myconfig{IC_expense}</select></td>
3013               </tr>
3014               <tr>
3015                 <th align=right nowrap>| . $locale->text('Foreign Exchange Gain') . qq|</th>
3016                 <td><select name=fxgain_accno>$myconfig{FX_gain}</select></td>
3017               </tr>
3018               <tr>
3019                 <th align=right nowrap>| . $locale->text('Foreign Exchange Loss') . qq|</th>
3020                 <td><select name=fxloss_accno>$myconfig{FX_loss}</select></td>
3021               </tr>
3022               <tr>
3023                 <td colspan=2>|
3024     . $locale->text(
3025     'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
3026     )
3027     . qq|<br><input name=curr size=40 value="$form->{defaults}{curr}"></td>
3028               </tr>
3029             </table>
3030           </td>
3031          </tr>
3032          <tr>
3033            <td colspan=2>
3034              <table width=100%>
3035               <tr>
3036                 <th align=right nowrap>| . $locale->text('Last Invoice Number') . qq|</th>
3037                 <td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></td>
3038                 <th align=right nowrap>|
3039     . $locale->text('Last Customer Number') . qq|</th>
3040                 <td><input name=customernumber size=10 value=$form->{defaults}{customernumber}></td>
3041               </tr>
3042               <tr>
3043                 <th align=right nowrap>|
3044     . $locale->text('Last Credit Note Number') . qq|</th>
3045                 <td><input name=cnnumber size=10 value=$form->{defaults}{cnnumber}></td>
3046                 <th align=right nowrap>|
3047     . $locale->text('Last Vendor Number') . qq|</th>
3048                 <td><input name=vendornumber size=10 value=$form->{defaults}{vendornumber}></td>
3049               </tr>
3050               <tr>
3051                 <th align=right nowrap>|
3052     . $locale->text('Last Sales Order Number') . qq|</th>
3053                 <td><input name=sonumber size=10 value=$form->{defaults}{sonumber}></td>
3054               </tr>
3055               <tr>
3056                 <th align=right nowrap>|
3057     . $locale->text('Last Purchase Order Number') . qq|</th>
3058                 <td><input name=ponumber size=10 value=$form->{defaults}{ponumber}></td>
3059                 <th align=right nowrap>|
3060     . $locale->text('Last Article Number') . qq|</th>
3061                 <td><input name=articlenumber size=10 value=$form->{defaults}{articlenumber}></td>
3062               </tr>
3063               <tr>
3064                 <th align=right nowrap>|
3065     . $locale->text('Last Sales Quotation Number') . qq|</th>
3066                 <td><input name=sqnumber size=10 value=$form->{defaults}{sqnumber}></td>
3067                 <th align=right nowrap>|
3068     . $locale->text('Last Service Number') . qq|</th>
3069                 <td><input name=servicenumber size=10 value=$form->{defaults}{servicenumber}></td>
3070               </tr>
3071               <tr>
3072                 <th align=right nowrap>| . $locale->text('Last RFQ Number') . qq|</th>
3073                 <td><input name=rfqnumber size=10 value=$form->{defaults}{rfqnumber}></td>
3074                 <th align=right nowrap></th>
3075                 <td></td>
3076               </tr>
3077             </table>
3078           </td>
3079         </tr>
3080         <tr class=listheading>
3081           <th colspan=2>| . $locale->text('Tax Accounts') . qq|</th>
3082         </tr>
3083         <tr>
3084           <td colspan=2>
3085             <table>
3086               <tr>
3087                 <th>&nbsp;</th>
3088                 <th>| . $locale->text('Rate') . qq| (%)</th>
3089                 <th>| . $locale->text('Number') . qq|</th>
3090               </tr>
3091 |;
3092
3093   foreach $accno (sort keys %{ $form->{taxrates} }) {
3094     print qq|
3095               <tr>
3096                 <th align=right>$form->{taxrates}{$accno}{description}</th>
3097                 <td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td>
3098                 <td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td>
3099               </tr>
3100 |;
3101     $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} ";
3102   }
3103
3104   chop $form->{taxaccounts};
3105
3106   print qq|
3107 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
3108
3109             </table>
3110           </td>
3111         </tr>
3112       </table>
3113     </td>
3114   </tr>
3115   <tr>
3116     <td><hr size=3 noshade></td>
3117   </tr>
3118 </table>
3119
3120 <input type=hidden name=path value=$form->{path}>
3121 <input type=hidden name=login value=$form->{login}>
3122 <input type=hidden name=password value=$form->{password}>
3123
3124 <br>
3125 <input type=submit class=submit name=action value="|
3126     . $locale->text('Save') . qq|">|;
3127
3128   if ($form->{menubar}) {
3129     require "$form->{path}/menu.pl";
3130     &menubar;
3131   }
3132
3133   print qq|
3134   </form>
3135
3136 </body>
3137 </html>
3138 |;
3139
3140   $lxdebug->leave_sub();
3141 }
3142
3143 sub save_preferences {
3144   $lxdebug->enter_sub();
3145
3146   $form->{stylesheet} = $form->{usestylesheet};
3147
3148   $form->redirect($locale->text('Preferences saved!'))
3149     if (
3150      AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath, $webdav
3151      ));
3152   $form->error($locale->text('Cannot save preferences!'));
3153
3154   $lxdebug->leave_sub();
3155 }
3156
3157 sub backup {
3158   $lxdebug->enter_sub();
3159
3160   if ($form->{media} eq 'email') {
3161     $form->error($locale->text('No email address for') . " $myconfig{name}")
3162       unless ($myconfig{email});
3163
3164     $form->{OUT} = "$sendmail";
3165
3166   }
3167
3168   AM->backup(\%myconfig, \%$form, $userspath);
3169
3170   if ($form->{media} eq 'email') {
3171     $form->redirect($locale->text('Backup sent to') . qq| $myconfig{email}|);
3172   }
3173
3174   $lxdebug->leave_sub();
3175 }
3176
3177 sub audit_control {
3178   $lxdebug->enter_sub();
3179
3180   $form->{title} = $locale->text('Audit Control');
3181
3182   AM->closedto(\%myconfig, \%$form);
3183
3184   if ($form->{revtrans}) {
3185     $checked{Y} = "checked";
3186   } else {
3187     $checked{N} = "checked";
3188   }
3189
3190   $form->header;
3191
3192   print qq|
3193 <body>
3194
3195 <form method=post action=$form->{script}>
3196
3197 <input type=hidden name=path value=$form->{path}>
3198 <input type=hidden name=login value=$form->{login}>
3199 <input type=hidden name=password value=$form->{password}>
3200
3201 <table width=100%>
3202   <tr><th class=listtop>$form->{title}</th></tr>
3203   <tr height="5"></tr>
3204   <tr>
3205     <td>
3206       <table>
3207         <tr>
3208           <td>|
3209     . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
3210           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
3211     . $locale->text('Yes')
3212     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
3213     . $locale->text('No')
3214     . qq|</td>
3215         </tr>
3216         <tr>
3217           <th>| . $locale->text('Close Books up to') . qq|</th>
3218           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
3219         </tr>
3220       </table>
3221     </td>
3222   </tr>
3223 </table>
3224
3225 <hr size=3 noshade>
3226
3227 <br>
3228 <input type=hidden name=nextsub value=doclose>
3229
3230 <input type=submit class=submit name=action value="|
3231     . $locale->text('Continue') . qq|">
3232
3233 </form>
3234
3235 </body>
3236 </html>
3237 |;
3238
3239   $lxdebug->leave_sub();
3240 }
3241
3242 sub doclose {
3243   $lxdebug->enter_sub();
3244
3245   AM->closebooks(\%myconfig, \%$form);
3246
3247   if ($form->{revtrans}) {
3248     $form->redirect(
3249                  $locale->text('Transaction reversal enforced for all dates'));
3250   } else {
3251     if ($form->{closedto}) {
3252       $form->redirect(
3253                      $locale->text('Transaction reversal enforced up to') . " "
3254                        . $locale->date(\%myconfig, $form->{closedto}, 1));
3255     } else {
3256       $form->redirect($locale->text('Books are open'));
3257     }
3258   }
3259
3260   $lxdebug->leave_sub();
3261 }
3262
3263 sub add_warehouse {
3264   $lxdebug->enter_sub();
3265
3266   $form->{title} = "Add";
3267
3268   $form->{callback} =
3269     "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"
3270     unless $form->{callback};
3271
3272   &warehouse_header;
3273   &form_footer;
3274
3275   $lxdebug->leave_sub();
3276 }
3277
3278 sub edit_warehouse {
3279   $lxdebug->enter_sub();
3280
3281   $form->{title} = "Edit";
3282
3283   AM->get_warehouse(\%myconfig, \%$form);
3284
3285   &warehouse_header;
3286   &form_footer;
3287
3288   $lxdebug->leave_sub();
3289 }
3290
3291 sub list_warehouse {
3292   $lxdebug->enter_sub();
3293
3294   AM->warehouses(\%myconfig, \%$form);
3295
3296   $form->{callback} =
3297     "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}";
3298
3299   $callback = $form->escape($form->{callback});
3300
3301   $form->{title} = $locale->text('Warehouses');
3302
3303   @column_index = qw(description);
3304
3305   $column_header{description} =
3306       qq|<th class=listheading width=100%>|
3307     . $locale->text('Description')
3308     . qq|</th>|;
3309
3310   $form->header;
3311
3312   print qq|
3313 <body>
3314
3315 <table width=100%>
3316   <tr>
3317     <th class=listtop>$form->{title}</th>
3318   </tr>
3319   <tr height="5"></tr>
3320   <tr>
3321     <td>
3322       <table width=100%>
3323         <tr class=listheading>
3324 |;
3325
3326   map { print "$column_header{$_}\n" } @column_index;
3327
3328   print qq|
3329         </tr>
3330 |;
3331
3332   foreach $ref (@{ $form->{ALL} }) {
3333
3334     $i++;
3335     $i %= 2;
3336
3337     print qq|
3338         <tr valign=top class=listrow$i>
3339 |;
3340
3341     $column_data{description} =
3342       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>|;
3343
3344     map { print "$column_data{$_}\n" } @column_index;
3345
3346     print qq|
3347         </tr>
3348 |;
3349   }
3350
3351   print qq|
3352       </table>
3353     </td>
3354   </tr>
3355   <tr>
3356   <td><hr size=3 noshade></td>
3357   </tr>
3358 </table>
3359
3360 <br>
3361 <form method=post action=$form->{script}>
3362
3363 <input name=callback type=hidden value="$form->{callback}">
3364
3365 <input type=hidden name=type value=warehouse>
3366
3367 <input type=hidden name=path value=$form->{path}>
3368 <input type=hidden name=login value=$form->{login}>
3369 <input type=hidden name=password value=$form->{password}>
3370
3371 <input class=submit type=submit name=action value="|
3372     . $locale->text('Add') . qq|">|;
3373
3374   if ($form->{menubar}) {
3375     require "$form->{path}/menu.pl";
3376     &menubar;
3377   }
3378
3379   print qq|
3380   </form>
3381
3382   </body>
3383   </html>
3384 |;
3385
3386   $lxdebug->leave_sub();
3387 }
3388
3389 sub warehouse_header {
3390   $lxdebug->enter_sub();
3391
3392   $form->{title} = $locale->text("$form->{title} Warehouse");
3393
3394   # $locale->text('Add Warehouse')
3395   # $locale->text('Edit Warehouse')
3396
3397   $form->{description} =~ s/\"/&quot;/g;
3398
3399   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
3400     $description =
3401       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
3402   } else {
3403     $description =
3404       qq|<input name=description size=60 value="$form->{description}">|;
3405   }
3406
3407   $form->header;
3408
3409   print qq|
3410 <body>
3411
3412 <form method=post action=$form->{script}>
3413
3414 <input type=hidden name=id value=$form->{id}>
3415 <input type=hidden name=type value=warehouse>
3416
3417 <table width=100%>
3418   <tr>
3419     <th class=listtop colspan=2>$form->{title}</th>
3420   </tr>
3421   <tr height="5"></tr>
3422   <tr>
3423     <th align=right>| . $locale->text('Description') . qq|</th>
3424     <td>$description</td>
3425   </tr>
3426   <tr>
3427     <td colspan=2><hr size=3 noshade></td>
3428   </tr>
3429 </table>
3430 |;
3431
3432   $lxdebug->leave_sub();
3433 }
3434
3435 sub save_warehouse {
3436   $lxdebug->enter_sub();
3437
3438   $form->isblank("description", $locale->text('Description missing!'));
3439   AM->save_warehouse(\%myconfig, \%$form);
3440   $form->redirect($locale->text('Warehouse saved!'));
3441
3442   $lxdebug->leave_sub();
3443 }
3444
3445 sub delete_warehouse {
3446   $lxdebug->enter_sub();
3447
3448   AM->delete_warehouse(\%myconfig, \%$form);
3449   $form->redirect($locale->text('Warehouse deleted!'));
3450
3451   $lxdebug->leave_sub();
3452 }
3453
3454 sub continue {
3455   $lxdebug->enter_sub();
3456
3457   &{ $form->{nextsub} };
3458
3459   $lxdebug->leave_sub();
3460 }
3461
3462 sub edit_units {
3463   $lxdebug->enter_sub();
3464
3465   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
3466   AM->units_in_use(\%myconfig, $form, $units);
3467   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
3468
3469   @unit_list = ();
3470   foreach $name (sort({ lc($a) cmp lc($b) } grep({ !$units->{$_}->{"base_unit"} } keys(%{$units})))) {
3471     map({ push(@unit_list, $units->{$_}); }
3472         sort({ ($units->{$a}->{"resolved_factor"} * 1) <=> ($units->{$b}->{"resolved_factor"} * 1) }
3473              grep({ $units->{$_}->{"resolved_base_unit"} eq $name } keys(%{$units}))));
3474   }
3475   map({ $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"}); } @unit_list);
3476
3477   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
3478   $ddbox = AM->unit_select_data($units, undef, 1);
3479
3480   $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
3481   $form->header();
3482   print($form->parse_html_template("am/edit_units", { "UNITS" => \@unit_list, "NEW_BASE_UNIT_DDBOX" => $ddbox }));
3483
3484   $lxdebug->leave_sub();
3485 }
3486
3487 sub add_unit {
3488   $lxdebug->enter_sub();
3489
3490   $form->isblank("new_name", $locale->text("The name is missing."));
3491   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
3492   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($units->{$form->{"new_name"}});
3493
3494   my ($base_unit, $factor);
3495   if ($form->{"new_base_unit"}) {
3496     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
3497
3498     $form->isblank("new_factor", $locale->text("The factor is missing."));
3499     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
3500     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
3501     $base_unit = $form->{"new_base_unit"};
3502   }
3503
3504   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"});
3505
3506   $form->{"saved_message"} = $locale->text("The unit has been saved.");
3507
3508   edit_units();
3509
3510   $lxdebug->leave_sub();
3511 }
3512
3513 sub save_unit {
3514   $lxdebug->enter_sub();
3515
3516   $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
3517   AM->units_in_use(\%myconfig, $form, $old_units);
3518
3519   $new_units = {};
3520   @delete_units = ();
3521   foreach $i (1..($form->{"rowcount"} * 1)) {
3522     $old_unit = $old_units->{$form->{"old_name_$i"}};
3523     if (!$old_unit) {
3524       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
3525     }
3526
3527     if ($form->{"unchangeable_$i"}) {
3528       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
3529       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
3530       next;
3531     }
3532
3533     if ($old_unit->{"in_use"}) {
3534       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
3535     }
3536
3537     if ($form->{"delete_$i"}) {
3538       push(@delete_units, $old_unit->{"name"});
3539       next;
3540     }
3541
3542     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
3543
3544     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
3545     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
3546     $new_units->{$form->{"name_$i"}} = \%h;
3547     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
3548   }
3549
3550   foreach $unit (values(%{$new_units})) {
3551     next unless ($unit->{"old_name"});
3552     if ($unit->{"base_unit"}) {
3553       $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"}))
3554         unless (defined($new_units->{$unit->{"base_unit"}}));
3555       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
3556       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
3557     } else {
3558       $unit->{"base_unit"} = undef;
3559       $unit->{"factor"} = undef;
3560     }
3561   }
3562
3563   foreach $unit (values(%{$new_units})) {
3564     next if ($unit->{"unchanged_unit"});
3565
3566     map({ $_->{"seen"} = 0; } values(%{$new_units}));
3567     $new_unit = $unit;
3568     while ($new_unit->{"base_unit"}) {
3569       $new_unit->{"seen"} = 1;
3570       $new_unit = $new_units->{$new_unit->{"base_unit"}};
3571       if ($new_unit->{"seen"}) {
3572         $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, " .
3573                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
3574       }
3575     }
3576   }
3577
3578   AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
3579
3580   $form->{"saved_message"} = $locale->text("The units have been saved.");
3581
3582   edit_units();
3583
3584   $lxdebug->leave_sub();
3585 }