LP#1750894 Invoice close date/by SQL/IDL WIP
authorBill Erickson <berickxx@gmail.com>
Tue, 13 Mar 2018 20:02:41 +0000 (16:02 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 13 Mar 2018 20:02:41 +0000 (16:02 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.invoice-close-date.sql [new file with mode: 0644]

index b272b9f..5a72d22 100644 (file)
@@ -8295,7 +8295,8 @@ SELECT  usr,
                        <field reporter:label="Payment Auth" name="payment_auth" reporter:datatype="text" />
                        <field reporter:label="Payment Method" name="payment_method" reporter:datatype="link" />
                        <field reporter:label="Note" name="note" reporter:datatype="text" />
-                       <field reporter:label="Complete" name="complete" reporter:datatype="bool" />
+                       <field reporter:label="Close Date" name="close_date" reporter:datatype="timestamp" />
+                       <field reporter:label="Closed By" name="closed_by" reporter:datatype="link" />
                        <field reporter:label="Invoice Entries" name="entries" reporter:datatype="link" oils_persist:virtual="true"/>
                        <field reporter:label="Invoice Items" name="items" reporter:datatype="link" oils_persist:virtual="true"/>
                </fields>
@@ -8307,6 +8308,7 @@ SELECT  usr,
                        <link field="payment_method" reltype="has_a" key="code" map="" class="acqipm"/>
                        <link field="entries" reltype="has_many" key="invoice" map="" class="acqie"/>
                        <link field="items" reltype="has_many" key="invoice" map="" class="acqii"/>
+                       <link field="closed_by" reltype="has_a" key="id" map="" class="au"/>
                </links>
         <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
             <actions>
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.invoice-close-date.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.invoice-close-date.sql
new file mode 100644 (file)
index 0000000..61a20c4
--- /dev/null
@@ -0,0 +1,50 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+-- TODO 
+-- ADD TO PATRON PURGE SQL FUNC
+-- Back-fill closed_by?  with ??
+
+DROP VIEW auditor.acq_invoice_lifecycle;
+
+ALTER TABLE acq.invoice
+    ADD COLUMN close_date TIMESTAMPTZ,
+    ADD COLUMN closed_by  INTEGER 
+        REFERENCES actor.usr (id) DEFERRABLE INITIALLY DEFERRED;
+
+-- duplicate steps for auditor table
+ALTER TABLE auditor.acq_invoice_history
+    ADD COLUMN close_date TIMESTAMPTZ,
+    ADD COLUMN closed_by  INTEGER;
+
+UPDATE acq.invoice SET close_date = NOW() WHERE complete;
+UPDATE auditor.acq_invoice_history SET close_date = NOW() WHERE complete;
+
+ALTER TABLE acq.invoice DROP COLUMN complete;
+ALTER TABLE auditor.acq_invoice_history DROP COLUMN complete;
+
+-- this recreates auditor.acq_invoice_lifecycle;
+SELECT auditor.update_auditors();
+
+COMMIT;
+
+
+-- UNDO
+/*
+
+BEGIN;
+DROP VIEW auditor.acq_invoice_lifecycle;
+ALTER TABLE acq.invoice ADD COLUMN complete BOOLEAN NOT NULL DEFAULT FALSE;
+ALTER TABLE auditor.acq_invoice_history 
+    ADD COLUMN complete BOOLEAN NOT NULL DEFAULT FALSE;
+UPDATE acq.invoice SET complete = TRUE where close_date IS NOT NULL;
+UPDATE auditor.acq_invoice_history 
+    SET complete = TRUE where close_date IS NOT NULL;
+ALTER TABLE acq.invoice DROP COLUMN close_date, DROP COLUMN closed_by;
+ALTER TABLE auditor.acq_invoice_history
+    DROP COLUMN close_date, DROP COLUMN closed_by;
+SELECT auditor.update_auditors();
+COMMIT;
+
+*/