public List <BC06_DTO> GetDataReport07(ClaimsPrincipal principal, string productId, string idPromotion, string idGift, string idBranch, string idDepartment, string fromDate, string toDate) { var result = new List <BC06_DTO>(); SessionManager.DoWork(ss => { try { var _fromDate = DateTime.ParseExact(fromDate + " 00:00:00,000", "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture); var _toDate = DateTime.ParseExact(toDate + " 00:00:00,000", "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture); //var _toDate = Convert.ToDateTime(DateTime.ParseExact(toDate, "dd-MM-yyyy", CultureInfo.InvariantCulture)); var userinfo = ContextProvider.GetUserInfo(principal); var promotions = ss.Query <Promotion>().ToList(); var organization = ss.Query <Organization>().ToList(); var branchs = organization.Where(w => w.ManageCode == "CN").ToList(); var dept = organization.Where(w => w.ManageCode == "PGD").ToList(); var gifts = ss.Query <Gift>().ToList(); var data = ss.Query <CustomerGift>().Where(s => s.Status == 2 && s.CREATEDDATE <= _toDate.AddDays(1) && s.CREATEDDATE >= _fromDate).ToList(); if (!string.IsNullOrEmpty(idPromotion)) { data = data.Where(s => s.Promotion.Id == new Guid(idPromotion)).ToList(); } if (!string.IsNullOrEmpty(idDepartment)) { var dep = dept.FirstOrDefault(w => w.Id == new Guid(idDepartment)); data = data.Where(s => s.SUBBRID == dep.Code).ToList(); } if (!string.IsNullOrEmpty(idBranch)) { var branch = branchs.FirstOrDefault(w => w.Id == new Guid(idBranch)); data = data.Where(s => s.BRANCHID == branch.Code).ToList(); } if (!string.IsNullOrEmpty(idGift)) { data = data.Where(s => s.Gift.Id == new Guid(idGift)).ToList(); } if (userinfo.OrganizationCode != "QLBH" && userinfo.UserName != "admin" && userinfo.UserName != "nva") { //Nếu là LD CN/PGD if (userinfo.Position.IsLeader) { data = data.Where(s => s.SUBBRID == userinfo.Organization.Code).ToList(); } else//CV CN/PGD { data = data.Where(s => s.CREATEDBy == userinfo.Id).ToList(); } } switch (productId.ToUpper()) { case "BC_07": var lstGift = (from _data in data join _gift in gifts on _data.Gift.Id equals _gift.Id join _promotion in promotions on _data.Promotion.Id equals _promotion.Id select new BC06_DTO { DepartmentName = _data.SUBBRNAME, BranchName = _data.BRNAME, SoTK = _data.Acctno, CIF = _data.CusId, CustomerName = _data.CusName, GhiChu = "", GiaTriQuaTang = _gift.Price, KyHan = _data.TERM, LoaiQua = _data.BRNAME, NgayGui = _data.TODATE.ToString("dd-MM-yyyy"), SoDu = _data.BALANCE, GiftName = _gift.Name, PromotionName = _promotion.Name, PhanHe = _data.PhanHe, LoaiTien = _data.CCYCD, TenLoaiHinh = _data.TENLOAIHINH, OrderByDate = ContextProvider.GetOrderDatetime(_data.CREATEDDATE) }).OrderBy(pp => pp.BranchName).OrderBy(p => p.DepartmentName).OrderByDescending(pp => pp.OrderByDate); result = lstGift.ToList(); break; case "BC_08": var lstBC_08 = new List <BC06_DTO>(); var groupPGD = data.GroupBy(g => new { g.SUBBRID, GifiId = g.Gift.Id }).Select(s => new { SUBBRID = s.Key.SUBBRID, GifiId = s.Key.GifiId, Amount = s.Count(), Balance = s.Sum(f => f.BALANCE) }).ToList(); groupPGD.ForEach(code => { var depBC08 = organization.FirstOrDefault(f => f.Code == code.SUBBRID); var branchBC08 = depBC08.ManageCode == "CN" ? depBC08 : organization.FirstOrDefault(f => f.Id == depBC08?.ParentId); var giftBC08 = gifts.FirstOrDefault(f => f.Id == code.GifiId); var save = new BC06_DTO { BranchName = branchBC08.Name, DepartmentName = depBC08.Name, SoDu = code.Balance, SoLuong = code.Amount.ToString(), GiaTriQuaTang = (giftBC08.Price * code.Amount), GiftCode = giftBC08.Code, GiftName = giftBC08.Name, GhiChu = "" }; lstBC_08.Add(save); }); lstBC_08 = lstBC_08.OrderBy(pp => pp.BranchName).OrderBy(p => p.DepartmentName).ToList(); result = lstBC_08.ToList(); break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } }); return(result); }
public List <BaoCaoQuaTangDTO> GetDataReport(ClaimsPrincipal principal, string productId, string idPromotion, string fromDate, string toDate) { var result = new List <BaoCaoQuaTangDTO>(); SessionManager.DoWork(ss => { try { var _fromDate = DateTime.ParseExact(fromDate + " 00:00:00,000", "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture); var _toDate = DateTime.ParseExact(toDate + " 00:00:00,000", "yyyy-MM-dd HH:mm:ss,fff", System.Globalization.CultureInfo.InvariantCulture); var userinfo = ContextProvider.GetUserInfo(principal); var promotion = ss.Query <Promotion>().ToList(); var organization = ss.Query <Organization>().ToList(); var tranfer = ss.Query <TransferGift>().Where(s => s.Status == 2 && s.CreatedDate <= _toDate.AddDays(1) && s.CreatedDate >= _fromDate).ToList(); if (productId != null) { tranfer = tranfer.Where(s => s.Product.Id == new Guid(productId)).ToList(); } if (userinfo.OrganizationCode != "QLBH" && userinfo.UserName != "admin" && userinfo.UserName != "nva") { //Nếu là LD CN/PGD if (userinfo.Position.IsLeader) { tranfer = tranfer.Where(s => s.DepartmentId == userinfo.Organization.Id).ToList(); } else//CV CN/PGD { tranfer = tranfer.Where(s => s.CreatedBy == userinfo.Id).ToList(); } } if (idPromotion != null && productId.ToUpper() != "7A452975-E667-41CB-9B32-5875D357FF37") { tranfer = tranfer.Where(s => s.PromotionId == new Guid(idPromotion)).ToList(); } var lstTranferId = tranfer.Select(s => s.Id); var tranferDetail = ss.Query <TransferDetail>().Where(s => lstTranferId.Contains(s.TransferGift.Id)).ToList(); var gifts = ss.Query <Gift>().ToList(); var lstGift = (from _tranfer in tranfer join _tranferDetail in tranferDetail on _tranfer.Id equals _tranferDetail.TransferGift.Id join _gifts in gifts on _tranferDetail.GiftId equals _gifts.Id select new BaoCaoQuaTangDTO { Amount = _tranferDetail.Amount, ReceivingDepartment = ContextProvider.GetOrganizationName(organization, _tranferDetail.ReceivingDepartment), ReceivingPromotion = ContextProvider.GetPromotionName(promotion, _tranferDetail.ReceivingPromotion), CreatedDate = ContextProvider.GetConvertDatetime(_tranfer.CreatedDate), TranferDepartment = ContextProvider.GetOrganizationName(organization, _tranfer.DepartmentId), Code = _gifts.Code, Name = _gifts.GiftGroup.OptionGift.Name + " - " + _gifts.GiftGroup.Name + " - " + _gifts.Name, UnitName = _gifts.Unit.Name, Price = _gifts.Price.ToString("f0"), GiftGroupId = _gifts.GiftGroup.Id.ToString(), GroupName = _gifts.GiftGroup.Name, OptionGiftId = _gifts.GiftGroup.OptionGift.Id.ToString(), OptionGiftName = _gifts.GiftGroup.OptionGift.Name, OrderByDate = ContextProvider.GetOrderDatetime(_tranfer.CreatedDate) }).OrderBy(pp => pp.Name).OrderBy(p => p.GroupName).OrderBy(pp => pp.OptionGiftName).OrderByDescending(pp => pp.OrderByDate); result = lstGift.ToList(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }); return(result); }