From da36e0095ae8b05e124507abd70b7122a94c15f1 Mon Sep 17 00:00:00 2001 From: tetragon Date: Thu, 2 Nov 2006 23:24:28 +0000 Subject: Change defaults queries to using new table structure git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@469 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/AM.pm | 7 ++++--- LedgerSMB/GL.pm | 22 ++++++++++++++++------ LedgerSMB/RC.pm | 6 ++++-- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index cf4b5df8..a8fd1e63 100755 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -251,8 +251,10 @@ sub delete_account { # set inventory_accno_id, income_accno_id, expense_accno_id to defaults $query = qq| UPDATE parts - SET inventory_accno_id = (SELECT inventory_accno_id - FROM defaults) + SET inventory_accno_id = (SELECT value + FROM defaults + WHERE setting_key = + 'inventory_accno_id') WHERE inventory_accno_id = ?|; $sth = $dbh->prepare($query); @@ -1592,7 +1594,6 @@ sub backup { my $boundary = time; my $tmpfile = "${LedgerSMB::Sysconfig::userspath}/$boundary.$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql"; $tmpfile .= ".gz" if ${LedgerSMB::Sysconfig::gzip}; - my $out = $form->{OUT}; $form->{OUT} = ">$tmpfile"; open(OUT, "$form->{OUT}") or $form->error("$form->{OUT} : $!"); diff --git a/LedgerSMB/GL.pm b/LedgerSMB/GL.pm index c6fe1037..8d31c453 100755 --- a/LedgerSMB/GL.pm +++ b/LedgerSMB/GL.pm @@ -500,13 +500,17 @@ sub transaction { if ($form->{id}) { - $query = "SELECT closedto, revtrans - FROM defaults"; + $query = "SELECT setting_key, value + FROM defaults + WHERE setting_key IN + ('closedto', 'revtrans')"; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); - ($form->{closedto}, $form->{revtrans}) = $sth->fetchrow_array; + my $results = $sth->fetchall_hashref('setting_key'); + $form->{closedto} = $results->{'closedto'}->{'value'}; + $form->{revtrans} = $results->{'revtrans'}->{'value'}; $sth->finish; $query = qq|SELECT g.*, d.description AS department @@ -544,13 +548,19 @@ sub transaction { $form->get_recurring($dbh); } else { - $query = "SELECT current_date AS transdate, closedto, revtrans - FROM defaults"; + $query = "SELECT current_date AS transdate, setting_key, value + FROM defaults + WHERE setting_key IN + ('closedto', 'revtrans')"; + $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); - ($form->{transdate}, $form->{closedto}, $form->{revtrans}) = $sth->fetchrow_array; + my $results = $sth->fetchall_hashref('setting_key'); + $form->{closedto} = $results->{'closedto'}->{'value'}; + $form->{revtrans} = $results->{'revtrans'}->{'value'}; + $form->{transdate} = $results->{'revtrans'}->{'transdate'}; } $sth->finish; diff --git a/LedgerSMB/RC.pm b/LedgerSMB/RC.pm index 5828f441..36488e37 100755 --- a/LedgerSMB/RC.pm +++ b/LedgerSMB/RC.pm @@ -232,9 +232,11 @@ sub payment_transactions { if ($form->{fx_transaction}) { $fx_transaction = qq| AND NOT (ac.chart_id IN - (SELECT fxgain_accno_id FROM defaults + (SELECT value AS fxgain_accno_id FROM defaults + WHERE setting_key = 'fxgain_accno_id' UNION - SELECT fxloss_accno_id FROM defaults))|; + SELECT value AS fxloss_accno_id FROM defaults + WHERE setting_key = 'fxloss_accno_id))|; } else { $fx_transaction = qq| AND ac.fx_transaction = '0'|; -- cgit v1.2.3