# connect to database
my $dbh = $form->dbconnect_noauto($myconfig);
+ # acc_trans entries are deleted by database triggers.
my $query = qq|DELETE FROM ap WHERE id = ?|;
do_query($form, $dbh, $query, $form->{id});
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
- # commit and redirect
my $rc = $dbh->commit;
$dbh->disconnect;
# connect to database, turn AutoCommit off
my $dbh = $form->dbconnect_noauto($myconfig);
+ # acc_trans entries are deleted by database triggers.
my $query = qq|DELETE FROM ar WHERE id = ?|;
do_query($form, $dbh, $query, $form->{id});
- $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
- do_query($form, $dbh, $query, $form->{id});
-
# commit
my $rc = $dbh->commit;
$dbh->disconnect;
# connect to database
my $dbh = $form->dbconnect_noauto($myconfig);
- my @values = (conv_i($form->{id}));
- do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values);
- do_query($form, $dbh, qq|DELETE FROM gl WHERE id = ?|, @values);
+ # acc_trans entries are deleted by database triggers.
+ do_query($form, $dbh, qq|DELETE FROM gl WHERE id = ?|, conv_i($form->{id}));
# commit and redirect
my $rc = $dbh->commit;
--- /dev/null
+-- @tag: ar_ap_gl_delete_triggers_deletion_from_acc_trans
+-- @description: Beim Löschen aus ar, ap, gl per Trigger auch dazugehörige Einträge aus acc_trans löschen
+-- @depends: release_3_0_0
+-- @charset: utf-8
+CREATE OR REPLACE FUNCTION clean_up_acc_trans_after_ar_ap_gl_delete() RETURNS trigger AS $$
+ BEGIN
+ DELETE FROM acc_trans WHERE trans_id = OLD.id;
+ RETURN OLD;
+ END;
+$$ LANGUAGE plpgsql;
+
+CREATE TRIGGER after_delete_ar_trigger
+AFTER DELETE ON ar FOR EACH ROW EXECUTE
+PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete();
+
+CREATE TRIGGER after_delete_ap_trigger
+AFTER DELETE ON ap FOR EACH ROW EXECUTE
+PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete();
+
+CREATE TRIGGER after_delete_gl_trigger
+AFTER DELETE ON gl FOR EACH ROW EXECUTE
+PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete();