Exemple #1
0
        /// <summary>
        /// 数据有效性检查
        /// 头部:
        ///     1、凭证字、凭证号不能为空
        ///     2、业务日期、日期、年度、期间不能为空
        ///     3、日期、年度、期间不能为已结账期间
        /// 分录:
        ///     1、科目、金额不能为0
        ///     2、借贷方要平衡
        /// </summary>
        /// <param name="item"></param>
        void CheckData(Voucher item)
        {
            var header = item.header;

            DataCheckHelper.StringIsNullOrEmpty(header.word, "凭证字不能为空");
            //DataCheckHelper.NumberIsZero(header.no, "凭证号不能为0");
            DataCheckHelper.IsNull(header.businessDate, "业务日期不能为空");
            DataCheckHelper.IsNull(header.date, "日期不能为空");
            DataCheckHelper.NumberIsZero(header.year, "会计年度不能为0");
            DataCheckHelper.NumberIsZero(header.period, "会计期间不能为0");
            DataCheckHelper.DateInPeriod(header.date, header.year, header.period, "日期和会计年度期间不符");

            SystemProfileService systemProfileService = SystemProfileService.GetInstance(mContext);
            var      currentYear   = systemProfileService.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);
            var      currentPeriod = systemProfileService.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod);
            DateTime current       = new DateTime(currentYear, currentPeriod, 1);

            if (current > header.date)
            {
                throw new FinanceException(FinanceResult.IMPERFECT_DATA, "不能录入已过账期间的凭证");
            }

            if (item.entries == null || item.entries.Count == 0)
            {
                throw new FinanceException(FinanceResult.IMPERFECT_DATA, "凭证不能没有分录");
            }

            decimal totalAmount = 0M;

            foreach (var entry in item.entries)
            {
                if (entry.accountSubjectId == 0 && string.IsNullOrEmpty(entry.accountSubjectNo))
                {
                    throw new FinanceException(FinanceResult.IMPERFECT_DATA, string.Format("第{0}行分录,科目不能为空", entry.index));
                }

                DataCheckHelper.NumberIsZero(entry.amount, string.Format("第{0}行分录,金额不能为0", entry.index));
                totalAmount += (entry.direction * entry.amount);
            }
            if (totalAmount != 0M)
            {
                throw new FinanceException(FinanceResult.AMMOUNT_IMBALANCE);
            }
        }