X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fgl.pl;h=3887720decf369e29f46474bf0618d1b0bfe3de6;hb=21e3b9697fa7e9481b79d0f16ef8cc5d0892f299;hp=a34572fbfe07978f6dc3db206a6e2de1d1bee8ce;hpb=d319704a66e9be64da837ccea10af6774c2b0838;p=kivitendo-erp.git
diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl
index a34572fbf..3887720de 100644
--- a/bin/mozilla/gl.pl
+++ b/bin/mozilla/gl.pl
@@ -31,12 +31,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;
-use Data::Dumper;
-
-require "$form->{path}/arap.pl";
+require "bin/mozilla/common.pl";
+require "bin/mozilla/reportgenerator.pl";
1;
@@ -73,38 +78,27 @@ require "$form->{path}/arap.pl";
sub add {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{title} = "Add";
- $form->{callback} =
- "$form->{script}?action=add&path=$form->{path}&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);
- map {
- $chart .=
- ""
- } @{ $form->{chart} };
map {
$tax .=
- qq|"
- } @{ $form->{chart} };
- $form->{chart} = $chart;
map {
$tax .=
- qq|";
- $form->{debitchart} =
- "";
- } else {
- $form->{creditchart} = $form->{chart};
- $form->{creditchart} =~
- s/value=\"$form->{creditchartselected}\"/value=\"$form->{creditchartselected}\" selected/;
+ if (($debitcount >= 2) && ($creditcount == 2)) {
+ $form->{"credit_$i"} = 0;
+ $form->{"tax_$i"} = 0;
+ $creditcount--;
+ $creditlock = 1;
+ }
+ if (($creditcount >= 2) && ($debitcount == 2)) {
+ $form->{"debit_$i"} = 0;
+ $form->{"tax_$i"} = 0;
+ $debitcount--;
+ $debitlock = 1;
+ }
+ if (($creditcount == 1) && ($debitcount == 2)) {
+ $creditlock = 1;
+ }
+ if (($creditcount == 2) && ($debitcount == 1)) {
+ $debitlock = 1;
+ }
+ if ($debitcredit && $credittax) {
+ $form->{"taxchart_$i"} = "0--0.00";
+ }
+ if (!$debitcredit && $debittax) {
+ $form->{"taxchart_$i"} = "0--0.00";
+ }
+ $amount =
+ ($form->{"debit_$i"} == 0)
+ ? $form->{"credit_$i"}
+ : $form->{"debit_$i"};
+ $j = $#a;
+ if (($debitcredit && $credittax) || (!$debitcredit && $debittax)) {
+ $form->{"taxchart_$i"} = "0--0.00";
+ $form->{"tax_$i"} = 0;
+ }
+ ($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;
+ }
+ } else {
+ $form->{"tax_$i"} = 0;
+ }
- $form->{debitchart} = $form->{chart};
- $form->{debitchart} =~
- s/value=\"$form->{debitchartselected}\"/value=\"$form->{debitchartselected}\" selected/;
- }
- ($debitaccno, $debittaxkey) = split(/--/, $form->{debitchartselected});
- ($creditaccno, $credittaxkey) = split(/--/, $form->{creditchartselected});
- if ($debittaxkey > 0) {
- $form->{taxchart} = $form->unescape($form->{taxchart});
- $form->{taxchart} =~ s/selected//ig;
- $form->{taxchart} =~
- s/\"$debittaxkey--([^\"]*)\"/\"$debittaxkey--$1\" selected/;
-
- $rate = $1;
-
- if ($form->{taxincluded}) {
- $form->{debit} =
- $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1);
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{tax} =
- $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1) * $rate;
- } else {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} =
- $form->parse_amount(\%myconfig, $form->{amount}) * ($rate + 1);
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) * $rate;
- }
- } else {
- $form->{taxchart} = $form->unescape($form->{taxchart});
- $form->{taxchart} =~ s/selected//ig;
- $form->{taxchart} =~
- s/\"$credittaxkey--([^\"]*)\"/\"$credittaxkey--$1\" selected/;
- $rate = $1;
-
- if ($form->{taxincluded}) {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} =
- $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1);
- $form->{tax} =
- $form->parse_amount(\%myconfig, $form->{amount}) / ($rate + 1) * $rate;
- } else {
- $form->{debit} =
- $form->parse_amount(\%myconfig, $form->{amount}) * ($rate + 1);
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{tax} = $form->parse_amount(\%myconfig, $form->{amount}) * $rate;
+ for (@flds) { $a[$j]->{$_} = $form->{"${_}_$i"} }
+ $count++;
}
}
- if ($form->{credit_splited}) {
- $form->{debit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{credit} = $credit_save;
- $form->{tax} = 0;
- } elsif ($form->{debit_splited}) {
- $form->{credit} = $form->parse_amount(\%myconfig, $form->{amount}) * 1;
- $form->{debit} = $debit_save;
- $form->{tax} = 0;
+
+ for $i (1 .. $count) {
+ $j = $i - 1;
+ for (@flds) { $form->{"${_}_$i"} = $a[$j]->{$_} }
+ }
+
+ for $i ($count + 1 .. $form->{rowcount}) {
+ for (@flds) { delete $form->{"${_}_$i"} }
}
- &check_project;
- &display_form;
+ $form->{rowcount} = $count + 1;
+ &display_form;
$lxdebug->leave_sub();
+
}
sub display_form {
+ my ($init) = @_;
$lxdebug->enter_sub();
- &form_header;
+ $auth->assert('general_ledger');
+
+ &form_header($init);
# for $i (1 .. $form->{rowcount}) {
# $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
@@ -991,30 +752,256 @@ sub display_form {
#
# &form_row($i);
# }
-
+ &display_rows($init);
&form_footer;
+ $lxdebug->leave_sub();
+
+}
+
+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"} }) {
+ push(@project_values, $item->{"id"});
+ $project_labels{$item->{"id"}} = $item->{"projectnumber"};
+ }
+
+ my %chart_labels = ();
+ my @chart_values = ();
+ my %charts = ();
+ my $taxchart_init;
+ foreach my $item (@{ $form->{ALL_CHARTS} }) {
+ my $key = $item->{accno} . "--" . $item->{tax_id};
+ $taxchart_init = $item->{taxkey_id} unless (@chart_values);
+ push(@chart_values, $key);
+ $chart_labels{$key} = $item->{accno} . "--" . $item->{description};
+ $charts{$item->{accno}} = $item;
+ }
+
+ my %taxchart_labels = ();
+ my @taxchart_values = ();
+ my %taxcharts = ();
+ foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
+ my $key = $item->{id} . "--" . $item->{rate};
+ $taxchart_init = $key if ($taxchart_init eq $item->{taxkey});
+ push(@taxchart_values, $key);
+ $taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %';
+ $taxcharts{$item->{id}} = $item;
+ }
+
+ for $i (1 .. $form->{rowcount}) {
+
+ 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"});
+ my $item = $charts{$accno_row};
+ $selected_accno_full = "$item->{accno}--$item->{tax_id}";
+
+ my $selected_taxchart = $form->{"taxchart_$i"};
+ my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
+ my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"});
+
+ if ($previous_accno &&
+ ($previous_accno eq $selected_accno) &&
+ ($previous_tax_id ne $selected_tax_id)) {
+ my $item = $taxcharts{$selected_tax_id};
+ $selected_taxchart = "$item->{id}--$item->{rate}";
+ }
+
+ $selected_accno = '' if ($init);
+ $selected_taxchart = $taxchart_init unless ($selected_taxchart ne "");
+
+ $accno = qq|| .
+ NTI($cgi->popup_menu('-name' => "accno_$i",
+ '-id' => "accno_$i",
+ '-onChange' => "setTaxkey(this, $i)",
+ '-style' => 'width:200px',
+ '-values' => \@chart_values,
+ '-labels' => \%chart_labels,
+ '-default' => $selected_accno_full))
+ . $cgi->hidden('-name' => "previous_accno_$i",
+ '-default' => $selected_accno_full)
+ . qq| | |;
+ $tax = qq|| .
+ NTI($cgi->popup_menu('-name' => "taxchart_$i",
+ '-id' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $selected_taxchart))
+ . qq| | |;
+
+ if ($init) {
+ if ($form->{transfer}) {
+ $fx_transaction = qq|
+ |
+ |;
+ }
+
+ } else {
+ if ($form->{"debit_$i"} != 0) {
+ $form->{totaldebit} += $form->{"debit_$i"};
+ if (!$form->{taxincluded}) {
+ $form->{totaldebit} += $form->{"tax_$i"};
+ }
+ } else {
+ $form->{totalcredit} += $form->{"credit_$i"};
+ if (!$form->{taxincluded}) {
+ $form->{totalcredit} += $form->{"tax_$i"};
+ }
+ }
+
+ for (qw(debit credit tax)) {
+ $form->{"${_}_$i"} =
+ ($form->{"${_}_$i"})
+ ? $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2)
+ : "";
+ }
+
+ if ($i < $form->{rowcount}) {
+ if ($form->{transfer}) {
+ $checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
+ $x = ($checked) ? "x" : "";
+ $fx_transaction = qq|
+ $x |
+ |;
+ }
+ $form->hide_form("accno_$i");
+
+ } else {
+ if ($form->{transfer}) {
+ $fx_transaction = qq|
+ |
+ |;
+ }
+ }
+ }
+ my $debitreadonly = "";
+ my $creditreadonly = "";
+ if ($i == $form->{rowcount}) {
+ if ($debitlock) {
+ $debitreadonly = "readonly";
+ } elsif ($creditlock) {
+ $creditreadonly = "readonly";
+ }
+ }
+
+ my $projectnumber =
+ NTI($cgi->popup_menu('-name' => "project_id_$i",
+ '-values' => \@project_values,
+ '-labels' => \%project_labels,
+ '-default' => $form->{"project_id_$i"} ));
+
+ my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1;
+
+ print qq|
+ $accno
+ $fx_transaction
+ |
+ |
+ $form->{"tax_$i"} |
+ $tax|;
+
+ if ($form->{show_details}) {
+ print qq|
+ $source
+ $memo
+ $projectnumber |
+|;
+ }
+ print qq|
+ $source_hidden
+ $memo_hidden
+
+|;
+ }
+
+ $form->hide_form(qw(rowcount selectaccno));
$lxdebug->leave_sub();
+
}
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" : "";
- $form->{urldebit} =
- "$form->{script}?action=split_debit&path=$form->{path}&login=$form->{login}&password=$form->{password}";
- $form->{urlcredit} =
- "$form->{script}?action=split_credit&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+ $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')
- map { $form->{$_} =~ s/\"/"/g } qw(reference description chart);
+
+ map { $form->{$_} =~ s/\"/"/g }
+ qw(reference description chart taxchart);
+
+ $form->{javascript} = qq||;
+ $form->{javascript} .= qq||;
$form->{selectdepartment} =~ s/ selected//;
- $form->{taxchart} =~ s/ selected//;
$form->{selectdepartment} =~
s/option>\Q$form->{department}\E/option selected>$form->{department}/;
@@ -1023,18 +1010,15 @@ sub form_header {
qq||;
} else {
$description =
- qq||;
+ qq||;
}
$taxincluded = ($form->{taxincluded}) ? "checked" : "";
- if (!$form->{id}) {
+ if ($init) {
$taxincluded = "checked";
}
- $amount =
- qq||;
-
$department = qq|
| . $locale->text('Department') . qq| |
@@ -1042,52 +1026,56 @@ sub form_header {
| if $form->{selectdepartment};
-
- $form->{fokus} = "gl.reference";
- $form->{remote} = 1;
+ if ($init) {
+ $form->{fokus} = "gl.reference";
+ } else {
+ $form->{fokus} = qq|gl.accno_$form->{rowcount}|;
+ }
# use JavaScript Calendar or not
- $form->{jsscript} = $jscalendar;
+ $form->{jsscript} = 1;
$jsscript = "";
if ($form->{jsscript}) {
# with JavaScript Calendar
$button1 = qq|
- {transdate} tabindex="2" $readonly> |
- text('button')
- . qq|> |
+
+ text('button') . qq|> |
|;
#write Trigger
$jsscript =
- Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1", "",
- "", "");
+ Form->write_trigger(\%myconfig, "1", "transdate", "BL", "trigger1");
} else {
# without JavaScript Calendar
$button1 =
- qq|{transdate} tabindex="2" $readonly> | |;
+ qq| | |;
}
+ $form->{previous_id} ||= "--";
+ $form->{previous_gldate} ||= "--";
+
$form->header;
print qq|
-
+
+
+
-