/****** Object:  View [dbo].[ViwAccWarehouseInfo]    Script Date: 10/23/2023 01:12:22 ق.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO
                    
ALTER VIEW [dbo].[ViwAccWarehouseInfo]
AS
SELECT     dbo.AccWarehouseInfo.ID, dbo.AccWarehouseInfo.Type, dbo.AccWarehouseInfo.Price, dbo.AccWarehouseInfo.Unit, dbo.SmallLists.Title AS UnitName, 
                      dbo.AccWarehouseInfo.MinimumIn, dbo.AccWarehouseInfo.OrderPoint, dbo.AccWarehouseInfo.Description, 
                      CASE dbo.AccWarehouseInfo.Type WHEN 0 THEN dbo.AccTotal.Title WHEN 1 THEN dbo.AccControl.Title ELSE dbo.AccDetail.Title END AS Title, 
                      dbo.AccWarehouseInfo.PriceSell, dbo.AccWarehouseInfo.IranCode, dbo.AccWarehouseInfo.BarCode, dbo.AccWarehouseInfo.StandardCode, 
                      dbo.AccWarehouseInfo.Avarez, dbo.AccWarehouseInfo.WareAddress, dbo.AccWarehouseInfo.AccID, dbo.AccWarehouseInfo.TotalID, 
                      dbo.AccWarehouseInfo.ControlID, dbo.AccWarehouseInfo.DetailID1, dbo.AccWarehouseInfo.DetailID2,
                      CASE dbo.AccWarehouseInfo.Type WHEN 0 THEN dbo.AccTotal.Code WHEN 1 THEN dbo.AccControl.Code ELSE dbo.AccDetail.Code END AS AccCode, 
                      dbo.AccTotal.Code as TotalCode, dbo.AccControl.Code as ControlCode, dbo.AccDetail.Code DetailCode
FROM         dbo.AccWarehouseInfo LEFT OUTER JOIN
                      dbo.SmallLists ON dbo.AccWarehouseInfo.Unit = dbo.SmallLists.ID LEFT OUTER JOIN
                      dbo.AccTotal ON dbo.AccWarehouseInfo.AccID = dbo.AccTotal.ID LEFT OUTER JOIN
                      dbo.AccDetail ON dbo.AccWarehouseInfo.AccID = dbo.AccDetail.ID LEFT OUTER JOIN
                      dbo.AccControl ON dbo.AccWarehouseInfo.AccID = dbo.AccControl.ID
WHERE     ((dbo.AccTotal.Type IN (4)) OR
          (dbo.AccDetail.Type is null or dbo.AccDetail.Type IN (4)) OR
          (dbo.AccControl.Type is null or dbo.AccControl.Type IN (4))) 
		and CASE dbo.AccWarehouseInfo.Type WHEN 0 THEN dbo.AccTotal.Code WHEN 1 THEN dbo.AccControl.Code ELSE dbo.AccDetail.Code END IS NOT NULL

GO

