1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
32 #======================================================================
34 use POSIX qw(strftime);
35 use List::Util qw(sum);
41 use SL::ReportGenerator;
43 require "bin/mozilla/common.pl";
44 require "bin/mozilla/drafts.pl";
45 require "bin/mozilla/reportgenerator.pl";
51 # this is for our long dates
52 # $locale->text('January')
53 # $locale->text('February')
54 # $locale->text('March')
55 # $locale->text('April')
56 # $locale->text('May ')
57 # $locale->text('June')
58 # $locale->text('July')
59 # $locale->text('August')
60 # $locale->text('September')
61 # $locale->text('October')
62 # $locale->text('November')
63 # $locale->text('December')
65 # this is for our short month
66 # $locale->text('Jan')
67 # $locale->text('Feb')
68 # $locale->text('Mar')
69 # $locale->text('Apr')
70 # $locale->text('May')
71 # $locale->text('Jun')
72 # $locale->text('Jul')
73 # $locale->text('Aug')
74 # $locale->text('Sep')
75 # $locale->text('Oct')
76 # $locale->text('Nov')
77 # $locale->text('Dec')
80 $lxdebug->enter_sub();
82 $auth->assert('general_ledger');
84 return $lxdebug->leave_sub() if (load_draft_maybe());
86 $form->{title} = "Add";
88 $form->{callback} = "gl.pl?action=add" unless $form->{callback};
90 # we use this only to set a default date
91 GL->transaction(\%myconfig, \%$form);
95 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
96 . ($_->{rate} * 100) . qq| %|
99 $form->{rowcount} = 2;
106 $form->all_departments(\%myconfig);
107 if (@{ $form->{all_departments} }) {
108 $form->{selectdepartment} = "<option>\n";
111 $form->{selectdepartment} .=
112 "<option>$_->{description}--$_->{id}\n"
113 } (@{ $form->{all_departments} });
116 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
119 $lxdebug->leave_sub();
123 sub prepare_transaction {
124 $lxdebug->enter_sub();
126 $auth->assert('general_ledger');
128 GL->transaction(\%myconfig, \%$form);
132 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
133 . ($_->{rate} * 100) . qq| %|
136 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
139 $form->all_departments(\%myconfig);
140 if (@{ $form->{all_departments} }) {
141 $form->{selectdepartment} = "<option>\n";
144 $form->{selectdepartment} .=
145 "<option>$_->{description}--$_->{id}\n"
146 } (@{ $form->{all_departments} });
152 foreach $ref (@{ $form->{GL} }) {
154 if ($tax && ($ref->{accno} eq $taxaccno)) {
155 $form->{"tax_$j"} = abs($ref->{amount});
156 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
157 if ($form->{taxincluded}) {
158 if ($ref->{amount} < 0) {
159 $form->{"debit_$j"} += $form->{"tax_$j"};
161 $form->{"credit_$j"} += $form->{"tax_$j"};
164 $form->{"project_id_$j"} = $ref->{project_id};
167 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
168 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
169 if ($ref->{amount} < 0) {
170 $form->{totaldebit} -= $ref->{amount};
171 $form->{"debit_$i"} = $ref->{amount} * -1;
173 $form->{totalcredit} += $ref->{amount};
174 $form->{"credit_$i"} = $ref->{amount};
176 $form->{"taxchart_$i"} = "0--0.00";
177 $form->{"project_id_$i"} = $ref->{project_id};
180 if ($ref->{taxaccno} && !$tax) {
181 $taxaccno = $ref->{taxaccno};
189 $form->{rowcount} = $i;
191 ($form->datetonum($form->{transdate}, \%myconfig) <=
192 $form->datetonum($form->{closedto}, \%myconfig));
194 $lxdebug->leave_sub();
198 $lxdebug->enter_sub();
200 $auth->assert('general_ledger');
202 prepare_transaction();
204 $form->{title} = "Edit";
206 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
212 $lxdebug->leave_sub();
217 $lxdebug->enter_sub();
219 $auth->assert('general_ledger');
221 $form->{title} = $locale->text('Journal');
223 $form->all_departments(\%myconfig);
226 if (@{ $form->{all_departments} }) {
227 $form->{selectdepartment} = "<option>\n";
230 $form->{selectdepartment} .=
231 "<option>$_->{description}--$_->{id}\n"
232 } (@{ $form->{all_departments} });
237 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
238 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
240 | if $form->{selectdepartment};
242 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
245 my %project_labels = ();
246 my @project_values = ("");
247 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
248 push(@project_values, $item->{"id"});
249 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
253 NTI($cgi->popup_menu('-name' => "project_id",
254 '-values' => \@project_values,
255 '-labels' => \%project_labels));
257 # use JavaScript Calendar or not
258 $form->{jsscript} = 1;
260 if ($form->{jsscript}) {
262 # with JavaScript Calendar
264 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
265 <input type=button name=datefrom id="trigger1" value=|
266 . $locale->text('button') . qq|></td>
269 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
270 <input type=button name=dateto id="trigger2" value=|
271 . $locale->text('button') . qq|></td>
276 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
277 "dateto", "BL", "trigger2");
280 # without JavaScript Calendar
282 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
284 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
286 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
288 $onload = qq|focus()|;
289 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
290 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
292 <body onLoad="$onload">
294 <form method=post action=gl.pl>
296 <input type=hidden name=sort value=transdate>
300 <th class=listtop>$form->{title}</th>
307 <th align=right>| . $locale->text('Reference') . qq|</th>
308 <td><input name=reference size=20></td>
309 <th align=right>| . $locale->text('Source') . qq|</th>
310 <td><input name=source size=20></td>
314 <th align=right>| . $locale->text('Description') . qq|</th>
315 <td colspan=3><input name=description size=40></td>
318 <th align=right>| . $locale->text('Notes') . qq|</th>
319 <td colspan=3><input name=notes size=40></td>
322 <th align=right>| . $locale->text('Project Number') . qq|</th>
323 <td colspan=3>$projectnumber</td>
326 <th align=right>| . $locale->text('From') . qq|</th>
328 <th align=right>| . $locale->text('To (time)') . qq|</th>
332 <th align=right>| . $locale->text('Include in Report') . qq|</th>
337 <input name="category" class=radio type=radio value=X checked> |
338 . $locale->text('All') . qq|
339 <input name="category" class=radio type=radio value=A> |
340 . $locale->text('Asset') . qq|
341 <input name="category" class=radio type=radio value=L> |
342 . $locale->text('Liability') . qq|
343 <input name="category" class=radio type=radio value=I> |
344 . $locale->text('Revenue') . qq|
345 <input name="category" class=radio type=radio value=E> |
346 . $locale->text('Expense') . qq|
352 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
353 <td>| . $locale->text('ID') . qq|</td>
354 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
355 <td>| . $locale->text('Date') . qq|</td>
356 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
357 <td>| . $locale->text('Reference') . qq|</td>
358 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
359 <td>| . $locale->text('Description') . qq|</td>
360 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
361 <td>| . $locale->text('Notes') . qq|</td>
364 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
365 <td>| . $locale->text('Debit') . qq|</td>
366 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
367 <td>| . $locale->text('Credit') . qq|</td>
368 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
369 <td>| . $locale->text('Source') . qq|</td>
370 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
371 <td>| . $locale->text('Account') . qq|</td>
374 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
375 <td>| . $locale->text('Subtotal') . qq|</td>
376 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
377 <td>| . $locale->text('Project Number') . qq|</td>
387 <td><hr size=3 noshade></td>
393 <input type=hidden name=nextsub value=generate_report>
396 <input class=submit type=submit name=action value="|
397 . $locale->text('Continue') . qq|">
403 $lxdebug->leave_sub();
406 sub create_subtotal_row {
407 $lxdebug->enter_sub();
409 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
411 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
413 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
415 map { $totals->{$_} = 0 } @{ $subtotal_columns };
417 $lxdebug->leave_sub();
422 sub generate_report {
423 $lxdebug->enter_sub();
425 $auth->assert('general_ledger');
427 report_generator_set_default_sort('transdate', 1);
429 GL->all_transactions(\%myconfig, \%$form);
431 my %acctype = ('A' => $locale->text('Asset'),
432 'C' => $locale->text('Contra'),
433 'L' => $locale->text('Liability'),
434 'Q' => $locale->text('Equity'),
435 'I' => $locale->text('Revenue'),
436 'E' => $locale->text('Expense'),);
438 $form->{title} = $locale->text('Journal');
439 if ($form->{category} ne 'X') {
440 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
443 $form->{landscape} = 1;
445 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
448 transdate id reference description
449 notes source debit debit_accno
450 credit credit_accno debit_tax debit_tax_accno
451 credit_tax credit_tax_accno projectnumbers balance
454 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
455 push @hidden_variables, map { "l_${_}" } @columns;
457 my (@options, @date_options);
458 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
459 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
460 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
461 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
462 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
464 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
465 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
466 push @options, join(' ', @date_options) if (scalar @date_options);
468 if ($form->{department}) {
469 my ($department) = split /--/, $form->{department};
470 push @options, $locale->text('Department') . " : $department";
474 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
476 $form->{l_credit_accno} = 'Y';
477 $form->{l_debit_accno} = 'Y';
478 $form->{l_credit_tax} = 'Y';
479 $form->{l_debit_tax} = 'Y';
480 $form->{l_credit_tax_accno} = 'Y';
481 $form->{l_debit_tax_accno} = 'Y';
482 $form->{l_balance} = $form->{accno} ? 'Y' : '';
485 'id' => { 'text' => $locale->text('ID'), },
486 'transdate' => { 'text' => $locale->text('Date'), },
487 'reference' => { 'text' => $locale->text('Reference'), },
488 'source' => { 'text' => $locale->text('Source'), },
489 'description' => { 'text' => $locale->text('Description'), },
490 'notes' => { 'text' => $locale->text('Notes'), },
491 'debit' => { 'text' => $locale->text('Debit'), },
492 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
493 'credit' => { 'text' => $locale->text('Credit'), },
494 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
495 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
496 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
497 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
498 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
499 'balance' => { 'text' => $locale->text('Balance'), },
500 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
503 foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
504 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
505 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
506 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
509 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
510 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
512 my %column_alignment;
513 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
514 map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
515 map { $column_alignment{$_} = 'left' } qw(description source notes);
516 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
518 my $report = SL::ReportGenerator->new(\%myconfig, $form);
520 $report->set_columns(%column_defs);
521 $report->set_column_order(@columns);
523 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
525 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
527 $report->set_options('top_info_text' => join("\n", @options),
528 'output_format' => 'HTML',
529 'title' => $form->{title},
530 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
532 $report->set_options_from_form();
534 # add sort to callback
535 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
538 my @totals_columns = qw(debit credit debit_tax credit_tax);
539 my %subtotals = map { $_ => 0 } @totals_columns;
540 my %totals = map { $_ => 0 } @totals_columns;
543 foreach $ref (@{ $form->{GL} }) {
547 foreach my $key (qw(debit credit debit_tax credit_tax)) {
549 foreach my $idx (sort keys(%{ $ref->{$key} })) {
550 my $value = $ref->{$key}->{$idx};
551 $subtotals{$key} += $value;
552 $totals{$key} += $value;
553 if ($key =~ /debit.*/) {
558 $form->{balance} = $form->{balance} + $value * $ml;
559 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
563 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
564 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
565 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
569 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
572 if ($form->{balance} < 0) {
575 } elsif ($form->{balance} > 0) {
579 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
582 $row->{balance}->{data} = $data;
583 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
585 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
587 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
589 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
590 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
593 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
595 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
597 my $row_set = [ $row ];
599 if (($form->{l_subtotal} eq 'Y')
600 && (($idx == (scalar @{ $form->{GL} } - 1))
601 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
602 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
605 $report->add_data($row_set);
610 $report->add_separator();
612 # = 0 for balanced ledger
613 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
615 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
618 if ($form->{balance} < 0) {
621 } elsif ($form->{balance} > 0) {
625 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
628 $row->{balance}->{data} = $data;
630 $report->add_data($row);
632 my $raw_bottom_info_text;
634 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
635 $raw_bottom_info_text .=
636 '<p><span class="unbalanced_ledger">'
637 . $locale->text('Unbalanced Ledger')
639 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
643 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
645 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
647 $report->generate_with_headers();
649 $lxdebug->leave_sub();
653 $lxdebug->enter_sub();
655 $auth->assert('general_ledger');
657 $form->{oldtransdate} = $form->{transdate};
669 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
671 for my $i (1 .. $form->{rowcount}) {
673 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
674 for (qw(debit credit tax)) {
676 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
680 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
687 if (($debitcount >= 2) && ($creditcount == 2)) {
688 $form->{"credit_$i"} = 0;
689 $form->{"tax_$i"} = 0;
693 if (($creditcount >= 2) && ($debitcount == 2)) {
694 $form->{"debit_$i"} = 0;
695 $form->{"tax_$i"} = 0;
699 if (($creditcount == 1) && ($debitcount == 2)) {
702 if (($creditcount == 2) && ($debitcount == 1)) {
705 if ($debitcredit && $credittax) {
706 $form->{"taxchart_$i"} = "0--0.00";
708 if (!$debitcredit && $debittax) {
709 $form->{"taxchart_$i"} = "0--0.00";
712 ($form->{"debit_$i"} == 0)
713 ? $form->{"credit_$i"}
714 : $form->{"debit_$i"};
716 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
717 $form->{"taxchart_$i"} = "0--0.00";
718 $form->{"tax_$i"} = 0;
720 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
727 if ($form->{taxincluded}) {
728 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
730 $form->{"tax_$i"} = $amount * $rate;
733 $form->{"tax_$i"} = 0;
736 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
741 for $i (1 .. $count) {
743 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
746 for $i ($count + 1 .. $form->{rowcount}) {
747 for (@flds) { delete $form->{"${_}_$i"} }
750 $form->{rowcount} = $count + 1;
753 $lxdebug->leave_sub();
759 $lxdebug->enter_sub();
761 $auth->assert('general_ledger');
765 # for $i (1 .. $form->{rowcount}) {
766 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
767 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
771 &display_rows($init);
773 $lxdebug->leave_sub();
779 $lxdebug->enter_sub();
781 $auth->assert('general_ledger');
783 $form->{debit_1} = 0 if !$form->{"debit_1"};
784 $form->{totaldebit} = 0;
785 $form->{totalcredit} = 0;
787 my %project_labels = ();
788 my @project_values = ("");
789 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
790 push(@project_values, $item->{"id"});
791 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
794 my %chart_labels = ();
795 my @chart_values = ();
798 foreach my $item (@{ $form->{ALL_CHARTS} }) {
799 my $key = $item->{accno} . "--" . $item->{tax_id};
800 $taxchart_init = $item->{tax_id} unless (@chart_values);
801 push(@chart_values, $key);
802 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
803 $charts{$item->{accno}} = $item;
806 my %taxchart_labels = ();
807 my @taxchart_values = ();
809 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
810 my $key = $item->{id} . "--" . $item->{rate};
811 $taxchart_init = $key if ($taxchart_init == $item->{id});
812 push(@taxchart_values, $key);
813 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
814 $taxcharts{$item->{id}} = $item;
817 for $i (1 .. $form->{rowcount}) {
818 if ($form->{show_details}) {
820 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
822 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
825 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
827 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
830 my $selected_accno_full;
831 my ($accno_row) = split(/--/, $form->{"accno_$i"});
832 my $item = $charts{$accno_row};
833 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
835 my $selected_taxchart = $form->{"taxchart_$i"};
836 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
837 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
839 if ($previous_accno &&
840 ($previous_accno eq $selected_accno) &&
841 ($previous_tax_id ne $selected_tax_id)) {
842 my $item = $taxcharts{$selected_tax_id};
843 $selected_taxchart = "$item->{id}--$item->{rate}";
846 $selected_accno = '' if ($init);
847 $selected_taxchart ||= $taxchart_init;
850 NTI($cgi->popup_menu('-name' => "accno_$i",
852 '-onChange' => "setTaxkey($i)",
853 '-style' => 'width:200px',
854 '-values' => \@chart_values,
855 '-labels' => \%chart_labels,
856 '-default' => $selected_accno_full))
857 . $cgi->hidden('-name' => "previous_accno_$i",
858 '-default' => $selected_accno_full)
861 NTI($cgi->popup_menu('-name' => "taxchart_$i",
862 '-id' => "taxchart_$i",
863 '-style' => 'width:200px',
864 '-values' => \@taxchart_values,
865 '-labels' => \%taxchart_labels,
866 '-default' => $selected_taxchart))
870 if ($form->{transfer}) {
871 $fx_transaction = qq|
872 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
877 if ($form->{"debit_$i"} != 0) {
878 $form->{totaldebit} += $form->{"debit_$i"};
879 if (!$form->{taxincluded}) {
880 $form->{totaldebit} += $form->{"tax_$i"};
883 $form->{totalcredit} += $form->{"credit_$i"};
884 if (!$form->{taxincluded}) {
885 $form->{totalcredit} += $form->{"tax_$i"};
889 for (qw(debit credit tax)) {
892 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
896 if ($i < $form->{rowcount}) {
897 if ($form->{transfer}) {
898 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
899 $x = ($checked) ? "x" : "";
900 $fx_transaction = qq|
901 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
904 $form->hide_form("accno_$i");
907 if ($form->{transfer}) {
908 $fx_transaction = qq|
909 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
914 my $debitreadonly = "";
915 my $creditreadonly = "";
916 if ($i == $form->{rowcount}) {
918 $debitreadonly = "readonly";
919 } elsif ($creditlock) {
920 $creditreadonly = "readonly";
925 NTI($cgi->popup_menu('-name' => "project_id_$i",
926 '-values' => \@project_values,
927 '-labels' => \%project_labels,
928 '-default' => $form->{"project_id_$i"} ));
930 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
932 print qq|<tr valign=top>
934 <td id="chart_balance_$i" align="right"> </td>
936 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
937 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
938 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
941 if ($form->{show_details}) {
945 <td>$projectnumber</td>
955 $form->hide_form(qw(rowcount selectaccno));
957 $lxdebug->leave_sub();
963 $lxdebug->enter_sub();
965 $auth->assert('general_ledger');
967 my @old_project_ids = ();
968 map({ push(@old_project_ids, $form->{"project_id_$_"})
969 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
971 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
973 "old_id" => \@old_project_ids },
974 "charts" => { "key" => "ALL_CHARTS",
975 "transdate" => $form->{transdate} },
976 "taxcharts" => "ALL_TAXCHARTS");
978 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
980 $title = $form->{title};
981 $form->{title} = $locale->text("$title General Ledger Transaction");
982 $readonly = ($form->{id}) ? "readonly" : "";
984 $show_details_checked = "checked" if $form->{show_details};
986 $ob_transaction_checked = "checked" if $form->{ob_transaction};
987 $cb_transaction_checked = "checked" if $form->{cb_transaction};
989 # $locale->text('Add General Ledger Transaction')
990 # $locale->text('Edit General Ledger Transaction')
992 map { $form->{$_} =~ s/\"/"/g }
993 qw(reference description chart taxchart);
995 $form->{javascript} = qq|<script type="text/javascript">
997 function setTaxkey(row) {
998 var accno = document.getElementById('accno_' + row);
999 var taxkey = accno.options[accno.selectedIndex].value;
1000 var reg = /--([0-9]*)/;
1001 var found = reg.exec(taxkey);
1002 var index = found[1];
1003 index = parseInt(index);
1004 var tax = 'taxchart_' + row;
1005 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1006 var reg2 = new RegExp("^"+ index, "");
1007 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1008 document.getElementById(tax).options[i].selected = true;
1014 function copy_debit_to_credit() {
1015 var txt = document.getElementsByName('debit_1')[0].value;
1016 document.getElementsByName('credit_2')[0].value = txt;
1020 <script type="text/javascript" src="js/show_form_details.js"></script>
1021 <script type="text/javascript" src="js/jquery.js"></script>
1024 $form->{selectdepartment} =~ s/ selected//;
1025 $form->{selectdepartment} =~
1026 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1028 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
1030 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1033 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1036 $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1039 $taxincluded = "checked";
1044 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1045 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1046 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1048 | if $form->{selectdepartment};
1050 $form->{fokus} = "gl.reference";
1052 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1055 # use JavaScript Calendar or not
1056 $form->{jsscript} = 1;
1058 if ($form->{jsscript}) {
1060 # with JavaScript Calendar
1062 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1063 <input type=button name=transdate id="trigger1" value=|
1064 . $locale->text('button') . qq|></td>
1069 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1072 # without JavaScript Calendar
1074 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1077 $form->{previous_id} ||= "--";
1078 $form->{previous_gldate} ||= "--";
1080 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1085 <body onLoad="focus()">
1087 <script type="text/javascript" src="js/follow_up.js"></script>
1089 <form method=post name="gl" action=gl.pl>
1092 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1095 <input type=hidden name=title value="$title">
1097 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1098 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1099 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1100 <input type="hidden" name="follow_up_rowcount" value="1">
1104 <th class=listtop>$form->{title}</th>
1106 <tr height="5"></tr>
1111 <td colspan="6" align="left">|
1112 . $locale->text("Previous transnumber text")
1113 . " $form->{previous_id} "
1114 . $locale->text("Previous transdate text")
1115 . " $form->{previous_gldate}"
1119 <th align=right>| . $locale->text('Reference') . qq|</th>
1120 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1124 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1133 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1134 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1138 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1139 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1150 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1151 <td width=1%>$description</td>
1155 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1156 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1163 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1164 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1172 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1173 <td width=1%>$description</td>
1177 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1178 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1187 <tr><td colspan=4><table><tr>
1189 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1192 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1194 </tr></table></td></tr>
1196 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1197 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1204 <tr class=listheading>
1205 <th class=listheading style="width:15%">|
1206 . $locale->text('Account') . qq|</th>
1207 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1208 <th class=listheading style="width:10%">|
1209 . $locale->text('Debit') . qq|</th>
1210 <th class=listheading style="width:10%">|
1211 . $locale->text('Credit') . qq|</th>
1212 <th class=listheading style="width:10%">|
1213 . $locale->text('Tax') . qq|</th>
1214 <th class=listheading style="width:5%">|
1215 . $locale->text('Taxkey') . qq|</th>|;
1217 if ($form->{show_details}) {
1219 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1220 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1221 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1230 $lxdebug->leave_sub();
1235 $lxdebug->enter_sub();
1237 $auth->assert('general_ledger');
1239 my $follow_ups_block;
1241 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1243 if (@{ $follow_ups} ) {
1244 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1245 $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
1249 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1251 $decimalplaces = ($dec > 2) ? $dec : 2;
1252 $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1255 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1256 } qw(totaldebit totalcredit);
1259 <tr class=listtotal>
1260 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1261 <th align=right class=listtotal> $form->{totalcredit}</th>
1269 <input name=callback type=hidden value="$form->{callback}">
1276 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1277 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1281 if (!$form->{storno}) {
1282 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1285 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1286 if (!$form->{locked} && $radieren) {
1288 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1289 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1293 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1294 <input type="button" class="submit" onclick="follow_up_window()" value="|
1295 . $locale->text('Follow-Up')
1299 if ($form->{draft_id}) {
1300 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1302 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1303 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1308 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1309 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1310 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1311 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1312 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1321 $lxdebug->leave_sub();
1326 $lxdebug->enter_sub();
1333 <form method=post action=gl.pl>
1336 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1338 delete $form->{header};
1340 foreach $key (keys %$form) {
1341 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1342 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1346 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1349 . $locale->text('Are you sure you want to delete Transaction')
1350 . qq| $form->{reference}</h4>
1352 <input name=action class=submit type=submit value="|
1353 . $locale->text('Yes') . qq|">
1356 $lxdebug->leave_sub();
1361 $lxdebug->enter_sub();
1362 if (GL->delete_transaction(\%myconfig, \%$form)){
1363 # saving the history
1364 if(!exists $form->{addition} && $form->{id} ne "") {
1365 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1366 $form->{addition} = "DELETED";
1367 $form->save_history($form->dbconnect(\%myconfig));
1369 # /saving the history
1370 $form->redirect($locale->text('Transaction deleted!'))
1372 $form->error($locale->text('Cannot delete transaction!'));
1373 $lxdebug->leave_sub();
1377 sub post_transaction {
1378 $lxdebug->enter_sub();
1380 # check if there is something in reference and date
1381 $form->isblank("reference", $locale->text('Reference missing!'));
1382 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1383 $form->isblank("description", $locale->text('Description missing!'));
1385 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1386 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1393 my $creditcount = 0;
1397 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1399 for my $i (1 .. $form->{rowcount}) {
1400 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1402 for (qw(debit credit tax)) {
1403 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1407 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1415 if (($debitcount >= 2) && ($creditcount == 2)) {
1416 $form->{"credit_$i"} = 0;
1417 $form->{"tax_$i"} = 0;
1421 if (($creditcount >= 2) && ($debitcount == 2)) {
1422 $form->{"debit_$i"} = 0;
1423 $form->{"tax_$i"} = 0;
1427 if (($creditcount == 1) && ($debitcount == 2)) {
1430 if (($creditcount == 2) && ($debitcount == 1)) {
1433 if ($debitcredit && $credittax) {
1434 $form->{"taxchart_$i"} = "0--0.00";
1436 if (!$debitcredit && $debittax) {
1437 $form->{"taxchart_$i"} = "0--0.00";
1439 $amount = ($form->{"debit_$i"} == 0)
1440 ? $form->{"credit_$i"}
1441 : $form->{"debit_$i"};
1443 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1444 $form->{"taxchart_$i"} = "0--0.00";
1445 $form->{"tax_$i"} = 0;
1447 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1454 if ($form->{taxincluded}) {
1455 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1457 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1459 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1462 $form->{"tax_$i"} = $amount * $rate;
1465 $form->{"tax_$i"} = 0;
1468 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1472 for $i (1 .. $count) {
1474 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1477 for $i ($count + 1 .. $form->{rowcount}) {
1478 for (@flds) { delete $form->{"${_}_$i"} }
1481 for $i (1 .. $form->{rowcount}) {
1482 $dr = $form->{"debit_$i"};
1483 $cr = $form->{"credit_$i"};
1484 $tax = $form->{"tax_$i"};
1486 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1488 $debit += $dr + $tax if $dr;
1489 $credit += $cr + $tax if $cr;
1490 $taxtotal += $tax if $form->{taxincluded}
1493 $form->{taxincluded} = 0 if !$taxtotal;
1495 # this is just for the wise guys
1496 $form->error($locale->text('Cannot post transaction for a closed period!'))
1497 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1498 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1499 $form->error($locale->text('Out of balance transaction!'));
1502 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1503 $form->error($locale->text('Empty transaction!'));
1506 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1508 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1509 $err[2] = $locale->text('Debit and credit out of balance!');
1510 $err[3] = $locale->text('Cannot post a transaction without a value!');
1512 $form->error($err[$errno]);
1514 undef($form->{callback});
1515 # saving the history
1516 if(!exists $form->{addition} && $form->{id} ne "") {
1517 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1518 $form->{addition} = "SAVED";
1519 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1520 $form->save_history($form->dbconnect(\%myconfig));
1522 # /saving the history
1524 $lxdebug->leave_sub();
1528 $lxdebug->enter_sub();
1530 $auth->assert('general_ledger');
1532 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1533 $form->{storno} = 0;
1537 remove_draft() if $form->{remove_draft};
1539 $form->{callback} = build_std_url("action=add", "show_details");
1540 $form->redirect($form->{callback});
1542 $lxdebug->leave_sub();
1546 $lxdebug->enter_sub();
1548 $auth->assert('general_ledger');
1552 $lxdebug->leave_sub();
1557 $lxdebug->enter_sub();
1559 $auth->assert('general_ledger');
1561 # don't cancel cancelled transactions
1562 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1563 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1564 $form->error($locale->text("Transaction has already been cancelled!"));
1567 GL->storno($form, \%myconfig, $form->{id});
1569 # saving the history
1570 if(!exists $form->{addition} && $form->{id} ne "") {
1571 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1572 $form->{addition} = "STORNO";
1573 $form->save_history($form->dbconnect(\%myconfig));
1575 # /saving the history
1577 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1579 $lxdebug->leave_sub();
1583 call_sub($form->{nextsub});