use JATesting
/* 
	-- REVERSE "Finalize Day".....
	declare @storenum int = (select distinct entityid from tbEntity where StoreNumber = '00663')
	declare @workingdate varchar(10) = '05/26/2020'

	update tbBankingClose
	set Authorised = 0
	where BankingDate = @workingdate and entityid = @storenum

	update tbWorkFlowTemplateInstance
	set StatusID = 0
	where BusinessDay = @workingdate and EntityID = @storenum

	
update tbWorkFlowTasksStatus set statusid = 4, StartTime = '11/02/2021', EndTime = '11/03/2021' where 
WorkFlowStatusID =
68400386



	get the individual status (StatusID) of each workflow step for a given instanceid....
	select * from tbWorkFlowTemplateInstance where BusinessDay = '5/13/2020' and EntityID = (select distinct entityid from tbEntity where StoreNumber = '01919')

	delete from tbWorkFlowTasksStatus where WorkFlowStatusParentID
	= 68475283

	update tbWorkFlowTasksStatus set StatusID = 0 where WorkFlowStatusID
	in (68475050)

select t.Description, w.* from tbWorkFlowTasksStatus w inner join tbWorkFlowTasks t on w.TaskID = t.TaskID where InstanceID = 3333124 order by WorkFlowStatusID desc

exec sp_helptext 'qryMMSWorkFlow_SetTaskToBegin'
exec sp_helptext 'MXC_Workflow_DetailTasksForDay'
exec sp_helptext 'MXC_Workflow_CurrentInstance'
exec MXC_Workflow_CurrentInstance @storenum
*/
declare @instanceid int = 3333124
declare @wfstatusid int = (select top 1 workflowstatusid from tbWorkFlowTasksStatus where instanceid = @instanceid)
declare @storenum int = (select distinct entityid from tbEntity where StoreNumber = '00663')


--declare @wfstatusid int = 68475050

-- ii. - show a specific task ....
select t.Description, w.* from tbWorkFlowTasksStatus w inner join tbWorkFlowTasks t on w.TaskID = t.TaskID where 
InstanceID = @instanceid
--WorkFlowStatusID = @wfstatusid

-- iii. - show ALL the tasks for a specific - instance id...
select t.Description, w.* from tbWorkFlowTasksStatus w inner join tbWorkFlowTasks t on w.TaskID = t.TaskID where 
w.InstanceID = @instanceid


-- iv. - show ALL the tasks for a specific - parent id...
select t.Description, w.* from tbWorkFlowTasksStatus w inner join tbWorkFlowTasks t on w.TaskID = t.TaskID where 
WorkFlowStatusParentID = (select top 1 WorkFlowStatusParentID from tbWorkFlowTasksStatus where WorkFlowStatusID = @wfstatusid)

select * from tbBankingClose
	--set Authorised = 0
	--where TransactionDate = '11/19/2020' and 
	where entityid = (select distinct EntityID from tbEntity where StoreNumber = '01580') order by BankingDate desc