提供PXSelector的数据查询

时间:2019-02-12 01:04:58

标签: acumatica

我需要建议将SQL转换为BQL或将C#代码操纵的结果集设置为PXSelector。

我需要自定义AR发票,并添加2个自定义字段来记录公司间客户将此发票行作为帐单时公司间客户的COGS GL帐户和子帐户。此自定义字段需要查找仅限于此客户的分支机构ID和GL帐户的所有子帐户。基本上,所有系统的子帐户查找都由限制组负责,但自定义字段除外;为此,需要编写一个自定义的PXSelector。下面是提供require子帐户的SQL,但是我需要知道如何使SQL查询在Acumatica中工作

-所需数据的SQL

rectheight

-以下PXSelector提供了限制组的所有子帐户方面的信息, -我需要PXSelector才能使用上面的SQL查询结果

DECLARE @GLAccountCD nvarchar(10) = 'COGS'
DECLARE @BranchCD nvarchar(30) = 'PurchaseBranch'
SELECT * 
FROM Sub 
where (((CAST(Sub.groupmask as int) & CAST((SELECT GroupMask FROM Account WHERE AccountCD = @GLAccountCD AND CompanyID = 3 AND DeletedDatabaseRecord = 0) AS int)) > 1 
        AND (CAST(Sub.groupmask as int) & CAST((SELECT GroupMask FROM Branch WHERE BranchCD = @BranchCD AND CompanyID = 3 AND DeletedDatabaseRecord = 0) AS int)) > 1)
        OR (Sub.GroupMask = 0 AND Sub.DeletedDatabaseRecord = 0))
        AND CompanyID = 3
ORDER BY SubCD

1 个答案:

答案 0 :(得分:0)

我认为使用Match BQL clause是可以实现的。

GLAccess.cs文件具有BQL查询以使用Match子句来限制基于Sub和Branch组掩码的帐户,这将是调查的好地方:

public PXSelect<Sub> Sub;
protected virtual IEnumerable sub(
)
{
    if (Group.Current != null && !String.IsNullOrEmpty(Group.Current.GroupName))
    {
        bool inserted = (Group.Cache.GetStatus(Group.Current) == PXEntryStatus.Inserted);
        foreach (Sub item in PXSelect<Sub,
            Where2<Match<Current<PX.SM.RelationGroup.groupName>>,
            Or2<Match<Required<Sub.groupMask>>, Or<Sub.groupMask, IsNull>>>>
            .Select(this, new byte[0]))
        {
            if (!inserted || item.Included == true)
            {
                Sub.Current = item;
                yield return item;
            }
            else if (item.GroupMask != null)
            {
                PX.SM.RelationGroup group = Group.Current;
                bool anyGroup = false;
                for (int i = 0; i < item.GroupMask.Length && i < group.GroupMask.Length; i++)
                {
                    if (group.GroupMask[i] != 0x00 && (item.GroupMask[i] & group.GroupMask[i]) == group.GroupMask[i])
                    {
                        Sub.Current = item;
                        yield return item;
                    }
                    anyGroup |= item.GroupMask[i] != 0x00;
                }
                if (!anyGroup)
                {
                    Sub.Current = item;
                    yield return item;
                }
            }
        }
    }
    else
    {
        yield break;
    }
}
public PXSelect<Branch> Branch;
protected virtual IEnumerable branch(
)
{
    if (Group.Current != null && !String.IsNullOrEmpty(Group.Current.GroupName))
    {
        bool inserted = (Group.Cache.GetStatus(Group.Current) == PXEntryStatus.Inserted);
        foreach (Branch item in PXSelect<Branch,
            Where2<Match<Current<PX.SM.RelationGroup.groupName>>,
            Or<Match<Required<Branch.groupMask>>>>>
            .Select(this, new byte[0]))
        {
            if (!inserted)
            {
                Branch.Current = item;
                yield return item;
            }
            else if (item.GroupMask != null)
            {
                PX.SM.RelationGroup group = Group.Current;
                bool anyGroup = false;
                for (int i = 0; i < item.GroupMask.Length && i < group.GroupMask.Length; i++)
                {
                    if (group.GroupMask[i] != 0x00 && (item.GroupMask[i] & group.GroupMask[i]) == group.GroupMask[i])
                    {
                        Branch.Current = item;
                        yield return item;
                    }
                    anyGroup |= item.GroupMask[i] != 0x00;
                }
                if (!anyGroup)
                {
                    Branch.Current = item;
                    yield return item;
                }
            }
        }
    }
    else
    {
        yield break;
    }
}