Пример #1
0
        private Amount getLevel1Rate(LevelRelation relation)
        {
            Amount result = Level1 == null ? null : Level1.GetRate(relation);

            if (result == null)
            {
                return(getLevel0Rate(relation));
            }
            return(result);
        }
Пример #2
0
        public Amount GetPointRate(string level, LevelRelation relation)
        {
            Amount rate = GetRate(level, relation);

            if (rate == null)
            {
                return(new Amount(RateType, 0));
            }

            rate = ApplyAdditionRule(level, relation, rate);
            return(rate);
        }
Пример #3
0
        private Amount GetRate(string level, LevelRelation relation)
        {
            if ("Level0".Equals(level, StringComparison.InvariantCultureIgnoreCase))
            {
                return(getLevel0Rate(relation));
            }
            else if ("Level1".Equals(level, StringComparison.InvariantCultureIgnoreCase))
            {
                return(getLevel1Rate(relation));
            }

            return(null);
        }
Пример #4
0
 public Amount GetRate(LevelRelation relation)
 {
     switch (relation) {
         case LevelRelation.Self:
             return SelfRate;
         case LevelRelation.Son:
             return SonRate;
         case LevelRelation.Grandson:
             return GrandsonRate;
         default:
             return null;
     }
 }
Пример #5
0
        private Amount GetRate(string level, LevelRelation relation)
        {
            if (isLevel0(level))
            {
                return(getLevel0Rate(relation));
            }
            else if (isLevel1(level))
            {
                return(getLevel1Rate(relation));
            }

            return(null);
        }
Пример #6
0
        private Amount ApplyAdditionRule(string level, LevelRelation relation, Amount rate)
        {
            if (LevelRelation.Self == relation && isLevel1(level))
            {
                int addR = 0;
                int.TryParse(level.Substring(6), out addR);
                if (addR > 8)
                {
                    addR = 8;
                }

                return(rate + new Amount(rate.Type, addR));
            }
            return(rate);
        }
Пример #7
0
        public Amount GetRate(LevelRelation relation)
        {
            switch (relation)
            {
            case LevelRelation.Self:
                return(SelfRate);

            case LevelRelation.Son:
                return(SonRate);

            case LevelRelation.Grandson:
                return(GrandsonRate);

            default:
                return(null);
            }
        }
Пример #8
0
        public decimal Calc(string level, LevelRelation relation, decimal qty)
        {
            Amount rate = GetRate(level, relation);

            if (rate == null)
            {
                return(0);
            }


            if ("%".Equals(rate.Type))
            {
                // rate = 20%
                // qty = 200
                // result = (200 * 20) / 100  = 40

                return((qty * rate.ValueOfNumber) / (new decimal(100)));
            }
            return(0);
        }
Пример #9
0
 private Amount getLevel0Rate(LevelRelation relation)
 {
     return(Level0 == null ? null : Level0.GetRate(relation));
 }
Пример #10
0
        private Amount GetRate(string level, LevelRelation relation)
        {
            if ("Level0".Equals(level, StringComparison.InvariantCultureIgnoreCase))
            {
                return getLevel0Rate(relation);
            }
            else if ("Level1".Equals(level, StringComparison.InvariantCultureIgnoreCase))
            {
                return getLevel1Rate(relation);
            }

            return null;
        }
Пример #11
0
 private Amount getLevel1Rate(LevelRelation relation)
 {
     Amount result = Level1 == null ? null : Level1.GetRate(relation);
     if (result == null) {
         return getLevel0Rate(relation);
     }
     return result;
 }
Пример #12
0
 private Amount getLevel0Rate(LevelRelation relation)
 {
     return Level0 == null ? null : Level0.GetRate(relation);
 }
Пример #13
0
        public decimal Calc(string level, LevelRelation relation, decimal qty)
        {
            Amount rate = GetRate(level, relation);
            if (rate == null)
            {
                return 0;
            }

            if ("%".Equals(rate.Type))
            {
                // rate = 20%
                // qty = 200
                // result = (200 * 20) / 100  = 40

                return (qty * rate.ValueOfNumber) / (new decimal(100));
            }
            return 0;
        }
Пример #14
0
        private async Task<decimal> AddOneMemberPoint(SaleToCustomerDetail saleToCustomerDetail,  MemberPointRule pointRule, 
            string customerID, string customerLevel, LevelRelation relation)
        {
            if (string.IsNullOrWhiteSpace(customerID) == false && string.IsNullOrWhiteSpace(customerLevel) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner = this.AppDbContext.FindOrAttachToLocal(customerID);
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity = pointRule.Calc(customerLevel, relation, saleToCustomerDetail.Price - saleToCustomerDetail.CashCoupon);
                menberPoint.ID = IDGenerator.GetMemberPointIDGenerator(this.AppDbContext).GetNext();

                await CalcCurrentTotal(menberPoint);

                this.AppDbContext.MemberPoint.Add(menberPoint);
                return menberPoint.Quantity;
            }
            return 0;
        }
Пример #15
0
        private async Task <decimal> AddOneMemberPoint(SaleToCustomerDetail saleToCustomerDetail, MemberPointRule pointRule,
                                                       string customerID, string customerLevel, LevelRelation relation)
        {
            if (string.IsNullOrWhiteSpace(customerID) == false && string.IsNullOrWhiteSpace(customerLevel) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner       = this.AppDbContext.FindOrAttachToLocal(customerID);
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity    = pointRule.Calc(customerLevel, relation, saleToCustomerDetail.Price - saleToCustomerDetail.CashCoupon);
                menberPoint.ID          = IDGenerator.GetMemberPointIDGenerator(this.AppDbContext).GetNext();

                await CalcCurrentTotal(menberPoint);

                this.AppDbContext.MemberPoint.Add(menberPoint);
                return(menberPoint.Quantity);
            }
            return(0);
        }