【问题标题】:How to implement "apply credit" to existing invoices if credits are available for that customer via .Net C# code by using Interop.QBFC13Lib.dll?如果使用 Interop.QBFC13Lib.dll 通过 .Net C# 代码为该客户提供信用,如何对现有发票实施“应用信用”?
【发布时间】:2017-07-26 09:22:48
【问题描述】:

如果该客户可以获得信用额度,我在尝试将 Quickbooks 的“应用信用额度”功能应用于现有发票时遇到了困难。我可以通过 Quickbooks 桌面 UI 来实现,但无法通过用 C# 编写的 .Net 集成应用程序来实现它。有人可以指导一下吗?

我用来通过 C# 代码对 Quickbooks 实施“应用信用”的代码。 我收到错误消息:“QuickBooks 在解析提供的 XML 文本流时发现错误。”用下面的代码。

public void ApplyCreditsOnPrePayInvoices()
    {
      // open connection and begin session before data fetch - intentionally skipped this code
      IMsgSetRequest msgset = null;
      ICreditMemoQuery creditMemoQuery = null;
      string sCustomerName = string.Empty;
      if (this.GetConnectedToQB()) //this is the method call to login to quickbooks desktop
      {
        try
        {
          // during data fetch
          msgset = m_sessionManager.CreateMsgSetRequest("US", 8, 0);
          creditMemoQuery = msgset.AppendCreditMemoQueryRq();
          creditMemoQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2012, 3, 31), false);
      IMsgSetResponse msgRes = m_sessionManager.DoRequests(msgset);
      IResponseList responseList = msgRes.ResponseList;
      if (responseList.Count > 0)
      {
        IResponse response = responseList.GetAt(0);
        ICreditMemoRetList creditMemoList = response.Detail as ICreditMemoRetList;
        if (creditMemoList == null)
        {
          return;
        }
        for (int i = 0; i <= creditMemoList.Count - 1; i++)
        {
          ICreditMemoRet qbCreditMemo = creditMemoList.GetAt(i);
          if (this.GetQBCustomerListId(qbCreditMemo.CustomerRef.FullName.GetValue()) != string.Empty)
          {
            m_requestMsgSet.ClearRequests();
            m_requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            IInvoiceAdd invoiceAddRq = m_requestMsgSet.AppendInvoiceAddRq();
            invoiceAddRq.CustomerRef.FullName.SetValue(qbCreditMemo.CustomerRef.FullName.GetValue());
            ISetCredit SetCredit1 = invoiceAddRq.SetCreditList.Append();
            SetCredit1.CreditTxnID.SetValue(qbCreditMemo.TxnID.GetValue());
            SetCredit1.AppliedAmount.SetValue(qbCreditMemo.TotalAmount.GetValue());
            IMsgSetResponse responseSetInvoice = m_sessionManager.DoRequests(m_requestMsgSet);
            DataSet dsInvoice = this.GetExtractResponseFromQB(responseSetInvoice);
            string sQueryResponse = Stringcl.GetValue(dsInvoice.Tables["InvoiceAddRs"].Rows[0]["statusMessage"]);
            if (sQueryResponse == "Status OK")
            {
              Console.WriteLine("Credit no.:" + qbCreditMemo.TxnID.GetValue() + " Customer:" + qbCreditMemo.CustomerRef.FullName.GetValue() + " Total:" + qbCreditMemo.TotalAmount.GetValue());
            }
          }
        }
      }
    }
    catch (Exception ex)
    {
      string ss = ex.Message;
      //handle exception here
    }
    finally
    {
      if (msgset != null)
      {
        Marshal.FinalReleaseComObject(msgset);
      }
      if (creditMemoQuery != null)
      {
        Marshal.FinalReleaseComObject(creditMemoQuery);
      }
    }
  }

  // end session and close connection after data fetch - intentionally skipped this code
}

提前致谢!!

【问题讨论】:

  • 请提供一些您尝试过的代码。你的问题应该是minimal reproducible example
  • 感谢 Balagurunathan 的回复,我已经发布了下面的代码,我用它来实现“应用信用”到 Quickbooks。
  • 您应该编辑您的问题并发布您的代码。请阅读How to Ask好问题
  • 感谢您的回复,我在问题部分做到了,如果可能,请提供帮助。

标签: c# asp.net quickbooks


【解决方案1】:

我通过使用以下函数得到了解决方案:-

public void ApplyCreditsOnPrePayInvoices(string sMonth, string sYear)
{
  IMsgSetRequest IMsgSetRequestToQB = null;
  ICreditMemoQuery ICreditMemoQueryToQB = null;
  string sInvoiceTxnId = string.Empty;
  string sInvoiceNumber = string.Empty;
  if (this.GetConnectedToQB())
  {
    try
    {
      IMsgSetRequestToQB = m_sessionManager.CreateMsgSetRequest("US", 8, 0);
      ICreditMemoQueryToQB = IMsgSetRequestToQB.AppendCreditMemoQueryRq();
      ICreditMemoQueryToQB.ORTxnQuery.TxnFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(DateTimecl.GetValue("1." + sMonth + sYear), true);
      IMsgSetResponse IMsgSetResponseFromQB = m_sessionManager.DoRequests(IMsgSetRequestToQB);
      IResponseList ICreditListMemoAvailable = IMsgSetResponseFromQB.ResponseList;
      if (ICreditListMemoAvailable.Count > 0)
      {
        string sCustomerListIdQB = string.Empty;
        string sCustomerAccountNumber = string.Empty;
        string sQBImportPrepayAccounts = Path.Combine(Environment.CurrentDirectory, sMonth + sYear, "Step11_QBImport_PrepayAccounts.csv");
        DataTable dtQBImportPrepayAccounts = Utilcl.GetDataTableFromCSVFile(sQBImportPrepayAccounts);
        IResponse ICreditMemoAvailable = ICreditListMemoAvailable.GetAt(0);
        ICreditMemoRetList iCreditMemoList = ICreditMemoAvailable.Detail as ICreditMemoRetList;
        if (iCreditMemoList != null)
        {
          for (int iCtr = 0; iCtr <= iCreditMemoList.Count - 1; iCtr++)
          {
            ICreditMemoRet ICreditMemo = iCreditMemoList.GetAt(iCtr);
            DataRow[] drInvoiceNos = dtQBImportPrepayAccounts.Select("RefNumber = '" + ICreditMemo.RefNumber.GetValue() + "'");
            if (drInvoiceNos.Length > 0)
            {
              sInvoiceNumber = Stringcl.GetValue(drInvoiceNos[0]["RefNumber"]);
              m_requestMsgSet.ClearRequests();
              m_requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
              IReceivePaymentAdd IReceivePayment = m_requestMsgSet.AppendReceivePaymentAddRq();
              sInvoiceTxnId = this.GetQBInvoiceTxnIDList(ICreditMemo.CustomerRef.FullName.GetValue()); //To get the Transaction ID of Invoice
              IReceivePayment.CustomerRef.FullName.SetValue(Stringcl.GetValue(ICreditMemo.CustomerRef.FullName.GetValue()));
              IAppliedToTxnAdd IAppliedToTxnAddress = IReceivePayment.ORApplyPayment.AppliedToTxnAddList.Append();
              IAppliedToTxnAddress.TxnID.SetValue(sInvoiceTxnId);
              ISetCredit ISetCreditToInvoice = IAppliedToTxnAddress.SetCreditList.Append();
              ISetCreditToInvoice.CreditTxnID.SetValue(ICreditMemo.TxnID.GetValue());
              ISetCreditToInvoice.AppliedAmount.SetValue(ICreditMemo.TotalAmount.GetValue());
              IMsgSetResponse responseApplyCredit = m_sessionManager.DoRequests(m_requestMsgSet);
              DataSet dsInvoice = this.GetExtractResponseFromQB(responseApplyCredit);
              string sQueryResponse = Stringcl.GetValue(dsInvoice.Tables["ReceivePaymentAddRs"].Rows[0]["statusMessage"]);
              if (sQueryResponse != "Status OK")
              {
                Utilcl.LogMessage("QB Credit Memo Query Response: " + sQueryResponse);
              }
            }
          }
        }
      }
    }
    catch (Exception ex)
    {
      Utilcl.LogMessage(ex);
    }
    finally
    {
      if (IMsgSetRequestToQB != null)
      {
        Marshal.FinalReleaseComObject(IMsgSetRequestToQB);
      }
      if (ICreditMemoQueryToQB != null)
      {
        Marshal.FinalReleaseComObject(ICreditMemoQueryToQB);
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-12
    • 2011-11-26
    • 2022-07-10
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    • 2020-06-29
    • 2020-10-17
    相关资源
    最近更新 更多