X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/03c310de8edb970a56ba51d0969979d0fe63f1b8..a751b16cead5e56b62e18ee616e04323919f5fe1:/SL/Form.pm diff --git a/SL/Form.pm b/SL/Form.pm index 2f7aa793a..e1ea94174 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -959,7 +959,7 @@ sub datetonum { # Database routines used throughout sub dbconnect { - $main::lxdebug->enter_sub(); + $main::lxdebug->enter_sub(2); my ($self, $myconfig) = @_; @@ -974,7 +974,7 @@ sub dbconnect { $dbh->do($myconfig->{dboptions}) || $self->dberror($myconfig->{dboptions}); } - $main::lxdebug->leave_sub(); + $main::lxdebug->leave_sub(2); return $dbh; } @@ -1526,6 +1526,70 @@ sub _get_printers { $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_employees { + $main::lxdebug->enter_sub(); + + my ($self, $dbh, $key) = @_; + + $key = "all_employees" unless ($key); + $self->{$key} = + selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee|); + + $main::lxdebug->leave_sub(); +} + sub get_lists { $main::lxdebug->enter_sub(); @@ -1556,6 +1620,18 @@ sub get_lists { $self->_get_printers($dbh, $params{"printers"}); } + if ($params{"charts"}) { + $self->_get_charts($dbh, $params{"charts"}); + } + + if ($params{"taxcharts"}) { + $self->_get_taxcharts($dbh, $params{"taxcharts"}); + } + + if ($params{"employees"}) { + $self->_get_employees($dbh, $params{"employees"}); + } + $dbh->disconnect(); $main::lxdebug->leave_sub(); @@ -1849,7 +1925,8 @@ sub create_links { # now get the account numbers $query = qq|SELECT c.accno, c.description, c.link, c.taxkey_id, tk.tax_id FROM chart c, taxkeys tk - WHERE c.link LIKE '%$module%' AND c.id=tk.chart_id AND tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1) + WHERE c.link LIKE '%$module%' AND c.id=tk.chart_id AND tk.id = + (SELECT id FROM taxkeys where taxkeys.chart_id = c.id AND startdate <= $transdate ORDER BY startdate desc LIMIT 1) ORDER BY c.accno|; $sth = $dbh->prepare($query); @@ -1877,43 +1954,17 @@ sub create_links { } # get taxkeys and description - $query = qq|SELECT id, taxkey, taxdescription - FROM tax|; - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - - $ref = $sth->fetchrow_hashref(NAME_lc); - - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $self->{TAXKEY} }, $ref; - } - - $sth->finish; - + $query = qq|SELECT id, taxkey, taxdescription FROM tax|; + $self->{TAXKEY} = selectall_hashref_query($form, $dbh, $query); # get tax zones - $query = qq|SELECT id, description - FROM tax_zones|; - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - - - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $self->{TAXZONE} }, $ref; - } - $sth->finish; + $query = qq|SELECT id, description FROM tax_zones|; + $self->{TAXZONE} = selectall_hashref_query($form, $dbh, $query); if (($module eq "AP") || ($module eq "AR")) { - # get tax rates and description $query = qq| SELECT * FROM tax t|; - $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - $self->{TAX} = (); - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $self->{TAX} }, $ref; - } - $sth->finish; + $self->{TAX} = selectall_hashref_query($form, $dbh, $query); } if ($self->{id}) { @@ -2388,9 +2439,14 @@ sub save_status { sub update_defaults { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $fld) = @_; + my ($self, $myconfig, $fld, $provided_dbh) = @_; - my $dbh = $self->dbconnect_noauto($myconfig); + my $dbh; + if ($provided_dbh) { + $dbh = $provided_dbh; + } else { + $dbh = $self->dbconnect_noauto($myconfig); + } my $query = qq|SELECT $fld FROM defaults FOR UPDATE|; my $sth = $dbh->prepare($query); @@ -2404,8 +2460,10 @@ sub update_defaults { SET $fld = '$var'|; $dbh->do($query) || $self->dberror($query); - $dbh->commit; - $dbh->disconnect; + if (!$provided_dbh) { + $dbh->commit; + $dbh->disconnect; + } $main::lxdebug->leave_sub();