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