
/****** Object:  View [dbo].[ViewChequeInReport]    Script Date: 15/11/1404 11:36:34 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER VIEW [dbo].[ViewChequeInReport]
AS
SELECT   CHQ.ID, CHQ.DebitTotalID, CHQ.DebitControlID, CHQ.DebitDetailID1, CHQ.DebitDetailID2, AccDocHeader.Number AS DocNumber, CHQ.DocItemRelationID, CHQ.BankName, CHQ.BankBranch, CHQ.ChequeNo, CHQ.ChequeDate, 
                CHQ.ChequeValue, CHQ.Description, CHQ.Status, CHQ.CashDate, CashHeader.Number AS CashDocNumber, CashHeader.Flags AS CashFlag, CashHeader.IsPermanent AS CashIsPermanent, CHQ.CashItemRelationID, CHQ.UpdateDate, 
                CHQ.Updater, dbo.FARSI_DATE2(CHQ.ChequeDate) AS ChequeDatePer, CAST(0 AS bit) AS Selected, AccDocHeader.Flags AS DocFlags, AccDocHeader.IsPermanent, CHQ.CashDocItemID, CHQ.DocItemID, DocItem.Description AS ItemDescription, 
                CashItem.Description AS CashItemDescription, CHQOwner.TotalID AS OwnerTotalID, CHQOwner.ControlID AS OwnerControlID, CHQOwner.DetailID1 AS OwnerDetailID1, CHQOwner.DetailID2 AS OwnerDetailID2, 
                CHQCredit.TotalID AS PersonTotalID, CHQCredit.ControlID AS PersonControlID, CHQCredit.DetailID1 AS PersonDetailID1, CHQCredit.DetailID2 AS PersonDetailID2, ReturnItem.Description AS ReturnDescription, 
                ReturnHeader.Number AS ReturnNumber, ReturnHeader.Flags AS ReturnFlags, ReturnHeader.IsPermanent AS ReturnIsPermanent, CHQ.ReturnDocItemID, DocItem.HeaderID AS DocHeaderID, ReturnItem.HeaderID AS ReturnDocHeaderID, 
                CashItem.HeaderID AS CashDocHeaderID, CHQ.Project, CHQ.CostCenter, CHQ.Flags, CHQ.ReturnDate, CHQ.Account, CHQ.Type, CHQOwner.ChequeValue AS OwnerValue, CHQCredit.ChequeValue AS CreditValue
FROM      dbo.AccDocHeader AS ReturnHeader WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccDocHeader AS CashHeader WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccDocItem AS CashItem WITH (NOLOCK) ON CashHeader.ID = CashItem.HeaderID RIGHT OUTER JOIN
                dbo.AccChequeInCredit AS CHQCredit WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccDocHeader AS AccDocHeader WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccDocItem AS ReturnItem WITH (NOLOCK) RIGHT OUTER JOIN
                dbo.AccChequeIn AS CHQ WITH (NOLOCK) ON ReturnItem.ID = CHQ.ReturnDocItemID LEFT OUTER JOIN
                dbo.AccDocItem AS DocItem WITH (NOLOCK) ON CHQ.DocItemID = DocItem.ID ON AccDocHeader.ID = DocItem.HeaderID ON CHQCredit.ChequeInID = CHQ.ID LEFT OUTER JOIN
                dbo.AccChequeInOwner AS CHQOwner WITH (NOLOCK) ON CHQ.ID = CHQOwner.ChequeInID ON CashItem.ID = CHQ.CashDocItemID ON ReturnHeader.ID = ReturnItem.HeaderID
GO


