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