can't set $p without $cgi
[freeside.git] / sql-ledger / old / sql-ledger / bin / mozilla / gl.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 # Genereal Ledger
25 #
26 #======================================================================
27
28
29 use SL::GL;
30 use SL::PE;
31
32 require "$form->{path}/arap.pl";
33
34 1;
35 # end of main
36
37
38 # this is for our long dates
39 # $locale->text('January')
40 # $locale->text('February')
41 # $locale->text('March')
42 # $locale->text('April')
43 # $locale->text('May ')
44 # $locale->text('June')
45 # $locale->text('July')
46 # $locale->text('August')
47 # $locale->text('September')
48 # $locale->text('October')
49 # $locale->text('November')
50 # $locale->text('December')
51
52 # this is for our short month
53 # $locale->text('Jan')
54 # $locale->text('Feb')
55 # $locale->text('Mar')
56 # $locale->text('Apr')
57 # $locale->text('May')
58 # $locale->text('Jun')
59 # $locale->text('Jul')
60 # $locale->text('Aug')
61 # $locale->text('Sep')
62 # $locale->text('Oct')
63 # $locale->text('Nov')
64 # $locale->text('Dec')
65
66
67 sub add {
68
69   $form->{title} = "Add";
70   
71   $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
72
73   # we use this only to set a default date
74   GL->transaction(\%myconfig, \%$form);
75   
76   map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} };
77   $form->{chart} = $chart;
78   
79   $form->{rowcount} = 4;
80   &display_form;
81   
82 }
83
84
85 sub edit {
86
87   GL->transaction(\%myconfig, \%$form);
88
89   map { $chart .= "<option>$_->{accno}--$_->{description}" } @{ $form->{chart} };
90   $form->{chart} = $chart;
91
92   $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
93
94   $form->{title} = "Edit";
95   
96   &form_header;
97
98   $i = 1;
99   foreach $ref (@{ $form->{GL} }) {
100     $form->{"accno_$i"} = $ref->{accno};
101     $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = $ref->{projectnumber};
102     $form->{"project_id_$i"} = $ref->{project_id};
103     
104     if ($ref->{amount} < 0) {
105       $form->{totaldebit} -= $ref->{amount};
106       $form->{"debit_$i"} = $form->format_amount(\%myconfig, $ref->{amount} * -1, 2);
107     } else {
108       $form->{totalcredit} += $ref->{amount};
109       $form->{"credit_$i"} = ($ref->{amount} > 0) ? $form->format_amount(\%myconfig, $ref->{amount}, 2) : "";
110     }
111
112     &form_row($i++);
113   }
114
115   &form_row($i);
116
117   &form_footer;
118   
119 }
120
121
122
123 sub search {
124
125   $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
126   
127   $form->header;
128   
129   print qq|
130 <body>
131
132 <form method=post action=$form->{script}>
133
134 <input type=hidden name=sort value=transdate>
135
136 <table width=100%>
137   <tr>
138     <th class=listtop>$form->{title}</th>
139   </tr>
140   <tr height="5"></tr>
141   <tr>
142     <td>
143       <table>
144         <tr>
145           <th align=right>|.$locale->text('Reference').qq|</th>
146           <td><input name=reference size=20></td>
147           <th align=right>|.$locale->text('Source').qq|</th>
148           <td><input name=source size=20></td>
149         </tr>
150         <tr>
151           <th align=right>|.$locale->text('Description').qq|</th>
152           <td colspan=3><input name=description size=40></td>
153         </tr>
154         <tr>
155           <th align=right>|.$locale->text('Notes').qq|</th>
156           <td colspan=3><input name=notes size=40></td>
157         </tr>
158         <tr>
159           <th align=right>|.$locale->text('From').qq|</th>
160           <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
161           <th align=right>|.$locale->text('to').qq|</th>
162           <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
163         </tr>
164         <tr>
165           <th align=right>|.$locale->text('Include in Report').qq|</th>
166           <td colspan=3>
167             <table>
168               <tr>
169                 <td>
170                   <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
171                   <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
172                   <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
173                   <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
174                   <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Income').qq|
175                   <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
176                 </td>
177               </tr>
178               <tr>
179                 <table>
180                   <tr>
181                     <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
182                     <td>|.$locale->text('ID').qq|</td>
183                     <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
184                     <td>|.$locale->text('Date').qq|</td>
185                     <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
186                     <td>|.$locale->text('Reference').qq|</td>
187                     <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
188                     <td>|.$locale->text('Description').qq|</td>
189                     <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
190                     <td>|.$locale->text('Notes').qq|</td>
191                   </tr>
192                   <tr>
193                     <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
194                     <td>|.$locale->text('Debit').qq|</td>
195                     <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
196                     <td>|.$locale->text('Credit').qq|</td>
197                     <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
198                     <td>|.$locale->text('Source').qq|</td>
199                     <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
200                     <td>|.$locale->text('Account').qq|</td>
201                     <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
202                     <td>|.$locale->text('GIFI').qq|</td>
203                   </tr>
204                   <tr>
205                     <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
206                     <td>|.$locale->text('Subtotal').qq|</td>
207                   </tr>
208                 </table>
209               </tr>
210             </table>
211         </tr>
212       </table>
213     </td>
214   </tr>
215   <tr>
216     <td><hr size=3 noshade></td>
217   </tr>
218 </table>
219
220 <input type=hidden name=nextsub value=generate_report>
221
222 <input type=hidden name=path value=$form->{path}>
223 <input type=hidden name=login value=$form->{login}>
224 <input type=hidden name=password value=$form->{password}>
225
226 <br>
227 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
228 </form>
229
230 </body>
231 </html>
232 |;
233 }
234
235
236 sub generate_report {
237
238   GL->all_transactions(\%myconfig, \%$form);
239   
240   $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
241  
242   %acctype = ( 'A' => $locale->text('Asset'),
243                'L' => $locale->text('Liability'),
244                'Q' => $locale->text('Equity'),
245                'I' => $locale->text('Income'),
246                'E' => $locale->text('Expense'),
247              );
248   
249   $form->{title} = $locale->text('General Ledger');
250   
251   $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
252
253   unless ($form->{category} eq 'X') {
254     $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
255   }
256   if ($form->{accno}) {
257     $callback .= "&accno=$form->{accno}";
258     $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
259   }
260   if ($form->{gifi_accno}) {
261     $callback .= "&gifi_accno=$form->{gifi_accno}";
262     $option .= "\n<br>" if $option;
263     $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
264   }
265   if ($form->{source}) {
266     $callback .= "&source=".$form->escape($form->{source});
267     $option .= "\n<br>" if $option;
268     $option .= $locale->text('Source')." : $form->{source}";
269   }
270   if ($form->{reference}) {
271     $callback .= "&reference=".$form->escape($form->{reference});
272     $option .= "\n<br>" if $option;
273     $option .= $locale->text('Reference')." : $form->{reference}";
274   }
275   if ($form->{description}) {
276     $callback .= "&description=".$form->escape($form->{description});
277     $option .= "\n<br>" if $option;
278     $option .= $locale->text('Description')." : $form->{description}";
279   }
280   if ($form->{notes}) {
281     $callback .= "&notes=".$form->escape($form->{notes});
282     $option .= "\n<br>" if $option;
283     $option .= $locale->text('Notes')." : $form->{notes}";
284   }
285    
286   if ($form->{datefrom}) {
287     $callback .= "&datefrom=$form->{datefrom}";
288     $option .= "\n<br>" if $option;
289     $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
290   }
291   if ($form->{dateto}) {
292     $callback .= "&dateto=$form->{dateto}";
293     if ($form->{datefrom}) {
294       $option .= " ";
295     } else {
296       $option .= "\n<br>" if $option;
297     }
298     $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
299   }
300
301
302   @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno));
303
304   if ($form->{accno} || $form->{gifi_accno}) {
305     @columns = grep !/(accno|gifi_accno)/, @columns;
306     push @columns, "balance";
307     $form->{l_balance} = "Y";
308   }
309   
310   $href = "$callback&sort=$form->{sort}";        # needed for accno
311   
312   foreach $item (@columns) {
313     if ($form->{"l_$item"} eq "Y") {
314       push @column_index, $item;
315
316       # add column to href and callback
317       $callback .= "&l_$item=Y";
318       $href .= "&l_$item=Y";
319     }
320   }
321   
322   if ($form->{l_subtotal} eq 'Y') {
323     $callback .= "&l_subtotal=Y";
324     $href .= "&l_subtotal=Y";
325   }
326
327   $callback .= "&category=$form->{category}";
328   $href .= "&category=$form->{category}";
329
330   $column_header{id} = "<th><a class=listheading href=$callback&sort=id>".$locale->text('ID')."</a></th>";
331   $column_header{transdate} = "<th><a class=listheading href=$callback&sort=transdate>".$locale->text('Date')."</a></th>";
332   $column_header{reference} = "<th><a class=listheading href=$callback&sort=reference>".$locale->text('Reference')."</a></th>";
333   $column_header{source} = "<th><a class=listheading href=$callback&sort=source>".$locale->text('Source')."</a></th>";
334   $column_header{description} = "<th><a class=listheading href=$callback&sort=description>".$locale->text('Description')."</a></th>";
335   $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
336   $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
337   $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
338   $column_header{accno} = "<th><a class=listheading href=$callback&sort=accno>".$locale->text('Account')."</a></th>";
339   $column_header{gifi_accno} = "<th><a class=listheading href=$callback&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
340   $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</th>";
341  
342   $form->header;
343
344   print qq|
345 <body>
346
347 <table width=100%>
348   <tr>
349     <th class=listtop>$form->{title}</th>
350   </tr>
351   <tr height="5"></tr>
352   <tr>
353     <td>$option</td>
354   </tr>
355   <tr>
356     <td>
357       <table width=100%>
358         <tr class=listheading>
359 |;
360
361 map { print "$column_header{$_}\n" } @column_index;
362
363 print "
364         </tr>
365 ";
366   
367   # add sort to callback
368   $form->{callback} = "$callback&sort=$form->{sort}";
369   $callback = $form->escape($form->{callback});
370   
371   # initial item for subtotals
372   if (@{ $form->{GL} }) {
373     $sameitem = $form->{GL}->[0]->{$form->{sort}};
374   }
375   
376   if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
377
378     map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
379     $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
380     
381     $i++; $i %= 2;
382     print qq|
383         <tr class=listrow$i>
384 |;
385     map { print "$column_data{$_}\n" } @column_index;
386     
387     print qq|
388         </tr>
389 |;
390   }
391     
392   foreach $ref (@{ $form->{GL} }) {
393
394     # if item ne sort print subtotal
395     if ($form->{l_subtotal} eq 'Y') {
396       if ($sameitem ne $ref->{$form->{sort}}) {
397         &gl_subtotal;
398       }
399     }
400     
401     $form->{balance} += $ref->{amount};
402     
403     $subtotaldebit += $ref->{debit};
404     $subtotalcredit += $ref->{credit};
405     
406     $totaldebit += $ref->{debit};
407     $totalcredit += $ref->{credit};
408
409     $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
410     $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
411     
412     $column_data{id} = "<td>$ref->{id}</td>";
413     $column_data{transdate} = "<td>$ref->{transdate}</td>";
414     $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
415     $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
416     $column_data{source} = "<td>$ref->{source}&nbsp;</td>";
417     $column_data{notes} = "<td>$ref->{notes}&nbsp;</td>";
418     $column_data{debit} = "<td align=right>$ref->{debit}</td>";
419     $column_data{credit} = "<td align=right>$ref->{credit}</td>";
420     $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
421     $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
422     $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
423
424     $i++; $i %= 2;
425     print "
426         <tr class=listrow$i>";
427     map { print "$column_data{$_}\n" } @column_index;
428     print "</tr>";
429     
430   }
431
432
433   &gl_subtotal if ($form->{l_subtotal} eq 'Y');
434
435
436   map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
437   
438   $column_data{debit} = "<th align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
439   $column_data{credit} = "<th align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
440   $column_data{balance} = "<th align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
441   
442   print qq|
443         <tr class=listtotal>
444 |;
445
446   map { print "$column_data{$_}\n" } @column_index;
447
448   print qq|
449         </tr>
450       </table>
451     </td>
452   </tr>
453   <tr>
454     <td><hr size=3 noshade></td>
455   </tr>
456 </table>
457
458 <br>
459
460 <form method=post action=$form->{script}>
461
462 <input name=callback type=hidden value="$form->{callback}">
463
464 <input type=hidden name=path value=$form->{path}>
465 <input type=hidden name=login value=$form->{login}>
466 <input type=hidden name=password value=$form->{password}>
467
468 <input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|">
469 <input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|">
470 <input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|">
471 <input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|">
472 <input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|">
473
474 </form>
475
476 </body>
477 </html>
478 |;
479
480 }
481
482
483 sub gl_subtotal {
484       
485   $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
486   $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
487   
488   map { $column_data{$_} = "<td>&nbsp;</td>" } qw(transdate id reference source description accno);
489   $column_data{debit} = "<th class=listsubtotal align=right>$subtotaldebit</td>";
490   $column_data{credit} = "<th class=listsubtotal align=right>$subtotalcredit</td>";
491
492   
493   print "<tr class=listsubtotal>";
494   map { print "$column_data{$_}\n" } @column_index;
495   print "</tr>";
496
497   $subtotaldebit = 0;
498   $subtotalcredit = 0;
499
500   $sameitem = $ref->{$form->{sort}};
501
502 }
503
504
505 sub update {
506
507   @a = ();
508   $count = 0;
509   @flds = (qw(accno debit credit projectnumber project_id));
510
511   for $i (1 .. $form->{rowcount}) {
512     unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
513       # take accno apart
514       ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"});
515       
516       push @a, {};
517       $j = $#a;
518       
519       map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
520       $count++;
521     }
522   }
523
524   for $i (1 .. $count) {
525     $j = $i - 1;
526     map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds;
527   }
528
529   for $i ($count + 1 .. $form->{rowcount}) {
530     map { delete $form->{"${_}_$i"} } @flds;
531   }
532
533   $form->{rowcount} = $count;
534
535   &check_project;
536
537   &display_form;
538   
539 }
540
541
542 sub display_form {
543
544   &form_header;
545
546   $form->{rowcount}++;
547   $form->{totaldebit} = 0;
548   $form->{totalcredit} = 0;
549   
550   for $i (1 .. $form->{rowcount}) {
551     $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
552     $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
553  
554     &form_row($i);
555   }
556
557   &form_footer;
558
559 }
560
561
562 sub form_row {
563   my $i = shift;
564   
565   my $chart = $form->{chart};
566   $chart =~ s/<option>$form->{"accno_$i"}/<option selected>$form->{"accno_$i"}/;
567   
568   print qq|<tr>
569   <td><select name="accno_$i">$chart</select></td>
570   <td><input name="debit_$i" size=12 value=$form->{"debit_$i"}></td>
571   <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
572   <td><input name="projectnumber_$i" size=12 value="$form->{"projectnumber_$i"}">
573       <input type=hidden name="project_id_$i" value=$form->{"project_id_$i"}>
574       <input type=hidden name="oldprojectnumber_$i" value="$form->{"oldprojectnumber_$i"}"></td>
575 </tr>
576 <input type=hidden name=rowcount value=$i>
577
578 |;
579
580 }
581
582
583 sub form_header {
584
585   $title = $form->{title};
586   $form->{title} = $locale->text("$title General Ledger Transaction");
587   
588 # $locale->text('Add General Ledger Transaction')
589 # $locale->text('Edit General Ledger Transaction')
590
591   map { $form->{$_} =~ s/"/&quot;/g } qw(reference description chart);
592
593   if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
594     $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
595   } else {
596     $description = qq|<input name=description size=50 value="$form->{description}">|;
597   }
598   
599   if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
600     $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
601   } else {
602     $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
603   }
604
605   $form->header;
606
607   print qq|
608 <body>
609
610 <form method=post action=$form->{script}>
611
612 <input name=id type=hidden value=$form->{id}>
613
614 <input name=chart type=hidden value="$form->{chart}">
615 <input type=hidden name=closedto value=$form->{closedto}>
616 <input type=hidden name=locked value=$form->{locked}>
617 <input type=hidden name=title value="$title">
618
619 <table width=100%>
620   <tr>
621     <th class=listtop>$form->{title}</th>
622   </tr>
623   <tr height="5"></tr>
624   <tr>
625     <td>
626       <table width=100%>
627         <tr>
628           <th align=right>|.$locale->text('Reference').qq|</th>
629           <td><input name=reference size=20 value="$form->{reference}"></td>
630           <td align=right>
631             <table>
632               <tr>
633                 <th align=right>|.$locale->text('Date').qq|</th>
634                 <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
635               </tr>
636             </table>
637           </td>
638         </tr>
639         <tr>
640           <th align=right>|.$locale->text('Description').qq|</th>
641           <td colspan=2>$description</td>
642         </tr>
643         <tr>
644           <th align=right>|.$locale->text('Notes').qq|</th>
645           <td colspan=2>$notes</td>
646         </tr>
647       </table>
648     </td>
649   </tr>
650   <tr>
651     <td>
652       <table width=100%>
653         <tr class=listheading>
654           <th class=listheading>|.$locale->text('Account').qq|</th>
655           <th class=listheading>|.$locale->text('Debit').qq|</th>
656           <th class=listheading>|.$locale->text('Credit').qq|</th>
657           <th class=listheading>|.$locale->text('Project').qq|</th>
658         </tr>
659 |;
660
661 }
662
663
664 sub form_footer {
665
666   ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
667   $dec = length $dec;
668   $decimalplaces = ($dec > 2) ? $dec : 2;
669   
670   map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, "&nbsp;") } qw(totaldebit totalcredit);
671   
672   print qq|
673         <tr class=listtotal>
674           <th>&nbsp;</th>
675           <th class=listtotal align=right>$form->{totaldebit}</th>
676           <th class=listtotal align=right>$form->{totalcredit}</th>
677           <th>&nbsp;</th>
678         </tr>
679       </table>
680     </td>
681   </tr>
682   <tr>
683     <td><hr size=3 noshade></td>
684   </tr>
685 </table>
686
687 <input type=hidden name=path value=$form->{path}>
688 <input type=hidden name=login value=$form->{login}>
689 <input type=hidden name=password value=$form->{password}>
690
691 <input name=callback type=hidden value="$form->{callback}">
692
693 <br>
694 |;
695
696   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
697   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
698   
699   if ($form->{id}) {
700     print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
701 |;
702
703     if (!$form->{revtrans}) {
704       if (!$form->{locked}) {
705         print qq|
706         <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
707         <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
708 |;
709       }
710     }
711
712     if ($transdate > $closedto) {
713       print qq|
714       <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
715 |;
716     }
717     
718   } else {
719     if ($transdate > $closedto) {
720       print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
721       <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
722     }
723   }
724
725   print "</form>
726
727 </body>
728 </html>
729 ";
730   
731 }
732
733
734 sub delete {
735
736   $form->header;
737
738   print qq|
739 <body>
740
741 <form method=post action=$form->{script}>
742 |;
743
744   map { $form->{$_} =~ s/"/&quot;/g } qw(reference description chart);
745
746   foreach $key (keys %$form) {
747     print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
748   }
749
750   print qq|
751 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
752
753 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
754
755 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
756 </form>
757 |;
758
759 }
760
761
762 sub yes {
763
764   $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form));
765   $form->error($locale->text('Cannot delete transaction!'));
766   
767 }
768
769
770 sub post {
771
772   # check if there is something in reference and date
773   $form->isblank("reference", $locale->text('Reference missing!'));
774   $form->isblank("transdate", $locale->text('Transaction Date missing!'));
775
776   $transdate = $form->datetonum($form->{transdate}, \%myconfig);
777   $closedto = $form->datetonum($form->{closedto}, \%myconfig);
778
779   # check project
780   &check_project;
781   
782   # this is just for the wise guys
783   $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
784   
785   if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
786     $errno *= -1;
787     $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
788     $err[2] = $locale->text('Debit and credit out of balance!');
789     $err[3] = $locale->text('Cannot post a transaction without a value!');
790     
791     $form->error($err[$errno]);
792   }
793     
794   $form->redirect($locale->text('Transaction posted!'));
795   
796 }
797
798
799 sub post_as_new {
800
801   $form->{id} = 0;
802   &post;
803
804 }
805
806