예제 #1
0
        public void Settle()
        {
            SystemProfileService system = new SystemProfileService(mContext);
            var year   = system.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);
            var period = system.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod);

            dynamic tran = DBHelper.GetInstance(mContext).BeginTransaction();

            try
            {
                //1、获取id
                DataTable dt     = DBHelper.GetInstance(mContext).ExecuteDt(string.Format("select _id from _VoucherHeader where _year = {0} and _period = {1}", year, period));
                var       lstIds = dt.AsEnumerable().Select(p => p.Field <long>("_id"));
                if (lstIds.Count() > 0)
                {
                    var ids = string.Join(",", lstIds);
                    //2、检查是否有未审核、未过账的,不能结账
                    var bExist = DBHelper.GetInstance(mContext).Exist(tran,
                                                                      string.Format("select 1 from _VoucherHeader where _id in ({0}) and _status < {1}", ids, (int)VoucherStatus.Posted));
                    if (bExist)
                    {
                        throw new FinanceException(FinanceResult.INCORRECT_STATE);
                    }

                    //3、把结账到余额表
                    string.Format(@"
                        insert into _AccountBalance(_year,_period,_accountSubjectId,_debitsAmount,_creditAmount)
                        select {1},{2},_accountSubjectId,SUM(_debitsAmount) as _debitsAmount,SUM(_creditAmout) _creditAmout from (
                        select _accountSubjectId,_amount as _debitsAmount,0 as _creditAmout from _VoucherEntry where _id in ({0}) and _direction = 1
                        union
                        select _accountSubjectId,0 as _debitsAmount,_amount as _creditAmout from _VoucherEntry where _id in ({0}) and _direction = -1
                        ) t group by _accountSubjectId
                        ", ids, year, period);

                    //4、更新状态
                    DBHelper.GetInstance(mContext).ExecuteSql(tran,
                                                              string.Format("update _VoucherHeader set _status = {0} where _id in ({1})", (int)VoucherStatus.Settled, ids));
                }
                //5、更新Current Period 为新的
                var next = CommonUtils.CalcNextPeriod(new PeridStrunct {
                    Year = year, Period = period
                });
                system.Update(tran, SystemProfileCategory.Account, SystemProfileKey.CurrentYear, next.Year.ToString());
                system.Update(tran, SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod, next.Period.ToString());

                DBHelper.GetInstance(mContext).CommitTransaction(tran);
            }
            catch (FinanceException ex)
            {
                DBHelper.GetInstance(mContext).RollbackTransaction(tran);
                throw ex;
            }
            catch (Exception e)
            {
                DBHelper.GetInstance(mContext).RollbackTransaction(tran);
                var traceId = SerialNoService.GetUUID();
                logger.Error(e, traceId);
                throw new FinanceException(FinanceResult.SYSTEM_ERROR, traceId);
            }
        }
예제 #2
0
        public Dictionary <string, string> Calc(Dictionary <string, string> template)
        {
            SystemProfileService systemProfile = SystemProfileService.GetInstance(mContext);
            var curYear   = systemProfile.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentYear);
            var curPeriod = systemProfile.GetInt(SystemProfileCategory.Account, SystemProfileKey.CurrentPeriod);

            AccountBalanceService abService = AccountBalanceService.GetInstance(mContext);

            m_lstYear   = abService.QueryOccurs(curYear, 1, curYear, 12);
            m_lstOccurs = abService.QueryOccurs(curYear, curPeriod, curYear, curPeriod);
            m_lstAso    = DataManager.GetInstance(mContext).Query <AccountSubject>(null).OrderBy(a => a.no).ToList();

            Dictionary <string, string> result = new Dictionary <string, string>();
            List <string> sumKeys = new List <string>();

            foreach (KeyValuePair <string, string> kv in template)
            {
                if (Regex.IsMatch(kv.Value, "(L)") && !Regex.IsMatch(kv.Value, "(SL)"))
                {
                    sumKeys.Add(kv.Key);
                    continue;
                }
                result.Add(kv.Key, Calc(kv.Value));
            }

            sumKeys.Sort();
            foreach (string key in sumKeys)
            {
                result.Add(key, SampleCalculator.sumLine(template[key], key, result));
            }

            return(result);
        }
예제 #3
0
        public void Finish()
        {
            SystemProfileService systemProfileService = SystemProfileService.GetInstance(mContext);
            var startPeriod = new PeridStrunct
            {
                Year   = systemProfileService.GetInt(SystemProfileCategory.Account, SystemProfileKey.StartYear),
                Period = systemProfileService.GetInt(SystemProfileCategory.Account, SystemProfileKey.StartPeriod)
            };

            PeridStrunct prev = CommonUtils.CalcPrevPeriod(startPeriod);

            DBHelper.GetInstance(mContext).ExecuteSql(string.Format(@"insert into _AccountBalance (_year,_period,_accountSubjectId,_debitsAmount,_creditAmount)  
            select {0},{1},_accountSubjectId,_debitsAmount,_creditAmount from _BeginBalance ", prev.Year, prev.Period));

            systemProfileService.Update(SystemProfileCategory.Account, SystemProfileKey.IsInited, "1");
        }
예제 #4
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);
            }
        }