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