/****** Object:  View [dbo].[ViwSellFactorByDate]    Script Date: 25/1/2025 01:38:52 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/*WHERE  (dbo.ViwSellFactorDetail.SellType in (1,2)) AND (dbo.AccDocumentGoods.Debit>0)*/
ALTER VIEW [dbo].[ViwSellFactorByDate]
AS
SELECT   dbo.ViwSellFactorDetail.TrucksDocItemID AS ItemID, dbo.ViwSellFactorDetail.SellType, dbo.ViwSellFactorDetail.SellTime, dbo.FarsiDateAdd(CASE dbo.ViwSellFactorDetail.SellType WHEN 1 THEN 1 WHEN 2 THEN 0 END, 
                dbo.AccDocumentGoods.DocDate, dbo.ViwSellFactorDetail.SellTime) - dbo.FarsiDate2Days(GETDATE()) AS DaysEnd, dbo.AccDocumentGoods.Number AS DocNumber, dbo.AccDocumentGoods.DocDate, dbo.AccDocumentGoods.TotalID, 
                dbo.AccDocumentGoods.ControlID, dbo.AccDocumentGoods.DetailID1, dbo.AccDocumentGoods.DetailID2, dbo.AccDocumentGoods.Selected, dbo.AccDocumentGoods.DocDatePer, dbo.AccDocumentGoods.Credit, dbo.AccDocumentGoods.Debit, 
                dbo.ViwSellFactorDetail.CompanyCode, dbo.ViwSellFactorDetail.FactorLazem, dbo.ViwSellFactorDetail.TaghirStatus, dbo.ViwSellFactorDetail.VizTotalID, dbo.ViwSellFactorDetail.VizControlID, dbo.ViwSellFactorDetail.VizDetailID1, 
                dbo.ViwSellFactorDetail.VizDetailID2, dbo.ViwSellFactorDetail.VizValue, dbo.ViwSellFactorDetail.ShomNameh, dbo.ViwSellFactorDetail.TarikhNameh
FROM      dbo.ViwSellFactorDetail LEFT OUTER JOIN
                dbo.AccDocumentGoods ON dbo.ViwSellFactorDetail.TrucksDocItemID = dbo.AccDocumentGoods.ItemID
GO


