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