/****** Object:  View [dbo].[ViewChequeOutReport]    Script Date: 13/11/2024 11:21:41 ق.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



ALTER VIEW [dbo].[ViewChequeOutReport]
AS
SELECT   dbo.AccChequeOut.ID, dbo.AccChequeOut.DebitTotalID, dbo.AccChequeOut.DebitControlID, dbo.AccChequeOut.DebitDetailID1, dbo.AccChequeOut.DebitDetailID2, dbo.AccChequeOut.CreditTotalID, dbo.AccChequeOut.CreditControlID, 
                dbo.AccChequeOut.CreditDetailID1, dbo.AccChequeOut.CreditDetailID2, AccDocHeader.Number AS DocNumber, dbo.AccChequeOut.DocItemRelationID, ' ' AS BankName, ' ' AS BankBranch, dbo.AccChequeOutItemInfo.ChequeNo, 
                dbo.AccChequeOutItemInfo.ChequeDate, dbo.AccChequeOutItemInfo.ChequeValue, dbo.AccChequeOut.Description, CAST(COALESCE (dbo.AccChequeOutItemInfo.Status, 0) AS int) AS Status, dbo.AccChequeOutItemInfo.CashDate, 
                CashHeader.Number AS CashDocNumber, dbo.AccChequeOutItemInfo.CashDocItemRelationID, dbo.AccChequeOut.UpdateDate, dbo.AccChequeOut.Updater, 
                dbo.FARSI_DATE2(dbo.AccChequeOutItemInfo.ChequeDate) AS ChequeDatePer, CAST(0 AS bit) AS Selected, AccDocHeader.Flags, AccDocHeader.IsPermanent, CashHeader.Flags AS CashFlag, CashHeader.IsPermanent AS CashIsPermanent, 
                dbo.AccChequeOutItemInfo.CashDocItemID, dbo.AccChequeOut.DocItemID, DocItem.Description AS ItemDescription, CashItem.Description AS CashItemDescription, dbo.AccChequeOutItemInfo.TotalID, dbo.AccChequeOutItemInfo.ControlID, 
                dbo.AccChequeOutItemInfo.DetailID1, dbo.AccChequeOutItemInfo.DetailID2, dbo.AccChequeOutDebit.TotalID AS PersonTotalID, dbo.AccChequeOutDebit.ControlID AS PersonControlID, dbo.AccChequeOutDebit.DetailID1 AS PersonDetailID1, 
                dbo.AccChequeOutDebit.DetailID2 AS PersonDetailID2, ReturnItem.Description AS ReturnDescription, ReturnHeader.Number as ReturnNumber, ReturnHeader.Flags AS ReturnFlags, ReturnHeader.IsPermanent AS ReturnIsPermanent, dbo.AccChequeOutItemInfo.ReturnDocItemID, DocItem.HeaderID as DocHeaderID, ReturnItem.headerID as ReturnDocHeaderID, CashItem.HeaderID as CashDocHeaderID
FROM      dbo.AccChequeOut WITH (NOLOCK) LEFT OUTER JOIN
                dbo.AccDocHeader AS AccDocHeader WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccDocItem AS DocItem WITH (NOLOCK) ON AccDocHeader.ID = DocItem.HeaderID ON dbo.AccChequeOut.DocItemID = DocItem.ID LEFT OUTER JOIN
                dbo.AccDocItem AS CashItem WITH (NOLOCK) LEFT OUTER JOIN
                dbo.AccDocHeader AS CashHeader WITH (NOLOCK) ON CashItem.HeaderID = CashHeader.ID RIGHT OUTER JOIN
                dbo.AccChequeOutItemInfo WITH (NOLOCK) LEFT OUTER JOIN
                dbo.AccDocItem AS ReturnItem LEFT OUTER JOIN
                dbo.AccDocHeader AS ReturnHeader ON ReturnItem.HeaderID = ReturnHeader.ID ON dbo.AccChequeOutItemInfo.ReturnDocItemID = ReturnItem.ID ON CashItem.ID = dbo.AccChequeOutItemInfo.CashDocItemID ON 
                dbo.AccChequeOut.ID = dbo.AccChequeOutItemInfo.ChequeOutID LEFT OUTER JOIN
                dbo.AccChequeOutDebit ON dbo.AccChequeOut.ID = dbo.AccChequeOutDebit.ChequeOutID
GO


