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