1 #=====================================================================
2 # SQL-Ledger Accounting
5 # Author: Dieter Simader
6 # Email: dsimader@sql-ledger.org
7 # Web: http://www.sql-ledger.org
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
27 #======================================================================
33 require "$form->{path}/arap.pl";
39 # this is for our long dates
40 # $locale->text('January')
41 # $locale->text('February')
42 # $locale->text('March')
43 # $locale->text('April')
44 # $locale->text('May ')
45 # $locale->text('June')
46 # $locale->text('July')
47 # $locale->text('August')
48 # $locale->text('September')
49 # $locale->text('October')
50 # $locale->text('November')
51 # $locale->text('December')
53 # this is for our short month
54 # $locale->text('Jan')
55 # $locale->text('Feb')
56 # $locale->text('Mar')
57 # $locale->text('Apr')
58 # $locale->text('May')
59 # $locale->text('Jun')
60 # $locale->text('Jul')
61 # $locale->text('Aug')
62 # $locale->text('Sep')
63 # $locale->text('Oct')
64 # $locale->text('Nov')
65 # $locale->text('Dec')
70 $form->{title} = "Add";
72 $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback};
74 # we use this only to set a default date
75 GL->transaction(\%myconfig, \%$form);
77 map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{all_accno} };
79 if ($form->{all_projects}) {
80 $form->{selectprojectnumber} = "<option>\n";
81 map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} };
85 $form->{rowcount} = ($form->{transfer}) ? 2 : 9;
88 $form->all_departments(\%myconfig);
89 if (@{ $form->{all_departments} }) {
90 $form->{selectdepartment} = "<option>\n";
92 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
102 GL->transaction(\%myconfig, \%$form);
104 map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}\n" } @{ $form->{all_accno} };
107 if ($form->{all_projects}) {
108 $form->{selectprojectnumber} = "<option>\n";
109 map { $form->{selectprojectnumber} .= qq|<option value="$_->{projectnumber}--$_->{id}">$_->{projectnumber}\n| } @{ $form->{all_projects} };
114 $form->all_departments(\%myconfig);
115 if (@{ $form->{all_departments} }) {
117 $form->{department} = "$form->{department}--$form->{department_id}";
119 $form->{selectdepartment} = "<option>\n";
121 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
124 $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
127 $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;
129 $form->{title} = "Edit";
134 foreach $ref (@{ $form->{GL} }) {
135 $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
137 $form->{"projectnumber_$i"} = "$ref->{projectnumber}--$ref->{project_id}";
138 $form->{"fx_transaction_$i"} = $ref->{fx_transaction};
140 if ($ref->{amount} < 0) {
141 $form->{totaldebit} -= $ref->{amount};
142 $form->{"debit_$i"} = $ref->{amount} * -1;
144 $form->{totalcredit} += $ref->{amount};
145 $form->{"credit_$i"} = $ref->{amount};
151 $form->{rowcount} = $i;
163 $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
165 $form->all_departments(\%myconfig);
167 if (@{ $form->{all_departments} }) {
168 $form->{selectdepartment} = "<option>\n";
170 map { $form->{selectdepartment} .= qq|<option value="$_->{description}--$_->{id}">$_->{description}\n| } (@{ $form->{all_departments} });
174 <th align=right nowrap>|.$locale->text('Department').qq|</th>
175 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
182 $form->{selectaccountingyear} = "<option>\n";
183 map { $form->{selectaccountingyear} .= qq|<option>$_\n| } @{ $form->{all_years} };
184 $form->{selectaccountingmonth} = "<option>\n";
185 map { $form->{selectaccountingmonth} .= qq|<option value=$_>|.$locale->text($form->{all_month}{$_}).qq|\n| } sort keys %{ $form->{all_month} };
189 <th align=right>|.$locale->text('Period').qq|</th>
191 <select name=month>$form->{selectaccountingmonth}</select>
192 <select name=year>$form->{selectaccountingyear}</select>
193 <input name=interval class=radio type=radio value=0 checked>|.$locale->text('Current').qq|
194 <input name=interval class=radio type=radio value=1>|.$locale->text('Month').qq|
195 <input name=interval class=radio type=radio value=3>|.$locale->text('Quarter').qq|
196 <input name=interval class=radio type=radio value=12>|.$locale->text('Year').qq|
207 <form method=post action=$form->{script}>
209 <input type=hidden name=sort value=transdate>
213 <th class=listtop>$form->{title}</th>
220 <th align=right>|.$locale->text('Reference').qq|</th>
221 <td><input name=reference size=20></td>
222 <th align=right>|.$locale->text('Source').qq|</th>
223 <td><input name=source size=20></td>
227 <th align=right>|.$locale->text('Description').qq|</th>
228 <td colspan=3><input name=description size=40></td>
231 <th align=right>|.$locale->text('Notes').qq|</th>
232 <td colspan=3><input name=notes size=40></td>
235 <th align=right>|.$locale->text('From').qq|</th>
236 <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
237 <th align=right>|.$locale->text('To').qq|</th>
238 <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
242 <th align=right>|.$locale->text('Amount').qq| >=</th>
243 <td><input name=amountfrom size=11></td>
244 <th align=right>|.$locale->text('Amount').qq| <=</th>
245 <td><input name=amountto size=11></td>
248 <th align=right>|.$locale->text('Include in Report').qq|</th>
253 <input name="category" class=radio type=radio value=X checked> |.$locale->text('All').qq|
254 <input name="category" class=radio type=radio value=A> |.$locale->text('Asset').qq|
255 <input name="category" class=radio type=radio value=C> |.$locale->text('Contra').qq|
256 <input name="category" class=radio type=radio value=L> |.$locale->text('Liability').qq|
257 <input name="category" class=radio type=radio value=Q> |.$locale->text('Equity').qq|
258 <input name="category" class=radio type=radio value=I> |.$locale->text('Income').qq|
259 <input name="category" class=radio type=radio value=E> |.$locale->text('Expense').qq|
265 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
266 <td>|.$locale->text('ID').qq|</td>
267 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
268 <td>|.$locale->text('Date').qq|</td>
269 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
270 <td>|.$locale->text('Reference').qq|</td>
271 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
272 <td>|.$locale->text('Description').qq|</td>
273 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
274 <td>|.$locale->text('Notes').qq|</td>
277 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
278 <td>|.$locale->text('Debit').qq|</td>
279 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
280 <td>|.$locale->text('Credit').qq|</td>
281 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
282 <td>|.$locale->text('Source').qq|</td>
283 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
284 <td>|.$locale->text('Account').qq|</td>
285 <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
286 <td>|.$locale->text('GIFI').qq|</td>
289 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
290 <td>|.$locale->text('Subtotal').qq|</td>
300 <td><hr size=3 noshade></td>
304 <input type=hidden name=nextsub value=generate_report>
306 <input type=hidden name=path value=$form->{path}>
307 <input type=hidden name=login value=$form->{login}>
308 <input type=hidden name=sessionid value=$form->{sessionid}>
311 <input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
320 sub generate_report {
322 $form->{sort} = "transdate" unless $form->{sort};
324 GL->all_transactions(\%myconfig, \%$form);
326 $href = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
330 $callback = "$form->{script}?action=generate_report&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
332 %acctype = ( 'A' => $locale->text('Asset'),
333 'C' => $locale->text('Contra'),
334 'L' => $locale->text('Liability'),
335 'Q' => $locale->text('Equity'),
336 'I' => $locale->text('Income'),
337 'E' => $locale->text('Expense'),
340 $form->{title} = $locale->text('General Ledger');
342 $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
344 unless ($form->{category} eq 'X') {
345 $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
347 if ($form->{accno}) {
348 $href .= "&accno=".$form->escape($form->{accno});
349 $callback .= "&accno=".$form->escape($form->{accno},1);
350 $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
352 if ($form->{gifi_accno}) {
353 $href .= "&gifi_accno=".$form->escape($form->{gifi_accno});
354 $callback .= "&gifi_accno=".$form->escape($form->{gifi_accno},1);
355 $option .= "\n<br>" if $option;
356 $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
358 if ($form->{source}) {
359 $href .= "&source=".$form->escape($form->{source});
360 $callback .= "&source=".$form->escape($form->{source},1);
361 $option .= "\n<br>" if $option;
362 $option .= $locale->text('Source')." : $form->{source}";
364 if ($form->{reference}) {
365 $href .= "&reference=".$form->escape($form->{reference});
366 $callback .= "&reference=".$form->escape($form->{reference},1);
367 $option .= "\n<br>" if $option;
368 $option .= $locale->text('Reference')." : $form->{reference}";
370 if ($form->{department}) {
371 $href .= "&department=".$form->escape($form->{department});
372 $callback .= "&department=".$form->escape($form->{department},1);
373 ($department) = split /--/, $form->{department};
374 $option .= "\n<br>" if $option;
375 $option .= $locale->text('Department')." : $department";
378 if ($form->{description}) {
379 $href .= "&description=".$form->escape($form->{description});
380 $callback .= "&description=".$form->escape($form->{description},1);
381 $option .= "\n<br>" if $option;
382 $option .= $locale->text('Description')." : $form->{description}";
384 if ($form->{notes}) {
385 $href .= "¬es=".$form->escape($form->{notes});
386 $callback .= "¬es=".$form->escape($form->{notes},1);
387 $option .= "\n<br>" if $option;
388 $option .= $locale->text('Notes')." : $form->{notes}";
391 if ($form->{datefrom}) {
392 $href .= "&datefrom=$form->{datefrom}";
393 $callback .= "&datefrom=$form->{datefrom}";
394 $option .= "\n<br>" if $option;
395 $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
397 if ($form->{dateto}) {
398 $href .= "&dateto=$form->{dateto}";
399 $callback .= "&dateto=$form->{dateto}";
400 if ($form->{datefrom}) {
403 $option .= "\n<br>" if $option;
405 $option .= $locale->text('To')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
408 if ($form->{amountfrom}) {
409 $href .= "&amountfrom=$form->{amountfrom}";
410 $callback .= "&amountfrom=$form->{amountfrom}";
411 $option .= "\n<br>" if $option;
412 $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2);
414 if ($form->{amountto}) {
415 $href .= "&amountto=$form->{amountto}";
416 $callback .= "&amountto=$form->{amountto}";
417 if ($form->{amountfrom}) {
420 $option .= "\n<br>" if $option;
421 $option .= $locale->text('Amount')." <= ";
423 $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);
427 @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno));
429 if ($form->{link} =~ /_paid/) {
430 @columns = $form->sort_columns(qw(transdate id reference description notes source cleared debit credit accno gifi_accno));
431 $form->{l_cleared} = "Y";
434 if ($form->{accno} || $form->{gifi_accno}) {
435 @columns = grep !/(accno|gifi_accno)/, @columns;
436 push @columns, "balance";
437 $form->{l_balance} = "Y";
441 foreach $item (@columns) {
442 if ($form->{"l_$item"} eq "Y") {
443 push @column_index, $item;
445 # add column to href and callback
446 $callback .= "&l_$item=Y";
447 $href .= "&l_$item=Y";
451 if ($form->{l_subtotal} eq 'Y') {
452 $callback .= "&l_subtotal=Y";
453 $href .= "&l_subtotal=Y";
456 $callback .= "&category=$form->{category}";
457 $href .= "&category=$form->{category}";
459 $column_header{id} = "<th><a class=listheading href=$href&sort=id>".$locale->text('ID')."</a></th>";
460 $column_header{transdate} = "<th><a class=listheading href=$href&sort=transdate>".$locale->text('Date')."</a></th>";
461 $column_header{reference} = "<th><a class=listheading href=$href&sort=reference>".$locale->text('Reference')."</a></th>";
462 $column_header{source} = "<th><a class=listheading href=$href&sort=source>".$locale->text('Source')."</a></th>";
463 $column_header{description} = "<th><a class=listheading href=$href&sort=description>".$locale->text('Description')."</a></th>";
464 $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
465 $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
466 $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
467 $column_header{accno} = "<th><a class=listheading href=$href&sort=accno>".$locale->text('Account')."</a></th>";
468 $column_header{gifi_accno} = "<th><a class=listheading href=$href&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
469 $column_header{balance} = "<th>".$locale->text('Balance')."</th>";
470 $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
479 <th class=listtop>$form->{title}</th>
488 <tr class=listheading>
491 map { print "$column_header{$_}\n" } @column_index;
497 # add sort to callback
498 $form->{callback} = "$callback&sort=$form->{sort}";
499 $callback = $form->escape($form->{callback});
501 # initial item for subtotals
502 if (@{ $form->{GL} }) {
503 $sameitem = $form->{GL}->[0]->{$form->{sort}};
506 if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
508 map { $column_data{$_} = "<td> </td>" } @column_index;
509 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
515 map { print "$column_data{$_}\n" } @column_index;
523 $direction = ($form->{direction} eq 'ASC') ? "ASC" : "DESC";
525 $href =~ s/direction=$form->{direction}/direction=$direction/;
527 foreach $ref (@{ $form->{GL} }) {
529 # if item ne sort print subtotal
530 if ($form->{l_subtotal} eq 'Y') {
531 if ($sameitem ne $ref->{$form->{sort}}) {
536 $form->{balance} += $ref->{amount};
538 $subtotaldebit += $ref->{debit};
539 $subtotalcredit += $ref->{credit};
541 $totaldebit += $ref->{debit};
542 $totalcredit += $ref->{credit};
544 $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, " ");
545 $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, " ");
547 $column_data{id} = "<td>$ref->{id}</td>";
548 $column_data{transdate} = "<td>$ref->{transdate}</td>";
549 $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{reference}</td>";
550 $column_data{description} = "<td>$ref->{description} </td>";
551 $column_data{source} = "<td>$ref->{source} </td>";
552 $column_data{notes} = "<td>$ref->{notes} </td>";
553 $column_data{debit} = "<td align=right>$ref->{debit}</td>";
554 $column_data{credit} = "<td align=right>$ref->{credit}</td>";
555 $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
556 $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a> </td>";
557 $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
558 $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td> </td>";
562 <tr class=listrow$i>";
563 map { print "$column_data{$_}\n" } @column_index;
569 &gl_subtotal if ($form->{l_subtotal} eq 'Y');
572 map { $column_data{$_} = "<td> </td>" } @column_index;
574 $column_data{debit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totaldebit, 2, " ")."</th>";
575 $column_data{credit} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $totalcredit, 2, " ")."</th>";
576 $column_data{balance} = "<th align=right class=listtotal>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
582 map { print "$column_data{$_}\n" } @column_index;
585 if ($myconfig{acs} !~ /GL--GL/) {
586 $button{'GL--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> |;
587 $button{'GL--Add Transaction'}{order} = $i++;
589 if ($myconfig{acs} !~ /AR--AR/) {
590 $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
591 $button{'AR--Add Transaction'}{order} = $i++;
592 $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice ').qq|"> |;
593 $button{'AR--Sales Invoice'}{order} = $i++;
595 if ($myconfig{acs} !~ /AP--AP/) {
596 $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
597 $button{'AP--Add Transaction'}{order} = $i++;
598 $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice ').qq|"> |;
599 $button{'AP--Vendor Invoice'}{order} = $i++;
602 foreach $item (split /;/, $myconfig{acs}) {
603 delete $button{$item};
612 <td><hr size=3 noshade></td>
618 <form method=post action=$form->{script}>
620 <input name=callback type=hidden value="$form->{callback}">
622 <input type=hidden name=path value=$form->{path}>
623 <input type=hidden name=login value=$form->{login}>
624 <input type=hidden name=sessionid value=$form->{sessionid}>
627 foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
631 if ($form->{menubar}) {
632 require "$form->{path}/menu.pl";
649 $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, " ");
650 $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, " ");
652 map { $column_data{$_} = "<td> </td>" } @column_index;
654 $column_data{debit} = "<th align=right class=listsubtotal>$subtotaldebit</td>";
655 $column_data{credit} = "<th align=right class=listsubtotal>$subtotalcredit</td>";
658 print "<tr class=listsubtotal>";
659 map { print "$column_data{$_}\n" } @column_index;
665 $sameitem = $ref->{$form->{sort}};
674 @flds = qw(accno debit credit projectnumber);
676 for $i (1 .. $form->{rowcount}) {
677 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
679 ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"});
680 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(debit credit);
685 map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
691 for $i (1 .. $count) {
693 map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds;
696 for $i ($count + 1 .. $form->{rowcount}) {
697 map { delete $form->{"${_}_$i"} } @flds;
700 $form->{rowcount} = $count + 1;
718 $form->{selectprojectnumber} = $form->unescape($form->{selectprojectnumber});
720 $form->{totaldebit} = 0;
721 $form->{totalcredit} = 0;
723 for $i (1 .. $form->{rowcount}) {
725 $form->{totaldebit} += $form->{"debit_$i"};
726 $form->{totalcredit} += $form->{"credit_$i"};
728 map { $form->{"${_}_$i"} = ($form->{"${_}_$i"}) ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) : "" } qw(debit credit);
730 $selectaccno = $form->{selectaccno};
731 $selectaccno =~ s/option>\Q$form->{"accno_$i"}\E/option selected>$form->{"accno_$i"}/;
733 if ($form->{selectprojectnumber}) {
734 $selectprojectnumber = $form->{selectprojectnumber};
735 $selectprojectnumber =~ s/(<option value="$form->{"projectnumber_$i"}")/$1 selected/;
738 <td><select name="projectnumber_$i">$selectprojectnumber</select></td>|;
742 if ($form->{transfer}) {
743 $form->{"fx_transaction_$i"} = ($form->{"fx_transaction_$i"}) ? "checked" : "";
744 $fx_transaction = qq|
745 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1 $form->{"fx_transaction_$i"}></td>
748 $fx_transaction = qq|
749 <input type=hidden name="fx_transaction_$i" value=$form->{"fx_transaction_$i"}>
755 <td><select name="accno_$i">$selectaccno</select></td>
757 <td><input name="debit_$i" size=12 value=$form->{"debit_$i"}></td>
758 <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
767 <input type=hidden name=rowcount value=$form->{rowcount}>
768 <input type=hidden name=selectaccno value="$form->{selectaccno}">
769 <input type=hidden name=selectprojectnumber value="|.$form->escape($form->{selectprojectnumber},1).qq|">|;
776 $title = $form->{title};
777 if ($form->{transfer}) {
778 $form->{title} = $locale->text("$title Cash Transfer Transaction");
780 $form->{title} = $locale->text("$title General Ledger Transaction");
783 # $locale->text('Add Cash Transfer Transaction')
784 # $locale->text('Edit Cash Transfer Transaction')
785 # $locale->text('Add General Ledger Transaction')
786 # $locale->text('Edit General Ledger Transaction')
789 $form->{selectdepartment} = $form->unescape($form->{selectdepartment});
790 $form->{selectdepartment} =~ s/ selected//;
791 $form->{selectdepartment} =~ s/(<option value="\Q$form->{department}\E")/$1 selected/;
793 map { $form->{$_} = $form->quote($form->{$_}) } qw(reference description notes);
795 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
796 $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
798 $description = qq|<input name=description size=50 value="$form->{description}">|;
801 if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
802 $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
804 $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
809 <th align=right nowrap>|.$locale->text('Department').qq|</th>
810 <td><select name=department>$form->{selectdepartment}</select></td>
811 <input type=hidden name=selectdepartment value="|.$form->escape($form->{selectdepartment},1).qq|">
813 | if $form->{selectdepartment};
816 <th class=listheading>|.$locale->text('Project').qq|</th>
817 | if $form->{selectprojectnumber};
819 if ($form->{transfer}) {
820 $fx_transaction = qq|
821 <th class=listheading>|.$locale->text('FX').qq|</th>
830 <form method=post action=$form->{script}>
832 <input name=id type=hidden value=$form->{id}>
834 <input type=hidden name=transfer value=$form->{transfer}>
836 <input type=hidden name=selectaccno value="$form->{selectaccno}">
838 <input type=hidden name=closedto value=$form->{closedto}>
839 <input type=hidden name=locked value=$form->{locked}>
840 <input type=hidden name=title value="$title">
844 <th class=listtop>$form->{title}</th>
851 <th align=right>|.$locale->text('Reference').qq|</th>
852 <td><input name=reference size=20 value="$form->{reference}"></td>
853 <th align=right>|.$locale->text('Date').qq|</th>
854 <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
858 <th align=right>|.$locale->text('Description').qq|</th>
859 <td colspan=3>$description</td>
862 <th align=right>|.$locale->text('Notes').qq|</th>
863 <td colspan=3>$notes</td>
871 <tr class=listheading>
872 <th class=listheading>|.$locale->text('Account').qq|</th>
874 <th class=listheading>|.$locale->text('Debit').qq|</th>
875 <th class=listheading>|.$locale->text('Credit').qq|</th>
885 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
887 $decimalplaces = ($dec > 2) ? $dec : 2;
889 map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, " ") } qw(totaldebit totalcredit);
894 | if $form->{selectprojectnumber};
896 if ($form->{transfer}) {
897 $fx_transaction = qq|
906 <th class=listtotal align=right>$form->{totaldebit}</th>
907 <th class=listtotal align=right>$form->{totalcredit}</th>
914 <td><hr size=3 noshade></td>
918 <input type=hidden name=path value=$form->{path}>
919 <input type=hidden name=login value=$form->{login}>
920 <input type=hidden name=sessionid value=$form->{sessionid}>
922 <input name=callback type=hidden value="$form->{callback}">
927 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
928 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
930 if (! $form->{readonly}) {
933 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
936 if (!$form->{locked}) {
938 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
939 <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
944 <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
948 if ($transdate > $closedto) {
949 print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
950 <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
955 if ($form->{menubar}) {
956 require "$form->{path}/menu.pl";
977 <form method=post action=$form->{script}>
983 <h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
985 <h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
987 <input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
996 $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form));
997 $form->error($locale->text('Cannot delete transaction!'));
1004 # check if there is something in reference and date
1005 $form->isblank("reference", $locale->text('Reference missing!'));
1006 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1008 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1009 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1012 $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
1014 # add up debits and credits
1015 if (!$form->{adjustment}) {
1016 for $i (1 .. $form->{rowcount}) {
1017 $debit += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
1018 $credit += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
1021 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1027 $form->redirect($locale->text('Transaction posted!')) if GL->post_transaction(\%myconfig, \%$form);
1028 $form->error($locale->text('Cannot post transaction!'));
1041 sub post_adjustment {
1048 <form method=post action=$form->{script}>
1050 <input type=hidden name=adjustment value=1>
1056 <h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
1058 <h4>|.$locale->text('Out of balance transaction!').qq|</h4>
1060 <input name=action class=submit type=submit value="|.$locale->text('Post').qq|">