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