I'd like to query for an account balance as of a given day.
It looks like I could probably do this using the CustomDetailReportQuery, but seems like overkill.
I'd like to query for an account balance as of a given day.
It looks like I could probably do this using the CustomDetailReportQuery, but seems like overkill.
The only way I know how is to use the CustomDetailReportQuery and set the appropriate dates, and look for the Total Row.
public bool GetBalance(string sAccount, DateTime dt, out decimal balance)
{
balance = 0.0M;
IMsgSetRequest msr = sm.CreateMsgSetRequest("US", 7, 0);
msr.Attributes.OnError = ENRqOnError.roeStop;
ICustomDetailReportQuery q = msr.AppendCustomDetailReportQueryRq();
q.ReportOpenBalanceAsOf.SetValue(ENReportOpenBalanceAsOf.robaoReportEndDate);
q.DisplayReport.SetValue(false);
q.IncludeColumnList.Add(ENIncludeColumn.icDate);
q.IncludeColumnList.Add(ENIncludeColumn.icName);
q.IncludeColumnList.Add(ENIncludeColumn.icMemo);
q.IncludeColumnList.Add(ENIncludeColumn.icDebit);
q.IncludeColumnList.Add(ENIncludeColumn.icCredit);
q.IncludeColumnList.Add(ENIncludeColumn.icRunningBalance);
q.ORReportPeriod.ReportPeriod.ToReportDate.SetValue(dt);
q.ReportAccountFilter.ORReportAccountFilter.FullNameList.Add(sAccount);
q.CustomDetailReportType.SetValue(ENCustomDetailReportType.cdrtCustomTxnDetail);
q.SummarizeRowsBy.SetValue(ENSummarizeRowsBy.srbTotalOnly);
IMsgSetResponse msrgrsp = sm.DoRequests(msr);
try
{
if (msrgrsp.ResponseList.Count == 1)
{
IResponse resp = msrgrsp.ResponseList.GetAt(0);
if (resp.StatusCode == 0)
{
IReportRet rp = (IReportRet)resp.Detail;
IORReportData data = rp.ReportData.ORReportDataList.GetAt(rp.NumRows.GetValue() - 1);
if (data.TotalRow != null)
{
balance = decimal.Parse(data.TotalRow.ColDataList.GetAt(data.TotalRow.ColDataList.Count - 1).value.GetValue());
return true;
}
}
}
}
catch (Exception e)
{
Log("Error finding balance of " + sAccount + ":");
Log(e.Message);
}
return false;
}
我更喜欢做一个CustomSummaryReportQuery这将返回所需的最少数据。
大多数代码是标准的,但使用它来构建查询和遍历返回的报告。将 QBCustName 留空以获取所有客户。客户余额将在结束日期退还。
代码是 VB.net
Imports QBFC7Lib
Private Sub BuildCustomSummaryReportQueryRq(ByVal requestMsgSet As IMsgSetRequest, _
ByVal EndDate As Date, ByVal QBCustName As String)
Dim CustomSummaryReportQueryRq As ICustomSummaryReportQuery
CustomSummaryReportQueryRq = requestMsgSet.AppendCustomSummaryReportQueryRq()
'Set field value for CustomSummaryReportType
CustomSummaryReportQueryRq.CustomSummaryReportType.SetValue(ENCustomSummaryReportType.csrtCustomSummary)
'Set field value for DisplayReport
CustomSummaryReportQueryRq.DisplayReport.SetValue(False)
'Set FromReportDate to earliest possible date
CustomSummaryReportQueryRq.ORReportPeriod.ReportPeriod.FromReportDate.SetValue(DateTime.Parse("1/1/1901"))
'Set field value for ToReportDate
CustomSummaryReportQueryRq.ORReportPeriod.ReportPeriod.ToReportDate.SetValue(EndDate)
'Set field value for AccountTypeFilter
CustomSummaryReportQueryRq.ReportAccountFilter.ORReportAccountFilter.AccountTypeFilter.SetValue(ENAccountTypeFilter.atfAccountsReceivable)
'Set field value for EntityTypeFilter
If QBCustName = "" Then
'all customers
CustomSummaryReportQueryRq.ReportEntityFilter.ORReportEntityFilter.EntityTypeFilter.SetValue(ENEntityTypeFilter.etfCustomer)
Else
'limit by customer name
CustomSummaryReportQueryRq.ReportEntityFilter.ORReportEntityFilter.FullNameList.Add(QBCustName)
End If
'Set field value for ReportDetailLevelFilter
CustomSummaryReportQueryRq.ReportDetailLevelFilter.SetValue(ENReportDetailLevelFilter.rdlfSummaryOnly)
'Set field value for ReportPostingStatusFilter
CustomSummaryReportQueryRq.ReportPostingStatusFilter.SetValue(ENReportPostingStatusFilter.rpsfEither)
'Set field value for SummarizeColumnsBy
CustomSummaryReportQueryRq.SummarizeColumnsBy.SetValue(ENSummarizeColumnsBy.scbTotalOnly)
'Set field value for SummarizeRowsBy
CustomSummaryReportQueryRq.SummarizeRowsBy.SetValue(ENSummarizeRowsBy.srbCustomer)
'Set field value for ReportCalendar
CustomSummaryReportQueryRq.ReportCalendar.SetValue(ENReportCalendar.rcCalendarYear)
'Set field value for ReturnRows
CustomSummaryReportQueryRq.ReturnRows.SetValue(ENReturnRows.rrActiveOnly)
'Set field value for ReturnColumns
CustomSummaryReportQueryRq.ReturnColumns.SetValue(ENReturnColumns.rcActiveOnly)
'Set field value for ReportBasis
CustomSummaryReportQueryRq.ReportBasis.SetValue(ENReportBasis.rbAccrual)
End Sub
'class to hold customer balance
Public Class CustBalReport
Public QBCustName As String
Public EndBal As Decimal
End Class
Private Sub WalkReportRetCustom(ByVal ReportRet As IReportRet)
'new list of customer bal items
Dim CustBalList As New List(Of CustBalReport)
'report title
Dim ReportTitle7 As String = ReportRet.ReportTitle.GetValue()
'report date
Dim ReportSubtitle8 As String = ReportRet.ReportSubtitle.GetValue()
Dim ErrNum As Integer = 1
Try
'iterate the report lines
ErrNum = 2
For RowNum As Integer = 0 To ReportRet.ReportData.ORReportDataList.Count - 1
'get new item
Dim ReportLine As CustBalReport = Nothing
ReportLine = New CustBalReport
'get row
ErrNum = 3
Dim ORReportData17 As IORReportData = Nothing
ORReportData17 = ReportRet.ReportData.ORReportDataList.GetAt(RowNum)
'don't care about total line; only get data rows
If ORReportData17.ortype = ENORReportData.orrdDataRow Then
'get customer name
ErrNum = 5
Dim ColCustName As IColData = Nothing
ColCustName = ORReportData17.DataRow.ColDataList.GetAt(0)
ReportLine.QBCustName = ColCustName.value.GetValue
'get customer balance
ErrNum = 6
Dim ColBalance As IColData = Nothing
ColBalance = ORReportData17.DataRow.ColDataList.GetAt(1)
ReportLine.EndBal = ColBalance.value.GetValue
'add to list
CustBalList.Add(ReportLine)
End If
Next RowNum
'assign to class variable
lCustBalList = CustBalList
Catch ex As Exception
Dim errMsg As String = ErrNum & ": Error getting customer balance summary"
Throw New ApplicationException(errMsg)
End Try
End Sub