From 0303f21d687059f314eaeef17e40eba99d22001f Mon Sep 17 00:00:00 2001 From: einhverfr Date: Sun, 24 Sep 2006 06:22:23 +0000 Subject: Added support for custom fields to IS, OE, and corrected API bugs in Form. Also AA now partially supports the custom fields. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@139 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/AA.pm | 43 +++++++++++++++++++++++++++---------------- LedgerSMB/Form.pm | 17 +++++++++++------ LedgerSMB/IS.pm | 20 ++++++++++++++++++++ LedgerSMB/OE.pm | 40 ++++++++++++++++++++++++++++++++++------ 4 files changed, 92 insertions(+), 28 deletions(-) (limited to 'LedgerSMB') diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm index a3e2d49e..f5b8a470 100755 --- a/LedgerSMB/AA.pm +++ b/LedgerSMB/AA.pm @@ -250,25 +250,36 @@ sub post_transaction { $form->{invnumber} = $form->update_defaults($myconfig, $invnumber) unless $form->{invnumber}; - $query = qq|UPDATE $table SET invnumber = |.$dbh->quote($form->{invnumber}).qq|, - ordnumber = |.$dbh->quote($form->{ordnumber}).qq|, - transdate = '$form->{transdate}', - $form->{vc}_id = $form->{"$form->{vc}_id"}, - taxincluded = '$form->{taxincluded}', - amount = $invamount, - duedate = '$form->{duedate}', - paid = $paid, - datepaid = $datepaid, - netamount = $invnetamount, - curr = '$form->{currency}', - notes = |.$dbh->quote($form->{notes}).qq|, - department_id = $form->{department_id}, - employee_id = $form->{employee_id}, - ponumber = |.$dbh->quote($form->{ponumber}).qq| - WHERE id = $form->{id}|; + $query = qq| + UPDATE $table + SET invnumber = |.$dbh->quote($form->{invnumber}).qq|, + ordnumber = |.$dbh->quote($form->{ordnumber}).qq|, + transdate = '$form->{transdate}', + $form->{vc}_id = $form->{"$form->{vc}_id"}, + taxincluded = '$form->{taxincluded}', + amount = $invamount, + duedate = '$form->{duedate}', + paid = $paid, + datepaid = $datepaid, + netamount = $invnetamount, + curr = '$form->{currency}', + notes = |.$dbh->quote($form->{notes}).qq|, + department_id = $form->{department_id}, + employee_id = $form->{employee_id}, + ponumber = |.$dbh->quote($form->{ponumber}).qq| + WHERE id = $form->{id} + |; $dbh->do($query) || $form->dberror($query); + @queries = $form->get_custom_queries($table, 'INSERT'); + for (@queries){ + $query = shift (@{$_}); + $sth = $dbh->prepare($query) || $form->db_error($query); + $sth->execute(@{$_}, $form->{id})|| $form->dberror($query);; + $sth->finish; + $did_insert = 1; + } # update exchangerate my $buy = $form->{exchangerate}; my $sell = 0; diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index 7a578448..2e0f6b4b 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -1304,6 +1304,7 @@ sub get_custom_queries { } for (keys %temphash){ my @data; + my $ins_values; $query = "$query_type "; if ($query_type eq 'UPDATE'){ $query .= " $_ SET "; @@ -1316,21 +1317,25 @@ sub get_custom_queries { if ($query_type eq 'UPDATE'){ $query .= '= ?'; } - my $ins_values .= "?, "; - if ($first == 0){ - $query .= ", "; - } + $ins_values .= "?, "; + $query .= ", "; $first = 0; - if ($query_type eq 'UPDATE' or $query_type eq 'INERT'){ - push @data, $form->{$_ . $linenum}; + if ($query_type eq 'UPDATE' or $query_type eq 'INSERT'){ + push @data, $self->{"$_$linenum"}; } } + if ($query_type ne 'INSERT'){ + $query =~ s/, $//; + } if ($query_type eq 'SELECT'){ $query .= " FROM $_"; } if ($query_type eq 'SELECT' or $query_type eq 'UPDATE'){ $query .= " WHERE field_id = ?"; } + if ($query_type eq 'INSERT'){ + $query .= " field_id) VALUES ($ins_values ?)"; + } if ($query_type eq 'SELECT'){ push @rc, [ $query ]; } else { diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index bda4d5b6..1e4714fa 100755 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -633,6 +633,15 @@ sub post_invoice { ($form->{id}) = $sth->fetchrow_array; $sth->finish; + + @queries = $form->get_custom_queries('ar', 'INSERT'); + for (@queries){ + $query = shift (@{$_}); + $sth = $dbh->prepare($query) || $form->db_error($query); + $sth->execute(@{$_}, $form->{id})|| $form->dberror($query);; + $sth->finish; + $did_insert = 1; + } } @@ -1421,6 +1430,17 @@ sub retrieve_invoice { my $rc = $dbh->commit; $dbh->disconnect; + @queries = $form->get_custom_queries('ar', 'SELECT'); + for (@queries){ + $query = shift @{$_}; + $sth = $form->{dbh}->prepare($query); + $sth->execute($form->{id}); + $ref = $sth->fetchrow_hashref(NAME_lc); + for (keys %{$ref}){ + $form->{$_} = $ref->{$_}; + } + } + $form->{dbh}->commit; $rc; } diff --git a/LedgerSMB/OE.pm b/LedgerSMB/OE.pm index ae4cd635..2fcaec9b 100755 --- a/LedgerSMB/OE.pm +++ b/LedgerSMB/OE.pm @@ -261,6 +261,7 @@ sub save { } } + my $did_insert = 0; if (! $form->{id}) { my $uid = localtime; @@ -276,7 +277,15 @@ sub save { $sth->execute || $form->dberror($query); ($form->{id}) = $sth->fetchrow_array; $sth->finish; - + @queries = $form->get_custom_queries('oe', 'INSERT'); + + for (@queries){ + $query = shift (@{$_}); + $sth = $dbh->prepare($query) || $form->db_error($query); + $sth->execute(@{$_}, $form->{id})|| $form->dberror($query);; + $sth->finish; + $did_insert = 1; + } } my $amount; @@ -451,6 +460,18 @@ sub save { WHERE id = $form->{id}|; $dbh->do($query) || $form->dberror($query); + if (!$did_insert){ + @queries = $form->get_custom_queries('oe', 'UPDATE'); + for (@queries){ + my $query = shift @{$_}; + $sth = $dbh->prepare($query); + $sth->execute (@{$_}, $form->{id}); + $sth->finish; + } + } + + + $form->{ordtotal} = $amount; # add shipto @@ -644,10 +665,6 @@ sub retrieve { $sth->finish; for (qw(printed emailed queued)) { $form->{$_} =~ s/ +$//g } - my %oid = ( 'Pg' => 'id', - 'Oracle' => 'rowid', - 'DB2' => '1=1' - ); # retrieve individual items $query = qq|SELECT o.id AS orderitems_id, @@ -665,7 +682,7 @@ sub retrieve { LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) LEFT JOIN translation t ON (t.trans_id = p.partsgroup_id AND t.language_code = '$form->{language_code}') WHERE o.trans_id = $form->{id} - ORDER BY o.$oid{$myconfig->{dbdriver}}|; + ORDER BY o.id|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); @@ -727,6 +744,17 @@ sub retrieve { # get recurring transaction $form->get_recurring($dbh); + @queries = $form->get_custom_queries('oe', 'SELECT'); + for (@queries){ + $query = shift @{$_}; + $sth = $form->{dbh}->prepare($query); + $sth->execute($form->{id}); + $ref = $sth->fetchrow_hashref(NAME_lc); + for (keys %{$ref}){ + $form->{$_} = $ref->{$_}; + } + } + $form->{dbh}->commit; } else { # get last name used -- cgit v1.2.3