コード例 #1
0
ファイル: FollowupApi.cs プロジェクト: franknew/AnjuManager
 public PagingEntity<FollowupModel> QueryFullFollowup(FullFollowupQueryForm form)
 {
     HouseBLL housebll = new HouseBLL();
     BuildingBLL buildingbll = new BuildingBLL();
     UserBLL userbll = new UserBLL();
     CustomerBLL customerbll = new CustomerBLL();
     House_CustomerBLL hcbll = new House_CustomerBLL();
     PagingEntity<FollowupModel> result = new PagingEntity<FollowupModel>();
     result.Record = new List<FollowupModel>();
     var list = bll.QueryFullFollowup(form);
     var houseids = (from f in list select f.HouseID).Distinct().ToList();
     var houses = housebll.Query(new HouseQueryForm { IDs = houseids });
     var buildingids = (from h in houses select h.BuildingID).Distinct().ToList();
     var ownerids = (from h in houses where !string.IsNullOrEmpty(h.OwnerID) select h.OwnerID).Distinct().ToList();
     var userids = (from f in list select f.Creator).Distinct().ToList();
     var buildings = buildingbll.Query(new BuildingQueryForm { IDs = buildingids });
     var hcs = hcbll.Query(new House_CustomerQueryForm { HouseOrRoomIDs = houseids });
     var customerids = (from hc in hcs select hc.CustomerID).Distinct().ToList();
     var customers = customerbll.Query(new CustomerQueryForm { IDs = customerids });
     var users = userbll.SimpleQuery(new FullUserQueryForm { IDs = userids });
     list.ForEach(t =>
     {
         FollowupModel followup = new FollowupModel
         {
             House = houses.Find(p => p.ID.Equals(t.HouseID)),
             Followup = t,
             User = users.Find(p=>p.ID.Equals(t.Creator)),
         };
         followup.Building = buildings.Find(p => p.ID.Equals(followup.House?.BuildingID));
         followup.Owner = (from hc in hcs
                           join c in customers on hc.CustomerID equals c.ID
                           where hc.HouseOrRoomID.Equals(followup.House?.ID) && c.Type == (int)CustomerType.业主
                           select c).FirstOrDefault();
         result.Record.Add(followup);
     });
     result.RecordCount = bll.QueryFullFollowupCount(form);
     return result;
 }
コード例 #2
0
ファイル: BillBLL.cs プロジェクト: franknew/AnjuManager
        public int GenerateBill(string userid)
        {
            #region init data
            var now = DateTime.Now;
            var premonth = DateTime.Now.AddMonths(-1);
            HouseBLL housebll = new HouseBLL();
            RentFeeBLL rentfeebll = new RentFeeBLL();
            OtherFeeBLL otherfeebll = new OtherFeeBLL();
            House_OtherFeeBLL hobll = new House_OtherFeeBLL();
            OtherFeeBillBLL ofbbll = new OtherFeeBillBLL();
            var houses = housebll.Query(new HouseQueryForm { IsDeleted = 0, Enabled = 1, IsOurs = 1 });
            var houseids = (from h in houses select h.ID).ToList();
            var rentfees = rentfeebll.Query(new RentFeeQueryForm { Enabled = 1, IsDeleted = 0, RentDay_Start = 1, RentDay_End = now.Day, ExpiredTime_Start = now });
            var premonthbills = Query(new BillQueryForm { Year = premonth.Year, Month = premonth.Month, HouseOrRoomIDs = houseids });
            var currentmonethbill = Query(new BillQueryForm { Year = now.Year, Month = now.Month, HouseOrRoomIDs = houseids });
            var otherfee = otherfeebll.Query(new OtherFeeQueryForm { });
            var ho = hobll.Query(new House_OtherFeeQueryForm { HouseOrRoomIDs = houseids });
            var premonthbillids = (from b in premonthbills select b.ID).ToList();
            var premonthofb = ofbbll.Query(new OtherFeeBillQueryForm { BillIDs = premonthbillids });
            var linked_ho = (from h in ho
                             join of in otherfee on h.OtherFeeID equals of.ID
                             select new { House_OtherFee = h, Fee = of }).ToList();
            #endregion

            #region 生成当日和当日之前未生成的账单
            int i = 0;
            foreach (var rentfee in rentfees)
            {
                //如果存在就说明已经生成过了,这条房租账单不生成
                if (currentmonethbill.Exists(t => t.HouseOrRoomID.Equals(rentfee.HouseOrRoomID))) continue;
                var billid = Guid.NewGuid().ToString().Replace("-", "");
                Bill bill = new Bill
                {
                    ID = billid,
                    HouseOrRoomID = rentfee.HouseOrRoomID,
                    PayDay = new DateTime(now.Year, now.Month, rentfee.RentDay.Value),
                    Month = now.Month,
                    Year = now.Year,
                    Type = rentfee.Type,
                    Creator = userid,
                    ShouldPay = rentfee.RentMoney,
                    Name = now.ToString("yyyyMM月账单"),

                };
                var house_otherfees = linked_ho.FindAll(t => t.House_OtherFee.HouseOrRoomID.Equals(rentfee.HouseOrRoomID));
                var premonthbill = premonthbills.Find(t => t.Year == premonth.Year && t.Month == premonth.Month);
                //生成其他费用账单
                foreach (var house_otherfee in house_otherfees)
                {
                    OtherFeeBill data = new OtherFeeBill
                    {
                        BillID = bill.ID,
                        OtherFeeID = house_otherfee.Fee.ID,
                        Name = house_otherfee.Fee.Name,
                        Creator = userid,
                        Fee = 0,
                        EndValue = 0,
                        StartValue = 0,
                    };
                    //把本月起始的计数设置为上月结束的计数
                    if (premonthbill != null) data.StartValue = premonthofb.Find(t => t.BillID.Equals(premonthbill.ID))?.EndValue;
                    ofbbll.Add(data);
                }
                Add(bill);
                i++;
            }
            #endregion
            return i;
        }