Feld ar.datepaid bei durch SEPA-Zahlungen nachträglich richtig setzen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 Jan 2014 09:57:40 +0000 (10:57 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 8 Jan 2014 09:57:40 +0000 (10:57 +0100)
Behebt #1925.

sql/Pg-upgrade2/fix_datepaid_for_sepa_transfers.sql [new file with mode: 0644]

diff --git a/sql/Pg-upgrade2/fix_datepaid_for_sepa_transfers.sql b/sql/Pg-upgrade2/fix_datepaid_for_sepa_transfers.sql
new file mode 100644 (file)
index 0000000..dd2b06b
--- /dev/null
@@ -0,0 +1,19 @@
+-- @tag: fix_datepaid_for_sepa_transfers
+-- @description: Feld »datepaid« bei via SEPA durchgeführten Transfers richtig setzen
+-- @depends: release_3_0_0
+UPDATE ar
+SET datepaid = (
+  SELECT MAX(acc.transdate)
+  FROM acc_trans acc
+  LEFT JOIN chart c ON (c.id = acc.chart_id)
+  WHERE (acc.trans_id = ar.id)
+    AND (c.link LIKE '%paid%')
+)
+WHERE (ar.amount != 0)
+  AND NOT ar.storno
+  AND ar.id IN (
+    SELECT sei.ar_id
+    FROM sepa_export_items sei
+    WHERE (sei.ar_id IS NOT NULL)
+      AND sei.executed
+  );