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 # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb
92 GL->transaction(\%myconfig, \%$form);
96 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
97 . ($_->{rate} * 100) . qq| %|
100 $form->{rowcount} = 2;
107 $form->all_departments(\%myconfig);
108 if (@{ $form->{all_departments} }) {
109 $form->{selectdepartment} = "<option>\n";
112 $form->{selectdepartment} .=
113 "<option>$_->{description}--$_->{id}\n"
114 } (@{ $form->{all_departments} });
117 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
120 $lxdebug->leave_sub();
124 sub prepare_transaction {
125 $lxdebug->enter_sub();
127 $auth->assert('general_ledger');
129 GL->transaction(\%myconfig, \%$form);
133 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
134 . ($_->{rate} * 100) . qq| %|
137 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
140 $form->all_departments(\%myconfig);
141 if (@{ $form->{all_departments} }) {
142 $form->{selectdepartment} = "<option>\n";
145 $form->{selectdepartment} .=
146 "<option>$_->{description}--$_->{id}\n"
147 } (@{ $form->{all_departments} });
153 foreach $ref (@{ $form->{GL} }) {
155 if ($tax && ($ref->{accno} eq $taxaccno)) {
156 $form->{"tax_$j"} = abs($ref->{amount});
157 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
158 if ($form->{taxincluded}) {
159 if ($ref->{amount} < 0) {
160 $form->{"debit_$j"} += $form->{"tax_$j"};
162 $form->{"credit_$j"} += $form->{"tax_$j"};
165 $form->{"project_id_$j"} = $ref->{project_id};
168 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
169 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
170 if ($ref->{amount} < 0) {
171 $form->{totaldebit} -= $ref->{amount};
172 $form->{"debit_$i"} = $ref->{amount} * -1;
174 $form->{totalcredit} += $ref->{amount};
175 $form->{"credit_$i"} = $ref->{amount};
177 $form->{"taxchart_$i"} = "0--0.00";
178 $form->{"project_id_$i"} = $ref->{project_id};
181 if ($ref->{taxaccno} && !$tax) {
182 $taxaccno = $ref->{taxaccno};
190 $form->{rowcount} = $i;
192 ($form->datetonum($form->{transdate}, \%myconfig) <=
193 $form->datetonum($form->{closedto}, \%myconfig));
195 $lxdebug->leave_sub();
199 $lxdebug->enter_sub();
201 $auth->assert('general_ledger');
203 prepare_transaction();
205 $form->{title} = "Edit";
207 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
213 $lxdebug->leave_sub();
218 $lxdebug->enter_sub();
220 $auth->assert('general_ledger');
222 $form->{title} = $locale->text('Journal');
224 $form->all_departments(\%myconfig);
227 if (@{ $form->{all_departments} }) {
228 $form->{selectdepartment} = "<option>\n";
231 $form->{selectdepartment} .=
232 "<option>$_->{description}--$_->{id}\n"
233 } (@{ $form->{all_departments} });
238 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
239 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
241 | if $form->{selectdepartment};
243 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
246 my %project_labels = ();
247 my @project_values = ("");
248 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
249 push(@project_values, $item->{"id"});
250 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
254 NTI($cgi->popup_menu('-name' => "project_id",
255 '-values' => \@project_values,
256 '-labels' => \%project_labels));
258 # use JavaScript Calendar or not
259 $form->{jsscript} = 1;
261 if ($form->{jsscript}) {
263 # with JavaScript Calendar
265 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
266 <input type=button name=datefrom id="trigger1" value=|
267 . $locale->text('button') . qq|></td>
270 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
271 <input type=button name=dateto id="trigger2" value=|
272 . $locale->text('button') . qq|></td>
277 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
278 "dateto", "BL", "trigger2");
281 # without JavaScript Calendar
283 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
285 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
287 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
289 $onload = qq|focus()|;
290 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
291 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
293 <body onLoad="$onload">
295 <form method=post action=gl.pl>
297 <input type=hidden name=sort value=transdate>
301 <th class=listtop>$form->{title}</th>
308 <th align=right>| . $locale->text('Reference') . qq|</th>
309 <td><input name=reference size=20></td>
310 <th align=right>| . $locale->text('Source') . qq|</th>
311 <td><input name=source size=20></td>
315 <th align=right>| . $locale->text('Description') . qq|</th>
316 <td colspan=3><input name=description size=40></td>
319 <th align=right>| . $locale->text('Notes') . qq|</th>
320 <td colspan=3><input name=notes size=40></td>
323 <th align=right>| . $locale->text('Project Number') . qq|</th>
324 <td colspan=3>$projectnumber</td>
327 <th align=right>| . $locale->text('From') . qq|</th>
329 <th align=right>| . $locale->text('To (time)') . qq|</th>
333 <th align=right>| . $locale->text('Include in Report') . qq|</th>
338 <input name="category" class=radio type=radio value=X checked> |
339 . $locale->text('All') . qq|
340 <input name="category" class=radio type=radio value=A> |
341 . $locale->text('Asset') . qq|
342 <input name="category" class=radio type=radio value=L> |
343 . $locale->text('Liability') . qq|
344 <input name="category" class=radio type=radio value=I> |
345 . $locale->text('Revenue') . qq|
346 <input name="category" class=radio type=radio value=E> |
347 . $locale->text('Expense') . qq|
353 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
354 <td>| . $locale->text('ID') . qq|</td>
355 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
356 <td>| . $locale->text('Date') . qq|</td>
357 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
358 <td>| . $locale->text('Reference') . qq|</td>
359 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
360 <td>| . $locale->text('Description') . qq|</td>
361 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
362 <td>| . $locale->text('Notes') . qq|</td>
365 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
366 <td>| . $locale->text('Debit') . qq|</td>
367 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
368 <td>| . $locale->text('Credit') . qq|</td>
369 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
370 <td>| . $locale->text('Source') . qq|</td>
371 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
372 <td>| . $locale->text('Account') . qq|</td>
375 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
376 <td>| . $locale->text('Subtotal') . qq|</td>
377 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
378 <td>| . $locale->text('Project Number') . qq|</td>
388 <td><hr size=3 noshade></td>
394 <input type=hidden name=nextsub value=generate_report>
397 <input class=submit type=submit name=action value="|
398 . $locale->text('Continue') . qq|">
404 $lxdebug->leave_sub();
407 sub create_subtotal_row {
408 $lxdebug->enter_sub();
410 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
412 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
414 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
416 map { $totals->{$_} = 0 } @{ $subtotal_columns };
418 $lxdebug->leave_sub();
423 sub generate_report {
424 $lxdebug->enter_sub();
426 $auth->assert('general_ledger');
428 report_generator_set_default_sort('transdate', 1);
430 GL->all_transactions(\%myconfig, \%$form);
432 my %acctype = ('A' => $locale->text('Asset'),
433 'C' => $locale->text('Contra'),
434 'L' => $locale->text('Liability'),
435 'Q' => $locale->text('Equity'),
436 'I' => $locale->text('Revenue'),
437 'E' => $locale->text('Expense'),);
439 $form->{title} = $locale->text('Journal');
440 if ($form->{category} ne 'X') {
441 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
444 $form->{landscape} = 1;
446 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
449 transdate id reference description
450 notes source debit debit_accno
451 credit credit_accno debit_tax debit_tax_accno
452 credit_tax credit_tax_accno projectnumbers balance
455 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
456 push @hidden_variables, map { "l_${_}" } @columns;
458 my (@options, @date_options);
459 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
460 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
461 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
462 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
463 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
465 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
466 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
467 push @options, join(' ', @date_options) if (scalar @date_options);
469 if ($form->{department}) {
470 my ($department) = split /--/, $form->{department};
471 push @options, $locale->text('Department') . " : $department";
475 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
477 $form->{l_credit_accno} = 'Y';
478 $form->{l_debit_accno} = 'Y';
479 $form->{l_credit_tax} = 'Y';
480 $form->{l_debit_tax} = 'Y';
481 $form->{l_credit_tax_accno} = 'Y';
482 $form->{l_debit_tax_accno} = 'Y';
483 $form->{l_balance} = $form->{accno} ? 'Y' : '';
486 'id' => { 'text' => $locale->text('ID'), },
487 'transdate' => { 'text' => $locale->text('Date'), },
488 'reference' => { 'text' => $locale->text('Reference'), },
489 'source' => { 'text' => $locale->text('Source'), },
490 'description' => { 'text' => $locale->text('Description'), },
491 'notes' => { 'text' => $locale->text('Notes'), },
492 'debit' => { 'text' => $locale->text('Debit'), },
493 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
494 'credit' => { 'text' => $locale->text('Credit'), },
495 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
496 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
497 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
498 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
499 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
500 'balance' => { 'text' => $locale->text('Balance'), },
501 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
504 foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
505 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
506 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
507 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
510 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
511 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
513 my %column_alignment;
514 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
515 map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
516 map { $column_alignment{$_} = 'left' } qw(description source notes);
517 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
519 my $report = SL::ReportGenerator->new(\%myconfig, $form);
521 $report->set_columns(%column_defs);
522 $report->set_column_order(@columns);
524 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
526 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
528 $report->set_options('top_info_text' => join("\n", @options),
529 'output_format' => 'HTML',
530 'title' => $form->{title},
531 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
533 $report->set_options_from_form();
535 # add sort to callback
536 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
539 my @totals_columns = qw(debit credit debit_tax credit_tax);
540 my %subtotals = map { $_ => 0 } @totals_columns;
541 my %totals = map { $_ => 0 } @totals_columns;
544 foreach $ref (@{ $form->{GL} }) {
548 foreach my $key (qw(debit credit debit_tax credit_tax)) {
550 foreach my $idx (sort keys(%{ $ref->{$key} })) {
551 my $value = $ref->{$key}->{$idx};
552 $subtotals{$key} += $value;
553 $totals{$key} += $value;
554 if ($key =~ /debit.*/) {
559 $form->{balance} = $form->{balance} + $value * $ml;
560 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
564 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
565 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
566 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
570 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
573 if ($form->{balance} < 0) {
576 } elsif ($form->{balance} > 0) {
580 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
583 $row->{balance}->{data} = $data;
584 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
586 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
588 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
590 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
591 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
594 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
596 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
598 my $row_set = [ $row ];
600 if (($form->{l_subtotal} eq 'Y')
601 && (($idx == (scalar @{ $form->{GL} } - 1))
602 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
603 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
606 $report->add_data($row_set);
611 $report->add_separator();
613 # = 0 for balanced ledger
614 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
616 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
619 if ($form->{balance} < 0) {
622 } elsif ($form->{balance} > 0) {
626 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
629 $row->{balance}->{data} = $data;
631 $report->add_data($row);
633 my $raw_bottom_info_text;
635 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
636 $raw_bottom_info_text .=
637 '<p><span class="unbalanced_ledger">'
638 . $locale->text('Unbalanced Ledger')
640 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
644 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
646 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
648 $report->generate_with_headers();
650 $lxdebug->leave_sub();
654 $lxdebug->enter_sub();
656 $auth->assert('general_ledger');
658 $form->{oldtransdate} = $form->{transdate};
670 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
672 for my $i (1 .. $form->{rowcount}) {
674 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
675 for (qw(debit credit tax)) {
677 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
681 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
688 if (($debitcount >= 2) && ($creditcount == 2)) {
689 $form->{"credit_$i"} = 0;
690 $form->{"tax_$i"} = 0;
694 if (($creditcount >= 2) && ($debitcount == 2)) {
695 $form->{"debit_$i"} = 0;
696 $form->{"tax_$i"} = 0;
700 if (($creditcount == 1) && ($debitcount == 2)) {
703 if (($creditcount == 2) && ($debitcount == 1)) {
706 if ($debitcredit && $credittax) {
707 $form->{"taxchart_$i"} = "0--0.00";
709 if (!$debitcredit && $debittax) {
710 $form->{"taxchart_$i"} = "0--0.00";
713 ($form->{"debit_$i"} == 0)
714 ? $form->{"credit_$i"}
715 : $form->{"debit_$i"};
717 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
718 $form->{"taxchart_$i"} = "0--0.00";
719 $form->{"tax_$i"} = 0;
721 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
728 if ($form->{taxincluded}) {
729 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
731 $form->{"tax_$i"} = $amount * $rate;
734 $form->{"tax_$i"} = 0;
737 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
742 for $i (1 .. $count) {
744 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
747 for $i ($count + 1 .. $form->{rowcount}) {
748 for (@flds) { delete $form->{"${_}_$i"} }
751 $form->{rowcount} = $count + 1;
754 $lxdebug->leave_sub();
760 $lxdebug->enter_sub();
762 $auth->assert('general_ledger');
766 # for $i (1 .. $form->{rowcount}) {
767 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
768 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
772 &display_rows($init);
774 $lxdebug->leave_sub();
780 $lxdebug->enter_sub();
782 $auth->assert('general_ledger');
784 $form->{debit_1} = 0 if !$form->{"debit_1"};
785 $form->{totaldebit} = 0;
786 $form->{totalcredit} = 0;
788 my %project_labels = ();
789 my @project_values = ("");
790 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
791 push(@project_values, $item->{"id"});
792 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
795 my %chart_labels = ();
796 my @chart_values = ();
799 foreach my $item (@{ $form->{ALL_CHARTS} }) {
800 if ($item->{charttype} eq 'H'){ #falls überschrift
801 next; #überspringen (Bug 1150)
803 my $key = $item->{accno} . "--" . $item->{tax_id};
804 $taxchart_init = $item->{tax_id} unless (@chart_values);
805 push(@chart_values, $key);
806 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
807 $charts{$item->{accno}} = $item;
810 my %taxchart_labels = ();
811 my @taxchart_values = ();
813 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
814 my $key = $item->{id} . "--" . $item->{rate};
815 $taxchart_init = $key if ($taxchart_init == $item->{id});
816 push(@taxchart_values, $key);
817 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
818 $taxcharts{$item->{id}} = $item;
821 for $i (1 .. $form->{rowcount}) {
822 if ($form->{show_details}) {
824 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
826 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
829 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
831 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
834 my $selected_accno_full;
835 my ($accno_row) = split(/--/, $form->{"accno_$i"});
836 my $item = $charts{$accno_row};
837 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
839 my $selected_taxchart = $form->{"taxchart_$i"};
840 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
841 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
843 if ($previous_accno &&
844 ($previous_accno eq $selected_accno) &&
845 ($previous_tax_id ne $selected_tax_id)) {
846 my $item = $taxcharts{$selected_tax_id};
847 $selected_taxchart = "$item->{id}--$item->{rate}";
850 $selected_accno = '' if ($init);
851 $selected_taxchart ||= $taxchart_init;
854 NTI($cgi->popup_menu('-name' => "accno_$i",
856 '-onChange' => "setTaxkey($i)",
857 '-style' => 'width:200px',
858 '-values' => \@chart_values,
859 '-labels' => \%chart_labels,
860 '-default' => $selected_accno_full))
861 . $cgi->hidden('-name' => "previous_accno_$i",
862 '-default' => $selected_accno_full)
865 NTI($cgi->popup_menu('-name' => "taxchart_$i",
866 '-id' => "taxchart_$i",
867 '-style' => 'width:200px',
868 '-values' => \@taxchart_values,
869 '-labels' => \%taxchart_labels,
870 '-default' => $selected_taxchart))
874 if ($form->{transfer}) {
875 $fx_transaction = qq|
876 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
881 if ($form->{"debit_$i"} != 0) {
882 $form->{totaldebit} += $form->{"debit_$i"};
883 if (!$form->{taxincluded}) {
884 $form->{totaldebit} += $form->{"tax_$i"};
887 $form->{totalcredit} += $form->{"credit_$i"};
888 if (!$form->{taxincluded}) {
889 $form->{totalcredit} += $form->{"tax_$i"};
893 for (qw(debit credit tax)) {
896 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
900 if ($i < $form->{rowcount}) {
901 if ($form->{transfer}) {
902 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
903 $x = ($checked) ? "x" : "";
904 $fx_transaction = qq|
905 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
908 $form->hide_form("accno_$i");
911 if ($form->{transfer}) {
912 $fx_transaction = qq|
913 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
918 my $debitreadonly = "";
919 my $creditreadonly = "";
920 if ($i == $form->{rowcount}) {
922 $debitreadonly = "readonly";
923 } elsif ($creditlock) {
924 $creditreadonly = "readonly";
929 NTI($cgi->popup_menu('-name' => "project_id_$i",
930 '-values' => \@project_values,
931 '-labels' => \%project_labels,
932 '-default' => $form->{"project_id_$i"} ));
934 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
936 print qq|<tr valign=top>
938 <td id="chart_balance_$i" align="right"> </td>
940 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
941 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
942 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
945 if ($form->{show_details}) {
949 <td>$projectnumber</td>
959 $form->hide_form(qw(rowcount selectaccno));
961 $lxdebug->leave_sub();
967 $lxdebug->enter_sub();
969 $auth->assert('general_ledger');
971 my @old_project_ids = ();
972 map({ push(@old_project_ids, $form->{"project_id_$_"})
973 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
975 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
977 "old_id" => \@old_project_ids },
978 "charts" => { "key" => "ALL_CHARTS",
979 "transdate" => $form->{transdate} },
980 "taxcharts" => "ALL_TAXCHARTS");
982 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
984 $title = $form->{title};
985 $form->{title} = $locale->text("$title General Ledger Transaction");
986 $readonly = ($form->{id}) ? "readonly" : "";
988 $show_details_checked = "checked" if $form->{show_details};
990 $ob_transaction_checked = "checked" if $form->{ob_transaction};
991 $cb_transaction_checked = "checked" if $form->{cb_transaction};
993 # $locale->text('Add General Ledger Transaction')
994 # $locale->text('Edit General Ledger Transaction')
996 map { $form->{$_} =~ s/\"/"/g }
997 qw(reference description chart taxchart);
999 $form->{javascript} = qq|<script type="text/javascript">
1001 function setTaxkey(row) {
1002 var accno = document.getElementById('accno_' + row);
1003 var taxkey = accno.options[accno.selectedIndex].value;
1004 var reg = /--([0-9]*)/;
1005 var found = reg.exec(taxkey);
1006 var index = found[1];
1007 index = parseInt(index);
1008 var tax = 'taxchart_' + row;
1009 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1010 var reg2 = new RegExp("^"+ index, "");
1011 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1012 document.getElementById(tax).options[i].selected = true;
1018 function copy_debit_to_credit() {
1019 var txt = document.getElementsByName('debit_1')[0].value;
1020 document.getElementsByName('credit_2')[0].value = txt;
1024 <script type="text/javascript" src="js/show_form_details.js"></script>
1025 <script type="text/javascript" src="js/jquery.js"></script>
1028 $form->{selectdepartment} =~ s/ selected//;
1029 $form->{selectdepartment} =~
1030 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1032 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
1034 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1037 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1040 $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1043 $taxincluded = "checked";
1048 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1049 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1050 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1052 | if $form->{selectdepartment};
1054 $form->{fokus} = "gl.reference";
1056 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1059 # use JavaScript Calendar or not
1060 $form->{jsscript} = 1;
1062 if ($form->{jsscript}) {
1064 # with JavaScript Calendar
1066 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1067 <input type=button name=transdate id="trigger1" value=|
1068 . $locale->text('button') . qq|></td>
1073 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1076 # without JavaScript Calendar
1078 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1081 $form->{previous_id} ||= "--";
1082 $form->{previous_gldate} ||= "--";
1084 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1089 <body onLoad="focus()">
1091 <script type="text/javascript" src="js/follow_up.js"></script>
1093 <form method=post name="gl" action=gl.pl>
1096 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1099 <input type=hidden name=title value="$title">
1101 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1102 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1103 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1104 <input type="hidden" name="follow_up_rowcount" value="1">
1108 <th class=listtop>$form->{title}</th>
1110 <tr height="5"></tr>
1115 <td colspan="6" align="left">|
1116 . $locale->text("Previous transnumber text")
1117 . " $form->{previous_id} "
1118 . $locale->text("Previous transdate text")
1119 . " $form->{previous_gldate}"
1123 <th align=right>| . $locale->text('Reference') . qq|</th>
1124 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1128 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1137 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1138 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1142 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1143 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1154 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1155 <td width=1%>$description</td>
1159 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1160 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1167 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1168 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1176 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1177 <td width=1%>$description</td>
1181 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1182 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1191 <tr><td colspan=4><table><tr>
1193 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1196 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1198 </tr></table></td></tr>
1200 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1201 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1208 <tr class=listheading>
1209 <th class=listheading style="width:15%">|
1210 . $locale->text('Account') . qq|</th>
1211 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1212 <th class=listheading style="width:10%">|
1213 . $locale->text('Debit') . qq|</th>
1214 <th class=listheading style="width:10%">|
1215 . $locale->text('Credit') . qq|</th>
1216 <th class=listheading style="width:10%">|
1217 . $locale->text('Tax') . qq|</th>
1218 <th class=listheading style="width:5%">|
1219 . $locale->text('Taxkey') . qq|</th>|;
1221 if ($form->{show_details}) {
1223 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1224 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1225 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1234 $lxdebug->leave_sub();
1239 $lxdebug->enter_sub();
1241 $auth->assert('general_ledger');
1243 my $follow_ups_block;
1245 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1247 if (@{ $follow_ups} ) {
1248 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1249 $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>|;
1253 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1255 $decimalplaces = ($dec > 2) ? $dec : 2;
1256 $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1259 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1260 } qw(totaldebit totalcredit);
1263 <tr class=listtotal>
1264 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1265 <th align=right class=listtotal> $form->{totalcredit}</th>
1273 <input name=callback type=hidden value="$form->{callback}">
1280 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1281 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1285 if (!$form->{storno}) {
1286 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1289 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1290 if (!$form->{locked} && $radieren) {
1292 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1293 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1297 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1298 <input type="button" class="submit" onclick="follow_up_window()" value="|
1299 . $locale->text('Follow-Up')
1303 if ($form->{draft_id}) {
1304 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1306 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1307 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1312 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1313 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1314 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1315 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1316 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1325 $lxdebug->leave_sub();
1330 $lxdebug->enter_sub();
1337 <form method=post action=gl.pl>
1340 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1342 delete $form->{header};
1344 foreach $key (keys %$form) {
1345 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1346 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1350 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1353 . $locale->text('Are you sure you want to delete Transaction')
1354 . qq| $form->{reference}</h4>
1356 <input name=action class=submit type=submit value="|
1357 . $locale->text('Yes') . qq|">
1360 $lxdebug->leave_sub();
1365 $lxdebug->enter_sub();
1366 if (GL->delete_transaction(\%myconfig, \%$form)){
1367 # saving the history
1368 if(!exists $form->{addition} && $form->{id} ne "") {
1369 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1370 $form->{addition} = "DELETED";
1371 $form->save_history($form->dbconnect(\%myconfig));
1373 # /saving the history
1374 $form->redirect($locale->text('Transaction deleted!'))
1376 $form->error($locale->text('Cannot delete transaction!'));
1377 $lxdebug->leave_sub();
1381 sub post_transaction {
1382 $lxdebug->enter_sub();
1384 # check if there is something in reference and date
1385 $form->isblank("reference", $locale->text('Reference missing!'));
1386 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1387 $form->isblank("description", $locale->text('Description missing!'));
1389 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1390 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1397 my $creditcount = 0;
1401 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1403 for my $i (1 .. $form->{rowcount}) {
1404 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1406 for (qw(debit credit tax)) {
1407 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1411 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1419 if (($debitcount >= 2) && ($creditcount == 2)) {
1420 $form->{"credit_$i"} = 0;
1421 $form->{"tax_$i"} = 0;
1425 if (($creditcount >= 2) && ($debitcount == 2)) {
1426 $form->{"debit_$i"} = 0;
1427 $form->{"tax_$i"} = 0;
1431 if (($creditcount == 1) && ($debitcount == 2)) {
1434 if (($creditcount == 2) && ($debitcount == 1)) {
1437 if ($debitcredit && $credittax) {
1438 $form->{"taxchart_$i"} = "0--0.00";
1440 if (!$debitcredit && $debittax) {
1441 $form->{"taxchart_$i"} = "0--0.00";
1443 $amount = ($form->{"debit_$i"} == 0)
1444 ? $form->{"credit_$i"}
1445 : $form->{"debit_$i"};
1447 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1448 $form->{"taxchart_$i"} = "0--0.00";
1449 $form->{"tax_$i"} = 0;
1451 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1458 if ($form->{taxincluded}) {
1459 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1461 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1463 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1466 $form->{"tax_$i"} = $amount * $rate;
1469 $form->{"tax_$i"} = 0;
1472 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1476 for $i (1 .. $count) {
1478 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1481 for $i ($count + 1 .. $form->{rowcount}) {
1482 for (@flds) { delete $form->{"${_}_$i"} }
1485 for $i (1 .. $form->{rowcount}) {
1486 $dr = $form->{"debit_$i"};
1487 $cr = $form->{"credit_$i"};
1488 $tax = $form->{"tax_$i"};
1490 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1492 $debit += $dr + $tax if $dr;
1493 $credit += $cr + $tax if $cr;
1494 $taxtotal += $tax if $form->{taxincluded}
1497 $form->{taxincluded} = 0 if !$taxtotal;
1499 # this is just for the wise guys
1500 $form->error($locale->text('Cannot post transaction for a closed period!'))
1501 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1502 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1503 $form->error($locale->text('Out of balance transaction!'));
1506 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1507 $form->error($locale->text('Empty transaction!'));
1510 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1512 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1513 $err[2] = $locale->text('Debit and credit out of balance!');
1514 $err[3] = $locale->text('Cannot post a transaction without a value!');
1516 $form->error($err[$errno]);
1518 undef($form->{callback});
1519 # saving the history
1520 if(!exists $form->{addition} && $form->{id} ne "") {
1521 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1522 $form->{addition} = "SAVED";
1523 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1524 $form->save_history($form->dbconnect(\%myconfig));
1526 # /saving the history
1528 $lxdebug->leave_sub();
1532 $lxdebug->enter_sub();
1534 $auth->assert('general_ledger');
1536 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1537 $form->{storno} = 0;
1541 remove_draft() if $form->{remove_draft};
1543 $form->{callback} = build_std_url("action=add", "show_details");
1544 $form->redirect($form->{callback});
1546 $lxdebug->leave_sub();
1550 $lxdebug->enter_sub();
1552 $auth->assert('general_ledger');
1556 $lxdebug->leave_sub();
1561 $lxdebug->enter_sub();
1563 $auth->assert('general_ledger');
1565 # don't cancel cancelled transactions
1566 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1567 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1568 $form->error($locale->text("Transaction has already been cancelled!"));
1571 GL->storno($form, \%myconfig, $form->{id});
1573 # saving the history
1574 if(!exists $form->{addition} && $form->{id} ne "") {
1575 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1576 $form->{addition} = "STORNO";
1577 $form->save_history($form->dbconnect(\%myconfig));
1579 # /saving the history
1581 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1583 $lxdebug->leave_sub();
1587 call_sub($form->{nextsub});