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";
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 $main::lxdebug->enter_sub();
80 $main::auth->assert('general_ledger');
82 my $form = $main::form;
83 my %myconfig = %main::myconfig;
85 return $main::lxdebug->leave_sub() if (load_draft_maybe());
87 $form->{title} = "Add";
89 $form->{callback} = "gl.pl?action=add" unless $form->{callback};
91 # we use this only to set a default date
92 # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb
93 GL->transaction(\%myconfig, \%$form);
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 $main::lxdebug->leave_sub();
119 sub prepare_transaction {
120 $main::lxdebug->enter_sub();
122 $main::auth->assert('general_ledger');
124 my $form = $main::form;
125 my %myconfig = %main::myconfig;
127 GL->transaction(\%myconfig, \%$form);
129 $form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
132 $form->all_departments(\%myconfig);
133 if (@{ $form->{all_departments} || [] }) {
134 $form->{selectdepartment} = "<option>\n";
137 $form->{selectdepartment} .=
138 "<option>$_->{description}--$_->{id}\n"
139 } (@{ $form->{all_departments} || [] });
145 foreach my $ref (@{ $form->{GL} }) {
147 if ($tax && ($ref->{accno} eq $taxaccno)) {
148 $form->{"tax_$j"} = abs($ref->{amount});
149 $form->{"taxchart_$j"} = $ref->{id} . "--" . $ref->{taxrate};
150 if ($form->{taxincluded}) {
151 if ($ref->{amount} < 0) {
152 $form->{"debit_$j"} += $form->{"tax_$j"};
154 $form->{"credit_$j"} += $form->{"tax_$j"};
157 $form->{"project_id_$j"} = $ref->{project_id};
160 $form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
161 for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} }
162 if ($ref->{amount} < 0) {
163 $form->{totaldebit} -= $ref->{amount};
164 $form->{"debit_$i"} = $ref->{amount} * -1;
166 $form->{totalcredit} += $ref->{amount};
167 $form->{"credit_$i"} = $ref->{amount};
169 $form->{"taxchart_$i"} = "0--0.00";
170 $form->{"project_id_$i"} = $ref->{project_id};
173 if ($ref->{taxaccno} && !$tax) {
174 $taxaccno = $ref->{taxaccno};
182 $form->{rowcount} = $i;
184 ($form->datetonum($form->{transdate}, \%myconfig) <=
185 $form->datetonum($form->{closedto}, \%myconfig));
187 $main::lxdebug->leave_sub();
191 $main::lxdebug->enter_sub();
193 $main::auth->assert('general_ledger');
195 my $form = $main::form;
196 my %myconfig = %main::myconfig;
198 prepare_transaction();
200 $form->{title} = "Edit";
202 $form->{show_details} = $myconfig{show_form_details} unless defined $form->{show_details};
208 $main::lxdebug->leave_sub();
213 $main::lxdebug->enter_sub();
215 $main::auth->assert('general_ledger');
217 my $form = $main::form;
218 my %myconfig = %main::myconfig;
219 my $locale = $main::locale;
220 my $cgi = $main::cgi;
222 $form->{title} = $locale->text('Journal');
224 $form->all_departments(\%myconfig);
227 if (@{ $form->{all_departments} || [] }) {
228 $form->{selectdepartment} = "<option>\n";
231 $form->{selectdepartment} .=
232 "<option>$_->{description}--$_->{id}\n"
233 } (@{ $form->{all_departments} || [] });
238 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
239 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
241 | if $form->{selectdepartment};
243 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
246 my %project_labels = ();
247 my @project_values = ("");
248 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
249 push(@project_values, $item->{"id"});
250 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
254 NTI($cgi->popup_menu('-name' => "project_id",
255 '-values' => \@project_values,
256 '-labels' => \%project_labels));
258 # use JavaScript Calendar or not
259 $form->{jsscript} = 1;
261 my ($button1, $button2, $onload);
262 if ($form->{jsscript}) {
264 # with JavaScript Calendar
266 <td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
267 <input type=button name=datefrom id="trigger1" value=|
268 . $locale->text('button') . qq|></td>
271 <td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\">
272 <input type=button name=dateto id="trigger2" value=|
273 . $locale->text('button') . qq|></td>
278 Form->write_trigger(\%myconfig, "2", "datefrom", "BR", "trigger1",
279 "dateto", "BL", "trigger2");
282 # without JavaScript Calendar
284 qq|<td><input name=datefrom id=datefrom size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
286 qq|<td><input name=dateto id=dateto size=11 title="$myconfig{dateformat}" onBlur=\"check_right_date_format(this)\"></td>|;
288 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
290 $onload = qq|focus()|;
291 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
292 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
294 <body onLoad="$onload">
296 <form method=post action=gl.pl>
298 <input type=hidden name=sort value=transdate>
302 <th class=listtop>$form->{title}</th>
309 <th align=right>| . $locale->text('Reference') . qq|</th>
310 <td><input name=reference size=20></td>
311 <th align=right>| . $locale->text('Source') . qq|</th>
312 <td><input name=source size=20></td>
316 <th align=right>| . $locale->text('Description') . qq|</th>
317 <td><input name=description size=40></td>
318 <th align=right>| . $locale->text('Account Number') . qq|</th>
319 <td><input name=accno size=20></td>
322 <th align=right>| . $locale->text('Notes') . qq|</th>
323 <td colspan=3><input name=notes size=40></td>
326 <th align=right>| . $locale->text('Project Number') . qq|</th>
327 <td colspan=3>$projectnumber</td>
330 <th align=right>| . $locale->text('From') . qq|</th>
332 <th align=right>| . $locale->text('To (time)') . qq|</th>
336 <th align=right>| . $locale->text('Include in Report') . qq|</th>
341 <input name="category" class=radio type=radio value=X checked> |
342 . $locale->text('All') . qq|
343 <input name="category" class=radio type=radio value=A> |
344 . $locale->text('Asset') . qq|
345 <input name="category" class=radio type=radio value=L> |
346 . $locale->text('Liability') . qq|
347 <input name="category" class=radio type=radio value=I> |
348 . $locale->text('Revenue') . qq|
349 <input name="category" class=radio type=radio value=E> |
350 . $locale->text('Expense') . qq|
356 <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
357 <td>| . $locale->text('ID') . qq|</td>
358 <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
359 <td>| . $locale->text('Date') . qq|</td>
360 <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
361 <td>| . $locale->text('Reference') . qq|</td>
362 <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
363 <td>| . $locale->text('Description') . qq|</td>
364 <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
365 <td>| . $locale->text('Notes') . qq|</td>
368 <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
369 <td>| . $locale->text('Debit') . qq|</td>
370 <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
371 <td>| . $locale->text('Credit') . qq|</td>
372 <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
373 <td>| . $locale->text('Source') . qq|</td>
374 <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
375 <td>| . $locale->text('Account') . qq|</td>
378 <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
379 <td>| . $locale->text('Subtotal') . qq|</td>
380 <td align=right><input name="l_projectnumbers" class=checkbox type=checkbox value=Y></td>
381 <td>| . $locale->text('Project Number') . qq|</td>
391 <td><hr size=3 noshade></td>
397 <input type=hidden name=nextsub value=generate_report>
400 <input class=submit type=submit name=action value="|
401 . $locale->text('Continue') . qq|">
407 $main::lxdebug->leave_sub();
410 sub create_subtotal_row {
411 $main::lxdebug->enter_sub();
413 my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
415 my $form = $main::form;
416 my %myconfig = %main::myconfig;
418 my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
420 map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
422 map { $totals->{$_} = 0 } @{ $subtotal_columns };
424 $main::lxdebug->leave_sub();
429 sub generate_report {
430 $main::lxdebug->enter_sub();
432 $main::auth->assert('general_ledger');
434 my $form = $main::form;
435 my %myconfig = %main::myconfig;
436 my $locale = $main::locale;
438 report_generator_set_default_sort('transdate', 1);
440 GL->all_transactions(\%myconfig, \%$form);
442 my %acctype = ('A' => $locale->text('Asset'),
443 'C' => $locale->text('Contra'),
444 'L' => $locale->text('Liability'),
445 'Q' => $locale->text('Equity'),
446 'I' => $locale->text('Revenue'),
447 'E' => $locale->text('Expense'),);
449 $form->{title} = $locale->text('Journal');
450 if ($form->{category} ne 'X') {
451 $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
454 $form->{landscape} = 1;
456 my $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
459 transdate id reference description
460 notes source debit debit_accno
461 credit credit_accno debit_tax debit_tax_accno
462 credit_tax credit_tax_accno projectnumbers balance
465 my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal);
466 push @hidden_variables, map { "l_${_}" } @columns;
468 my (@options, @date_options);
469 push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno});
470 push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source});
471 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
472 push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description});
473 push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
475 push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom});
476 push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto});
477 push @options, join(' ', @date_options) if (scalar @date_options);
479 if ($form->{department}) {
480 my ($department) = split /--/, $form->{department};
481 push @options, $locale->text('Department') . " : $department";
485 my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
487 $form->{l_credit_accno} = 'Y';
488 $form->{l_debit_accno} = 'Y';
489 $form->{l_credit_tax} = 'Y';
490 $form->{l_debit_tax} = 'Y';
491 $form->{l_credit_tax_accno} = 'Y';
492 $form->{l_debit_tax_accno} = 'Y';
493 $form->{l_balance} = $form->{accno} ? 'Y' : '';
496 'id' => { 'text' => $locale->text('ID'), },
497 'transdate' => { 'text' => $locale->text('Date'), },
498 'reference' => { 'text' => $locale->text('Reference'), },
499 'source' => { 'text' => $locale->text('Source'), },
500 'description' => { 'text' => $locale->text('Description'), },
501 'notes' => { 'text' => $locale->text('Notes'), },
502 'debit' => { 'text' => $locale->text('Debit'), },
503 'debit_accno' => { 'text' => $locale->text('Debit Account'), },
504 'credit' => { 'text' => $locale->text('Credit'), },
505 'credit_accno' => { 'text' => $locale->text('Credit Account'), },
506 'debit_tax' => { 'text' => $locale->text('Debit Tax'), },
507 'debit_tax_accno' => { 'text' => $locale->text('Debit Tax Account'), },
508 'credit_tax' => { 'text' => $locale->text('Credit Tax'), },
509 'credit_tax_accno' => { 'text' => $locale->text('Credit Tax Account'), },
510 'balance' => { 'text' => $locale->text('Balance'), },
511 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), },
514 foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
515 my $sortname = $name =~ m/accno/ ? 'accno' : $name;
516 my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir};
517 $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir";
520 map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
521 map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno};
523 my %column_alignment;
524 map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance);
525 map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno);
526 map { $column_alignment{$_} = 'left' } qw(description source notes);
527 map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment;
529 my $report = SL::ReportGenerator->new(\%myconfig, $form);
531 $report->set_columns(%column_defs);
532 $report->set_column_order(@columns);
534 $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir));
536 $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir});
538 $report->set_options('top_info_text' => join("\n", @options),
539 'output_format' => 'HTML',
540 'title' => $form->{title},
541 'attachment_basename' => $locale->text('general_ledger_list') . strftime('_%Y%m%d', localtime time),
543 $report->set_options_from_form();
545 # add sort to callback
546 $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
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 my $ref (@{ $form->{GL} }) {
558 foreach my $key (qw(debit credit debit_tax credit_tax)) {
560 foreach my $idx (sort keys(%{ $ref->{$key} })) {
561 my $value = $ref->{$key}->{$idx};
562 $subtotals{$key} += $value;
563 $totals{$key} += $value;
564 if ($key =~ /debit.*/) {
569 $form->{balance} = $form->{balance} + $value * $ml;
570 push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2);
574 foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) {
575 my $col = $key eq 'ac_transdate' ? 'transdate' : $key;
576 $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ];
580 map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns;
583 if ($form->{balance} < 0) {
586 } elsif ($form->{balance} > 0) {
590 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
593 $row->{balance}->{data} = $data;
594 $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} };
596 map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes);
598 map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source);
600 foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) {
601 $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ];
604 map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax);
606 $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback');
608 my $row_set = [ $row ];
610 if (($form->{l_subtotal} eq 'Y')
611 && (($idx == (scalar @{ $form->{GL} } - 1))
612 || ($ref->{ $form->{sort} } ne $form->{GL}->[$idx + 1]->{ $form->{sort} }))) {
613 push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, [ qw(debit credit) ], 'listsubtotal');
616 $report->add_data($row_set);
621 $report->add_separator();
623 # = 0 for balanced ledger
624 my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax};
626 my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal');
629 if ($form->{balance} < 0) {
632 } elsif ($form->{balance} > 0) {
636 my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2);
639 $row->{balance}->{data} = $data;
641 $report->add_data($row);
643 my $raw_bottom_info_text;
645 if (!$form->{accno} && (abs($balanced_ledger) > 0.001)) {
646 $raw_bottom_info_text .=
647 '<p><span class="unbalanced_ledger">'
648 . $locale->text('Unbalanced Ledger')
650 . $form->format_amount(\%myconfig, $balanced_ledger, 3)
654 $raw_bottom_info_text .= $form->parse_html_template('gl/generate_report_bottom');
656 $report->set_options('raw_bottom_info_text' => $raw_bottom_info_text);
658 $report->generate_with_headers();
660 $main::lxdebug->leave_sub();
664 $main::lxdebug->enter_sub();
666 $main::auth->assert('general_ledger');
668 my $form = $main::form;
669 my %myconfig = %main::myconfig;
671 $form->{oldtransdate} = $form->{transdate};
679 my ($debitcredit, $amount);
682 qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
684 for my $i (1 .. $form->{rowcount}) {
686 unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
687 for (qw(debit credit tax)) {
689 $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
693 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
700 if (($debitcount >= 2) && ($creditcount == 2)) {
701 $form->{"credit_$i"} = 0;
702 $form->{"tax_$i"} = 0;
704 $form->{creditlock} = 1;
706 if (($creditcount >= 2) && ($debitcount == 2)) {
707 $form->{"debit_$i"} = 0;
708 $form->{"tax_$i"} = 0;
710 $form->{debitlock} = 1;
712 if (($creditcount == 1) && ($debitcount == 2)) {
713 $form->{creditlock} = 1;
715 if (($creditcount == 2) && ($debitcount == 1)) {
716 $form->{debitlock} = 1;
718 if ($debitcredit && $credittax) {
719 $form->{"taxchart_$i"} = "0--0.00";
721 if (!$debitcredit && $debittax) {
722 $form->{"taxchart_$i"} = "0--0.00";
725 ($form->{"debit_$i"} == 0)
726 ? $form->{"credit_$i"}
727 : $form->{"debit_$i"};
729 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
730 $form->{"taxchart_$i"} = "0--0.00";
731 $form->{"tax_$i"} = 0;
733 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
740 if ($form->{taxincluded}) {
741 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
743 $form->{"tax_$i"} = $amount * $rate;
746 $form->{"tax_$i"} = 0;
749 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
754 for my $i (1 .. $count) {
756 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
759 for my $i ($count + 1 .. $form->{rowcount}) {
760 for (@flds) { delete $form->{"${_}_$i"} }
763 $form->{rowcount} = $count + 1;
766 $main::lxdebug->leave_sub();
772 $main::lxdebug->enter_sub();
774 $main::auth->assert('general_ledger');
776 my $form = $main::form;
777 my %myconfig = %main::myconfig;
781 # for $i (1 .. $form->{rowcount}) {
782 # $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
783 # $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
787 &display_rows($init);
789 $main::lxdebug->leave_sub();
795 $main::lxdebug->enter_sub();
797 $main::auth->assert('general_ledger');
799 my $form = $main::form;
800 my %myconfig = %main::myconfig;
801 my $cgi = $main::cgi;
803 $form->{debit_1} = 0 if !$form->{"debit_1"};
804 $form->{totaldebit} = 0;
805 $form->{totalcredit} = 0;
807 my %project_labels = ();
808 my @project_values = ("");
809 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
810 push(@project_values, $item->{"id"});
811 $project_labels{$item->{"id"}} = $item->{"projectnumber"};
814 my %chart_labels = ();
815 my @chart_values = ();
818 foreach my $item (@{ $form->{ALL_CHARTS} }) {
819 if ($item->{charttype} eq 'H'){ #falls überschrift
820 next; #überspringen (Bug 1150)
822 my $key = $item->{accno} . "--" . $item->{tax_id};
823 $taxchart_init = $item->{tax_id} unless (@chart_values);
824 push(@chart_values, $key);
825 $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
826 $charts{$item->{accno}} = $item;
829 my %taxchart_labels = ();
830 my @taxchart_values = ();
832 foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
833 my $key = $item->{id} . "--" . $item->{rate};
834 $taxchart_init = $key if ($taxchart_init == $item->{id});
835 push(@taxchart_values, $key);
836 $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
837 $taxcharts{$item->{id}} = $item;
840 my ($source, $memo, $source_hidden, $memo_hidden);
841 for my $i (1 .. $form->{rowcount}) {
842 if ($form->{show_details}) {
844 <td><input name="source_$i" value="$form->{"source_$i"}" size="16"></td>|;
846 <td><input name="memo_$i" value="$form->{"memo_$i"}" size="16"></td>|;
849 <input type="hidden" name="source_$i" value="$form->{"source_$i"}" size="16">|;
851 <input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|;
854 my $selected_accno_full;
855 my ($accno_row) = split(/--/, $form->{"accno_$i"});
856 my $item = $charts{$accno_row};
857 $selected_accno_full = "$item->{accno}--$item->{tax_id}";
859 my $selected_taxchart = $form->{"taxchart_$i"};
860 my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
861 my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
863 if ($previous_accno &&
864 ($previous_accno eq $selected_accno) &&
865 ($previous_tax_id ne $selected_tax_id)) {
866 my $item = $taxcharts{$selected_tax_id};
867 $selected_taxchart = "$item->{id}--$item->{rate}";
870 $selected_accno = '' if ($init);
871 $selected_taxchart ||= $taxchart_init;
873 my $accno = qq|<td>| .
874 NTI($cgi->popup_menu('-name' => "accno_$i",
876 '-onChange' => "setTaxkey($i)",
877 '-style' => 'width:200px',
878 '-values' => \@chart_values,
879 '-labels' => \%chart_labels,
880 '-default' => $selected_accno_full))
881 . $cgi->hidden('-name' => "previous_accno_$i",
882 '-default' => $selected_accno_full)
884 my $tax_ddbox = qq|<td>| .
885 NTI($cgi->popup_menu('-name' => "taxchart_$i",
886 '-id' => "taxchart_$i",
887 '-style' => 'width:200px',
888 '-values' => \@taxchart_values,
889 '-labels' => \%taxchart_labels,
890 '-default' => $selected_taxchart))
893 my ($fx_transaction, $checked);
895 if ($form->{transfer}) {
896 $fx_transaction = qq|
897 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
902 if ($form->{"debit_$i"} != 0) {
903 $form->{totaldebit} += $form->{"debit_$i"};
904 if (!$form->{taxincluded}) {
905 $form->{totaldebit} += $form->{"tax_$i"};
908 $form->{totalcredit} += $form->{"credit_$i"};
909 if (!$form->{taxincluded}) {
910 $form->{totalcredit} += $form->{"tax_$i"};
914 for (qw(debit credit tax)) {
917 ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
921 if ($i < $form->{rowcount}) {
922 if ($form->{transfer}) {
923 $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
924 my $x = ($checked) ? "x" : "";
925 $fx_transaction = qq|
926 <td><input type=hidden name="fx_transaction_$i" value="$checked">$x</td>
929 $form->hide_form("accno_$i");
932 if ($form->{transfer}) {
933 $fx_transaction = qq|
934 <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1></td>
939 my $debitreadonly = "";
940 my $creditreadonly = "";
941 if ($i == $form->{rowcount}) {
942 if ($form->{debitlock}) {
943 $debitreadonly = "readonly";
944 } elsif ($form->{creditlock}) {
945 $creditreadonly = "readonly";
950 NTI($cgi->popup_menu('-name' => "project_id_$i",
951 '-values' => \@project_values,
952 '-labels' => \%project_labels,
953 '-default' => $form->{"project_id_$i"} ));
954 my $projectnumber_hidden = qq|
955 <input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|;
957 my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
959 print qq|<tr valign=top>
961 <td id="chart_balance_$i" align="right"> </td>
963 <td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td>
964 <td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td>
965 <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
968 if ($form->{show_details}) {
972 <td>$projectnumber</td>
978 $projectnumber_hidden
986 $form->hide_form(qw(rowcount selectaccno));
988 $main::lxdebug->leave_sub();
994 $main::lxdebug->enter_sub();
996 $main::auth->assert('general_ledger');
998 my $form = $main::form;
999 my %myconfig = %main::myconfig;
1000 my $locale = $main::locale;
1002 my @old_project_ids = ();
1003 map({ push(@old_project_ids, $form->{"project_id_$_"})
1004 if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
1006 $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
1008 "old_id" => \@old_project_ids },
1009 "charts" => { "key" => "ALL_CHARTS",
1010 "transdate" => $form->{transdate} },
1011 "taxcharts" => "ALL_TAXCHARTS");
1013 GL->get_chart_balances('charts' => $form->{ALL_CHARTS});
1015 my $title = $form->{title};
1016 $form->{title} = $locale->text("$title General Ledger Transaction");
1017 my $readonly = ($form->{id}) ? "readonly" : "";
1019 my $show_details_checked = "checked" if $form->{show_details};
1021 my $ob_transaction_checked = "checked" if $form->{ob_transaction};
1022 my $cb_transaction_checked = "checked" if $form->{cb_transaction};
1024 # $locale->text('Add General Ledger Transaction')
1025 # $locale->text('Edit General Ledger Transaction')
1027 map { $form->{$_} =~ s/\"/"/g }
1028 qw(reference description chart taxchart);
1030 $form->{javascript} = qq|<script type="text/javascript">
1032 function setTaxkey(row) {
1033 var accno = document.getElementById('accno_' + row);
1034 var taxkey = accno.options[accno.selectedIndex].value;
1035 var reg = /--([0-9]*)/;
1036 var found = reg.exec(taxkey);
1037 var index = found[1];
1038 index = parseInt(index);
1039 var tax = 'taxchart_' + row;
1040 for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
1041 var reg2 = new RegExp("^"+ index, "");
1042 if (reg2.exec(document.getElementById(tax).options[i].value)) {
1043 document.getElementById(tax).options[i].selected = true;
1049 function copy_debit_to_credit() {
1050 var txt = document.getElementsByName('debit_1')[0].value;
1051 document.getElementsByName('credit_2')[0].value = txt;
1055 <script type="text/javascript" src="js/show_form_details.js"></script>
1056 <script type="text/javascript" src="js/jquery.js"></script>
1059 $form->{selectdepartment} =~ s/ selected//;
1060 $form->{selectdepartment} =~
1061 s/option>\Q$form->{department}\E/option selected>$form->{department}/;
1064 if ((my $rows = $form->numtextrows($form->{description}, 50)) > 1) {
1066 qq|<textarea name=description rows=$rows cols=50 wrap=soft $readonly >$form->{description}</textarea>|;
1069 qq|<input name=description size=50 value="$form->{description}" $readonly>|;
1072 my $taxincluded = ($form->{taxincluded}) ? "checked" : "";
1075 $taxincluded = "checked";
1081 <th align=right nowrap>| . $locale->text('Department') . qq|</th>
1082 <td colspan=3><select name=department>$form->{selectdepartment}</select></td>
1083 <input type=hidden name=selectdepartment value="$form->{selectdepartment}">
1085 | if $form->{selectdepartment};
1087 $form->{fokus} = "gl.reference";
1089 $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
1092 # use JavaScript Calendar or not
1093 $form->{jsscript} = 1;
1095 my ($button1, $button2);
1096 if ($form->{jsscript}) {
1098 # with JavaScript Calendar
1100 <td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\">
1101 <input type=button name=transdate id="trigger1" value=|
1102 . $locale->text('button') . qq|></td>
1107 Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
1110 # without JavaScript Calendar
1112 qq|<td><input name=transdate id=transdate size=11 title="$myconfig{dateformat}" value="$form->{transdate}" $readonly onBlur=\"check_right_date_format(this)\"></td>|;
1115 $form->{previous_id} ||= "--";
1116 $form->{previous_gldate} ||= "--";
1118 $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
1123 <body onLoad="focus()">
1125 <script type="text/javascript" src="js/follow_up.js"></script>
1127 <form method=post name="gl" action=gl.pl>
1130 $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate));
1133 <input type=hidden name=title value="$title">
1135 <input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
1136 <input type="hidden" name="follow_up_trans_type_1" value="gl_transaction">
1137 <input type="hidden" name="follow_up_trans_info_1" value="| . H($form->{id}) . qq|">
1138 <input type="hidden" name="follow_up_rowcount" value="1">
1142 <th class=listtop>$form->{title}</th>
1145 ($form->{saved_message} ? qq|
1147 <td>$form->{saved_message}</th>
1151 <tr height="5"></tr>
1156 <td colspan="6" align="left">|
1157 . $locale->text("Previous transnumber text")
1158 . " $form->{previous_id} "
1159 . $locale->text("Previous transdate text")
1160 . " $form->{previous_gldate}"
1164 <th align=right>| . $locale->text('Reference') . qq|</th>
1165 <td><input name=reference size=20 value="$form->{reference}" $readonly></td>
1169 <th align=right nowrap>| . $locale->text('Date') . qq|</th>
1178 <th align=right>| . $locale->text('Belegnummer') . qq|</th>
1179 <td><input name=id size=20 value="$form->{id}" $readonly></td>
1183 <th align=right width=50%>| . $locale->text('Buchungsdatum') . qq|</th>
1184 <td align=left><input name=gldate size=11 title="$myconfig{dateformat}" value=$form->{gldate} $readonly onBlur=\"check_right_date_format(this)\"></td>
1195 <th align=right width=1%>| . $locale->text('Description') . qq|</th>
1196 <td width=1%>$description</td>
1200 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1201 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1208 <th align=right width=50%>| . $locale->text('Mitarbeiter') . qq|</th>
1209 <td align=left><input name=employee size=20 value="| . H($form->{employee}) . qq|" readonly></td>
1217 <th align=left width=1%>| . $locale->text('Description') . qq|</th>
1218 <td width=1%>$description</td>
1222 <th align=left>| . $locale->text('MwSt. inkl.') . qq|</th>
1223 <td><input type=checkbox name=taxincluded value=1 $taxincluded></td>
1232 <tr><td colspan=4><table><tr>
1234 | . $locale->text('OB Transaction') . qq|<input type="checkbox" name="ob_transaction" value="1" $ob_transaction_checked>
1237 | . $locale->text('CB Transaction') . qq|<input type="checkbox" name="cb_transaction" value="1" $cb_transaction_checked>
1239 </tr></table></td></tr>
1241 <td width="1%" align="right" nowrap>| . $locale->text('Show details') . qq|</td>
1242 <td width="1%"><input type="checkbox" onclick="show_form_details();" name="show_details" value="1" $show_details_checked></td>
1249 <tr class=listheading>
1250 <th class=listheading style="width:15%">|
1251 . $locale->text('Account') . qq|</th>
1252 <th class=listheading style="width:10%">| . $locale->text('Chart balance') . qq|</th>
1253 <th class=listheading style="width:10%">|
1254 . $locale->text('Debit') . qq|</th>
1255 <th class=listheading style="width:10%">|
1256 . $locale->text('Credit') . qq|</th>
1257 <th class=listheading style="width:10%">|
1258 . $locale->text('Tax') . qq|</th>
1259 <th class=listheading style="width:5%">|
1260 . $locale->text('Taxkey') . qq|</th>|;
1262 if ($form->{show_details}) {
1264 <th class=listheading style="width:20%">| . $locale->text('Source') . qq|</th>
1265 <th class=listheading style="width:20%">| . $locale->text('Memo') . qq|</th>
1266 <th class=listheading style="width:20%">| . $locale->text('Project Number') . qq|</th>
1275 $main::lxdebug->leave_sub();
1280 $main::lxdebug->enter_sub();
1282 $main::auth->assert('general_ledger');
1284 my $form = $main::form;
1285 my %myconfig = %main::myconfig;
1286 my $locale = $main::locale;
1287 my $cgi = $main::cgi;
1289 my $follow_ups_block;
1291 my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
1293 if (@{ $follow_ups} ) {
1294 my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
1295 $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>|;
1299 my ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
1301 my $decimalplaces = ($dec > 2) ? $dec : 2;
1302 my $radieren = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
1305 $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, 2, " ")
1306 } qw(totaldebit totalcredit);
1309 <tr class=listtotal>
1310 <th colspan="3" align=right class=listtotal> $form->{totaldebit}</th>
1311 <th align=right class=listtotal> $form->{totalcredit}</th>
1319 <input name=callback type=hidden value="$form->{callback}">
1326 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1327 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1331 if (!$form->{storno}) {
1332 print qq|<input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|">|;
1335 # Löschen und Ändern von Buchungen nicht mehr möglich (GoB) nur am selben Tag möglich
1336 if (!$form->{locked} && $radieren) {
1338 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|" accesskey="b">
1339 <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|">|;
1343 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1344 <input type="button" class="submit" onclick="follow_up_window()" value="|
1345 . $locale->text('Follow-Up')
1349 if ($form->{draft_id}) {
1350 my $remove_draft_checked = 'checked' if ($form->{remove_draft});
1352 . qq| <input name="remove_draft" id="remove_draft" type="checkbox" class="checkbox" ${remove_draft_checked}>|
1353 . qq| <label for="remove_draft">| . $locale->text('Remove Draft') . qq|</label>\n|
1358 <input class=submit type=submit name=action id=update_button value="| . $locale->text('Update') . qq|">
1359 <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> |
1360 . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'))
1361 . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
1362 . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]);
1371 $main::lxdebug->leave_sub();
1376 $main::lxdebug->enter_sub();
1378 my $form = $main::form;
1379 my $locale = $main::locale;
1386 <form method=post action=gl.pl>
1389 map { $form->{$_} =~ s/\"/"/g } qw(reference description);
1391 delete $form->{header};
1393 foreach my $key (keys %$form) {
1394 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1395 print qq|<input type="hidden" name="$key" value="$form->{$key}">\n|;
1399 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1402 . $locale->text('Are you sure you want to delete Transaction')
1403 . qq| $form->{reference}</h4>
1405 <input name=action class=submit type=submit value="|
1406 . $locale->text('Yes') . qq|">
1409 $main::lxdebug->leave_sub();
1414 $main::lxdebug->enter_sub();
1416 my $form = $main::form;
1417 my %myconfig = %main::myconfig;
1418 my $locale = $main::locale;
1420 if (GL->delete_transaction(\%myconfig, \%$form)){
1421 # saving the history
1422 if(!exists $form->{addition} && $form->{id} ne "") {
1423 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1424 $form->{addition} = "DELETED";
1425 $form->save_history;
1427 # /saving the history
1428 $form->redirect($locale->text('Transaction deleted!'))
1430 $form->error($locale->text('Cannot delete transaction!'));
1431 $main::lxdebug->leave_sub();
1435 sub post_transaction {
1436 $main::lxdebug->enter_sub();
1438 my $form = $main::form;
1439 my %myconfig = %main::myconfig;
1440 my $locale = $main::locale;
1442 # check if there is something in reference and date
1443 $form->isblank("reference", $locale->text('Reference missing!'));
1444 $form->isblank("transdate", $locale->text('Transaction Date missing!'));
1445 $form->isblank("description", $locale->text('Description missing!'));
1447 my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
1448 my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1455 my $creditcount = 0;
1458 my @flds = qw(accno debit credit projectnumber fx_transaction source memo tax taxchart);
1460 for my $i (1 .. $form->{rowcount}) {
1461 next if $form->{"debit_$i"} eq "" && $form->{"credit_$i"} eq "";
1463 for (qw(debit credit tax)) {
1464 $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"});
1468 $debitcredit = ($form->{"debit_$i"} == 0) ? "0" : "1";
1476 if (($debitcount >= 2) && ($creditcount == 2)) {
1477 $form->{"credit_$i"} = 0;
1478 $form->{"tax_$i"} = 0;
1480 $form->{creditlock} = 1;
1482 if (($creditcount >= 2) && ($debitcount == 2)) {
1483 $form->{"debit_$i"} = 0;
1484 $form->{"tax_$i"} = 0;
1486 $form->{debitlock} = 1;
1488 if (($creditcount == 1) && ($debitcount == 2)) {
1489 $form->{creditlock} = 1;
1491 if (($creditcount == 2) && ($debitcount == 1)) {
1492 $form->{debitlock} = 1;
1494 if ($debitcredit && $credittax) {
1495 $form->{"taxchart_$i"} = "0--0.00";
1497 if (!$debitcredit && $debittax) {
1498 $form->{"taxchart_$i"} = "0--0.00";
1500 my $amount = ($form->{"debit_$i"} == 0)
1501 ? $form->{"credit_$i"}
1502 : $form->{"debit_$i"};
1504 if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
1505 $form->{"taxchart_$i"} = "0--0.00";
1506 $form->{"tax_$i"} = 0;
1508 my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
1515 if ($form->{taxincluded}) {
1516 $form->{"tax_$i"} = $amount / ($rate + 1) * $rate;
1518 $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"};
1520 $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"};
1523 $form->{"tax_$i"} = $amount * $rate;
1526 $form->{"tax_$i"} = 0;
1529 for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
1533 for my $i (1 .. $count) {
1535 for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
1538 for my $i ($count + 1 .. $form->{rowcount}) {
1539 for (@flds) { delete $form->{"${_}_$i"} }
1542 my ($debit, $credit, $taxtotal);
1543 for my $i (1 .. $form->{rowcount}) {
1544 my $dr = $form->{"debit_$i"};
1545 my $cr = $form->{"credit_$i"};
1546 my $tax = $form->{"tax_$i"};
1548 $form->error($locale->text('Cannot post transaction with a debit and credit entry for the same account!'));
1550 $debit += $dr + $tax if $dr;
1551 $credit += $cr + $tax if $cr;
1552 $taxtotal += $tax if $form->{taxincluded}
1555 $form->{taxincluded} = 0 if !$taxtotal;
1557 # this is just for the wise guys
1558 $form->error($locale->text('Cannot post transaction for a closed period!'))
1559 if ($form->date_closed($form->{"transdate"}, \%myconfig));
1560 if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
1561 $form->error($locale->text('Out of balance transaction!'));
1564 if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) {
1565 $form->error($locale->text('Empty transaction!'));
1568 if ((my $errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) {
1571 $err[1] = $locale->text('Cannot have a value in both Debit and Credit!');
1572 $err[2] = $locale->text('Debit and credit out of balance!');
1573 $err[3] = $locale->text('Cannot post a transaction without a value!');
1575 $form->error($err[$errno]);
1577 undef($form->{callback});
1578 # saving the history
1579 if(!exists $form->{addition} && $form->{id} ne "") {
1580 $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
1581 $form->{addition} = "SAVED";
1582 $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id};
1583 $form->save_history;
1585 # /saving the history
1587 $main::lxdebug->leave_sub();
1591 $main::lxdebug->enter_sub();
1593 $main::auth->assert('general_ledger');
1595 my $form = $main::form;
1596 my $locale = $main::locale;
1598 if ($::myconfig{mandatory_departments} && !$form->{department}) {
1599 $form->{saved_message} = $::locale->text('You have to specify a department.');
1604 $form->{title} = $locale->text("$form->{title} General Ledger Transaction");
1605 $form->{storno} = 0;
1609 remove_draft() if $form->{remove_draft};
1611 $form->{callback} = build_std_url("action=add", "show_details");
1612 $form->redirect($form->{callback});
1614 $main::lxdebug->leave_sub();
1618 $main::lxdebug->enter_sub();
1620 $main::auth->assert('general_ledger');
1622 my $form = $main::form;
1626 $main::lxdebug->leave_sub();
1631 $main::lxdebug->enter_sub();
1633 $main::auth->assert('general_ledger');
1635 my $form = $main::form;
1636 my %myconfig = %main::myconfig;
1637 my $locale = $main::locale;
1639 # don't cancel cancelled transactions
1640 if (IS->has_storno(\%myconfig, $form, 'gl')) {
1641 $form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
1642 $form->error($locale->text("Transaction has already been cancelled!"));
1645 GL->storno($form, \%myconfig, $form->{id});
1647 # saving the history
1648 if(!exists $form->{addition} && $form->{id} ne "") {
1649 $form->{snumbers} = "ordnumber_$form->{ordnumber}";
1650 $form->{addition} = "STORNO";
1651 $form->save_history;
1653 # /saving the history
1655 $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
1657 $main::lxdebug->leave_sub();
1661 call_sub($main::form->{nextsub});