Add user_share support to invoices.
authorBen Thompson <ben@xtuple.com>
Fri, 9 May 2014 16:36:20 +0000 (12:36 -0400)
committerBen Thompson <ben@xtuple.com>
Fri, 9 May 2014 16:36:20 +0000 (12:36 -0400)
enyo-client/database/orm/models/invoice.json
enyo-client/database/source/manifest.js
enyo-client/database/source/public/tables/invchead.sql [new file with mode: 0644]
enyo-client/extensions/source/billing/database/source/manifest.js
enyo-client/extensions/source/billing/database/source/xt/tables/sharetype.sql [new file with mode: 0644]
enyo-client/extensions/source/billing/database/source/xt/views/share_users_invchead.sql [new file with mode: 0644]

index 4c7d750..748b018 100644 (file)
         "isVoid": {
           "update": false
         }
+      },
+      "personal": {
+        "create": false,
+        "read": "ViewPersonalCRMAccounts",
+        "update": false,
+        "delete": false,
+        "properties": [
+          "crmaccountUsers"
+        ]
       }
     },
     "properties": [
           "column": "invchead_id",
           "inverse": "source"
         }
+      },
+      {
+        "name": "crmaccountUsers",
+        "toMany": {
+          "type": "ShareUsers",
+          "column": "obj_uuid",
+          "inverse": "uuid"
+        }
       }
     ],
     "isSystem": true
index a986adc..0c7cdef 100644 (file)
@@ -33,6 +33,7 @@
     "public/tables/docass.sql",
     "public/tables/grppriv.sql",
     "public/tables/incdt.sql",
+    "public/tables/invchead.sql",
     "public/tables/invcitem.sql",
     "public/tables/invcitemtax.sql",
     "public/tables/itemsite.sql",
diff --git a/enyo-client/database/source/public/tables/invchead.sql b/enyo-client/database/source/public/tables/invchead.sql
new file mode 100644 (file)
index 0000000..749bb47
--- /dev/null
@@ -0,0 +1,4 @@
+-- add uuid column here because there are views that need this
+select xt.add_column('invchead','obj_uuid', 'uuid', 'default xt.uuid_generate_v4()', 'public');
+select xt.add_inheritance('invchead', 'xt.obj');
+select xt.add_constraint('invchead', 'invchead_obj_uuid','unique(obj_uuid)', 'public');
index fce729d..db5f6cc 100644 (file)
@@ -4,6 +4,7 @@
   "loadOrder": 30,
   "databaseScripts": [
     "xt/tables/rptdef.sql",
+    "xt/tables/sharetype.sql",
     "xm/javascript/billing.sql",
     "xm/javascript/cashrcpt.sql",
     "xm/javascript/invoice.sql",
@@ -16,6 +17,7 @@
     "xt/views/receivable_invoice_return.sql",
     "xt/views/aropeninfo.sql",
     "xt/views/receivable_applications.sql",
+    "xt/views/share_users_invchead.sql",
     "xt/views/cashrcpt.sql"
   ]
 }
diff --git a/enyo-client/extensions/source/billing/database/source/xt/tables/sharetype.sql b/enyo-client/extensions/source/billing/database/source/xt/tables/sharetype.sql
new file mode 100644 (file)
index 0000000..fc4059b
--- /dev/null
@@ -0,0 +1,13 @@
+-- Invoice CRM Account's users.
+delete from xt.sharetype where sharetype_tblname = 'share_users_invchead';
+insert into xt.sharetype (
+  sharetype_nsname,
+  sharetype_tblname,
+  sharetype_col_obj_uuid,
+  sharetype_col_username
+) values (
+  'xt',
+  'share_users_invchead',
+  'obj_uuid',
+  'username'
+);
diff --git a/enyo-client/extensions/source/billing/database/source/xt/views/share_users_invchead.sql b/enyo-client/extensions/source/billing/database/source/xt/views/share_users_invchead.sql
new file mode 100644 (file)
index 0000000..f21c0de
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * This view lists all postgres usernames that are associated with a CRM
+ * Account that owns a resource. That associaiton is either the main user
+ * account, owner's user account, customer's sale rep's user account or
+ * a shared access that has been specifically granted.
+ *
+ * This view can be used to determine which users have personal privilege
+ * access to an Invoice based on what CRM Account it belongs to.
+ */
+
+select xt.create_view('xt.share_users_invchead', $$
+
+  -- Invoice CRM Account's users.
+  SELECT
+    invchead_cust_crmacct_ids.obj_uuid::uuid AS obj_uuid,
+    username::text AS username
+  FROM (
+    SELECT
+      invchead.obj_uuid,
+      crmacct_id
+    FROM invchead
+    LEFT JOIN custinfo ON invchead_cust_id = cust_id
+    LEFT JOIN crmacct ON cust_id = crmacct_cust_id
+  ) invchead_cust_crmacct_ids
+  LEFT JOIN xt.crmacct_users USING (crmacct_id)
+  WHERE 1=1
+    AND username IS NOT NULL;
+
+$$, false);