使用QBFC在Quickbooks中查找第一支支票号码 [英] Find First check number in Quickbooks using QBFC

查看:149
本文介绍了使用QBFC在Quickbooks中查找第一支支票号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Quickbooks QBFC,并希望以编程方式检索第一支票号"字段的值.

I am using Quickbooks QBFC and want to retrive the value of "First Check Number" field programatically.

可以在Quickbooks的File> Print Forms> Checks

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.

推荐答案

您不能直接执行此操作,但是可以查询针对您感兴趣的帐户所写的最新支票.默认为第一个支票号码比已写的最高支票号码大一.

You can't do this directly, but you can query for the most recent checks that have been written against the account that you are interested in. The default first check number will be one greater than the highest check number that's been written.

通常,我不为他们编写人的代码,我今天例外,只是因为它是星期五,而且我的心情很疯狂.以下代码可用作有用的最后支票号码例程的起点.为了拥有一个现实,可用的例程,您(而不是我)将不得不处理人们使用支票簿的方式所产生的所有怪癖:非数字,乱序的数字等.

As a rule, I don't write people's code for them, I'm making an exception today only because it's Friday and I'm in a crazy mood. The following code can be used as a starting point for a useful last check number routine. In order to have a realistic, usable routine you, not I, will have to deal with all of the eccentricities that attach to the way people use their checkbooks: non-numeric numbers, numbers out of sequence, etc.

请注意:此代码使用 Zombie开源库和QBFC 11.

Please note: this code uses the Zombie open source library and 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;
        }
    }
}

这篇关于使用QBFC在Quickbooks中查找第一支支票号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆