Add user_share support to invoices.
[xtuple] / enyo-client / extensions / source / billing / database / source / xt / views / share_users_invchead.sql
1 /*
2  * This view lists all postgres usernames that are associated with a CRM
3  * Account that owns a resource. That associaiton is either the main user
4  * account, owner's user account, customer's sale rep's user account or
5  * a shared access that has been specifically granted.
6  *
7  * This view can be used to determine which users have personal privilege
8  * access to an Invoice based on what CRM Account it belongs to.
9  */
10
11 select xt.create_view('xt.share_users_invchead', $$
12
13   -- Invoice CRM Account's users.
14   SELECT
15     invchead_cust_crmacct_ids.obj_uuid::uuid AS obj_uuid,
16     username::text AS username
17   FROM (
18     SELECT
19       invchead.obj_uuid,
20       crmacct_id
21     FROM invchead
22     LEFT JOIN custinfo ON invchead_cust_id = cust_id
23     LEFT JOIN crmacct ON cust_id = crmacct_cust_id
24   ) invchead_cust_crmacct_ids
25   LEFT JOIN xt.crmacct_users USING (crmacct_id)
26   WHERE 1=1
27     AND username IS NOT NULL;
28
29 $$, false);