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