Beispiel #1
0
        public void Refresh()
        {
            ResultList.Clear();
            var rl = TargetObject.GetResult();

            if (rl == null)
            {
                return;
            }
            var l = new List <IInstrument>();

            foreach (var r in rl)
            {
                l.Add(Instrument.AllInstrumentList.FirstOrDefault(v => v.Ticker == r.Ticker));
            }
            l.ForEach(v => ResultList.Add(v));
            CalculateList.Clear();
            foreach (var kv in rl)
            {
                CalculateList.Add(new CalculateItem()
                {
                    Name = kv.InstrumentName, Ticker = kv.Ticker, Value = kv.Value
                });
            }
        }
Beispiel #2
0
        /// <summary>
        /// 生成账单价格
        /// </summary>
        /// <param name="billRelated">生成账单的住民</param>
        /// <param name="nowDate">当前时间</param>
        /// <param name="minByMonth">最小月份时间</param>
        /// <param name="maxByMonth">最大月份时间</param>
        /// <param name="days">时间</param>
        /// <param name="fixedCostByDay">固定费用录入(日)</param>
        /// <param name="fixedCostByMonth">固定费用录入(月)</param>
        /// <param name="costDtl">费用录入</param>
        /// <param name="leavehospList">离院记录</param>
        /// <returns>价格</returns>
        private CalculateList CalculateCost(BillRelated billRelated, DateTime nowDate, DateTime minByMonth, DateTime maxByMonth, int days, List <LTC_FIXEDCOST> fixedCostByDay, List <LTC_FIXEDCOST> fixedCostByMonth, List <LTC_COSTDTL> costDtl, List <LTC_LEAVEHOSP> leavehospList)
        {
            long feeNo = billRelated.FEENO;

            decimal  dtlCost        = 0;
            decimal  fixedDayCost   = 0;
            decimal  fixedMonthCost = 0;
            decimal  totalcost      = 0;
            DateTime repeatStartDate;
            DateTime repeatDayDate;

            CalculateList    calculateList        = new CalculateList();
            List <FixedCost> returnDayFixedCost   = new List <FixedCost>();
            List <FixedCost> returnMonthFixedCost = new List <FixedCost>();

            #region 费用录入价格
            billRelated.CostDtlList = costDtl.FindAll(m => m.FEENO == feeNo && m.BILLID == 0);
            dtlCost += billRelated.CostDtlList.Sum(m => m.TOTALPRICE ?? 0);
            #endregion


            #region 累加按天的固定收費

            var fixedCostByDayFeeNo = fixedCostByDay.FindAll(m => m.FEENO == feeNo);

            fixedCostByDayFeeNo.ForEach(m =>
            {
                int leaveDay    = 0;
                int repeatCount = 0;
                repeatDayDate   = nowDate;


                if (!Convert.ToBoolean(m.ISENDCHARGES))
                {
                    if (m.ENDDATE.HasValue && m.ENDDATE != null)
                    {
                        if (m.REPEATCOUNT == null || m.REPEATCOUNT == 0)
                        {
                            repeatCount   = DateDiff(Convert.ToDateTime(m.STARTDATE), Convert.ToDateTime(m.ENDDATE));
                            repeatDayDate = Convert.ToDateTime(m.STARTDATE);
                            //leaveDay = LeaveDays(leavehospList, Convert.ToDateTime(m.STARTDATE), repeatCount);
                        }
                        else if (m.REPEATCOUNT.HasValue && m.REPEATCOUNT != 0)
                        {
                            DateTime RePeatDay = m.STARTDATE.AddDays(Convert.ToDouble(m.REPEATCOUNT));
                            if (RePeatDay >= Convert.ToDateTime(m.ENDDATE))
                            {
                                repeatCount = 0;
                                //leaveDay = 0;
                            }
                            else
                            {
                                repeatCount   = DateDiff(Convert.ToDateTime(RePeatDay), Convert.ToDateTime(m.ENDDATE));
                                repeatDayDate = Convert.ToDateTime(RePeatDay);
                                //leaveDay = LeaveDays(leavehospList, RePeatDay, repeatCount);
                            }
                        }
                    }
                    else
                    {
                        if (m.REPEATCOUNT == null || m.REPEATCOUNT == 0)
                        {
                            repeatCount   = DateDiff(Convert.ToDateTime(m.STARTDATE), nowDate);
                            repeatDayDate = Convert.ToDateTime(m.STARTDATE);
                            //leaveDay = LeaveDays(leavehospList, Convert.ToDateTime(m.STARTDATE), repeatCount);
                        }
                        else if (m.REPEATCOUNT.HasValue && m.REPEATCOUNT != 0)
                        {
                            DateTime RePeatDay = m.STARTDATE.AddDays(Convert.ToDouble(m.REPEATCOUNT));
                            if (RePeatDay >= nowDate)
                            {
                                repeatCount = 0;
                                //leaveDay = 0;
                            }
                            else
                            {
                                repeatCount   = DateDiff(RePeatDay, nowDate);
                                repeatDayDate = Convert.ToDateTime(RePeatDay);
                                // leaveDay = LeaveDays(leavehospList, RePeatDay, repeatCount);
                            }
                        }
                    }
                }
                if (m.PRICE.HasValue && m.PRICE != null)
                {
                    var total     = Convert.ToDecimal(m.PRICE) * repeatCount;
                    fixedDayCost += total;
                }
                else
                {
                    var total     = 0 * repeatCount;
                    fixedDayCost += total;
                }

                m.GENERATEDATE = nowDate;
                m.REPEATCOUNT += repeatCount;
                unitOfWork.GetRepository <LTC_FIXEDCOST>().Update(m);

                FixedCost fixDay    = new FixedCost();
                fixDay.CostItemNo   = m.COSTITEMNO;
                fixDay.CostName     = m.COSTNAME;
                fixDay.Period       = m.PERIOD;
                fixDay.GenerateDate = nowDate;
                fixDay.RegNo        = m.REGNO;
                fixDay.FeeNo        = m.FEENO;
                fixDay.OrgId        = m.ORGID;
                fixDay.Price        = m.PRICE;
                fixDay.StartDate    = repeatDayDate;
                fixDay.RepeatCount  = repeatCount;
                returnDayFixedCost.Add(fixDay);
            });
            #endregion

            #region 累加按月固定收费

            var fixedCostByMonthFeeNo = fixedCostByMonth.FindAll(m => m.FEENO == feeNo);
            fixedCostByMonthFeeNo.ForEach(m =>
            {
                int leaveDay    = 0;
                int repeatCount = 0;
                repeatStartDate = new DateTime(1900, 1, 1);
                if (!Convert.ToBoolean(m.ISENDCHARGES))
                {
                    if (m.ENDDATE.HasValue && m.ENDDATE != null)
                    {
                        if (m.REPEATCOUNT == null || m.REPEATCOUNT == 0)
                        {
                            repeatCount     = DiffDateMonth(Convert.ToDateTime(m.STARTDATE), Convert.ToDateTime(m.ENDDATE));
                            repeatStartDate = Convert.ToDateTime(m.STARTDATE);
                            //repeatCount = DateDiffMonth(ReturnStartDate(Convert.ToDateTime(m.STARTDATE)), ReturnEndDate(Convert.ToDateTime(m.ENDDATE)));
                            //leaveDay = LeaveDays(leavehospList, Convert.ToDateTime(m.STARTDATE), repeatCount);
                        }
                        else if (m.REPEATCOUNT.HasValue && m.REPEATCOUNT != 0)
                        {
                            //DateTime RePeatDay = ReturnStartDate(Convert.ToDateTime(m.STARTDATE)).AddMonths(Convert.ToInt32(m.REPEATCOUNT));
                            DateTime RePeatDay = Convert.ToDateTime(m.STARTDATE).AddMonths(Convert.ToInt32(m.REPEATCOUNT));
                            if (RePeatDay > Convert.ToDateTime(m.ENDDATE))
                            {
                                repeatCount = 0;
                                //leaveDay = 0;
                            }
                            else
                            {
                                repeatCount     = DiffDateMonth(Convert.ToDateTime(RePeatDay), Convert.ToDateTime(m.ENDDATE));
                                repeatStartDate = Convert.ToDateTime(RePeatDay);
                                // repeatCount = DateDiffMonth(Convert.ToDateTime(RePeatDay), ReturnEndDate(Convert.ToDateTime(m.ENDDATE)));
                                //leaveDay = LeaveDays(leavehospList, RePeatDay, repeatCount);
                            }
                        }
                    }
                    else
                    {
                        if (m.REPEATCOUNT == null || m.REPEATCOUNT == 0)
                        {
                            repeatCount     = DiffDateMonth(Convert.ToDateTime(m.STARTDATE), nowDate);
                            repeatStartDate = Convert.ToDateTime(Convert.ToDateTime(m.STARTDATE));
                            //repeatCount = DateDiffMonth(ReturnStartDate(Convert.ToDateTime(m.STARTDATE)), ReturnEndDate(nowDate));
                            //leaveDay = LeaveDays(leavehospList, Convert.ToDateTime(m.STARTDATE), repeatCount);
                        }
                        else if (m.REPEATCOUNT.HasValue && m.REPEATCOUNT != 0)
                        {
                            DateTime RePeatDay = Convert.ToDateTime(m.STARTDATE).AddMonths(Convert.ToInt32(m.REPEATCOUNT));
                            //DateTime RePeatDay = ReturnStartDate(Convert.ToDateTime(m.STARTDATE)).AddMonths(Convert.ToInt32(m.REPEATCOUNT));
                            if (RePeatDay > nowDate)
                            {
                                repeatCount = 0;
                                //leaveDay = 0;
                            }
                            else
                            {
                                repeatCount     = DiffDateMonth(RePeatDay, nowDate);
                                repeatStartDate = RePeatDay;
                                //repeatCount = DateDiffMonth(RePeatDay,  ReturnEndDate(nowDate));
                                // leaveDay = LeaveDays(leavehospList, RePeatDay, repeatCount);
                            }
                        }
                    }
                }
                if (m.PRICE.HasValue && m.PRICE != null)
                {
                    var total       = Convert.ToDecimal(m.PRICE) * repeatCount;
                    fixedMonthCost += total;
                }
                else
                {
                    var total       = 0 * repeatCount;
                    fixedMonthCost += total;
                }

                m.GENERATEDATE = nowDate;
                m.REPEATCOUNT += repeatCount;
                unitOfWork.GetRepository <LTC_FIXEDCOST>().Update(m);

                FixedCost fixMonth    = new FixedCost();
                fixMonth.CostItemNo   = m.COSTITEMNO;
                fixMonth.CostName     = m.COSTNAME;
                fixMonth.Period       = m.PERIOD;
                fixMonth.GenerateDate = nowDate;
                fixMonth.RegNo        = m.REGNO;
                fixMonth.FeeNo        = m.FEENO;
                fixMonth.OrgId        = m.ORGID;
                fixMonth.Price        = m.PRICE;
                fixMonth.RepeatCount  = repeatCount;
                fixMonth.StartDate    = repeatStartDate;
                returnMonthFixedCost.Add(fixMonth);
            });
            #endregion

            calculateList.Cost = dtlCost + fixedDayCost + fixedMonthCost;  //账单总价

            calculateList.FixedDayCost   = fixedDayCost;
            calculateList.FixedMonthCost = fixedMonthCost;

            calculateList.ReturnDayFixedCost   = returnDayFixedCost;
            calculateList.ReturnMonthFixedCost = returnMonthFixedCost;
            return(calculateList);
        }
Beispiel #3
0
        public BaseResponse GenerateBill(int FeeNo, string OrgId)
        {
            BaseResponse response = new BaseResponse();

            var nowTime    = DateTime.Now.Date;
            var minByMonth = new DateTime(nowTime.Year, nowTime.Month, 1);
            var days       = DateTime.DaysInMonth(nowTime.Year, nowTime.Month);
            var maxByMonth = new DateTime(nowTime.Year, nowTime.Month, days);

            // 週期為天的固定收費
            var fixedCostByDay = unitOfWork.GetRepository <LTC_FIXEDCOST>().dbSet
                                 .Where(m => m.PERIOD == "Day");
            var fixedCostByDayList = fixedCostByDay.ToList();
            // 週期為月的固定收費
            var fixedCostByMonth     = unitOfWork.GetRepository <LTC_FIXEDCOST>().dbSet.Where(m => m.PERIOD == "Month");
            var fixedCostByMonthList = fixedCostByMonth.ToList();
            //.ToList();
            // 查找所有沒有賬單的收費明細
            var costDtl     = unitOfWork.GetRepository <LTC_COSTDTL>().dbSet.Where(m => !m.BILLID.HasValue || (m.BILLID.HasValue && m.BILLID.Value == 0));
            var costDtlList = costDtl.ToList();

            // 查找有固定收費或有示出賬單的收費明細的住民
            var q = from reg in unitOfWork.GetRepository <LTC_REGFILE>().dbSet
                    join ipd in unitOfWork.GetRepository <LTC_IPDREG>().dbSet on reg.REGNO equals ipd.REGNO
                    where  costDtl.Any(m => m.FEENO == ipd.FEENO) || fixedCostByDay.Any(m => m.FEENO == ipd.FEENO) || fixedCostByMonth.Any(m => m.FEENO == ipd.FEENO)
                    select new BillRelated {
                REGNO = reg.REGNO, ORGID = reg.ORGID, FEENO = ipd.FEENO
            };

            q = q.Distinct();

            q = q.Where(m => m.FEENO == FeeNo && m.ORGID == OrgId);

            var ipdList = q.ToList();

            var feeNoList = ipdList.Select(m => m.FEENO).ToList();

            // 需要出賬單且在這個月有請假的請假數據
            var leavehospList = unitOfWork.GetRepository <LTC_LEAVEHOSP>().dbSet.Where(m => feeNoList.Contains(m.FEENO ?? 0) &&
                                                                                       ((m.STARTDATE.HasValue && m.STARTDATE.Value.CompareTo(minByMonth) <= 0 && m.ENDDATE.HasValue && m.ENDDATE.Value.CompareTo(minByMonth) >= 0) ||
                                                                                        (m.STARTDATE.HasValue && m.STARTDATE.Value.CompareTo(maxByMonth) <= 0 && m.ENDDATE.HasValue && m.ENDDATE.Value.CompareTo(maxByMonth) >= 0))
                                                                                       ).ToList();
            var calculateCostList = new CalculateList();

            // 生成賬單
            ipdList.ForEach(ipd =>
            {
                // 計算出賬單費用
                calculateCostList = CalculateCost(ipd, nowTime, minByMonth, maxByMonth, days, fixedCostByDayList, fixedCostByMonthList, costDtlList, leavehospList);

                if (calculateCostList.Cost != 0)
                {
                    LTC_BILL model  = new LTC_BILL();
                    model.BILLNO    = base.GenerateCode(SecurityHelper.CurrentPrincipal.OrgId, EnumCodeKey.BillNo); //???
                    model.BILLSTATE = GetEnumDescription(EnumBillState.Open).ToString();

                    model.COST        = calculateCostList.Cost;
                    model.DESCRIPTION = DateTime.Now.ToString("yyyy-MM-dd");

                    if (calculateCostList.FixedMonthCost != 0)
                    {
                        var minDate  = calculateCostList.ReturnMonthFixedCost.Where(m => m.RepeatCount != 0).Select(m => m.StartDate).Min();
                        var maxCount = calculateCostList.ReturnMonthFixedCost.Where(m => m.RepeatCount != 0).Select(m => m.RepeatCount).Max();

                        model.BILLDATE    = minDate;
                        model.BILLENDDATE = Convert.ToDateTime(minDate).AddMonths(Convert.ToInt32(maxCount));
                    }
                    else if (calculateCostList.FixedMonthCost == 0 && calculateCostList.FixedDayCost != 0)
                    {
                        var minDate  = calculateCostList.ReturnDayFixedCost.Where(m => m.RepeatCount != 0).Select(m => m.StartDate).Min();
                        var maxCount = calculateCostList.ReturnDayFixedCost.Where(m => m.RepeatCount != 0).Select(m => m.RepeatCount).Max();

                        model.BILLDATE    = minDate;
                        model.BILLENDDATE = Convert.ToDateTime(minDate).AddDays(Convert.ToInt32(maxCount));
                    }
                    else
                    {
                        model.BILLDATE    = DateTime.Now;
                        model.BILLENDDATE = DateTime.Now;
                    }

                    model.FEENO      = ipd.FEENO;
                    model.REGNO      = ipd.REGNO;
                    model.ORGID      = ipd.ORGID;
                    model.CREATEDATE = nowTime;
                    unitOfWork.GetRepository <LTC_BILL>().Insert(model);
                    ipd.Bill            = model;
                    response.ResultCode = 1001;
                }
                else
                {
                    response.ResultCode = 1002;
                }
            });

            unitOfWork.Save();
            // 反寫收費明細表的賬單ID
            ipdList.ForEach(ipd =>
            {
                ipd.CostDtlList.ForEach(cost =>
                {
                    cost.BILLID = ipd.Bill.ID;
                    unitOfWork.GetRepository <LTC_COSTDTL>().Update(cost);
                });

                if (calculateCostList.FixedDayCost != 0)
                {
                    calculateCostList.ReturnDayFixedCost.ForEach(fixInfo =>
                    {
                        if (fixInfo.RepeatCount != 0)
                        {
                            LTC_COSTDTL costdtl = new LTC_COSTDTL
                            {
                                COSTITEMNO  = fixInfo.CostItemNo,
                                COSTNAME    = fixInfo.CostName,
                                ITEMTYPE    = fixInfo.Period,
                                OCCURTIME   = fixInfo.GenerateDate,
                                QUANTITY    = fixInfo.RepeatCount,
                                PRICE       = fixInfo.Price,
                                TOTALPRICE  = (fixInfo.RepeatCount) * (fixInfo.Price),
                                SELFFLAG    = true,
                                DESCRIPTION = Convert.ToDateTime(fixInfo.StartDate).ToString("yyyy-MM-dd") + " 至  " + Convert.ToDateTime(fixInfo.StartDate).AddDays(Convert.ToDouble(fixInfo.RepeatCount)).ToString("yyyy-MM-dd"),
                                REGNO       = fixInfo.RegNo,
                                FEENO       = fixInfo.FeeNo,
                                ORGID       = fixInfo.OrgId,
                                COSTSOURCE  = 0,
                                BILLID      = Convert.ToInt32(ipd.Bill.ID)
                            };
                            unitOfWork.GetRepository <LTC_COSTDTL>().Insert(costdtl);
                        }
                    });
                }

                if (calculateCostList.FixedMonthCost != 0)
                {
                    calculateCostList.ReturnMonthFixedCost.ForEach(fixInfo =>
                    {
                        if (fixInfo.RepeatCount != 0)
                        {
                            for (int i = 1; i <= fixInfo.RepeatCount; i++)
                            {
                                if (i == 1)
                                {
                                    LTC_COSTDTL costdtl = new LTC_COSTDTL
                                    {
                                        COSTITEMNO  = fixInfo.CostItemNo,
                                        COSTNAME    = fixInfo.CostName,
                                        ITEMTYPE    = fixInfo.Period,
                                        OCCURTIME   = fixInfo.GenerateDate,
                                        QUANTITY    = 1,
                                        PRICE       = fixInfo.Price,
                                        TOTALPRICE  = 1 * (fixInfo.Price),
                                        SELFFLAG    = true,
                                        DESCRIPTION = Convert.ToDateTime(fixInfo.StartDate).ToString("yyyy-MM-dd") + " 至  " + Convert.ToDateTime(fixInfo.StartDate).AddMonths(1).ToString("yyyy-MM-dd"),
                                        REGNO       = fixInfo.RegNo,
                                        FEENO       = fixInfo.FeeNo,
                                        ORGID       = fixInfo.OrgId,
                                        COSTSOURCE  = 0,
                                        BILLID      = Convert.ToInt32(ipd.Bill.ID)
                                    };
                                    unitOfWork.GetRepository <LTC_COSTDTL>().Insert(costdtl);
                                }
                                else
                                {
                                    LTC_COSTDTL costdtl = new LTC_COSTDTL
                                    {
                                        COSTITEMNO  = fixInfo.CostItemNo,
                                        COSTNAME    = fixInfo.CostName,
                                        ITEMTYPE    = fixInfo.Period,
                                        OCCURTIME   = fixInfo.GenerateDate,
                                        QUANTITY    = 1,
                                        PRICE       = fixInfo.Price,
                                        TOTALPRICE  = 1 * (fixInfo.Price),
                                        SELFFLAG    = true,
                                        DESCRIPTION = Convert.ToDateTime(fixInfo.StartDate).AddMonths(i - 1).AddDays(1).ToString("yyyy-MM-dd") + " 至  " + Convert.ToDateTime(fixInfo.StartDate).AddMonths(i).ToString("yyyy-MM-dd"),
                                        REGNO       = fixInfo.RegNo,
                                        FEENO       = fixInfo.FeeNo,
                                        ORGID       = fixInfo.OrgId,
                                        COSTSOURCE  = 0,
                                        BILLID      = Convert.ToInt32(ipd.Bill.ID)
                                    };
                                    unitOfWork.GetRepository <LTC_COSTDTL>().Insert(costdtl);
                                }
                            }
                        }
                    });
                }
            });

            unitOfWork.Save();

            if (ipdList.Count == 0)
            {
                response.ResultCode = 1002;
            }
            return(response);
        }