
/****** Object:  View [dbo].[vsSellFactorDetail1]    Script Date: 3/7/2025 11:50:07 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


create view [dbo].[vsSellFactorDetail1]
AS
select Number, ID AS OrderID, TrucksID, TrucksWeight , OrderDate, OrderDatePer, TrucksDate, TrucksDatePer, SellPrice, BuyPrice, OrderFullCode,OrderTitle,BuyerFullCode,BuyerTitle,SellerFullCode,SellerTitle,Request,RequestText,Destination, BKharidId, Cottage, City, Address, BKhAddress from ViwSellFactorDetail 
GO


/****** Object:  View [dbo].[vsSellFactor1]    Script Date: 3/7/2025 11:53:51 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


create view [dbo].[vsSellFactor1]
AS
select Main.Number, Main.ID AS OrderID, Main.OrderDate, OrderDatePer, Main.Request, Main.RequestText, Main.TrucksWeight, Main.Request-TrucksWeight as REM, Main.Source, Main.SellPrice, Main.BuyPrice
, AccOrder.FullCode AS OrderFullCode, AccOrder.Title as OrderTitle
, AccBuyer.FullCode as BuyerFullCode, AccBuyer.Title as BuyerTitle
, AccSeller.FullCode as SellerFullCode,AccSeller.Title as SellerTitle
, Main.Destination, Cottage, City, Address, BKhAddress 
from ViwAccSellFactor as Main LEFT OUTER JOIN
    dbo.ViwAccounts AS AccOrder WITH (NOLOCK) ON AccOrder.TotalID = Main.OrderTotalID AND AccOrder.ControlID = Main.OrderControlID AND AccOrder.Detail1ID = Main.OrderDetailID1 AND 
    AccOrder.Detail2ID = Main.OrderDetailID2 LEFT OUTER JOIN
    dbo.ViwAccounts AS AccBuyer WITH (NOLOCK) ON AccBuyer.TotalID = Main.BuyerTotalID AND AccBuyer.ControlID = Main.BuyerControlID AND AccBuyer.Detail1ID = Main.BuyerDetailID1 AND 
    AccBuyer.Detail2ID = Main.BuyerDetailID2 LEFT OUTER JOIN
    dbo.ViwAccounts AS AccSeller WITH (NOLOCK) ON AccSeller.TotalID = Main.SellerTotalID AND AccSeller.ControlID = Main.SellerControlID AND AccSeller.Detail1ID = Main.SellerDetailID1 AND 
    AccSeller.Detail2ID = Main.SellerDetailID2 
GO

/****** Object:  View [dbo].[vsDocs1]    Script Date: 3/7/2025 11:54:02 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


create view [dbo].[vsDocs1]
AS
Select SUM(Debit) as Debit, SUM(Credit) as Credit, FullCode, Title from 
(
select Main.Debit,Main.Credit, Acc.FullCode, Acc.Title   from AccDocumentGoods as Main  LEFT OUTER JOIN
   dbo.ViwAccounts AS Acc WITH (NOLOCK) ON Acc.TotalID = Main.TotalID AND Acc.ControlID = Main.ControlID AND Acc.Detail1ID = Main.DetailID1 AND 
    Acc.Detail2ID = Main.DetailID2 
) t
group by   FullCode, Title 
GO


