示例#1
0
        private static Voucher ParseVoucher(JToken obj)
        {
            var      dateStr = obj["date"]?.Value <string>();
            DateTime?date    = null;

            if (dateStr != null)
            {
                date = ClientDateTime.Parse(dateStr);
            }
            var detail  = obj["detail"];
            var typeStr = obj["type"]?.Value <string>();
            var type    = VoucherType.Ordinary;

            if (typeStr != null)
            {
                Enum.TryParse(typeStr, out type);
            }

            return(new Voucher
            {
                ID = obj["id"]?.Value <string>(),
                Date = date,
                Remark = obj["remark"]?.Value <string>(),
                Type = type,
                Details = detail == null
                        ? new List <VoucherDetail>()
                        : detail.Select(ParseVoucherDetail).ToList(),
            });
        }
        public void WithinTestBy(bool expected, string valueS)
        {
            var value  = valueS == null ? (DateTime?)null : ClientDateTime.Parse(valueS);
            var filter = new DateFilter(null, new DateTime(2017, 1, 1, 0, 0, 0, DateTimeKind.Utc));

            Assert.True(filter.Nullable);
            Assert.Equal(expected, DateHelper.Within(value, filter));
        }
        private AssetItem ParseAssetItem(JToken obj)
        {
            var      dateStr = obj["date"]?.Value <string>();
            DateTime?date    = null;

            if (dateStr != null)
            {
                date = ClientDateTime.Parse(dateStr);
            }
            var voucherId = obj["voucherId"]?.Value <string>();
            var value     = obj["value"]?.Value <double>() ?? 0;
            var remark    = obj["remark"]?.Value <string>();

            switch (obj["type"].Value <string>())
            {
            case "acquisation":
                return(new AcquisationItem
                {
                    Date = date,
                    VoucherID = voucherId,
                    Value = value,
                    Remark = remark,
                    OrigValue = obj["origValue"].Value <double>()
                });

            case "depreciation":
                return(new DepreciateItem
                {
                    Date = date,
                    VoucherID = voucherId,
                    Value = value,
                    Remark = remark,
                    Amount = obj["amount"].Value <double>()
                });

            case "devaluation":
                return(new DevalueItem
                {
                    Date = date,
                    VoucherID = voucherId,
                    Value = value,
                    Remark = remark,
                    FairValue = obj["fairValue"].Value <double>()
                });

            case "disposition":
                return(new DispositionItem
                {
                    Date = date,
                    VoucherID = voucherId,
                    Value = value,
                    Remark = remark
                });

            default:
                throw new ArgumentException("类型未知", nameof(obj));
            }
        }
示例#4
0
        public void WithinTestSinceA(bool expected, string valueS)
        {
            var value  = valueS == null ? (DateTime?)null : ClientDateTime.Parse(valueS);
            var filter = new DateFilter(new(2017, 1, 1, 0, 0, 0, DateTimeKind.Utc), null)
            {
                Nullable = true
            };

            Assert.Equal(expected, DateHelper.Within(value, filter));
        }
    }
示例#5
0
        /// <inheritdoc />
        public Asset ParseAsset(string str)
        {
            if (str.StartsWith(AssetToken, StringComparison.OrdinalIgnoreCase))
            {
                str = str.Substring(AssetToken.Length);
            }

            var      obj     = ParseJson(str);
            var      dateStr = obj["date"]?.Value <string>();
            DateTime?date    = null;

            if (dateStr != null)
            {
                date = ClientDateTime.Parse(dateStr);
            }
            var schedule = obj["schedule"];
            var typeStr  = obj["method"]?.Value <string>();
            var method   = DepreciationMethod.StraightLine;

            if (typeStr != null)
            {
                Enum.TryParse(typeStr, out method);
            }

            return(new Asset
            {
                StringID = obj["id"]?.Value <string>(),
                Name = obj["name"]?.Value <string>(),
                Date = date,
                User = obj["user"]?.Value <string>(),
                Currency = obj["currency"]?.Value <string>(),
                Value = obj["value"]?.Value <double?>(),
                Salvage = obj["salvage"]?.Value <double?>(),
                Life = obj["life"]?.Value <int?>(),
                Title = obj["title"]?.Value <int?>(),
                Method = method,
                DepreciationTitle = obj["depreciation"]?["title"]?.Value <int?>(),
                DepreciationExpenseTitle = obj["depreciation"]?["expense"]?["title"]?.Value <int?>(),
                DepreciationExpenseSubTitle = obj["depreciation"]?["expense"]?["subtitle"]?.Value <int?>(),
                DevaluationTitle = obj["devaluation"]?["title"]?.Value <int?>(),
                DevaluationExpenseTitle = obj["devaluation"]?["expense"]?["title"]?.Value <int?>(),
                DevaluationExpenseSubTitle = obj["devaluation"]?["expense"]?["subtitle"]?.Value <int?>(),
                Remark = obj["remark"]?.Value <string>(),
                Schedule = schedule == null ? new List <AssetItem>() : schedule.Select(ParseAssetItem).ToList(),
            });
        }
示例#6
0
        private static AmortItem ParseAmortItem(JToken obj)
        {
            var      dateStr = obj["date"]?.Value <string>();
            DateTime?date    = null;

            if (dateStr != null)
            {
                date = ClientDateTime.Parse(dateStr);
            }

            return(new AmortItem
            {
                Date = date,
                VoucherID = obj["voucherId"]?.Value <string>(),
                Amount = obj["amount"].Value <double>(),
                Remark = obj["remark"]?.Value <string>(),
                Value = obj["value"]?.Value <double?>() ?? 0,
            });
        }
示例#7
0
        /// <inheritdoc />
        public Amortization ParseAmort(string str)
        {
            if (str.StartsWith(AmortToken, StringComparison.OrdinalIgnoreCase))
            {
                str = str.Substring(AmortToken.Length);
            }

            var      obj     = ParseJson(str);
            var      dateStr = obj["date"]?.Value <string>();
            DateTime?date    = null;

            if (dateStr != null)
            {
                date = ClientDateTime.Parse(dateStr);
            }
            var schedule = obj["schedule"];
            var typeStr  = obj["interval"]?.Value <string>();
            var interval = AmortizeInterval.EveryDay;

            if (typeStr != null)
            {
                Enum.TryParse(typeStr, out interval);
            }

            return(new Amortization
            {
                StringID = obj["id"]?.Value <string>(),
                Name = obj["name"]?.Value <string>(),
                Date = date,
                User = obj["user"]?.Value <string>(),
                Value = obj["value"]?.Value <double?>(),
                TotalDays = obj["totalDays"]?.Value <int?>(),
                Interval = interval,
                Template = ParseVoucher(obj["template"]),
                Remark = obj["remark"]?.Value <string>(),
                Schedule = schedule == null ? new List <AmortItem>() : schedule.Select(ParseAmortItem).ToList(),
            });
        }
示例#8
0
 public static DateTime?ToDateTime(this string b1S) => b1S == null
     ? (DateTime?)null
     : ClientDateTime.Parse(b1S);
        public void WithinTestNullOnly(bool expected, string valueS)
        {
            var value = valueS == null ? (DateTime?)null : ClientDateTime.Parse(valueS);

            Assert.Equal(expected, DateHelper.Within(value, DateFilter.TheNullOnly));
        }
        public void WithinTestUnconstrained(bool expected, string valueS)
        {
            var value = valueS == null ? (DateTime?)null : ClientDateTime.Parse(valueS);

            Assert.Equal(expected, DateHelper.Within(value, DateFilter.Unconstrained));
        }
示例#11
0
        public void Parse(string expr)
        {
            var headerB = ParsingF.Line(ref expr);
            var header  = headerB;

            var dateId = -1;
            var fundId = -1;

            var dateReg = new Regex(@"^trans(?:\.|action)\s+date$", RegexOptions.IgnoreCase);
            var fundReg = new Regex(@"^(?:amount|fund|value)$", RegexOptions.IgnoreCase);

            for (var i = 0; !string.IsNullOrWhiteSpace(header); i++)
            {
                var f = Next(ref header);
                if (dateReg.IsMatch(f))
                {
                    dateId = i;
                }
                else if (fundReg.IsMatch(f))
                {
                    fundId = i;
                }
            }

            if (dateId < 0)
            {
                header = headerB;
                var dateReg2 = new Regex(@"^date$", RegexOptions.IgnoreCase);
                for (var i = 0; !string.IsNullOrWhiteSpace(header); i++)
                {
                    var f = Next(ref header);
                    if (i == fundId)
                    {
                        continue;
                    }
                    if (dateReg2.IsMatch(f))
                    {
                        dateId = i;
                    }
                }

                if (dateId < 0)
                {
                    throw new ApplicationException("找不到日期字段");
                }
            }
            if (fundId < 0)
            {
                throw new ApplicationException("找不到金额字段");
            }

            Items = new List <BankItem>();
            while (!string.IsNullOrWhiteSpace(expr))
            {
                var l    = ParsingF.Line(ref expr);
                var item = new BankItem {
                    Raw = l
                };
                for (var i = 0; !string.IsNullOrWhiteSpace(l); i++)
                {
                    var f = Next(ref l);
                    if (i == dateId)
                    {
                        item.Date = ClientDateTime.Parse(f);
                    }
                    else if (i == fundId)
                    {
                        item.Fund = m_Dir * Convert.ToDouble(f);
                    }
                }

                Items.Add(item);
            }
        }