예제 #1
0
        public virtual void Update(CustomerGift entity)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("Gift_Update");

            cmd.SetParameterValue <CustomerGift>(entity);
            cmd.ExecuteNonQuery();
        }
예제 #2
0
        public virtual int UpdateStatus(CustomerGift entity)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("Gift_UpdateStatus");

            cmd.SetParameterValue("@SysNo", entity.SysNo);
            cmd.SetParameterValue("@Status", (int)entity.Status);
            return(cmd.ExecuteNonQuery());
        }
예제 #3
0
        public virtual CustomerGift Insert(CustomerGift entity)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("Gift_Insert");

            cmd.SetParameterValue <CustomerGift>(entity);
            cmd.ExecuteNonQuery();
            entity.SysNo = Convert.ToInt32(cmd.GetParameterValue("@SysNo"));
            return(entity);
        }
예제 #4
0
        /// <summary>
        /// 领取奖品
        /// </summary>
        /// <param name="customerSysNo"></param>
        /// <param name="productSysNo"></param>
        /// <param name="soSysNo"></param>
        public virtual void GetGift(int customerSysNo, int productSysNo, int soSysNo)
        {
            CustomerGift entity = _giftDA.Load(customerSysNo, productSysNo, CustomerGiftStatus.Origin);

            if (entity == null)
            {
                throw new BizException(GetString("GiftCantGet"));
            }
            entity.Status  = CustomerGiftStatus.Assigned;
            entity.SOSysNo = soSysNo;
            _giftDA.Update(entity);
        }
예제 #5
0
 private void SaveCustomerGiftLog(ISession s, Stage st, CustomerGift c, UserDTO u)
 {
     s.Save(new CustomerGiftLog
     {
         Id = new Guid(),
         //CustomerGift = c,
         CustomerGiftId     = c.ParentId,
         AssignUserId       = u.Id,
         AssignDeaprtmentId = u.Organization.Id,
         Status             = c.Status,
         UpdateDate         = DateTime.ParseExact(DateTime.Now.ToString("u"), "u", CultureInfo.InvariantCulture),
         StageId            = st.Id,
         Comment            = "",
     });
 }
예제 #6
0
        public string TangQuaKhachHangQuyDoi(CustomerDTO obj, string promotionId, ClaimsPrincipal principal)
        {
            var result       = string.Empty;
            var _promotionId = new Guid(promotionId);

            try
            {
                var userinfo = ContextProvider.GetUserInfo(principal);
                SessionManager.DoWork(ss =>
                {
                    var lst       = obj.QuaTangKH.ToList();
                    var idGifts   = lst.Select(s => Guid.Parse(s.GiftId)).ToList();
                    var gifts     = ss.Query <Gift>().Where(s => idGifts.Contains(s.Id)).ToList();
                    var promotion = ss.Query <Promotion>().SingleOrDefault(s => s.Id == _promotionId);

                    if (CheckMaxGiftInDay(_promotionId, promotion.MaxGiftInDay))
                    {
                        var parentId = Guid.NewGuid();
                        lst.ForEach(itm =>
                        {
                            if (CheckMaxGiftWithCustomer(promotion.MaxGiftWithCustomer, _promotionId, obj.Acctno, itm.NumEdit))
                            {
                                var store = ss.Query <Store>().FirstOrDefault(s => s.DepartmentId == userinfo.OrganizationId && s.PromotionId == _promotionId && s.GiftId == Guid.Parse(itm.GiftId));
                                if (store != null && store.Amount >= itm.NumEdit)
                                {
                                    var _productId = new Guid(Constants.ID_PRODUCT_TANG_QUA_KHACH_HANG);
                                    var product    = ss.Get <Product>(_productId);
                                    var stage      = ss.Query <Stage>().SingleOrDefault(p => p.ProductId == product.Id && p.PositionId == userinfo.Position.Id && p.Name == Constants.GUI_DUYET);
                                    if (stage != null)
                                    {
                                        itm.Error = Constants.GUI_DUYET_THANH_CONG;
                                    }
                                    else
                                    {
                                        itm.Error = "Chức năng này chỉ dành cho GDV";
                                    }
                                }
                                else
                                {
                                    itm.Error = "Số lượng quà trong kho không đủ, xin hãy kiểm tra lại";
                                }
                            }
                            else
                            {
                                itm.Error = "Mỗi khách hàng không được nhận quá số lượng: " + promotion.MaxGiftWithCustomer;
                            }
                        });
                        if (lst.Any(a => a.Error != Constants.GUI_DUYET_THANH_CONG))
                        {
                            result = lst.FirstOrDefault(f => f.Error != Constants.GUI_DUYET_THANH_CONG).Error;
                        }
                        else
                        {
                            lst.ForEach(itm =>
                            {
                                var newCus         = new CustomerGift();
                                newCus.Id          = new Guid();
                                newCus.USERID      = userinfo.Id;
                                newCus.Gift        = gifts.FirstOrDefault(f => f.Id == Guid.Parse(itm.GiftId));
                                newCus.Status      = (int)ContextProvider.statusTransfer.Initialize;
                                newCus.Promotion   = promotion;
                                newCus.CREATEDBy   = userinfo.Id;
                                newCus.CREATEDDATE = DateTime.ParseExact(DateTime.Now.ToString("u"), "u", CultureInfo.InvariantCulture);
                                newCus.NumGift     = itm.NumEdit;
                                newCus.PhanHe      = obj.PhanHe;
                                newCus.Acctno      = obj.Acctno;
                                newCus.TENLOAIHINH = obj.TENLOAIHINH;
                                newCus.CusName     = obj.CusName;
                                newCus.CusId       = obj.CusId;
                                newCus.TERM        = obj.TERM;
                                newCus.TERMCD      = obj.TERMCD;
                                newCus.BALANCE     = obj.BALANCE;
                                newCus.FRDATE      = obj.FRDATE;
                                newCus.TODATE      = obj.TODATE;
                                newCus.CHEQUENO    = obj.CHEQUENO;
                                newCus.INTRATE     = obj.INTRATE;
                                newCus.RATECD      = obj.RATECD;
                                newCus.LICENSE     = obj.LICENSE;
                                newCus.SUBBRID     = obj.SUBBRID;
                                newCus.SUBBRNAME   = obj.SUBBRNAME;
                                newCus.BRANCHID    = obj.BRANCHID;
                                newCus.BRNAME      = obj.BRNAME;
                                newCus.ACTYPE      = obj.ACTYPE;
                                newCus.CCYCD       = obj.CCYCD;
                                newCus.ParentId    = parentId;
                                ss.Save(newCus);
                            });
                            var _productId = new Guid(Constants.ID_PRODUCT_TANG_QUA_KHACH_HANG);
                            var product    = ss.Get <Product>(_productId);
                            var stage      = ss.Query <Stage>().SingleOrDefault(p => p.ProductId == product.Id && p.PositionId == userinfo.Position.Id && p.Name == Constants.GUI_DUYET);
                            if (stage != null)
                            {
                                ss.Save(new CustomerGiftLog
                                {
                                    Id = new Guid(),
                                    //CustomerGift = newCus,
                                    CustomerGiftId     = parentId,
                                    AssignUserId       = userinfo.Id,
                                    AssignDeaprtmentId = userinfo.Organization.Id,
                                    Comment            = "",
                                    Status             = (int)ContextProvider.statusTransfer.Initialize,
                                    UpdateDate         = DateTime.ParseExact(DateTime.Now.ToString("u"), "u", CultureInfo.InvariantCulture),
                                    StageId            = stage.Id
                                });
                            }
                            result = Constants.GUI_DUYET_THANH_CONG;
                        }
                    }
                    else
                    {
                        result = "Mỗi ngày không được tặng quá " + promotion.MaxGiftInDay + " quà tặng";
                    }
                });

                return(result);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
예제 #7
0
        private List <QuaTangKH> CreateLstGift(List <DataKhaiBaoQuaTang> dataGift, List <Gift> gifts, CustomerGift infoCusFromCoreBanking)
        {
            var lstQuaTangKH = new List <QuaTangKH>();

            foreach (var itmGift in dataGift)
            {
                var minsotien = decimal.Parse(itmGift.minsotien);
                var minkyhan  = decimal.Parse(itmGift.minkyhan);
                var maxsotien = decimal.Parse(itmGift.maxsotien);
                var maxkyhan  = decimal.Parse(itmGift.maxkyhan);

                if (infoCusFromCoreBanking.BALANCE >= minsotien && infoCusFromCoreBanking.TERM >= minkyhan)
                {
                    var newGift = NewGift(itmGift);
                    var gift    = gifts.FirstOrDefault(f => f.Id == Guid.Parse(newGift.GiftId));
                    newGift.UnitName   = gift.Unit.Name;
                    newGift.GiftCode   = gift.Code;
                    newGift.Price      = gift.Price;
                    newGift.TotalPrice = gift.Price * newGift.Num;
                    if (maxsotien == 0 && maxkyhan == 0)
                    {
                        lstQuaTangKH.Add(newGift);
                    }

                    else if (maxsotien != 0 && maxkyhan == 0)
                    {
                        if (infoCusFromCoreBanking.BALANCE <= maxsotien)
                        {
                            lstQuaTangKH.Add(newGift);
                        }
                    }
                    else if (maxsotien == 0 && maxkyhan != 0)
                    {
                        if (infoCusFromCoreBanking.TERM <= maxkyhan)
                        {
                            lstQuaTangKH.Add(newGift);
                        }
                    }
                    else
                    {
                        if (infoCusFromCoreBanking.BALANCE <= maxsotien && infoCusFromCoreBanking.TERM <= maxkyhan)
                        {
                            lstQuaTangKH.Add(newGift);
                        }
                    }
                }
            }
            return(lstQuaTangKH);
        }
예제 #8
0
 private void UpdateCustomerGift(CustomerGift c, UserDTO u, int status)
 {
     c.Status     = status;
     c.NguoiDuyet = u.Id;
     c.NgayDuyet  = DateTime.ParseExact(DateTime.Now.ToString("u"), "u", CultureInfo.InvariantCulture);
 }
예제 #9
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);
        }