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";
53 # this is for our long dates
54 # $locale->text('January')
55 # $locale->text('February')
56 # $locale->text('March')
57 # $locale->text('April')
58 # $locale->text('May ')
59 # $locale->text('June')
60 # $locale->text('July')
61 # $locale->text('August')
62 # $locale->text('September')
63 # $locale->text('October')
64 # $locale->text('November')
65 # $locale->text('December')
67 # this is for our short month
68 # $locale->text('Jan')
69 # $locale->text('Feb')
70 # $locale->text('Mar')
71 # $locale->text('Apr')
72 # $locale->text('May')
73 # $locale->text('Jun')
74 # $locale->text('Jul')
75 # $locale->text('Aug')
76 # $locale->text('Sep')
77 # $locale->text('Oct')
78 # $locale->text('Nov')
79 # $locale->text('Dec')
86 $main::lxdebug->enter_sub();
88 $main::auth->assert('general_ledger');
90 my $form = $main::form;
91 my %myconfig = %main::myconfig;
93 return $main::lxdebug->leave_sub() if (load_draft_maybe());
95 $form->{title} = "Add";
97 $form->{callback} = "gl.pl?action=add" unless $form->{callback};
99 # we use this only to set a default date
100 # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb
101 GL->transaction(\%myconfig, \%$form);
105 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
106 . ($_->{rate} * 100) . qq| %|
109 $form->{rowcount} = 2;
116 $form->all_departments(\%myconfig);
117 if (@{ $form->{all_departments} }) {
118 $form->{selectdepartment} = "<option>\n";
121 $form->{selectdepartment} .=
122 "<option>$_->{description}--$_->{id}\n"
123 } (@{ $form->{all_departments} });
126 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
129 $main::lxdebug->leave_sub();
133 sub prepare_transaction {
134 $main::lxdebug->enter_sub();
136 $main::auth->assert('general_ledger');
138 my $form = $main::form;
139 my %myconfig = %main::myconfig;
141 GL->transaction(\%myconfig, \%$form);
145 qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
146 . ($_->{rate} * 100) . qq| %|
149 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
152 $form->all_departments(\%myconfig);
153 if (@{ $form->{all_departments} }) {
154 $form->{selectdepartment} = "<option>\n";
157 $form->{selectdepartment} .=
158 "<option>$_->{description}--$_->{id}\n"
159 } (@{ $form->{all_departments} });
165 foreach my $ref (@{ $form->{GL} }) {
167 if ($tax && ($ref->{accno} eq $taxaccno)) {
168 $form->{"tax_$j"} = abs($ref->{amount});
169 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
170 if ($form->{taxincluded}) {
171 if ($ref->{amount} < 0) {
172 $form->{"debit_$j"} += $form->{"tax_$j"};
174 $form->{"credit_$j"} += $form->{"tax_$j"};
177 $form->{"project_id_$j"} = $ref->{project_id};
180 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
181 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
182 if ($ref->{amount} < 0) {
183 $form->{totaldebit} -= $ref->{amount};
184 $form->{"debit_$i"} = $ref->{amount} * -1;
186 $form->{totalcredit} += $ref->{amount};
187 $form->{"credit_$i"} = $ref->{amount};
189 $form->{"taxchart_$i"} = "0--0.00";
190 $form->{"project_id_$i"} = $ref->{project_id};
193 if ($ref->{taxaccno} && !$tax) {
194 $taxaccno = $ref->{taxaccno};
202 $form->{rowcount} = $i;
204 ($form->datetonum($form->{transdate}, \%myconfig) <=
205 $form->datetonum($form->{closedto}, \%myconfig));
207 $main::lxdebug->leave_sub();
211 $main::lxdebug->enter_sub();
213 $main::auth->assert('general_ledger');
215 my $form = $main::form;
216 my %myconfig = %main::myconfig;
218 prepare_transaction();
220 $form->{title} = "Edit";
222 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
228 $main::lxdebug->leave_sub();
233 $main::lxdebug->enter_sub();
235 $main::auth->assert('general_ledger');
237 my $form = $main::form;
238 my %myconfig = %main::myconfig;
239 my $locale = $main::locale;
240 my $cgi = $main::cgi;
242 $form->{title} = $locale->text('Journal');
244 $form->all_departments(\%myconfig);
247 if (@{ $form->{all_departments} }) {
248 $form->{selectdepartment} = "<option>\n";
251 $form->{selectdepartment} .=
252 "<option>$_->{description}--$_->{id}\n"
253 } (@{ $form->{all_departments} });
258 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
259 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
261 | if $form->{selectdepartment};
263 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
266 my %project_labels = ();
267 my @project_values = ("");
268 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
269 push(@project_values, $item->{"id"});
270 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
274 NTI($cgi->popup_menu('-name' => "project_id",
275 '-values' => \@project_values,
276 '-labels' => \%project_labels));
278 # use JavaScript Calendar or not
279 $form->{jsscript} = 1;
281 my ($button1, $button2, $onload);
282 if ($form->{jsscript}) {
284 # with JavaScript Calendar
286 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
287 <input type=button name=datefrom id="trigger1" value=|
288 . $locale->text('button') . qq|></td>
291 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
292 <input type=button name=dateto id="trigger2" value=|
293 . $locale->text('button') . qq|></td>
298 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
299 "dateto", "BL", "trigger2");
302 # without JavaScript Calendar
304 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
306 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
308 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
310 $onload = qq|focus()|;
311 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
312 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
314 <body onLoad="$onload">
316 <form method=post action=gl.pl>
318 <input type=hidden name=sort value=transdate>
322 <th class=listtop>$form->{title}</th>
329 <th align=right>| . $locale->text('Reference') . qq|</th>
330 <td><input name=reference size=20></td>
331 <th align=right>| . $locale->text('Source') . qq|</th>
332 <td><input name=source size=20></td>
336 <th align=right>| . $locale->text('Description') . qq|</th>
337 <td colspan=3><input name=description size=40></td>
340 <th align=right>| . $locale->text('Notes') . qq|</th>
341 <td colspan=3><input name=notes size=40></td>
344 <th align=right>| . $locale->text('Project Number') . qq|</th>
345 <td colspan=3>$projectnumber</td>
348 <th align=right>| . $locale->text('From') . qq|</th>
350 <th align=right>| . $locale->text('To (time)') . qq|</th>
354 <th align=right>| . $locale->text('Include in Report') . qq|</th>
359 <input name="category" class=radio type=radio value=X checked> |
360 . $locale->text('All') . qq|
361 <input name="category" class=radio type=radio value=A> |
362 . $locale->text('Asset') . qq|
363 <input name="category" class=radio type=radio value=L> |
364 . $locale->text('Liability') . qq|
365 <input name="category" class=radio type=radio value=I> |
366 . $locale->text('Revenue') . qq|
367 <input name="category" class=radio type=radio value=E> |
368 . $locale->text('Expense') . qq|
374 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
375 <td>| . $locale->text('ID') . qq|</td>
376 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
377 <td>| . $locale->text('Date') . qq|</td>
378 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
379 <td>| . $locale->text('Reference') . qq|</td>
380 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
381 <td>| . $locale->text('Description') . qq|</td>
382 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
383 <td>| . $locale->text('Notes') . qq|</td>
386 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
387 <td>| . $locale->text('Debit') . qq|</td>
388 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
389 <td>| . $locale->text('Credit') . qq|</td>
390 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
391 <td>| . $locale->text('Source') . qq|</td>
392 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
393 <td>| . $locale->text('Account') . qq|</td>
396 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
397 <td>| . $locale->text('Subtotal') . qq|</td>
398 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
399 <td>| . $locale->text('Project Number') . qq|</td>
409 <td><hr size=3 noshade></td>
415 <input type=hidden name=nextsub value=generate_report>
418 <input class=submit type=submit name=action value="|
419 . $locale->text('Continue') . qq|">
425 $main::lxdebug->leave_sub();
428 sub create_subtotal_row {
429 $main::lxdebug->enter_sub();
431 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
433 my $form = $main::form;
434 my %myconfig = %main::myconfig;
436 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
438 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
440 map { $totals->{$_} = 0 } @{ $subtotal_columns };
442 $main::lxdebug->leave_sub();
447 sub generate_report {
448 $main::lxdebug->enter_sub();
450 $main::auth->assert('general_ledger');
452 my $form = $main::form;
453 my %myconfig = %main::myconfig;
454 my $locale = $main::locale;
456 report_generator_set_default_sort('transdate', 1);
458 GL->all_transactions(\%myconfig, \%$form);
460 my %acctype = ('A' => $locale->text('Asset'),
461 'C' => $locale->text('Contra'),
462 'L' => $locale->text('Liability'),
463 'Q' => $locale->text('Equity'),
464 'I' => $locale->text('Revenue'),
465 'E' => $locale->text('Expense'),);
467 $form->{title} = $locale->text('Journal');
468 if ($form->{category} ne 'X') {
469 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
472 $form->{landscape} = 1;
474 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
477 transdate id reference description
478 notes source debit debit_accno
479 credit credit_accno debit_tax debit_tax_accno
480 credit_tax credit_tax_accno projectnumbers balance
483 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
484 push @hidden_variables, map { "l_${_}" } @columns;
486 my (@options, @date_options);
487 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
488 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
489 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
490 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
491 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
493 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
494 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
495 push @options, join(' ', @date_options) if (scalar @date_options);
497 if ($form->{department}) {
498 my ($department) = split /--/, $form->{department};
499 push @options, $locale->text('Department') . " : $department";
503 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
505 $form->{l_credit_accno} = 'Y';
506 $form->{l_debit_accno} = 'Y';
507 $form->{l_credit_tax} = 'Y';
508 $form->{l_debit_tax} = 'Y';
509 $form->{l_credit_tax_accno} = 'Y';
510 $form->{l_debit_tax_accno} = 'Y';
511 $form->{l_balance} = $form->{accno} ? 'Y' : '';
514 'id' => { 'text' => $locale->text('ID'), },
515 'transdate' => { 'text' => $locale->text('Date'), },
516 'reference' => { 'text' => $locale->text('Reference'), },
517 'source' => { 'text' => $locale->text('Source'), },
518 'description' => { 'text' => $locale->text('Description'), },
519 'notes' => { 'text' => $locale->text('Notes'), },
520 'debit' => { 'text' => $locale->text('Debit'), },
521 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
522 'credit' => { 'text' => $locale->text('Credit'), },
523 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
524 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
525 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
526 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
527 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
528 'balance' => { 'text' => $locale->text('Balance'), },
529 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
532 foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
533 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
534 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
535 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
538 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
539 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
541 my %column_alignment;
542 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
543 map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
544 map { $column_alignment{$_} = 'left' } qw(description source notes);
545 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
547 my $report = SL::ReportGenerator->new(\%myconfig, $form);
549 $report->set_columns(%column_defs);
550 $report->set_column_order(@columns);
552 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
554 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
556 $report->set_options('top_info_text' => join("\n", @options),
557 'output_format' => 'HTML',
558 'title' => $form->{title},
559 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
561 $report->set_options_from_form();
563 # add sort to callback
564 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
567 my @totals_columns = qw(debit credit debit_tax credit_tax);
568 my %subtotals = map { $_ => 0 } @totals_columns;
569 my %totals = map { $_ => 0 } @totals_columns;
572 foreach my $ref (@{ $form->{GL} }) {
576 foreach my $key (qw(debit credit debit_tax credit_tax)) {
578 foreach my $idx (sort keys(%{ $ref->{$key} })) {
579 my $value = $ref->{$key}->{$idx};
580 $subtotals{$key} += $value;
581 $totals{$key} += $value;
582 if ($key =~ /debit.*/) {
587 $form->{balance} = $form->{balance} + $value * $ml;
588 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
592 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
593 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
594 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
598 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
601 if ($form->{balance} < 0) {
604 } elsif ($form->{balance} > 0) {
608 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
611 $row->{balance}->{data} = $data;
612 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
614 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
616 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
618 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
619 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
622 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
624 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
626 my $row_set = [ $row ];
628 if (($form->{l_subtotal} eq 'Y')
629 && (($idx == (scalar @{ $form->{GL} } - 1))
630 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
631 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
634 $report->add_data($row_set);
639 $report->add_separator();
641 # = 0 for balanced ledger
642 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
644 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
647 if ($form->{balance} < 0) {
650 } elsif ($form->{balance} > 0) {
654 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
657 $row->{balance}->{data} = $data;
659 $report->add_data($row);
661 my $raw_bottom_info_text;
663 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
664 $raw_bottom_info_text .=
665 '<p><span class="unbalanced_ledger">'
666 . $locale->text('Unbalanced Ledger')
668 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
672 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
674 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
676 $report->generate_with_headers();
678 $main::lxdebug->leave_sub();
682 $main::lxdebug->enter_sub();
684 $main::auth->assert('general_ledger');
686 my $form = $main::form;
687 my %myconfig = %main::myconfig;
689 $form->{oldtransdate} = $form->{transdate};
697 my ($debitcredit, $amount);
700 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
702 for my $i (1 .. $form->{rowcount}) {
704 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
705 for (qw(debit credit tax)) {
707 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
711 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
718 if (($debitcount >= 2) && ($creditcount == 2)) {
719 $form->{"credit_$i"} = 0;
720 $form->{"tax_$i"} = 0;
724 if (($creditcount >= 2) && ($debitcount == 2)) {
725 $form->{"debit_$i"} = 0;
726 $form->{"tax_$i"} = 0;
730 if (($creditcount == 1) && ($debitcount == 2)) {
733 if (($creditcount == 2) && ($debitcount == 1)) {
736 if ($debitcredit && $credittax) {
737 $form->{"taxchart_$i"} = "0--0.00";
739 if (!$debitcredit && $debittax) {
740 $form->{"taxchart_$i"} = "0--0.00";
743 ($form->{"debit_$i"} == 0)
744 ? $form->{"credit_$i"}
745 : $form->{"debit_$i"};
747 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
748 $form->{"taxchart_$i"} = "0--0.00";
749 $form->{"tax_$i"} = 0;
751 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
758 if ($form->{taxincluded}) {
759 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
761 $form->{"tax_$i"} = $amount * $rate;
764 $form->{"tax_$i"} = 0;
767 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
772 for my $i (1 .. $count) {
774 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
777 for my $i ($count + 1 .. $form->{rowcount}) {
778 for (@flds) { delete $form->{"${_}_$i"} }
781 $form->{rowcount} = $count + 1;
784 $main::lxdebug->leave_sub();
790 $main::lxdebug->enter_sub();
792 $main::auth->assert('general_ledger');
794 my $form = $main::form;
795 my %myconfig = %main::myconfig;
799 # for $i (1 .. $form->{rowcount}) {
800 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
801 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
805 &display_rows($init);
807 $main::lxdebug->leave_sub();
813 $main::lxdebug->enter_sub();
815 $main::auth->assert('general_ledger');
817 my $form = $main::form;
818 my %myconfig = %main::myconfig;
819 my $cgi = $main::cgi;
821 $form->{debit_1} = 0 if !$form->{"debit_1"};
822 $form->{totaldebit} = 0;
823 $form->{totalcredit} = 0;
825 my %project_labels = ();
826 my @project_values = ("");
827 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
828 push(@project_values, $item->{"id"});
829 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
832 my %chart_labels = ();
833 my @chart_values = ();
836 foreach my $item (@{ $form->{ALL_CHARTS} }) {
837 if ($item->{charttype} eq 'H'){ #falls überschrift
838 next; #überspringen (Bug 1150)
840 my $key = $item->{accno} . "--" . $item->{tax_id};
841 $taxchart_init = $item->{tax_id} unless (@chart_values);
842 push(@chart_values, $key);
843 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
844 $charts{$item->{accno}} = $item;
847 my %taxchart_labels = ();
848 my @taxchart_values = ();
850 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
851 my $key = $item->{id} . "--" . $item->{rate};
852 $taxchart_init = $key if ($taxchart_init == $item->{id});
853 push(@taxchart_values, $key);
854 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
855 $taxcharts{$item->{id}} = $item;
858 my ($source, $memo, $source_hidden, $memo_hidden);
859 for my $i (1 .. $form->{rowcount}) {
860 if ($form->{show_details}) {
862 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
864 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
867 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
869 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
872 my $selected_accno_full;
873 my ($accno_row) = split(/--/, $form->{"accno_$i"});
874 my $item = $charts{$accno_row};
875 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
877 my $selected_taxchart = $form->{"taxchart_$i"};
878 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
879 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
881 if ($previous_accno &&
882 ($previous_accno eq $selected_accno) &&
883 ($previous_tax_id ne $selected_tax_id)) {
884 my $item = $taxcharts{$selected_tax_id};
885 $selected_taxchart = "$item->{id}--$item->{rate}";
888 $selected_accno = '' if ($init);
889 $selected_taxchart ||= $taxchart_init;
891 my $accno = qq|<td>| .
892 NTI($cgi->popup_menu('-name' => "accno_$i",
894 '-onChange' => "setTaxkey($i)",
895 '-style' => 'width:200px',
896 '-values' => \@chart_values,
897 '-labels' => \%chart_labels,
898 '-default' => $selected_accno_full))
899 . $cgi->hidden('-name' => "previous_accno_$i",
900 '-default' => $selected_accno_full)
903 NTI($cgi->popup_menu('-name' => "taxchart_$i",
904 '-id' => "taxchart_$i",
905 '-style' => 'width:200px',
906 '-values' => \@taxchart_values,
907 '-labels' => \%taxchart_labels,
908 '-default' => $selected_taxchart))
911 my ($fx_transaction, $checked);
913 if ($form->{transfer}) {
914 $fx_transaction = qq|
915 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
920 if ($form->{"debit_$i"} != 0) {
921 $form->{totaldebit} += $form->{"debit_$i"};
922 if (!$form->{taxincluded}) {
923 $form->{totaldebit} += $form->{"tax_$i"};
926 $form->{totalcredit} += $form->{"credit_$i"};
927 if (!$form->{taxincluded}) {
928 $form->{totalcredit} += $form->{"tax_$i"};
932 for (qw(debit credit tax)) {
935 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
939 if ($i < $form->{rowcount}) {
940 if ($form->{transfer}) {
941 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
942 my $x = ($checked) ? "x" : "";
943 $fx_transaction = qq|
944 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
947 $form->hide_form("accno_$i");
950 if ($form->{transfer}) {
951 $fx_transaction = qq|
952 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
957 my $debitreadonly = "";
958 my $creditreadonly = "";
959 if ($i == $form->{rowcount}) {
961 $debitreadonly = "readonly";
962 } elsif ($creditlock) {
963 $creditreadonly = "readonly";
968 NTI($cgi->popup_menu('-name' => "project_id_$i",
969 '-values' => \@project_values,
970 '-labels' => \%project_labels,
971 '-default' => $form->{"project_id_$i"} ));
973 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
975 print qq|<tr valign=top>
977 <td id="chart_balance_$i" align="right"> </td>
979 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
980 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
981 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
984 if ($form->{show_details}) {
988 <td>$projectnumber</td>
998 $form->hide_form(qw(rowcount selectaccno));
1000 $main::lxdebug->leave_sub();
1006 $main::lxdebug->enter_sub();
1008 $main::auth->assert('general_ledger');
1010 my $form = $main::form;
1011 my %myconfig = %main::myconfig;
1012 my $locale = $main::locale;
1014 my @old_project_ids = ();
1015 map({ push(@old_project_ids, $form->{"project_id_$_"})
1016 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
1018 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1020 "old_id" => \@old_project_ids },
1021 "charts" => { "key" => "ALL_CHARTS",
1022 "transdate" => $form->{transdate} },
1023 "taxcharts" => "ALL_TAXCHARTS");
1025 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
1027 my $title = $form->{title};
1028 $form->{title} = $locale->text("$title General Ledger Transaction");
1029 my $readonly = ($form->{id}) ? "readonly" : "";
1031 my $show_details_checked = "checked" if $form->{show_details};
1033 my $ob_transaction_checked = "checked" if $form->{ob_transaction};
1034 my $cb_transaction_checked = "checked" if $form->{cb_transaction};
1036 # $locale->text('Add General Ledger Transaction')
1037 # $locale->text('Edit General Ledger Transaction')
1039 map { $form->{$_} =~ s/\"/"/g }
1040 qw(reference description chart taxchart);
1042 $form->{javascript} = qq|<script type="text/javascript">
1044 function setTaxkey(row) {
1045 var accno = document.getElementById('accno_' + row);
1046 var taxkey = accno.options[accno.selectedIndex].value;
1047 var reg = /--([0-9]*)/;
1048 var found = reg.exec(taxkey);
1049 var index = found[1];
1050 index = parseInt(index);
1051 var tax = 'taxchart_' + row;
1052 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1053 var reg2 = new RegExp("^"+ index, "");
1054 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1055 document.getElementById(tax).options[i].selected = true;
1061 function copy_debit_to_credit() {
1062 var txt = document.getElementsByName('debit_1')[0].value;
1063 document.getElementsByName('credit_2')[0].value = txt;
1067 <script type="text/javascript" src="js/show_form_details.js"></script>
1068 <script type="text/javascript" src="js/jquery.js"></script>
1071 $form->{selectdepartment} =~ s/ selected//;
1072 $form->{selectdepartment} =~
1073 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1076 if ((my $rows = $form->numtextrows($form->{description}, 50)) > 1) {
1078 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1081 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1084 my $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1087 $taxincluded = "checked";
1093 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1094 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1095 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1097 | if $form->{selectdepartment};
1099 $form->{fokus} = "gl.reference";
1101 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1104 # use JavaScript Calendar or not
1105 $form->{jsscript} = 1;
1107 my ($button1, $button2);
1108 if ($form->{jsscript}) {
1110 # with JavaScript Calendar
1112 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1113 <input type=button name=transdate id="trigger1" value=|
1114 . $locale->text('button') . qq|></td>
1119 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1122 # without JavaScript Calendar
1124 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1127 $form->{previous_id} ||= "--";
1128 $form->{previous_gldate} ||= "--";
1130 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1135 <body onLoad="focus()">
1137 <script type="text/javascript" src="js/follow_up.js"></script>
1139 <form method=post name="gl" action=gl.pl>
1142 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1145 <input type=hidden name=title value="$title">
1147 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1148 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1149 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1150 <input type="hidden" name="follow_up_rowcount" value="1">
1154 <th class=listtop>$form->{title}</th>
1156 <tr height="5"></tr>
1161 <td colspan="6" align="left">|
1162 . $locale->text("Previous transnumber text")
1163 . " $form->{previous_id} "
1164 . $locale->text("Previous transdate text")
1165 . " $form->{previous_gldate}"
1169 <th align=right>| . $locale->text('Reference') . qq|</th>
1170 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1174 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1183 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1184 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1188 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1189 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1200 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1201 <td width=1%>$description</td>
1205 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1206 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1213 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1214 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1222 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1223 <td width=1%>$description</td>
1227 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1228 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1237 <tr><td colspan=4><table><tr>
1239 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1242 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1244 </tr></table></td></tr>
1246 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1247 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1254 <tr class=listheading>
1255 <th class=listheading style="width:15%">|
1256 . $locale->text('Account') . qq|</th>
1257 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1258 <th class=listheading style="width:10%">|
1259 . $locale->text('Debit') . qq|</th>
1260 <th class=listheading style="width:10%">|
1261 . $locale->text('Credit') . qq|</th>
1262 <th class=listheading style="width:10%">|
1263 . $locale->text('Tax') . qq|</th>
1264 <th class=listheading style="width:5%">|
1265 . $locale->text('Taxkey') . qq|</th>|;
1267 if ($form->{show_details}) {
1269 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1270 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1271 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1280 $main::lxdebug->leave_sub();
1285 $main::lxdebug->enter_sub();
1287 $main::auth->assert('general_ledger');
1289 my $form = $main::form;
1290 my %myconfig = %main::myconfig;
1291 my $locale = $main::locale;
1292 my $cgi = $main::cgi;
1294 my $follow_ups_block;
1296 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1298 if (@{ $follow_ups} ) {
1299 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1300 $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>|;
1304 my ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1306 my $decimalplaces = ($dec > 2) ? $dec : 2;
1307 my $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1310 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1311 } qw(totaldebit totalcredit);
1314 <tr class=listtotal>
1315 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1316 <th align=right class=listtotal> $form->{totalcredit}</th>
1324 <input name=callback type=hidden value="$form->{callback}">
1331 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1332 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1336 if (!$form->{storno}) {
1337 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1340 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1341 if (!$form->{locked} && $radieren) {
1343 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1344 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1348 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1349 <input type="button" class="submit" onclick="follow_up_window()" value="|
1350 . $locale->text('Follow-Up')
1354 if ($form->{draft_id}) {
1355 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1357 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1358 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1363 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1364 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1365 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1366 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1367 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1376 $main::lxdebug->leave_sub();
1381 $main::lxdebug->enter_sub();
1383 my $form = $main::form;
1384 my $locale = $main::locale;
1391 <form method=post action=gl.pl>
1394 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1396 delete $form->{header};
1398 foreach my $key (keys %$form) {
1399 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1400 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1404 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1407 . $locale->text('Are you sure you want to delete Transaction')
1408 . qq| $form->{reference}</h4>
1410 <input name=action class=submit type=submit value="|
1411 . $locale->text('Yes') . qq|">
1414 $main::lxdebug->leave_sub();
1419 $main::lxdebug->enter_sub();
1421 my $form = $main::form;
1422 my %myconfig = %main::myconfig;
1423 my $locale = $main::locale;
1425 if (GL->delete_transaction(\%myconfig, \%$form)){
1426 # saving the history
1427 if(!exists $form->{addition} && $form->{id} ne "") {
1428 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1429 $form->{addition} = "DELETED";
1430 $form->save_history($form->dbconnect(\%myconfig));
1432 # /saving the history
1433 $form->redirect($locale->text('Transaction deleted!'))
1435 $form->error($locale->text('Cannot delete transaction!'));
1436 $main::lxdebug->leave_sub();
1440 sub post_transaction {
1441 $main::lxdebug->enter_sub();
1443 my $form = $main::form;
1444 my %myconfig = %main::myconfig;
1445 my $locale = $main::locale;
1447 # check if there is something in reference and date
1448 $form->isblank("reference", $locale->text('Reference missing!'));
1449 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1450 $form->isblank("description", $locale->text('Description missing!'));
1452 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1453 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1460 my $creditcount = 0;
1463 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1465 for my $i (1 .. $form->{rowcount}) {
1466 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1468 for (qw(debit credit tax)) {
1469 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1473 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1481 if (($debitcount >= 2) && ($creditcount == 2)) {
1482 $form->{"credit_$i"} = 0;
1483 $form->{"tax_$i"} = 0;
1487 if (($creditcount >= 2) && ($debitcount == 2)) {
1488 $form->{"debit_$i"} = 0;
1489 $form->{"tax_$i"} = 0;
1493 if (($creditcount == 1) && ($debitcount == 2)) {
1496 if (($creditcount == 2) && ($debitcount == 1)) {
1499 if ($debitcredit && $credittax) {
1500 $form->{"taxchart_$i"} = "0--0.00";
1502 if (!$debitcredit && $debittax) {
1503 $form->{"taxchart_$i"} = "0--0.00";
1505 my $amount = ($form->{"debit_$i"} == 0)
1506 ? $form->{"credit_$i"}
1507 : $form->{"debit_$i"};
1509 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1510 $form->{"taxchart_$i"} = "0--0.00";
1511 $form->{"tax_$i"} = 0;
1513 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1520 if ($form->{taxincluded}) {
1521 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1523 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1525 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1528 $form->{"tax_$i"} = $amount * $rate;
1531 $form->{"tax_$i"} = 0;
1534 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1538 for my $i (1 .. $count) {
1540 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1543 for my $i ($count + 1 .. $form->{rowcount}) {
1544 for (@flds) { delete $form->{"${_}_$i"} }
1547 my ($debit, $credit, $taxtotal);
1548 for my $i (1 .. $form->{rowcount}) {
1549 my $dr = $form->{"debit_$i"};
1550 my $cr = $form->{"credit_$i"};
1551 $tax = $form->{"tax_$i"};
1553 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1555 $debit += $dr + $tax if $dr;
1556 $credit += $cr + $tax if $cr;
1557 $taxtotal += $tax if $form->{taxincluded}
1560 $form->{taxincluded} = 0 if !$taxtotal;
1562 # this is just for the wise guys
1563 $form->error($locale->text('Cannot post transaction for a closed period!'))
1564 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1565 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1566 $form->error($locale->text('Out of balance transaction!'));
1569 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1570 $form->error($locale->text('Empty transaction!'));
1573 if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1576 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1577 $err[2] = $locale->text('Debit and credit out of balance!');
1578 $err[3] = $locale->text('Cannot post a transaction without a value!');
1580 $form->error($err[$errno]);
1582 undef($form->{callback});
1583 # saving the history
1584 if(!exists $form->{addition} && $form->{id} ne "") {
1585 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1586 $form->{addition} = "SAVED";
1587 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1588 $form->save_history($form->dbconnect(\%myconfig));
1590 # /saving the history
1592 $main::lxdebug->leave_sub();
1596 $main::lxdebug->enter_sub();
1598 $main::auth->assert('general_ledger');
1600 my $form = $main::form;
1601 my $locale = $main::locale;
1603 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1604 $form->{storno} = 0;
1608 remove_draft() if $form->{remove_draft};
1610 $form->{callback} = build_std_url("action=add", "show_details");
1611 $form->redirect($form->{callback});
1613 $main::lxdebug->leave_sub();
1617 $main::lxdebug->enter_sub();
1619 $main::auth->assert('general_ledger');
1621 my $form = $main::form;
1625 $main::lxdebug->leave_sub();
1630 $main::lxdebug->enter_sub();
1632 $main::auth->assert('general_ledger');
1634 my $form = $main::form;
1635 my %myconfig = %main::myconfig;
1636 my $locale = $main::locale;
1638 # don't cancel cancelled transactions
1639 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1640 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1641 $form->error($locale->text("Transaction has already been cancelled!"));
1644 GL->storno($form, \%myconfig, $form->{id});
1646 # saving the history
1647 if(!exists $form->{addition} && $form->{id} ne "") {
1648 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1649 $form->{addition} = "STORNO";
1650 $form->save_history($form->dbconnect(\%myconfig));
1652 # /saving the history
1654 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1656 $main::lxdebug->leave_sub();
1660 call_sub($main::form->{nextsub});