Whitespace an den Zeilenenden entfernt.
[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 1;
40
41 # end of main
42
43 sub add    { &{"add_$form->{type}"} }
44 sub edit   { &{"edit_$form->{type}"} }
45 sub save   { &{"save_$form->{type}"} }
46 sub delete { &{"delete_$form->{type}"} }
47
48 sub add_account {
49   $lxdebug->enter_sub();
50
51   $form->{title}     = "Add";
52   $form->{charttype} = "A";
53   AM->get_account(\%myconfig, \%$form);
54
55   $form->{callback} =
56     "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}"
57     unless $form->{callback};
58
59   &account_header;
60   &form_footer;
61
62   $lxdebug->leave_sub();
63 }
64
65 sub edit_account {
66   $lxdebug->enter_sub();
67
68   $form->{title} = "Edit";
69   AM->get_account(\%myconfig, \%$form);
70
71   foreach my $item (split(/:/, $form->{link})) {
72     $form->{$item} = "checked";
73   }
74
75   &account_header;
76   &form_footer;
77
78   $lxdebug->leave_sub();
79 }
80
81 sub account_header {
82   $lxdebug->enter_sub();
83
84   $form->{title} = $locale->text("$form->{title} Account");
85
86   $checked{ $form->{charttype} } = "checked";
87   $checked{"$form->{category}_"} = "checked";
88   $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked";
89
90   $form->{description} =~ s/\"/"/g;
91
92   if (@{ $form->{TAXKEY} }) {
93     $form->{selecttaxkey} = "<option value=0>Keine Steuer 0%\n";
94     foreach $item (@{ $form->{TAXKEY} }) {
95       if ($item->{taxkey} == $form->{taxkey_id}) {
96         $form->{selecttaxkey} .=
97           "<option value=$item->{taxkey} selected>$item->{taxdescription}\n";
98       } else {
99         $form->{selecttaxkey} .=
100           "<option value=$item->{taxkey}>$item->{taxdescription}\n";
101       }
102
103     }
104   }
105
106   $taxkey = qq|
107               <tr>
108                 <th align=right>| . $locale->text('Steuersatz') . qq|</th>
109                 <td><select name=taxkey_id>$form->{selecttaxkey}</select></td>
110                 <input type=hidden name=selecttaxkey value="$form->{selecttaxkey}">
111               </tr>|;
112
113   $form->{selectustva} = "<option>\n";
114   %ustva = (48 => "Steuerfrei, Zeile 48",
115             51 => "Steuerpflichtig 16%, Zeile 51",
116             86 => "Steuerpflichtig 7%, Zeile 86",
117             91 => "Steuerfrei, Zeile 91",
118             97 => "Steuerpflichtig 16%, Zeile 97",
119             93 => "Steuerpflichtig 7%, Zeile 93",
120             94 => "Steuerpflichtig 16%, Zeile 94",
121             66 => "Vorsteuer, Zeile 66");
122   foreach $item (sort({ $a <=> $b } keys %ustva)) {
123     if ($item == $form->{pos_ustva}) {
124       $form->{selectustva} .= "<option value=$item selected>$ustva{$item}\n";
125     } else {
126       $form->{selectustva} .= "<option value=$item>$ustva{$item}\n";
127     }
128
129   }
130
131   $ustva = qq|
132               <tr>
133                 <th align=right>| . $locale->text('Umsatzsteuervoranmeldung') . qq|</th>
134                 <td><select name=pos_ustva>$form->{selectustva}</select></td>
135                 <input type=hidden name=selectustva value="$form->{selectustva}">
136               </tr>|;
137
138   $form->{selecteur} = "<option>\n";
139   %eur = (1  => "Umsatzerlöse",
140           2  => "sonstige Erlöse",
141           3  => "Privatanteile",
142           4  => "Zinserträge",
143           5  => "Ausserordentliche Erträge",
144           6  => "Vereinnahmte Umsatzst.",
145           7  => "Umsatzsteuererstattungen",
146           8  => "Wareneingänge",
147           9  => "Löhne und Gehälter",
148           10 => "Gesetzl. sozialer Aufw.",
149           11 => "Mieten",
150           12 => "Gas, Strom, Wasser",
151           13 => "Instandhaltung",
152           14 => "Steuern, Versich., Beiträge",
153           15 => "Kfz-Steuern",
154           16 => "Kfz-Versicherungen",
155           17 => "Sonst. Fahrtkosten",
156           18 => "Werbe- und Reisekosten",
157           19 => "Instandhaltung u. Werkzeuge",
158           20 => "Fachzeitschriften, Bücher",
159           21 => "Miete für Einrichtungen",
160           22 => "Rechts- und Beratungskosten",
161           23 => "Bürobedarf, Porto, Telefon",
162           24 => "Sonstige Aufwendungen",
163           25 => "Abschreibungen auf Anlagever.",
164           26 => "Abschreibungen auf GWG",
165           27 => "Vorsteuer",
166           28 => "Umsatzsteuerzahlungen",
167           29 => "Zinsaufwand",
168           30 => "Ausserordentlicher Aufwand",
169           31 => "Betriebliche Steuern");
170   foreach $item (sort({ $a <=> $b } keys(%eur))) {
171     if ($item == $form->{pos_eur}) {
172       $form->{selecteur} .= "<option value=$item selected>$eur{$item}\n";
173     } else {
174       $form->{selecteur} .= "<option value=$item>$eur{$item}\n";
175     }
176
177   }
178
179   $eur = qq|
180               <tr>
181                 <th align=right>| . $locale->text('EÜR') . qq|</th>
182                 <td><select name=pos_eur>$form->{selecteur}</select></td>
183                 <input type=hidden name=selecteur value="$form->{selecteur}">
184               </tr>|;
185
186   $form->{selectbwa} = "<option>\n";
187
188   %bwapos = (1  => 'Umsatzerlöse',
189              2  => 'Best.Verdg.FE/UE',
190              3  => 'Aktiv.Eigenleistung',
191              4  => 'Mat./Wareneinkauf',
192              5  => 'So.betr.Erlöse',
193              10 => 'Personalkosten',
194              11 => 'Raumkosten',
195              12 => 'Betriebl.Steuern',
196              13 => 'Vers./Beiträge',
197              14 => 'Kfz.Kosten o.St.',
198              15 => 'Werbe-Reisek.',
199              16 => 'Kosten Warenabgabe',
200              17 => 'Abschreibungen',
201              18 => 'Rep./instandhlt.',
202              19 => 'Übrige Steuern',
203              20 => 'Sonst.Kosten',
204              30 => 'Zinsauwand',
205              31 => 'Sonst.neutr.Aufw.',
206              32 => 'Zinserträge',
207              33 => 'Sonst.neutr.Ertrag',
208              34 => 'Verr.kalk.Kosten',
209              35 => 'Steuern Eink.u.Ertr.');
210   foreach $item (sort({ $a <=> $b } keys %bwapos)) {
211     if ($item == $form->{pos_bwa}) {
212       $form->{selectbwa} .= "<option value=$item selected>$bwapos{$item}\n";
213     } else {
214       $form->{selectbwa} .= "<option value=$item>$bwapos{$item}\n";
215     }
216
217   }
218
219   $bwa = qq|
220               <tr>
221                 <th align=right>| . $locale->text('BWA') . qq|</th>
222                 <td><select name=pos_bwa>$form->{selectbwa}</select></td>
223                 <input type=hidden name=selectbwa value="$form->{selectbwa}">
224               </tr>|;
225
226   $form->{selectbilanz} = "<option>\n";
227   foreach $item ((1, 2, 3, 4)) {
228     if ($item == $form->{pos_bilanz}) {
229       $form->{selectbilanz} .= "<option value=$item selected>$item\n";
230     } else {
231       $form->{selectbilanz} .= "<option value=$item>$item\n";
232     }
233
234   }
235
236   $bilanz = qq|
237               <tr>
238                 <th align=right>| . $locale->text('Bilanz') . qq|</th>
239                 <td><select name=pos_bilanz>$form->{selectbilanz}</select></td>
240                 <input type=hidden name=selectbilanz value="$form->{selectbilanz}">
241               </tr>|;
242
243   # this is for our parser only!
244   # type=submit $locale->text('Add Account')
245   # type=submit $locale->text('Edit Account')
246
247   $form->header;
248
249   print qq|
250 <body>
251
252 <form method=post action=$form->{script}>
253
254 <input type=hidden name=id value=$form->{id}>
255 <input type=hidden name=type value=account>
256
257 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>
258 <input type=hidden name=income_accno_id value=$form->{income_accno_id}>
259 <input type=hidden name=expense_accno_id value=$form->{expense_accno_id}>
260 <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>
261 <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}>
262
263 <table border=0 width=100%>
264   <tr>
265     <th class=listtop>$form->{title}</th>
266   </tr>
267   <tr height="5"></tr>
268   <tr valign=top>
269     <td>
270       <table>
271         <tr>
272           <th align=right>| . $locale->text('Account Number') . qq|</th>
273           <td><input name=accno size=20 value=$form->{accno}></td>
274         </tr>
275         <tr>
276           <th align=right>| . $locale->text('Description') . qq|</th>
277           <td><input name=description size=40 value="$form->{description}"></td>
278         </tr>
279         <tr>
280           <th align=right>| . $locale->text('Account Type') . qq|</th>
281           <td>
282             <table>
283               <tr valign=top>
284                 <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|
285     . $locale->text('Asset')
286     . qq|\n<br>
287                 <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|
288     . $locale->text('Liability')
289     . qq|\n<br>
290                 <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|
291     . $locale->text('Equity')
292     . qq|\n<br>
293                 <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|
294     . $locale->text('Revenue')
295     . qq|\n<br>
296                 <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|
297     . $locale->text('Expense')
298     . qq|</td>
299                 <td width=50>&nbsp;</td>
300                 <td>
301                 <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|
302     . $locale->text('Heading') . qq|<br>
303                 <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|
304     . $locale->text('Account')
305     . qq|</td>
306               </tr>
307             </table>
308           </td>
309         </tr>
310 |;
311
312   if ($form->{charttype} eq "A") {
313     print qq|
314         <tr>
315           <td colspan=2>
316             <table>
317               <tr>
318                 <th align=left>|
319       . $locale->text('Is this a summary account to record')
320       . qq|</th>
321                 <td>
322                 <input name=AR type=checkbox class=checkbox value=AR $form->{AR}>&nbsp;|
323       . $locale->text('AR')
324       . qq|&nbsp;<input name=AP type=checkbox class=checkbox value=AP $form->{AP}>&nbsp;|
325       . $locale->text('AP')
326       . qq|&nbsp;<input name=IC type=checkbox class=checkbox value=IC $form->{IC}>&nbsp;|
327       . $locale->text('Inventory')
328       . qq|</td>
329               </tr>
330             </table>
331           </td>
332         </tr>
333         <tr>
334           <th colspan=2>| . $locale->text('Include in drop-down menus') . qq|</th>
335         </tr>
336         <tr valign=top>
337           <td colspan=2>
338             <table width=100%>
339               <tr>
340                 <th align=left>| . $locale->text('Receivables') . qq|</th>
341                 <th align=left>| . $locale->text('Payables') . qq|</th>
342                 <th align=left>| . $locale->text('Parts Inventory') . qq|</th>
343                 <th align=left>| . $locale->text('Service Items') . qq|</th>
344               </tr>
345               <tr>
346                 <td>
347                 <input name=AR_amount type=checkbox class=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|
348       . $locale->text('Revenue')
349       . qq|\n<br>
350                 <input name=AR_paid type=checkbox class=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|
351       . $locale->text('Receipt')
352       . qq|\n<br>
353                 <input name=AR_tax type=checkbox class=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|
354       . $locale->text('Tax') . qq|
355                 </td>
356                 <td>
357                 <input name=AP_amount type=checkbox class=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|
358       . $locale->text('Expense/Asset')
359       . qq|\n<br>
360                 <input name=AP_paid type=checkbox class=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|
361       . $locale->text('Payment')
362       . qq|\n<br>
363                 <input name=AP_tax type=checkbox class=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|
364       . $locale->text('Tax') . qq|
365                 </td>
366                 <td>
367                 <input name=IC_sale type=checkbox class=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|
368       . $locale->text('Revenue')
369       . qq|\n<br>
370                 <input name=IC_cogs type=checkbox class=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|
371       . $locale->text('COGS')
372       . qq|\n<br>
373                 <input name=IC_taxpart type=checkbox class=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|
374       . $locale->text('Tax') . qq|
375                 </td>
376                 <td>
377                 <input name=IC_income type=checkbox class=checkbox value=IC_income $form->{IC_income}>&nbsp;|
378       . $locale->text('Revenue')
379       . qq|\n<br>
380                 <input name=IC_expense type=checkbox class=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|
381       . $locale->text('Expense')
382       . qq|\n<br>
383                 <input name=IC_taxservice type=checkbox class=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|
384       . $locale->text('Tax') . qq|
385                 </td>
386               </tr>
387             </table>
388           </td>
389         </tr>
390 |;
391   }
392
393   print qq|
394         $taxkey
395         $ustva
396         $eur
397         $bwa
398         $bilanz
399       </table>
400     </td>
401   </tr>
402   <tr>
403     <td><hr size=3 noshade></td>
404   </tr>
405 </table>
406 |;
407
408   $lxdebug->leave_sub();
409 }
410
411 sub form_footer {
412   $lxdebug->enter_sub();
413
414   print qq|
415
416 <input name=callback type=hidden value="$form->{callback}">
417
418 <input type=hidden name=path value=$form->{path}>
419 <input type=hidden name=login value=$form->{login}>
420 <input type=hidden name=password value=$form->{password}>
421
422 <br>
423 <input type=submit class=submit name=action value="|
424     . $locale->text('Save') . qq|">
425 |;
426
427   if ($form->{id} && $form->{orphaned}) {
428     print qq|<input type=submit class=submit name=action value="|
429       . $locale->text('Delete') . qq|">|;
430   }
431
432   if ($form->{menubar}) {
433     require "$form->{path}/menu.pl";
434     &menubar;
435   }
436
437   print qq|
438 </form>
439
440 </body>
441 </html>
442 |;
443
444   $lxdebug->leave_sub();
445 }
446
447 sub save_account {
448   $lxdebug->enter_sub();
449
450   $form->isblank("accno",    $locale->text('Account Number missing!'));
451   $form->isblank("category", $locale->text('Account Type missing!'));
452
453   $form->redirect($locale->text('Account saved!'))
454     if (AM->save_account(\%myconfig, \%$form));
455   $form->error($locale->text('Cannot save account!'));
456
457   $lxdebug->leave_sub();
458 }
459
460 sub list_account {
461   $lxdebug->enter_sub();
462
463   CA->all_accounts(\%myconfig, \%$form);
464
465   $form->{title} = $locale->text('Chart of Accounts');
466
467   # construct callback
468   $callback =
469     "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}";
470
471   @column_index = qw(accno gifi_accno description debit credit link);
472
473   $column_header{accno} = qq|<th>| . $locale->text('Account') . qq|</a></th>|;
474   $column_header{gifi_accno} =
475     qq|<th>| . $locale->text('GIFI') . qq|</a></th>|;
476   $column_header{description} =
477     qq|<th>| . $locale->text('Description') . qq|</a></th>|;
478   $column_header{debit}  = qq|<th>| . $locale->text('Debit') . qq|</a></th>|;
479   $column_header{credit} = qq|<th>| . $locale->text('Credit') . qq|</a></th>|;
480   $column_header{link}   = qq|<th>| . $locale->text('Link') . qq|</a></th>|;
481
482   $form->header;
483   $colspan = $#column_index + 1;
484
485   print qq|
486 <body>
487
488 <table width=100%>
489   <tr>
490     <th class=listtop colspan=$colspan>$form->{title}</th>
491   </tr>
492   <tr height=5></tr>
493   <tr class=listheading>
494 |;
495
496   map { print "$column_header{$_}\n" } @column_index;
497
498   print qq|
499 </tr>
500 |;
501
502   # escape callback
503   $callback = $form->escape($callback);
504
505   foreach $ca (@{ $form->{CA} }) {
506
507     $ca->{debit}  = "&nbsp;";
508     $ca->{credit} = "&nbsp;";
509
510     if ($ca->{amount} > 0) {
511       $ca->{credit} =
512         $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
513     }
514     if ($ca->{amount} < 0) {
515       $ca->{debit} =
516         $form->format_amount(\%myconfig, -$ca->{amount}, 2, "&nbsp;");
517     }
518
519     $ca->{link} =~ s/:/<br>/og;
520
521     if ($ca->{charttype} eq "H") {
522       print qq|<tr class=listheading>|;
523
524       $column_data{accno} =
525         qq|<th><a href=$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</a></th>|;
526       $column_data{gifi_accno} =
527         qq|<th><a href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno}</a>&nbsp;</th>|;
528       $column_data{description} = qq|<th>$ca->{description}&nbsp;</th>|;
529       $column_data{debit}       = qq|<th>&nbsp;</th>|;
530       $column_data{credit}      = qq| <th>&nbsp;</th>|;
531       $column_data{link}        = qq|<th>&nbsp;</th>|;
532
533     } else {
534       $i++;
535       $i %= 2;
536       print qq|
537 <tr valign=top class=listrow$i>|;
538       $column_data{accno} =
539         qq|<td><a href=$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</a></td>|;
540       $column_data{gifi_accno} =
541         qq|<td><a href=$form->{script}?action=edit_gifi&accno=$ca->{gifi_accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{gifi_accno}</a>&nbsp;</td>|;
542       $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
543       $column_data{debit}       = qq|<td align=right>$ca->{debit}</td>|;
544       $column_data{credit}      = qq|<td align=right>$ca->{credit}</td>|;
545       $column_data{link}        = qq|<td>$ca->{link}&nbsp;</td>|;
546
547     }
548
549     map { print "$column_data{$_}\n" } @column_index;
550
551     print "</tr>\n";
552   }
553
554   print qq|
555   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
556 </table>
557
558 </body>
559 </html>
560 |;
561
562   $lxdebug->leave_sub();
563 }
564
565 sub delete_account {
566   $lxdebug->enter_sub();
567
568   $form->{title} = $locale->text('Delete Account');
569
570   foreach $id (
571     qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
572     ) {
573     if ($form->{id} == $form->{$id}) {
574       $form->error($locale->text('Cannot delete default account!'));
575     }
576   }
577
578   $form->redirect($locale->text('Account deleted!'))
579     if (AM->delete_account(\%myconfig, \%$form));
580   $form->error($locale->text('Cannot delete account!'));
581
582   $lxdebug->leave_sub();
583 }
584
585 sub list_gifi {
586   $lxdebug->enter_sub();
587
588   @{ $form->{fields} } = (accno, description);
589   $form->{table}     = "gifi";
590   $form->{sortorder} = "accno";
591
592   AM->gifi_accounts(\%myconfig, \%$form);
593
594   $form->{title} = $locale->text('GIFI');
595
596   # construct callback
597   $callback =
598     "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}";
599
600   @column_index = qw(accno description);
601
602   $column_header{accno} = qq|<th>| . $locale->text('GIFI') . qq|</a></th>|;
603   $column_header{description} =
604     qq|<th>| . $locale->text('Description') . qq|</a></th>|;
605
606   $form->header;
607   $colspan = $#column_index + 1;
608
609   print qq|
610 <body>
611
612 <table width=100%>
613   <tr>
614     <th class=listtop colspan=$colspan>$form->{title}</th>
615   </tr>
616   <tr height="5"></tr>
617   <tr class=listheading>
618 |;
619
620   map { print "$column_header{$_}\n" } @column_index;
621
622   print qq|
623 </tr>
624 |;
625
626   # escape callback
627   $callback = $form->escape($callback);
628
629   foreach $ca (@{ $form->{ALL} }) {
630
631     $i++;
632     $i %= 2;
633
634     print qq|
635 <tr valign=top class=listrow$i>|;
636
637     $column_data{accno} =
638       qq|<td><a href=$form->{script}?action=edit_gifi&coa=1&accno=$ca->{accno}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</td>|;
639     $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
640
641     map { print "$column_data{$_}\n" } @column_index;
642
643     print "</tr>\n";
644   }
645
646   print qq|
647   <tr>
648     <td colspan=$colspan><hr size=3 noshade></td>
649   </tr>
650 </table>
651
652 </body>
653 </html>
654 |;
655
656   $lxdebug->leave_sub();
657 }
658
659 sub add_gifi {
660   $lxdebug->enter_sub();
661
662   $form->{title} = "Add";
663
664   # construct callback
665   $form->{callback} =
666     "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}";
667
668   $form->{coa} = 1;
669
670   &gifi_header;
671   &gifi_footer;
672
673   $lxdebug->leave_sub();
674 }
675
676 sub edit_gifi {
677   $lxdebug->enter_sub();
678
679   $form->{title} = "Edit";
680
681   AM->get_gifi(\%myconfig, \%$form);
682
683   &gifi_header;
684   &gifi_footer;
685
686   $lxdebug->leave_sub();
687 }
688
689 sub gifi_header {
690   $lxdebug->enter_sub();
691
692   $form->{title} = $locale->text("$form->{title} GIFI");
693
694   # $locale->text('Add GIFI')
695   # $locale->text('Edit GIFI')
696
697   $form->{description} =~ s/\"/&quot;/g;
698
699   $form->header;
700
701   print qq|
702 <body>
703
704 <form method=post action=$form->{script}>
705
706 <input type=hidden name=id value=$form->{accno}>
707 <input type=hidden name=type value=gifi>
708
709 <table width=100%>
710   <tr>
711     <th class=listtop>$form->{title}</th>
712   </tr>
713   <tr height="5"></tr>
714   <tr>
715     <td>
716       <table>
717         <tr>
718           <th align=right>| . $locale->text('GIFI') . qq|</th>
719           <td><input name=accno size=20 value=$form->{accno}></td>
720         </tr>
721         <tr>
722           <th align=right>| . $locale->text('Description') . qq|</th>
723           <td><input name=description size=60 value="$form->{description}"></td>
724         </tr>
725       </table>
726     </td>
727   </tr>
728   <tr>
729     <td colspan=2><hr size=3 noshade></td>
730   </tr>
731 </table>
732 |;
733
734   $lxdebug->leave_sub();
735 }
736
737 sub gifi_footer {
738   $lxdebug->enter_sub();
739
740   print qq|
741
742 <input name=callback type=hidden value="$form->{callback}">
743
744 <input type=hidden name=path value=$form->{path}>
745 <input type=hidden name=login value=$form->{login}>
746 <input type=hidden name=password value=$form->{password}>
747
748 <br><input type=submit class=submit name=action value="|
749     . $locale->text('Save') . qq|">|;
750
751   if ($form->{coa}) {
752     print qq|
753 <input type=submit class=submit name=action value="|
754       . $locale->text('Copy to COA') . qq|">
755 |;
756
757     if ($form->{accno} && $form->{orphaned}) {
758       print qq|<input type=submit class=submit name=action value="|
759         . $locale->text('Delete') . qq|">|;
760     }
761   }
762
763   if ($form->{menubar}) {
764     require "$form->{path}/menu.pl";
765     &menubar;
766   }
767
768   print qq|
769   </form>
770
771 </body>
772 </html>
773 |;
774
775   $lxdebug->leave_sub();
776 }
777
778 sub save_gifi {
779   $lxdebug->enter_sub();
780
781   $form->isblank("accno", $locale->text('GIFI missing!'));
782   AM->save_gifi(\%myconfig, \%$form);
783   $form->redirect($locale->text('GIFI saved!'));
784
785   $lxdebug->leave_sub();
786 }
787
788 sub copy_to_coa {
789   $lxdebug->enter_sub();
790
791   $form->isblank("accno", $locale->text('GIFI missing!'));
792
793   AM->save_gifi(\%myconfig, \%$form);
794
795   delete $form->{id};
796   $form->{gifi_accno} = $form->{accno};
797   $form->{title}      = "Add";
798   $form->{charttype}  = "A";
799
800   &account_header;
801   &form_footer;
802
803   $lxdebug->leave_sub();
804 }
805
806 sub delete_gifi {
807   $lxdebug->enter_sub();
808
809   AM->delete_gifi(\%myconfig, \%$form);
810   $form->redirect($locale->text('GIFI deleted!'));
811
812   $lxdebug->leave_sub();
813 }
814
815 sub add_department {
816   $lxdebug->enter_sub();
817
818   $form->{title} = "Add";
819   $form->{role}  = "P";
820
821   $form->{callback} =
822     "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&password=$form->{password}"
823     unless $form->{callback};
824
825   &department_header;
826   &form_footer;
827
828   $lxdebug->leave_sub();
829 }
830
831 sub edit_department {
832   $lxdebug->enter_sub();
833
834   $form->{title} = "Edit";
835
836   AM->get_department(\%myconfig, \%$form);
837
838   &department_header;
839   &form_footer;
840
841   $lxdebug->leave_sub();
842 }
843
844 sub list_department {
845   $lxdebug->enter_sub();
846
847   AM->departments(\%myconfig, \%$form);
848
849   $form->{callback} =
850     "$form->{script}?action=list_department&path=$form->{path}&login=$form->{login}&password=$form->{password}";
851
852   $callback = $form->escape($form->{callback});
853
854   $form->{title} = $locale->text('Departments');
855
856   @column_index = qw(description cost profit);
857
858   $column_header{description} =
859       qq|<th class=listheading width=90%>|
860     . $locale->text('Description')
861     . qq|</th>|;
862   $column_header{cost} =
863       qq|<th class=listheading nowrap>|
864     . $locale->text('Cost Center')
865     . qq|</th>|;
866   $column_header{profit} =
867       qq|<th class=listheading nowrap>|
868     . $locale->text('Profit Center')
869     . qq|</th>|;
870
871   $form->header;
872
873   print qq|
874 <body>
875
876 <table width=100%>
877   <tr>
878     <th class=listtop>$form->{title}</th>
879   </tr>
880   <tr height="5"></tr>
881   <tr>
882     <td>
883       <table width=100%>
884         <tr class=listheading>
885 |;
886
887   map { print "$column_header{$_}\n" } @column_index;
888
889   print qq|
890         </tr>
891 |;
892
893   foreach $ref (@{ $form->{ALL} }) {
894
895     $i++;
896     $i %= 2;
897
898     print qq|
899         <tr valign=top class=listrow$i>
900 |;
901
902     $costcenter   = ($ref->{role} eq "C") ? "X" : "";
903     $profitcenter = ($ref->{role} eq "P") ? "X" : "";
904
905     $column_data{description} =
906       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>|;
907     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
908     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
909
910     map { print "$column_data{$_}\n" } @column_index;
911
912     print qq|
913         </tr>
914 |;
915   }
916
917   print qq|
918       </table>
919     </td>
920   </tr>
921   <tr>
922   <td><hr size=3 noshade></td>
923   </tr>
924 </table>
925
926 <br>
927 <form method=post action=$form->{script}>
928
929 <input name=callback type=hidden value="$form->{callback}">
930
931 <input type=hidden name=type value=department>
932
933 <input type=hidden name=path value=$form->{path}>
934 <input type=hidden name=login value=$form->{login}>
935 <input type=hidden name=password value=$form->{password}>
936
937 <input class=submit type=submit name=action value="|
938     . $locale->text('Add') . qq|">|;
939
940   if ($form->{menubar}) {
941     require "$form->{path}/menu.pl";
942     &menubar;
943   }
944
945   print qq|
946   </form>
947
948   </body>
949   </html>
950 |;
951
952   $lxdebug->leave_sub();
953 }
954
955 sub department_header {
956   $lxdebug->enter_sub();
957
958   $form->{title} = $locale->text("$form->{title} Department");
959
960   # $locale->text('Add Department')
961   # $locale->text('Edit Department')
962
963   $form->{description} =~ s/\"/&quot;/g;
964
965   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
966     $description =
967       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
968   } else {
969     $description =
970       qq|<input name=description size=60 value="$form->{description}">|;
971   }
972
973   $costcenter   = "checked" if $form->{role} eq "C";
974   $profitcenter = "checked" if $form->{role} eq "P";
975
976   $form->header;
977
978   print qq|
979 <body>
980
981 <form method=post action=$form->{script}>
982
983 <input type=hidden name=id value=$form->{id}>
984 <input type=hidden name=type value=department>
985
986 <table width=100%>
987   <tr>
988     <th class=listtop colspan=2>$form->{title}</th>
989   </tr>
990   <tr height="5"></tr>
991   <tr>
992     <th align=right>| . $locale->text('Description') . qq|</th>
993     <td>$description</td>
994   </tr>
995   <tr>
996     <td></td>
997     <td><input type=radio style=radio name=role value="C" $costcenter> |
998     . $locale->text('Cost Center') . qq|
999         <input type=radio style=radio name=role value="P" $profitcenter> |
1000     . $locale->text('Profit Center') . qq|
1001     </td>
1002   <tr>
1003     <td colspan=2><hr size=3 noshade></td>
1004   </tr>
1005 </table>
1006 |;
1007
1008   $lxdebug->leave_sub();
1009 }
1010
1011 sub save_department {
1012   $lxdebug->enter_sub();
1013
1014   $form->isblank("description", $locale->text('Description missing!'));
1015   AM->save_department(\%myconfig, \%$form);
1016   $form->redirect($locale->text('Department saved!'));
1017
1018   $lxdebug->leave_sub();
1019 }
1020
1021 sub delete_department {
1022   $lxdebug->enter_sub();
1023
1024   AM->delete_department(\%myconfig, \%$form);
1025   $form->redirect($locale->text('Department deleted!'));
1026
1027   $lxdebug->leave_sub();
1028 }
1029
1030 sub add_business {
1031   $lxdebug->enter_sub();
1032
1033   $form->{title} = "Add";
1034
1035   $form->{callback} =
1036     "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&password=$form->{password}"
1037     unless $form->{callback};
1038
1039   &business_header;
1040   &form_footer;
1041
1042   $lxdebug->leave_sub();
1043 }
1044
1045 sub edit_business {
1046   $lxdebug->enter_sub();
1047
1048   $form->{title} = "Edit";
1049
1050   AM->get_business(\%myconfig, \%$form);
1051
1052   &business_header;
1053
1054   $form->{orphaned} = 1;
1055   &form_footer;
1056
1057   $lxdebug->leave_sub();
1058 }
1059
1060 sub list_business {
1061   $lxdebug->enter_sub();
1062
1063   AM->business(\%myconfig, \%$form);
1064
1065   $form->{callback} =
1066     "$form->{script}?action=list_business&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1067
1068   $callback = $form->escape($form->{callback});
1069
1070   $form->{title} = $locale->text('Type of Business');
1071
1072   @column_index = qw(description discount customernumberinit);
1073
1074   $column_header{description} =
1075       qq|<th class=listheading width=60%>|
1076     . $locale->text('Description')
1077     . qq|</th>|;
1078   $column_header{discount} =
1079       qq|<th class=listheading width=10%>|
1080     . $locale->text('Discount')
1081     . qq| %</th>|;
1082   $column_header{customernumberinit} =
1083       qq|<th class=listheading>|
1084     . $locale->text('Customernumberinit')
1085     . qq|</th>|;
1086
1087   $form->header;
1088
1089   print qq|
1090 <body>
1091
1092 <table width=100%>
1093   <tr>
1094     <th class=listtop>$form->{title}</th>
1095   </tr>
1096   <tr height="5"></tr>
1097   <tr>
1098     <td>
1099       <table width=100%>
1100         <tr class=listheading>
1101 |;
1102
1103   map { print "$column_header{$_}\n" } @column_index;
1104
1105   print qq|
1106         </tr>
1107 |;
1108
1109   foreach $ref (@{ $form->{ALL} }) {
1110
1111     $i++;
1112     $i %= 2;
1113
1114     print qq|
1115         <tr valign=top class=listrow$i>
1116 |;
1117
1118     $discount =
1119       $form->format_amount(\%myconfig, $ref->{discount} * 100, 1, "&nbsp");
1120     $description =
1121       ($ref->{salesman})
1122       ? "<b>$ref->{description}</b>"
1123       : "$ref->{description}";
1124     $column_data{description} =
1125       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>|;
1126     $column_data{discount}           = qq|<td align=right>$discount</td>|;
1127     $column_data{customernumberinit} =
1128       qq|<td align=right>$ref->{customernumberinit}</td>|;
1129
1130     map { print "$column_data{$_}\n" } @column_index;
1131
1132     print qq|
1133         </tr>
1134 |;
1135   }
1136
1137   print qq|
1138       </table>
1139     </td>
1140   </tr>
1141   <tr>
1142   <td><hr size=3 noshade></td>
1143   </tr>
1144 </table>
1145
1146 <br>
1147 <form method=post action=$form->{script}>
1148
1149 <input name=callback type=hidden value="$form->{callback}">
1150
1151 <input type=hidden name=type value=business>
1152
1153 <input type=hidden name=path value=$form->{path}>
1154 <input type=hidden name=login value=$form->{login}>
1155 <input type=hidden name=password value=$form->{password}>
1156
1157 <input class=submit type=submit name=action value="|
1158     . $locale->text('Add') . qq|">|;
1159
1160   if ($form->{menubar}) {
1161     require "$form->{path}/menu.pl";
1162     &menubar;
1163   }
1164
1165   print qq|
1166
1167   </form>
1168
1169   </body>
1170   </html>
1171 |;
1172
1173   $lxdebug->leave_sub();
1174 }
1175
1176 sub business_header {
1177   $lxdebug->enter_sub();
1178
1179   $form->{title}    = $locale->text("$form->{title} Business");
1180   $form->{salesman} = "checked" if $form->{salesman};
1181
1182   # $locale->text('Add Business')
1183   # $locale->text('Edit Business')
1184
1185   $form->{description} =~ s/\"/&quot;/g;
1186   $form->{discount} =
1187     $form->format_amount(\%myconfig, $form->{discount} * 100);
1188
1189   $form->header;
1190
1191   print qq|
1192 <body>
1193
1194 <form method=post action=$form->{script}>
1195
1196 <input type=hidden name=id value=$form->{id}>
1197 <input type=hidden name=type value=business>
1198
1199 <table width=100%>
1200   <tr>
1201     <th class=listtop colspan=2>$form->{title}</th>
1202   </tr>
1203   <tr height="5"></tr>
1204   <tr>
1205     <th align=right>| . $locale->text('Type of Business') . qq|</th>
1206     <td><input name=description size=30 value="$form->{description}"></td>
1207   <tr>
1208   <tr>
1209     <th align=right>| . $locale->text('Discount') . qq| %</th>
1210     <td><input name=discount size=5 value=$form->{discount}></td>
1211   </tr>
1212   <tr>
1213     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
1214     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
1215   </tr>
1216   <tr>
1217     <td align=right>| . $locale->text('Salesman') . qq|</td>
1218     <td><input name=salesman class=checkbox type=checkbox value=1 $form->{salesman}></td>
1219   </tr>
1220   <td colspan=2><hr size=3 noshade></td>
1221   </tr>
1222 </table>
1223 |;
1224
1225   $lxdebug->leave_sub();
1226 }
1227
1228 sub save_business {
1229   $lxdebug->enter_sub();
1230
1231   $form->isblank("description", $locale->text('Description missing!'));
1232   AM->save_business(\%myconfig, \%$form);
1233   $form->redirect($locale->text('Business saved!'));
1234
1235   $lxdebug->leave_sub();
1236 }
1237
1238 sub delete_business {
1239   $lxdebug->enter_sub();
1240
1241   AM->delete_business(\%myconfig, \%$form);
1242   $form->redirect($locale->text('Business deleted!'));
1243
1244   $lxdebug->leave_sub();
1245 }
1246
1247 sub add_sic {
1248   $lxdebug->enter_sub();
1249
1250   $form->{title} = "Add";
1251
1252   $form->{callback} =
1253     "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}"
1254     unless $form->{callback};
1255
1256   &sic_header;
1257   &form_footer;
1258
1259   $lxdebug->leave_sub();
1260 }
1261
1262 sub edit_sic {
1263   $lxdebug->enter_sub();
1264
1265   $form->{title} = "Edit";
1266
1267   AM->get_sic(\%myconfig, \%$form);
1268
1269   &sic_header;
1270
1271   $form->{orphaned} = 1;
1272   &form_footer;
1273
1274   $lxdebug->leave_sub();
1275 }
1276
1277 sub list_sic {
1278   $lxdebug->enter_sub();
1279
1280   AM->sic(\%myconfig, \%$form);
1281
1282   $form->{callback} =
1283     "$form->{script}?action=list_sic&path=$form->{path}&login=$form->{login}&password=$form->{password}";
1284
1285   $callback = $form->escape($form->{callback});
1286
1287   $form->{title} = $locale->text('Standard Industrial Codes');
1288
1289   @column_index = qw(code description);
1290
1291   $column_header{code} =
1292     qq|<th class=listheading>| . $locale->text('Code') . qq|</th>|;
1293   $column_header{description} =
1294     qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
1295
1296   $form->header;
1297
1298   print qq|
1299 <body>
1300
1301 <table width=100%>
1302   <tr>
1303     <th class=listtop>$form->{title}</th>
1304   </tr>
1305   <tr height="5"></tr>
1306   <tr>
1307     <td>
1308       <table width=100%>
1309         <tr class=listheading>
1310 |;
1311
1312   map { print "$column_header{$_}\n" } @column_index;
1313
1314   print qq|
1315         </tr>
1316 |;
1317
1318   foreach $ref (@{ $form->{ALL} }) {
1319
1320     $i++;
1321     $i %= 2;
1322
1323     if ($ref->{sictype} eq 'H') {
1324       print qq|
1325         <tr valign=top class=listheading>
1326 |;
1327       $column_data{code} =
1328         qq|<th><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}</th>|;
1329       $column_data{description} = qq|<th>$ref->{description}</th>|;
1330
1331     } else {
1332       print qq|
1333         <tr valign=top class=listrow$i>
1334 |;
1335
1336       $column_data{code} =
1337         qq|<td><a href=$form->{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}</td>|;
1338       $column_data{description} = qq|<td>$ref->{description}</td>|;
1339
1340     }
1341
1342     map { print "$column_data{$_}\n" } @column_index;
1343
1344     print qq|
1345         </tr>
1346 |;
1347   }
1348
1349   print qq|
1350       </table>
1351     </td>
1352   </tr>
1353   <tr>
1354   <td><hr size=3 noshade></td>
1355   </tr>
1356 </table>
1357
1358 <br>
1359 <form method=post action=$form->{script}>
1360
1361 <input name=callback type=hidden value="$form->{callback}">
1362
1363 <input type=hidden name=type value=sic>
1364
1365 <input type=hidden name=path value=$form->{path}>
1366 <input type=hidden name=login value=$form->{login}>
1367 <input type=hidden name=password value=$form->{password}>
1368
1369 <input class=submit type=submit name=action value="|
1370     . $locale->text('Add') . qq|">|;
1371
1372   if ($form->{menubar}) {
1373     require "$form->{path}/menu.pl";
1374     &menubar;
1375   }
1376
1377   print qq|
1378   </form>
1379
1380   </body>
1381   </html>
1382 |;
1383
1384   $lxdebug->leave_sub();
1385 }
1386
1387 sub sic_header {
1388   $lxdebug->enter_sub();
1389
1390   $form->{title} = $locale->text("$form->{title} SIC");
1391
1392   # $locale->text('Add SIC')
1393   # $locale->text('Edit SIC')
1394
1395   $form->{code}        =~ s/\"/&quot;/g;
1396   $form->{description} =~ s/\"/&quot;/g;
1397
1398   $checked = ($form->{sictype} eq 'H') ? "checked" : "";
1399
1400   $form->header;
1401
1402   print qq|
1403 <body>
1404
1405 <form method=post action=$form->{script}>
1406
1407 <input type=hidden name=type value=sic>
1408 <input type=hidden name=id value=$form->{code}>
1409
1410 <table width=100%>
1411   <tr>
1412     <th class=listtop colspan=2>$form->{title}</th>
1413   </tr>
1414   <tr height="5"></tr>
1415   <tr>
1416     <th align=right>| . $locale->text('Code') . qq|</th>
1417     <td><input name=code size=10 value=$form->{code}></td>
1418   <tr>
1419   <tr>
1420     <td></td>
1421     <th align=left><input name=sictype type=checkbox style=checkbox value="H" $checked> |
1422     . $locale->text('Heading')
1423     . qq|</th>
1424   <tr>
1425   <tr>
1426     <th align=right>| . $locale->text('Description') . qq|</th>
1427     <td><input name=description size=60 value="$form->{description}"></td>
1428   </tr>
1429     <td colspan=2><hr size=3 noshade></td>
1430   </tr>
1431 </table>
1432 |;
1433
1434   $lxdebug->leave_sub();
1435 }
1436
1437 sub save_sic {
1438   $lxdebug->enter_sub();
1439
1440   $form->isblank("code",        $locale->text('Code missing!'));
1441   $form->isblank("description", $locale->text('Description missing!'));
1442   AM->save_sic(\%myconfig, \%$form);
1443   $form->redirect($locale->text('SIC saved!'));
1444
1445   $lxdebug->leave_sub();
1446 }
1447
1448 sub delete_sic {
1449   $lxdebug->enter_sub();
1450
1451   AM->delete_sic(\%myconfig, \%$form);
1452   $form->redirect($locale->text('SIC deleted!'));
1453
1454   $lxdebug->leave_sub();
1455 }
1456
1457 sub display_stylesheet {
1458   $lxdebug->enter_sub();
1459
1460   $form->{file} = "css/$myconfig{stylesheet}";
1461   &display_form;
1462
1463   $lxdebug->leave_sub();
1464 }
1465
1466 sub display_form {
1467   $lxdebug->enter_sub();
1468
1469   $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
1470   $form->{file} =~ s/^\/*//g;
1471   $form->{file} =~ s/$userspath//;
1472
1473   $form->error("$!: $form->{file}") unless -f $form->{file};
1474
1475   AM->load_template(\%$form);
1476
1477   $form->{title} = $form->{file};
1478
1479   # if it is anything but html
1480   if ($form->{file} !~ /\.html$/) {
1481     $form->{body} = "<pre>\n$form->{body}\n</pre>";
1482   }
1483
1484   $form->header;
1485
1486   print qq|
1487 <body>
1488
1489 $form->{body}
1490
1491 <form method=post action=$form->{script}>
1492
1493 <input name=file type=hidden value=$form->{file}>
1494 <input name=type type=hidden value=template>
1495
1496 <input type=hidden name=path value=$form->{path}>
1497 <input type=hidden name=login value=$form->{login}>
1498 <input type=hidden name=password value=$form->{password}>
1499
1500 <input name=action type=submit class=submit value="|
1501     . $locale->text('Edit') . qq|">|;
1502
1503   if ($form->{menubar}) {
1504     require "$form->{path}/menu.pl";
1505     &menubar;
1506   }
1507
1508   print qq|
1509   </form>
1510
1511 </body>
1512 </html>
1513 |;
1514
1515   $lxdebug->leave_sub();
1516 }
1517
1518 sub edit_template {
1519   $lxdebug->enter_sub();
1520
1521   AM->load_template(\%$form);
1522
1523   $form->{title} = $locale->text('Edit Template');
1524
1525   # convert &nbsp to &amp;nbsp;
1526   $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
1527
1528   $form->header;
1529
1530   print qq|
1531 <body>
1532
1533 <form method=post action=$form->{script}>
1534
1535 <input name=file type=hidden value=$form->{file}>
1536 <input name=type type=hidden value=template>
1537
1538 <input type=hidden name=path value=$form->{path}>
1539 <input type=hidden name=login value=$form->{login}>
1540 <input type=hidden name=password value=$form->{password}>
1541
1542 <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}">
1543
1544 <textarea name=body rows=25 cols=70>
1545 $form->{body}
1546 </textarea>
1547
1548 <br>
1549 <input type=submit class=submit name=action value="|
1550     . $locale->text('Save') . qq|">|;
1551
1552   if ($form->{menubar}) {
1553     require "$form->{path}/menu.pl";
1554     &menubar;
1555   }
1556
1557   print q|
1558   </form>
1559
1560
1561 </body>
1562 </html>
1563 |;
1564
1565   $lxdebug->leave_sub();
1566 }
1567
1568 sub save_template {
1569   $lxdebug->enter_sub();
1570
1571   AM->save_template(\%$form);
1572   $form->redirect($locale->text('Template saved!'));
1573
1574   $lxdebug->leave_sub();
1575 }
1576
1577 sub config {
1578   $lxdebug->enter_sub();
1579
1580   # get defaults for account numbers and last numbers
1581   AM->defaultaccounts(\%myconfig, \%$form);
1582
1583   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
1584     $dateformat .=
1585       ($item eq $myconfig{dateformat})
1586       ? "<option selected>$item\n"
1587       : "<option>$item\n";
1588   }
1589
1590   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
1591     $numberformat .=
1592       ($item eq $myconfig{numberformat})
1593       ? "<option selected>$item\n"
1594       : "<option>$item\n";
1595   }
1596
1597   foreach $item (qw(name company address signature)) {
1598     $myconfig{$item} =~ s/\"/&quot;/g;
1599   }
1600
1601   foreach $item (qw(address signature)) {
1602     $myconfig{$item} =~ s/\\n/\r\n/g;
1603   }
1604
1605   %countrycodes = User->country_codes;
1606   $countrycodes = '';
1607   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} }
1608                 keys %countrycodes) {
1609     $countrycodes .=
1610       ($myconfig{countrycode} eq $key)
1611       ? "<option selected value=$key>$countrycodes{$key}\n"
1612       : "<option value=$key>$countrycodes{$key}\n";
1613   }
1614   $countrycodes = "<option>American English\n$countrycodes";
1615
1616   foreach $key (keys %{ $form->{IC} }) {
1617     foreach $accno (sort keys %{ $form->{IC}{$key} }) {
1618       $myconfig{$key} .=
1619         ($form->{IC}{$key}{$accno}{id} == $form->{defaults}{$key})
1620         ? "<option selected>$accno--$form->{IC}{$key}{$accno}{description}\n"
1621         : "<option>$accno--$form->{IC}{$key}{$accno}{description}\n";
1622     }
1623   }
1624
1625   opendir CSS, "css/.";
1626   @all = grep /.*\.css$/, readdir CSS;
1627   closedir CSS;
1628
1629   foreach $item (@all) {
1630     if ($item eq $myconfig{stylesheet}) {
1631       $selectstylesheet .= qq|<option selected>$item\n|;
1632     } else {
1633       $selectstylesheet .= qq|<option>$item\n|;
1634     }
1635   }
1636   $selectstylesheet .= "<option>\n";
1637
1638   $form->{title} = $locale->text('Edit Preferences for') . qq| $form->{login}|;
1639
1640   $form->header;
1641
1642   print qq|
1643 <body>
1644
1645 <form method=post action=$form->{script}>
1646
1647 <input type=hidden name=old_password value=$myconfig{password}>
1648 <input type=hidden name=type value=preferences>
1649 <input type=hidden name=role value=$myconfig{role}>
1650
1651 <table width=100%>
1652   <tr><th class=listtop>$form->{title}</th></tr>
1653   <tr>
1654     <td>
1655       <table>
1656         <tr>
1657           <th align=right>| . $locale->text('Name') . qq|</th>
1658           <td><input name=name size=15 value="$myconfig{name}"></td>
1659         </tr>
1660         <tr>
1661           <th align=right>| . $locale->text('Password') . qq|</th>
1662           <td><input type=password name=new_password size=10 value=$myconfig{password}></td>
1663         </tr>
1664         <tr>
1665           <th align=right>| . $locale->text('E-mail') . qq|</th>
1666           <td><input name=email size=30 value="$myconfig{email}"></td>
1667         </tr>
1668         <tr valign=top>
1669           <th align=right>| . $locale->text('Signature') . qq|</th>
1670           <td><textarea name=signature rows=3 cols=50>$myconfig{signature}</textarea></td>
1671         </tr>
1672         <tr>
1673           <th align=right>| . $locale->text('Phone') . qq|</th>
1674           <td><input name=tel size=14 value="$myconfig{tel}"></td>
1675         </tr>
1676         <tr>
1677           <th align=right>| . $locale->text('Fax') . qq|</th>
1678           <td><input name=fax size=14 value="$myconfig{fax}"></td>
1679         </tr>
1680         <tr>
1681           <th align=right>| . $locale->text('Company') . qq|</th>
1682           <td><input name=company size=30 value="$myconfig{company}"></td>
1683         </tr>
1684         <tr valign=top>
1685           <th align=right>| . $locale->text('Address') . qq|</th>
1686           <td><textarea name=address rows=4 cols=50>$myconfig{address}</textarea></td>
1687         </tr>
1688         <tr>
1689           <th align=right>| . $locale->text('Date Format') . qq|</th>
1690           <td><select name=dateformat>$dateformat</select></td>
1691         </tr>
1692         <tr>
1693           <th align=right>| . $locale->text('Number Format') . qq|</th>
1694           <td><select name=numberformat>$numberformat</select></td>
1695         </tr>
1696         <tr>
1697           <th align=right>| . $locale->text('Dropdown Limit') . qq|</th>
1698           <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
1699         </tr>
1700         <tr>
1701           <th align=right>| . $locale->text('Language') . qq|</th>
1702           <td><select name=countrycode>$countrycodes</select></td>
1703         </tr>
1704         <tr>
1705           <th align=right>| . $locale->text('Character Set') . qq|</th>
1706           <td><input name=charset size=20 value="$myconfig{charset}"></td>
1707         </tr>
1708         <tr>
1709           <th align=right>| . $locale->text('Stylesheet') . qq|</th>
1710           <td><select name=usestylesheet>$selectstylesheet</select></td>
1711         </tr>
1712         <input name=printer type=hidden value="$myconfig{printer}">
1713         <tr class=listheading>
1714           <th colspan=2>&nbsp;</th>
1715         </tr>
1716         <tr>
1717           <th align=right>| . $locale->text('Business Number') . qq|</th>
1718           <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td>
1719         </tr>
1720         <tr>
1721           <td colspan=2>
1722             <table width=100%>
1723               <tr>
1724                 <th align=right>| . $locale->text('Year End') . qq| (mm/dd)</th>
1725                 <td><input name=yearend size=5 value=$form->{defaults}{yearend}></td>
1726                 <th align=right>| . $locale->text('Weight Unit') . qq|</th>
1727                 <td><input name=weightunit size=5 value="$form->{defaults}{weightunit}"></td>
1728               </tr>
1729             </table>
1730           </td>
1731         </tr>
1732         <tr class=listheading>
1733           <th colspan=2>|
1734     . $locale->text('Last Numbers & Default Accounts')
1735     . qq|</th>
1736         </tr>
1737         <tr>
1738           <td colspan=2>
1739             <table width=100%>
1740               <tr>
1741                 <th align=right nowrap>| . $locale->text('Inventory Account') . qq|</th>
1742                 <td><select name=inventory_accno>$myconfig{IC}</select></td>
1743               </tr>
1744               <tr>
1745                 <th align=right nowrap>| . $locale->text('Revenue Account') . qq|</th>
1746                 <td><select name=income_accno>$myconfig{IC_income}</select></td>
1747               </tr>
1748               <tr>
1749                 <th align=right nowrap>| . $locale->text('Expense Account') . qq|</th>
1750                 <td><select name=expense_accno>$myconfig{IC_expense}</select></td>
1751               </tr>
1752               <tr>
1753                 <th align=right nowrap>| . $locale->text('Foreign Exchange Gain') . qq|</th>
1754                 <td><select name=fxgain_accno>$myconfig{FX_gain}</select></td>
1755               </tr>
1756               <tr>
1757                 <th align=right nowrap>| . $locale->text('Foreign Exchange Loss') . qq|</th>
1758                 <td><select name=fxloss_accno>$myconfig{FX_loss}</select></td>
1759               </tr>
1760               <tr>
1761                 <td colspan=2>|
1762     . $locale->text(
1763     'Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies'
1764     )
1765     . qq|<br><input name=curr size=40 value="$form->{defaults}{curr}"></td>
1766               </tr>
1767             </table>
1768           </td>
1769          </tr>
1770          <tr>
1771            <td colspan=2>
1772              <table width=100%>
1773               <tr>
1774                 <th align=right nowrap>| . $locale->text('Last Invoice Number') . qq|</th>
1775                 <td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></td>
1776                 <th align=right nowrap>|
1777     . $locale->text('Last Customer Number')
1778     . qq|</th>
1779                 <td><input name=customernumber size=10 value=$form->{defaults}{customernumber}></td>
1780               </tr>
1781               <tr>
1782                 <th align=right nowrap>|
1783     . $locale->text('Last Sales Order Number')
1784     . qq|</th>
1785                 <td><input name=sonumber size=10 value=$form->{defaults}{sonumber}></td>
1786                 <th align=right nowrap>|
1787     . $locale->text('Last Vendor Number')
1788     . qq|</th>
1789                 <td><input name=vendornumber size=10 value=$form->{defaults}{vendornumber}></td>
1790               </tr>
1791               <tr>
1792                 <th align=right nowrap>|
1793     . $locale->text('Last Purchase Order Number')
1794     . qq|</th>
1795                 <td><input name=ponumber size=10 value=$form->{defaults}{ponumber}></td>
1796                 <th align=right nowrap>|
1797     . $locale->text('Last Article Number')
1798     . qq|</th>
1799                 <td><input name=articlenumber size=10 value=$form->{defaults}{articlenumber}></td>
1800               </tr>
1801               <tr>
1802                 <th align=right nowrap>|
1803     . $locale->text('Last Sales Quotation Number')
1804     . qq|</th>
1805                 <td><input name=sqnumber size=10 value=$form->{defaults}{sqnumber}></td>
1806                 <th align=right nowrap>|
1807     . $locale->text('Last Service Number')
1808     . qq|</th>
1809                 <td><input name=servicenumber size=10 value=$form->{defaults}{servicenumber}></td>
1810               </tr>
1811               <tr>
1812                 <th align=right nowrap>| . $locale->text('Last RFQ Number') . qq|</th>
1813                 <td><input name=rfqnumber size=10 value=$form->{defaults}{rfqnumber}></td>
1814                 <th align=right nowrap></th>
1815                 <td></td>
1816               </tr>
1817             </table>
1818           </td>
1819         </tr>
1820         <tr class=listheading>
1821           <th colspan=2>| . $locale->text('Tax Accounts') . qq|</th>
1822         </tr>
1823         <tr>
1824           <td colspan=2>
1825             <table>
1826               <tr>
1827                 <th>&nbsp;</th>
1828                 <th>| . $locale->text('Rate') . qq| (%)</th>
1829                 <th>| . $locale->text('Number') . qq|</th>
1830               </tr>
1831 |;
1832
1833   foreach $accno (sort keys %{ $form->{taxrates} }) {
1834     print qq|
1835               <tr>
1836                 <th align=right>$form->{taxrates}{$accno}{description}</th>
1837                 <td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td>
1838                 <td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td>
1839               </tr>
1840 |;
1841     $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} ";
1842   }
1843
1844   chop $form->{taxaccounts};
1845
1846   print qq|
1847 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
1848
1849             </table>
1850           </td>
1851         </tr>
1852       </table>
1853     </td>
1854   </tr>
1855   <tr>
1856     <td><hr size=3 noshade></td>
1857   </tr>
1858 </table>
1859
1860 <input type=hidden name=path value=$form->{path}>
1861 <input type=hidden name=login value=$form->{login}>
1862 <input type=hidden name=password value=$form->{password}>
1863
1864 <br>
1865 <input type=submit class=submit name=action value="|
1866     . $locale->text('Save') . qq|">|;
1867
1868   if ($form->{menubar}) {
1869     require "$form->{path}/menu.pl";
1870     &menubar;
1871   }
1872
1873   print qq|
1874   </form>
1875
1876 </body>
1877 </html>
1878 |;
1879
1880   $lxdebug->leave_sub();
1881 }
1882
1883 sub save_preferences {
1884   $lxdebug->enter_sub();
1885
1886   $form->{stylesheet} = $form->{usestylesheet};
1887
1888   $form->redirect($locale->text('Preferences saved!'))
1889     if (
1890      AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath, $webdav
1891      ));
1892   $form->error($locale->text('Cannot save preferences!'));
1893
1894   $lxdebug->leave_sub();
1895 }
1896
1897 sub backup {
1898   $lxdebug->enter_sub();
1899
1900   if ($form->{media} eq 'email') {
1901     $form->error($locale->text('No email address for') . " $myconfig{name}")
1902       unless ($myconfig{email});
1903
1904     $form->{OUT} = "$sendmail";
1905
1906   }
1907
1908   AM->backup(\%myconfig, \%$form, $userspath);
1909
1910   if ($form->{media} eq 'email') {
1911     $form->redirect($locale->text('Backup sent to') . qq| $myconfig{email}|);
1912   }
1913
1914   $lxdebug->leave_sub();
1915 }
1916
1917 sub audit_control {
1918   $lxdebug->enter_sub();
1919
1920   $form->{title} = $locale->text('Audit Control');
1921
1922   AM->closedto(\%myconfig, \%$form);
1923
1924   if ($form->{revtrans}) {
1925     $checked{Y} = "checked";
1926   } else {
1927     $checked{N} = "checked";
1928   }
1929
1930   $form->header;
1931
1932   print qq|
1933 <body>
1934
1935 <form method=post action=$form->{script}>
1936
1937 <input type=hidden name=path value=$form->{path}>
1938 <input type=hidden name=login value=$form->{login}>
1939 <input type=hidden name=password value=$form->{password}>
1940
1941 <table width=100%>
1942   <tr><th class=listtop>$form->{title}</th></tr>
1943   <tr height="5"></tr>
1944   <tr>
1945     <td>
1946       <table>
1947         <tr>
1948           <td>|
1949     . $locale->text('Enforce transaction reversal for all dates')
1950     . qq|</th>
1951           <td><input name=revtrans class=radio type=radio value="1" $checked{Y}> |
1952     . $locale->text('Yes')
1953     . qq| <input name=revtrans class=radio type=radio value="0" $checked{N}> |
1954     . $locale->text('No')
1955     . qq|</td>
1956         </tr>
1957         <tr>
1958           <th>| . $locale->text('Close Books up to') . qq|</th>
1959           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1960         </tr>
1961       </table>
1962     </td>
1963   </tr>
1964 </table>
1965
1966 <hr size=3 noshade>
1967
1968 <br>
1969 <input type=hidden name=nextsub value=doclose>
1970
1971 <input type=submit class=submit name=action value="|
1972     . $locale->text('Continue') . qq|">
1973
1974 </form>
1975
1976 </body>
1977 </html>
1978 |;
1979
1980   $lxdebug->leave_sub();
1981 }
1982
1983 sub doclose {
1984   $lxdebug->enter_sub();
1985
1986   AM->closebooks(\%myconfig, \%$form);
1987
1988   if ($form->{revtrans}) {
1989     $form->redirect(
1990                  $locale->text('Transaction reversal enforced for all dates'));
1991   } else {
1992     if ($form->{closedto}) {
1993       $form->redirect(
1994                      $locale->text('Transaction reversal enforced up to') . " "
1995                        . $locale->date(\%myconfig, $form->{closedto}, 1));
1996     } else {
1997       $form->redirect($locale->text('Books are open'));
1998     }
1999   }
2000
2001   $lxdebug->leave_sub();
2002 }
2003
2004 sub add_warehouse {
2005   $lxdebug->enter_sub();
2006
2007   $form->{title} = "Add";
2008
2009   $form->{callback} =
2010     "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"
2011     unless $form->{callback};
2012
2013   &warehouse_header;
2014   &form_footer;
2015
2016   $lxdebug->leave_sub();
2017 }
2018
2019 sub edit_warehouse {
2020   $lxdebug->enter_sub();
2021
2022   $form->{title} = "Edit";
2023
2024   AM->get_warehouse(\%myconfig, \%$form);
2025
2026   &warehouse_header;
2027   &form_footer;
2028
2029   $lxdebug->leave_sub();
2030 }
2031
2032 sub list_warehouse {
2033   $lxdebug->enter_sub();
2034
2035   AM->warehouses(\%myconfig, \%$form);
2036
2037   $form->{callback} =
2038     "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}";
2039
2040   $callback = $form->escape($form->{callback});
2041
2042   $form->{title} = $locale->text('Warehouses');
2043
2044   @column_index = qw(description);
2045
2046   $column_header{description} =
2047       qq|<th class=listheading width=100%>|
2048     . $locale->text('Description')
2049     . qq|</th>|;
2050
2051   $form->header;
2052
2053   print qq|
2054 <body>
2055
2056 <table width=100%>
2057   <tr>
2058     <th class=listtop>$form->{title}</th>
2059   </tr>
2060   <tr height="5"></tr>
2061   <tr>
2062     <td>
2063       <table width=100%>
2064         <tr class=listheading>
2065 |;
2066
2067   map { print "$column_header{$_}\n" } @column_index;
2068
2069   print qq|
2070         </tr>
2071 |;
2072
2073   foreach $ref (@{ $form->{ALL} }) {
2074
2075     $i++;
2076     $i %= 2;
2077
2078     print qq|
2079         <tr valign=top class=listrow$i>
2080 |;
2081
2082     $column_data{description} =
2083       qq|<td><a href=$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
2084
2085     map { print "$column_data{$_}\n" } @column_index;
2086
2087     print qq|
2088         </tr>
2089 |;
2090   }
2091
2092   print qq|
2093       </table>
2094     </td>
2095   </tr>
2096   <tr>
2097   <td><hr size=3 noshade></td>
2098   </tr>
2099 </table>
2100
2101 <br>
2102 <form method=post action=$form->{script}>
2103
2104 <input name=callback type=hidden value="$form->{callback}">
2105
2106 <input type=hidden name=type value=warehouse>
2107
2108 <input type=hidden name=path value=$form->{path}>
2109 <input type=hidden name=login value=$form->{login}>
2110 <input type=hidden name=password value=$form->{password}>
2111
2112 <input class=submit type=submit name=action value="|
2113     . $locale->text('Add') . qq|">|;
2114
2115   if ($form->{menubar}) {
2116     require "$form->{path}/menu.pl";
2117     &menubar;
2118   }
2119
2120   print qq|
2121   </form>
2122
2123   </body>
2124   </html>
2125 |;
2126
2127   $lxdebug->leave_sub();
2128 }
2129
2130 sub warehouse_header {
2131   $lxdebug->enter_sub();
2132
2133   $form->{title} = $locale->text("$form->{title} Warehouse");
2134
2135   # $locale->text('Add Warehouse')
2136   # $locale->text('Edit Warehouse')
2137
2138   $form->{description} =~ s/\"/&quot;/g;
2139
2140   if (($rows = $form->numtextrows($form->{description}, 60)) > 1) {
2141     $description =
2142       qq|<textarea name="description" rows=$rows cols=60 wrap=soft>$form->{description}</textarea>|;
2143   } else {
2144     $description =
2145       qq|<input name=description size=60 value="$form->{description}">|;
2146   }
2147
2148   $form->header;
2149
2150   print qq|
2151 <body>
2152
2153 <form method=post action=$form->{script}>
2154
2155 <input type=hidden name=id value=$form->{id}>
2156 <input type=hidden name=type value=warehouse>
2157
2158 <table width=100%>
2159   <tr>
2160     <th class=listtop colspan=2>$form->{title}</th>
2161   </tr>
2162   <tr height="5"></tr>
2163   <tr>
2164     <th align=right>| . $locale->text('Description') . qq|</th>
2165     <td>$description</td>
2166   </tr>
2167   <tr>
2168     <td colspan=2><hr size=3 noshade></td>
2169   </tr>
2170 </table>
2171 |;
2172
2173   $lxdebug->leave_sub();
2174 }
2175
2176 sub save_warehouse {
2177   $lxdebug->enter_sub();
2178
2179   $form->isblank("description", $locale->text('Description missing!'));
2180   AM->save_warehouse(\%myconfig, \%$form);
2181   $form->redirect($locale->text('Warehouse saved!'));
2182
2183   $lxdebug->leave_sub();
2184 }
2185
2186 sub delete_warehouse {
2187   $lxdebug->enter_sub();
2188
2189   AM->delete_warehouse(\%myconfig, \%$form);
2190   $form->redirect($locale->text('Warehouse deleted!'));
2191
2192   $lxdebug->leave_sub();
2193 }
2194
2195 sub continue {
2196   $lxdebug->enter_sub();
2197
2198   &{ $form->{nextsub} };
2199
2200   $lxdebug->leave_sub();
2201 }