Esempio n. 1
0
        /// <inheritdoc />
        protected override IQueryResult ExcuteResetMixed(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                         DateFilter rng)
        {
            var cnt = 0L;

            foreach (var a in Accountant.SelectAmortizations(distQuery))
            {
                if (a.Schedule == null)
                {
                    continue;
                }

                var flag = false;
                foreach (var item in a.Schedule.Where(item => item.Date.Within(rng))
                         .Where(item => item.VoucherID != null))
                {
                    var voucher = Accountant.SelectVoucher(item.VoucherID);
                    if (voucher == null)
                    {
                        item.VoucherID = null;
                        cnt++;
                        flag = true;
                    }
                    else if (Accountant.DeleteVoucher(voucher.ID))
                    {
                        item.VoucherID = null;
                        cnt++;
                        flag = true;
                    }
                }

                if (flag)
                {
                    Accountant.Upsert(a);
                }
            }

            return(new NumberAffected(cnt));
        }
        /// <inheritdoc />
        protected override IQueryResult ExecuteApply(IQueryCompunded <IDistributedQueryAtom> distQuery, DateFilter rng,
                                                     bool isCollapsed)
        {
            var sb = new StringBuilder();

            foreach (var a in Sort(Accountant.SelectAssets(distQuery)))
            {
                foreach (var item in Accountant.Update(a, rng, isCollapsed))
                {
                    sb.AppendLine(ListAssetItem(item));
                }

                Accountant.Upsert(a);
            }

            if (sb.Length > 0)
            {
                return(new DirtyText(sb.ToString()));
            }

            return(new PlainSucceed());
        }
Esempio n. 3
0
 public UnionQueries(IQueryCompunded <TAtom> filter1,
                     IQueryCompunded <TAtom> filter2) : base(filter1, filter2)
 {
 }
Esempio n. 4
0
 /// <inheritdoc />
 protected override IQueryResult ExecuteQuery(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                              IEntitiesSerializer serializer)
 => new PlainText(serializer.PresentAssets(Sort(Accountant.SelectAssets(distQuery))));
Esempio n. 5
0
        /// <inheritdoc />
        public long DeleteAmortizations(IQueryCompunded <IDistributedQueryAtom> filter)
        {
            var res = m_Amortizations.DeleteMany(filter.Accept(new MongoDbNativeDistributed <Amortization>()));

            return(res.DeletedCount);
        }
Esempio n. 6
0
 /// <inheritdoc />
 public IEnumerable <Asset> SelectAssets(IQueryCompunded <IDistributedQueryAtom> filter) =>
 m_Assets.FindSync(filter.Accept(new MongoDbNativeDistributed <Asset>()))
 .ToEnumerable();
Esempio n. 7
0
 /// <inheritdoc />
 public IEnumerable <Voucher> SelectVouchers(IQueryCompunded <IVoucherQueryAtom> query) =>
 m_Vouchers.Find(query.Accept(new MongoDbNativeVoucher())).Sort(Builders <Voucher> .Sort.Ascending("date"))
 .ToEnumerable();
Esempio n. 8
0
 /// <summary>
 ///     判断一般检索式是否成立
 /// </summary>
 /// <param name="query">检索式</param>
 /// <param name="atomPredictor">原子检索式成立条件</param>
 /// <returns>是否成立</returns>
 public static bool IsMatch <TAtom>(IQueryCompunded <TAtom> query, Func <TAtom, bool> atomPredictor)
     where TAtom : class => query?.Accept(new MatchHelperVisitor <TAtom>(atomPredictor)) ?? true;
 /// <summary>
 ///     执行检查表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="rng">日期过滤器</param>
 /// <param name="serializer">表示器</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteCheck(IQueryCompunded <IDistributedQueryAtom> distQuery, DateFilter rng,
                                              IEntitiesSerializer serializer);
 /// <summary>
 ///     执行应用表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="rng">日期过滤器</param>
 /// <param name="isCollapsed">是否压缩</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteApply(IQueryCompunded <IDistributedQueryAtom> distQuery, DateFilter rng,
                                              bool isCollapsed);
 /// <summary>
 ///     执行硬重置表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="query">记账凭证检索式</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteResetHard(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                  IQueryCompunded <IVoucherQueryAtom> query);
 /// <summary>
 ///     执行混合重置表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="rng">日期过滤器</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExcuteResetMixed(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                  DateFilter rng);
 /// <summary>
 ///     执行重新计算表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="serializer">表示器</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteRecal(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                              IEntitiesSerializer serializer);
 /// <summary>
 ///     执行解除注册表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="rng">日期过滤器</param>
 /// <param name="query">记账凭证检索式</param>
 /// <param name="serializer">表示器</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteUnregister(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                   DateFilter rng, IQueryCompunded <IVoucherQueryAtom> query, IEntitiesSerializer serializer);
 /// <summary>
 ///     执行列表表达式
 /// </summary>
 /// <param name="distQuery">分期检索式</param>
 /// <param name="dt">计算账面价值的时间</param>
 /// <param name="showSchedule">是否显示折旧计算表</param>
 /// <param name="serializer">表示器</param>
 /// <returns>执行结果</returns>
 protected abstract IQueryResult ExecuteList(IQueryCompunded <IDistributedQueryAtom> distQuery, DateTime?dt,
                                             bool showSchedule, IEntitiesSerializer serializer);
Esempio n. 16
0
 public static bool IsMatch(this VoucherDetail voucherDetail, IQueryCompunded <IDetailQueryAtom> query)
 => IsMatch(query, q => IsMatch(voucherDetail, q.Filter, q.Dir));
Esempio n. 17
0
 public static bool IsMatch(this Voucher voucher, IQueryCompunded <IVoucherQueryAtom> query)
 => IsMatch(query, q => IsMatch(voucher, q));
Esempio n. 18
0
 public long DeleteAmortizations(IQueryCompunded <IDistributedQueryAtom> filter)
 => m_Db.DeleteAmortizations(filter);
Esempio n. 19
0
        /// <summary>
        ///     找出未在资产计算表中注册的记账凭证,并尝试建立引用
        /// </summary>
        /// <param name="asset">资产</param>
        /// <param name="rng">日期过滤器</param>
        /// <param name="query">检索式</param>
        /// <returns>未注册的记账凭证</returns>
        public IEnumerable <Voucher> RegisterVouchers(Asset asset, DateFilter rng,
                                                      IQueryCompunded <IVoucherQueryAtom> query)
        {
            if (asset.Remark == Asset.IgnoranceMark)
            {
                yield break;
            }

            foreach (
                var voucher in
                Db.SelectVouchers(ParsingF.VoucherQuery($"U{asset.User.AsUser()} T{asset.Title.AsTitle()} {asset.StringID.Quotation('\'')}"))
                .Where(v => v.IsMatch(query)))
            {
                if (voucher.Remark == Asset.IgnoranceMark)
                {
                    continue;
                }

                if (asset.Schedule.Any(item => item.VoucherID == voucher.ID))
                {
                    continue;
                }

                // ReSharper disable once PossibleInvalidOperationException
                var value =
                    voucher.Details.Single(d => d.Title == asset.Title && d.Content == asset.StringID).Fund.Value;

                if (value > 0)
                {
                    var lst = asset.Schedule.Where(item => item.Date.Within(rng))
                              .Where(
                        item =>
                        item is AcquisationItem &&
                        (!voucher.Date.HasValue || item.Date == voucher.Date) &&
                        (((AcquisationItem)item).OrigValue - value).IsZero())
                              .ToList();

                    if (lst.Count == 1)
                    {
                        lst[0].VoucherID = voucher.ID;
                    }
                    else
                    {
                        yield return(voucher);
                    }
                }
                else if (value < 0)
                {
                    var lst = asset.Schedule.Where(item => item.Date.Within(rng))
                              .Where(
                        item =>
                        item is DispositionItem &&
                        (!voucher.Date.HasValue || item.Date == voucher.Date))
                              .ToList();

                    if (lst.Count == 1)
                    {
                        lst[0].VoucherID = voucher.ID;
                    }
                    else
                    {
                        yield return(voucher);
                    }
                }
                else
                {
                    yield return(voucher);
                }
            }

            foreach (
                var voucher in
                Db.SelectVouchers(
                    ParsingF.VoucherQuery($"U{asset.User.AsUser()} T{asset.DepreciationTitle.AsTitle()} {asset.StringID.Quotation('\'')}")))
            {
                if (voucher.Remark == Asset.IgnoranceMark)
                {
                    continue;
                }

                if (asset.Schedule.Any(item => item.VoucherID == voucher.ID))
                {
                    continue;
                }

                var lst = asset.Schedule.Where(
                    item =>
                    item is DepreciateItem &&
                    (!voucher.Date.HasValue || item.Date == voucher.Date))
                          .ToList();

                if (lst.Count == 1)
                {
                    lst[0].VoucherID = voucher.ID;
                }
                else
                {
                    yield return(voucher);
                }
            }

            foreach (
                var voucher in
                Db.SelectVouchers(
                    ParsingF.VoucherQuery($"U{asset.User.AsUser()} T{asset.DevaluationTitle.AsTitle()} {asset.StringID.Quotation('\'')}")))
            {
                if (voucher.Remark == Asset.IgnoranceMark)
                {
                    continue;
                }

                if (asset.Schedule.Any(item => item.VoucherID == voucher.ID))
                {
                    continue;
                }

                var lst = asset.Schedule.Where(
                    item =>
                    item is DevalueItem &&
                    (!voucher.Date.HasValue || item.Date == voucher.Date))
                          .ToList();

                if (lst.Count == 1)
                {
                    lst[0].VoucherID = voucher.ID;
                }
                else
                {
                    yield return(voucher);
                }
            }
        }
Esempio n. 20
0
 public IEnumerable <Voucher> RegisterVouchers(Amortization amort, DateFilter rng,
                                               IQueryCompunded <IVoucherQueryAtom> query)
 => m_AmortAccountant.RegisterVouchers(amort, rng, query);
Esempio n. 21
0
        /// <inheritdoc />
        public long DeleteVouchers(IQueryCompunded <IVoucherQueryAtom> query)
        {
            var res = m_Vouchers.DeleteMany(query.Accept(new MongoDbNativeVoucher()));

            return(res.DeletedCount);
        }
Esempio n. 22
0
 public IEnumerable <Voucher> SelectVouchers(IQueryCompunded <IVoucherQueryAtom> query)
 => m_Db.SelectVouchers(query);
Esempio n. 23
0
 /// <inheritdoc />
 public IEnumerable <Amortization> SelectAmortizations(IQueryCompunded <IDistributedQueryAtom> filter) =>
 m_Amortizations.FindSync(filter.Accept(new MongoDbNativeDistributed <Amortization>()))
 .ToEnumerable();
Esempio n. 24
0
 public long DeleteVouchers(IQueryCompunded <IVoucherQueryAtom> query)
 => m_Db.DeleteVouchers(query);
Esempio n. 25
0
 /// <inheritdoc />
 protected override IQueryResult ExecuteResetHard(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                  IQueryCompunded <IVoucherQueryAtom> query) => throw new InvalidOperationException();
Esempio n. 26
0
 public IEnumerable <Asset> SelectAssets(IQueryCompunded <IDistributedQueryAtom> filter)
 => m_Db.SelectAssets(filter).Select(AssetAccountant.InternalRegular);
Esempio n. 27
0
 public IntersectQueries(IQueryCompunded <TAtom> filter1,
                         IQueryCompunded <TAtom> filter2) : base(filter1, filter2)
 {
 }
Esempio n. 28
0
 public long DeleteAssets(IQueryCompunded <IDistributedQueryAtom> filter)
 => m_Db.DeleteAssets(filter);
Esempio n. 29
0
 protected BinaryQueries(IQueryCompunded <TAtom> filter1,
                         IQueryCompunded <TAtom> filter2)
 {
     Filter1 = filter1;
     Filter2 = filter2;
 }
Esempio n. 30
0
 public IEnumerable <Voucher> RegisterVouchers(Asset asset, DateFilter rng,
                                               IQueryCompunded <IVoucherQueryAtom> query)
 => m_AssetAccountant.RegisterVouchers(asset, rng, query);