0

我将其归结为一个使用 QB Enterprise 总是失败的简单示例。(奇怪的是,我可以发誓这段代码曾经可以工作。)

  1. 通过 SDK 使用特定参考号“PTD1234”创建日记帐分录
  2. 在同一代码块中搜索该特定日记帐分录
  3. 观察,没有发现结果?

但是,如果我更改流程以在 QB 中手动创建相同的日记帐分录,则下面的搜索代码可以正常工作并找到日记帐分录。

        Quickbooks qb = new Quickbooks();
        qb.Connect(this);

        IMsgSetRequest msr = qb.sm.CreateMsgSetRequest("US", 7, 0);
        msr.Attributes.OnError = ENRqOnError.roeStop;

        IJournalEntryAdd jea = msr.AppendJournalEntryAddRq();

        jea.TxnDate.SetValue(new DateTime(2013, 3, 1));
        jea.RefNumber.SetValue("PTD1234");

        IJournalCreditLine jcl = jea.ORJournalLineList.Append().JournalCreditLine;
        jcl.Amount.SetValue(1);
        jcl.AccountRef.FullName.SetValue("Credit Card Batches:Paymentech");
        jcl.EntityRef.FullName.SetValue("CHASE PAYMENTECH");

        IJournalDebitLine jdl = jea.ORJournalLineList.Append().JournalDebitLine;
        jdl.Amount.SetValue(1);
        jdl.AccountRef.FullName.SetValue("Chase Deposits EUR");
        jdl.EntityRef.FullName.SetValue("CHASE PAYMENTECH");

        IMsgSetResponse msp = qb.sm.DoRequests(msr);
        IResponse resp = msp.ResponseList.GetAt(0);
        if (resp.StatusCode != 0)
        {
            Log("-------------\r\nError during test");
            Log(resp.StatusMessage);
        }

        IJournalEntryRet jet = null;

        msr = qb.sm.CreateMsgSetRequest("US", 7, 0);
        msr.Attributes.OnError = ENRqOnError.roeStop;

        IJournalEntryQuery q = msr.AppendJournalEntryQueryRq();
        q.metaData.SetValue(ENmetaData.mdNoMetaData);
        q.ORTxnQuery.TxnFilter.ORRefNumberFilter.RefNumberFilter.RefNumber.SetValue("PTD1234");
        q.ORTxnQuery.TxnFilter.ORRefNumberFilter.RefNumberFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
        q.ORTxnQuery.TxnFilter.AccountFilter.ORAccountFilter.FullNameList.Add("Chase Deposits EUR");
        q.IncludeLineItems.SetValue(false);

        msp = qb.sm.DoRequests(msr);
        if (msp.ResponseList.Count > 0)
        {
            IResponseList rl = msp.ResponseList;
            if (rl.Count >= 1)
            {
                IResponse r = rl.GetAt(0);
                if (r.Detail == null)
                    Log("Fail: Detail was null");

                if (r.StatusCode != 0)
                    Log("Fail: Status code was not zero");

                if (r.Type.GetValue() == (short)ENResponseType.rtJournalEntryQueryRs)
                {
                    IJournalEntryRetList crl = (IJournalEntryRetList)r.Detail;
                    if (crl != null && crl.Count == 1)
                        jet = crl.GetAt(0);
                }
            }
        }

        if (jet != null)
            Log("Success!");

        qb.Cleanup();
4

1 回答 1

0

由于未知原因,使用 JournalEntryQuery 和 TxnFilter.ORRefNumberFilter.RefNumberFilter 不会显示某些日记条目。但是,一种解决方法是使用 ORTxnQuery.RefNumberList,然后循环浏览日记帐行并确保帐户匹配。

   public bool GetExactJournalTransaction(string sRefNum, string sAccount, out IJournalEntryRet jet)
    {
        jet = null;

        IMsgSetRequest msr = sm.CreateMsgSetRequest("US", 4, 0);
        msr.Attributes.OnError = ENRqOnError.roeStop;

        IJournalEntryQuery q = msr.AppendJournalEntryQueryRq();
        q.metaData.SetValue(ENmetaData.mdNoMetaData);
        q.ORTxnQuery.RefNumberList.Add(sRefNum);
        q.IncludeLineItems.SetValue(true);


        IMsgSetResponse resp = sm.DoRequests(msr);
        if (resp.ResponseList.Count == 0)
            return false;

        IResponseList rl = resp.ResponseList;
        if (rl.Count == 1)
        {
            IResponse r = rl.GetAt(0);
            if (r.Detail == null)
                return false;

            if (r.StatusCode != 0)
                return false;

            if (r.Type.GetValue() == (short)ENResponseType.rtJournalEntryQueryRs)
            {
                IJournalEntryRetList crl = (IJournalEntryRetList)r.Detail;
                if (crl != null)
                {
                    for (int i = 0; i < crl.Count; i++)
                    {
                        jet = crl.GetAt(i);
                        for (int j = 0; j < jet.ORJournalLineList.Count; j++)
                        {
                            IORJournalLine l = jet.ORJournalLineList.GetAt(j);
                            if (l.JournalCreditLine != null && l.JournalCreditLine.AccountRef.FullName.GetValue() == sAccount)
                                return true;
                            else if (l.JournalDebitLine != null && l.JournalDebitLine.AccountRef.FullName.GetValue() == sAccount)
                                return true;
                        }
                    }
                }
            }
        }
        return false;
    }
于 2013-03-13T02:37:05.913 回答