
ALTER PROC PROC_SYNCHRONIZE_ISLAMI(
	  @Flag VARCHAR(10)
	 ,@AGENTID VARCHAR(10)
	 ,@TRANID VARCHAR(10)=NULL
	 ,@CONTROLNO VARCHAR(30)=NULL
)AS
SET NOCOUNT ON;
SET XACT_ABORT ON;
BEGIN
	IF @Flag='list'
	BEGIN
		SELECT TOP 5
			 'GM' + CAST(id AS VARCHAR(50)) AS TranId
			--,dbo.FNADecryptString(controlNo) AS ControlNo
			--,controlNo2 AS ControlNo2
			--,ContNo AS ContNo 
		FROM dbo.remitTran(NOLOCK) WHERE pAgent=@AGENTID
	END

	ELSE IF @Flag='paid'
	BEGIN
		UPDATE remitTran SET 
			payStatus		= 'Paid', 
			tranStatus		= 'Paid', 
			paidBy			= 'system', 
			paidDate		= GETDATE(),
			paidDateLocal	= GETUTCDATE()
		WHERE id = @TRANID
		AND payStatus IN ('Post','Unpaid') AND tranStatus='Payment' AND pAgent  = @AGENTID
	END

	ELSE IF @Flag='cancel'
	BEGIN
		DECLARE @message VARCHAR(100)='Cancel in Api'
		SELECT @CONTROLNO = DBO.FNADecryptString(CONTROLNO) FROM remitTran(NOLOCK) WHERE id = @TRANID AND pAgent  = @AGENTID

		EXEC [proc_cancelTran] @flag = 'cancel',@controlNo = @CONTROLNO,@user = 'system',@cancelReason = @message,@refund = 'N'

		EXEC [proc_cancelTran] @flag = 'cancelReceipt',@tranId = @TRANID,@user = 'system'
	END
END


