Ejemplo n.º 1
0
 /// <summary>
 /// Retrieves the payment plan on record for the specified candidate and election cycle.
 /// </summary>
 /// <param name="candidateID">The ID of the candidate whose statement reviews are to be retrieved.</param>
 /// <param name="electionCycle">The election cycle in which to search.</param>
 public PaymentPlan GetPaymentPlan(string candidateID, string electionCycle)
 {
     using (PaymentPlanTds ds = new PaymentPlanTds())
     {
         using (PaymentPlanTableAdapter ta = new PaymentPlanTableAdapter())
         {
             ta.Fill(ds.PaymentPlan, candidateID, electionCycle);
         }
         PaymentPlan plan;
         foreach (PaymentPlanTds.PaymentPlanRow row in ds.PaymentPlan.Rows)
         {
             // payment schedule
             using (PaymentScheduleTableAdapter ta = new PaymentScheduleTableAdapter())
             {
                 ta.Fill(ds.PaymentSchedule, candidateID, electionCycle);
             }
             // payment history
             using (PlanPaymentsTableAdapter ta = new PlanPaymentsTableAdapter())
             {
                 ta.Fill(ds.PlanPayments, candidateID, electionCycle);
             }
             plan = new PaymentPlan()
             {
                 // basic plan info
                 FirstPaymentDate    = row.FirstPaymentDate,
                 Total               = Convert.ToUInt32(row.TotalAmount),
                 PaymentCount        = Convert.ToUInt16(row.Installments),
                 Period              = CPConvert.ToPaymentPeriod(row.PeriodTypeCode.Trim()),
                 PeriodPaymentAmount = Convert.ToUInt32(row.PeriodPaymentAmount),
                 GracePeriod         = Convert.ToByte(row.GracePeriod),
                 // payment schedule
                 Schedule = ParsePaymentSchedule(ds),
                 // payment history
                 History = ParsePlanPaymentHistory(ds)
             };
             // balances
             plan.ComputeBalances();
             // summaries
             plan.Summarize();
             return(plan);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves a history of public funds determinations for a specific candidate and election cycle.
        /// </summary>
        /// <param name="candidateID">The ID of the candidate whose public funds determination history is to be retrieved.</param>
        /// <param name="electionCycle">The election cycle in which to search.</param>
        /// <returns>A history of public funds determinations for the specified candidate and election cycle.</returns>
        public PublicFundsHistory GetPublicFundsHistory(string candidateID, string electionCycle)
        {
            // retrieve CMO message IDs
            using (Data.CmoEntities context = new Data.CmoEntities())
            {
                var messages = from m in context.CmoMessages
                               join p in context.CmoAuditReviews
                               on new { m.CandidateId, m.MessageId } equals new { p.CandidateId, p.MessageId }
                where m.CandidateId == candidateID && m.ElectionCycle == electionCycle && m.PostDate.HasValue
                group p by p.ReviewNumber into pgroup
                select new { Run = pgroup.Key, MessageID = pgroup.Max(p => p.MessageId) };

                // retrieve payment records
                using (PaymentPlanTds ds = new PaymentPlanTds())
                {
                    PaymentPlanTds.PublicFundsHistoryDataTable table = ds.PublicFundsHistory;
                    using (PublicFundsHistoryTableAdapter ta = new PublicFundsHistoryTableAdapter())
                    {
                        ta.Fill(table, candidateID, electionCycle);
                    }
                    PublicFundsHistory history = new PublicFundsHistory(table.Count);
                    foreach (PaymentPlanTds.PublicFundsHistoryRow row in table)
                    {
                        PublicFundsDetermination payment = new PublicFundsDetermination(row.Date, row.Amount > 0)
                        {
                            ElectionType  = CPConvert.ToElectionType(row.ElectionTypeCode.Trim()),
                            PaymentAmount = row.Amount,
                            PaymentMethod = string.IsNullOrEmpty(row.CheckNumber.Trim()) ? PaymentMethod.Eft : PaymentMethod.Check,
                            Run           = row.Run
                        };
                        // associate message ID if found
                        var message = messages.FirstOrDefault(m => m.Run == row.Run);
                        if (message != null)
                        {
                            payment.MessageID = message.MessageID;
                        }
                        history.Determinations.Add(payment);
                    }
                    return(history);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses a typed data set of plan payments into a <see cref="PlanPaymentHistory"/> collection.
        /// </summary>
        /// <param name="ds">The typed data set to parse.</param>
        /// <returns>A collection representing the data contained in the data set.</returns>
        private PlanPaymentHistory ParsePlanPaymentHistory(PaymentPlanTds ds)
        {
            PlanPaymentHistory history = new PlanPaymentHistory(ds.PlanPayments.Count);

            foreach (PaymentPlanTds.PlanPaymentsRow row in ds.PlanPayments.Rows)
            {
                ushort checkNumber;
                if (ushort.TryParse(row.CheckNumber, out checkNumber))
                {
                    history.Add(new PlanPayment()
                    {
                        Amount      = Convert.ToUInt32(row.Amount),
                        CheckNumber = checkNumber,
                        Date        = row.Date,
                        Type        = CPConvert.ToPaymentType(row.TransactionCode.Trim())
                    });
                }
            }
            return(history);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses a typed data set of payment installments into a <see cref="PaymentSchedule"/> collection.
        /// </summary>
        /// <param name="ds">The typed data set to parse.</param>
        /// <returns>A collection representing the data contained in the data set.</returns>
        private PaymentSchedule ParsePaymentSchedule(PaymentPlanTds ds)
        {
            PaymentSchedule schedule = new PaymentSchedule(ds.PaymentSchedule.Count);

            foreach (PaymentPlanTds.PaymentScheduleRow row in ds.PaymentSchedule.Rows)
            {
                schedule.Add(new PaymentInstallment(Convert.ToUInt16(row.Number))
                {
                    AmountDue  = Convert.ToUInt32(row.Amount),
                    DueDate    = row.DueDate.Date,
                    AmountPaid = null,
                });
            }
            // TODO: what the heck is up with start date?
            DateTime startDate = DateTime.MinValue.Date;

            foreach (PaymentInstallment installment in schedule.Values)
            {
                installment.StartDate = startDate;
                startDate             = installment.DueDate.AddDays(1);
            }
            return(schedule);
        }