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