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);
39 use SL::ReportGenerator;
41 require "bin/mozilla/arap.pl";
42 require "bin/mozilla/common.pl";
43 require "bin/mozilla/report_generator.pl";
49 # this is for our long dates
50 # $locale->text('January')
51 # $locale->text('February')
52 # $locale->text('March')
53 # $locale->text('April')
54 # $locale->text('May ')
55 # $locale->text('June')
56 # $locale->text('July')
57 # $locale->text('August')
58 # $locale->text('September')
59 # $locale->text('October')
60 # $locale->text('November')
61 # $locale->text('December')
63 # this is for our short month
64 # $locale->text('Jan')
65 # $locale->text('Feb')
66 # $locale->text('Mar')
67 # $locale->text('Apr')
68 # $locale->text('May')
69 # $locale->text('Jun')
70 # $locale->text('Jul')
71 # $locale->text('Aug')
72 # $locale->text('Sep')
73 # $locale->text('Oct')
74 # $locale->text('Nov')
75 # $locale->text('Dec')
78 $lxdebug->enter_sub();
80 $form->{title} = "Add";
83 "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
84 unless $form->{callback};
86 # we use this only to set a default date
87 GL->transaction(\%myconfig, \%$form);
91 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
92 . ($_->{rate} * 100) . qq| %|
95 $form->{rowcount} = 2;
102 $form->all_departments(\%myconfig);
103 if (@{ $form->{all_departments} }) {
104 $form->{selectdepartment} = "<option>\n";
107 $form->{selectdepartment} .=
108 "<option>$_->{description}--$_->{id}\n"
109 } (@{ $form->{all_departments} });
112 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
115 $lxdebug->leave_sub();
119 sub prepare_transaction {
120 $lxdebug->enter_sub();
122 GL->transaction(\%myconfig, \%$form);
126 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
127 . ($_->{rate} * 100) . qq| %|
130 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
133 $form->all_departments(\%myconfig);
134 if (@{ $form->{all_departments} }) {
135 $form->{selectdepartment} = "<option>\n";
138 $form->{selectdepartment} .=
139 "<option>$_->{description}--$_->{id}\n"
140 } (@{ $form->{all_departments} });
146 foreach $ref (@{ $form->{GL} }) {
148 if ($tax && ($ref->{accno} eq $taxaccno)) {
149 $form->{"tax_$j"} = abs($ref->{amount});
150 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
151 if ($form->{taxincluded}) {
152 if ($ref->{amount} < 0) {
153 $form->{"debit_$j"} += $form->{"tax_$j"};
155 $form->{"credit_$j"} += $form->{"tax_$j"};
158 $form->{"project_id_$j"} = $ref->{project_id};
161 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
162 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
163 if ($ref->{amount} < 0) {
164 $form->{totaldebit} -= $ref->{amount};
165 $form->{"debit_$i"} = $ref->{amount} * -1;
167 $form->{totalcredit} += $ref->{amount};
168 $form->{"credit_$i"} = $ref->{amount};
170 $form->{"taxchart_$i"} = "0--0.00";
171 $form->{"project_id_$i"} = $ref->{project_id};
174 if ($ref->{taxaccno} && !$tax) {
175 $taxaccno = $ref->{taxaccno};
183 $form->{rowcount} = $i;
185 ($form->datetonum($form->{transdate}, \%myconfig) <=
186 $form->datetonum($form->{closedto}, \%myconfig));
188 $lxdebug->leave_sub();
192 $lxdebug->enter_sub();
194 prepare_transaction();
196 $form->{title} = "Edit";
198 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
204 $lxdebug->leave_sub();
209 $lxdebug->enter_sub();
211 $form->{title} = $locale->text('Journal');
213 $form->all_departments(\%myconfig);
216 if (@{ $form->{all_departments} }) {
217 $form->{selectdepartment} = "<option>\n";
220 $form->{selectdepartment} .=
221 "<option>$_->{description}--$_->{id}\n"
222 } (@{ $form->{all_departments} });
227 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
228 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
230 | if $form->{selectdepartment};
232 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
235 my %project_labels = ();
236 my @project_values = ("");
237 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
238 push(@project_values, $item->{"id"});
239 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
243 NTI($cgi->popup_menu('-name' => "project_id",
244 '-values' => \@project_values,
245 '-labels' => \%project_labels));
247 # use JavaScript Calendar or not
248 $form->{jsscript} = 1;
250 if ($form->{jsscript}) {
252 # with JavaScript Calendar
254 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
255 <input type=button name=datefrom id="trigger1" value=|
256 . $locale->text('button') . qq|></td>
259 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
260 <input type=button name=dateto id="trigger2" value=|
261 . $locale->text('button') . qq|></td>
266 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
267 "dateto", "BL", "trigger2");
270 # without JavaScript Calendar
272 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
274 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
276 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
278 $onload = qq|focus()|;
279 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
280 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
282 <body onLoad="$onload">
284 <form method=post action=$form->{script}>
286 <input type=hidden name=sort value=transdate>
290 <th class=listtop>$form->{title}</th>
297 <th align=right>| . $locale->text('Reference') . qq|</th>
298 <td><input name=reference size=20></td>
299 <th align=right>| . $locale->text('Source') . qq|</th>
300 <td><input name=source size=20></td>
304 <th align=right>| . $locale->text('Description') . qq|</th>
305 <td colspan=3><input name=description size=40></td>
308 <th align=right>| . $locale->text('Notes') . qq|</th>
309 <td colspan=3><input name=notes size=40></td>
312 <th align=right>| . $locale->text('Project Number') . qq|</th>
313 <td colspan=3>$projectnumber</td>
316 <th align=right>| . $locale->text('From') . qq|</th>
318 <th align=right>| . $locale->text('To (time)') . qq|</th>
322 <th align=right>| . $locale->text('Include in Report') . qq|</th>
327 <input name="category" class=radio type=radio value=X checked> |
328 . $locale->text('All') . qq|
329 <input name="category" class=radio type=radio value=A> |
330 . $locale->text('Asset') . qq|
331 <input name="category" class=radio type=radio value=L> |
332 . $locale->text('Liability') . qq|
333 <input name="category" class=radio type=radio value=I> |
334 . $locale->text('Revenue') . qq|
335 <input name="category" class=radio type=radio value=E> |
336 . $locale->text('Expense') . qq|
342 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
343 <td>| . $locale->text('ID') . qq|</td>
344 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
345 <td>| . $locale->text('Date') . qq|</td>
346 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
347 <td>| . $locale->text('Reference') . qq|</td>
348 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
349 <td>| . $locale->text('Description') . qq|</td>
350 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
351 <td>| . $locale->text('Notes') . qq|</td>
354 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
355 <td>| . $locale->text('Debit') . qq|</td>
356 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
357 <td>| . $locale->text('Credit') . qq|</td>
358 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
359 <td>| . $locale->text('Source') . qq|</td>
360 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
361 <td>| . $locale->text('Account') . qq|</td>
364 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
365 <td>| . $locale->text('Subtotal') . qq|</td>
366 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
367 <td>| . $locale->text('Project Number') . qq|</td>
377 <td><hr size=3 noshade></td>
383 <input type=hidden name=nextsub value=generate_report>
385 <input type=hidden name=login value=$form->{login}>
386 <input type=hidden name=password value=$form->{password}>
389 <input class=submit type=submit name=action value="|
390 . $locale->text('Continue') . qq|">
396 $lxdebug->leave_sub();
399 sub create_subtotal_row {
400 $lxdebug->enter_sub();
402 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
404 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
406 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
408 map { $totals->{$_} = 0 } @{ $subtotal_columns };
410 $lxdebug->leave_sub();
415 sub generate_report {
416 $lxdebug->enter_sub();
418 $form->{sort} ||= "transdate";
420 GL->all_transactions(\%myconfig, \%$form);
422 my %acctype = ('A' => $locale->text('Asset'),
423 'C' => $locale->text('Contra'),
424 'L' => $locale->text('Liability'),
425 'Q' => $locale->text('Equity'),
426 'I' => $locale->text('Revenue'),
427 'E' => $locale->text('Expense'),);
429 $form->{title} = $locale->text('Journal');
430 if ($form->{category} ne 'X') {
431 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
434 $form->{landscape} = 1;
436 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
439 transdate id reference description
440 notes source debit debit_accno
441 credit credit_accno debit_tax debit_tax_accno
442 credit_tax credit_tax_accno projectnumbers balance
445 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
446 push @hidden_variables, map { "l_${_}" } @columns;
448 my (@options, $date_option);
449 if ($form->{accno}) {
450 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}";
452 if ($form->{source}) {
453 push @options, $locale->text('Source') . " : $form->{source}";
455 if ($form->{reference}) {
456 push @options, $locale->text('Reference') . " : $form->{reference}";
458 if ($form->{department}) {
459 my ($department) = split /--/, $form->{department};
460 push @options, $locale->text('Department') . " : $department";
462 if ($form->{description}) {
463 push @options, $locale->text('Description') . " : $form->{description}";
465 if ($form->{notes}) {
466 push @options, $locale->text('Notes') . " : $form->{notes}";
468 if ($form->{datefrom}) {
469 $date_option = $locale->text('From') . " " . $locale->date(\%myconfig, $form->{datefrom}, 1);
471 if ($form->{dateto}) {
472 if ($form->{datefrom}) {
475 $date_option .= $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{dateto}, 1);
477 push @options, $date_option if $date_option;
479 my $callback = build_std_url('action=generate_report', @hidden_variables);
481 $form->{l_credit_accno} = 'Y';
482 $form->{l_debit_accno} = 'Y';
483 $form->{l_credit_tax} = 'Y';
484 $form->{l_debit_tax} = 'Y';
485 $form->{l_credit_tax_accno} = 'Y';
486 $form->{l_debit_tax_accno} = 'Y';
487 $form->{l_balance} = $form->{accno} ? 'Y' : '';
490 'id' => { 'text' => $locale->text('ID'), },
491 'transdate' => { 'text' => $locale->text('Date'), },
492 'reference' => { 'text' => $locale->text('Reference'), },
493 'source' => { 'text' => $locale->text('Source'), },
494 'description' => { 'text' => $locale->text('Description'), },
495 'notes' => { 'text' => $locale->text('Notes'), },
496 'debit' => { 'text' => $locale->text('Debit'), },
497 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
498 'credit' => { 'text' => $locale->text('Credit'), },
499 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
500 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
501 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
502 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
503 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
504 'balance' => { 'text' => $locale->text('Balance'), },
505 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
508 map { $column_defs{$_}->{link} = $callback . "&sort=${_}" } qw(id transdate reference source description);
509 map { $column_defs{$_}->{link} = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax);
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);
515 map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno);
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);
524 $report->set_sort_indicator($form->{sort}, 1);
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});
536 $form->{balance} *= $ml;
538 if ($form->{accno} && $form->{balance}) {
541 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2),
546 $report->add_data($row);
549 my @totals_columns = qw(debit credit debit_tax credit_tax);
550 my %subtotals = map { $_ => 0 } @totals_columns;
551 my %totals = map { $_ => 0 } @totals_columns;
554 foreach $ref (@{ $form->{GL} }) {
555 $form->{balance} *= $ml;
559 foreach my $key (qw(debit credit debit_tax credit_tax)) {
561 foreach my $idx (sort keys(%{ $ref->{$key} })) {
562 my $value = $ref->{$key}->{$idx};
563 $subtotals{$key} += $value;
564 $totals{$key} += $value;
565 $form->{balance} = abs($form->{balance}) - abs($value);
566 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
570 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate)) {
571 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
572 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
576 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
578 $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2);
579 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
581 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes);
583 map { $row->{$_}->{data} = join "\n", @{ $rows{$_} }; } qw(transdate debit credit);
585 map { $row->{$_}->{data} = join "\n", @{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
587 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
588 if (lc $report->{options}->{output_format} eq 'html') {
589 $row->{$col}->{raw_data} = join "<br>", map { "<a href=\"${callback}&accno=" . E($_) . "\">$_</a>" } @{ $rows{$col} };
591 $row->{$col}->{data} = join "\n", @{ $rows{$col} };
595 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
597 my $row_set = [ $row ];
599 if (($form->{l_subtotal} eq 'Y')
600 && (($idx == (scalar @{ $form->{GL} } - 1))
601 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
602 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
605 $report->add_data($row_set);
610 $report->add_separator();
612 # = 0 for balanced ledger
613 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
615 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
617 'data' => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2),
619 'class' => 'listtotal',
621 $report->add_data($row);
623 my $raw_bottom_info_text;
625 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
626 $raw_bottom_info_text .=
627 '<p><span class="unbalanced_ledger">'
628 . $locale->text('Unbalanced Ledger')
630 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
634 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
636 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
638 $report->generate_with_headers();
640 $lxdebug->leave_sub();
644 $lxdebug->enter_sub();
646 $form->{oldtransdate} = $form->{transdate};
658 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
660 for my $i (1 .. $form->{rowcount}) {
662 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
663 for (qw(debit credit tax)) {
665 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
669 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
676 if (($debitcount >= 2) && ($creditcount == 2)) {
677 $form->{"credit_$i"} = 0;
678 $form->{"tax_$i"} = 0;
682 if (($creditcount >= 2) && ($debitcount == 2)) {
683 $form->{"debit_$i"} = 0;
684 $form->{"tax_$i"} = 0;
688 if (($creditcount == 1) && ($debitcount == 2)) {
691 if (($creditcount == 2) && ($debitcount == 1)) {
694 if ($debitcredit && $credittax) {
695 $form->{"taxchart_$i"} = "0--0.00";
697 if (!$debitcredit && $debittax) {
698 $form->{"taxchart_$i"} = "0--0.00";
701 ($form->{"debit_$i"} == 0)
702 ? $form->{"credit_$i"}
703 : $form->{"debit_$i"};
705 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
706 $form->{"taxchart_$i"} = "0--0.00";
707 $form->{"tax_$i"} = 0;
709 if (!$form->{"korrektur_$i"}) {
710 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
717 if ($form->{taxincluded}) {
718 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
720 $form->{"tax_$i"} = $amount * $rate;
723 $form->{"tax_$i"} = 0;
727 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
732 for $i (1 .. $count) {
734 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
737 for $i ($count + 1 .. $form->{rowcount}) {
738 for (@flds) { delete $form->{"${_}_$i"} }
741 $form->{rowcount} = $count + 1;
744 $lxdebug->leave_sub();
750 $lxdebug->enter_sub();
754 # for $i (1 .. $form->{rowcount}) {
755 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
756 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
760 &display_rows($init);
762 $lxdebug->leave_sub();
768 $lxdebug->enter_sub();
770 $form->{debit_1} = 0 if !$form->{"debit_1"};
771 $form->{totaldebit} = 0;
772 $form->{totalcredit} = 0;
774 my @old_project_ids = ();
775 map({ push(@old_project_ids, $form->{"project_id_$_"})
776 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
778 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
780 "old_id" => \@old_project_ids },
781 "charts" => { "key" => "ALL_CHARTS",
782 "transdate" => $form->{transdate} },
783 "taxcharts" => "ALL_TAXCHARTS");
785 my %project_labels = ();
786 my @project_values = ("");
787 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
788 push(@project_values, $item->{"id"});
789 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
792 my %chart_labels = ();
793 my @chart_values = ();
796 foreach my $item (@{ $form->{ALL_CHARTS} }) {
797 my $key = Q($item->{accno}) . "--" . Q($item->{tax_id});
798 $taxchart_init = $item->{taxkey_id} unless (@chart_values);
799 push(@chart_values, $key);
800 $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
801 $charts{$item->{accno}} = $item;
804 my %taxchart_labels = ();
805 my @taxchart_values = ();
807 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
808 my $key = Q($item->{id}) . "--" . Q($item->{rate});
809 $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
810 push(@taxchart_values, $key);
811 $taxchart_labels{$key} = H($item->{taxdescription}) . " " .
812 H($item->{rate} * 100) . ' %';
813 $taxcharts{$item->{id}} = $item;
816 for $i (1 .. $form->{rowcount}) {
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>|;
823 my $selected_accno_full;
824 my ($accno_row) = split(/--/, $form->{"accno_$i"});
825 my $item = $charts{$accno_row};
826 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
828 my $selected_taxchart = $form->{"taxchart_$i"};
829 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
830 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
832 if ($previous_accno &&
833 ($previous_accno eq $selected_accno) &&
834 ($previous_tax_id ne $selected_tax_id)) {
835 my $item = $taxcharts{$selected_tax_id};
836 $selected_taxchart = "$item->{id}--$item->{rate}";
839 $selected_accno = '' if ($init);
840 $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
843 NTI($cgi->popup_menu('-name' => "accno_$i",
845 '-onChange' => "setTaxkey(this, $i)",
846 '-style' => 'width:200px',
847 '-values' => \@chart_values,
848 '-labels' => \%chart_labels,
849 '-default' => $selected_accno_full))
850 . $cgi->hidden('-name' => "previous_accno_$i",
851 '-default' => $selected_accno_full)
854 NTI($cgi->popup_menu('-name' => "taxchart_$i",
855 '-id' => "taxchart_$i",
856 '-style' => 'width:200px',
857 '-values' => \@taxchart_values,
858 '-labels' => \%taxchart_labels,
859 '-default' => $selected_taxchart))
864 qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
865 if ($form->{transfer}) {
866 $fx_transaction = qq|
867 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
872 if ($form->{"debit_$i"} != 0) {
873 $form->{totaldebit} += $form->{"debit_$i"};
874 if (!$form->{taxincluded}) {
875 $form->{totaldebit} += $form->{"tax_$i"};
878 $form->{totalcredit} += $form->{"credit_$i"};
879 if (!$form->{taxincluded}) {
880 $form->{totalcredit} += $form->{"tax_$i"};
884 for (qw(debit credit tax)) {
887 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
891 if ($i < $form->{rowcount}) {
892 if ($form->{transfer}) {
893 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
894 $x = ($checked) ? "x" : "";
895 $fx_transaction = qq|
896 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
899 $checked = ($form->{"korrektur_$i"}) ? "checked" : "";
901 qq|<td><input type="checkbox" name="korrektur_$i" value="1" $checked></td>|;
902 $form->hide_form("accno_$i");
906 qq|<td><input type="checkbox" name="korrektur_$i" value="1"></td>|;
907 if ($form->{transfer}) {
908 $fx_transaction = qq|
909 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
914 my $debitreadonly = "";
915 my $creditreadonly = "";
916 if ($i == $form->{rowcount}) {
918 $debitreadonly = "readonly";
919 } elsif ($creditlock) {
920 $creditreadonly = "readonly";
925 NTI($cgi->popup_menu('-name' => "project_id_$i",
926 '-values' => \@project_values,
927 '-labels' => \%project_labels,
928 '-default' => $form->{"project_id_$i"} ));
930 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
932 print qq|<tr valign=top>
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 name="tax_$i" size=6 value="$form->{"tax_$i"}"></td>
941 if ($form->{show_details}) {
945 <td>$projectnumber</td>
953 $form->hide_form(qw(rowcount selectaccno));
955 $lxdebug->leave_sub();
961 $lxdebug->enter_sub();
962 $title = $form->{title};
963 $form->{title} = $locale->text("$title General Ledger Transaction");
964 $readonly = ($form->{id}) ? "readonly" : "";
966 $show_details_checked = "checked" if $form->{show_details};
968 # $locale->text('Add General Ledger Transaction')
969 # $locale->text('Edit General Ledger Transaction')
971 map { $form->{$_} =~ s/\"/"/g }
972 qw(reference description chart taxchart);
974 $form->{javascript} = qq|<script type="text/javascript">
976 function setTaxkey(accno, row) {
977 var taxkey = accno.options[accno.selectedIndex].value;
978 var reg = /--([0-9]*)/;
979 var found = reg.exec(taxkey);
980 var index = found[1];
981 index = parseInt(index);
982 var tax = 'taxchart_' + row;
983 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
984 var reg2 = new RegExp("^"+ index, "");
985 if (reg2.exec(document.getElementById(tax).options[i].value)) {
986 document.getElementById(tax).options[i].selected = true;
992 function copy_debit_to_credit() {
993 var txt = document.getElementsByName('debit_1')[0].value;
994 document.getElementsByName('credit_2')[0].value = txt;
999 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
1001 $form->{selectdepartment} =~ s/ selected//;
1002 $form->{selectdepartment} =~
1003 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1005 if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
1007 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1010 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1013 $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1016 $taxincluded = "checked";
1021 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1022 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1023 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1025 | if $form->{selectdepartment};
1027 $form->{fokus} = "gl.reference";
1029 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1032 # use JavaScript Calendar or not
1033 $form->{jsscript} = 1;
1035 if ($form->{jsscript}) {
1037 # with JavaScript Calendar
1039 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1040 <input type=button name=transdate id="trigger1" value=|
1041 . $locale->text('button') . qq|></td>
1046 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1049 # without JavaScript Calendar
1051 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1054 $form->{previous_id} ||= "--";
1055 $form->{previous_gldate} ||= "--";
1060 <body onLoad="fokus()">
1062 <form method=post name="gl" action=$form->{script}>
1065 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1068 <input type=hidden name=title value="$title">
1073 <th class=listtop>$form->{title}</th>
1075 <tr height="5"></tr>
1080 <td colspan="6" align="left">|
1081 . $locale->text("Previous transnumber text")
1082 . " $form->{previous_id} "
1083 . $locale->text("Previous transdate text")
1084 . " $form->{previous_gldate}"
1088 <th align=right>| . $locale->text('Reference') . qq|</th>
1089 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1093 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1102 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1103 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1107 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1108 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1119 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1120 <td width=1%>$description</td>
1124 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1125 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1132 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1133 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1141 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1142 <td width=1%>$description</td>
1146 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1147 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1155 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1156 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1163 <tr class=listheading>
1164 <th class=listheading style="width:15%">|
1165 . $locale->text('Account') . qq|</th>
1166 <th class=listheading style="width:10%">|
1167 . $locale->text('Debit') . qq|</th>
1168 <th class=listheading style="width:10%">|
1169 . $locale->text('Credit') . qq|</th>
1170 <th class=listheading style="width:10%">|
1171 . $locale->text('Tax') . qq|</th>
1172 <th class=listheading style="width:5%">|
1173 . $locale->text('Korrektur') . qq|</th>
1174 <th class=listheading style="width:10%">|
1175 . $locale->text('Taxkey') . qq|</th>|;
1177 if ($form->{show_details}) {
1179 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1180 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1181 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1190 $lxdebug->leave_sub();
1195 $lxdebug->enter_sub();
1196 ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1198 $decimalplaces = ($dec > 2) ? $dec : 2;
1199 $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1202 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1203 } qw(totaldebit totalcredit);
1206 <tr class=listtotal>
1208 <th align=right class=listtotal> $form->{totaldebit}</th>
1209 <th align=right class=listtotal> $form->{totalcredit}</th>
1217 <input type=hidden name=login value=$form->{login}>
1218 <input type=hidden name=password value=$form->{password}>
1220 <input name=callback type=hidden value="$form->{callback}">
1225 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1226 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1230 if (!$form->{storno}) {
1231 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1234 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1235 if (!$form->{locked} && $radieren) {
1237 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1238 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1242 if ($transdate > $closedto) {
1244 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1245 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">|;
1255 $lxdebug->leave_sub();
1260 $lxdebug->enter_sub();
1267 <form method=post action=$form->{script}>
1270 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1272 delete $form->{header};
1274 foreach $key (keys %$form) {
1275 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1279 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1282 . $locale->text('Are you sure you want to delete Transaction')
1283 . qq| $form->{reference}</h4>
1285 <input name=action class=submit type=submit value="|
1286 . $locale->text('Yes') . qq|">
1289 $lxdebug->leave_sub();
1294 $lxdebug->enter_sub();
1295 if (GL->delete_transaction(\%myconfig, \%$form)){
1296 # saving the history
1297 if(!exists $form->{addition} && $form->{id} ne "") {
1298 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1299 $form->{addition} = "DELETED";
1300 $form->save_history($form->dbconnect(\%myconfig));
1302 # /saving the history
1303 $form->redirect($locale->text('Transaction deleted!'))
1305 $form->error($locale->text('Cannot delete transaction!'));
1306 $lxdebug->leave_sub();
1310 sub post_transaction {
1311 $lxdebug->enter_sub();
1313 # check if there is something in reference and date
1314 $form->isblank("reference", $locale->text('Reference missing!'));
1315 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1316 $form->isblank("description", $locale->text('Description missing!'));
1318 $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1319 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1326 my $creditcount = 0;
1330 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1332 for my $i (1 .. $form->{rowcount}) {
1333 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1335 for (qw(debit credit tax)) {
1336 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1340 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1348 if (($debitcount >= 2) && ($creditcount == 2)) {
1349 $form->{"credit_$i"} = 0;
1350 $form->{"tax_$i"} = 0;
1354 if (($creditcount >= 2) && ($debitcount == 2)) {
1355 $form->{"debit_$i"} = 0;
1356 $form->{"tax_$i"} = 0;
1360 if (($creditcount == 1) && ($debitcount == 2)) {
1363 if (($creditcount == 2) && ($debitcount == 1)) {
1366 if ($debitcredit && $credittax) {
1367 $form->{"taxchart_$i"} = "0--0.00";
1369 if (!$debitcredit && $debittax) {
1370 $form->{"taxchart_$i"} = "0--0.00";
1372 $amount = ($form->{"debit_$i"} == 0)
1373 ? $form->{"credit_$i"}
1374 : $form->{"debit_$i"};
1376 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1377 $form->{"taxchart_$i"} = "0--0.00";
1378 $form->{"tax_$i"} = 0;
1380 if (!$form->{"korrektur_$i"}) {
1381 ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1388 if ($form->{taxincluded}) {
1389 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1391 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1393 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1396 $form->{"tax_$i"} = $amount * $rate;
1399 $form->{"tax_$i"} = 0;
1401 } elsif ($form->{taxincluded}) {
1403 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1405 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1409 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1413 for $i (1 .. $count) {
1415 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1418 for $i ($count + 1 .. $form->{rowcount}) {
1419 for (@flds) { delete $form->{"${_}_$i"} }
1422 for $i (1 .. $form->{rowcount}) {
1423 $dr = $form->{"debit_$i"};
1424 $cr = $form->{"credit_$i"};
1425 $tax = $form->{"tax_$i"};
1427 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1429 $debit += $dr + $tax if $dr;
1430 $credit += $cr + $tax if $cr;
1431 $taxtotal += $tax if $form->{taxincluded}
1434 $form->{taxincluded} = 0 if !$taxtotal;
1436 # this is just for the wise guys
1437 $form->error($locale->text('Cannot post transaction for a closed period!'))
1438 if ($transdate <= $closedto);
1439 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1440 $form->error($locale->text('Out of balance transaction!'));
1443 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1444 $form->error($locale->text('Empty transaction!'));
1447 if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1449 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1450 $err[2] = $locale->text('Debit and credit out of balance!');
1451 $err[3] = $locale->text('Cannot post a transaction without a value!');
1453 $form->error($err[$errno]);
1455 undef($form->{callback});
1456 # saving the history
1457 if(!exists $form->{addition} && $form->{id} ne "") {
1458 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1459 $form->{addition} = "SAVED";
1460 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1461 $form->save_history($form->dbconnect(\%myconfig));
1463 # /saving the history
1465 $lxdebug->leave_sub();
1469 $lxdebug->enter_sub();
1471 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1472 $form->{storno} = 0;
1476 $form->{callback} = build_std_url("action=add", "show_details");
1477 $form->redirect($form->{callback});
1479 $lxdebug->leave_sub();
1483 $lxdebug->enter_sub();
1487 $lxdebug->leave_sub();
1492 $lxdebug->enter_sub();
1494 # don't cancel cancelled transactions
1495 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1496 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1497 $form->error($locale->text("Transaction has already been cancelled!"));
1500 GL->storno($form, \%myconfig, $form->{id});
1502 # saving the history
1503 if(!exists $form->{addition} && $form->{id} ne "") {
1504 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1505 $form->{addition} = "STORNO";
1506 $form->save_history($form->dbconnect(\%myconfig));
1508 # /saving the history
1510 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1512 $lxdebug->leave_sub();