$main::lxdebug->leave_sub();
}
+sub _get_charts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $params) = @_;
+
+ $key = $params->{key};
+ $key = "all_charts" unless ($key);
+ $self->{$key} = [];
+
+ my $transdate = quote_db_date($params->{transdate});
+
+ my $query =
+ qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
+ qq|FROM chart c | .
+ qq|LEFT JOIN taxkeys tk ON | .
+ qq|(tk.id = (SELECT id FROM taxkeys | .
+ qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
+ qq| ORDER BY startdate DESC LIMIT 1)) | .
+ qq|ORDER BY c.accno|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_taxcharts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_taxcharts" unless ($key);
+ $self->{$key} = [];
+
+ my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
sub get_lists {
$main::lxdebug->enter_sub();
$self->_get_printers($dbh, $params{"printers"});
}
+ if ($params{"charts"}) {
+ $self->_get_charts($dbh, $params{"charts"});
+ }
+
+ if ($params{"taxcharts"}) {
+ $self->_get_taxcharts($dbh, $params{"taxcharts"});
+ }
+
$dbh->disconnect();
$main::lxdebug->leave_sub();
# we use this only to set a default date
GL->transaction(\%myconfig, \%$form);
- map {
- $chart .=
- "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
- } @{ $form->{chart} };
map {
$tax .=
qq|<option value="$_->{id}--$_->{rate}">$_->{taxdescription} |
. ($_->{rate} * 100) . qq| %|
} @{ $form->{TAX} };
- $form->{chart} = $chart;
- $form->{chartinit} = $chart;
$form->{rowcount} = 2;
- $form->{debitchart} = $chart;
- $form->{creditchart} = $chart;
- $form->{taxchart} = $tax;
-
$form->{debit} = 0;
$form->{credit} = 0;
$form->{tax} = 0;
$lxdebug->enter_sub();
GL->transaction(\%myconfig, \%$form);
- map {
- $chart .=
- "<option value=\"$_->{accno}--$_->{tax_id}\">$_->{accno}--$_->{description}</option>"
- } @{ $form->{chart} };
map {
$tax .=
. ($_->{rate} * 100) . qq| %|
} @{ $form->{TAX} };
- $form->{chart} = $chart;
-
- $form->{taxchart} = $tax;
-
$form->{amount} = $form->format_amount(\%myconfig, $form->{amount}, 2);
# departments
$form->{totaldebit} = 0;
$form->{totalcredit} = 0;
- my $chart = $form->{chart};
- $chart = $form->unquote($chart);
- $form->{taxchart} = $form->unquote($form->{taxchart});
- $taxchart = $form->{taxchart};
my @old_project_ids = ();
map({ push(@old_project_ids, $form->{"project_id_$_"})
$form->get_lists("projects" => { "key" => "ALL_PROJECTS",
"all" => 0,
- "old_id" => \@old_project_ids });
+ "old_id" => \@old_project_ids },
+ "charts" => { "key" => "ALL_CHARTS",
+ "transdate" => $form->{transdate} },
+ "taxcharts" => "ALL_TAXCHARTS");
my %project_labels = ();
my @project_values = ("");
$project_labels{$item->{"id"}} = $item->{"projectnumber"};
}
+ my %chart_labels = ();
+ my @chart_values = ();
+ 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);
+ push(@chart_values, $key);
+ $chart_labels{$key} = H($item->{accno}) . "--" . H($item->{description});
+ }
+
+ my %taxchart_labels = ();
+ my @taxchart_values = ();
+ foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
+ my $key = Q($item->{id}) . "--" . Q($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) . ' %';
+ }
+
for $i (1 .. $form->{rowcount}) {
$source = qq|
<td><input name="memo_$i" value="$form->{"memo_$i"}" size="16" tabindex=|
. ($i + 12 + (($i - 1) * 8)) . qq|></td>|;
- if ($init) {
- $accno = qq|
- <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
- . ($i + 5 + (($i - 1) * 8)) . qq|>$form->{chartinit}</select></td>|;
- $tax =
- qq|<td><select id="taxchart_$i" name="taxchart_$i" style="width:200px" tabindex=|
- . ($i + 10 + (($i - 1) * 8))
- . qq|>$form->{taxchart}</select></td>|;
+ $accno = qq|<td>| .
+ $cgi->popup_menu('-name' => "accno_$i",
+ '-onChange' => "setTaxkey(this, $i)",
+ '-style' => 'width:200px',
+ '-tabindex' => ($i + 5 + (($i - 1) * 8)),
+ '-values' => \@chart_values,
+ '-labels' => \%chart_labels,
+ '-default' => $init ? '' : $form->{"accno_$i"})
+ . qq|</td>|;
+ $tax = qq|<td>| .
+ $cgi->popup_menu('-name' => "taxchart_$i",
+ '-style' => 'width:200px',
+ '-tabindex' => ($i + 10 + (($i - 1) * 8)),
+ '-values' => \@taxchart_values,
+ '-labels' => \%taxchart_labels,
+ '-default' => $init ? $taxchart_init : $form->{"taxchart_$i"})
+ . qq|</td>|;
+ if ($init) {
$korrektur =
qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
. ($i + 9 + (($i - 1) * 8))
}
if ($i < $form->{rowcount}) {
-
- $accno = $chart;
- $chart_selected = $form->{"accno_$i"};
- $accno =~
- s/value=\"$chart_selected\"/value=\"$chart_selected\" selected/;
- $accno =
- qq|<td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:200px" tabindex=|
- . ($i + 5 + (($i - 1) * 8))
- . qq|>$accno</select></td>|;
- $tax = $taxchart;
- $tax_selected = $form->{"taxchart_$i"};
- $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/;
- $tax =
- qq|<td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
- . ($i + 10 + (($i - 1) * 8))
- . qq|>$tax</select></td>|;
-
if ($form->{transfer}) {
$checked = ($form->{"fx_transaction_$i"}) ? "1" : "";
$x = ($checked) ? "x" : "";
$form->hide_form("accno_$i");
} else {
-
- $accno = qq|
- <td><select name="accno_$i" onChange="setTaxkey(this, $i)" style="width:300px" tabindex=|
- . ($i + 5 + (($i - 1) * 8)) . qq|>$chart</select></td>|;
- $tax = qq|
- <td><select id="taxchart_$i" name="taxchart_$i" tabindex=|
- . ($i + 10 + (($i - 1) * 8)) . qq|>$taxchart</select></td>|;
-
$korrektur =
qq|<td><input type="checkbox" name="korrektur_$i" value="1" tabindex=|
. ($i + 9 + (($i - 1) * 8))
<input type=hidden name=closedto value=$form->{closedto}>
<input type=hidden name=locked value=$form->{locked}>
<input type=hidden name=title value="$title">
-<input type=hidden name=taxchart value="$form->{taxchart}">
-<input type=hidden name=chart value="$form->{chart}">
<table width=100%>
<form method=post action=$form->{script}>
|;
- map { $form->{$_} =~ s/\"/"/g } qw(reference description chart taxchart);
+ map { $form->{$_} =~ s/\"/"/g } qw(reference description);
delete $form->{header};