示例#1
0
        public ActionResult QueryMonthEnd(string payTypeId, string yearMonth)
        {
            var companyRecords = CompanyRecordHelper.CompanyList();

            if (!string.IsNullOrEmpty(yearMonth))
            {
                int year  = int.Parse(yearMonth.Split('-')[0]);
                int month = int.Parse(yearMonth.Split('-')[1]);
                companyRecords = companyRecords.Where(item => item.TransTime.Year == year && item.TransTime.Month == month).ToList();
            }
            if (!string.IsNullOrEmpty(payTypeId))
            {
                companyRecords = companyRecords.Where(item => item.PayTypeId == payTypeId).ToList();
            }

            TempData["companyRecords"] = companyRecords;
            return(RedirectToAction("CompanyEnd", new { payTypeId = payTypeId, yearMonth = yearMonth }));
        }
示例#2
0
        public ActionResult QueryCompanyRecord(CompanyQueryMod queryMod, int pageIndex = 1)
        {
            var companyRecords = CompanyRecordHelper.CompanyList().OrderByDescending(item => item.TransTime).Where(item => item.Id != "");

            if (!string.IsNullOrEmpty(queryMod.StaffId))
            {
                companyRecords = companyRecords.Where(item => item.StaffId == queryMod.StaffId);
            }
            if (!string.IsNullOrEmpty(queryMod.PayTypeId))
            {
                companyRecords = companyRecords.Where(item => item.PayTypeId == queryMod.PayTypeId);
            }
            if (queryMod.PayTimeBegin >= Convert.ToDateTime("2017-01-01"))
            {
                companyRecords = companyRecords.Where(item => item.TransTime >= queryMod.PayTimeBegin);
            }
            if (queryMod.PayTimeEnd >= Convert.ToDateTime("2017-01-01"))
            {
                companyRecords = companyRecords.Where(item => item.TransTime <= queryMod.PayTimeEnd.AddHours(8));
            }
            //获取页条数
            int pageSize   = PageSize();
            var sumRecords = companyRecords.ToList();

            TempData["queryRecords"] = sumRecords
                                       .OrderByDescending(item => item.TransTime)
                                       .Skip((pageIndex - 1) * pageSize)
                                       .Take(pageSize)
                                       .ToList();

            TempData["allRecords"] = sumRecords;

            TempData["queryMod"] = queryMod;
            //记录分页相关字段
            TempData["totalPage"] = sumRecords.Count() % pageSize == 0
                ? sumRecords.Count() / pageSize
                : Math.Ceiling(Convert.ToDouble(sumRecords.Count()) / pageSize);
            TempData["totalSize"]   = sumRecords.Count();
            TempData["currentPage"] = pageIndex;

            return(RedirectToAction("CompanyRecord"));
        }
        // GET: Summary
        public ActionResult Index(string yearMonth)
        {
            int year;
            int month;

            if (string.IsNullOrEmpty(yearMonth))
            {
                //默认显示上一个月的月底结算情况
                year      = DateTime.Now.AddMonths(-1).Year;
                month     = DateTime.Now.AddMonths(-1).Month;
                yearMonth = year + "-" + month;
            }
            else
            {
                year  = int.Parse(yearMonth.Split('-')[0]);
                month = int.Parse(yearMonth.Split('-')[1]);
            }

            var records  = DailyRecordHelper.DailyRecordList().Where(item => item.VisitDate.Year == year && item.VisitDate.Month == month);
            var products = ProductHelper.ProductList();

            var dailyRecords =
                DailyRecordHelper.DailyRecordList()
                .Where(item => item.VisitDate.Year == year && item.VisitDate.Month == month);
            var companyRecords =
                CompanyRecordHelper.CompanyList()
                .Where(item => item.TransTime.Year == year && item.TransTime.Month == month);
            MonthEndSummary monthEnd = new MonthEndSummary();
            //员工汇总
            MonthEndSummary monthEnd1 = dailyRecords.GroupBy(item => new { item.VisitDate.Year, item.VisitDate.Month })
                                        .Select(g => new MonthEndSummary()
            {
                StaffEarn =
                    g.Sum(x => x.EarnMonthEndPrice) + g.Sum(x => x.EarnWaterCardPrice) + g.Sum(x => x.EarnDeposit),
                StaffPay = g.Sum(x => x.PayDeposit)
            }).FirstOrDefault();

            ////公司汇总
            //公司支出动态加入员工提成
            double commission   = Commission();
            double sumBucketCom = dailyRecords.Sum(i => i.SendBucketAmount) * commission;

            MonthEndSummary monthEnd2 = companyRecords.GroupBy(item => new { item.TransTime.Year, item.TransTime.Month })
                                        .Select(g => new MonthEndSummary()
            {
                CompanyEarn = g.Where(item => item.IsPayType == false).Sum(x => x.TransSum),
                CompanyPay  = g.Where(item => item.IsPayType).Sum(x => x.TransSum) + sumBucketCom    //进水支出不计入公司盈利运算   2018.03.14:进水支出计入公司盈利运算
            }).FirstOrDefault();

            //计算员工月送水成本
            double sumCost = records.Join(products, x => x.SendProductId, y => y.Id, (x, y) => new { x, y })
                             .Select(item => new SumSendbucketCost
            {
                SumCost = item.x.SendBucketAmount * item.y.CostPrice
            }).Sum(item => item.SumCost);


            monthEnd.CompanyEarn  = (monthEnd2?.CompanyEarn ?? 0) + (monthEnd1?.StaffEarn ?? 0);                                   //仅保留公司收入/公司支出
            monthEnd.CompanyPay   = (monthEnd2?.CompanyPay ?? 0) + (monthEnd1?.StaffPay ?? 0);
            monthEnd.MonthEndEarn = monthEnd.StaffEarn + monthEnd.CompanyEarn - monthEnd.StaffPay - monthEnd.CompanyPay - sumCost; //2018.03.28改动:月底盈利减去员工送水成本
            monthEnd.YearMonth    = year + "-" + month;

            //计算员工提成,作为发工资的参考
            var staffs = StaffHelper.StaffList();
            List <StaffCommissionViewModel> staffCommission = new List <StaffCommissionViewModel>();

            foreach (var staff in staffs)
            {
                int bucketCount = dailyRecords.Where(item => item.StaffId == staff.Id).Sum(i => i.SendBucketAmount);
                staffCommission.Add(new StaffCommissionViewModel
                {
                    StaffName   = staff.StaffName,
                    BucketCount = bucketCount,
                    Comission   = bucketCount * commission
                });
            }
            ViewBag.staffCommission = staffCommission;

            ViewBag.queryPam = JsonConvert.SerializeObject(new { YearMonth = yearMonth });
            ViewBag.flag     = "EndSummary";
            ViewBag.staffs   = staffs;
            ViewBag.sumCost  = sumCost;
            return(View(monthEnd));
        }
        /// <summary>
        /// 1. 水厂库存明细,统计字段:交易年月 产品名称 库存 空桶库存
        /// 2. 水厂交易明细 支付总押金 退还总押金 进水总支出
        /// </summary>
        /// <returns></returns>
        public ActionResult TransRecord(string yearMonth, string factoryId)
        {
            int year;
            int month;
            if (string.IsNullOrEmpty(yearMonth))
            {
                //默认显示上一个月的月底结算情况
                year = DateTime.Now.AddMonths(-1).Year;
                month = DateTime.Now.AddMonths(-1).Month;
                yearMonth = year + "-" + month;
            }
            else
            {
                year = int.Parse(yearMonth.Split('-')[0]);
                month = int.Parse(yearMonth.Split('-')[1]);
            }
            var factories = FactoryHelper.FactoryList();
            var products = ProductHelper.ProductList();
            var payTypes = CompanyPayTypeHelper.PayTypeList();
            //选定年月下的日常、公司交易记录
            var companyRecords = CompanyRecordHelper.CompanyList();
            var dailyRecords = DailyRecordHelper.DailyRecordList();
            //1.库存明细
            var factoryStocks = (from r in dailyRecords
                                 join p in products
                                 on r.SendProductId equals p.Id
                                 where r.VisitDate.Year == year && r.VisitDate.Month == month
                                 join f in factories
                                 on p.FactoryId equals f.Id
                                 where f.Id == (string.IsNullOrEmpty(factoryId) ? f.Id : factoryId)
                                 group
                                 new { p.FactoryId, p.Id, r.SendBucketAmount, r.ReceiveEmptyBucketAmount, p.ProductName, f.FactoryName } by
                                 new { p.FactoryId, p.Id }
                into t
                                 select new FactoryStock
                                 {
                                     FactoryName = t.First().FactoryName,
                                     TransMonth = yearMonth,
                                     ProductName = t.First().ProductName,
                                     BucketStock = t.Sum(i => i.SendBucketAmount),
                                     EmptyBucketStock = t.Sum(i => i.ReceiveEmptyBucketAmount)
                                 }).OrderByDescending(item => item.FactoryName);

            //2.交易明细
            var factoryTrans = (from c in companyRecords
                                join f in factories
                                on c.FactoryId equals f.Id
                                where c.TransTime.Year == year && c.TransTime.Month == month && f.Id == (string.IsNullOrEmpty(factoryId) ? f.Id : factoryId)
                                join p in payTypes
                                on c.PayTypeId equals p.Id
                                group new { c.IsPayType, c.TransSum, f.FactoryName, p.PayType } by
                                new { c.FactoryId, c.PayTypeId }
                into t
                                select new FactoryTrans
                                {
                                    FactoryName = t.First().FactoryName,
                                    TransType = t.First().PayType,
                                    IsPayType = t.First().IsPayType,
                                    TransSum = t.Sum(i => i.TransSum),
                                    TransMonth = yearMonth
                                }).OrderByDescending(item => item.FactoryName);

            FactorySumaryViewModel factorySumary = new FactorySumaryViewModel
            {
                FactoryStock = factoryStocks.ToList(),
                FactoryTrans = factoryTrans.ToList()
            };

            ViewBag.queryPam = JsonConvert.SerializeObject(new { YearMonth = yearMonth, FactoryId = factoryId });
            factories.Insert(0, new Factory { Id = "", FactoryName = "" });
            ViewBag.factories = factories;
            ViewBag.flag = "FactoryTransRecord";
            ViewBag.YearMonth = yearMonth;
            return View(factorySumary);
        }
示例#5
0
        public ActionResult CompanyRecord()
        {
            //获取页条数
            int pageSize          = PageSize();
            var companyRecords    = CompanyRecordHelper.CompanyList();
            var companyPayRecords = TempData["queryRecords"] == null
                ? companyRecords.OrderByDescending(item => item.TransTime).Skip(0).Take(pageSize)
                : TempData["queryRecords"] as List <CompanyPayRecord>;

            //用于导出的所有纪录
            var allRecords = TempData["allRecords"] == null
                ? companyRecords.OrderByDescending(item => item.TransTime).ToList()
                : TempData["allRecords"] as List <CompanyPayRecord>;

            var staffs   = StaffHelper.StaffList();
            var paytypes = CompanyPayTypeHelper.PayTypeList();

            var payRecordInfo = (from r in companyPayRecords
                                 join p in paytypes
                                 on r.PayTypeId equals p.Id
                                 join s in staffs
                                 on r.StaffId equals s.Id
                                 select new CompanyPayRecordDesc()
            {
                StaffName = s.StaffName,
                PayTypeDesc = p.PayType,
                IsPayType = r.IsPayType,
                TransSum = r.TransSum,
                TransTime = r.TransTime,
                Describe = r.Describe
            }).ToList();

            var allRecordsToExport = (from r in allRecords
                                      join p in paytypes
                                      on r.PayTypeId equals p.Id
                                      join s in staffs
                                      on r.StaffId equals s.Id
                                      select new CompanyPayRecordDesc()
            {
                StaffName = s.StaffName,
                PayTypeDesc = p.PayType,
                IsPayType = r.IsPayType,
                TransSum = r.TransSum,
                TransTime = r.TransTime,
                Describe = r.Describe
            }).ToList();

            ViewBag.AllRecords = allRecordsToExport;
            ViewBag.Staffs     = staffs;
            ViewBag.Paytypes   = paytypes;

            ViewBag.queryPam = TempData["queryMod"] == null ? "{}" : JsonConvert.SerializeObject(TempData["queryMod"]);

            ViewBag.totalPage = TempData["totalPage"] == null
                ? (companyRecords.Count() % pageSize == 0
                    ? companyRecords.Count() / pageSize
                    : Math.Ceiling(Convert.ToDouble(companyRecords.Count()) / pageSize))
                : int.Parse(TempData["totalPage"].ToString());

            ViewBag.totalSize = TempData["totalSize"] == null
                ? companyRecords.Count
                : int.Parse(TempData["totalSize"].ToString());
            ViewBag.currentPage = TempData["currentPage"] == null
                 ? 1
                 : int.Parse(TempData["currentPage"].ToString());

            ViewBag.flag = "CompanyRecord";
            return(View(payRecordInfo));
        }
示例#6
0
        /// <summary>
        /// 公司结算汇总
        /// </summary>
        /// <returns></returns>
        public ActionResult CompanyEnd(string payTypeId, string yearMonth)
        {
            var companyRecords = TempData["companyRecords"] != null
                ? TempData["companyRecords"] as List <CompanyPayRecord>
                : CompanyRecordHelper.CompanyList();

            var payType = CompanyPayTypeHelper.PayTypeList();
            //日常记录信息,用于统计提成
            var dailyRecords = DailyRecordHelper.DailyRecordList();

            //按年月分组
            var comRecordsMonth = companyRecords
                                  .OrderByDescending(item => item.TransTime)
                                  .GroupBy(item => new { item.TransTime.Year, item.TransTime.Month })
                                  .Select(g => new CompanyPayRecord
            {
                TransTime = g.First().TransTime,
                TransSum  = g.Sum(i => i.IsPayType ? -i.TransSum : i.TransSum)
            }).ToList();

            //按年月、消费类型分组
            var comRecordsMonType = companyRecords
                                    .OrderByDescending(item => item.TransTime)
                                    .GroupBy(item => new { item.TransTime.Year, item.TransTime.Month, item.PayTypeId })
                                    .Select(g => new CompanyPayRecord
            {
                TransTime = g.First().TransTime,
                TransSum  = g.Sum(i => i.IsPayType ? -i.TransSum : i.TransSum),
                PayTypeId = g.First().PayTypeId
            }).Join(payType, x => x.PayTypeId, y => y.Id, (x, y) => new { x, y })
                                    .Select(p => new CompanyPayRecordDesc
            {
                TransTime   = p.x.TransTime,
                TransSum    = p.x.TransSum,
                PayTypeDesc = p.y.PayType
            }).ToList();

            //公司月底结算,动态加入员工提成
            double commission = Commission();

            foreach (var item in comRecordsMonth)
            {
                int sumBucket =
                    dailyRecords.Where(i => i.VisitDate.Year == item.TransTime.Year && i.VisitDate.Month == item.TransTime.Month)
                    .Sum(i => i.SendBucketAmount);
                //当月总支出减去员工提成
                item.TransSum -= sumBucket * commission;

                //年月消费类型集合中添加该月员工统计提成条目
                int index =
                    comRecordsMonType.FindLastIndex(t => t.TransTime.Year == item.TransTime.Year && t.TransTime.Month == item.TransTime.Month);
                comRecordsMonType.Insert(index + 1, new CompanyPayRecordDesc
                {
                    PayTypeDesc = "员工提成(" + commission + "元/桶)",
                    TransTime   = item.TransTime,
                    TransSum    = -sumBucket * commission
                });
            }

            CompanyPayRecordViewModel viewModel = new CompanyPayRecordViewModel()
            {
                CompanyPayRecord     = comRecordsMonth,
                CompanyPayRecordDesc = comRecordsMonType
            };

            //记录查询条件
            ViewBag.queryPam = JsonConvert.SerializeObject(new { YearMonth = yearMonth, PayTypeId = payTypeId });
            ViewBag.flag     = "CompanyEnd";
            ViewBag.PayType  = payType;
            return(View(viewModel));
        }