X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fgl.pl;h=7516cf8d11e5d42e995ff0c53766396127f2f713;hb=875873f10da35c4359e4bc994e709c247aab905e;hp=6c4b413560a9c60e7a149de45fb72e3b875b124f;hpb=8c7e44938a661e035f62840e1e177353240ace5d;p=kivitendo-erp.git
diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl
index 6c4b41356..7516cf8d1 100644
--- a/bin/mozilla/gl.pl
+++ b/bin/mozilla/gl.pl
@@ -32,13 +32,16 @@
#======================================================================
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/common.pl";
+require "bin/mozilla/drafts.pl";
require "bin/mozilla/reportgenerator.pl";
1;
@@ -78,6 +81,8 @@ sub add {
$auth->assert('general_ledger');
+ return $lxdebug->leave_sub() if (load_draft_maybe());
+
$form->{title} = "Add";
$form->{callback} = "gl.pl?action=add" unless $form->{callback};
@@ -258,7 +263,7 @@ sub search {
$button1 = qq|
text('button') . qq|> |
+ . $locale->text('button') . qq|>
|;
$button2 = qq|
@@ -419,7 +424,7 @@ sub generate_report {
$auth->assert('general_ledger');
- $form->{sort} ||= "transdate";
+ report_generator_set_default_sort('transdate', 1);
GL->all_transactions(\%myconfig, \%$form);
@@ -449,38 +454,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';
@@ -509,23 +500,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',
@@ -535,20 +532,8 @@ sub generate_report {
$report->set_options_from_form();
# add sort to callback
- $form->{callback} = "$callback&sort=" . E($form->{sort});
+ $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir});
- $form->{balance} *= $ml;
-
- 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;
@@ -556,7 +541,6 @@ sub generate_report {
my $idx = 0;
foreach $ref (@{ $form->{GL} }) {
- $form->{balance} *= $ml;
my %rows;
@@ -566,12 +550,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} }) ];
}
@@ -579,12 +568,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} } ];
@@ -613,11 +613,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;
@@ -708,22 +717,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"} }
@@ -777,17 +784,6 @@ sub display_rows {
$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"} }) {
@@ -800,10 +796,10 @@ 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);
+ 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;
}
@@ -811,20 +807,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"});
@@ -842,13 +843,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,
@@ -866,8 +867,6 @@ sub display_rows {
. qq| | |;
if ($init) {
- $korrektur =
- qq| | |;
if ($form->{transfer}) {
$fx_transaction = qq|
|
@@ -902,14 +901,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|
|
@@ -937,11 +931,11 @@ sub display_rows {
print qq|
$accno
+ |
$fx_transaction
|
|
- |
- $korrektur
+ $form->{"tax_$i"} |
$tax|;
if ($form->{show_details}) {
@@ -952,6 +946,8 @@ sub display_rows {
|;
}
print qq|
+ $source_hidden
+ $memo_hidden
|;
}
@@ -968,12 +964,28 @@ sub form_header {
$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')
@@ -982,7 +994,8 @@ sub form_header {
$form->{javascript} = qq||;
- $form->{javascript} .= qq||;
+
+
+
+|;
$form->{selectdepartment} =~ s/ selected//;
$form->{selectdepartment} =~
@@ -1047,7 +1061,7 @@ sub form_header {
$button1 = qq|
text('button') . qq|> |
+ . $locale->text('button') . qq|>
|;
#write Trigger
@@ -1063,10 +1077,14 @@ sub form_header {
$form->{previous_id} ||= "--";
$form->{previous_gldate} ||= "--";
+ $jsscript .= $form->parse_html_template('gl/form_header_chart_balances_js');
+
$form->header;
print qq|
-
+
+
+