コード例 #1
0
ファイル: MembershipPackage.cs プロジェクト: rahodges/Tessen
        /// <summary>
        /// Builds the memberships for the current member. If the member has
        /// submembers associated, these submemberships will be added to the
        /// member's memberships listing and associated to the submembers.
        ///
        /// Members are responsible for their submember's fees, but not any
        /// members beneath the submembers.
        /// </summary>
        /// <param name="member"></param>
        /// <param name="typeTemplate"></param>
        /// <param name="builder"></param>
        public void Build(
            DojoMember member,
            DojoMemberTypeTemplate typeTemplate,
            MembershipBuilder builder)
        {
            DojoMembershipTemplateCollection membershipTemplates;

            // Builds new memberships for the member.

            // * Pull old memberships associated with the member.
            // * Build the next membership based of the template.
            // * Add membership.

            Clear();

            this.member       = member;
            this.typeTemplate = typeTemplate;
            this.memberships  = new DojoMembershipCollection();

            if (typeTemplate != null)
            {
                membershipTemplates = builder.getMembershipTemplates(member, typeTemplate);

                if (membershipTemplates != null)
                {
                    foreach (DojoMembershipTemplate template in membershipTemplates)
                    {
                        addTemplate(member, template, builder);
                    }
                }

                // WALK TEMPLATE TREE AND SUB MEMBERS LOCK STEP AND ADD EACH
                // SUBMEMBER'S MEMBERSHIPS TO THE CURRENT PACKAGE.
                builder.pullData(member);
                if (member.subMembers != null)
                {
                    if (typeTemplate.subTemplates != null)
                    {
                        for (int i = 0; i < typeTemplate.subTemplates.Count; i++)
                        {
                            // This is for safety although the builder should only return
                            // members that have submembers that equal the type template's sub templates
                            if (i < member.subMembers.Count)
                            {
                                membershipTemplates =
                                    builder.getMembershipTemplates(member.subMembers[i],
                                                                   typeTemplate.subTemplates[i]);

                                foreach (DojoMembershipTemplate template in membershipTemplates)
                                {
                                    addTemplate(member.subMembers[i], template, builder);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: MembershipPackage.cs プロジェクト: rahodges/Tessen
        private void addTemplate(
            DojoMember member,
            DojoMembershipTemplate template,
            MembershipBuilder builder)
        {
            // Get Prior
            DojoMembership prior = getPrior(member, template);

            // If the prior membership has not yet ended and the prior membership's
            // end date preceeds the template's pre-purchase date, skip this template.
            if (prior != null)
            {
                if (prior.EndDate >= builder.BuildTime)
                {
                    if (prior.EndDate >= builder.BuildTime.Subtract(template.PrePurchaseTime))
                    {
                        return;
                    }
                }
            }

            // Since this membership is either a new, renewal or pre-purchased renewal,
            // add it to the membership list.
            DojoMembership membership = new DojoMembership();

            membership.Member               = member;
            membership.MembershipTemplate   = template;
            membership.PriorMembership      = prior;
            membership.Organization         = template.Organization;
            membership.OrganizationMemberID =
                prior != null ? prior.OrganizationMemberID : string.Empty;
            calcMembership(membership, builder);
            // calcMembership takes care of this!
            // membership.EndDate = calcDate(membership.startDate,
            //     template.MembershipEnd);
            // membership.Fee = template.Fee;

            memberships.Add(membership);

            totalFee += membership.Fee;
        }
コード例 #3
0
ファイル: MembershipPackage.cs プロジェクト: rahodges/Tessen
        /// <summary>
        /// Calculates a fee and end date for a membership based on the
        /// provided membership's start date. This will take into account the
        /// ProRate settings on the membership's parent template. ProRate
        /// settings can use either the day, the month or the month/day
        /// combination. This will NOT ProRate memberships that do not have
        /// a prior membership.
        ///
        /// This will add the startup fees for each member at the end.
        /// </summary>
        /// <param name="membership">The membership to calculate.</param>
        private void calcMembership(DojoMembership membership, MembershipBuilder builder)
        {
            DateTime               now      = builder.BuildTime;
            DojoMember             member   = membership.member;
            DojoMembershipTemplate template = membership.MembershipTemplate;

            if (membership.priorMembership == null)
            {
                membership.StartDate =
                    calcDate(now, template.MembershipStart);
            }
            else
            {
                membership.StartDate = DateManipulator.FirstOfNextDay(
                    membership.PriorMembership.EndDate);
            }

            membership.EndDate =
                calcDate(membership.StartDate,
                         template.MembershipEnd);
            membership.Fee = template.Fee;

            if (membership.PriorMembership == null)
            {
                // PRO RATE A ==================================
                if (template.ProRateMonthA > 0 &&
                    template.ProRateMonthA <= now.Month)
                {
                    if (template.ProRateDayA > 0)
                    {
                        if (template.ProRateDayA <= now.Day)
                        {
                            membership.EndDate =
                                calcDate(membership.StartDate,
                                         template.ProRateEndA);
                            membership.Fee =
                                template.ProRateFeeA;
                            membership.IsProRated = true;
                        }
                    }
                    else
                    {
                        membership.EndDate =
                            calcDate(membership.StartDate,
                                     template.ProRateEndA);
                        membership.Fee =
                            template.ProRateFeeA;
                        membership.IsProRated = true;
                    }

                    // PRO RATE B ==================================
                    if (template.ProRateMonthB > 0 &&
                        template.ProRateMonthB <= now.Month)
                    {
                        if (template.ProRateDayB > 0)
                        {
                            if (template.ProRateDayB <= now.Day)
                            {
                                membership.EndDate =
                                    calcDate(membership.StartDate,
                                             template.ProRateEndB);
                                membership.Fee =
                                    template.ProRateFeeB;
                                membership.IsProRated = true;
                            }
                        }
                        else
                        {
                            membership.EndDate =
                                calcDate(membership.StartDate,
                                         template.ProRateEndB);
                            membership.Fee =
                                template.ProRateFeeB;
                            membership.IsProRated = true;
                        }

                        // PRO RATE C ==================================
                        if (template.ProRateMonthC > 0 &&
                            template.ProRateMonthC <= now.Month)
                        {
                            if (template.ProRateDayC > 0)
                            {
                                if (template.ProRateDayC <= now.Day)
                                {
                                    membership.EndDate =
                                        calcDate(membership.StartDate,
                                                 template.ProRateEndC);
                                    membership.Fee =
                                        template.ProRateFeeC;
                                    membership.IsProRated = true;
                                }
                            }
                            else
                            {
                                membership.EndDate =
                                    calcDate(membership.StartDate,
                                             template.ProRateEndC);
                                membership.Fee =
                                    template.ProRateFeeC;
                                membership.IsProRated = true;
                            }
                        }
                        else if (template.ProRateDayC > 0 &&
                                 template.ProRateDayC <= now.Day)
                        {
                            membership.EndDate =
                                calcDate(membership.StartDate,
                                         template.ProRateEndC);
                            membership.Fee =
                                template.ProRateFeeC;
                            membership.IsProRated = true;
                        }
                    }
                    else if (template.ProRateDayB > 0 &&
                             template.ProRateDayB <= now.Day)
                    {
                        membership.EndDate =
                            calcDate(membership.StartDate,
                                     template.ProRateEndB);
                        membership.Fee =
                            template.ProRateFeeB;
                        membership.IsProRated = true;
                    }
                }
                else if (template.ProRateDayA > 0 &&
                         template.ProRateDayA <= now.Day)
                {
                    membership.EndDate =
                        calcDate(membership.StartDate,
                                 template.ProRateEndA);
                    membership.Fee =
                        template.ProRateFeeA;
                    membership.IsProRated = true;
                }
            }

            if (membership.PriorMembership == null)
            {
                membership.Fee += template.StartupFee;
            }
        }