import of sql-ledger 2.0.8
[freeside.git] / sql-ledger / bin / mozilla / am.pl
1 #=====================================================================
2 # SQL-Ledger Accounting
3 # Copyright (c) 1998-2002
4 #
5 #  Author: Dieter Simader
6 #   Email: dsimader@sql-ledger.org
7 #     Web: http://www.sql-ledger.org
8 #
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
23 #
24 # administration
25 #
26 #======================================================================
27
28
29 use SL::AM;
30 use SL::CA;
31 use SL::Form;
32 use SL::User;
33
34
35 1;
36 # end of main
37
38
39
40 sub add {
41
42   $form->{title} = "Add";
43   $form->{charttype} = "A";
44   
45   $form->{callback} = "$form->{script}?action=list&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
46
47   &form_header;
48   &form_footer;
49   
50 }
51
52
53 sub edit {
54   $form->{title} = "Edit";
55
56   # if it is a template
57   if ($form->{file}) {
58     $form->{type} = "template";
59     &edit_template;
60     exit;
61   }
62
63   AM->get_account(\%myconfig, \%$form);
64   
65   foreach my $item (split(/:/, $form->{link})) {
66     $form->{$item} = "checked";
67   }
68
69   &form_header;
70   &form_footer;
71
72 }
73
74
75 sub form_header {
76
77   $form->{title} = $locale->text("$form->{title} Account");
78   
79   $checked{$form->{charttype}} = "checked";
80   $checked{"$form->{category}_"} = "checked";
81   $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked";
82   
83   $form->{description} =~ s/"/"/g;
84
85 # this is for our parser only!
86 # type=submit $locale->text('Add Account')
87 # type=submit $locale->text('Edit Account')
88
89   $form->header;
90
91   print qq|
92 <body>
93
94 <form method=post action=$form->{script}>
95
96 <input type=hidden name=id value=$form->{id}>
97 <input type=hidden name=type value=account>
98
99 <input type=hidden name=inventory_accno_id value=$form->{inventory_accno_id}>
100 <input type=hidden name=income_accno_id value=$form->{income_accno_id}>
101 <input type=hidden name=expense_accno_id value=$form->{expense_accno_id}>
102 <input type=hidden name=fxgain_accno_id values=$form->{fxgain_accno_id}>
103 <input type=hidden name=fxloss_accno_id values=$form->{fxloss_accno_id}>
104
105 <input type=hidden name=amount value=$form->{amount}>
106
107 <table border=0 width=100%>
108   <tr>
109     <th class=listtop>$form->{title}</th>
110   </tr>
111   <tr height="5"></tr>
112   <tr valign=top>
113     <td>
114       <table>
115         <tr>
116           <th align=right>|.$locale->text('Account Number').qq|</th>
117           <td><input name=accno size=20 value=$form->{accno}></td>
118         </tr>
119         <tr>
120           <th align=right>|.$locale->text('Description').qq|</th>
121           <td><input name=description size=40 value="$form->{description}"></td>
122         </tr>
123         <tr>
124           <th align=right>|.$locale->text('Account Type').qq|</th>
125           <td>
126             <table>
127               <tr valign=top>
128                 <td><input name=category type=radio class=radio value=A $checked{A_}>&nbsp;|.$locale->text('Asset').qq|\n<br>
129                 <input name=category type=radio class=radio value=L $checked{L_}>&nbsp;|.$locale->text('Liability').qq|\n<br>
130                 <input name=category type=radio class=radio value=Q $checked{Q_}>&nbsp;|.$locale->text('Equity').qq|\n<br>
131                 <input name=category type=radio class=radio value=I $checked{I_}>&nbsp;|.$locale->text('Income').qq|\n<br>
132                 <input name=category type=radio class=radio value=E $checked{E_}>&nbsp;|.$locale->text('Expense')
133                 .qq|</td>
134                 <td>
135                 <input name=charttype type=radio class=radio value="H" $checked{H}>&nbsp;|.$locale->text('Heading').qq|<br>
136                 <input name=charttype type=radio class=radio value="A" $checked{A}>&nbsp;|.$locale->text('Account')
137                 .qq|</td>
138               </tr>
139             </table>
140           </td>
141         </tr>
142 |;
143
144
145 if ($form->{charttype} eq "A") {
146   print qq|
147         <tr>
148           <td colspan=2>
149             <table>
150               <tr>
151                 <th align=left>|.$locale->text('Is this a summary account to record').qq|</th>
152                 <td>
153                 <input name=AR type=checkbox class=checkbox value=AR $form->{AR}>&nbsp;|.$locale->text('AR')
154                 .qq|&nbsp;<input name=AP type=checkbox class=checkbox value=AP $form->{AP}>&nbsp;|.$locale->text('AP')
155                 .qq|&nbsp;<input name=IC type=checkbox class=checkbox value=IC $form->{IC}>&nbsp;|.$locale->text('Inventory')
156                 .qq|</td>
157               </tr>
158             </table>
159           </td>
160         </tr>
161         <tr>
162           <th colspan=2>|.$locale->text('Include in drop-down menus').qq|</th>
163         </tr>
164         <tr valign=top>
165           <td colspan=2>
166             <table width=100%>
167               <tr>
168                 <th align=left>|.$locale->text('Receivables').qq|</th>
169                 <th align=left>|.$locale->text('Payables').qq|</th>
170                 <th align=left>|.$locale->text('Parts Inventory').qq|</th>
171                 <th align=left>|.$locale->text('Service Items').qq|</th>
172               </tr>
173               <tr>
174                 <td>
175                 <input name=AR_amount type=checkbox class=checkbox value=AR_amount $form->{AR_amount}>&nbsp;|.$locale->text('Income').qq|\n<br>
176                 <input name=AR_paid type=checkbox class=checkbox value=AR_paid $form->{AR_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
177                 <input name=AR_tax type=checkbox class=checkbox value=AR_tax $form->{AR_tax}>&nbsp;|.$locale->text('Tax')
178                 .qq|
179                 </td>
180                 <td>
181                 <input name=AP_amount type=checkbox class=checkbox value=AP_amount $form->{AP_amount}>&nbsp;|.$locale->text('Expense/Asset').qq|\n<br>
182                 <input name=AP_paid type=checkbox class=checkbox value=AP_paid $form->{AP_paid}>&nbsp;|.$locale->text('Payment').qq|\n<br>
183                 <input name=AP_tax type=checkbox class=checkbox value=AP_tax $form->{AP_tax}>&nbsp;|.$locale->text('Tax')
184                 .qq|
185                 </td>
186                 <td>
187                 <input name=IC_sale type=checkbox class=checkbox value=IC_sale $form->{IC_sale}>&nbsp;|.$locale->text('Sales').qq|\n<br>
188                 <input name=IC_cogs type=checkbox class=checkbox value=IC_cogs $form->{IC_cogs}>&nbsp;|.$locale->text('COGS').qq|\n<br>
189                 <input name=IC_taxpart type=checkbox class=checkbox value=IC_taxpart $form->{IC_taxpart}>&nbsp;|.$locale->text('Tax')
190                 .qq|
191                 </td>
192                 <td>
193                 <input name=IC_income type=checkbox class=checkbox value=IC_income $form->{IC_income}>&nbsp;|.$locale->text('Income').qq|\n<br>
194                 <input name=IC_expense type=checkbox class=checkbox value=IC_expense $form->{IC_expense}>&nbsp;|.$locale->text('Expense').qq|\n<br>
195                 <input name=IC_taxservice type=checkbox class=checkbox value=IC_taxservice $form->{IC_taxservice}>&nbsp;|.$locale->text('Tax')
196                 .qq|
197                 </td>
198               </tr>
199             </table>
200           </td>  
201         </tr>  
202         <tr>
203           <td colspan=2>
204             <table>
205               <tr>
206                 <th align=left>|.$locale->text('Include this account on the customer/vendor forms to flag customer/vendor as taxable?').qq|</th>
207                 <td>
208                   <input name=CT_tax type=radio class=radio value=CT_tax $form->{CT_tax}>&nbsp;|.$locale->text('Yes').qq|&nbsp;
209                   <input name=CT_tax type=radio class=radio value="" $checked{CT_tax}>&nbsp;|.$locale->text('No')
210                 .qq|
211                 </td>
212               </tr>
213             </table>
214           </td>
215         </tr>
216 |;
217 }
218
219 print qq|
220         <tr>
221           <th align=right>|.$locale->text('GIFI').qq|</th>
222           <td><input name=gifi_accno size=9 value=$form->{gifi_accno}></td>
223         </tr>
224       </table>
225     </td>
226   </tr>
227   <tr>
228     <td><hr size=3 noshade></td>
229   </tr>
230 </table>
231 |;
232
233 }
234
235
236 sub form_footer {
237
238   print qq|
239
240 <input name=callback type=hidden value="$form->{callback}">
241
242 <input type=hidden name=path value=$form->{path}>
243 <input type=hidden name=login value=$form->{login}>
244 <input type=hidden name=password value=$form->{password}>
245
246 <br>
247 <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
248 |;
249
250   if ($form->{id}) {
251     print qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
252   }
253
254   print qq|
255 </form>
256
257 </body>
258 </html>
259 |;
260
261 }
262
263
264 sub save { &{ "save_$form->{type}" } };
265   
266 sub save_account {
267
268   $form->isblank("accno", $locale->text('Account Number missing!'));
269   $form->isblank("category", $locale->text('Account Type missing!'));
270   
271   $form->redirect($locale->text('Account saved!')) if (AM->save_account(\%myconfig, \%$form));
272   $form->error($locale->text('Cannot save account!'));
273
274 }
275
276
277 sub list {
278
279   CA->all_accounts(\%myconfig, \%$form);
280
281   $form->{title} = $locale->text('Chart of Accounts');
282   
283   # construct callback
284   $callback = "$form->{script}?action=list&path=$form->{path}&login=$form->{login}&password=$form->{password}";
285
286   @column_index = qw(accno gifi_accno description debit credit link);
287
288   $column_header{accno} = qq|<th class=listheading>|.$locale->text('Account').qq|</a></th>|;
289   $column_header{gifi_accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</a></th>|;
290   $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</a></th>|;
291   $column_header{debit} = qq|<th class=listheading>|.$locale->text('Debit').qq|</a></th>|;
292   $column_header{credit} = qq|<th class=listheading>|.$locale->text('Credit').qq|</a></th>|;
293   $column_header{link} = qq|<th class=listheading>|.$locale->text('Link').qq|</a></th>|;
294
295
296   $form->header;
297   $colspan = $#column_index + 1;
298
299   print qq|
300 <body>
301
302 <table border=0 width=100%>
303   <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
304   <tr height=5></tr>
305   <tr class=listheading>
306 |;
307
308   map { print "$column_header{$_}\n" } @column_index;
309   
310   print qq|
311 </tr>
312 |;
313
314   # escape callback
315   $callback = $form->escape($callback);
316   
317   foreach $ca (@{ $form->{CA} }) {
318     
319     $ca->{debit} = "&nbsp;";
320     $ca->{credit} = "&nbsp;";
321
322     # needed if we can delete an account
323     $amount = 0;
324
325     if ($ca->{amount} > 0) {
326       $amount = $ca->{amount};
327       $ca->{credit} = $form->format_amount(\%myconfig, $ca->{amount}, 2, "&nbsp;");
328     }
329     if ($ca->{amount} < 0) {
330       $amount = -$ca->{amount};
331       $ca->{debit} = $form->format_amount(\%myconfig, -$ca->{amount}, 2, "&nbsp;");
332     }
333
334     $ca->{link} =~ s/:/<br>/og;
335
336     if ($ca->{charttype} eq "H") {
337       print qq|<tr class=listheading>|;
338
339       $column_data{accno} = qq|<th><a class=listheading href=$form->{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ca->{accno}</a></th>|;
340       $column_data{gifi_accno} = qq|<th><a class=listheading 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>|;
341       $column_data{description} = qq|<th class=listheading>$ca->{description}&nbsp;</th>|;
342       $column_data{debit} = qq|<th>&nbsp;</th>|;
343       $column_data{credit} = qq| <th>&nbsp;</th>|;
344       $column_data{link} = qq|<th>&nbsp;</th>|;
345
346     } else {
347       $i++; $i %= 2;
348       print qq|
349 <tr valign=top class=listrow$i>|;
350       $column_data{accno} = qq|<td><a href=$form->{script}?action=edit&id=$ca->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback&amount=$amount>$ca->{accno}</a></td>|;
351       $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&amount=$amount>$ca->{gifi_accno}</a>&nbsp;</td>|;
352       $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
353       $column_data{debit} = qq|<td align=right>$ca->{debit}</td>|;
354       $column_data{credit} = qq|<td align=right>$ca->{credit}</td>|;
355       $column_data{link} = qq|<td>$ca->{link}&nbsp;</td>|;
356       
357     }
358
359     map { print "$column_data{$_}\n" } @column_index;
360     
361     print "</tr>\n";
362   }
363   
364   print qq|
365   <tr><td colspan=$colspan><hr size=3 noshade></td></tr>
366 </table>
367
368 </body>
369 </html>
370 |;
371
372 }
373
374
375 sub delete { &{ "delete_$form->{type}" } };
376
377 sub delete_account {
378
379   $form->{title} = $locale->text('Delete Account');
380
381   if ($form->{amount} != 0) {  
382     $form->error($locale->text('Transactions exist; cannot delete account!'));
383   }
384
385   foreach $id (qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)) {
386     if ($form->{id} == $form->{$id}) {
387       $form->error($locale->text('Cannot delete default account!'));
388     }
389   }
390
391   $form->redirect($locale->text('Account deleted!')) if (AM->delete_account(\%myconfig, \%$form));
392   $form->error($locale->text('Cannot delete account!'));
393
394 }
395
396
397 sub list_gifi {
398
399   @{ $form->{fields} } = (accno, description);
400   $form->{table} = "gifi";
401   $form->{sortorder} = "accno";
402   
403   AM->gifi_accounts(\%myconfig, \%$form);
404
405   $form->{title} = $locale->text('GIFI');
406   
407   # construct callback
408   $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}";
409
410   @column_index = qw(accno description);
411
412   $column_header{accno} = qq|<th class=listheading>|.$locale->text('GIFI').qq|</a></th>|;
413   $column_header{description} = qq|<th class=listheading>|.$locale->text('Description').qq|</a></th>|;
414
415
416   $form->header;
417   $colspan = $#column_index + 1;
418
419   print qq|
420 <body>
421
422 <table border=0 width=100%>
423   <tr><th class=listtop colspan=$colspan>$form->{title}</th></tr>
424   <tr height="5"></tr>
425   <tr class=listheading>
426 |;
427
428   map { print "$column_header{$_}\n" } @column_index;
429   
430   print qq|
431 </tr>
432 |;
433
434   # escape callback
435   $callback = $form->escape($callback);
436   
437   foreach $ca (@{ $form->{ALL} }) {
438     
439     $i++; $i %= 2;
440     
441     print qq|
442 <tr valign=top class=listrow$i>|;
443     
444     $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>|;
445     $column_data{description} = qq|<td>$ca->{description}&nbsp;</td>|;
446     
447     map { print "$column_data{$_}\n" } @column_index;
448     
449     print "</tr>\n";
450   }
451   
452   print qq|
453   <tr>
454     <td colspan=$colspan><hr size=3 noshade></td>
455   </tr>
456 </table>
457
458 </body>
459 </html>
460 |;
461
462 }
463
464
465 sub add_gifi {
466   $form->{title} = "Add";
467   
468   # construct callback
469   $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&password=$form->{password}";
470
471   $form->{coa} = 1;
472   
473   &gifi_header;
474   &gifi_footer;
475   
476 }
477
478
479 sub edit_gifi {
480   
481   $form->{title} = "Edit";
482
483   AM->get_gifi(\%myconfig, \%$form);
484   
485   &gifi_header;
486   &gifi_footer;
487   
488 }
489
490
491 sub gifi_header {
492
493   $form->{title} = $locale->text("$form->{title} GIFI");
494   
495 # $locale->text('Add GIFI')
496 # $locale->text('Edit GIFI')
497
498   $form->{description} =~ s/"/&quot;/g;
499
500   $form->header;
501
502   print qq|
503 <body>
504
505 <form method=post action=$form->{script}>
506
507 <input type=hidden name=id value=$form->{accno}>
508 <input type=hidden name=type value=gifi>
509
510 <table width=100%>
511   <tr>
512     <th class=listtop>$form->{title}</th>
513   </tr>
514   <tr height="5"></tr>
515   <tr>
516     <td>
517       <table>
518         <tr>
519           <th align=right>|.$locale->text('GIFI').qq|</th>
520           <td><input name=accno size=20 value=$form->{accno}></td>
521         </tr>
522         <tr>
523           <th align=right>|.$locale->text('Description').qq|</th>
524           <td><input name=description size=60 value="$form->{description}"></td>
525         </tr>
526       </table>
527     </td>
528   </tr>
529   <tr>
530     <td colspan=2><hr size=3 noshade></td>
531   </tr>
532 </table>
533 |;
534
535 }
536
537
538 sub gifi_footer {
539
540   print qq|
541
542 <input name=callback type=hidden value="$form->{callback}">
543
544 <input type=hidden name=path value=$form->{path}>
545 <input type=hidden name=login value=$form->{login}>
546 <input type=hidden name=password value=$form->{password}>
547
548 <br><input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
549 |;
550
551   if ($form->{coa}) {
552     print qq|
553 <input type=submit class=submit name=action value="|.$locale->text('Copy to COA').qq|">
554 |;
555
556     if ($form->{accno}) {
557       print qq|<input type=submit class=submit name=action value="|.$locale->text('Delete').qq|">|;
558     }
559   }
560
561   print qq|
562 </form>
563
564 </body>
565 </html>
566 |;
567
568 }
569
570
571 sub save_gifi {
572
573   $form->isblank("accno", $locale->text('GIFI missing!'));
574   AM->save_gifi(\%myconfig, \%$form);
575   $form->redirect($locale->text('GIFI saved!'));
576
577 }
578
579
580 sub copy_to_coa {
581
582   $form->isblank("accno", $locale->text('GIFI missing!'));
583
584   AM->save_gifi(\%myconfig, \%$form);
585
586   delete $form->{id};
587   $form->{gifi_accno} = $form->{accno};
588   $form->{title} = "Add";
589   $form->{charttype} = "A";
590   
591   &form_header;
592   &form_footer;
593   
594 }
595
596
597 sub delete_gifi {
598
599   AM->delete_gifi(\%myconfig, \%$form);
600   $form->redirect($locale->text('GIFI deleted!'));
601
602 }
603
604
605 sub display_stylesheet {
606   
607   $form->{file} = "css/$myconfig{stylesheet}";
608   &display_form;
609   
610 }
611
612
613 sub display_form {
614
615   $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
616   $form->{file} =~ s/^\/*//g;
617   $form->{file} =~ s/$userspath//;
618
619   $form->error("$!: $form->{file}") unless -f $form->{file};
620
621   AM->load_template(\%$form);
622
623   $form->{title} = $form->{file};
624
625   # if it is anything but html
626   if ($form->{file} !~ /\.html$/) {
627     $form->{body} = "<pre>\n$form->{body}\n</pre>";
628   }
629     
630   $form->header;
631
632   print qq|
633 <body>
634
635 $form->{body}
636
637 <form method=post action=$form->{script}>
638
639 <input name=file type=hidden value=$form->{file}>
640
641 <input type=hidden name=path value=$form->{path}>
642 <input type=hidden name=login value=$form->{login}>
643 <input type=hidden name=password value=$form->{password}>
644
645 <input name=action type=submit class=submit value="|.$locale->text('Edit').qq|">
646 </form>
647
648
649 </body>
650 </html>
651 |;
652
653 }
654
655
656 sub edit_template {
657
658   AM->load_template(\%$form);
659
660   $form->{title} = $locale->text('Edit Template');
661   # convert &nbsp to &amp;nbsp;
662   $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
663   
664
665   $form->header;
666   
667   print qq|
668 <body>
669
670 <form method=post action=$form->{script}>
671
672 <input name=file type=hidden value=$form->{file}>
673 <input name=type type=hidden value=template>
674
675 <input type=hidden name=path value=$form->{path}>
676 <input type=hidden name=login value=$form->{login}>
677 <input type=hidden name=password value=$form->{password}>
678
679 <input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}">
680
681 <textarea name=body rows=25 cols=70>
682 $form->{body}
683 </textarea>
684
685 <br>
686 <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
687
688 </form>
689
690
691 </body>
692 </html>
693 |;
694
695 }
696
697
698 sub save_template {
699
700   AM->save_template(\%$form);
701   $form->redirect($locale->text('Template saved!'));
702   
703 }
704
705
706 sub config {
707
708   # get defaults for account numbers and last numbers
709   AM->defaultaccounts(\%myconfig, \%$form);
710
711   foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) {
712     $dateformat .= ($item eq $myconfig{dateformat}) ? "<option selected>$item\n" : "<option>$item\n";
713   }
714
715   foreach $item (qw(1,000.00 1000.00 1.000,00 1000,00)) {
716     $numberformat .= ($item eq $myconfig{numberformat}) ? "<option selected>$item\n" : "<option>$item\n";
717   }
718
719   foreach $item (qw(name company address signature shippingpoint)) {
720     $myconfig{$item} =~ s/"/&quot;/g;
721   }
722
723   foreach $item (qw(address signature)) {
724     $myconfig{$item} =~ s/\\n/\r\n/g;
725   }
726
727   %countrycodes = User->country_codes;
728   $countrycodes = '';
729   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
730     $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n";
731   }
732   $countrycodes = "<option>American English\n$countrycodes";
733
734   foreach $key (keys %{ $form->{IC} }) {
735     foreach $accno (sort keys %{ $form->{IC}{$key} }) {
736       $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";
737     }
738   }
739   
740   $form->{title} = $locale->text('Edit Preferences for').qq| $form->{login}|;
741   
742   $form->header;
743   
744   print qq|
745 <body>
746
747 <form method=post action=$form->{script}>
748
749 <input type=hidden name=old_password value=$myconfig{password}>
750 <input type=hidden name=type value=preferences>
751
752 <table width=100%>
753   <tr><th class=listtop>$form->{title}</th></tr>
754   <tr>
755     <td>
756       <table>
757         <tr>
758           <th align=right>|.$locale->text('Name').qq|</th>
759           <td><input name=name size=15 value="$myconfig{name}"></td>
760         </tr>
761         <tr>
762           <th align=right>|.$locale->text('Password').qq|</th>
763           <td><input type=password name=password size=10 value=$myconfig{password}></td>
764         </tr>
765         <tr>
766           <th align=right>|.$locale->text('E-mail').qq|</th>
767           <td><input name=email size=30 value="$myconfig{email}"></td>
768         </tr>
769         <tr valign=top>
770           <th align=right>|.$locale->text('Signature').qq|</th>
771           <td><textarea name=signature rows=3 cols=50>$myconfig{signature}</textarea></td>
772         </tr>
773         <tr>
774           <th align=right>|.$locale->text('Phone').qq|</th>
775           <td><input name=tel size=14 value="$myconfig{tel}"></td>
776         </tr>
777         <tr>
778           <th align=right>|.$locale->text('Fax').qq|</th>
779           <td><input name=fax size=14 value="$myconfig{fax}"></td>
780         </tr>
781         <tr>
782           <th align=right>|.$locale->text('Company').qq|</th>
783           <td><input name=company size=30 value="$myconfig{company}"></td>
784         </tr>
785         <tr valign=top>
786           <th align=right>|.$locale->text('Address').qq|</th>
787           <td><textarea name=address rows=4 cols=50>$myconfig{address}</textarea></td>
788         </tr>
789         <tr>
790           <th align=right>|.$locale->text('Date Format').qq|</th>
791           <td><select name=dateformat>$dateformat</select></td>
792         </tr>
793         <tr>
794           <th align=right>|.$locale->text('Number Format').qq|</th>
795           <td><select name=numberformat>$numberformat</select></td>
796         </tr>
797         <tr>
798           <th align=right>|.$locale->text('Dropdown Limit').qq|</th>
799           <td><input name=vclimit size=10 value="$myconfig{vclimit}"></td>
800         </tr>
801         <tr>
802           <th align=right>|.$locale->text('Language').qq|</th>
803           <td><select name=countrycode>$countrycodes</select></td>
804         </tr>
805         <tr>
806           <th align=right>|.$locale->text('Character Set').qq|</th>
807           <td><input name=charset size=20 value="$myconfig{charset}"></td>
808         </tr>
809         <tr>
810           <th align=right>|.$locale->text('Stylesheet').qq|</th>
811           <td><input name=stylesheet size=20 value="$myconfig{stylesheet}"></td>
812         </tr>
813         <input name=printer type=hidden value="$myconfig{printer}">
814         <tr>
815           <th align=right>|.$locale->text('Ship via').qq|</th>
816           <td><input name=shippingpoint size=25 value="$myconfig{shippingpoint}"></td>
817         </tr>
818         <tr class=listheading>
819           <th colspan=2>&nbsp;</th>
820         </tr>
821         <tr>
822           <th align=right>|.$locale->text('Business Number').qq|</th>
823           <td><input name=businessnumber size=25 value="$myconfig{businessnumber}"></td>
824         </tr>
825         <tr>
826           <td colspan=2>
827             <table width=100%>
828               <tr>
829                 <th align=right>|.$locale->text('Year End').qq| (mm/dd)</th>
830                 <td><input name=yearend size=5 maxsize=5 value=$form->{defaults}{yearend}></td>
831                 <th align=right>|.$locale->text('Weight Unit').qq|</th>
832                 <td><input name=weightunit size=5 value="$form->{defaults}{weightunit}"></td>
833               </tr>
834             </table>
835           </td>
836         </tr>
837         <tr class=listheading>
838           <th class=listheading colspan=2>|.$locale->text('Last Numbers & Default Accounts').qq|</th>
839         </tr>
840         <tr>
841           <td colspan=2>
842             <table width=100%>
843               <tr>
844                 <th width=1% align=right nowrap>|.$locale->text('Inventory Account').qq|</th>
845                 <td><select name=inventory_accno>$myconfig{IC}</select></td>
846               </tr>
847               <tr>
848                 <th align=right nowrap>|.$locale->text('Income Account').qq|</th>
849                 <td><select name=income_accno>$myconfig{IC_income}</select></td>
850               </tr>
851               <tr>
852                 <th align=right nowrap>|.$locale->text('Expense Account').qq|</th>
853                 <td><select name=expense_accno>$myconfig{IC_expense}</select></td>
854               </tr>
855               <tr>
856                 <th align=right nowrap>|.$locale->text('Foreign Exchange Gain').qq|</th>
857                 <td><select name=fxgain_accno>$myconfig{FX_gain}</select></td>
858               </tr>
859               <tr>
860                 <th align=right nowrap>|.$locale->text('Foreign Exchange Loss').qq|</th>
861                 <td><select name=fxloss_accno>$myconfig{FX_loss}</select></td>
862               </tr>
863               <tr>
864                 <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>
865               </tr>
866               <tr>
867                 <th align=right nowrap>|.$locale->text('Last Invoice Number').qq|</th>
868                 <td><input name=invnumber size=10 value=$form->{defaults}{invnumber}></td>
869               </tr>
870               <tr>
871                 <th align=right nowrap>|.$locale->text('Last Sales Order Number').qq|</th>
872                 <td><input name=sonumber size=10 value=$form->{defaults}{sonumber}></td>
873               </tr>
874               <tr>
875                 <th align=right nowrap>|.$locale->text('Last Purchase Order Number').qq|</th>
876                 <td><input name=ponumber size=10 value=$form->{defaults}{ponumber}></td>
877               </tr>
878             </table>
879           </td>
880         </tr>
881         <tr class=listheading>
882           <th class=listheading colspan=2>|.$locale->text('Tax Accounts').qq|</th>
883         </tr>
884         <tr>
885           <td colspan=2>
886             <table>
887               <tr>
888                 <th>&nbsp;</th>
889                 <th>|.$locale->text('Rate').qq| (%)</th>
890                 <th>|.$locale->text('Number').qq|</th>
891               </tr>
892 |;
893
894   foreach $accno (sort keys %{ $form->{taxrates} }) {
895     print qq|
896               <tr>
897                 <th align=right>$form->{taxrates}{$accno}{description}</th>
898                 <td><input name=$form->{taxrates}{$accno}{id} size=6 value=$form->{taxrates}{$accno}{rate}></td>
899                 <td><input name="taxnumber_$form->{taxrates}{$accno}{id}" value="$form->{taxrates}{$accno}{taxnumber}"></td>
900               </tr>
901 |;
902     $form->{taxaccounts} .= "$form->{taxrates}{$accno}{id} ";
903   }
904
905   chop $form->{taxaccounts};
906
907   print qq|
908 <input name=taxaccounts type=hidden value="$form->{taxaccounts}">
909
910             </table>
911           </td>
912         </tr>
913       </table>
914     </td>
915   </tr>
916   <tr>
917     <td><hr size=3 noshade></td>
918   </tr>
919 </table>
920
921 <input type=hidden name=path value=$form->{path}>
922 <input type=hidden name=login value=$form->{login}>
923 <input type=hidden name=password value=$form->{password}>
924
925 <br>
926 <input type=submit class=submit name=action value="|.$locale->text('Save').qq|">
927 </form>
928
929 </body>
930 </html>
931 |;
932
933 }
934
935
936 sub save_preferences {
937
938   # does stylesheet exist
939   if ($form->{stylesheet}) {
940     $form->error($locale->text('Stylesheet').": css/$form->{stylesheet} ".$locale->text('does not exist')) unless (-f "css/$form->{stylesheet}");
941   } 
942
943   $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, $memberfile, $userspath));
944   $form->error($locale->text('Cannot save preferences!'));
945
946 }
947
948
949 sub backup {
950
951   if ($form->{media} eq 'email') {
952     $form->error($locale->text('No email address for')." $myconfig{name}") unless ($myconfig{email});
953     
954     $form->{OUT} = "$sendmail";
955
956   }
957   
958   AM->backup(\%myconfig, \%$form, $userspath);
959
960   if ($form->{media} eq 'email') {
961     $form->redirect($locale->text('Backup sent to').qq| $myconfig{email}|);
962   }
963
964 }
965
966
967
968 sub audit_control {
969
970   $form->{title} = $locale->text('Audit Control');
971
972   AM->closedto(\%myconfig, \%$form);
973   
974   if ($form->{revtrans}) {
975     $checked{Y} = "checked";
976   } else {
977     $checked{N} = "checked";
978   }
979   
980   $form->header;
981   
982   print qq|
983 <body>
984
985 <form method=post action=$form->{script}>
986
987 <input type=hidden name=path value=$form->{path}>
988 <input type=hidden name=login value=$form->{login}>
989 <input type=hidden name=password value=$form->{password}>
990
991 <table width=100%>
992   <tr><th class=listtop>$form->{title}</th></tr>
993   <tr height="5"></tr>
994   <tr>
995     <td>
996       <table>
997         <tr>
998           <td>|.$locale->text('Enforce transaction reversal for all dates').qq|</th>
999           <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>
1000         </tr>
1001         <tr>
1002           <td>|.$locale->text('Close Books up to').qq|</th>
1003           <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
1004         </tr>
1005       </table>
1006     </td>
1007   </tr>
1008 </table>
1009
1010 <hr size=3 noshade>
1011
1012 <br>
1013 <input type=hidden name=nextsub value=doclose>
1014
1015 <input type=submit class=submit name=action value="|.$locale->text('Continue').qq|">
1016
1017 </form>
1018
1019 </body>
1020 </html>
1021 |;
1022
1023 }
1024
1025
1026 sub doclose {
1027
1028   AM->closebooks(\%myconfig, \%$form);
1029   
1030   if ($form->{revtrans}) {
1031     $form->redirect($locale->text('Transaction reversal enforced for all dates'));
1032   } else {
1033     if ($form->{closedto}) {
1034       $form->redirect($locale->text('Transaction reversal enforced up to')
1035       ." ".$locale->date(\%myconfig, $form->{closedto}, 1));
1036     } else {
1037       $form->redirect($locale->text('Books are open'));
1038     }
1039   }
1040
1041 }
1042
1043
1044
1045 sub continue {
1046     
1047   &{ $form->{nextsub} };
1048
1049 }
1050
1051