initial invoicing schema
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 16 Feb 2010 16:33:30 +0000 (16:33 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 16 Feb 2010 16:33:30 +0000 (16:33 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15552 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/0162.schema.acq-invoicing.sql [new file with mode: 0644]

index bd34bef..06d21d7 100644 (file)
@@ -847,6 +847,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
         </permacrud>
        </class>
 
+       <class id="aiit" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::invoice_item_type" oils_persist:tablename="acq.invoice_item_type" reporter:label="Non-bibliographic Invoice Item Type" oils_persist:field_safe="true">
+               <fields oils_persist:primary="code">
+                       <field reporter:label="Code" name="code" reporter:selector="name" reporter:datatype="id"/>
+                       <field reporter:label="Label" name="label" reporter:datatype="text" oils_persist:i18n="true"/>
+               </fields>
+               <links/>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="CREATE_INVOICE_ITEM_TYPE" global_required="true"/>
+                <retrieve/>
+                <update permission="UPDATE_INVOICE_ITEM_TYPE" global_required="true"/>
+                <delete permission="DELETE_INVOICE_ITEM_TYPE" global_required="true"/>
+            </actions>
+        </permacrud>
+       </class>
+
+       <class id="acqim" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::invoice_method" oils_persist:tablename="acq.invoice_method" reporter:label="Invoice Method used by Vendor" oils_persist:field_safe="true">
+               <fields oils_persist:primary="code">
+                       <field reporter:label="Code" name="code" reporter:selector="name" reporter:datatype="id"/>
+                       <field reporter:label="Label" name="label" reporter:datatype="text" oils_persist:i18n="true"/>
+               </fields>
+               <links/>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="CREATE_INVOICE_METHOD" global_required="true"/>
+                <retrieve/>
+                <update permission="UPDATE_INVOICE_METHOD" global_required="true"/>
+                <delete permission="DELETE_INVOICE_METHOD" global_required="true"/>
+            </actions>
+        </permacrud>
+       </class>
+
        <class id="ccpbt" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="container::copy_bucket_type" oils_persist:tablename="container.copy_bucket_type" reporter:label="Copy Bucket Type" oils_persist:field_safe="true">
                <fields oils_persist:primary="code">
                        <field reporter:label="Code" name="code" reporter:selector="name" reporter:datatype="id"/>
@@ -4444,6 +4476,105 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
         </permacrud>
        </class>
 
+       <class id="acqinv" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::invoice" oils_persist:tablename="acq.invoice" reporter:label="Invoice">
+               <fields oils_persist:primary="id" oils_persist:sequence="acq.invoice_id_seq">
+                       <field reporter:label="Internal Invoice ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Receiver" name="receiver" reporter:datatype="org_unit" />
+                       <field reporter:label="Provider" name="provider" reporter:datatype="link"/>
+                       <field reporter:label="Shipper" name="shipper" reporter:datatype="link"/>
+                       <field reporter:label="Receive Date/Time" name="recv_date" reporter:datatype="timestamp" />
+                       <field reporter:label="Receive Method" name="receive_method" reporter:datatype="link" />
+                       <field reporter:label="Invoice Type" name="invoice_type" reporter:datatype="text" />
+                       <field reporter:label="Vendor Invoice ID" name="inv_ident" reporter:datatype="text" />
+               </fields>
+               <links>
+                       <link field="receiver" reltype="has_a" key="id" map="" class="aou"/>
+                       <link field="provider" reltype="has_a" key="id" map="" class="acqpro"/>
+                       <link field="shipper" reltype="has_a" key="id" map="" class="acqpro"/>
+                       <link field="receive_method" reltype="has_a" key="id" map="" class="acqim"/>
+               </links>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create   permission="ADMIN_INVOICE" context_field="receiver"/>
+                <retrieve permission="ADMIN_INVOICE" context_field="receiver"/>
+                <update   permission="ADMIN_INVOICE" context_field="receiver"/>
+                <delete   permission="ADMIN_INVOICE" context_field="receiver"/>
+            </actions>
+        </permacrud>
+       </class>
+
+       <class id="acqie" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::invoice_entry" oils_persist:tablename="acq.invoice_entry" reporter:label="Invoice Entry">
+               <fields oils_persist:primary="id" oils_persist:sequence="acq.invoice_entry_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Invoice" name="invoice" reporter:datatype="link" />
+                       <field reporter:label="Purchase Order" name="purchase_order" reporter:datatype="link"/>
+                       <field reporter:label="PO Line Item" name="lineitem" reporter:datatype="link"/>
+                       <field reporter:label="Invoice Item Count" name="inv_item_count" reporter:datatype="int" />
+                       <field reporter:label="Physical Item Count" name="phys_item_count" reporter:datatype="int" />
+                       <field reporter:label="Note" name="note" reporter:datatype="text" />
+                       <field reporter:label="Billed Cost per Item" name="billed_per_item" reporter:datatype="bool" />
+                       <field reporter:label="Cost Billed" name="cost_billed" reporter:datatype="money" />
+                       <field reporter:label="Actual Cost" name="actual_cost" reporter:datatype="money" />
+               </fields>
+               <links>
+                       <link field="invoice" reltype="has_a" key="id" map="" class="acqinv"/>
+                       <link field="purchase_order" reltype="has_a" key="id" map="" class="acqpo"/>
+                       <link field="lineitem" reltype="has_a" key="id" map="" class="acqli"/>
+               </links>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </create>
+                <retrieve permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </retrieve>
+                <update   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </update>
+                               <delete   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </delete>
+            </actions>
+        </permacrud>
+       </class>
+
+       <class id="acqii" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::invoice_item" oils_persist:tablename="acq.invoice_item" reporter:label="Non-bibliographic Invoice Item">
+               <fields oils_persist:primary="id" oils_persist:sequence="acq.invoice_item_id_seq">
+                       <field reporter:label="ID" name="id" reporter:datatype="id"/>
+                       <field reporter:label="Invoice" name="invoice" reporter:datatype="link" />
+                       <field reporter:label="Purchase Order" name="purchase_order" reporter:datatype="link"/>
+                       <field reporter:label="Fund Debit" name="fund_debit" reporter:datatype="link"/>
+                       <field reporter:label="Invoice Item Type" name="inv_item_type" reporter:datatype="link" />
+                       <field reporter:label="Title or Item Name" name="title" reporter:datatype="text" />
+                       <field reporter:label="Author" name="author" reporter:datatype="text" />
+                       <field reporter:label="Note" name="note" reporter:datatype="text" />
+                       <field reporter:label="Cost Billed" name="cost_billed" reporter:datatype="money" />
+                       <field reporter:label="Actual Cost" name="actual_cost" reporter:datatype="money" />
+               </fields>
+               <links>
+                       <link field="invoice" reltype="has_a" key="id" map="" class="acqinv"/>
+                       <link field="purchase_order" reltype="has_a" key="id" map="" class="acqpo"/>
+                       <link field="fund_debit" reltype="has_a" key="id" map="" class="acqfdeb"/>
+               </links>
+        <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </create>
+                <retrieve permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </retrieve>
+                <update   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </update>
+                               <delete   permission="ADMIN_INVOICE">
+                                       <context link="invoice" field="receiver"/>
+                               </delete>
+            </actions>
+        </permacrud>
+       </class>
+
        <class id="acqpa" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::provider_address" oils_persist:tablename="acq.provider_address" reporter:label="Provider Address">
                <fields oils_persist:primary="id" oils_persist:sequence="acq.provider_address_id_seq">
                        <field reporter:label="Address Type" name="address_type"  reporter:datatype="text"/>
index fb3dffe..ceb3e8c 100644 (file)
@@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log (
     install_date    TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
 );
 
-INSERT INTO config.upgrade_log (version) VALUES ('0161'); --Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0162'); --miker
 
 CREATE TABLE config.bib_source (
        id              SERIAL  PRIMARY KEY,
index 82e06c7..ae3632c 100644 (file)
@@ -700,6 +700,62 @@ CREATE INDEX acq_attribution_debit_idx
 CREATE INDEX acq_attribution_credit_idx
     ON acq.debit_attribution( funding_source_credit );
 
+-- Invoicing
+
+CREATE TABLE acq.invoice_method (
+    code    TEXT    PRIMARY KEY,
+    name    TEXT    NOT NULL -- i18n-ize
+);
+INSERT INTO acq.invoice_method (code,name) VALUES ('EDI',oils_i18n_gettext('EDI', 'EDI', 'acqim', 'name'));
+INSERT INTO acq.invoice_method (code,name) VALUES ('PPR',oils_i18n_gettext('PPR', 'Paper', 'acqit', 'name'));
+
+
+CREATE TABLE acq.invoice (
+    id          SERIAL      PRIMARY KEY,
+    receiver    INT         NOT NULL REFERENCES actor.org_unit (id),
+    provider    INT         NOT NULL REFERENCES acq.provider (id),
+    shipper     INT         NOT NULL REFERENCES acq.provider (id),
+    recv_date   TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+    recv_method TEXT        NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI',
+    inv_type    TEXT,       -- A "type" field is desired, but no idea what goes here
+    inv_ident   TEXT        NOT NULL -- vendor-supplied invoice id/number
+);
+
+CREATE TABLE acq.invoice_entry (
+    id              SERIAL      PRIMARY KEY,
+    invoice         INT         NOT NULL REFERENCES acq.invoice (id) ON DELETE CASCADE,
+    purchase_order  INT         REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    lineitem        INT         REFERENCES acq.lineitem (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    inv_item_count  INT         NOT NULL, -- How many acqlids did they say they sent
+    phys_item_count INT, -- and how many did staff count
+    note            TEXT,
+    billed_per_item BOOL,
+    cost_billed     NUMERIC(8,2),
+    actual_cost     NUMERIC(8,2)
+);
+
+CREATE TABLE acq.invoice_item_type (
+    code    TEXT    PRIMARY KEY,
+    name    TEXT    NOT NULL -- i18n-ize
+);
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('TAX',oils_i18n_gettext('TAX', 'Tax', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('PRO',oils_i18n_gettext('PRO', 'Processing Fee', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('SHP',oils_i18n_gettext('SHP', 'Shipping Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('HND',oils_i18n_gettext('HND', 'Handling Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('ITM',oils_i18n_gettext('ITM', 'Non-library Item', 'aiit', 'name'));
+
+CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib items/etc
+    id              SERIAL      PRIMARY KEY,
+    invoice         INT         NOT NULL REFERENCES acq.invoice (id) ON UPDATE CASCADE ON DELETE CASCADE,
+    purchase_order  INT         REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    fund_debit      INT         REFERENCES acq.fund_debit (id),
+    inv_item_type   TEXT        NOT NULL REFERENCES acq.invoice_item_type (code),
+    title           TEXT,
+    author          TEXT,
+    note            TEXT,
+    cost_billed     NUMERIC(8,2),
+    actual_cost     NUMERIC(8,2)
+);
 
 -- Patron requests
 CREATE TABLE acq.user_request_type (
index 00613fe..ef94bec 100644 (file)
@@ -3921,3 +3921,13 @@ VALUES (
     oils_i18n_gettext('acq.fund.balance_limit.block', 'When the amount remaining in the fund, including spent money and encumbrances, goes below this percentage, attempts to spend from the fund will be blocked.', 'coust', 'description'),
     'integer'
 );
+
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('TAX',oils_i18n_gettext('TAX', 'Tax', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('PRO',oils_i18n_gettext('PRO', 'Processing Fee', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('SHP',oils_i18n_gettext('SHP', 'Shipping Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('HND',oils_i18n_gettext('HND', 'Handling Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('ITM',oils_i18n_gettext('ITM', 'Non-library Item', 'aiit', 'name'));
+
+INSERT INTO acq.invoice_method (code,name) VALUES ('EDI',oils_i18n_gettext('EDI', 'EDI', 'acqim', 'name'));
+INSERT INTO acq.invoice_method (code,name) VALUES ('PPR',oils_i18n_gettext('PPR', 'Paper', 'acqit', 'name'));
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/0162.schema.acq-invoicing.sql b/Open-ILS/src/sql/Pg/upgrade/0162.schema.acq-invoicing.sql
new file mode 100644 (file)
index 0000000..92e7dba
--- /dev/null
@@ -0,0 +1,61 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0162'); -- miker
+
+CREATE TABLE acq.invoice_method (
+    code    TEXT    PRIMARY KEY,
+    name    TEXT    NOT NULL -- i18n-ize
+);
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('EDI',oils_i18n_gettext('EDI', 'EDI', 'acqim', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('PPR',oils_i18n_gettext('PPR', 'Paper', 'acqit', 'name'));
+
+
+CREATE TABLE acq.invoice (
+    id          SERIAL      PRIMARY KEY,
+    receiver    INT         NOT NULL REFERENCES actor.org_unit (id),
+    provider    INT         NOT NULL REFERENCES acq.provider (id),
+    shipper     INT         NOT NULL REFERENCES acq.provider (id),
+    recv_date   TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+    recv_method TEXT        NOT NULL REFERENCES acq.invoice_method (code) DEFAULT 'EDI',
+    inv_type    TEXT,       -- A "type" field is desired, but no idea what goes here
+    inv_ident   TEXT        NOT NULL -- vendor-supplied invoice id/number
+);
+
+CREATE TABLE acq.invoice_entry (
+    id              SERIAL      PRIMARY KEY,
+    invoice         INT         NOT NULL REFERENCES acq.invoice (id) ON DELETE CASCADE,
+    purchase_order  INT         REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    lineitem        INT         REFERENCES acq.lineitem (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    inv_item_count  INT         NOT NULL, -- How many acqlids did they say they sent
+    phys_item_count INT, -- and how many did staff count
+    note            TEXT,
+    billed_per_item BOOL,
+    cost_billed     NUMERIC(8,2),
+    actual_cost     NUMERIC(8,2)
+);
+
+CREATE TABLE acq.invoice_item_type (
+    code    TEXT    PRIMARY KEY,
+    name    TEXT    NOT NULL -- i18n-ize
+);
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('TAX',oils_i18n_gettext('TAX', 'Tax', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('PRO',oils_i18n_gettext('PRO', 'Processing Fee', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('SHP',oils_i18n_gettext('SHP', 'Shipping Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('HND',oils_i18n_gettext('HND', 'Handling Charge', 'aiit', 'name'));
+INSERT INTO acq.invoice_item_type (code,name) VALUES ('ITM',oils_i18n_gettext('ITM', 'Non-library Item', 'aiit', 'name'));
+
+CREATE TABLE acq.invoice_item ( -- for invoice-only debits: taxes/fees/non-bib items/etc
+    id              SERIAL      PRIMARY KEY,
+    invoice         INT         NOT NULL REFERENCES acq.invoice (id) ON UPDATE CASCADE ON DELETE CASCADE,
+    purchase_order  INT         REFERENCES acq.purchase_order (id) ON UPDATE CASCADE ON DELETE SET NULL,
+    fund_debit      INT         REFERENCES acq.fund_debit (id),
+    inv_item_type   TEXT        NOT NULL REFERENCES acq.invoice_item_type (code),
+    title           TEXT,
+    author          TEXT,
+    note            TEXT,
+    cost_billed     NUMERIC(8,2),
+    actual_cost     NUMERIC(8,2)
+);
+
+COMMIT;
+