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(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno);
515 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
517 my $report = SL::ReportGenerator->new(\%myconfig, $form);
519 $report->set_columns(%column_defs);
520 $report->set_column_order(@columns);
522 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
524 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
526 $report->set_options('top_info_text' => join("\n", @options),
527 'output_format' => 'HTML',
528 'title' => $form->{title},
529 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
531 $report->set_options_from_form();
533 # add sort to callback
534 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
537 my @totals_columns = qw(debit credit debit_tax credit_tax);
538 my %subtotals = map { $_ => 0 } @totals_columns;
539 my %totals = map { $_ => 0 } @totals_columns;
542 foreach $ref (@{ $form->{GL} }) {
546 foreach my $key (qw(debit credit debit_tax credit_tax)) {
548 foreach my $idx (sort keys(%{ $ref->{$key} })) {
549 my $value = $ref->{$key}->{$idx};
550 $subtotals{$key} += $value;
551 $totals{$key} += $value;
552 if ($key =~ /debit.*/) {
557 $form->{balance} = $form->{balance} + $value * $ml;
558 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
562 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
563 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
564 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
568 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
571 if ($form->{balance} < 0) {
574 } elsif ($form->{balance} > 0) {
578 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
581 $row->{balance}->{data} = $data;
582 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
584 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
586 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
588 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
589 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
592 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
594 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
596 my $row_set = [ $row ];
598 if (($form->{l_subtotal} eq 'Y')
599 && (($idx == (scalar @{ $form->{GL} } - 1))
600 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
601 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
604 $report->add_data($row_set);
609 $report->add_separator();
611 # = 0 for balanced ledger
612 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
614 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
617 if ($form->{balance} < 0) {
620 } elsif ($form->{balance} > 0) {
624 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
627 $row->{balance}->{data} = $data;
629 $report->add_data($row);
631 my $raw_bottom_info_text;
633 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
634 $raw_bottom_info_text .=
635 '<p><span class="unbalanced_ledger">'
636 . $locale->text('Unbalanced Ledger')
638 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
642 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
644 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
646 $report->generate_with_headers();
648 $lxdebug->leave_sub();
652 $lxdebug->enter_sub();
654 $auth->assert('general_ledger');
656 $form->{oldtransdate} = $form->{transdate};
668 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
670 for my $i (1 .. $form->{rowcount}) {
672 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
673 for (qw(debit credit tax)) {
675 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
679 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
686 if (($debitcount >= 2) && ($creditcount == 2)) {
687 $form->{"credit_$i"} = 0;
688 $form->{"tax_$i"} = 0;
692 if (($creditcount >= 2) && ($debitcount == 2)) {
693 $form->{"debit_$i"} = 0;
694 $form->{"tax_$i"} = 0;
698 if (($creditcount == 1) && ($debitcount == 2)) {
701 if (($creditcount == 2) && ($debitcount == 1)) {
704 if ($debitcredit && $credittax) {
705 $form->{"taxchart_$i"} = "0--0.00";
707 if (!$debitcredit && $debittax) {
708 $form->{"taxchart_$i"} = "0--0.00";
711 ($form->{"debit_$i"} == 0)
712 ? $form->{"credit_$i"}
713 : $form->{"debit_$i"};
715 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
716 $form->{"taxchart_$i"} = "0--0.00";
717 $form->{"tax_$i"} = 0;
719 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
726 if ($form->{taxincluded}) {
727 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
729 $form->{"tax_$i"} = $amount * $rate;
732 $form->{"tax_$i"} = 0;
735 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
740 for $i (1 .. $count) {
742 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
745 for $i ($count + 1 .. $form->{rowcount}) {
746 for (@flds) { delete $form->{"${_}_$i"} }
749 $form->{rowcount} = $count + 1;
752 $lxdebug->leave_sub();
758 $lxdebug->enter_sub();
760 $auth->assert('general_ledger');
764 # for $i (1 .. $form->{rowcount}) {
765 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
766 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
770 &display_rows($init);
772 $lxdebug->leave_sub();
778 $lxdebug->enter_sub();
780 $auth->assert('general_ledger');
782 $form->{debit_1} = 0 if !$form->{"debit_1"};
783 $form->{totaldebit} = 0;
784 $form->{totalcredit} = 0;
786 my %project_labels = ();
787 my @project_values = ("");
788 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
789 push(@project_values, $item->{"id"});
790 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
793 my %chart_labels = ();
794 my @chart_values = ();
797 foreach my $item (@{ $form->{ALL_CHARTS} }) {
798 my $key = $item->{accno} . "--" . $item->{tax_id};
799 $taxchart_init = $item->{tax_id} unless (@chart_values);
800 push(@chart_values, $key);
801 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
802 $charts{$item->{accno}} = $item;
805 my %taxchart_labels = ();
806 my @taxchart_values = ();
808 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
809 my $key = $item->{id} . "--" . $item->{rate};
810 $taxchart_init = $key if ($taxchart_init == $item->{id});
811 push(@taxchart_values, $key);
812 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
813 $taxcharts{$item->{id}} = $item;
816 for $i (1 .. $form->{rowcount}) {
817 if ($form->{show_details}) {
819 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
821 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
824 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
826 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
829 my $selected_accno_full;
830 my ($accno_row) = split(/--/, $form->{"accno_$i"});
831 my $item = $charts{$accno_row};
832 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
834 my $selected_taxchart = $form->{"taxchart_$i"};
835 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
836 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
838 if ($previous_accno &&
839 ($previous_accno eq $selected_accno) &&
840 ($previous_tax_id ne $selected_tax_id)) {
841 my $item = $taxcharts{$selected_tax_id};
842 $selected_taxchart = "$item->{id}--$item->{rate}";
845 $selected_accno = '' if ($init);
846 $selected_taxchart ||= $taxchart_init;
849 NTI($cgi->popup_menu('-name' => "accno_$i",
851 '-onChange' => "setTaxkey($i)",
852 '-style' => 'width:200px',
853 '-values' => \@chart_values,
854 '-labels' => \%chart_labels,
855 '-default' => $selected_accno_full))
856 . $cgi->hidden('-name' => "previous_accno_$i",
857 '-default' => $selected_accno_full)
860 NTI($cgi->popup_menu('-name' => "taxchart_$i",
861 '-id' => "taxchart_$i",
862 '-style' => 'width:200px',
863 '-values' => \@taxchart_values,
864 '-labels' => \%taxchart_labels,
865 '-default' => $selected_taxchart))
869 if ($form->{transfer}) {
870 $fx_transaction = qq|
871 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
876 if ($form->{"debit_$i"} != 0) {
877 $form->{totaldebit} += $form->{"debit_$i"};
878 if (!$form->{taxincluded}) {
879 $form->{totaldebit} += $form->{"tax_$i"};
882 $form->{totalcredit} += $form->{"credit_$i"};
883 if (!$form->{taxincluded}) {
884 $form->{totalcredit} += $form->{"tax_$i"};
888 for (qw(debit credit tax)) {
891 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
895 if ($i < $form->{rowcount}) {
896 if ($form->{transfer}) {
897 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
898 $x = ($checked) ? "x" : "";
899 $fx_transaction = qq|
900 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
903 $form->hide_form("accno_$i");
906 if ($form->{transfer}) {
907 $fx_transaction = qq|
908 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
913 my $debitreadonly = "";
914 my $creditreadonly = "";
915 if ($i == $form->{rowcount}) {
917 $debitreadonly = "readonly";
918 } elsif ($creditlock) {
919 $creditreadonly = "readonly";
924 NTI($cgi->popup_menu('-name' => "project_id_$i",
925 '-values' => \@project_values,
926 '-labels' => \%project_labels,
927 '-default' => $form->{"project_id_$i"} ));
929 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
931 print qq|<tr valign=top>
933 <td id="chart_balance_$i" align="right"> </td>
935 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
936 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
937 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
940 if ($form->{show_details}) {
944 <td>$projectnumber</td>
954 $form->hide_form(qw(rowcount selectaccno));
956 $lxdebug->leave_sub();
962 $lxdebug->enter_sub();
964 $auth->assert('general_ledger');
966 my @old_project_ids = ();
967 map({ push(@old_project_ids, $form->{"project_id_$_"})
968 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
970 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
972 "old_id" => \@old_project_ids },
973 "charts" => { "key" => "ALL_CHARTS",
974 "transdate" => $form->{transdate} },
975 "taxcharts" => "ALL_TAXCHARTS");
977 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
979 $title = $form->{title};
980 $form->{title} = $locale->text("$title General Ledger Transaction");
981 $readonly = ($form->{id}) ? "readonly" : "";
983 $show_details_checked = "checked" if $form->{show_details};
985 $ob_transaction_checked = "checked" if $form->{ob_transaction};
986 $cb_transaction_checked = "checked" if $form->{cb_transaction};
988 # $locale->text('Add General Ledger Transaction')
989 # $locale->text('Edit General Ledger Transaction')
991 map { $form->{$_} =~ s/\"/"/g }
992 qw(reference description chart taxchart);
994 $form->{javascript} = qq|<script type="text/javascript">
996 function setTaxkey(row) {
997 var accno = document.getElementById('accno_' + row);
998 var taxkey = accno.options[accno.selectedIndex].value;
999 var reg = /--([0-9]*)/;
1000 var found = reg.exec(taxkey);
1001 var index = found[1];
1002 index = parseInt(index);
1003 var tax = 'taxchart_' + row;
1004 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1005 var reg2 = new RegExp("^"+ index, "");
1006 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1007 document.getElementById(tax).options[i].selected = true;
1013 function copy_debit_to_credit() {
1014 var txt = document.getElementsByName('debit_1')[0].value;
1015 document.getElementsByName('credit_2')[0].value = txt;
1019 <script type="text/javascript" src="js/show_form_details.js"></script>
1020 <script type="text/javascript" src="js/jquery.js"></script>
1023 $form->{selectdepartment} =~ s/ selected//;
1024 $form->{selectdepartment} =~
1025 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1027 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
1029 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1032 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1035 $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1038 $taxincluded = "checked";
1043 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1044 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1045 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1047 | if $form->{selectdepartment};
1049 $form->{fokus} = "gl.reference";
1051 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1054 # use JavaScript Calendar or not
1055 $form->{jsscript} = 1;
1057 if ($form->{jsscript}) {
1059 # with JavaScript Calendar
1061 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1062 <input type=button name=transdate id="trigger1" value=|
1063 . $locale->text('button') . qq|></td>
1068 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1071 # without JavaScript Calendar
1073 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1076 $form->{previous_id} ||= "--";
1077 $form->{previous_gldate} ||= "--";
1079 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1084 <body onLoad="focus()">
1086 <script type="text/javascript" src="js/follow_up.js"></script>
1088 <form method=post name="gl" action=gl.pl>
1091 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1094 <input type=hidden name=title value="$title">
1096 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1097 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1098 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1099 <input type="hidden" name="follow_up_rowcount" value="1">
1103 <th class=listtop>$form->{title}</th>
1105 <tr height="5"></tr>
1110 <td colspan="6" align="left">|
1111 . $locale->text("Previous transnumber text")
1112 . " $form->{previous_id} "
1113 . $locale->text("Previous transdate text")
1114 . " $form->{previous_gldate}"
1118 <th align=right>| . $locale->text('Reference') . qq|</th>
1119 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1123 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1132 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1133 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1137 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1138 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1149 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1150 <td width=1%>$description</td>
1154 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1155 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1162 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1163 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1171 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1172 <td width=1%>$description</td>
1176 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1177 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1186 <tr><td colspan=4><table><tr>
1188 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1191 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1193 </tr></table></td></tr>
1195 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1196 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1203 <tr class=listheading>
1204 <th class=listheading style="width:15%">|
1205 . $locale->text('Account') . qq|</th>
1206 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1207 <th class=listheading style="width:10%">|
1208 . $locale->text('Debit') . qq|</th>
1209 <th class=listheading style="width:10%">|
1210 . $locale->text('Credit') . qq|</th>
1211 <th class=listheading style="width:10%">|
1212 . $locale->text('Tax') . qq|</th>
1213 <th class=listheading style="width:5%">|
1214 . $locale->text('Taxkey') . qq|</th>|;
1216 if ($form->{show_details}) {
1218 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1219 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1220 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1229 $lxdebug->leave_sub();
1234 $lxdebug->enter_sub();
1236 $auth->assert('general_ledger');
1238 my $follow_ups_block;
1240 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1242 if (@{ $follow_ups} ) {
1243 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1244 $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>|;
1248 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1250 $decimalplaces = ($dec > 2) ? $dec : 2;
1251 $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1254 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1255 } qw(totaldebit totalcredit);
1258 <tr class=listtotal>
1259 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1260 <th align=right class=listtotal> $form->{totalcredit}</th>
1268 <input name=callback type=hidden value="$form->{callback}">
1275 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1276 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1280 if (!$form->{storno}) {
1281 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1284 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1285 if (!$form->{locked} && $radieren) {
1287 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1288 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1292 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1293 <input type="button" class="submit" onclick="follow_up_window()" value="|
1294 . $locale->text('Follow-Up')
1298 if ($form->{draft_id}) {
1299 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1301 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1302 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1307 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1308 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1309 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1310 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1311 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1320 $lxdebug->leave_sub();
1325 $lxdebug->enter_sub();
1332 <form method=post action=gl.pl>
1335 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1337 delete $form->{header};
1339 foreach $key (keys %$form) {
1340 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1341 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1345 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1348 . $locale->text('Are you sure you want to delete Transaction')
1349 . qq| $form->{reference}</h4>
1351 <input name=action class=submit type=submit value="|
1352 . $locale->text('Yes') . qq|">
1355 $lxdebug->leave_sub();
1360 $lxdebug->enter_sub();
1361 if (GL->delete_transaction(\%myconfig, \%$form)){
1362 # saving the history
1363 if(!exists $form->{addition} && $form->{id} ne "") {
1364 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1365 $form->{addition} = "DELETED";
1366 $form->save_history($form->dbconnect(\%myconfig));
1368 # /saving the history
1369 $form->redirect($locale->text('Transaction deleted!'))
1371 $form->error($locale->text('Cannot delete transaction!'));
1372 $lxdebug->leave_sub();
1376 sub post_transaction {
1377 $lxdebug->enter_sub();
1379 # check if there is something in reference and date
1380 $form->isblank("reference", $locale->text('Reference missing!'));
1381 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1382 $form->isblank("description", $locale->text('Description missing!'));
1384 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1385 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1392 my $creditcount = 0;
1396 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1398 for my $i (1 .. $form->{rowcount}) {
1399 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1401 for (qw(debit credit tax)) {
1402 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1406 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1414 if (($debitcount >= 2) && ($creditcount == 2)) {
1415 $form->{"credit_$i"} = 0;
1416 $form->{"tax_$i"} = 0;
1420 if (($creditcount >= 2) && ($debitcount == 2)) {
1421 $form->{"debit_$i"} = 0;
1422 $form->{"tax_$i"} = 0;
1426 if (($creditcount == 1) && ($debitcount == 2)) {
1429 if (($creditcount == 2) && ($debitcount == 1)) {
1432 if ($debitcredit && $credittax) {
1433 $form->{"taxchart_$i"} = "0--0.00";
1435 if (!$debitcredit && $debittax) {
1436 $form->{"taxchart_$i"} = "0--0.00";
1438 $amount = ($form->{"debit_$i"} == 0)
1439 ? $form->{"credit_$i"}
1440 : $form->{"debit_$i"};
1442 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1443 $form->{"taxchart_$i"} = "0--0.00";
1444 $form->{"tax_$i"} = 0;
1446 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1453 if ($form->{taxincluded}) {
1454 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1456 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1458 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1461 $form->{"tax_$i"} = $amount * $rate;
1464 $form->{"tax_$i"} = 0;
1467 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1471 for $i (1 .. $count) {
1473 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1476 for $i ($count + 1 .. $form->{rowcount}) {
1477 for (@flds) { delete $form->{"${_}_$i"} }
1480 for $i (1 .. $form->{rowcount}) {
1481 $dr = $form->{"debit_$i"};
1482 $cr = $form->{"credit_$i"};
1483 $tax = $form->{"tax_$i"};
1485 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1487 $debit += $dr + $tax if $dr;
1488 $credit += $cr + $tax if $cr;
1489 $taxtotal += $tax if $form->{taxincluded}
1492 $form->{taxincluded} = 0 if !$taxtotal;
1494 # this is just for the wise guys
1495 $form->error($locale->text('Cannot post transaction for a closed period!'))
1496 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1497 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1498 $form->error($locale->text('Out of balance transaction!'));
1501 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1502 $form->error($locale->text('Empty transaction!'));
1505 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1507 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1508 $err[2] = $locale->text('Debit and credit out of balance!');
1509 $err[3] = $locale->text('Cannot post a transaction without a value!');
1511 $form->error($err[$errno]);
1513 undef($form->{callback});
1514 # saving the history
1515 if(!exists $form->{addition} && $form->{id} ne "") {
1516 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1517 $form->{addition} = "SAVED";
1518 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1519 $form->save_history($form->dbconnect(\%myconfig));
1521 # /saving the history
1523 $lxdebug->leave_sub();
1527 $lxdebug->enter_sub();
1529 $auth->assert('general_ledger');
1531 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1532 $form->{storno} = 0;
1536 remove_draft() if $form->{remove_draft};
1538 $form->{callback} = build_std_url("action=add", "show_details");
1539 $form->redirect($form->{callback});
1541 $lxdebug->leave_sub();
1545 $lxdebug->enter_sub();
1547 $auth->assert('general_ledger');
1551 $lxdebug->leave_sub();
1556 $lxdebug->enter_sub();
1558 $auth->assert('general_ledger');
1560 # don't cancel cancelled transactions
1561 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1562 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1563 $form->error($locale->text("Transaction has already been cancelled!"));
1566 GL->storno($form, \%myconfig, $form->{id});
1568 # saving the history
1569 if(!exists $form->{addition} && $form->{id} ne "") {
1570 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1571 $form->{addition} = "STORNO";
1572 $form->save_history($form->dbconnect(\%myconfig));
1574 # /saving the history
1576 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1578 $lxdebug->leave_sub();
1582 call_sub($form->{nextsub});