X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fgl.pl;h=15b49d2e1968df40ac66fbeb1ea4eaae8a032dfa;hb=bb5ee43d0ddff8f8b57ce0f15a5664b26c110d1f;hp=5069cefa7f89fd26cfbab3999b07fa99c7fd153b;hpb=18da4a96827fd65559a6f64334c3d8a313884f84;p=kivitendo-erp.git diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 5069cefa7..15b49d2e1 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -32,13 +32,14 @@ #====================================================================== 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/reportgenerator.pl"; @@ -77,11 +78,11 @@ require "bin/mozilla/reportgenerator.pl"; sub add { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $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 GL->transaction(\%myconfig, \%$form); @@ -119,6 +120,8 @@ sub add { sub prepare_transaction { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + GL->transaction(\%myconfig, \%$form); map { @@ -191,6 +194,8 @@ sub prepare_transaction { sub edit { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + prepare_transaction(); $form->{title} = "Edit"; @@ -208,6 +213,8 @@ sub edit { sub search { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{title} = $locale->text('Journal'); $form->all_departments(\%myconfig); @@ -253,7 +260,7 @@ sub search { $button1 = qq| text('button') . qq|> + . $locale->text('button') . qq|> |; $button2 = qq| @@ -281,7 +288,7 @@ sub search { print qq| -
{script}> + @@ -382,9 +389,6 @@ $jsscript -{login}> -{password}> -
@@ -415,7 +419,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 +451,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 +497,28 @@ 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); + map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno); + 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 +528,8 @@ sub generate_report { $report->set_options_from_form(); # add sort to callback - $form->{callback} = "$callback&sort=" . E($form->{sort}); - - $form->{balance} *= $ml; - - if ($form->{accno} && $form->{balance}) { - my $row = { - 'balance' => { - 'data' => $form->format_amount(\%myconfig, $form->{balance}, 2), - 'align' => 'right', - }, - }; + $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir}); - $report->add_data($row); - } my @totals_columns = qw(debit credit debit_tax credit_tax); my %subtotals = map { $_ => 0 } @totals_columns; @@ -552,7 +537,6 @@ sub generate_report { my $idx = 0; foreach $ref (@{ $form->{GL} }) { - $form->{balance} *= $ml; my %rows; @@ -562,12 +546,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,12 +564,23 @@ sub generate_report { my $row = { }; map { $row->{$_} = { 'data' => '', 'align' => $column_alignment{$_} } } @columns; - $row->{balance}->{data} = $form->format_amount(\%myconfig, $form->{balance}, 2); + 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; $row->{projectnumbers}->{data} = join ", ", sort { lc($a) cmp lc($b) } keys %{ $ref->{projectnumbers} }; - map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description source notes); + map { $row->{$_}->{data} = $ref->{$_} } qw(id reference description notes); - map { $row->{$_}->{data} = \@{ $rows{$_} }; } qw(transdate debit credit debit_accno credit_accno debit_tax_accno credit_tax_accno); + 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)) { $row->{$col}->{link} = [ map { "${callback}&accno=" . E($_) } @{ $rows{$col} } ]; @@ -609,11 +609,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; @@ -639,6 +648,8 @@ sub generate_report { sub update { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{oldtransdate} = $form->{transdate}; my @a = (); @@ -702,22 +713,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 { - $form->{"tax_$i"} = 0; + $credittax = 1; + } + if ($form->{taxincluded}) { + $form->{"tax_$i"} = $amount / ($rate + 1) * $rate; + } else { + $form->{"tax_$i"} = $amount * $rate; } + } else { + $form->{"tax_$i"} = 0; } for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} } @@ -745,6 +754,8 @@ sub display_form { my ($init) = @_; $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + &form_header($init); # for $i (1 .. $form->{rowcount}) { @@ -763,6 +774,8 @@ 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; @@ -790,10 +803,10 @@ sub display_rows { my %charts = (); my $taxchart_init; foreach my $item (@{ $form->{ALL_CHARTS} }) { - my $key = Q($item->{accno}) . "--" . Q($item->{tax_id}); + my $key = $item->{accno} . "--" . $item->{tax_id}; $taxchart_init = $item->{taxkey_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; } @@ -801,20 +814,26 @@ sub display_rows { my @taxchart_values = (); my %taxcharts = (); foreach my $item (@{ $form->{ALL_TAXCHARTS} }) { - my $key = Q($item->{id}) . "--" . Q($item->{rate}); + my $key = $item->{id} . "--" . $item->{rate}; $taxchart_init = $key if ($taxchart_init eq $item->{taxkey}); 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"}); @@ -856,8 +875,6 @@ sub display_rows { . qq||; if ($init) { - $korrektur = - qq||; if ($form->{transfer}) { $fx_transaction = qq| @@ -892,14 +909,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| @@ -930,8 +942,7 @@ sub display_rows { $fx_transaction - - $korrektur + $form->{"tax_$i"} $tax|; if ($form->{show_details}) { @@ -942,6 +953,8 @@ sub display_rows { |; } print qq| + $source_hidden + $memo_hidden |; } @@ -955,12 +968,18 @@ sub display_rows { sub form_header { my ($init) = @_; $lxdebug->enter_sub(); + + $auth->assert('general_ledger'); + $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') @@ -1034,7 +1053,7 @@ sub form_header { $button1 = qq| text('button') . qq|> + . $locale->text('button') . qq|> |; #write Trigger @@ -1053,9 +1072,11 @@ sub form_header { $form->header; print qq| - + + + -{script}> + |; $form->hide_form(qw(id closedto locked storno storno_id previous_id previous_gldate)); @@ -1063,6 +1084,10 @@ sub form_header { print qq| + + + + @@ -1107,7 +1132,7 @@ sub form_header { |; } - print qq| + print qq| $department|; if ($form->{id}) { print qq| @@ -1147,7 +1172,17 @@ sub form_header { |; } - print qq| + print qq| + + + |; @@ -1166,8 +1201,6 @@ sub form_header { - |; if ($form->{show_details}) { @@ -1189,6 +1222,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; @@ -1202,7 +1248,7 @@ sub form_footer { - +
+ + +
+ | . $locale->text('OB Transaction') . qq| + + | . $locale->text('CB Transaction') . qq| +
| . $locale->text('Show details') . qq|
| . $locale->text('Tax') . qq| | - . $locale->text('Korrektur') . qq|| . $locale->text('Taxkey') . qq|
$form->{totaldebit} $form->{totalcredit} $form->{totalcredit}
@@ -1210,11 +1256,10 @@ sub form_footer { -{login}> -{password}> - +$follow_ups_block +
|; @@ -1234,12 +1279,16 @@ sub form_footer { |; } + print qq| + + |; + } else { - if ($transdate > $closedto) { print qq| |; - } } print " @@ -1260,7 +1309,7 @@ sub delete { print qq| -{script}> + |; map { $form->{$_} =~ s/\"/"/g } qw(reference description); @@ -1268,6 +1317,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|; } @@ -1295,7 +1345,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!')); @@ -1373,33 +1423,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; - } - 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; + $form->{"credit_$i"} = $form->{"credit_$i"} - $form->{"tax_$i"}; } } 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"} } @@ -1426,20 +1468,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!'); @@ -1453,10 +1495,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(); } @@ -1464,6 +1506,8 @@ sub post_transaction { sub post { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{title} = $locale->text("$form->{title} General Ledger Transaction"); $form->{storno} = 0; @@ -1478,6 +1522,8 @@ sub post { sub post_as_new { $lxdebug->enter_sub(); + $auth->assert('general_ledger'); + $form->{id} = 0; &add; $lxdebug->leave_sub(); @@ -1487,6 +1533,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"); @@ -1501,10 +1549,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}); +}