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