summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-xLedgerSMB/Form.pm30
-rwxr-xr-xLedgerSMB/IS.pm16
-rwxr-xr-xLedgerSMB/OE.pm24
3 files changed, 29 insertions, 41 deletions
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index 5ea22710..3b8e79ca 100755
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -1282,6 +1282,7 @@ sub db_init {
}
sub get_custom_queries {
+ my $dbh = $self->{dbh};
my ($self, $tablename, $query_type, $linenum) = @_;
if ($query_type !~ /^(select|insert|update)$/i){
$self->error($locale->text(
@@ -1308,7 +1309,10 @@ sub get_custom_queries {
my $ins_values;
$query = "$query_type ";
if ($query_type eq 'UPDATE'){
- $query .= " $_ SET ";
+ $query = "DELETE FROM $_ WHERE row_id = ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute->($form->{"id"."$linenum"})
+ || $self->dberror($query);
} elsif ($query_type eq 'INSERT'){
$query .= " INTO $_ (";
}
@@ -1344,6 +1348,30 @@ sub get_custom_queries {
push @rc, [ @data ];
}
}
+ if ($query_type eq 'INSERT'){
+ for (@rc){
+ $query = shift (@{$_});
+ $sth = $dbh->prepare($query)
+ || $form->db_error($query);
+ $sth->execute(@{$_}, $form->{id})
+ || $form->dberror($query);;
+ $sth->finish;
+ $did_insert = 1;
+ }
+ } elsif ($query_type eq 'UPDATE'){
+ @rc = $self->get_custom_queries(
+ $tablename, $query_type, $linenum);
+ } elsif ($query_type eq 'SELECT'){
+ for (@rc){
+ $query = shift @{$_};
+ $sth = $form->{dbh}->prepare($query);
+ $sth->execute($form->{id});
+ $ref = $sth->fetchrow_hashref(NAME_lc);
+ for (keys %{$ref}){
+ $form->{$_} = $ref->{$_};
+ }
+ }
+ }
@rc;
}
diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm
index c88d527e..1620bb11 100755
--- a/LedgerSMB/IS.pm
+++ b/LedgerSMB/IS.pm
@@ -635,13 +635,6 @@ sub post_invoice {
$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;
- }
}
@@ -1431,15 +1424,6 @@ sub retrieve_invoice {
$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 a008092a..5d85faa8 100755
--- a/LedgerSMB/OE.pm
+++ b/LedgerSMB/OE.pm
@@ -362,15 +362,6 @@ sub save {
@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;
@@ -632,12 +623,6 @@ sub save {
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;
- }
}
@@ -958,15 +943,6 @@ sub retrieve {
$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 {