X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fgl.pl;h=ae476bd17ee77a78bc52bb50664f8adc1087b4e2;hb=a25cb06e5823fc35924c0eae0c358763841307d0;hp=0fd863e514d7a91079c82572a364c0cd49a985f7;hpb=7a1f60ec2df4d0d0a1b546f186df7bb968b8f498;p=kivitendo-erp.git diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 0fd863e51..ae476bd17 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -32,15 +32,17 @@ #====================================================================== use POSIX qw(strftime); +use List::Util qw(sum); +use SL::FU; use SL::GL; use SL::IS; use SL::PE; use SL::ReportGenerator; -require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; -require "bin/mozilla/report_generator.pl"; +require "bin/mozilla/drafts.pl"; +require "bin/mozilla/reportgenerator.pl"; 1; @@ -77,13 +79,16 @@ require "bin/mozilla/report_generator.pl"; sub add { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + + return $lxdebug->leave_sub() if (load_draft_maybe()); + $form->{title} = "Add"; - $form->{callback} = - "$form->{script}?action=add&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; + $form->{callback} = "gl.pl?action=add" unless $form->{callback}; # we use this only to set a default date + # yep. aber er holt hier auch schon ALL_CHARTS. Aufwand / Nutzen? jb GL->transaction(\%myconfig, \%$form); map { @@ -119,6 +124,8 @@ sub add { sub prepare_transaction { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + GL->transaction(\%myconfig, \%$form); map { @@ -191,6 +198,8 @@ sub prepare_transaction { sub edit { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + prepare_transaction(); $form->{title} = "Edit"; @@ -208,6 +217,8 @@ sub edit { sub search { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{title} = $locale->text('Journal'); $form->all_departments(\%myconfig); @@ -253,7 +264,7 @@ sub search { $button1 = qq| text('button') . qq|> + . $locale->text('button') . qq|> |; $button2 = qq| @@ -281,7 +292,7 @@ sub search { print qq| -
{script}> + @@ -382,9 +393,6 @@ $jsscript -{login}> -{password}> -
@@ -415,7 +423,9 @@ sub create_subtotal_row { sub generate_report { $lxdebug->enter_sub(); - $form->{sort} ||= "transdate"; + $auth->assert('general_ledger'); + + report_generator_set_default_sort('transdate', 1); GL->all_transactions(\%myconfig, \%$form); @@ -445,38 +455,24 @@ sub generate_report { my @hidden_variables = qw(accno source reference department description notes project_id datefrom dateto category l_subtotal); push @hidden_variables, map { "l_${_}" } @columns; - my (@options, $date_option); - if ($form->{accno}) { - push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}"; - } - if ($form->{source}) { - push @options, $locale->text('Source') . " : $form->{source}"; - } - if ($form->{reference}) { - push @options, $locale->text('Reference') . " : $form->{reference}"; - } + my (@options, @date_options); + push @options, $locale->text('Account') . " : $form->{accno} $form->{account_description}" if ($form->{accno}); + push @options, $locale->text('Source') . " : $form->{source}" if ($form->{source}); + push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference}); + push @options, $locale->text('Description') . " : $form->{description}" if ($form->{description}); + push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes}); + + push @date_options, $locale->text('From'), $locale->date(\%myconfig, $form->{datefrom}, 1) if ($form->{datefrom}); + push @date_options, $locale->text('Bis'), $locale->date(\%myconfig, $form->{dateto}, 1) if ($form->{dateto}); + push @options, join(' ', @date_options) if (scalar @date_options); + if ($form->{department}) { my ($department) = split /--/, $form->{department}; push @options, $locale->text('Department') . " : $department"; } - if ($form->{description}) { - push @options, $locale->text('Description') . " : $form->{description}"; - } - if ($form->{notes}) { - push @options, $locale->text('Notes') . " : $form->{notes}"; - } - if ($form->{datefrom}) { - $date_option = $locale->text('From') . " " . $locale->date(\%myconfig, $form->{datefrom}, 1); - } - if ($form->{dateto}) { - if ($form->{datefrom}) { - $date_option .= " "; - } - $date_option .= $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{dateto}, 1); - } - push @options, $date_option if $date_option; - my $callback = build_std_url('action=generate_report', @hidden_variables); + + my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables); $form->{l_credit_accno} = 'Y'; $form->{l_debit_accno} = 'Y'; @@ -505,23 +501,29 @@ sub generate_report { 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), }, ); - map { $column_defs{$_}->{link} = $callback . "&sort=${_}" } qw(id transdate reference source description); - map { $column_defs{$_}->{link} = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax); + foreach my $name (qw(id transdate reference description debit_accno credit_accno debit_tax_accno credit_tax_accno)) { + my $sortname = $name =~ m/accno/ ? 'accno' : $name; + my $sortdir = $sortname eq $form->{sort} ? 1 - $form->{sortdir} : $form->{sortdir}; + $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir"; + } + map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno}; my %column_alignment; - map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax); - map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno); + map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax balance); + map { $column_alignment{$_} = 'center' } qw(reference debit_accno credit_accno debit_tax_accno credit_tax_accno); + map { $column_alignment{$_} = 'left' } qw(description source notes); + map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment; my $report = SL::ReportGenerator->new(\%myconfig, $form); $report->set_columns(%column_defs); $report->set_column_order(@columns); - $report->set_export_options('generate_report', @hidden_variables); + $report->set_export_options('generate_report', @hidden_variables, qw(sort sortdir)); - $report->set_sort_indicator($form->{sort}, 1); + $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir}); $report->set_options('top_info_text' => join("\n", @options), 'output_format' => 'HTML', @@ -531,20 +533,8 @@ sub generate_report { $report->set_options_from_form(); # add sort to callback - $form->{callback} = "$callback&sort=" . E($form->{sort}); - - $form->{balance} *= $ml; + $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir}); - if ($form->{accno} && $form->{balance}) { - my $row = { - 'balance' => { - 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2), - 'align' => 'right', - }, - }; - - $report->add_data($row); - } my @totals_columns = qw(debit credit debit_tax credit_tax); my %subtotals = map { $_ => 0 } @totals_columns; @@ -552,7 +542,6 @@ sub generate_report { my $idx = 0; foreach $ref (@{ $form->{GL} }) { - $form->{balance} *= $ml; my %rows; @@ -562,12 +551,17 @@ sub generate_report { my $value = $ref->{$key}->{$idx}; $subtotals{$key} += $value; $totals{$key} += $value; - $form->{balance} = abs($form->{balance}) - abs($value); + if ($key =~ /debit.*/) { + $ml = -1; + } else { + $ml = 1; + } + $form->{balance} = $form->{balance} + $value * $ml; push @{ $rows{$key} }, $form->format_amount(\%myconfig, $value, 2); } } - foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate)) { + foreach my $key (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno ac_transdate source)) { my $col = $key eq 'ac_transdate' ? 'transdate' : $key; $rows{$col} = [ map { $ref->{$key}->{$_} } sort keys(%{ $ref->{$key} }) ]; } @@ -575,23 +569,30 @@ sub generate_report { my $row = { }; map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns; - $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2); - $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} }; + my $sh = ""; + if ($form->{balance} < 0) { + $sh = " S"; + $ml = -1; + } elsif ($form->{balance} > 0) { + $sh = " H"; + $ml = 1; + } + my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2); + $data .= $sh; - map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes); + $row->{balance}->{data} = $data; + $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} }; - map { $row->{$_}->{data} = join "\n", @{ $rows{$_} }; } qw(transdate debit credit); + map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes); - map { $row->{$_}->{data} = join "\n", @{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax); + map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno source); foreach my $col (qw(debit_accno credit_accno debit_tax_accno credit_tax_accno)) { - if (lc $report->{options}->{output_format} eq 'html') { - $row->{$col}->{raw_data} = join "
", map { "$_" } @{ $rows{$col} }; - } else { - $row->{$col}->{data} = join "\n", @{ $rows{$col} }; - } + $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ]; } + map { $row->{$_}->{data} = \@{ $rows{$_} } if ($ref->{"${_}_accno"} ne "") } qw(debit_tax credit_tax); + $row->{reference}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'id=' . E($ref->{id}), 'callback'); my $row_set = [ $row ]; @@ -613,11 +614,20 @@ sub generate_report { my $balanced_ledger = $totals{debit} + $totals{debit_tax} - $totals{credit} - $totals{credit_tax}; my $row = create_subtotal_row(\%totals, \@columns, \%column_alignment, [ qw(debit credit debit_tax credit_tax) ], 'listtotal'); - $row->{balance} = { - 'data' => $form->format_amount(\%myconfig, $form->{balance} * $ml, 2), - 'align' => 'right', - 'class' => 'listtotal', - }; + + my $sh = ""; + if ($form->{balance} < 0) { + $sh = " S"; + $ml = -1; + } elsif ($form->{balance} > 0) { + $sh = " H"; + $ml = 1; + } + my $data = $form->format_amount(\%myconfig, ($form->{balance} * $ml), 2); + $data .= $sh; + + $row->{balance}->{data} = $data; + $report->add_data($row); my $raw_bottom_info_text; @@ -643,6 +653,8 @@ sub generate_report { sub update { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{oldtransdate} = $form->{transdate}; my @a = (); @@ -706,22 +718,20 @@ sub update { $form->{"taxchart_$i"} = "0--0.00"; $form->{"tax_$i"} = 0; } - if (!$form->{"korrektur_$i"}) { - ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); - if ($taxkey > 1) { - if ($debitcredit) { - $debittax = 1; - } else { - $credittax = 1; - } - if ($form->{taxincluded}) { - $form->{"tax_$i"} = $amount / ($rate + 1) * $rate; - } else { - $form->{"tax_$i"} = $amount * $rate; - } + ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + if ($taxkey > 1) { + if ($debitcredit) { + $debittax = 1; + } else { + $credittax = 1; + } + if ($form->{taxincluded}) { + $form->{"tax_$i"} = $amount / ($rate + 1) * $rate; } else { - $form->{"tax_$i"} = 0; + $form->{"tax_$i"} = $amount * $rate; } + } else { + $form->{"tax_$i"} = 0; } for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } @@ -749,6 +759,8 @@ sub display_form { my ($init) = @_; $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + &form_header($init); # for $i (1 .. $form->{rowcount}) { @@ -767,21 +779,12 @@ sub display_rows { my ($init) = @_; $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{debit_1} = 0 if !$form->{"debit_1"}; $form->{totaldebit} = 0; $form->{totalcredit} = 0; - my @old_project_ids = (); - map({ push(@old_project_ids, $form->{"project_id_$_"}) - if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"})); - - $form->get_lists("projects" => { "key" => "ALL_PROJECTS", - "all" => 0, - "old_id" => \@old_project_ids }, - "charts" => { "key" => "ALL_CHARTS", - "transdate" => $form->{transdate} }, - "taxcharts" => "ALL_TAXCHARTS"); - my %project_labels = (); my @project_values = (""); foreach my $item (@{ $form->{"ALL_PROJECTS"} }) { @@ -794,10 +797,13 @@ sub display_rows { my %charts = (); my $taxchart_init; foreach my $item (@{ $form->{ALL_CHARTS} }) { - my $key = Q($item->{accno}) . "--" . Q($item->{tax_id}); - $taxchart_init = $item->{taxkey_id} unless (@chart_values); + if ($item->{charttype} eq 'H'){ #falls überschrift + next; #überspringen (Bug 1150) + } + my $key = $item->{accno} . "--" . $item->{tax_id}; + $taxchart_init = $item->{tax_id} unless (@chart_values); push(@chart_values, $key); - $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description}); + $chart_labels{$key} = $item->{accno} . "--" . $item->{description}; $charts{$item->{accno}} = $item; } @@ -805,20 +811,25 @@ sub display_rows { my @taxchart_values = (); my %taxcharts = (); foreach my $item (@{ $form->{ALL_TAXCHARTS} }) { - my $key = Q($item->{id}) . "--" . Q($item->{rate}); - $taxchart_init = $key if ($taxchart_init eq $item->{taxkey}); + my $key = $item->{id} . "--" . $item->{rate}; + $taxchart_init = $key if ($taxchart_init == $item->{id}); push(@taxchart_values, $key); - $taxchart_labels{$key} = H($item->{taxdescription}) . " " . - H($item->{rate} * 100) . ' %'; + $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %'; $taxcharts{$item->{id}} = $item; } for $i (1 .. $form->{rowcount}) { - - $source = qq| - |; - $memo = qq| - |; + if ($form->{show_details}) { + $source = qq| + |; + $memo = qq| + |; + } else { + $source_hidden = qq| + |; + $memo_hidden = qq| + |; + } my $selected_accno_full; my ($accno_row) = split(/--/, $form->{"accno_$i"}); @@ -836,13 +847,13 @@ sub display_rows { $selected_taxchart = "$item->{id}--$item->{rate}"; } - $selected_accno = '' if ($init); - $selected_taxchart = $taxchart_init unless ($selected_taxchart ne ""); + $selected_accno = '' if ($init); + $selected_taxchart ||= $taxchart_init; $accno = qq|| . NTI($cgi->popup_menu('-name' => "accno_$i", '-id' => "accno_$i", - '-onChange' => "setTaxkey(this, $i)", + '-onChange' => "setTaxkey($i)", '-style' => 'width:200px', '-values' => \@chart_values, '-labels' => \%chart_labels, @@ -860,8 +871,6 @@ sub display_rows { . qq||; if ($init) { - $korrektur = - qq||; if ($form->{transfer}) { $fx_transaction = qq| @@ -896,14 +905,9 @@ sub display_rows { $x |; } - $checked = ($form->{"korrektur_$i"}) ? "checked" : ""; - $korrektur = - qq||; $form->hide_form("accno_$i"); } else { - $korrektur = - qq||; if ($form->{transfer}) { $fx_transaction = qq| @@ -931,11 +935,11 @@ sub display_rows { print qq| $accno +   $fx_transaction - - $korrektur + $form->{"tax_$i"} $tax|; if ($form->{show_details}) { @@ -946,6 +950,8 @@ sub display_rows { |; } print qq| + $source_hidden + $memo_hidden |; } @@ -959,12 +965,31 @@ sub display_rows { sub form_header { my ($init) = @_; $lxdebug->enter_sub(); + + $auth->assert('general_ledger'); + + my @old_project_ids = (); + map({ push(@old_project_ids, $form->{"project_id_$_"}) + if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"})); + + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "charts" => { "key" => "ALL_CHARTS", + "transdate" => $form->{transdate} }, + "taxcharts" => "ALL_TAXCHARTS"); + + GL->get_chart_balances('charts' => $form->{ALL_CHARTS}); + $title = $form->{title}; $form->{title} = $locale->text("$title General Ledger Transaction"); $readonly = ($form->{id}) ? "readonly" : ""; $show_details_checked = "checked" if $form->{show_details}; + $ob_transaction_checked = "checked" if $form->{ob_transaction}; + $cb_transaction_checked = "checked" if $form->{cb_transaction}; + # $locale->text('Add General Ledger Transaction') # $locale->text('Edit General Ledger Transaction') @@ -973,7 +998,8 @@ sub form_header { $form->{javascript} = qq||; - $form->{javascript} .= qq||; + + + +|; $form->{selectdepartment} =~ s/ selected//; $form->{selectdepartment} =~ @@ -1038,7 +1065,7 @@ sub form_header { $button1 = qq| text('button') . qq|> + . $locale->text('button') . qq|> |; #write Trigger @@ -1054,12 +1081,16 @@ sub form_header { $form->{previous_id} ||= "--"; $form->{previous_gldate} ||= "--"; + $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js'); + $form->header; print qq| - + -{script}> + + + |; $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate)); @@ -1067,6 +1098,10 @@ sub form_header { print qq| + + + + @@ -1111,7 +1146,7 @@ sub form_header { |; } - print qq| + print qq| $department|; if ($form->{id}) { print qq| @@ -1151,7 +1186,17 @@ sub form_header { |; } - print qq| + print qq| + + + |; @@ -1163,6 +1208,7 @@ sub form_header { + - |; if ($form->{show_details}) { @@ -1193,6 +1237,19 @@ $jsscript sub form_footer { $lxdebug->enter_sub(); + + $auth->assert('general_ledger'); + + my $follow_ups_block; + if ($form->{id}) { + my $follow_ups = FU->follow_ups('trans_id' => $form->{id}); + + if (@{ $follow_ups} ) { + my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups }; + $follow_ups_block = qq|

| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|

|; + } + } + ($dec) = ($form->{totaldebit} =~ /\.(\d+)/); $dec = length $dec; $decimalplaces = ($dec > 2) ? $dec : 2; @@ -1204,9 +1261,8 @@ sub form_footer { print qq| - - - + +
+ + +
+ | . $locale->text('OB Transaction') . qq| + + | . $locale->text('CB Transaction') . qq| +
| . $locale->text('Show details') . qq|
| . $locale->text('Account') . qq|| . $locale->text('Chart balance') . qq| | . $locale->text('Debit') . qq| | @@ -1170,8 +1216,6 @@ sub form_header { | . $locale->text('Tax') . qq| | - . $locale->text('Korrektur') . qq|| . $locale->text('Taxkey') . qq|
$form->{totaldebit} $form->{totalcredit} $form->{totaldebit} $form->{totalcredit}
@@ -1214,11 +1270,10 @@ sub form_footer { -{login}> -{password}> - +$follow_ups_block +
|; @@ -1238,12 +1293,27 @@ sub form_footer { |; } - } else { - if ($transdate > $closedto) { - print qq| + print qq| - |; + |; + + } else { + if ($form->{draft_id}) { + my $remove_draft_checked = 'checked' if ($form->{remove_draft}); + print qq|

\n| + . qq| | + . qq| \n| + . qq|

\n|; } + + print qq| + + | + . NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit')) + . $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}]) + . $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]); } print " @@ -1264,7 +1334,7 @@ sub delete { print qq| -{script}> + |; map { $form->{$_} =~ s/\"/"/g } qw(reference description); @@ -1272,6 +1342,7 @@ sub delete { delete $form->{header}; foreach $key (keys %$form) { + next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key})); print qq|\n|; } @@ -1299,7 +1370,7 @@ sub yes { $form->{addition} = "DELETED"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history $form->redirect($locale->text('Transaction deleted!')) } $form->error($locale->text('Cannot delete transaction!')); @@ -1377,33 +1448,25 @@ sub post_transaction { $form->{"taxchart_$i"} = "0--0.00"; $form->{"tax_$i"} = 0; } - if (!$form->{"korrektur_$i"}) { - ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); - if ($taxkey > 1) { + ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + if ($taxkey > 1) { + if ($debitcredit) { + $debittax = 1; + } else { + $credittax = 1; + } + if ($form->{taxincluded}) { + $form->{"tax_$i"} = $amount / ($rate + 1) * $rate; if ($debitcredit) { - $debittax = 1; + $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"}; } else { - $credittax = 1; + $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"}; } - if ($form->{taxincluded}) { - $form->{"tax_$i"} = $amount / ($rate + 1) * $rate; - if ($debitcredit) { - $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"}; - } else { - $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"}; - } - } else { - $form->{"tax_$i"} = $amount * $rate; - } - } else { - $form->{"tax_$i"} = 0; - } - } elsif ($form->{taxincluded}) { - if ($debitcredit) { - $form->{"debit_$i"} = $form->{"debit_$i"} - $form->{"tax_$i"}; } else { - $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"}; + $form->{"tax_$i"} = $amount * $rate; } + } else { + $form->{"tax_$i"} = 0; } for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } @@ -1430,20 +1493,20 @@ sub post_transaction { $credit += $cr + $tax if $cr; $taxtotal += $tax if $form->{taxincluded} } - + $form->{taxincluded} = 0 if !$taxtotal; # this is just for the wise guys $form->error($locale->text('Cannot post transaction for a closed period!')) - if ($transdate <= $closedto); + if ($form->date_closed($form->{"transdate"}, \%myconfig)); if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) { $form->error($locale->text('Out of balance transaction!')); } - + if ($form->round_amount($debit, 2) + $form->round_amount($credit, 2) == 0) { $form->error($locale->text('Empty transaction!')); } - + if (($errno = GL->post_transaction(\%myconfig, \%$form)) <= -1) { $errno *= -1; $err[1] = $locale->text('Cannot have a value in both Debit and Credit!'); @@ -1457,10 +1520,10 @@ sub post_transaction { if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber}; $form->{addition} = "SAVED"; - $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; + $form->{what_done} = $locale->text("Buchungsnummer") . " = " . $form->{id}; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history $lxdebug->leave_sub(); } @@ -1468,11 +1531,15 @@ sub post_transaction { sub post { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{title} = $locale->text("$form->{title} General Ledger Transaction"); $form->{storno} = 0; post_transaction(); + remove_draft() if $form->{remove_draft}; + $form->{callback} = build_std_url("action=add", "show_details"); $form->redirect($form->{callback}); @@ -1482,6 +1549,8 @@ sub post { sub post_as_new { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{id} = 0; &add; $lxdebug->leave_sub(); @@ -1491,6 +1560,8 @@ sub post_as_new { sub storno { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + # don't cancel cancelled transactions if (IS->has_storno(\%myconfig, $form, 'gl')) { $form->{title} = $locale->text("Cancel Accounts Receivables Transaction"); @@ -1505,10 +1576,13 @@ sub storno { $form->{addition} = "STORNO"; $form->save_history($form->dbconnect(\%myconfig)); } - # /saving the history + # /saving the history - $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); + $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id}); $lxdebug->leave_sub(); } +sub continue { + call_sub($form->{nextsub}); +}