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/reportgenerator.pl";
50 # this is for our long dates
51 # $locale->text('January')
52 # $locale->text('February')
53 # $locale->text('March')
54 # $locale->text('April')
55 # $locale->text('May ')
56 # $locale->text('June')
57 # $locale->text('July')
58 # $locale->text('August')
59 # $locale->text('September')
60 # $locale->text('October')
61 # $locale->text('November')
62 # $locale->text('December')
64 # this is for our short month
65 # $locale->text('Jan')
66 # $locale->text('Feb')
67 # $locale->text('Mar')
68 # $locale->text('Apr')
69 # $locale->text('May')
70 # $locale->text('Jun')
71 # $locale->text('Jul')
72 # $locale->text('Aug')
73 # $locale->text('Sep')
74 # $locale->text('Oct')
75 # $locale->text('Nov')
76 # $locale->text('Dec')
79 $lxdebug->enter_sub();
81 $auth->assert('general_ledger');
83 $form->{title} = "Add";
85 $form->{callback} = "gl.pl?action=add" unless $form->{callback};
87 # we use this only to set a default date
88 GL->transaction(\%myconfig, \%$form);
92 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
93 . ($_->{rate} * 100) . qq| %|
96 $form->{rowcount} = 2;
103 $form->all_departments(\%myconfig);
104 if (@{ $form->{all_departments} }) {
105 $form->{selectdepartment} = "<option>\n";
108 $form->{selectdepartment} .=
109 "<option>$_->{description}--$_->{id}\n"
110 } (@{ $form->{all_departments} });
113 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
116 $lxdebug->leave_sub();
120 sub prepare_transaction {
121 $lxdebug->enter_sub();
123 $auth->assert('general_ledger');
125 GL->transaction(\%myconfig, \%$form);
129 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
130 . ($_->{rate} * 100) . qq| %|
133 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
136 $form->all_departments(\%myconfig);
137 if (@{ $form->{all_departments} }) {
138 $form->{selectdepartment} = "<option>\n";
141 $form->{selectdepartment} .=
142 "<option>$_->{description}--$_->{id}\n"
143 } (@{ $form->{all_departments} });
149 foreach $ref (@{ $form->{GL} }) {
151 if ($tax && ($ref->{accno} eq $taxaccno)) {
152 $form->{"tax_$j"} = abs($ref->{amount});
153 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
154 if ($form->{taxincluded}) {
155 if ($ref->{amount} < 0) {
156 $form->{"debit_$j"} += $form->{"tax_$j"};
158 $form->{"credit_$j"} += $form->{"tax_$j"};
161 $form->{"project_id_$j"} = $ref->{project_id};
164 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
165 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
166 if ($ref->{amount} < 0) {
167 $form->{totaldebit} -= $ref->{amount};
168 $form->{"debit_$i"} = $ref->{amount} * -1;
170 $form->{totalcredit} += $ref->{amount};
171 $form->{"credit_$i"} = $ref->{amount};
173 $form->{"taxchart_$i"} = "0--0.00";
174 $form->{"project_id_$i"} = $ref->{project_id};
177 if ($ref->{taxaccno} && !$tax) {
178 $taxaccno = $ref->{taxaccno};
186 $form->{rowcount} = $i;
188 ($form->datetonum($form->{transdate}, \%myconfig) <=
189 $form->datetonum($form->{closedto}, \%myconfig));
191 $lxdebug->leave_sub();
195 $lxdebug->enter_sub();
197 $auth->assert('general_ledger');
199 prepare_transaction();
201 $form->{title} = "Edit";
203 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
209 $lxdebug->leave_sub();
214 $lxdebug->enter_sub();
216 $auth->assert('general_ledger');
218 $form->{title} = $locale->text('Journal');
220 $form->all_departments(\%myconfig);
223 if (@{ $form->{all_departments} }) {
224 $form->{selectdepartment} = "<option>\n";
227 $form->{selectdepartment} .=
228 "<option>$_->{description}--$_->{id}\n"
229 } (@{ $form->{all_departments} });
234 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
235 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
237 | if $form->{selectdepartment};
239 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
242 my %project_labels = ();
243 my @project_values = ("");
244 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
245 push(@project_values, $item->{"id"});
246 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
250 NTI($cgi->popup_menu('-name' => "project_id",
251 '-values' => \@project_values,
252 '-labels' => \%project_labels));
254 # use JavaScript Calendar or not
255 $form->{jsscript} = 1;
257 if ($form->{jsscript}) {
259 # with JavaScript Calendar
261 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
262 <input type=button name=datefrom id="trigger1" value=|
263 . $locale->text('button') . qq|></td>
266 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
267 <input type=button name=dateto id="trigger2" value=|
268 . $locale->text('button') . qq|></td>
273 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
274 "dateto", "BL", "trigger2");
277 # without JavaScript Calendar
279 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
281 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
283 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
285 $onload = qq|focus()|;
286 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
287 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
289 <body onLoad="$onload">
291 <form method=post action=gl.pl>
293 <input type=hidden name=sort value=transdate>
297 <th class=listtop>$form->{title}</th>
304 <th align=right>| . $locale->text('Reference') . qq|</th>
305 <td><input name=reference size=20></td>
306 <th align=right>| . $locale->text('Source') . qq|</th>
307 <td><input name=source size=20></td>
311 <th align=right>| . $locale->text('Description') . qq|</th>
312 <td colspan=3><input name=description size=40></td>
315 <th align=right>| . $locale->text('Notes') . qq|</th>
316 <td colspan=3><input name=notes size=40></td>
319 <th align=right>| . $locale->text('Project Number') . qq|</th>
320 <td colspan=3>$projectnumber</td>
323 <th align=right>| . $locale->text('From') . qq|</th>
325 <th align=right>| . $locale->text('To (time)') . qq|</th>
329 <th align=right>| . $locale->text('Include in Report') . qq|</th>
334 <input name="category" class=radio type=radio value=X checked> |
335 . $locale->text('All') . qq|
336 <input name="category" class=radio type=radio value=A> |
337 . $locale->text('Asset') . qq|
338 <input name="category" class=radio type=radio value=L> |
339 . $locale->text('Liability') . qq|
340 <input name="category" class=radio type=radio value=I> |
341 . $locale->text('Revenue') . qq|
342 <input name="category" class=radio type=radio value=E> |
343 . $locale->text('Expense') . qq|
349 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
350 <td>| . $locale->text('ID') . qq|</td>
351 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
352 <td>| . $locale->text('Date') . qq|</td>
353 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
354 <td>| . $locale->text('Reference') . qq|</td>
355 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
356 <td>| . $locale->text('Description') . qq|</td>
357 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
358 <td>| . $locale->text('Notes') . qq|</td>
361 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
362 <td>| . $locale->text('Debit') . qq|</td>
363 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
364 <td>| . $locale->text('Credit') . qq|</td>
365 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
366 <td>| . $locale->text('Source') . qq|</td>
367 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
368 <td>| . $locale->text('Account') . qq|</td>
371 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
372 <td>| . $locale->text('Subtotal') . qq|</td>
373 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
374 <td>| . $locale->text('Project Number') . qq|</td>
384 <td><hr size=3 noshade></td>
390 <input type=hidden name=nextsub value=generate_report>
393 <input class=submit type=submit name=action value="|
394 . $locale->text('Continue') . qq|">
400 $lxdebug->leave_sub();
403 sub create_subtotal_row {
404 $lxdebug->enter_sub();
406 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
408 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
410 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
412 map { $totals->{$_} = 0 } @{ $subtotal_columns };
414 $lxdebug->leave_sub();
419 sub generate_report {
420 $lxdebug->enter_sub();
422 $auth->assert('general_ledger');
424 $form->{sort} ||= "transdate";
426 GL->all_transactions(\%myconfig, \%$form);
428 my %acctype = ('A' => $locale->text('Asset'),
429 'C' => $locale->text('Contra'),
430 'L' => $locale->text('Liability'),
431 'Q' => $locale->text('Equity'),
432 'I' => $locale->text('Revenue'),
433 'E' => $locale->text('Expense'),);
435 $form->{title} = $locale->text('Journal');
436 if ($form->{category} ne 'X') {
437 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
440 $form->{landscape} = 1;
442 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
445 transdate id reference description
446 notes source debit debit_accno
447 credit credit_accno debit_tax debit_tax_accno
448 credit_tax credit_tax_accno projectnumbers balance
451 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
452 push @hidden_variables, map { "l_${_}" } @columns;
454 my (@options, @date_options);
455 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
456 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
457 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
458 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
459 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
461 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
462 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
463 push @options, join(' ', @date_options) if (scalar @date_options);
465 if ($form->{department}) {
466 my ($department) = split /--/, $form->{department};
467 push @options, $locale->text('Department') . " : $department";
471 my $callback = build_std_url('action=generate_report', @hidden_variables);
473 $form->{l_credit_accno} = 'Y';
474 $form->{l_debit_accno} = 'Y';
475 $form->{l_credit_tax} = 'Y';
476 $form->{l_debit_tax} = 'Y';
477 $form->{l_credit_tax_accno} = 'Y';
478 $form->{l_debit_tax_accno} = 'Y';
479 $form->{l_balance} = $form->{accno} ? 'Y' : '';
482 'id' => { 'text' => $locale->text('ID'), },
483 'transdate' => { 'text' => $locale->text('Date'), },
484 'reference' => { 'text' => $locale->text('Reference'), },
485 'source' => { 'text' => $locale->text('Source'), },
486 'description' => { 'text' => $locale->text('Description'), },
487 'notes' => { 'text' => $locale->text('Notes'), },
488 'debit' => { 'text' => $locale->text('Debit'), },
489 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
490 'credit' => { 'text' => $locale->text('Credit'), },
491 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
492 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
493 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
494 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
495 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
496 'balance' => { 'text' => $locale->text('Balance'), },
497 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
500 map { $column_defs{$_}->{link} = $callback . "&sort=${_}" } qw(id transdate reference source description);
501 map { $column_defs{$_}->{link} = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax);
502 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
503 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
505 my %column_alignment;
506 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax);
507 map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno);
509 my $report = SL::ReportGenerator->new(\%myconfig, $form);
511 $report->set_columns(%column_defs);
512 $report->set_column_order(@columns);
514 $report->set_export_options('generate_report', @hidden_variables);
516 $report->set_sort_indicator($form->{sort}, 1);
518 $report->set_options('top_info_text' => join("\n", @options),
519 'output_format' => 'HTML',
520 'title' => $form->{title},
521 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
523 $report->set_options_from_form();
525 # add sort to callback
526 $form->{callback} = "$callback&sort=" . E($form->{sort});
528 $form->{balance} *= $ml;
530 if ($form->{accno} && $form->{balance}) {
533 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2),
538 $report->add_data($row);
541 my @totals_columns = qw(debit credit debit_tax credit_tax);
542 my %subtotals = map { $_ => 0 } @totals_columns;
543 my %totals = map { $_ => 0 } @totals_columns;
546 foreach $ref (@{ $form->{GL} }) {
547 $form->{balance} *= $ml;
551 foreach my $key (qw(debit credit debit_tax credit_tax)) {
553 foreach my $idx (sort keys(%{ $ref->{$key} })) {
554 my $value = $ref->{$key}->{$idx};
555 $subtotals{$key} += $value;
556 $totals{$key} += $value;
557 $form->{balance} = abs($form->{balance}) - abs($value);
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)) {
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;
570 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2);
571 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
573 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
575 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno);
577 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
578 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
581 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
583 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
585 my $row_set = [ $row ];
587 if (($form->{l_subtotal} eq 'Y')
588 && (($idx == (scalar @{ $form->{GL} } - 1))
589 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
590 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
593 $report->add_data($row_set);
598 $report->add_separator();
600 # = 0 for balanced ledger
601 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
603 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
605 'data' => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2),
607 'class' => 'listtotal',
609 $report->add_data($row);
611 my $raw_bottom_info_text;
613 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
614 $raw_bottom_info_text .=
615 '<p><span class="unbalanced_ledger">'
616 . $locale->text('Unbalanced Ledger')
618 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
622 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
624 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
626 $report->generate_with_headers();
628 $lxdebug->leave_sub();
632 $lxdebug->enter_sub();
634 $auth->assert('general_ledger');
636 $form->{oldtransdate} = $form->{transdate};
648 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
650 for my $i (1 .. $form->{rowcount}) {
652 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
653 for (qw(debit credit tax)) {
655 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
659 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
666 if (($debitcount >= 2) && ($creditcount == 2)) {
667 $form->{"credit_$i"} = 0;
668 $form->{"tax_$i"} = 0;
672 if (($creditcount >= 2) && ($debitcount == 2)) {
673 $form->{"debit_$i"} = 0;
674 $form->{"tax_$i"} = 0;
678 if (($creditcount == 1) && ($debitcount == 2)) {
681 if (($creditcount == 2) && ($debitcount == 1)) {
684 if ($debitcredit && $credittax) {
685 $form->{"taxchart_$i"} = "0--0.00";
687 if (!$debitcredit && $debittax) {
688 $form->{"taxchart_$i"} = "0--0.00";
691 ($form->{"debit_$i"} == 0)
692 ? $form->{"credit_$i"}
693 : $form->{"debit_$i"};
695 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
696 $form->{"taxchart_$i"} = "0--0.00";
697 $form->{"tax_$i"} = 0;
699 if (!$form->{"korrektur_$i"}) {
700 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
707 if ($form->{taxincluded}) {
708 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
710 $form->{"tax_$i"} = $amount * $rate;
713 $form->{"tax_$i"} = 0;
717 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
722 for $i (1 .. $count) {
724 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
727 for $i ($count + 1 .. $form->{rowcount}) {
728 for (@flds) { delete $form->{"${_}_$i"} }
731 $form->{rowcount} = $count + 1;
734 $lxdebug->leave_sub();
740 $lxdebug->enter_sub();
742 $auth->assert('general_ledger');
746 # for $i (1 .. $form->{rowcount}) {
747 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
748 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
752 &display_rows($init);
754 $lxdebug->leave_sub();
760 $lxdebug->enter_sub();
762 $auth->assert('general_ledger');
764 $form->{debit_1} = 0 if !$form->{"debit_1"};
765 $form->{totaldebit} = 0;
766 $form->{totalcredit} = 0;
768 my @old_project_ids = ();
769 map({ push(@old_project_ids, $form->{"project_id_$_"})
770 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
772 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
774 "old_id" => \@old_project_ids },
775 "charts" => { "key" => "ALL_CHARTS",
776 "transdate" => $form->{transdate} },
777 "taxcharts" => "ALL_TAXCHARTS");
779 my %project_labels = ();
780 my @project_values = ("");
781 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
782 push(@project_values, $item->{"id"});
783 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
786 my %chart_labels = ();
787 my @chart_values = ();
790 foreach my $item (@{ $form->{ALL_CHARTS} }) {
791 my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
792 $taxchart_init = $item->{taxkey_id} unless (@chart_values);
793 push(@chart_values, $key);
794 $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
795 $charts{$item->{accno}} = $item;
798 my %taxchart_labels = ();
799 my @taxchart_values = ();
801 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
802 my $key = Q($item->{id}) . "--" . Q($item->{rate});
803 $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
804 push(@taxchart_values, $key);
805 $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
806 H($item->{rate} * 100) . ' %';
807 $taxcharts{$item->{id}} = $item;
810 for $i (1 .. $form->{rowcount}) {
813 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
815 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
817 my $selected_accno_full;
818 my ($accno_row) = split(/--/, $form->{"accno_$i"});
819 my $item = $charts{$accno_row};
820 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
822 my $selected_taxchart = $form->{"taxchart_$i"};
823 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
824 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
826 if ($previous_accno &&
827 ($previous_accno eq $selected_accno) &&
828 ($previous_tax_id ne $selected_tax_id)) {
829 my $item = $taxcharts{$selected_tax_id};
830 $selected_taxchart = "$item->{id}--$item->{rate}";
833 $selected_accno = '' if ($init);
834 $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
837 NTI($cgi->popup_menu('-name' => "accno_$i",
839 '-onChange' => "setTaxkey(this, $i)",
840 '-style' => 'width:200px',
841 '-values' => \@chart_values,
842 '-labels' => \%chart_labels,
843 '-default' => $selected_accno_full))
844 . $cgi->hidden('-name' => "previous_accno_$i",
845 '-default' => $selected_accno_full)
848 NTI($cgi->popup_menu('-name' => "taxchart_$i",
849 '-id' => "taxchart_$i",
850 '-style' => 'width:200px',
851 '-values' => \@taxchart_values,
852 '-labels' => \%taxchart_labels,
853 '-default' => $selected_taxchart))
858 qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
859 if ($form->{transfer}) {
860 $fx_transaction = qq|
861 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
866 if ($form->{"debit_$i"} != 0) {
867 $form->{totaldebit} += $form->{"debit_$i"};
868 if (!$form->{taxincluded}) {
869 $form->{totaldebit} += $form->{"tax_$i"};
872 $form->{totalcredit} += $form->{"credit_$i"};
873 if (!$form->{taxincluded}) {
874 $form->{totalcredit} += $form->{"tax_$i"};
878 for (qw(debit credit tax)) {
881 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
885 if ($i < $form->{rowcount}) {
886 if ($form->{transfer}) {
887 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
888 $x = ($checked) ? "x" : "";
889 $fx_transaction = qq|
890 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
893 $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
895 qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
896 $form->hide_form("accno_$i");
900 qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
901 if ($form->{transfer}) {
902 $fx_transaction = qq|
903 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
908 my $debitreadonly = "";
909 my $creditreadonly = "";
910 if ($i == $form->{rowcount}) {
912 $debitreadonly = "readonly";
913 } elsif ($creditlock) {
914 $creditreadonly = "readonly";
919 NTI($cgi->popup_menu('-name' => "project_id_$i",
920 '-values' => \@project_values,
921 '-labels' => \%project_labels,
922 '-default' => $form->{"project_id_$i"} ));
924 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
926 print qq|<tr valign=top>
929 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
930 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
931 <td><input name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
935 if ($form->{show_details}) {
939 <td>$projectnumber</td>
947 $form->hide_form(qw(rowcount selectaccno));
949 $lxdebug->leave_sub();
955 $lxdebug->enter_sub();
957 $auth->assert('general_ledger');
959 $title = $form->{title};
960 $form->{title} = $locale->text("$title General Ledger Transaction");
961 $readonly = ($form->{id}) ? "readonly" : "";
963 $show_details_checked = "checked" if $form->{show_details};
965 # $locale->text('Add General Ledger Transaction')
966 # $locale->text('Edit General Ledger Transaction')
968 map { $form->{$_} =~ s/\"/"/g }
969 qw(reference description chart taxchart);
971 $form->{javascript} = qq|<script type="text/javascript">
973 function setTaxkey(accno, row) {
974 var taxkey = accno.options[accno.selectedIndex].value;
975 var reg = /--([0-9]*)/;
976 var found = reg.exec(taxkey);
977 var index = found[1];
978 index = parseInt(index);
979 var tax = 'taxchart_' + row;
980 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
981 var reg2 = new RegExp("^"+ index, "");
982 if (reg2.exec(document.getElementById(tax).options[i].value)) {
983 document.getElementById(tax).options[i].selected = true;
989 function copy_debit_to_credit() {
990 var txt = document.getElementsByName('debit_1')[0].value;
991 document.getElementsByName('credit_2')[0].value = txt;
996 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
998 $form->{selectdepartment} =~ s/ selected//;
999 $form->{selectdepartment} =~
1000 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1002 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
1004 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1007 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1010 $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1013 $taxincluded = "checked";
1018 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1019 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1020 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1022 | if $form->{selectdepartment};
1024 $form->{fokus} = "gl.reference";
1026 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1029 # use JavaScript Calendar or not
1030 $form->{jsscript} = 1;
1032 if ($form->{jsscript}) {
1034 # with JavaScript Calendar
1036 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1037 <input type=button name=transdate id="trigger1" value=|
1038 . $locale->text('button') . qq|></td>
1043 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1046 # without JavaScript Calendar
1048 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1051 $form->{previous_id} ||= "--";
1052 $form->{previous_gldate} ||= "--";
1057 <body onLoad="fokus()">
1059 <script type="text/javascript" src="js/common.js"></script>
1060 <script type="text/javascript" src="js/follow_up.js"></script>
1062 <form method=post name="gl" action=gl.pl>
1065 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1068 <input type=hidden name=title value="$title">
1070 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1071 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1072 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1073 <input type="hidden" name="follow_up_rowcount" value="1">
1077 <th class=listtop>$form->{title}</th>
1079 <tr height="5"></tr>
1084 <td colspan="6" align="left">|
1085 . $locale->text("Previous transnumber text")
1086 . " $form->{previous_id} "
1087 . $locale->text("Previous transdate text")
1088 . " $form->{previous_gldate}"
1092 <th align=right>| . $locale->text('Reference') . qq|</th>
1093 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1097 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1106 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1107 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1111 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1112 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1123 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1124 <td width=1%>$description</td>
1128 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1129 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1136 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1137 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1145 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1146 <td width=1%>$description</td>
1150 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1151 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1159 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1160 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1167 <tr class=listheading>
1168 <th class=listheading style="width:15%">|
1169 . $locale->text('Account') . qq|</th>
1170 <th class=listheading style="width:10%">|
1171 . $locale->text('Debit') . qq|</th>
1172 <th class=listheading style="width:10%">|
1173 . $locale->text('Credit') . qq|</th>
1174 <th class=listheading style="width:10%">|
1175 . $locale->text('Tax') . qq|</th>
1176 <th class=listheading style="width:5%">|
1177 . $locale->text('Korrektur') . qq|</th>
1178 <th class=listheading style="width:10%">|
1179 . $locale->text('Taxkey') . qq|</th>|;
1181 if ($form->{show_details}) {
1183 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1184 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1185 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1194 $lxdebug->leave_sub();
1199 $lxdebug->enter_sub();
1201 $auth->assert('general_ledger');
1203 my $follow_ups_block;
1205 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1207 if (@{ $follow_ups} ) {
1208 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1209 $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>|;
1213 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1215 $decimalplaces = ($dec > 2) ? $dec : 2;
1216 $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1219 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1220 } qw(totaldebit totalcredit);
1223 <tr class=listtotal>
1225 <th align=right class=listtotal> $form->{totaldebit}</th>
1226 <th align=right class=listtotal> $form->{totalcredit}</th>
1234 <input name=callback type=hidden value="$form->{callback}">
1241 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1242 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1246 if (!$form->{storno}) {
1247 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1250 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1251 if (!$form->{locked} && $radieren) {
1253 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1254 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1258 <input type="button" class="submit" onclick="follow_up_window()" value="|
1259 . $locale->text('Follow-Up')
1263 if ($transdate > $closedto) {
1265 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1266 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">|;
1276 $lxdebug->leave_sub();
1281 $lxdebug->enter_sub();
1288 <form method=post action=gl.pl>
1291 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1293 delete $form->{header};
1295 foreach $key (keys %$form) {
1296 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1297 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1301 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1304 . $locale->text('Are you sure you want to delete Transaction')
1305 . qq| $form->{reference}</h4>
1307 <input name=action class=submit type=submit value="|
1308 . $locale->text('Yes') . qq|">
1311 $lxdebug->leave_sub();
1316 $lxdebug->enter_sub();
1317 if (GL->delete_transaction(\%myconfig, \%$form)){
1318 # saving the history
1319 if(!exists $form->{addition} && $form->{id} ne "") {
1320 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1321 $form->{addition} = "DELETED";
1322 $form->save_history($form->dbconnect(\%myconfig));
1324 # /saving the history
1325 $form->redirect($locale->text('Transaction deleted!'))
1327 $form->error($locale->text('Cannot delete transaction!'));
1328 $lxdebug->leave_sub();
1332 sub post_transaction {
1333 $lxdebug->enter_sub();
1335 # check if there is something in reference and date
1336 $form->isblank("reference", $locale->text('Reference missing!'));
1337 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1338 $form->isblank("description", $locale->text('Description missing!'));
1340 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1341 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1348 my $creditcount = 0;
1352 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1354 for my $i (1 .. $form->{rowcount}) {
1355 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1357 for (qw(debit credit tax)) {
1358 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1362 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1370 if (($debitcount >= 2) && ($creditcount == 2)) {
1371 $form->{"credit_$i"} = 0;
1372 $form->{"tax_$i"} = 0;
1376 if (($creditcount >= 2) && ($debitcount == 2)) {
1377 $form->{"debit_$i"} = 0;
1378 $form->{"tax_$i"} = 0;
1382 if (($creditcount == 1) && ($debitcount == 2)) {
1385 if (($creditcount == 2) && ($debitcount == 1)) {
1388 if ($debitcredit && $credittax) {
1389 $form->{"taxchart_$i"} = "0--0.00";
1391 if (!$debitcredit && $debittax) {
1392 $form->{"taxchart_$i"} = "0--0.00";
1394 $amount = ($form->{"debit_$i"} == 0)
1395 ? $form->{"credit_$i"}
1396 : $form->{"debit_$i"};
1398 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1399 $form->{"taxchart_$i"} = "0--0.00";
1400 $form->{"tax_$i"} = 0;
1402 if (!$form->{"korrektur_$i"}) {
1403 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1410 if ($form->{taxincluded}) {
1411 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1413 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1415 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1418 $form->{"tax_$i"} = $amount * $rate;
1421 $form->{"tax_$i"} = 0;
1423 } elsif ($form->{taxincluded}) {
1425 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1427 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1431 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1435 for $i (1 .. $count) {
1437 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1440 for $i ($count + 1 .. $form->{rowcount}) {
1441 for (@flds) { delete $form->{"${_}_$i"} }
1444 for $i (1 .. $form->{rowcount}) {
1445 $dr = $form->{"debit_$i"};
1446 $cr = $form->{"credit_$i"};
1447 $tax = $form->{"tax_$i"};
1449 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1451 $debit += $dr + $tax if $dr;
1452 $credit += $cr + $tax if $cr;
1453 $taxtotal += $tax if $form->{taxincluded}
1456 $form->{taxincluded} = 0 if !$taxtotal;
1458 # this is just for the wise guys
1459 $form->error($locale->text('Cannot post transaction for a closed period!'))
1460 if ($transdate <= $closedto);
1461 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1462 $form->error($locale->text('Out of balance transaction!'));
1465 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1466 $form->error($locale->text('Empty transaction!'));
1469 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1471 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1472 $err[2] = $locale->text('Debit and credit out of balance!');
1473 $err[3] = $locale->text('Cannot post a transaction without a value!');
1475 $form->error($err[$errno]);
1477 undef($form->{callback});
1478 # saving the history
1479 if(!exists $form->{addition} && $form->{id} ne "") {
1480 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1481 $form->{addition} = "SAVED";
1482 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1483 $form->save_history($form->dbconnect(\%myconfig));
1485 # /saving the history
1487 $lxdebug->leave_sub();
1491 $lxdebug->enter_sub();
1493 $auth->assert('general_ledger');
1495 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1496 $form->{storno} = 0;
1500 $form->{callback} = build_std_url("action=add", "show_details");
1501 $form->redirect($form->{callback});
1503 $lxdebug->leave_sub();
1507 $lxdebug->enter_sub();
1509 $auth->assert('general_ledger');
1513 $lxdebug->leave_sub();
1518 $lxdebug->enter_sub();
1520 $auth->assert('general_ledger');
1522 # don't cancel cancelled transactions
1523 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1524 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1525 $form->error($locale->text("Transaction has already been cancelled!"));
1528 GL->storno($form, \%myconfig, $form->{id});
1530 # saving the history
1531 if(!exists $form->{addition} && $form->{id} ne "") {
1532 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1533 $form->{addition} = "STORNO";
1534 $form->save_history($form->dbconnect(\%myconfig));
1536 # /saving the history
1538 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1540 $lxdebug->leave_sub();
1544 call_sub($form->{nextsub});