Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("BranchId,BranchName,Count")] FncBranch fncBranch)
        {
            if (id != fncBranch.BranchId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fncBranch);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FncBranchExists(fncBranch.BranchId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView("~/Areas/Finance/Views/FncBrh/CreateEdit.cshtml", fncBranch));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("BranchId,BranchName,Count")] FncBranch fncBranch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(fncBranch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView("~/Areas/Finance/Views/FncBrh/CreateEdit.cshtml", fncBranch));
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> EditBranch([FromBody] FncBranch fncBranch)
        {
            AppIdentityUser _user = await _userManager.FindByNameAsync(User.Identity.Name);

            var brh = _context.FncBranch.SingleOrDefault(x => x.BranchId == fncBranch.BranchId);

            brh.IsType = fncBranch.IsType;
            _context.Update(brh);
            _context.SaveChanges();
            return(Json(new { brh }));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Index(string branchName = "既见·南国", int branchId = 2, int count = 15)
        {
            AppIdentityUser _user = await _userManager.FindByNameAsync(User.Identity.Name);

            ViewData["UserName"] = _user.UserName;
            ViewData["Branch"]   = _user.Branch;
            ViewData["BranchId"] = branchId;
            var fncBranch = new FncBranch();

            fncBranch.BranchName = branchName;
            fncBranch.BranchId   = branchId;
            fncBranch.Count      = count;
            var list_branch = await _context.FncBranch.Where(x => x.BranchName != "运营中心" && x.BranchName != "町隐学院").ToListAsync();

            return(View(Tuple.Create <FncBranch, List <FncBranch> >(fncBranch, list_branch)));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Index(string branchName = "既见·南国", int branchId = 2)
        {
            ViewData["BranchId"] = branchId;
            var fncBranch = new FncBranch();

            fncBranch.BranchName = branchName;
            fncBranch.BranchId   = branchId;

            var list_paymentType = await _context.FncPaymentType.ToListAsync();

            ViewData["PaymentType"] = new SelectList(list_paymentType, "PaymentType", "PaymentType");
            var list_channelType = await _context.FncChannelType.ToListAsync();

            ViewData["ChannelType"] = new SelectList(list_channelType, "ChannelType", "ChannelType");

            return(View(fncBranch));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Index(string branchName = "既见·南国", int branchId = 2)
        {
            #region 前台账目去重
            //var templist = _context.BrhFrontDeskAccounts.ToList();
            //var grouplist=templist.Where((x, i) => templist.FindIndex(z => z.HouseNumber == x.HouseNumber&&z.StartDate==x.StartDate&&z.EndDate==x.EndDate&&z.State==x.State) == i).ToList();
            //foreach(var t in templist)
            //{
            //    if(grouplist.Find(x=>x.FrontDeskAccountsId==t.FrontDeskAccountsId)==null)
            //    {
            //        _context.Remove(t);
            //        _context.SaveChanges();
            //    }
            //}
            #endregion

            #region 云掌柜导入后台
            //var templist = _context.BrhYun.ToList();
            //foreach (var t in templist)
            //{
            //    BrhFrontDeskAccounts brhFrontDeskAccounts = new BrhFrontDeskAccounts();
            //    brhFrontDeskAccounts.Branch = "既见·南国";
            //    brhFrontDeskAccounts.Channel = t.订单来源;
            //    brhFrontDeskAccounts.CustomerName = t.客人;
            //    brhFrontDeskAccounts.CustomerCount = 1;
            //    brhFrontDeskAccounts.EndDate = t.退房时间;
            //    brhFrontDeskAccounts.EnteringStaff = "李辉";
            //    brhFrontDeskAccounts.FrontDeskAccountsId = t.系统订单号;
            //    brhFrontDeskAccounts.FrontDeskLeader = "";
            //    string[] ts = t.房间号.Split(".");
            //    brhFrontDeskAccounts.HouseNumber = ts[0];
            //    brhFrontDeskAccounts.Note = t.订单备注;
            //    brhFrontDeskAccounts.Receivable = t.房费;
            //    brhFrontDeskAccounts.RelationStaff = "";
            //    brhFrontDeskAccounts.StartDate = t.到店时间;
            //    brhFrontDeskAccounts.Steward = "";
            //    brhFrontDeskAccounts.StewardLeader = "";
            //    brhFrontDeskAccounts.TotalPrice = t.房费;
            //    brhFrontDeskAccounts.UnitPrice = t.房费 / t.间夜;
            //    brhFrontDeskAccounts.Count = t.间夜;
            //    foreach (StateType f in Enum.GetValues(typeof(StateType)))
            //    {
            //        if (t.订单状态 == Enum.GetName(typeof(StateType), f))
            //        {
            //            brhFrontDeskAccounts.State = f;
            //        }
            //    }

            //    brhFrontDeskAccounts.Received = t.房费;

            //    brhFrontDeskAccounts.IsFinance = true;
            //    brhFrontDeskAccounts.IsFront = true;
            //    brhFrontDeskAccounts.IsFinish = true;

            //    brhFrontDeskAccounts.EnteringDate = t.预订日期;

            //    var channel1 = _context.FncChannelType.ToList();
            //    var test = 0;
            //    foreach (var c in channel1)
            //    {
            //        if (c.ChannelType == brhFrontDeskAccounts.Channel)
            //        {
            //            brhFrontDeskAccounts.Color = c.Color;
            //            test++;
            //            break;
            //        }
            //    }
            //    if (test == 0)
            //        brhFrontDeskAccounts.Color = "yellow";
            //    if (_context.BrhFrontDeskAccounts.Find(brhFrontDeskAccounts.FrontDeskAccountsId) == null)
            //    {
            //        _context.Add(brhFrontDeskAccounts);
            //        await _context.SaveChangesAsync();
            //    }
            //}
            #endregion

            #region 计算间夜和订单状态
            //var templist = _context.BrhFrontDeskAccounts.Where(x=>DateTime.Compare(x.EndDate, Convert.ToDateTime("2018-11-26"))<=0&&x.Color=="yellow").ToList();
            //foreach (var t in templist)
            //{
            //t.State = StateType.已退房;
            //t.Count = (t.EndDate - t.StartDate).Days;
            //x.Count != (x.EndDate - x.StartDate).Days && (x.EndDate - x.StartDate).Days != 0
            //var count = (t.EndDate - t.StartDate).Days;
            //    t.Count = count;
            //    t.UnitPrice = t.TotalPrice / count;
            //if (t.Color == "yellow")
            //{
            //t.Color = "gray";
            //}
            //_context.Update(t);
            //_context.SaveChanges();
            //}

            #endregion

            ViewData["BranchId"] = branchId;
            var fncBranch = new FncBranch();
            fncBranch.BranchName = branchName;
            fncBranch.BranchId   = branchId;

            var list_paymentType = await _context.FncPaymentType.ToListAsync();

            ViewData["PaymentType"] = new SelectList(list_paymentType, "PaymentType", "PaymentType");
            var list_channelType = await _context.FncChannelType.ToListAsync();

            ViewData["ChannelType"] = new SelectList(list_channelType, "ChannelType", "ChannelType");

            return(View(fncBranch));
        }
Ejemplo n.º 7
0
        public async Task <JsonResult> GetMonthData([FromBody] FncBranch fncBranch)
        {
            var frontList   = _context.BrhFrontDeskAccounts.Where(x => x.Branch == fncBranch.BranchName && x.State != StateType.已删除 && DateTime.Compare(x.StartDate.Date, DateTime.Now.Date) <= 0).ToList();
            var earningList = _context.BrhEarningRecord.Where(x => x.Branch == fncBranch.BranchName).ToList();
            var expendList  = _context.BrhExpendRecord.Where(x => x.Branch == fncBranch.BranchName).ToList();
            var stewardList = _context.BrhStewardAccounts.Where(x => x.Branch == fncBranch.BranchName).ToList();
            var start       = frontList.Select(x => x.StartDate).Min().Date;

            start = start.AddDays(1 - start.Day);
            var end = frontList.Select(x => x.EndDate).Max().Date;

            if (DateTime.Compare(end, DateTime.Now) < 0)
            {
                end = DateTime.Now.AddDays(1).Date;
            }
            end = end.AddDays(1 - end.Day);
            var ms = (end.Year * 12 + end.Month) - (start.Year * 12 + start.Month);

            if (ms == 0)
            {
                return(Json(new { }));
            }
            var monthDataList    = new List <MonthData>();
            var fncMonthDataList = _context.FncMonthData.Where(x => x.BranchId == fncBranch.BranchId).ToList();
            var monthData_Month  = fncMonthDataList.Select(x => x.Month.ToString("yyyy-MM")).ToList();

            for (var i = 0; i <= ms; i++)
            {
                var fncMonthData = new FncMonthData();
                var cFrontList   = frontList.Where(x => DateTime.Compare(start.AddMonths(i), x.StartDate) <= 0 && DateTime.Compare(x.StartDate, start.AddMonths(i + 1)) < 0).ToList();
                var cEarningList = earningList.Where(x => DateTime.Compare(start.AddMonths(i), x.EnteringDate) <= 0 && DateTime.Compare(x.EnteringDate, start.AddMonths(i + 1)) < 0).ToList();
                var cExpendList  = expendList.Where(x => DateTime.Compare(start.AddMonths(i), x.EnteringDate) <= 0 && DateTime.Compare(x.EnteringDate, start.AddMonths(i + 1)) < 0).ToList();
                var cStewardList = stewardList.Where(x => DateTime.Compare(start.AddMonths(i), x.EnteringDate) <= 0 && DateTime.Compare(x.EnteringDate, start.AddMonths(i + 1)) < 0).ToList();
                if (!monthData_Month.Contains(start.AddMonths(i).ToString("yyyy-MM")))
                {
                    fncMonthData.BranchId    = fncBranch.BranchId;
                    fncMonthData.Earning     = cEarningList.Select(x => x.Amount).Sum();
                    fncMonthData.Expend      = cExpendList.Select(x => x.Amount).Sum();
                    fncMonthData.HouseAmount = cFrontList.Select(x => x.TotalPrice).Sum();
                    fncMonthData.HouseCount  = cFrontList.Select(x => x.Count).Sum();
                    if (i != ms)
                    {
                        fncMonthData.HouseTotal = DateTime.DaysInMonth(start.AddMonths(i).Year, start.AddMonths(i).Month) * fncBranch.Count;
                    }
                    else
                    {
                        fncMonthData.HouseTotal = DateTime.Now.Day * fncBranch.Count;
                    }
                    if (fncMonthData.HouseTotal != 0)
                    {
                        fncMonthData.Rate         = (double)fncMonthData.HouseCount / (double)fncMonthData.HouseTotal;
                        fncMonthData.ValidAverage = fncMonthData.HouseAmount / fncMonthData.HouseTotal;
                    }
                    else
                    {
                        fncMonthData.Rate         = 0;
                        fncMonthData.ValidAverage = 0;
                    }
                    if (fncMonthData.HouseCount != 0)
                    {
                        fncMonthData.Average = fncMonthData.HouseAmount / fncMonthData.HouseCount;
                    }
                    else
                    {
                        fncMonthData.Average = 0;
                    }
                    fncMonthData.Month      = start.AddMonths(i);
                    fncMonthData.SaleAmount = cStewardList.Select(x => x.Amount).Sum();
                    fncMonthData.SaleProfit = cStewardList.Select(x => x.Profit).Sum();
                    _context.Add(fncMonthData);
                    fncMonthDataList.Add(fncMonthData);
                }
                else if (i == ms - 1)
                {
                    var tempMonthData = fncMonthDataList.SingleOrDefault(x => DateTime.Compare(x.Month, start.AddMonths(i)) == 0);
                    tempMonthData.BranchId    = fncBranch.BranchId;
                    tempMonthData.Earning     = cEarningList.Select(x => x.Amount).Sum();
                    tempMonthData.Expend      = cExpendList.Select(x => x.Amount).Sum();
                    tempMonthData.HouseAmount = cFrontList.Select(x => x.TotalPrice).Sum();
                    tempMonthData.HouseCount  = cFrontList.Select(x => x.Count).Sum();
                    tempMonthData.HouseTotal  = DateTime.DaysInMonth(start.AddMonths(i).Year, start.AddMonths(i).Month) * fncBranch.Count;
                    if (tempMonthData.HouseTotal != 0)
                    {
                        tempMonthData.Rate         = (double)tempMonthData.HouseCount / (double)tempMonthData.HouseTotal;
                        tempMonthData.ValidAverage = tempMonthData.HouseAmount / tempMonthData.HouseTotal;
                    }
                    else
                    {
                        tempMonthData.Rate         = 0;
                        tempMonthData.ValidAverage = 0;
                    }
                    if (tempMonthData.HouseCount != 0)
                    {
                        tempMonthData.Average = tempMonthData.HouseAmount / tempMonthData.HouseCount;
                    }
                    else
                    {
                        tempMonthData.Average = 0;
                    }
                    tempMonthData.Month      = start.AddMonths(i);
                    tempMonthData.SaleAmount = cStewardList.Select(x => x.Amount).Sum();
                    tempMonthData.SaleProfit = cStewardList.Select(x => x.Profit).Sum();
                    _context.Update(tempMonthData);
                }
                else if (i == ms)
                {
                    var tempMonthData = fncMonthDataList.SingleOrDefault(x => DateTime.Compare(x.Month, start.AddMonths(i)) == 0);
                    tempMonthData.BranchId    = fncBranch.BranchId;
                    tempMonthData.Earning     = cEarningList.Select(x => x.Amount).Sum();
                    tempMonthData.Expend      = cExpendList.Select(x => x.Amount).Sum();
                    tempMonthData.HouseAmount = cFrontList.Select(x => x.TotalPrice).Sum();
                    tempMonthData.HouseCount  = cFrontList.Select(x => x.Count).Sum();
                    tempMonthData.HouseTotal  = DateTime.Now.Day * fncBranch.Count;
                    if (tempMonthData.HouseTotal != 0)
                    {
                        tempMonthData.Rate         = (double)tempMonthData.HouseCount / (double)tempMonthData.HouseTotal;
                        tempMonthData.ValidAverage = tempMonthData.HouseAmount / tempMonthData.HouseTotal;
                    }
                    else
                    {
                        tempMonthData.Rate         = 0;
                        tempMonthData.ValidAverage = 0;
                    }
                    if (tempMonthData.HouseCount != 0)
                    {
                        tempMonthData.Average = tempMonthData.HouseAmount / tempMonthData.HouseCount;
                    }
                    else
                    {
                        tempMonthData.Average = 0;
                    }
                    tempMonthData.Month      = start.AddMonths(i);
                    tempMonthData.SaleAmount = cStewardList.Select(x => x.Amount).Sum();
                    tempMonthData.SaleProfit = cStewardList.Select(x => x.Profit).Sum();
                    _context.Update(tempMonthData);
                }
                await _context.SaveChangesAsync();
            }

            foreach (var fncMonthData1 in fncMonthDataList)
            {
                var monthData1 = new MonthData();
                var ParentType = typeof(FncMonthData);
                var Properties = ParentType.GetProperties();
                foreach (var Propertie in Properties)
                {
                    if (Propertie.CanRead && Propertie.CanWrite)
                    {
                        Propertie.SetValue(monthData1, Propertie.GetValue(fncMonthData1, null), null);
                    }
                }
                var fncMonthData2 = fncMonthDataList.SingleOrDefault(x => x.Month.ToString("yyyy-MM") == fncMonthData1.Month.AddMonths(-1).ToString("yyyy-MM"));
                if (fncMonthData2 != null)
                {
                    monthData1.环比增长额   = fncMonthData1.HouseAmount - fncMonthData2.HouseAmount;
                    monthData1.环比增长率   = (double)monthData1.环比增长额 / (double)fncMonthData2.HouseAmount;
                    monthData1.出环比增长额  = (decimal)(fncMonthData1.Rate - fncMonthData2.Rate);
                    monthData1.出环比增长率  = (double)monthData1.出环比增长额 / fncMonthData2.Rate;
                    monthData1.均环比增长额  = fncMonthData1.Average - fncMonthData2.Average;
                    monthData1.均环比增长率  = (double)monthData1.均环比增长额 / (double)fncMonthData2.Average;
                    monthData1.环比增长额   = fncMonthData1.ValidAverage - fncMonthData2.ValidAverage;
                    monthData1.环比增长率   = (double)monthData1.环比增长额 / (double)fncMonthData2.ValidAverage;
                    monthData1.支环比增长额  = fncMonthData1.Expend - fncMonthData2.Expend;
                    monthData1.支环比增长率  = (double)monthData1.支环比增长额 / (double)fncMonthData2.Expend;
                    monthData1.外环比增长额  = fncMonthData1.SaleAmount - fncMonthData2.SaleAmount;
                    monthData1.外环比增长率  = (double)monthData1.外环比增长额 / (double)fncMonthData2.SaleAmount;
                    monthData1.外利环比增长额 = fncMonthData1.SaleProfit - fncMonthData2.SaleProfit;
                    monthData1.外利环比增长率 = (double)monthData1.外利环比增长额 / (double)fncMonthData2.SaleProfit;
                }
                else
                {
                    monthData1.环比增长额   = 0;
                    monthData1.环比增长率   = 0;
                    monthData1.出环比增长额  = 0;
                    monthData1.出环比增长率  = 0;
                    monthData1.均环比增长额  = 0;
                    monthData1.均环比增长率  = 0;
                    monthData1.环比增长额   = 0;
                    monthData1.环比增长率   = 0;
                    monthData1.支环比增长额  = 0;
                    monthData1.支环比增长率  = 0;
                    monthData1.外环比增长额  = 0;
                    monthData1.外环比增长率  = 0;
                    monthData1.外利环比增长额 = 0;
                    monthData1.外利环比增长率 = 0;
                }
                var fncMonthData3 = fncMonthDataList.SingleOrDefault(x => x.Month.ToString("yyyy-MM") == fncMonthData1.Month.AddYears(-1).ToString("yyyy-MM"));
                if (fncMonthData3 != null)
                {
                    monthData1.比增长额    = fncMonthData1.HouseAmount - fncMonthData3.HouseAmount;
                    monthData1.比增长率    = (double)monthData1.比增长额 / (double)fncMonthData3.HouseAmount;
                    monthData1.出同比增长额  = (decimal)(fncMonthData1.Rate - fncMonthData3.Rate);
                    monthData1.出同比增长率  = (double)monthData1.出同比增长额 / fncMonthData3.Rate;
                    monthData1.均同比增长额  = fncMonthData1.Average - fncMonthData3.Average;
                    monthData1.均同比增长率  = (double)monthData1.均同比增长额 / (double)fncMonthData3.Average;
                    monthData1.比增长额    = fncMonthData1.ValidAverage - fncMonthData3.ValidAverage;
                    monthData1.比增长率    = (double)monthData1.比增长额 / (double)fncMonthData3.ValidAverage;
                    monthData1.支同比增长额  = fncMonthData1.Expend - fncMonthData3.Expend;
                    monthData1.支同比增长率  = (double)monthData1.支同比增长额 / (double)fncMonthData3.Expend;
                    monthData1.外同比增长额  = fncMonthData1.SaleAmount - fncMonthData3.SaleAmount;
                    monthData1.外同比增长率  = (double)monthData1.外同比增长额 / (double)fncMonthData3.SaleAmount;
                    monthData1.外利同比增长额 = fncMonthData1.SaleProfit - fncMonthData3.SaleProfit;
                    monthData1.外利同比增长率 = (double)monthData1.外利同比增长额 / (double)fncMonthData3.SaleProfit;
                }
                else
                {
                    monthData1.比增长额    = 0;
                    monthData1.比增长率    = 0;
                    monthData1.出同比增长额  = 0;
                    monthData1.出同比增长率  = 0;
                    monthData1.均同比增长额  = 0;
                    monthData1.均同比增长率  = 0;
                    monthData1.比增长额    = 0;
                    monthData1.比增长率    = 0;
                    monthData1.支同比增长额  = 0;
                    monthData1.支同比增长率  = 0;
                    monthData1.外同比增长额  = 0;
                    monthData1.外同比增长率  = 0;
                    monthData1.外利同比增长额 = 0;
                    monthData1.外利同比增长率 = 0;
                }
                monthDataList.Add(monthData1);
            }
            monthDataList = monthDataList.OrderBy(x => x.Month).ToList();

            var front2List = _context.BrhFrontDeskAccounts.Where(x => x.Branch == fncBranch.BranchName && x.State != StateType.已删除 && x.StartDate.Month != x.EndDate.AddDays(-1).Month).ToList();

            return(Json(new { monthDataList, monthData_Month, front2List }));
        }