Пример #1
0
        public dynamic TonKho(ClaimsPrincipal principal)
        {
            dynamic result   = new ExpandoObject();
            var     userinfo = ContextProvider.GetUserInfo(principal);

            try
            {
                SessionManager.DoWork(ss =>
                {
                    var lstOrgan     = ss.Query <Organization>().ToList();
                    var lstPromotion = ss.Query <Promotion>().ToList();
                    var lstGift      = ss.Query <Gift>().ToList();
                    result           = ss.Query <Store>().Where(s => s.DepartmentId == userinfo.OrganizationId)
                                       .Select(p => new
                    {
                        DepartmentName = ContextProvider.GetOrganizationName(lstOrgan, p.DepartmentId),
                        PromotionName  = ContextProvider.GetPromotionName(lstPromotion, p.PromotionId),
                        GiftName       = ContextProvider.GiftName(lstGift, p.GiftId),
                        p.Amount,
                        p.UpdatedDate
                    }).ToList();
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(result);
        }
Пример #2
0
        public List <StoreDTO> GetDataReportInventory(ClaimsPrincipal principal, string productId, string idPromotion, string toDate)
        {
            var result   = new List <StoreDTO>();
            var userinfo = ContextProvider.GetUserInfo(principal);

            SessionManager.DoWork(ss =>
            {
                try
                {
                    var _toDate = DateTime.ParseExact(toDate.Replace("-", "/") + " 23:59:59,000", "dd/MM/yyyy HH:mm:ss,fff",
                                                      System.Globalization.CultureInfo.InvariantCulture);
                    var lstPromotions = ss.Query <Promotion>().Where(w => w.CreatedDate <= _toDate && w.Status == 2).ToList();
                    if (!string.IsNullOrEmpty(idPromotion))
                    {
                        lstPromotions = lstPromotions.Where(n => n.Id == Guid.Parse(idPromotion)).ToList();
                    }
                    if (userinfo.OrganizationCode != "QLBH" && userinfo.UserName != "admin" && userinfo.UserName != "nva")
                    {
                        //Nếu là LD CN/PGD
                        if (userinfo.Position.IsLeader)
                        {
                            lstPromotions = lstPromotions.Where(s => s.NguoiDuyet == userinfo.Organization.Id).ToList();
                        }
                        else//CV CN/PGD
                        {
                            lstPromotions = lstPromotions.Where(s => s.CreatedBy == userinfo.Id).ToList();
                        }
                    }
                    var idPromotions     = lstPromotions.Select(s => s.Id).ToList();
                    var idGiftPromotions = lstPromotions.Select(s => s.GiftPromotionId).ToList();
                    var giftPromotions   = ss.Query <GiftPromotion>().Where(s => idGiftPromotions.Contains(s.GiftPromotionId)).ToList();

                    var lstGiftsId      = giftPromotions.Select(s => s.GiftId).ToList();
                    var gifts           = ss.Query <Gift>().Where(s => lstGiftsId.Contains(s.Id)).ToList();
                    var transferGift    = ss.Query <TransferGift>().Where(s => s.Status == 2).ToList();
                    var transferDetails = ss.Query <TransferDetail>().Where(s => lstGiftsId.Contains(s.GiftId)).ToList();
                    var stores          = ss.Query <Store>().Where(s => lstGiftsId.Contains(s.GiftId)).ToList();


                    #region SL Nhap kho
                    var idTranNK    = transferGift.Where(w => w.Product.Id.ToString().ToUpper() == Constants.PARAM_NHAP_KHO && w.Status == 2).Select(s => s.Id);
                    var gbNKDetails = transferDetails.Where(s => idTranNK.Contains(s.TransferGift.Id)).GroupBy(g => new { g.GiftId, g.ReceivingDepartment, productId }).Select(s => new
                    {
                        s.Key.GiftId,
                        DepartmentId = s.Key.ReceivingDepartment,
                        Total        = s.Sum(t => t.Amount)
                    }).ToList();
                    #endregion

                    #region SL Xuất kho
                    var idTranXK    = transferGift.Where(w => w.Product.Id.ToString().ToUpper() == Constants.PARAM_XUAT_KHO && w.Status == 2).Select(s => s.Id);
                    var gbXKDetails = transferDetails.Where(s => idTranXK.Contains(s.TransferGift.Id)).GroupBy(g => new { g.GiftId, g.ReceivingDepartment, productId }).Select(s => new
                    {
                        s.Key.GiftId,
                        DepartmentId = s.Key.ReceivingDepartment,
                        Total        = s.Sum(t => t.Amount)
                    }).ToList();
                    #endregion

                    #region SL Dieu chuyen ngang
                    var idTranDCN    = transferGift.Where(w => w.Product.Id.ToString().ToUpper() == Constants.PARAM_DIEU_CHUYEN_NGANG && w.Status == 2).Select(s => s.Id);
                    var gbDCNDetails = transferDetails.Where(s => idTranDCN.Contains(s.TransferGift.Id)).GroupBy(g => new { g.GiftId, g.ReceivingDepartment, productId }).Select(s => new
                    {
                        s.Key.GiftId,
                        DepartmentId = s.Key.ReceivingDepartment,
                        Total        = s.Sum(t => t.Amount)
                    }).ToList();
                    #endregion

                    #region SL Dieu chuyen noi bo
                    var idTranDCNB    = transferGift.Where(w => w.Product.Id.ToString().ToUpper() == Constants.PARAM_DIEU_CHUYEN_NOI_BO && w.Status == 2).Select(s => s.Id);
                    var gbDCNBDetails = transferDetails.Where(s => idTranDCNB.Contains(s.TransferGift.Id)).GroupBy(g => new { g.GiftId, g.ReceivingDepartment, productId }).Select(s => new
                    {
                        s.Key.GiftId,
                        DepartmentId = s.Key.ReceivingDepartment,
                        Total        = s.Sum(t => t.Amount)
                    }).ToList();
                    #endregion

                    #region SL Phan Bo
                    var idTranPBo    = transferGift.Where(w => w.Product.Id.ToString().ToUpper() == Constants.PARAM_PHAN_BO && w.Status == 2).Select(s => s.Id);
                    var gbPBoDetails = transferDetails.Where(s => idTranPBo.Contains(s.TransferGift.Id)).GroupBy(g => new { g.GiftId, g.ReceivingDepartment, productId }).Select(s => new
                    {
                        s.Key.GiftId,
                        DepartmentId = s.Key.ReceivingDepartment,
                        Total        = s.Sum(t => t.Amount)
                    }).ToList();
                    #endregion

                    //So luong ton kho
                    var groupByStores = stores.GroupBy(g => new { g.GiftId, g.DepartmentId }).Select(s => new { s.Key.GiftId, s.Key.DepartmentId, Total = s.Sum(t => t.Amount), }).ToList();
                    var lstOrgan      = ss.Query <Organization>().ToList();
                    groupByStores.ForEach(store =>
                    {
                        var amountTotal       = gbNKDetails.Where(w => w.GiftId == store.GiftId && w.DepartmentId == store.DepartmentId).Sum(s => s.Total);
                        var amountAttribution = gbPBoDetails.Where(w => w.GiftId == store.GiftId && w.DepartmentId == store.DepartmentId).Sum(s => s.Total);
                        //gbDCNDetails.Where(w => w.GiftId == store.GiftId && w.DepartmentId == store.DepartmentId).Sum(s => s.Total)
                        //+ gbDCNBDetails.Where(w => w.GiftId == store.GiftId && w.DepartmentId == store.DepartmentId).Sum(s => s.Total);
                        var depCode  = ContextProvider.GetOrganizationCode(lstOrgan, store.DepartmentId);
                        var saveItem = new StoreDTO
                        {
                            GiftId            = store.GiftId,
                            GiftName          = ContextProvider.GiftName(gifts, store.GiftId),
                            GiftCode          = ContextProvider.GiftCode(gifts, store.GiftId),
                            Price             = (ContextProvider.GiftPrice(gifts, store.GiftId) * store.Total).ToString("N", CultureInfo.CurrentCulture),
                            DepartmentId      = store.DepartmentId,
                            DepartmentName    = ContextProvider.GetOrganizationName(lstOrgan, store.DepartmentId),
                            AmountInventory   = store.Total,//amountTotal - amountAttribution,
                            AmountUse         = depCode == "QLBH" ? 0 : amountAttribution - amountTotal,
                            AmountAttribution = depCode == "QLBH" ? 0 : amountAttribution
                        };
                        if (!string.IsNullOrEmpty(saveItem.GiftCode))
                        {
                            result.Add(saveItem);
                        }
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            });
            return(result);
        }
Пример #3
0
        public dynamic Check(string accNo, string json, string phanhe, ClaimsPrincipal principal)
        {
            dynamic result = new ExpandoObject();

            try
            {
                var lstPromotion = new List <PromotionOut>();
                var lstCusGift   = new List <CustomerGift>();
                var cusGift      = new CustomerGift();

                var userinfo = ContextProvider.GetUserInfo(principal);

                var infoCusFromCoreBanking = ConvertJson(json);
                //var infoCusFromCoreBanking = JsonConvert.DeserializeObject<CustomerDTO>(json);

                SessionManager.DoWork(ss =>
                {
                    var lstUser      = ss.Query <User>().ToList();
                    var now          = DateTime.Now;
                    var timeNow      = DateTime.ParseExact(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0).ToString("yyyy-MM-dd hh:mm:ss tt"), "yyyy-MM-dd hh:mm:ss tt", CultureInfo.InvariantCulture);
                    var idPromotions = ss.Query <Store>().Where(s => s.DepartmentId == userinfo.Organization.Id && s.Amount > 0).Select(s => s.PromotionId).ToList();
                    if (idPromotions.Count == 0)
                    {
                        result.MesError = "Hiện không triển khai chương trình khuyến mãi nào.";
                    }
                    var promotions = ss.Query <Promotion>().Where(s =>
                                                                  s.StartDate <= timeNow &&
                                                                  s.FinishDate >= timeNow &&
                                                                  s.Status == 2).ToList();
                    if (promotions.Count == 0)
                    {
                        result.MesError = "Hiện không triển khai chương trình khuyến mãi nào.";
                    }
                    else
                    {
                        var status = false;
                        foreach (var itm in promotions)
                        {
                            var quaTangKH       = new QuaTangKH();
                            var promotionIdUsed = new Guid();

                            cusGift = ss.Query <CustomerGift>().SingleOrDefault(s => s.Acctno == accNo && s.Promotion.Id == itm.Id && s.PhanHe == phanhe);
                            if (cusGift != null)
                            {
                                status = true;
                                lstCusGift.Add(cusGift);

                                var gifts       = ss.Query <Gift>().Where(s => s.Id == cusGift.Gift.Id).ToList();
                                promotionIdUsed = cusGift.Promotion.Id;

                                quaTangKH.GiftId   = cusGift.Gift.Id.ToString();
                                quaTangKH.GiftName = ContextProvider.GiftName(gifts, cusGift.Gift.Id);
                                quaTangKH.Num      = cusGift.NumGift;

                                var lstQuaTangKH = new List <QuaTangKH>();
                                lstQuaTangKH.Add(quaTangKH);

                                var promotionOut = new PromotionOut
                                {
                                    Id          = promotionIdUsed.ToString(),
                                    Code        = ContextProvider.GetPromotionCode(promotions, promotionIdUsed),
                                    Name        = ContextProvider.GetPromotionName(promotions, promotionIdUsed),
                                    label       = ContextProvider.GetPromotionCode(promotions, promotionIdUsed),
                                    value       = promotionIdUsed.ToString(),
                                    FlagTangQua = cusGift.Status,
                                    QuaTangKH   = lstQuaTangKH
                                };
                                lstPromotion.Add(promotionOut);
                            }
                            if (idPromotions.Any(a => a == itm.Id))
                            {
                                var idGP    = promotions.Select(s => s.GiftPromotionId).ToList();
                                var giftIds = ss.Query <GiftPromotion>().Where(s => idGP.Contains(s.GiftPromotionId)).Select(s => s.GiftId).ToList();
                                var gift    = ss.Query <Gift>().Where(s => giftIds.Contains(s.Id)).ToList();
                                if (promotionIdUsed.ToString() != Constants.GUIDE_TYPE_NULL)
                                {
                                    if (itm.Id != promotionIdUsed)
                                    {
                                        var lstQuaTangKH = new List <QuaTangKH>();

                                        if (infoCusFromCoreBanking.FRDATE >= itm.StartDate && infoCusFromCoreBanking.FRDATE <= itm.FinishDate)
                                        {
                                            var configPromotion = JsonConvert.DeserializeObject <List <ConfigPromotion> >(itm.ConfigPromotion.ToString());
                                            foreach (var itmConfigPromotion in configPromotion)
                                            {
                                                if (string.IsNullOrEmpty(phanhe))
                                                {
                                                    phanhe = "DEFAULT";
                                                }
                                                if (infoCusFromCoreBanking.TERM >= decimal.Parse(itmConfigPromotion.kyhantoithieu) &&
                                                    infoCusFromCoreBanking.BALANCE >= decimal.Parse(itmConfigPromotion.sodutoithieu) &&
                                                    itmConfigPromotion.phanhe.ToUpper() == phanhe.ToUpper())
                                                {
                                                    infoCusFromCoreBanking.PhanHe = phanhe.ToUpper();

                                                    var dataGift = itmConfigPromotion.dataKhaiBaoQuaTang;
                                                    if (dataGift == null)
                                                    {
                                                        result.MesError = "Chưa thiết lập nguyên tắc tặng quà.";
                                                    }
                                                    else
                                                    {
                                                        lstQuaTangKH = CreateLstGift(dataGift, gift, infoCusFromCoreBanking);
                                                    }
                                                }
                                            }
                                        }
                                        if (lstQuaTangKH.Count > 0)
                                        {
                                            lstPromotion.Add(CreateCardPromotion(itm, lstQuaTangKH));
                                        }
                                    }
                                }

                                else
                                {
                                    var lstQuaTangKH = new List <QuaTangKH>();

                                    if (infoCusFromCoreBanking.FRDATE >= itm.StartDate && infoCusFromCoreBanking.FRDATE <= itm.FinishDate)
                                    {
                                        var configPromotion = JsonConvert.DeserializeObject <List <ConfigPromotion> >(itm.ConfigPromotion.ToString());
                                        foreach (var itmConfigPromotion in configPromotion)
                                        {
                                            if (string.IsNullOrEmpty(phanhe))
                                            {
                                                phanhe = "DEFAULT";
                                            }
                                            if (infoCusFromCoreBanking.TERM >= decimal.Parse(itmConfigPromotion.kyhantoithieu) &&
                                                infoCusFromCoreBanking.BALANCE >= decimal.Parse(itmConfigPromotion.sodutoithieu) &&
                                                itmConfigPromotion.phanhe.ToUpper() == phanhe.ToUpper())
                                            {
                                                infoCusFromCoreBanking.PhanHe = phanhe.ToUpper();

                                                var dataGift = itmConfigPromotion.dataKhaiBaoQuaTang;
                                                if (dataGift == null)
                                                {
                                                    result.MesError = "Chưa thiết lập nguyên tắc tặng quà.";
                                                }

                                                else
                                                {
                                                    lstQuaTangKH = CreateLstGift(dataGift, gift, infoCusFromCoreBanking);
                                                }
                                            }
                                        }
                                    }
                                    if (lstQuaTangKH.Count > 0)
                                    {
                                        lstPromotion.Add(CreateCardPromotion(itm, lstQuaTangKH));
                                    }
                                }
                            }
                        }

                        if (lstCusGift.Count == 0)
                        {
                            lstCusGift.Add(infoCusFromCoreBanking);
                        }

                        result.InfoCus = LstCustomer(lstCusGift, phanhe, lstUser);

                        result.LstPromotion = lstPromotion.ToList().OrderByDescending(o => o.CountPrice).ToList();
                        result.Status       = status;
                    }
                });
            }
            catch (Exception ex)
            {
                throw;
            }
            return(result);
        }