X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/afe8a81b6245af6a09f5dc822f311be19bc90ca6..644c68bae03521cec693800af0a19b9ab4e0ed9c:/SL/Form.pm?ds=inline diff --git a/SL/Form.pm b/SL/Form.pm index d690be1c1..6a1fa813c 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1960,8 +1960,9 @@ sub create_links { ORDER BY c.accno|; $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); - + + do_statement($form, $sth, $query); + $self->{accounts} = ""; while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { @@ -2012,7 +2013,7 @@ sub create_links { LEFT JOIN department d ON (d.id = a.department_id) WHERE a.id = $self->{id}|; $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + do_statement($form, $sth, $query); $ref = $sth->fetchrow_hashref(NAME_lc); foreach $key (keys %$ref) { @@ -2027,13 +2028,30 @@ 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 (((tk.chart_id=c.id) AND NOT(c.link like '%_tax%')) OR (NOT(tk.chart_id=c.id) AND (c.link like '%_tax%'))) AND (((tk.id = (SELECT id from taxkeys where taxkeys.chart_id =c.id AND startdate<=$transdate ORDER BY startdate desc LIMIT 1)) AND NOT(c.link like '%_tax%')) OR (c.link like '%_tax%')) - ORDER BY c.accno|; - + $query = qq| + SELECT + c.accno, + c.description, + c.link, + c.taxkey_id, + tk.tax_id + FROM chart c + LEFT JOIN taxkeys tk ON (tk.chart_id = c.id) + WHERE + c.link LIKE ? + AND + (tk.chart_id = c.id AND NOT c.link like '%_tax%') + OR (NOT tk.chart_id = c.id AND c.link like '%_tax%') + AND + tk.id = ( SELECT id from taxkeys + WHERE taxkeys.chart_id = c.id + AND startdate <= ? + ORDER BY startdate desc LIMIT 1 + ) + ORDER BY c.accno|; + $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + do_statement($form, $sth, $query, "%$module%", $transdate); $self->{accounts} = ""; while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { @@ -2067,7 +2085,7 @@ sub create_links { AND a.fx_transaction = '0' ORDER BY a.oid,a.transdate|; $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + do_statement($form, $sth, $query); my $fld = ($table eq 'customer') ? 'buy' : 'sell'; @@ -2101,7 +2119,7 @@ sub create_links { WHERE d.fxloss_accno_id = c.id) AS fxloss_accno FROM defaults d|; $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + do_statement($form, $sth, $query); $ref = $sth->fetchrow_hashref(NAME_lc); map { $self->{$_} = $ref->{$_} } keys %$ref; @@ -2118,7 +2136,7 @@ sub create_links { WHERE d.fxloss_accno_id = c.id) AS fxloss_accno FROM defaults d|; $sth = $dbh->prepare($query); - $sth->execute || $self->dberror($query); + do_statement($form, $sth, $query); $ref = $sth->fetchrow_hashref(NAME_lc); map { $self->{$_} = $ref->{$_} } keys %$ref; @@ -2503,9 +2521,14 @@ sub update_defaults { sub update_business { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $business_id) = @_; + my ($self, $myconfig, $business_id, $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 customernumberinit FROM business WHERE id=$business_id FOR UPDATE|; my $sth = $dbh->prepare($query); @@ -2520,8 +2543,10 @@ sub update_business { SET customernumberinit = '$var' WHERE id=$business_id|; $dbh->do($query) || $self->dberror($query); - $dbh->commit; - $dbh->disconnect; + if (!$provided_dbh) { + $dbh->commit; + $dbh->disconnect; + } $main::lxdebug->leave_sub();