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