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