I am using Quickbooks QBFC and want to retrive the value of "First Check Number" field programatically.
It can be found in Quickbooks at File>Print Forms>Checks
Please suggest how this can be done or any reference i can look at.
I am using Quickbooks QBFC and want to retrive the value of "First Check Number" field programatically.
It can be found in Quickbooks at File>Print Forms>Checks
Please suggest how this can be done or any reference i can look at.
您不能直接执行此操作,但您可以查询最近针对您感兴趣的帐户开出的支票。默认的第一张支票号码将比已开出的最高支票号码大一个。
作为一项规则,我不会为人们编写代码,我今天例外,只是因为今天是星期五,我的心情很疯狂。以下代码可用作有用的最后一个校验号例程的起点。为了有一个现实的、可用的例程,你,而不是我,将不得不处理与人们使用支票簿的方式相关的所有怪癖:非数字数字、乱序数字等。
请注意:此代码使用Zombie 开源库和 QBFC 11。
class CheckNumbers
{
private const int DATE_INTERVAL = -7;
private string _accountName;
private DateTime _lastToDate;
private DateTime _lastFromDate;
public CheckNumbers(string accountName)
{
_accountName = accountName;
_lastToDate = DateTime.Today;
_lastFromDate = _lastToDate.AddDays(DATE_INTERVAL);
}
private void SetCriteria(IORTxnQuery qry)
{
qry.TxnFilter.AccountFilter.ORAccountFilter.FullNameList.Add(_accountName);
var dateFilter = qry.TxnFilter.ORDateRangeFilter.ModifiedDateRangeFilter;
dateFilter.FromModifiedDate.SetValue(_lastFromDate, true);
dateFilter.ToModifiedDate.SetValue(_lastToDate, true);
}
private void ProcessCheckNumber(string checkNumber, ref int highestNumber)
{
if (!string.IsNullOrEmpty(checkNumber))
{
int thisCheck;
if (!int.TryParse(checkNumber, out thisCheck))
{
throw new Exception(string.Format("Check number {0} cannot be read as an integer", checkNumber));
}
if (thisCheck > highestNumber) highestNumber = thisCheck;
}
}
public int GetLastCheckNumber()
{
DateTime failSafe = DateTime.Parse("1/1/2010");
using (var cn = Zombie.ConnectionMgr.GetConnection())
{
int highestCheck = 0;
while (highestCheck == 0 && _lastFromDate > failSafe)
{
var batch = cn.NewBatch();
var checkQuery = batch.MsgSet.AppendCheckQueryRq();
checkQuery.IncludeRetElementList.Add("RefNumber");
SetCriteria(checkQuery.ORTxnQuery);
batch.SetClosures(checkQuery, b =>
{
var checks = new Zombie.QBFCIterator<ICheckRetList, ICheckRet>(b);
foreach (var check in checks)
{
ProcessCheckNumber(Zombie.Safe.Value(check.RefNumber), ref highestCheck);
}
});
var billCheckQuery = batch.MsgSet.AppendBillPaymentCheckQueryRq();
billCheckQuery.IncludeRetElementList.Add("RefNumber");
SetCriteria(billCheckQuery.ORTxnQuery);
batch.SetClosures(billCheckQuery, b =>
{
var checks = new Zombie.QBFCIterator<IBillPaymentCheckRetList, IBillPaymentCheckRet>(b);
foreach (var check in checks)
{
ProcessCheckNumber(Zombie.Safe.Value(check.RefNumber), ref highestCheck);
}
});
if (!batch.Run()) return 0;
_lastToDate = _lastFromDate;
_lastFromDate = _lastToDate.AddDays(DATE_INTERVAL);
}
return highestCheck;
}
}
}