/****** Object:  View [dbo].[ViwAccSellFactor2]    Script Date: 25/1/2025 01:26:39 ب.ظ ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



ALTER VIEW [dbo].[ViwAccSellFactor2]
AS
SELECT        Main.ID, Main.Number, Main.OrderDate, Main.OrderTotalID, Main.OrderControlID, Main.OrderDetailID1, Main.OrderDetailID2, Main.Type, Main.Source, Main.BuyerTotalID, Main.BuyerControlID, Main.BuyerDetailID1, 
                         Main.BuyerDetailID2, Main.SellerTotalID, Main.SellerControlID, Main.SellerDetailID1, Main.SellerDetailID2, Main.Request, Main.RequestUnit, Main.RequestText, Main.SendDate, Main.ControlA, Main.ControlB, Main.ControlC, 
                         Main.ControlD, Main.SellType, Main.SellTime, Main.SellPrice, Main.BuyType, Main.BuyTime, Main.BuyPrice, Main.City, Main.Destination, Main.Address, Main.DocItemID, Main.DocItemRelationID, Main.DocItemType, 
                         Main.Description, Main.UpdateDate, Main.Updater, Main.Trailer, COALESCE (Trucks.Weigh, 0) AS TrucksWeight, dbo.FARSI_DATE2(Main.OrderDate) AS OrderDatePer, CAST(0 AS bit) AS Selected, COALESCE (Trucks.DocItemID, 0) 
                         AS TrucksDocItemID, Main.PrintCount, Main.BuyerRef, Main.MelliCode, Main.BuyerPaid, Main.SellerPaid, Main.IsPermanent, Main.Tel, Main.BuyPrice2, Main.SellPrice2, Main.Barbari, Main.WareOutID, Main.WareInID, 
                         Main.PostalCode, Main.FinancialCode, Main.WareOrderID, Main.InsertDate, Main.Inserter, Main.CancelDate, Main.ProfitType, Main.Canceler, Main.PermanentDate, Main.Permanenter, Main.Sender, Main.AppData, Main.FactorID, 
                         Main.Sign1User, Main.Sign1Date, Main.Sign2User, Main.Sign2Date, dbo.FARSI_DATE2(Main.UpdateDate) AS UpdateDatePer, dbo.FARSI_DATE2(Main.InsertDate) AS InsertDatePer, dbo.FARSI_DATE2(Main.SendDate) 
                         AS SendDatePer, dbo.FARSI_DATE2(Main.CancelDate) AS CancelDatePer, CONVERT(bit, CASE MelliCards.Image1 WHEN MelliCards.Image1 THEN 1 ELSE 0 END) AS HasMelliImage, Main.Cottage
FROM            dbo.AccSellFactor AS Main WITH (NOLOCK) RIGHT OUTER JOIN
                             (SELECT        SellFactorID, CAST(0 AS bigint) AS DocItemID, SUM(Weigh) AS Weigh
                                FROM            dbo.AccSellFactorTrucks WITH (NOLOCK)
                                WHERE        (DocItemID > 0)
                                GROUP BY SellFactorID) AS Trucks ON Main.ID = Trucks.SellFactorID LEFT OUTER JOIN
                         dbo.MelliCards ON Main.MelliCode = dbo.MelliCards.MelliCode
GO


