Example #1
0
        /// <summary>
        /// 查询支出明细列表
        /// </summary>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task <PageAmountList <OutRecordListInfo> > QueryOutRecordAsync(OutRecordReq req)
        {
            //查询
            var taskModel         = ReportDAL.Inst.QueryOutRecordAsync(this.LoginInfo.FamilyID, req); //明细
            var taskOutCategory   = BasicDAL.Inst.QueryOutCategoryAsync(this.LoginInfo.FamilyID);     //分类
            var taskOutType       = BasicDAL.Inst.QueryOutTypeAsync(this.LoginInfo.FamilyID);         //类型
            var taskAmountAccount = BasicDAL.Inst.QueryAmountAccountAsync(this.LoginInfo.FamilyID);   //账户

            var lstModel         = await taskModel;                                                   //明细
            var lstOutCategory   = await taskOutCategory;                                             //分类
            var lstOutType       = await taskOutType;                                                 //类型
            var lstAmountAccount = await taskAmountAccount;                                           //账户

            var list = new List <OutRecordListInfo>();
            var seq  = req.GetSkip() + 1;

            foreach (var model in lstModel)
            {
                var item = new OutRecordListInfo();
                list.Add(item);

                //类型
                var outType = lstOutType.Find(m => m.ID == model.OutTypeID);

                //分类
                OutCategory outCategory = null;
                if (outType != null)
                {
                    outCategory = lstOutCategory.Find(m => m.ID == outType.OutCategoryID);
                }

                //账户
                var amountAccount = lstAmountAccount.Find(m => m.ID == model.AmountAccountID);

                item.Seq               = seq++;
                item.ID                = model.ID;
                item.OutDate           = model.OutDate;
                item.OutCategoryName   = outCategory != null ? outCategory.Name : "";
                item.OutTypeName       = outType != null ? outType.Name : "";
                item.AmountAccountName = amountAccount != null ? amountAccount.Name : "";
                item.Amount            = model.Amount;
                item.Remark            = model.Remark;
            }

            return(new PageAmountList <OutRecordListInfo>(list, lstModel.TotalRecord, lstModel.TotalAmount));
        }
Example #2
0
        /// <summary>
        /// 查询支出明细列表
        /// </summary>
        /// <param name="familyID">家庭ID</param>
        /// <param name="req">条件</param>
        /// <returns></returns>
        public async Task <PageAmountList <OutPut> > QueryOutRecordAsync(int familyID, OutRecordReq req)
        {
            using (IOSysContext db = new IOSysContext())
            {
                #region 条件

                //家庭ID
                var q = db.OutPuts.AsNoTracking().Where(m => m.FamilyID == familyID);

                //开始日期
                if (req.StartDate.HasValue)
                {
                    q = q.Where(m => m.OutDate >= req.StartDate.Value);
                }

                //截止日期
                if (req.EndDate.HasValue)
                {
                    q = q.Where(m => m.OutDate <= req.EndDate.Value);
                }

                //类型
                if (req.LstOutTypeID != null && req.LstOutTypeID.Count > 0)
                {
                    q = q.Where(m => req.LstOutTypeID.Contains(m.OutTypeID));
                }

                //账户
                if (req.LstAmountAccountID != null && req.LstAmountAccountID.Count > 0)
                {
                    q = q.Where(m => req.LstAmountAccountID.Contains(m.AmountAccountID));
                }

                //备注(模糊匹配)
                if (string.IsNullOrWhiteSpace(req.Remark) == false)
                {
                    q = q.Where(m => m.Remark.Contains(req.Remark));
                }

                #endregion

                var totalRecord = 0;  //总条数
                var totalAmount = 0M; //总金额

                //是否需要分页
                if (req.IsSetPage())
                {
                    totalAmount = await q.SumAsync(m => m.Amount);

                    totalRecord = await q.CountAsync();
                }

                //设置排序和分页
                if (CvtHelper.ToStr(req.Sort).StartsWith("OutCategoryID"))
                {
                    if (CvtHelper.ToStr(req.Sort).EndsWith("asc"))
                    {
                        q = from op in q
                            join otTemp in db.OutTypes on op.OutTypeID equals otTemp.ID into otJoin
                            from ot in otJoin.DefaultIfEmpty()
                            orderby ot.OutCategoryID ascending
                            select op;
                    }
                    else
                    {
                        q = from op in q
                            join otTemp in db.OutTypes on op.OutTypeID equals otTemp.ID into otJoin
                            from ot in otJoin.DefaultIfEmpty()
                            orderby ot.OutCategoryID descending
                            select op;
                    }

                    req.Sort = string.Empty;
                    this.SetSortPage(ref q, req);
                }
                else
                {
                    this.SetSortPage(ref q, req);
                }

                //查询列表
                var list = await q.ToListAsync();

                //是否需要分页
                if (req.IsSetPage() == false)
                {
                    totalRecord = list.Count;
                    totalAmount = list.Sum(m => m.Amount);
                }

                return(new PageAmountList <OutPut>(list, totalRecord, totalAmount));
            }
        }
Example #3
0
        public async Task <ResultPageAmountList <OutRecordListInfo> > QueryOutRecordAsync([FromBody] OutRecordReq req)
        {
            var list = await this.bll.QueryOutRecordAsync(req);

            return(new ResultPageAmountList <OutRecordListInfo>(true, this.bll.Res.Gen.OK, list, (req.GetSkip() + 1), list.TotalRecord, list.TotalAmount));
        }
Example #4
0
        /// <summary>
        /// 查询账户流水
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task <PageMonthAmountList <AccountTurnoverListInfo> > QueryAccountTurnoverAsync(AccountTurnoverListReq req)
        {
            //开始日期
            DateTime startDate = new DateTime(req.Month.Year, req.Month.Month, 1);
            //结束日期
            DateTime endDate = startDate.AddMonths(1).AddMilliseconds(-1);

            #region 查询

            //查询收入明细
            var reqIn = new InRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskIn = this.QueryInRecordAsync(reqIn);

            //查询支出明细
            var reqOut = new OutRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskOut = this.QueryOutRecordAsync(reqOut);

            //查询转账转出明细
            var reqTransferFrom = new TransferRecordReq()
            {
                StartDate = startDate,
                EndDate   = endDate,
                LstFromAmountAccountID = req.LstAmountAccountID
            };
            var taskTransferFrom = this.QueryTransferRecordAsync(reqTransferFrom);

            //查询转账转入明细
            var reqTransferTo = new TransferRecordReq()
            {
                StartDate            = startDate,
                EndDate              = endDate,
                LstToAmountAccountID = req.LstAmountAccountID
            };
            var taskTransferTo = this.QueryTransferRecordAsync(reqTransferTo);

            //查询借还明细
            var reqBR = new BorrowRepayRecordReq()
            {
                StartDate          = startDate,
                EndDate            = endDate,
                LstAmountAccountID = req.LstAmountAccountID
            };
            var taskBR = this.QueryBorrowRepayRecordAsync(reqBR);

            #endregion

            #region 结果类型转换

            //返回结果
            var list = new List <AccountTurnoverListInfo>();

            //收入
            var lstIn = await taskIn;
            foreach (var record in lstIn)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.In;
                item.ID                = record.ID;
                item.Date              = record.InDate;
                item.AmountAccountName = record.AmountAccountName;
                item.TypeName          = record.InTypeName;
                item.Amount            = record.Amount;
            }

            //支出
            var lstOut = await taskOut;
            foreach (var record in lstOut)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Out;
                item.ID                = record.ID;
                item.Date              = record.OutDate;
                item.AmountAccountName = record.AmountAccountName;
                item.TypeName          = record.OutTypeName;
                item.Amount            = -record.Amount;
            }

            //转账转出
            var lstTransferFrom = await taskTransferFrom;
            foreach (var record in lstTransferFrom)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Transfer;
                item.ID                = record.ID;
                item.Date              = record.TransferDate;
                item.AmountAccountName = record.FromAmountAccountName;
                item.TypeName          = this.Res.Cst.TranDir.TransferOut;
                item.Amount            = -record.Amount;
            }

            //转账转入
            var lstTransferTo = await taskTransferTo;
            foreach (var record in lstTransferTo)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.Transfer;
                item.ID                = record.ID;
                item.Date              = record.TransferDate;
                item.AmountAccountName = record.ToAmountAccountName;
                item.TypeName          = this.Res.Cst.TranDir.TransferIn;
                item.Amount            = record.Amount;
            }

            //借还
            var lstBR = await taskBR;
            foreach (var record in lstBR)
            {
                var item = new AccountTurnoverListInfo();
                list.Add(item);

                item.DataType          = EnmDataType.BorrowRepay;
                item.ID                = record.ID;
                item.Date              = record.BRDate;
                item.AmountAccountName = record.AmountAccountName;

                switch ((EnmBorrowRepayType)record.BRType)
                {
                case EnmBorrowRepayType.BorrowIn:
                    item.TypeName = this.Res.Cst.BRT.BorrowIn;
                    item.Amount   = record.Amount;
                    break;

                case EnmBorrowRepayType.RepayIn:
                    item.TypeName = this.Res.Cst.BRT.RepayIn;
                    item.Amount   = record.Amount;
                    break;

                case EnmBorrowRepayType.BorrowOut:
                    item.TypeName = this.Res.Cst.BRT.BorrowOut;
                    item.Amount   = -record.Amount;
                    break;

                case EnmBorrowRepayType.RepayOut:
                    item.TypeName = this.Res.Cst.BRT.RepayOut;
                    item.Amount   = -record.Amount;
                    break;
                }
            }

            //总金额
            var totalAmount = list.Sum(m => m.Amount);

            #endregion

            //排序
            list = list.OrderByDescending(m => m.Date).ThenByDescending(m => m.ID).ThenBy(m => m.Amount).ToList();

            //是否还有前一个月的数据
            var hasPreMonth = startDate > (await InOutDAL.Inst.GetMinTurnoverDate(this.LoginInfo.FamilyID));

            return(new PageMonthAmountList <AccountTurnoverListInfo>(list, req.Month, totalAmount, hasPreMonth));
        }