
select * from CUSTOMIZED_FORM_USER_OR_GROUP
where idno in (
	select idno from personal where active = 'T'
)
and CUSTOMIZED_FORM_ID = 53

EXEC GET_ASSIGNED_FORMS_DETAILS 'SALES QUOTE','AEV','SALES QUOTE'
EXEC GET_ASSIGNED_FORMS_DETAILS 'SALES ORDERS','SUP-MU','SALES ORDERS'

select * from CUSTOMIZED_FORM where CUSTOMIZED_FORM_ID in (54,36)

select * from CUSTOMIZED_FORM where CUSTOMIZED_FORM_ID in (53)

select * from CUSTOMIZED_FORM where form_name like 'SALES QUOTE%'

select * into zd2300763_SO_FORM_53
from CUSTOMIZED_FORM_USER_OR_GROUP
where CUSTOMIZED_FORM_ID = 53

rollback

--begin transaction 
--update CUSTOMIZED_FORM_USER_OR_GROUP set CUSTOMIZED_FORM_ID = 36 where CUSTOMIZED_FORM_ID = 54 and CUSTOMIZED_FORM_USER_OR_GROUP_ID in (
--select CUSTOMIZED_FORM_USER_OR_GROUP_ID from zd2300763_SQ_FORM_54
--where department is null or DEPARTMENT not in ('EVERY')
--)

--commit transaction 

EXEC GET_ASSIGNED_FORMS_DETAILS 'SALES ORDER','SUP-MU','SALES ORDER'
select * from CUSTOMIZED_FORM where form_name like 'SALES ORDER%' -- 37

SELECT * FROM CUSTOMIZED_FORM_USER_OR_GROUP WHERE CUSTOMIZED_FORM_USER_OR_GROUP_ID = 412
SELECT * FROM CUSTOMIZED_FORM_USER_OR_GROUP WHERE CUSTOMIZED_FORM_ID = 53

/*
BEGIN TRANSACTION 
UPDATE CUSTOMIZED_FORM_USER_OR_GROUP SET CUSTOMIZED_FORM_ID=37 WHERE CUSTOMIZED_FORM_USER_OR_GROUP_ID IN (
SELECT CUSTOMIZED_FORM_USER_OR_GROUP_ID FROM zd2300763_SO_FORM_53
) -- 53

COMMIT TRANSACTION 

ROLLBACK
*/
---------

EXEC GET_ASSIGNED_FORMS_DETAILS 'SALES INVOICE','DMB','SALES INVOICE'--49

select * from CUSTOMIZED_FORM where form_name like 'SALES INVOICE%' -- 38
select FORM_SPECIFICATION from CUSTOMIZED_FORM where CUSTOMIZED_FORM_ID = 38


select * into zd2300763_SI_FORM_49
from CUSTOMIZED_FORM_USER_OR_GROUP
where CUSTOMIZED_FORM_ID = 49


--BEGIN TRANSACTION 
--UPDATE CUSTOMIZED_FORM_USER_OR_GROUP SET CUSTOMIZED_FORM_ID=38 WHERE CUSTOMIZED_FORM_USER_OR_GROUP_ID IN (
--SELECT CUSTOMIZED_FORM_USER_OR_GROUP_ID FROM zd2300763_SI_FORM_49 
--) -- 53

--commit

Select * FROM CUSTOMIZED_FORM_USER_OR_GROUP A JOIN CUSTOMIZED_FORM C ON(C.CUSTOMIZED_FORM_ID=A.CUSTOMIZED_FORM_ID) JOIN GROUPS G ON (G.DEPARTMENT= A.DEPARTMENT) WHERE A.CUSTOMIZED_FORM_ID = 51 AND G.ACTIVE = 'T'

select * from groups where active = 'T' and department not in(SELECT DEPARTMENT FROM CUSTOMIZED_FORM_USER_OR_GROUP A JOIN CUSTOMIZED_FORM C ON( C.CUSTOMIZED_FORM_ID = A.CUSTOMIZED_FORM_ID) WHERE DEPARTMENT is not null and A.CUSTOMIZED_FORM_ID = 51  AND C.IS_SYSTEM_FORM <> 'T')

SELECT f.* FROM MEMBERS M WITH(NOLOCK)  
		, CUSTOMIZED_FORM_USER_OR_GROUP F WITH(NOLOCK)  
		WHERE M.MEMBER_OF = F.DEPARTMENT  
		AND M.USER_ID = 'SUP-MU'   
		AND F.CUSTOMIZED_FORM_ID IN (SELECT CUSTOMIZED_FORM_ID   
		FROM CUSTOMIZED_FORM C WITH(NOLOCK), FORM R WITH(NOLOCK)   
		WHERE C.FORM_ID = R.FORM_ID AND R.FORM_CLASS = 'SALES INVOICE')  
		ORDER BY MEMBER_OF ASC


select * from CUSTOMIZED_FORM where form_name like 'SALES INVOICE%' -- 38

		SELECT C.CUSTOMIZED_FORM_ID , C.FORM_ID, A.*, f.*  
		FROM CUSTOMIZED_FORM C WITH(NOLOCK), FORM F WITH(NOLOCK)  
		, CUSTOMIZED_FORM_USER_OR_GROUP A WITH(NOLOCK)  
		WHERE F.FORM_ID = C.FORM_ID   
		AND A.CUSTOMIZED_FORM_ID = C.CUSTOMIZED_FORM_ID  
		AND A.DEPARTMENT = 'Admin'
		AND C.DOC_ALIAS = ''
		AND F.FORM_CLASS ='SALES INVOICE'

		SELECT C.CUSTOMIZED_FORM_ID , C.FORM_ID,  f.*  
		FROM CUSTOMIZED_FORM C WITH(NOLOCK), FORM F WITH(NOLOCK)  
		WHERE F.FORM_ID = C.FORM_ID   
		AND C.DOC_ALIAS = ''
		AND F.FORM_CLASS ='SALES INVOICE'

		select * from CUSTOMIZED_FORM_USER_OR_GROUP where customized_form_id in (
			38
		)

select * from CUSTOMIZED_FORM_USER_OR_GROUP where CUSTOMIZED_FORM_USER_OR_GROUP_ID = 150

--begin transaction 
--update CUSTOMIZED_FORM_USER_OR_GROUP set customized_form_id = 38 where CUSTOMIZED_FORM_USER_OR_GROUP_ID = 150

--commit transaction 
