SQL View可以获取复杂的数据但是针对哪家公司

时间:2017-01-27 16:40:44

标签: acumatica

我创建了一个SQL视图,以根据某些计算获取复杂数据。现在我正在使用这些视图来创建GI。但是,在查看GI结果时,它会向我显示所有公司的数据,无论我登录的是哪家公司。

这是我创建的SQL视图 -



CREATE VIEW [dbo].[vw_View1]
AS
	SELECT	CompanyID,
			OrderNbr, 
			OrderType,
			SUM(BodyCost) AS BodyCost, 
			SUM(TruckCost) AS TruckCost, 
			SUM(CostOfParts) AS CostOfParts, 
			SUM(CostOfLabour) AS CostOfLabour,
			SUM(CostOfSub) AS CostOfSub,
			SUM(GrossSale) AS GrossSale,
			SUM(FET) AS FET,
			SUM(TireCredit) as TireCredit,
			SUM(LabourHours) AS LabourHours,
			InvoiceNbr
	FROM
	(
		SELECT
			/* 00 */ so.CompanyID,
			/* 00 */ so.OrderNbr,
			/* 00 */ so.OrderType,
			/* 05 */ CASE WHEN (ic.ItemClassID = '030')
						OR (ic.ItemClassID = '040')
						OR (ic.ItemClassID = '050')
						OR (ic.ItemClassID = '060')
						OR (ic.ItemClassID = '061')
						OR (ic.ItemClassID = '070')
						OR (ic.ItemClassID = '080')
						OR (ic.ItemClassID = '090')
						OR (ic.ItemClassID = '100')
						THEN SUM(sol.UsrUserDefinedCost * sol.OrderQty) 
					 END AS BodyCost,
			/* 35 */ CASE WHEN (ic.ItemClassID = '110')
						OR (ic.ItemClassID = '111')
						THEN SUM(sol.OrderQty)
					 END AS LabourHours
		FROM	SOOrder so
		LEFT JOIN SOLine sol ON so.OrderType = sol.OrderType AND so.OrderNbr = sol.OrderNbr and so.CompanyID = sol.CompanyID
		LEFT JOIN InventoryItem inv ON sol.InventoryID = inv.InventoryID and sol.CompanyID = inv.CompanyID
		LEFT JOIN INItemClass ic ON inv.ItemClassID = ic.ItemClassID and inv.CompanyID = ic.CompanyID
		WHERE so.CompanyID > 0
		GROUP BY so.CompanyID, 
				so.OrderNbr,
				so.OrderType,
				ic.ItemClassID,
				ic.Descr
	) AS X
	GROUP BY CompanyID, OrderNbr, OrderType, InvoiceNbr;
GO




1 个答案:

答案 0 :(得分:0)

在我的结尾,有一个类似于你的视图,GI结果只包含可从当前公司访问的记录。以下是代码摘要和屏幕截图,以证明这一点:

  • SQL视图:

    CREATE VIEW [dbo].[View1]
    AS
    SELECT  
        CompanyID,
        OrderNbr, 
        OrderType,
        SUM(LabourHours) AS LabourHours
    FROM
        (
            SELECT
                so.CompanyID,
                so.OrderNbr,
                so.OrderType,
                SUM(sol.OrderQty) AS LabourHours
            FROM    SOOrder so
            LEFT JOIN SOLine sol ON so.OrderType = sol.OrderType AND so.OrderNbr = sol.OrderNbr and so.CompanyID = sol.CompanyID
            LEFT JOIN InventoryItem inv ON sol.InventoryID = inv.InventoryID and sol.CompanyID = inv.CompanyID
            LEFT JOIN INItemClass ic ON inv.ItemClassID = ic.ItemClassID and inv.CompanyID = ic.CompanyID
            WHERE so.CompanyID > 0
            GROUP BY so.CompanyID, 
                    so.OrderNbr,
                    so.OrderType,
                    ic.ItemClassID,
                    ic.Descr
        ) AS X
        GROUP BY CompanyID, OrderNbr, OrderType
    GO
    
  • DAC:

    using System;
    using PX.Data;
    
    namespace View
    {
      [Serializable]
      public class View1: IBqlTable
      {
        #region OrderNbr
        [PXDBString(15, IsKey = true, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Order Nbr")]
        public string OrderNbr { get; set; }
    
        public class orderNbr : IBqlField{}
        #endregion
    
        #region OrderType
        [PXDBString(2, IsKey = true, IsFixed = true, InputMask = "")]
        [PXUIField(DisplayName = "Order Type")]
        public string OrderType { get; set; }
    
        public class orderType : IBqlField{}
        #endregion
    
        #region LabourHours
    
        [PXDBDecimal()]
        [PXUIField(DisplayName = "Labour Hours")]
        public Decimal? LabourHours { get; set; }
    
        public class labourHours : IBqlField{}
        #endregion
      }
    }
    
  • 公司的GI结果: enter image description here

  • 公司2的GI结果: enter image description here

根据以下要求,我在两家公司中添加了 SO 类型和 001252 号码的销售订单。请查看下面的截图结果(没有任何意外或奇怪的):

  • 公司的GI结果: enter image description here

  • 公司2的GI结果: enter image description here