Zeiger in JS Menu als Hand, wie bei den anderen Menues
[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(up down description inventory_accno
1786                      income_accno_0 expense_accno_0
1787                      income_accno_1 expense_accno_1
1788                      income_accno_2 expense_accno_2
1789                      income_accno_3 expense_accno_3 );
1790
1791   $column_header{up} =
1792       qq|<th class="listheading">|
1793     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
1794     . qq|</th>|;
1795   $column_header{down} =
1796       qq|<th class="listheading">|
1797     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
1798     . qq|</th>|;
1799   $column_header{description} =
1800       qq|<th class="listheading" width="40%">|
1801     . $locale->text('Description')
1802     . qq|</th>|;
1803   $column_header{inventory_accno} =
1804       qq|<th class=listheading>|
1805     . $locale->text('Bestandskonto')
1806     . qq|</th>|;
1807   $column_header{income_accno_0} =
1808       qq|<th class=listheading>|
1809     . $locale->text('Erlöse Inland')
1810     . qq|</th>|;
1811   $column_header{expense_accno_0} =
1812       qq|<th class=listheading>|
1813     . $locale->text('Aufwand Inland')
1814     . qq|</th>|;
1815   $column_header{income_accno_1} =
1816       qq|<th class=listheading>|
1817     . $locale->text('Erlöse EU m. UStId')
1818     . qq|</th>|;
1819   $column_header{expense_accno_1} =
1820       qq|<th class=listheading>|
1821     . $locale->text('Aufwand EU m. UStId')
1822     . qq|</th>|;
1823   $column_header{income_accno_2} =
1824       qq|<th class=listheading>|
1825     . $locale->text('Erlöse EU o. UStId')
1826     . qq|</th>|;
1827   $column_header{expense_accno_2} =
1828       qq|<th class=listheading>|
1829     . $locale->text('Aufwand EU o. UStId')
1830     . qq|</th>|;
1831   $column_header{income_accno_3} =
1832       qq|<th class=listheading>|
1833     . $locale->text('Erlöse Ausland')
1834     . qq|</th>|;
1835   $column_header{expense_accno_3} =
1836       qq|<th class=listheading>|
1837     . $locale->text('Aufwand Ausland')
1838     . qq|</th>|;
1839   $form->header;
1840
1841   print qq|
1842 <body>
1843
1844 <table width=100%>
1845   <tr>
1846     <th class=listtop>$form->{title}</th>
1847   </tr>
1848   <tr height="5"></tr>
1849   <tr>
1850     <td>
1851       <table width=100%>
1852         <tr class=listheading>
1853 |;
1854
1855   map { print "$column_header{$_}\n" } @column_index;
1856
1857   print qq|
1858         </tr>
1859 |;
1860
1861   my $swap_link = qq|$form->{script}?action=swap_buchungsgruppen&|;
1862   map({ $swap_link .= $_ . "=" . $form->escape($form->{$_}) . "&" }
1863       qw(login password path));
1864
1865   my $row = 0;
1866   foreach $ref (@{ $form->{ALL} }) {
1867
1868     $i++;
1869     $i %= 2;
1870
1871     print qq|
1872         <tr valign=top class=listrow$i>
1873 |;
1874
1875     if ($row) {
1876       my $pref = $form->{ALL}->[$row - 1];
1877       $column_data{up} =
1878         qq|<td align="center" valign="center">| .
1879         qq|<a href="${swap_link}id1=$ref->{id}&id2=$pref->{id}">| .
1880         qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">| .
1881         qq|</a></td>|;
1882     } else {
1883       $column_data{up} = qq|<td>&nbsp;</td>|;
1884     }
1885
1886     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
1887       $column_data{down} = qq|<td>&nbsp;</td>|;
1888     } else {
1889       my $nref = $form->{ALL}->[$row + 1];
1890       $column_data{down} =
1891         qq|<td align="center" valign="center">| .
1892         qq|<a href="${swap_link}id1=$ref->{id}&id2=$nref->{id}">| .
1893         qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">| .
1894         qq|</a></td>|;
1895     }
1896
1897     $column_data{description} =
1898       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>|;
1899     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
1900     $column_data{income_accno_0} =
1901       qq|<td align=right>$ref->{income_accno_0}</td>|;
1902     $column_data{expense_accno_0}           = qq|<td align=right>$ref->{expense_accno_0}</td>|;
1903     $column_data{income_accno_1} =
1904       qq|<td align=right>$ref->{income_accno_1}</td>|;
1905     $column_data{expense_accno_1}           = qq|<td align=right>$ref->{expense_accno_1}</td>|;
1906     $column_data{income_accno_2} =
1907       qq|<td align=right>$ref->{income_accno_2}</td>|;
1908     $column_data{expense_accno_2}           = qq|<td align=right>$ref->{expense_accno_2}</td>|;
1909     $column_data{income_accno_3} =
1910       qq|<td align=right>$ref->{income_accno_3}</td>|;
1911     $column_data{expense_accno_3}           = qq|<td align=right>$ref->{expense_accno_3}</td>|;
1912
1913     map { print "$column_data{$_}\n" } @column_index;
1914
1915     print qq|
1916         </tr>
1917 |;
1918
1919     $row++;
1920   }
1921
1922   print qq|
1923       </table>
1924     </td>
1925   </tr>
1926   <tr>
1927   <td><hr size=3 noshade></td>
1928   </tr>
1929 </table>
1930
1931 <br>
1932 <form method=post action=$form->{script}>
1933
1934 <input name=callback type=hidden value="$form->{callback}">
1935
1936 <input type=hidden name=type value=buchungsgruppe>
1937
1938 <input type=hidden name=path value=$form->{path}>
1939 <input type=hidden name=login value=$form->{login}>
1940 <input type=hidden name=password value=$form->{password}>
1941
1942 <input class=submit type=submit name=action value="|
1943     . $locale->text('Add') . qq|">
1944
1945   </form>
1946
1947   </body>
1948   </html>
1949 |;
1950
1951   $lxdebug->leave_sub();
1952 }
1953
1954 sub buchungsgruppe_header {
1955   $lxdebug->enter_sub();
1956
1957   $form->{title}    = $locale->text("$form->{title} Buchungsgruppe");
1958
1959   # $locale->text('Buchungsgruppe hinzufügen')
1960   # $locale->text('Buchungsgruppe bearbeiten')
1961
1962   my ($acc_inventory, $acc_income, $acc_expense) = ({}, {}, {});
1963   my %acc_type_map = (
1964     "IC" => $acc_inventory,
1965     "IC_income" => $acc_income,
1966     "IC_sale" => $acc_income,
1967     "IC_expense" => $acc_expense,
1968     "IC_cogs" => $acc_expense,
1969     );
1970
1971   foreach $key (keys(%acc_type_map)) {
1972     foreach $ref (@{ $form->{IC_links}{$key} }) {
1973       $acc_type_map{$key}->{$ref->{"id"}} = $ref;
1974     }
1975   }
1976
1977   foreach my $type (qw(IC IC_income IC_expense)) {
1978     $form->{"select$type"} =
1979       join("",
1980            map({ "<option value=$_->{id} $_->{selected}>" .
1981                    "$_->{accno}--" . H($_->{description}) . "</option>" }
1982                sort({ $a->{"accno"} cmp $b->{"accno"} }
1983                     values(%{$acc_type_map{$type}}))));
1984   }
1985
1986   if ($form->{id}) {
1987     $form->{selectIC} =~ s/selected//g;
1988     $form->{selectIC} =~ s/ value=$form->{inventory_accno_id}/  value=$form->{inventory_accno_id} selected/;
1989     $form->{selectIC_income} =~ s/selected//g;
1990     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_0}/  value=$form->{income_accno_id_0} selected/;
1991     $form->{selectIC_expense} =~ s/selected//g;
1992     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_0}/  value=$form->{expense_accno_id_0} selected/;
1993   }
1994
1995   if (!$eur) {
1996     $linkaccounts = qq|
1997                <tr>
1998                 <th align=right>| . $locale->text('Inventory') . qq|</th>
1999                 <td><select name=inventory_accno_id>$form->{selectIC}</select></td>
2000                 <input name=selectIC type=hidden value="$form->{selectIC}">
2001               </tr>|;
2002   } else {
2003     $linkaccounts = qq|
2004                 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>|;
2005   }
2006
2007
2008   $linkaccounts .= qq|
2009               <tr>
2010                 <th align=right>| . $locale->text('Erlöse Inland') . qq|</th>
2011                 <td><select name=income_accno_id_0>$form->{selectIC_income}</select></td>
2012               </tr>
2013               <tr>
2014                 <th align=right>| . $locale->text('Aufwand Inland') . qq|</th>
2015                 <td><select name=expense_accno_id_0>$form->{selectIC_expense}</select></td>
2016               </tr>|;
2017   if ($form->{id}) {
2018     $form->{selectIC_income} =~ s/selected//g;
2019     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_1}/  value=$form->{income_accno_id_1} selected/;
2020     $form->{selectIC_expense} =~ s/selected//g;
2021     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_1}/  value=$form->{expense_accno_id_1} selected/;
2022   }
2023   $linkaccounts .= qq|        <tr>
2024                 <th align=right>| . $locale->text('Erlöse EU m. UStId') . qq|</th>
2025                 <td><select name=income_accno_id_1>$form->{selectIC_income}</select></td>
2026               </tr>
2027               <tr>
2028                 <th align=right>| . $locale->text('Aufwand EU m UStId') . qq|</th>
2029                 <td><select name=expense_accno_id_1>$form->{selectIC_expense}</select></td>
2030               </tr>|;
2031
2032   if ($form->{id}) {
2033     $form->{selectIC_income} =~ s/selected//g;
2034     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_2}/  value=$form->{income_accno_id_2} selected/;
2035     $form->{selectIC_expense} =~ s/selected//g;
2036     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_2}/  value=$form->{expense_accno_id_2} selected/;
2037   }
2038
2039   $linkaccounts .= qq|        <tr>
2040                 <th align=right>| . $locale->text('Erlöse EU o. UStId') . qq|</th>
2041                 <td><select name=income_accno_id_2>$form->{selectIC_income}</select></td>
2042               </tr>
2043               <tr>
2044                 <th align=right>| . $locale->text('Aufwand EU o. UStId') . qq|</th>
2045                 <td><select name=expense_accno_id_2>$form->{selectIC_expense}</select></td>
2046               </tr>|;
2047
2048   if ($form->{id}) {
2049     $form->{selectIC_income} =~ s/selected//g;
2050     $form->{selectIC_income} =~ s/ value=$form->{income_accno_id_3}/  value=$form->{income_accno_id_3} selected/;
2051     $form->{selectIC_expense} =~ s/selected//g;
2052     $form->{selectIC_expense} =~ s/ value=$form->{expense_accno_id_3}/  value=$form->{expense_accno_id_3} selected/;
2053   }
2054
2055   $linkaccounts .= qq|        <tr>
2056                 <th align=right>| . $locale->text('Erlöse Ausland') . qq|</th>
2057                 <td><select name=income_accno_id_3>$form->{selectIC_income}</select></td>
2058               </tr>
2059               <tr>
2060                 <th align=right>| . $locale->text('Aufwand Ausland') . qq|</th>
2061                 <td><select name=expense_accno_id_3>$form->{selectIC_expense}</select></td>
2062               </tr>
2063 |;
2064
2065
2066   $form->header;
2067
2068   print qq|
2069 <body>
2070
2071 <form method=post action=$form->{script}>
2072
2073 <input type=hidden name=id value=$form->{id}>
2074 <input type=hidden name=type value=buchungsgruppe>
2075
2076 <table width=100%>
2077   <tr>
2078     <th class=listtop colspan=2>$form->{title}</th>
2079   </tr>
2080   <tr height="5"></tr>
2081   <tr>
2082     <th align=right>| . $locale->text('Buchungsgruppe') . qq|</th>
2083     <td><input name=description size=30 value="| . $form->quote($form->{description}) . qq|"></td>
2084   <tr>
2085   $linkaccounts
2086   <td colspan=2><hr size=3 noshade></td>
2087   </tr>
2088 </table>
2089 |;
2090
2091   $lxdebug->leave_sub();
2092 }
2093
2094 sub save_buchungsgruppe {
2095   $lxdebug->enter_sub();
2096
2097   $form->isblank("description", $locale->text('Description missing!'));
2098
2099   AM->save_buchungsgruppe(\%myconfig, \%$form);
2100   $form->redirect($locale->text('Buchungsgruppe gespeichert!'));
2101
2102   $lxdebug->leave_sub();
2103 }
2104
2105 sub delete_buchungsgruppe {
2106   $lxdebug->enter_sub();
2107
2108   AM->delete_buchungsgruppe(\%myconfig, \%$form);
2109   $form->redirect($locale->text('Buchungsgruppe gelöscht!'));
2110
2111   $lxdebug->leave_sub();
2112 }
2113
2114 sub swap_buchungsgruppen {
2115   $lxdebug->enter_sub();
2116
2117   AM->swap_sortkeys(\%myconfig, $form, "buchungsgruppen");
2118   list_buchungsgruppe();
2119
2120   $lxdebug->leave_sub();
2121 }
2122
2123
2124 sub add_printer {
2125   $lxdebug->enter_sub();
2126
2127   $form->{title} = "Add";
2128
2129   $form->{callback} =
2130     "$form->{script}?action=add_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2131     unless $form->{callback};
2132
2133   &printer_header;
2134   &form_footer;
2135
2136   $lxdebug->leave_sub();
2137 }
2138
2139 sub edit_printer {
2140   $lxdebug->enter_sub();
2141
2142   $form->{title} = "Edit";
2143
2144   AM->get_printer(\%myconfig, \%$form);
2145
2146   &printer_header;
2147
2148   $form->{orphaned} = 1;
2149   &form_footer;
2150
2151   $lxdebug->leave_sub();
2152 }
2153
2154 sub list_printer {
2155   $lxdebug->enter_sub();
2156
2157   AM->printer(\%myconfig, \%$form);
2158
2159   $form->{callback} =
2160     "$form->{script}?action=list_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2161
2162   $callback = $form->escape($form->{callback});
2163
2164   $form->{title} = $locale->text('Printer');
2165
2166   @column_index = qw(printer_description printer_command template_code);
2167
2168   $column_header{printer_description} =
2169       qq|<th class=listheading width=60%>|
2170     . $locale->text('Printer Description')
2171     . qq|</th>|;
2172   $column_header{printer_command} =
2173       qq|<th class=listheading width=10%>|
2174     . $locale->text('Printer Command')
2175     . qq|</th>|;
2176   $column_header{template_code} =
2177       qq|<th class=listheading>|
2178     . $locale->text('Template Code')
2179     . qq|</th>|;
2180
2181   $form->header;
2182
2183   print qq|
2184 <body>
2185
2186 <table width=100%>
2187   <tr>
2188     <th class=listtop>$form->{title}</th>
2189   </tr>
2190   <tr height="5"></tr>
2191   <tr>
2192     <td>
2193       <table width=100%>
2194         <tr class=listheading>
2195 |;
2196
2197   map { print "$column_header{$_}\n" } @column_index;
2198
2199   print qq|
2200         </tr>
2201 |;
2202
2203   foreach $ref (@{ $form->{ALL} }) {
2204
2205     $i++;
2206     $i %= 2;
2207
2208     print qq|
2209         <tr valign=top class=listrow$i>
2210 |;
2211
2212
2213     $column_data{printer_description} =
2214       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>|;
2215     $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
2216     $column_data{template_code} =
2217       qq|<td align=right>$ref->{template_code}</td>|;
2218
2219     map { print "$column_data{$_}\n" } @column_index;
2220
2221     print qq|
2222         </tr>
2223 |;
2224   }
2225
2226   print qq|
2227       </table>
2228     </td>
2229   </tr>
2230   <tr>
2231   <td><hr size=3 noshade></td>
2232   </tr>
2233 </table>
2234
2235 <br>
2236 <form method=post action=$form->{script}>
2237
2238 <input name=callback type=hidden value="$form->{callback}">
2239
2240 <input type=hidden name=type value=printer>
2241
2242 <input type=hidden name=path value=$form->{path}>
2243 <input type=hidden name=login value=$form->{login}>
2244 <input type=hidden name=password value=$form->{password}>
2245
2246 <input class=submit type=submit name=action value="|
2247     . $locale->text('Add') . qq|">
2248
2249   </form>
2250
2251   </body>
2252   </html>
2253 |;
2254
2255   $lxdebug->leave_sub();
2256 }
2257
2258 sub printer_header {
2259   $lxdebug->enter_sub();
2260
2261   $form->{title}    = $locale->text("$form->{title} Printer");
2262
2263   # $locale->text('Add Printer')
2264   # $locale->text('Edit Printer')
2265
2266   $form->{printer_description} =~ s/\"/&quot;/g;
2267   $form->{template_code} =~ s/\"/&quot;/g;
2268   $form->{printer_command} =~ s/\"/&quot;/g;
2269
2270
2271   $form->header;
2272
2273   print qq|
2274 <body>
2275
2276 <form method=post action=$form->{script}>
2277
2278 <input type=hidden name=id value=$form->{id}>
2279 <input type=hidden name=type value=printer>
2280
2281 <table width=100%>
2282   <tr>
2283     <th class=listtop colspan=2>$form->{title}</th>
2284   </tr>
2285   <tr height="5"></tr>
2286   <tr>
2287     <th align=right>| . $locale->text('Printer') . qq|</th>
2288     <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
2289   <tr>
2290   <tr>
2291     <th align=right>| . $locale->text('Printer Command') . qq|</th>
2292     <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
2293   </tr>
2294   <tr>
2295     <th align=right>| . $locale->text('Template Code') . qq|</th>
2296     <td><input name=template_code size=5 value="$form->{template_code}"></td>
2297   </tr>
2298   <td colspan=2><hr size=3 noshade></td>
2299   </tr>
2300 </table>
2301 |;
2302
2303   $lxdebug->leave_sub();
2304 }
2305
2306 sub save_printer {
2307   $lxdebug->enter_sub();
2308
2309   $form->isblank("printer_description", $locale->text('Description missing!'));
2310   $form->isblank("printer_command", $locale->text('Printer Command missing!'));
2311   AM->save_printer(\%myconfig, \%$form);
2312   $form->redirect($locale->text('Printer saved!'));
2313
2314   $lxdebug->leave_sub();
2315 }
2316
2317 sub delete_printer {
2318   $lxdebug->enter_sub();
2319
2320   AM->delete_printer(\%myconfig, \%$form);
2321   $form->redirect($locale->text('Printer deleted!'));
2322
2323   $lxdebug->leave_sub();
2324 }
2325
2326
2327 sub add_payment {
2328   $lxdebug->enter_sub();
2329
2330   $form->{title} = "Add";
2331
2332   $form->{callback} =
2333     "$form->{script}?action=add_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2334     unless $form->{callback};
2335
2336   $form->{terms_netto} = 0;
2337   $form->{terms_skonto} = 0;
2338   $form->{percent_skonto} = 0;
2339   &payment_header;
2340   &form_footer;
2341
2342   $lxdebug->leave_sub();
2343 }
2344
2345 sub edit_payment {
2346   $lxdebug->enter_sub();
2347
2348   $form->{title} = "Edit";
2349
2350   AM->get_payment(\%myconfig, \%$form);
2351   $form->{percent_skonto} =
2352     $form->format_amount(\%myconfig, $form->{percent_skonto} * 100);
2353
2354   &payment_header;
2355
2356   $form->{orphaned} = 1;
2357   &form_footer;
2358
2359   $lxdebug->leave_sub();
2360 }
2361
2362 sub list_payment {
2363   $lxdebug->enter_sub();
2364
2365   AM->payment(\%myconfig, \%$form);
2366
2367   $form->{callback} = build_std_url("action=list_payment");
2368
2369   $callback = $form->escape($form->{callback});
2370
2371   $form->{title} = $locale->text('Payment Terms');
2372
2373   @column_index = qw(up down description description_long terms_netto
2374                      terms_skonto percent_skonto);
2375
2376   $column_header{up} =
2377       qq|<th class="listheading" align="center" valign="center">|
2378     . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
2379     . qq|</th>|;
2380   $column_header{down} =
2381       qq|<th class="listheading" align="center" valign="center">|
2382     . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
2383     . qq|</th>|;
2384   $column_header{description} =
2385       qq|<th class=listheading>|
2386     . $locale->text('Description')
2387     . qq|</th>|;
2388   $column_header{description_long} =
2389       qq|<th class=listheading>|
2390     . $locale->text('Long Description')
2391     . qq|</th>|;
2392   $column_header{terms_netto} =
2393       qq|<th class=listheading>|
2394     . $locale->text('Netto Terms')
2395     . qq|</th>|;
2396   $column_header{terms_skonto} =
2397       qq|<th class=listheading>|
2398     . $locale->text('Skonto Terms')
2399     . qq|</th>|;
2400   $column_header{percent_skonto} =
2401       qq|<th class=listheading>|
2402     . $locale->text('Skonto')
2403     . qq| %</th>|;
2404
2405   $form->header;
2406
2407   print qq|
2408 <body>
2409
2410 <table width=100%>
2411   <tr>
2412     <th class=listtop>$form->{title}</th>
2413   </tr>
2414   <tr height="5"></tr>
2415   <tr>
2416     <td>
2417       <table width=100%>
2418         <tr class=listheading>
2419 |;
2420
2421   map { print "$column_header{$_}\n" } @column_index;
2422
2423   print qq|
2424         </tr>
2425 |;
2426
2427   my $swap_link = build_std_url("action=swap_payment_terms");
2428
2429   my $row = 0;
2430   foreach $ref (@{ $form->{ALL} }) {
2431
2432     $i++;
2433     $i %= 2;
2434
2435     print qq|
2436         <tr valign=top class=listrow$i>
2437 |;
2438
2439     if ($row) {
2440       my $pref = $form->{ALL}->[$row - 1];
2441       $column_data{up} =
2442         qq|<td align="center" valign="center">| .
2443         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
2444         qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">| .
2445         qq|</a></td>|;
2446     } else {
2447       $column_data{up} = qq|<td>&nbsp;</td>|;
2448     }
2449
2450     if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
2451       $column_data{down} = qq|<td>&nbsp;</td>|;
2452     } else {
2453       my $nref = $form->{ALL}->[$row + 1];
2454       $column_data{down} =
2455         qq|<td align="center" valign="center">| .
2456         qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
2457         qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">| .
2458         qq|</a></td>|;
2459     }
2460
2461     $column_data{description} =
2462       qq|<td><a href="| .
2463       build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
2464       qq|">| . H($ref->{description}) . qq|</a></td>|;
2465     $column_data{description_long} =
2466       qq|<td align=right>| . H($ref->{description_long}) . qq|</td>|;
2467     $column_data{terms_netto} =
2468       qq|<td align=right>$ref->{terms_netto}</td>|;
2469     $column_data{terms_skonto} =
2470       qq|<td align=right>$ref->{terms_skonto}</td>|;
2471     $column_data{percent_skonto} =
2472       qq|<td align=right>| .
2473       $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
2474       qq|%</td>|;
2475     map { print "$column_data{$_}\n" } @column_index;
2476
2477     print qq|
2478         </tr>
2479 |;
2480     $row++;
2481   }
2482
2483   print qq|
2484       </table>
2485     </td>
2486   </tr>
2487   <tr>
2488   <td><hr size=3 noshade></td>
2489   </tr>
2490 </table>
2491
2492 <br>
2493 <form method=post action=$form->{script}>
2494
2495 <input name=callback type=hidden value="$form->{callback}">
2496
2497 <input type=hidden name=type value=payment>
2498
2499 <input type=hidden name=path value=$form->{path}>
2500 <input type=hidden name=login value=$form->{login}>
2501 <input type=hidden name=password value=$form->{password}>
2502
2503 <input class=submit type=submit name=action value="|
2504     . $locale->text('Add') . qq|">
2505
2506   </form>
2507
2508   </body>
2509   </html>
2510 |;
2511
2512   $lxdebug->leave_sub();
2513 }
2514
2515 sub payment_header {
2516   $lxdebug->enter_sub();
2517
2518   $form->{title}    = $locale->text("$form->{title} Payment Terms");
2519
2520   # $locale->text('Add Payment Terms')
2521   # $locale->text('Edit Payment Terms')
2522
2523   $form->{description} =~ s/\"/&quot;/g;
2524
2525
2526
2527   $form->header;
2528
2529   print qq|
2530 <body>
2531
2532 <form method=post action=$form->{script}>
2533
2534 <input type=hidden name=id value=$form->{id}>
2535 <input type=hidden name=type value=payment>
2536
2537 <table width=100%>
2538   <tr>
2539     <th class=listtop colspan=2>$form->{title}</th>
2540   </tr>
2541   <tr height="5"></tr>
2542   <tr>
2543     <th align=right>| . $locale->text('Description') . qq|</th>
2544     <td><input name=description size=30 value="$form->{description}"></td>
2545   <tr>
2546   <tr>
2547     <th align=right>| . $locale->text('Long Description') . qq|</th>
2548     <td><input name=description_long size=50 value="$form->{description_long}"></td>
2549   </tr>
2550   <tr>
2551     <th align=right>| . $locale->text('Netto Terms') . qq|</th>
2552     <td><input name=terms_netto size=10 value="$form->{terms_netto}"></td>
2553   </tr>
2554   <tr>
2555     <th align=right>| . $locale->text('Skonto Terms') . qq|</th>
2556     <td><input name=terms_skonto size=10 value="$form->{terms_skonto}"></td>
2557   </tr>  
2558   <tr>
2559     <th align=right>| . $locale->text('Skonto') . qq| %</th>
2560     <td><input name=percent_skonto size=10 value="$form->{percent_skonto}"></td>
2561   </tr> 
2562   <td colspan=2><hr size=3 noshade></td>
2563   </tr>
2564 </table>
2565 |;
2566
2567   $lxdebug->leave_sub();
2568 }
2569
2570 sub save_payment {
2571   $lxdebug->enter_sub();
2572
2573   $form->isblank("description", $locale->text('Description missing!'));
2574   $form->{"percent_skonto"} =
2575     $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100;
2576   AM->save_payment(\%myconfig, \%$form);
2577   $form->redirect($locale->text('Payment Terms saved!'));
2578
2579   $lxdebug->leave_sub();
2580 }
2581
2582 sub delete_payment {
2583   $lxdebug->enter_sub();
2584
2585   AM->delete_payment(\%myconfig, \%$form);
2586   $form->redirect($locale->text('Payment terms deleted!'));
2587
2588   $lxdebug->leave_sub();
2589 }
2590
2591 sub swap_payment_terms {
2592   $lxdebug->enter_sub();
2593
2594   AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
2595   list_payment();
2596
2597   $lxdebug->leave_sub();
2598 }
2599
2600 sub add_sic {
2601   $lxdebug->enter_sub();
2602
2603   $form->{title} = "Add";
2604
2605   $form->{callback} =
2606     "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2607     unless $form->{callback};
2608
2609   &sic_header;
2610   &form_footer;
2611
2612   $lxdebug->leave_sub();
2613 }
2614
2615 sub edit_sic {
2616   $lxdebug->enter_sub();
2617
2618   $form->{title} = "Edit";
2619
2620   AM->get_sic(\%myconfig, \%$form);
2621
2622   &sic_header;
2623
2624   $form->{orphaned} = 1;
2625   &form_footer;
2626
2627   $lxdebug->leave_sub();
2628 }
2629
2630 sub list_sic {
2631   $lxdebug->enter_sub();
2632
2633   AM->sic(\%myconfig, \%$form);
2634
2635   $form->{callback} =
2636     "$form->{script}?action=list_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2637
2638   $callback = $form->escape($form->{callback});
2639
2640   $form->{title} = $locale->text('Standard Industrial Codes');
2641
2642   @column_index = qw(code description);
2643
2644   $column_header{code} =
2645     qq|<th class=listheading>| . $locale->text('Code') . qq|</th>|;
2646   $column_header{description} =
2647     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
2648
2649   $form->header;
2650
2651   print qq|
2652 <body>
2653
2654 <table width=100%>
2655   <tr>
2656     <th class=listtop>$form->{title}</th>
2657   </tr>
2658   <tr height="5"></tr>
2659   <tr>
2660     <td>
2661       <table width=100%>
2662         <tr class=listheading>
2663 |;
2664
2665   map { print "$column_header{$_}\n" } @column_index;
2666
2667   print qq|
2668         </tr>
2669 |;
2670
2671   foreach $ref (@{ $form->{ALL} }) {
2672
2673     $i++;
2674     $i %= 2;
2675
2676     if ($ref->{sictype} eq 'H') {
2677       print qq|
2678         <tr valign=top class=listheading>
2679 |;
2680       $column_data{code} =
2681         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>|;
2682       $column_data{description} = qq|<th>$ref->{description}</th>|;
2683
2684     } else {
2685       print qq|
2686         <tr valign=top class=listrow$i>
2687 |;
2688
2689       $column_data{code} =
2690         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>|;
2691       $column_data{description} = qq|<td>$ref->{description}</td>|;
2692
2693     }
2694
2695     map { print "$column_data{$_}\n" } @column_index;
2696
2697     print qq|
2698         </tr>
2699 |;
2700   }
2701
2702   print qq|
2703       </table>
2704     </td>
2705   </tr>
2706   <tr>
2707   <td><hr size=3 noshade></td>
2708   </tr>
2709 </table>
2710
2711 <br>
2712 <form method=post action=$form->{script}>
2713
2714 <input name=callback type=hidden value="$form->{callback}">
2715
2716 <input type=hidden name=type value=sic>
2717
2718 <input type=hidden name=path value=$form->{path}>
2719 <input type=hidden name=login value=$form->{login}>
2720 <input type=hidden name=password value=$form->{password}>
2721
2722 <input class=submit type=submit name=action value="|
2723     . $locale->text('Add') . qq|">
2724
2725   </form>
2726
2727   </body>
2728   </html>
2729 |;
2730
2731   $lxdebug->leave_sub();
2732 }
2733
2734 sub sic_header {
2735   $lxdebug->enter_sub();
2736
2737   $form->{title} = $locale->text("$form->{title} SIC");
2738
2739   # $locale->text('Add SIC')
2740   # $locale->text('Edit SIC')
2741
2742   $form->{code}        =~ s/\"/&quot;/g;
2743   $form->{description} =~ s/\"/&quot;/g;
2744
2745   $checked = ($form->{sictype} eq 'H') ? "checked" : "";
2746
2747   $form->header;
2748
2749   print qq|
2750 <body>
2751
2752 <form method=post action=$form->{script}>
2753
2754 <input type=hidden name=type value=sic>
2755 <input type=hidden name=id value=$form->{code}>
2756
2757 <table width=100%>
2758   <tr>
2759     <th class=listtop colspan=2>$form->{title}</th>
2760   </tr>
2761   <tr height="5"></tr>
2762   <tr>
2763     <th align=right>| . $locale->text('Code') . qq|</th>
2764     <td><input name=code size=10 value=$form->{code}></td>
2765   <tr>
2766   <tr>
2767     <td></td>
2768     <th align=left><input name=sictype type=checkbox style=checkbox value="H" $checked> |
2769     . $locale->text('Heading') . qq|</th>
2770   <tr>
2771   <tr>
2772     <th align=right>| . $locale->text('Description') . qq|</th>
2773     <td><input name=description size=60 value="$form->{description}"></td>
2774   </tr>
2775     <td colspan=2><hr size=3 noshade></td>
2776   </tr>
2777 </table>
2778 |;
2779
2780   $lxdebug->leave_sub();
2781 }
2782
2783 sub save_sic {
2784   $lxdebug->enter_sub();
2785
2786   $form->isblank("code",        $locale->text('Code missing!'));
2787   $form->isblank("description", $locale->text('Description missing!'));
2788   AM->save_sic(\%myconfig, \%$form);
2789   $form->redirect($locale->text('SIC saved!'));
2790
2791   $lxdebug->leave_sub();
2792 }
2793
2794 sub delete_sic {
2795   $lxdebug->enter_sub();
2796
2797   AM->delete_sic(\%myconfig, \%$form);
2798   $form->redirect($locale->text('SIC deleted!'));
2799
2800   $lxdebug->leave_sub();
2801 }
2802
2803 sub display_stylesheet {
2804   $lxdebug->enter_sub();
2805
2806   $form->{file} = "css/$myconfig{stylesheet}";
2807   &display_form;
2808
2809   $lxdebug->leave_sub();
2810 }
2811
2812 sub display_form {
2813   $lxdebug->enter_sub();
2814
2815   $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
2816   $form->{file} =~ s/^\/*//g;
2817   $form->{file} =~ s/$userspath//;
2818
2819   $form->error("$!: $form->{file}") unless -f $form->{file};
2820
2821   AM->load_template(\%$form);
2822
2823   $form->{title} = $form->{file};
2824
2825   # if it is anything but html
2826   if ($form->{file} !~ /\.html$/) {
2827     $form->{body} = "<pre>\n$form->{body}\n</pre>";
2828   }
2829
2830   $form->header;
2831
2832   print qq|
2833 <body>
2834
2835 $form->{body}
2836
2837 <form method=post action=$form->{script}>
2838
2839 <input name=file type=hidden value=$form->{file}>
2840 <input name=type type=hidden value=template>
2841
2842 <input type=hidden name=path value=$form->{path}>
2843 <input type=hidden name=login value=$form->{login}>
2844 <input type=hidden name=password value=$form->{password}>
2845
2846 <input name=action type=submit class=submit value="|
2847     . $locale->text('Edit') . qq|">
2848
2849   </form>
2850
2851 </body>
2852 </html>
2853 |;
2854
2855   $lxdebug->leave_sub();
2856 }
2857
2858 sub edit_template {
2859   $lxdebug->enter_sub();
2860
2861   AM->load_template(\%$form);
2862
2863   $form->{title} = $locale->text('Edit Template');
2864
2865   # convert &nbsp to &amp;nbsp;
2866   $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
2867
2868   $form->header;
2869
2870   print qq|
2871 <body>
2872
2873 <form method=post action=$form->{script}>
2874
2875 <input name=file type=hidden value=$form->{file}>
2876 <input name=type type=hidden value=template>
2877
2878 <input type=hidden name=path value=$form->{path}>
2879 <input type=hidden name=login value=$form->{login}>
2880 <input type=hidden name=password value=$form->{password}>
2881
2882 <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}">
2883
2884 <textarea name=body rows=25 cols=70>
2885 $form->{body}
2886 </textarea>
2887
2888 <br>
2889 <input type=submit class=submit name=action value="|
2890     . $locale->text('Save') . qq|">
2891
2892   </form>
2893
2894
2895 </body>
2896 </html>
2897 |;
2898
2899   $lxdebug->leave_sub();
2900 }
2901
2902 sub save_template {
2903   $lxdebug->enter_sub();
2904
2905   AM->save_template(\%$form);
2906   $form->redirect($locale->text('Template saved!'));
2907
2908   $lxdebug->leave_sub();
2909 }
2910
2911 sub config {
2912   $lxdebug->enter_sub();
2913
2914   # get defaults for account numbers and last numbers
2915   AM->defaultaccounts(\%myconfig, \%$form);
2916
2917   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
2918     $dateformat .=
2919       ($item eq $myconfig{dateformat})
2920       ? "<option selected>$item\n"
2921       : "<option>$item\n";
2922   }
2923
2924   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
2925     $numberformat .=
2926       ($item eq $myconfig{numberformat})
2927       ? "<option selected>$item\n"
2928       : "<option>$item\n";
2929   }
2930
2931   foreach $item (qw(name company address signature)) {
2932     $myconfig{$item} =~ s/\"/&quot;/g;
2933   }
2934
2935   foreach $item (qw(address signature)) {
2936     $myconfig{$item} =~ s/\\n/\r\n/g;
2937   }
2938
2939   @formats = ();
2940   if ($opendocument_templates && $openofficeorg_writer_bin &&
2941       $xvfb_bin && (-x $openofficeorg_writer_bin) && (-x $xvfb_bin)) {
2942     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
2943                      "value" => "opendocument_pdf" });
2944   }
2945   if ($latex_templates) {
2946     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
2947   }
2948   push(@formats, { "name" => "HTML", "value" => "html" });
2949   if ($latex_templates) {
2950     push(@formats, { "name" => $locale->text("Postscript"),
2951                      "value" => "postscript" });
2952   }
2953   if ($opendocument_templates) {
2954     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
2955                      "value" => "opendocument" });
2956   }
2957
2958   if (!$myconfig{"template_format"}) {
2959     $myconfig{"template_format"} = "pdf";
2960   }
2961   my $template_format = "";
2962   foreach $item (@formats) {
2963     $template_format .=
2964       "<option value=\"$item->{value}\"" .
2965       ($item->{"value"} eq $myconfig{"template_format"} ?
2966        " selected" : "") .
2967        ">" . H($item->{"name"}) . "</option>";
2968   }
2969
2970   if (!$myconfig{"default_media"}) {
2971     $myconfig{"default_media"} = "screen";
2972   }
2973   my %selected = ($myconfig{"default_media"} => "selected");
2974   my $default_media = qq|
2975   <option value="screen" $selected{'screen'}>| . $locale->text("Screen") . qq|</option>
2976   <option value="printer" $selected{'printer'}>| . $locale->text("Printer") . qq|</option>
2977   <option value="queue" $selected{'queue'}>| . $locale->text("Queue") . qq|</option>
2978 |;
2979
2980   %selected = ();
2981   $selected{$myconfig{"default_printer_id"}} = "selected"
2982     if ($myconfig{"default_printer_id"});
2983   my $default_printer = qq|<option></option>|;
2984   AM->printer(\%myconfig, $form);
2985   foreach my $printer (@{$form->{"ALL"}}) {
2986     $default_printer .= qq|<option value="| . Q($printer->{"id"}) .
2987       qq|" $selected{$printer->{'id'}}>| .
2988       H($printer->{"printer_description"}) . qq|</option>|;
2989   }
2990
2991   %countrycodes = User->country_codes;
2992   $countrycodes = '';
2993   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} }
2994                 keys %countrycodes
2995     ) {
2996     $countrycodes .=
2997       ($myconfig{countrycode} eq $key)
2998       ? "<option selected value=$key>$countrycodes{$key}\n"
2999       : "<option value=$key>$countrycodes{$key}\n";
3000   }
3001   $countrycodes = "<option>American English\n$countrycodes";
3002
3003   # use an other input number format than output numberformat
3004   # look at Form.pm, sub parse_amount
3005   my $in_numberformat = '';
3006   $text1 = qq|value="0">| . $locale->text('equal Outputformat');
3007   $text2 = qq|value="1">| . $locale->text('1000,00 or 1000.00');
3008   @in_nf = ($text1, $text2);
3009   foreach $item (@in_nf) {
3010     $in_numberformat .=
3011       (substr($item, 7, 1) eq $myconfig{in_numberformat})
3012       ? "<option selected $item\n"
3013       : "<option $item\n";
3014   }
3015
3016   foreach $key (keys %{ $form->{IC} }) {
3017     foreach $accno (sort keys %{ $form->{IC}{$key} }) {
3018       $myconfig{$key} .=
3019         ($form->{IC}{$key}{$accno}{id} == $form->{defaults}{$key})
3020         ? "<option selected>$accno--$form->{IC}{$key}{$accno}{description}\n"
3021         : "<option>$accno--$form->{IC}{$key}{$accno}{description}\n";
3022     }
3023   }
3024
3025   opendir CSS, "css/.";
3026   @all = grep /.*\.css$/, readdir CSS;
3027   closedir CSS;
3028
3029   foreach $item (@all) {
3030     if ($item eq $myconfig{stylesheet}) {
3031       $selectstylesheet .= qq|<option selected>$item\n|;
3032     } else {
3033       $selectstylesheet .= qq|<option>$item\n|;
3034     }
3035   }
3036   $selectstylesheet .= "<option>\n";
3037
3038   $form->{title} = $locale->text('Edit Preferences for') . qq| $form->{login}|;
3039
3040   $form->header;
3041
3042   if ($myconfig{menustyle} eq "old") {
3043     $menustyle_old = "checked";
3044   } elsif ($myconfig{menustyle} eq "neu") {
3045     $menustyle_neu = "checked";
3046   } elsif ($myconfig{menustyle} eq "v3") {
3047     $menustyle_v3 = "checked";
3048   }
3049
3050   my ($show_form_details, $hide_form_details);
3051   $myconfig{"show_form_details"} = 1
3052     unless (defined($myconfig{"show_form_details"}));
3053   $show_form_details = "checked" if ($myconfig{"show_form_details"});
3054   $hide_form_details = "checked" unless ($myconfig{"show_form_details"});
3055
3056   print qq|
3057 <body>
3058
3059 <form method=post action=$form->{script}>
3060
3061 <input type=hidden name=old_password value=$myconfig{password}>
3062 <input type=hidden name=type value=preferences>
3063 <input type=hidden name=role value=$myconfig{role}>
3064
3065 <table width=100%>
3066   <tr><th class=listtop>$form->{title}</th></tr>
3067   <tr>
3068     <td>
3069       <table>
3070         <tr>
3071           <th align=right>| . $locale->text('Name') . qq|</th>
3072           <td><input name=name size=15 value="$myconfig{name}"></td>
3073         </tr>
3074         <tr>
3075           <th align=right>| . $locale->text('Password') . qq|</th>
3076           <td><input type=password name=new_password size=10 value=$myconfig{password}></td>
3077         </tr>
3078         <tr>
3079           <th align=right>| . $locale->text('E-mail') . qq|</th>
3080           <td><input name=email size=30 value="$myconfig{email}"></td>
3081         </tr>
3082         <tr valign=top>
3083           <th align=right>| . $locale->text('Signature') . qq|</th>
3084           <td><textarea name=signature rows=3 cols=50>$myconfig{signature}</textarea></td>
3085         </tr>
3086         <tr>
3087           <th align=right>| . $locale->text('Phone') . qq|</th>
3088           <td><input name=tel size=14 value="$myconfig{tel}"></td>
3089         </tr>
3090         <tr>
3091           <th align=right>| . $locale->text('Fax') . qq|</th>
3092           <td><input name=fax size=14 value="$myconfig{fax}"></td>
3093         </tr>
3094         <tr>
3095           <th align=right>| . $locale->text('Company') . qq|</th>
3096           <td><input name=company size=30 value="$myconfig{company}"></td>
3097         </tr>
3098         <tr valign=top>
3099           <th align=right>| . $locale->text('Address') . qq|</th>
3100           <td><textarea name=address rows=4 cols=50>$myconfig{address}</textarea></td>
3101         </tr>
3102         <tr>
3103           <th align=right>| . $locale->text('Date Format') . qq|</th>
3104           <td><select name=dateformat>$dateformat</select></td>
3105         </tr>
3106         <tr>
3107           <th align=right>| . $locale->text('Output Number Format') . qq|</th>
3108           <td><select name=numberformat>$numberformat</select></td>
3109         </tr>
3110         <tr>
3111           <th align=right>| . $locale->text('Input Number Format') . qq|</th>
3112           <td><select name=in_numberformat>$in_numberformat</select></td>
3113         </tr>
3114
3115         <tr>
3116           <th align=right>| . $locale->text('Dropdown Limit') . qq|</th>
3117           <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
3118         </tr>
3119         <tr>
3120           <th align=right>| . $locale->text('Language') . qq|</th>
3121           <td><select name=countrycode>$countrycodes</select></td>
3122         </tr>
3123         <tr>
3124           <th align=right>| . $locale->text('Stylesheet') . qq|</th>
3125           <td><select name=usestylesheet>$selectstylesheet</select></td>
3126         </tr>
3127         <tr>
3128           <th align=right>| . $locale->text('Setup Menu') . qq|</th>
3129           <td><input name=menustyle type=radio class=radio value=v3 $menustyle_v3>&nbsp;| .
3130     $locale->text("Top (CSS)") . qq|
3131           <input name=menustyle type=radio class=radio value=neu $menustyle_neu>&nbsp;| .
3132     $locale->text("Top (Javascript)") . qq|
3133     <input name=menustyle type=radio class=radio value=old $menustyle_old>&nbsp;| .
3134     $locale->text("Old (on the side)") . qq|</td>
3135   </tr>
3136   <tr>
3137     <th align=right>| . $locale->text('Form details (second row)') . qq|</th>
3138     <td><input type="radio" id="rad_show_form_details" name="show_form_details" value="1" $show_form_details>&nbsp;
3139     <label for="rad_show_form_details">| . $locale->text('Show by default') . qq|</label>
3140     <input type="radio" id="rad_hide_form_details" name="show_form_details" value="0" $hide_form_details>&nbsp;
3141     <label for="rad_hide_form_details">| . $locale->text('Hide by default') . qq|</label></td>
3142         </tr>
3143         <input name=printer type=hidden value="$myconfig{printer}">
3144         <tr class=listheading>
3145           <th colspan=2>| . $locale->text("Print options") . qq|</th>
3146         </tr>
3147         <tr>
3148           <th align=right>| . $locale->text('Default template format') . qq|</th>
3149           <td><select name="template_format">$template_format</select></td>
3150         </tr>
3151         <tr>
3152           <th align=right>| . $locale->text('Default output medium') . qq|</th>
3153           <td><select name="default_media">$default_media</select></td>
3154         </tr>
3155         <tr>
3156           <th align=right>| . $locale->text('Default printer') . qq|</th>
3157           <td><select name="default_printer_id">$default_printer</select></td>
3158         </tr>
3159         <tr>
3160           <th align=right>| . $locale->text('Number of copies') . qq|</th>
3161           <td><input name="copies" size="10" value="| .
3162     $form->quote($myconfig{"copies"}) . qq|"></td>
3163         </tr>
3164
3165
3166         <tr class=listheading>
3167           <th colspan=2>&nbsp;</th>
3168         </tr>
3169         <tr>
3170           <th align=right>| . $locale->text('Business Number') . qq|</th>
3171           <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td>
3172         </tr>
3173         <tr>
3174                 <th align=right>| . $locale->text('Year End') . qq| (mm/dd)</th>
3175                 <td><input name=yearend size=5 value=$form->{defaults}{yearend}></td>
3176         </tr>
3177         <tr class=listheading>
3178           <th colspan=2>|
3179     . $locale->text('Last Numbers & Default Accounts') . qq|</th>
3180         </tr>
3181         <tr>
3182           <td colspan=2>
3183             <table width=100%>
3184               <tr>
3185                 <th align=right nowrap>| . $locale->text('Inventory Account') . qq|</th>
3186                 <td><select name=inventory_accno>$myconfig{IC}</select></td>
3187               </tr>
3188               <tr>
3189                 <th align=right nowrap>| . $locale->text('Revenue Account') . qq|</th>
3190                 <td><select name=income_accno>$myconfig{IC_income}</select></td>
3191               </tr>
3192               <tr>
3193                 <th align=right nowrap>| . $locale->text('Expense Account') . qq|</th>
3194                 <td><select name=expense_accno>$myconfig{IC_expense}</select></td>
3195               </tr>
3196               <tr>
3197                 <th align=right nowrap>| . $locale->text('Foreign Exchange Gain') . qq|</th>
3198                 <td><select name=fxgain_accno>$myconfig{FX_gain}</select></td>
3199               </tr>
3200               <tr>
3201                 <th align=right nowrap>| . $locale->text('Foreign Exchange Loss') . qq|</th>
3202                 <td><select name=fxloss_accno>$myconfig{FX_loss}</select></td>
3203               </tr>
3204               <tr>
3205                 <td colspan=2>|
3206     . $locale->text(
3207     'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
3208     )
3209     . qq|<br><input name=curr size=40 value="$form->{defaults}{curr}"></td>
3210               </tr>
3211             </table>
3212           </td>
3213          </tr>
3214          <tr>
3215            <td colspan=2>
3216              <table width=100%>
3217               <tr>
3218                 <th align=right nowrap>| . $locale->text('Last Invoice Number') . qq|</th>
3219                 <td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></td>
3220                 <th align=right nowrap>|
3221     . $locale->text('Last Customer Number') . qq|</th>
3222                 <td><input name=customernumber size=10 value=$form->{defaults}{customernumber}></td>
3223               </tr>
3224               <tr>
3225                 <th align=right nowrap>|
3226     . $locale->text('Last Credit Note Number') . qq|</th>
3227                 <td><input name=cnnumber size=10 value=$form->{defaults}{cnnumber}></td>
3228                 <th align=right nowrap>|
3229     . $locale->text('Last Vendor Number') . qq|</th>
3230                 <td><input name=vendornumber size=10 value=$form->{defaults}{vendornumber}></td>
3231               </tr>
3232               <tr>
3233                 <th align=right nowrap>|
3234     . $locale->text('Last Sales Order Number') . qq|</th>
3235                 <td><input name=sonumber size=10 value=$form->{defaults}{sonumber}></td>
3236               </tr>
3237               <tr>
3238                 <th align=right nowrap>|
3239     . $locale->text('Last Purchase Order Number') . qq|</th>
3240                 <td><input name=ponumber size=10 value=$form->{defaults}{ponumber}></td>
3241                 <th align=right nowrap>|
3242     . $locale->text('Last Article Number') . qq|</th>
3243                 <td><input name=articlenumber size=10 value=$form->{defaults}{articlenumber}></td>
3244               </tr>
3245               <tr>
3246                 <th align=right nowrap>|
3247     . $locale->text('Last Sales Quotation Number') . qq|</th>
3248                 <td><input name=sqnumber size=10 value=$form->{defaults}{sqnumber}></td>
3249                 <th align=right nowrap>|
3250     . $locale->text('Last Service Number') . qq|</th>
3251                 <td><input name=servicenumber size=10 value=$form->{defaults}{servicenumber}></td>
3252               </tr>
3253               <tr>
3254                 <th align=right nowrap>| . $locale->text('Last RFQ Number') . qq|</th>
3255                 <td><input name=rfqnumber size=10 value=$form->{defaults}{rfqnumber}></td>
3256                 <th align=right nowrap></th>
3257                 <td></td>
3258               </tr>
3259             </table>
3260           </td>
3261         </tr>|;
3262 #       <tr class=listheading>
3263 #         <th colspan=2>| . $locale->text('Tax Accounts') . qq|</th>
3264 #       </tr>
3265 #       <tr>
3266 #         <td colspan=2>
3267 #           <table>
3268 #             <tr>
3269 #               <th>&nbsp;</th>
3270 #               <th>| . $locale->text('Rate') . qq| (%)</th>
3271 #               <th>| . $locale->text('Number') . qq|</th>
3272 #             </tr>
3273 # |;
3274
3275 #   foreach $accno (sort keys %{ $form->{taxrates} }) {
3276 #     print qq|
3277 #               <tr>
3278 #               <th align=right>$form->{taxrates}{$accno}{description}</th>
3279 #               <td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td>
3280 #               <td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td>
3281 #             </tr>
3282 # |;
3283 #     $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} ";
3284 #   }
3285
3286 #   chop $form->{taxaccounts};
3287
3288 #   print qq|
3289 # <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
3290
3291 #             </table>
3292 #         </td>
3293 #       </tr>
3294 print qq|      </table>
3295     </td>
3296   </tr>
3297   <tr>
3298     <td><hr size=3 noshade></td>
3299   </tr>
3300 </table>
3301
3302 <input type=hidden name=path value=$form->{path}>
3303 <input type=hidden name=login value=$form->{login}>
3304 <input type=hidden name=password value=$form->{password}>
3305
3306 <br>
3307 <input type=submit class=submit name=action value="|
3308     . $locale->text('Save') . qq|">
3309
3310   </form>
3311
3312 </body>
3313 </html>
3314 |;
3315
3316   $lxdebug->leave_sub();
3317 }
3318
3319 sub save_preferences {
3320   $lxdebug->enter_sub();
3321
3322   $form->{stylesheet} = $form->{usestylesheet};
3323
3324   $form->redirect($locale->text('Preferences saved!'))
3325     if (
3326      AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath, $webdav
3327      ));
3328   $form->error($locale->text('Cannot save preferences!'));
3329
3330   $lxdebug->leave_sub();
3331 }
3332
3333 sub backup {
3334   $lxdebug->enter_sub();
3335
3336   if ($form->{media} eq 'email') {
3337     $form->error($locale->text('No email address for') . " $myconfig{name}")
3338       unless ($myconfig{email});
3339
3340     $form->{OUT} = "$sendmail";
3341
3342   }
3343
3344   AM->backup(\%myconfig, \%$form, $userspath);
3345
3346   if ($form->{media} eq 'email') {
3347     $form->redirect($locale->text('Backup sent to') . qq| $myconfig{email}|);
3348   }
3349
3350   $lxdebug->leave_sub();
3351 }
3352
3353 sub audit_control {
3354   $lxdebug->enter_sub();
3355
3356   $form->{title} = $locale->text('Audit Control');
3357
3358   AM->closedto(\%myconfig, \%$form);
3359
3360   if ($form->{revtrans}) {
3361     $checked{Y} = "checked";
3362   } else {
3363     $checked{N} = "checked";
3364   }
3365
3366   $form->header;
3367
3368   print qq|
3369 <body>
3370
3371 <form method=post action=$form->{script}>
3372
3373 <input type=hidden name=path value=$form->{path}>
3374 <input type=hidden name=login value=$form->{login}>
3375 <input type=hidden name=password value=$form->{password}>
3376
3377 <table width=100%>
3378   <tr><th class=listtop>$form->{title}</th></tr>
3379   <tr height="5"></tr>
3380   <tr>
3381     <td>
3382       <table>
3383         <tr>
3384           <td>|
3385     . $locale->text('Enforce transaction reversal for all dates') . qq|</th>
3386           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
3387     . $locale->text('Yes')
3388     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
3389     . $locale->text('No')
3390     . qq|</td>
3391         </tr>
3392         <tr>
3393           <th>| . $locale->text('Close Books up to') . qq|</th>
3394           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
3395         </tr>
3396       </table>
3397     </td>
3398   </tr>
3399 </table>
3400
3401 <hr size=3 noshade>
3402
3403 <br>
3404 <input type=hidden name=nextsub value=doclose>
3405
3406 <input type=submit class=submit name=action value="|
3407     . $locale->text('Continue') . qq|">
3408
3409 </form>
3410
3411 </body>
3412 </html>
3413 |;
3414
3415   $lxdebug->leave_sub();
3416 }
3417
3418 sub doclose {
3419   $lxdebug->enter_sub();
3420
3421   AM->closebooks(\%myconfig, \%$form);
3422
3423   if ($form->{revtrans}) {
3424     $form->redirect(
3425                  $locale->text('Transaction reversal enforced for all dates'));
3426   } else {
3427     if ($form->{closedto}) {
3428       $form->redirect(
3429                      $locale->text('Transaction reversal enforced up to') . " "
3430                        . $locale->date(\%myconfig, $form->{closedto}, 1));
3431     } else {
3432       $form->redirect($locale->text('Books are open'));
3433     }
3434   }
3435
3436   $lxdebug->leave_sub();
3437 }
3438
3439 sub add_warehouse {
3440   $lxdebug->enter_sub();
3441
3442   $form->{title} = "Add";
3443
3444   $form->{callback} =
3445     "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"
3446     unless $form->{callback};
3447
3448   &warehouse_header;
3449   &form_footer;
3450
3451   $lxdebug->leave_sub();
3452 }
3453
3454 sub edit_warehouse {
3455   $lxdebug->enter_sub();
3456
3457   $form->{title} = "Edit";
3458
3459   AM->get_warehouse(\%myconfig, \%$form);
3460
3461   &warehouse_header;
3462   &form_footer;
3463
3464   $lxdebug->leave_sub();
3465 }
3466
3467 sub list_warehouse {
3468   $lxdebug->enter_sub();
3469
3470   AM->warehouses(\%myconfig, \%$form);
3471
3472   $form->{callback} =
3473     "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}";
3474
3475   $callback = $form->escape($form->{callback});
3476
3477   $form->{title} = $locale->text('Warehouses');
3478
3479   @column_index = qw(description);
3480
3481   $column_header{description} =
3482       qq|<th class=listheading width=100%>|
3483     . $locale->text('Description')
3484     . qq|</th>|;
3485
3486   $form->header;
3487
3488   print qq|
3489 <body>
3490
3491 <table width=100%>
3492   <tr>
3493     <th class=listtop>$form->{title}</th>
3494   </tr>
3495   <tr height="5"></tr>
3496   <tr>
3497     <td>
3498       <table width=100%>
3499         <tr class=listheading>
3500 |;
3501
3502   map { print "$column_header{$_}\n" } @column_index;
3503
3504   print qq|
3505         </tr>
3506 |;
3507
3508   foreach $ref (@{ $form->{ALL} }) {
3509
3510     $i++;
3511     $i %= 2;
3512
3513     print qq|
3514         <tr valign=top class=listrow$i>
3515 |;
3516
3517     $column_data{description} =
3518       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>|;
3519
3520     map { print "$column_data{$_}\n" } @column_index;
3521
3522     print qq|
3523         </tr>
3524 |;
3525   }
3526
3527   print qq|
3528       </table>
3529     </td>
3530   </tr>
3531   <tr>
3532   <td><hr size=3 noshade></td>
3533   </tr>
3534 </table>
3535
3536 <br>
3537 <form method=post action=$form->{script}>
3538
3539 <input name=callback type=hidden value="$form->{callback}">
3540
3541 <input type=hidden name=type value=warehouse>
3542
3543 <input type=hidden name=path value=$form->{path}>
3544 <input type=hidden name=login value=$form->{login}>
3545 <input type=hidden name=password value=$form->{password}>
3546
3547 <input class=submit type=submit name=action value="|
3548     . $locale->text('Add') . qq|">
3549
3550   </form>
3551
3552   </body>
3553   </html>
3554 |;
3555
3556   $lxdebug->leave_sub();
3557 }
3558
3559 sub warehouse_header {
3560   $lxdebug->enter_sub();
3561
3562   $form->{title} = $locale->text("$form->{title} Warehouse");
3563
3564   # $locale->text('Add Warehouse')
3565   # $locale->text('Edit Warehouse')
3566
3567   $form->{description} =~ s/\"/&quot;/g;
3568
3569   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
3570     $description =
3571       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
3572   } else {
3573     $description =
3574       qq|<input name=description size=60 value="$form->{description}">|;
3575   }
3576
3577   $form->header;
3578
3579   print qq|
3580 <body>
3581
3582 <form method=post action=$form->{script}>
3583
3584 <input type=hidden name=id value=$form->{id}>
3585 <input type=hidden name=type value=warehouse>
3586
3587 <table width=100%>
3588   <tr>
3589     <th class=listtop colspan=2>$form->{title}</th>
3590   </tr>
3591   <tr height="5"></tr>
3592   <tr>
3593     <th align=right>| . $locale->text('Description') . qq|</th>
3594     <td>$description</td>
3595   </tr>
3596   <tr>
3597     <td colspan=2><hr size=3 noshade></td>
3598   </tr>
3599 </table>
3600 |;
3601
3602   $lxdebug->leave_sub();
3603 }
3604
3605 sub save_warehouse {
3606   $lxdebug->enter_sub();
3607
3608   $form->isblank("description", $locale->text('Description missing!'));
3609   AM->save_warehouse(\%myconfig, \%$form);
3610   $form->redirect($locale->text('Warehouse saved!'));
3611
3612   $lxdebug->leave_sub();
3613 }
3614
3615 sub delete_warehouse {
3616   $lxdebug->enter_sub();
3617
3618   AM->delete_warehouse(\%myconfig, \%$form);
3619   $form->redirect($locale->text('Warehouse deleted!'));
3620
3621   $lxdebug->leave_sub();
3622 }
3623
3624 sub continue {
3625   $lxdebug->enter_sub();
3626
3627   &{ $form->{nextsub} };
3628
3629   $lxdebug->leave_sub();
3630 }
3631
3632 sub edit_units {
3633   $lxdebug->enter_sub();
3634
3635   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
3636   AM->units_in_use(\%myconfig, $form, $units);
3637   map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
3638
3639   @languages = AM->language(\%myconfig, $form, 1);
3640
3641   @unit_list = ();
3642   foreach $name (sort({ lc($a) cmp lc($b) } grep({ !$units->{$_}->{"base_unit"} } keys(%{$units})))) {
3643     map({ push(@unit_list, $units->{$_}); }
3644         sort({ ($units->{$a}->{"resolved_factor"} * 1) <=> ($units->{$b}->{"resolved_factor"} * 1) }
3645              grep({ $units->{$_}->{"resolved_base_unit"} eq $name } keys(%{$units}))));
3646   }
3647   my $i = 1;
3648   foreach (@unit_list) {
3649     $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"});
3650     $_->{"UNITLANGUAGES"} = [];
3651     foreach my $lang (@languages) {
3652       push(@{ $_->{"UNITLANGUAGES"} },
3653            { "idx" => $i,
3654              "unit" => $_->{"name"},
3655              "language_id" => $lang->{"id"},
3656              "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
3657              "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
3658            });
3659     }
3660     $i++;
3661   }
3662
3663   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
3664   $ddbox = AM->unit_select_data($units, undef, 1);
3665
3666   $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
3667   $form->header();
3668   print($form->parse_html_template("am/edit_units",
3669                                    { "UNITS" => \@unit_list,
3670                                      "NEW_BASE_UNIT_DDBOX" => $ddbox,
3671                                      "LANGUAGES" => \@languages }));
3672
3673   $lxdebug->leave_sub();
3674 }
3675
3676 sub add_unit {
3677   $lxdebug->enter_sub();
3678
3679   $form->isblank("new_name", $locale->text("The name is missing."));
3680   $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
3681   $all_units = AM->retrieve_units(\%myconfig, $form);
3682   $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
3683
3684   my ($base_unit, $factor);
3685   if ($form->{"new_base_unit"}) {
3686     $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
3687
3688     $form->isblank("new_factor", $locale->text("The factor is missing."));
3689     $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
3690     $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
3691     $base_unit = $form->{"new_base_unit"};
3692   }
3693
3694   my @languages;
3695   foreach my $lang (AM->language(\%myconfig, $form, 1)) {
3696     next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
3697     push(@languages, { "id" => $lang->{"id"},
3698                        "localized" => $form->{"new_localized_$lang->{id}"},
3699                        "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
3700          });
3701   }
3702
3703   AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages);
3704
3705   $form->{"saved_message"} = $locale->text("The unit has been saved.");
3706
3707   edit_units();
3708
3709   $lxdebug->leave_sub();
3710 }
3711
3712 sub set_unit_languages {
3713   $lxdebug->enter_sub();
3714
3715   my ($unit, $languages, $idx) = @_;
3716
3717   $unit->{"LANGUAGES"} = [];
3718
3719   foreach my $lang (@{$languages}) {
3720     push(@{ $unit->{"LANGUAGES"} },
3721          { "id" => $lang->{"id"},
3722            "localized" => $form->{"localized_${idx}_$lang->{id}"},
3723            "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
3724          });
3725   }
3726
3727   $lxdebug->leave_sub();
3728 }
3729
3730 sub save_unit {
3731   $lxdebug->enter_sub();
3732
3733   $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
3734   AM->units_in_use(\%myconfig, $form, $old_units);
3735
3736   @languages = AM->language(\%myconfig, $form, 1);
3737
3738   $new_units = {};
3739   @delete_units = ();
3740   foreach $i (1..($form->{"rowcount"} * 1)) {
3741     $old_unit = $old_units->{$form->{"old_name_$i"}};
3742     if (!$old_unit) {
3743       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
3744     }
3745
3746     if ($form->{"unchangeable_$i"}) {
3747       $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
3748       $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
3749       set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
3750       next;
3751     }
3752
3753     if ($old_unit->{"in_use"}) {
3754       $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
3755     }
3756
3757     if ($form->{"delete_$i"}) {
3758       push(@delete_units, $old_unit->{"name"});
3759       next;
3760     }
3761
3762     $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
3763
3764     $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
3765     my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
3766     $new_units->{$form->{"name_$i"}} = \%h;
3767     $new_units->{$form->{"name_$i"}}->{"row"} = $i;
3768     set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
3769   }
3770
3771   foreach $unit (values(%{$new_units})) {
3772     next unless ($unit->{"old_name"});
3773     if ($unit->{"base_unit"}) {
3774       $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"}))
3775         unless (defined($new_units->{$unit->{"base_unit"}}));
3776       $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
3777       $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
3778     } else {
3779       $unit->{"base_unit"} = undef;
3780       $unit->{"factor"} = undef;
3781     }
3782   }
3783
3784   foreach $unit (values(%{$new_units})) {
3785     next if ($unit->{"unchanged_unit"});
3786
3787     map({ $_->{"seen"} = 0; } values(%{$new_units}));
3788     $new_unit = $unit;
3789     while ($new_unit->{"base_unit"}) {
3790       $new_unit->{"seen"} = 1;
3791       $new_unit = $new_units->{$new_unit->{"base_unit"}};
3792       if ($new_unit->{"seen"}) {
3793         $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, " .
3794                                                         "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
3795       }
3796     }
3797   }
3798
3799   AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units);
3800
3801   $form->{"saved_message"} = $locale->text("The units have been saved.");
3802
3803   edit_units();
3804
3805   $lxdebug->leave_sub();
3806 }