Пример #1
0
        public void VoucherQueryTest(bool dangerous, string expr)
        {
            var query = ParsingF.VoucherQuery(ref expr);

            ParsingF.Eof(expr);
            Assert.Equal(dangerous, query.IsDangerous());
        }
Пример #2
0
 protected override IQueryResult ExecuteResetHard(IQueryCompunded <IDistributedQueryAtom> distQuery,
                                                  IQueryCompunded <IVoucherQueryAtom> query) => new NumberAffected(
     Accountant.SelectAssets(distQuery)
     .Sum(
         a => Accountant.DeleteVouchers(
             new IntersectQueries <IVoucherQueryAtom>(
                 query ?? VoucherQueryUnconstrained.Instance,
                 ParsingF.VoucherQuery(
                     $"{{ T{a.DepreciationTitle.AsTitle()} {a.StringID.Quotation('\'')} Depreciation }} + {{ T{a.DevaluationTitle.AsTitle()} {a.StringID.Quotation('\'')} Devalue }}")))));
Пример #3
0
        public virtual void RunTestA(bool expected, string query)
        {
            var voucher = new Voucher
            {
                ID      = "59278b516c2f021e80f51912",
                Date    = null,
                Type    = VoucherType.Uncertain,
                Remark  = "rmk1",
                Details = new List <VoucherDetail>
                {
                    new VoucherDetail
                    {
                        Currency = "JPY",
                        Title    = 1001,
                        SubTitle = 05,
                        Content  = "cont1",
                        Fund     = 123.45
                    },
                    new VoucherDetail
                    {
                        Currency = "JPY",
                        Title    = 1234,
                        Remark   = "remk2",
                        Fund     = -123.45
                    },
                    new VoucherDetail
                    {
                        Currency = "USD",
                        Title    = 2345,
                        Content  = "cont3",
                        Fund     = -77.66
                    },
                    new VoucherDetail
                    {
                        Currency = "USD",
                        Title    = 3456,
                        SubTitle = 05,
                        Content  = "cont4",
                        Remark   = "remk4",
                        Fund     = 77.66
                    }
                }
            };

            ResetVouchers();
            PrepareVoucher(voucher);
            Assert.Equal(expected, RunQuery(ParsingF.VoucherQuery(query)));
            ResetVouchers();
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
    public virtual async Task RunTestA(bool expected, string query)
    {
        var voucher = new Voucher
        {
            ID      = null,
            Date    = null,
            Type    = VoucherType.Uncertain,
            Remark  = "rmk1",
            Details = new()
            {
                new()
                {
                    User     = "******",
                    Currency = "JPY",
                    Title    = 1001,
                    SubTitle = 05,
                    Content  = "cont1",
                    Fund     = 123.45,
                },
                new()
                {
                    User     = "******",
                    Currency = "JPY",
                    Title    = 1234,
                    Remark   = "remk2",
                    Fund     = -123.45,
                },
                new()
                {
                    User     = "******",
                    Currency = "USD",
                    Title    = 2345,
                    Content  = "cont3",
                    Fund     = -77.66,
                },
                new()
                {
                    User     = "******",
                    Currency = "USD",
                    Title    = 3456,
                    SubTitle = 05,
                    Content  = "cont4",
                    Remark   = "remk4",
                    Fund     = 77.66,
                },
                new()
                {
                    User     = "******",
                    Currency = "EUR",
                    Title    = 1111,
                    SubTitle = 22,
                    Fund     = 114514,
                },
            },
        };

        await ResetVouchers();
        await PrepareVoucher(voucher);

        Assert.Equal(expected, await RunQuery(ParsingF.VoucherQuery(query, Client)));
        await ResetVouchers();
    }