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