예제 #1
0
        }         // BuildWorkingSet

        public void Calculate()
        {
            if (!IsCountable)
            {
                return;
            }

            if (Transactions.Count < 1)
            {
                return;
            }

            if (ProcessedTransactionCount < Transactions.Count)
            {
                Schedule oSh = Actual.FirstOrDefault(sh => !sh.IsAlreadyProcessed) ?? Actual.First();

                foreach (Transaction trn in Transactions)
                {
                    if (trn.IsAlreadyProcessed)
                    {
                        continue;
                    }

                    ScheduleTransactions.Add(new ScheduleTransaction {
                        FeesDelta      = -trn.Fees,
                        InterestDelta  = -trn.Interest,
                        PrincipalDelta = -trn.Principal,
                        Schedule       = oSh,
                        Status         = LoanScheduleStatus.Late,
                        Transaction    = trn
                    });
                }                 // for each transaction

                return;
            }             // if

            if (WorkingSet.Count < 1)
            {
                return;
            }

            Transaction[] aryTransactions = Transactions.ToArray();
            Schedule[]    aryWorkingSet   = WorkingSet.ToArray();
            int           nCurSchedule    = 0;
            int           nCurTransaction = 0;

            Transaction oCurTrn = null;
            Schedule    oCurSch = null;

            for ( ; ;)
            {
                if (oCurTrn == null)
                {
                    oCurTrn = new Transaction(aryTransactions[nCurTransaction]);
                }

                if (oCurSch == null)
                {
                    oCurSch = new Schedule(aryWorkingSet[nCurSchedule]);
                }

                if ((oCurSch.Principal == 0) && (oCurTrn.Principal == 0))
                {
                    ScheduleTransactions.Add(new ScheduleTransaction {
                        FeesDelta      = -oCurTrn.Fees,
                        InterestDelta  = -oCurTrn.Interest,
                        PrincipalDelta = 0,
                        Schedule       = oCurSch,
                        Status         = GetStatus(oCurSch, oCurTrn),
                        Transaction    = oCurTrn
                    });

                    if ((nCurSchedule == aryWorkingSet.Length - 1) || (nCurTransaction == aryTransactions.Length - 1))
                    {
                        break;
                    }

                    oCurSch = null;
                    oCurTrn = null;

                    nCurSchedule++;
                    nCurTransaction++;

                    continue;
                }                 // if both zeros

                if (oCurSch.Principal < oCurTrn.Principal)
                {
                    ScheduleTransactions.Add(new ScheduleTransaction {
                        FeesDelta      = -oCurTrn.Fees,
                        InterestDelta  = -oCurTrn.Interest,
                        PrincipalDelta = -oCurSch.Principal,
                        Schedule       = oCurSch,
                        Status         = GetStatus(oCurSch, oCurTrn),
                        Transaction    = oCurTrn
                    });

                    oCurTrn.Principal -= oCurSch.Principal;

                    if (nCurSchedule == aryWorkingSet.Length - 1)
                    {
                        break;
                    }

                    oCurSch = null;

                    nCurSchedule++;

                    continue;
                }                 // if schedule less than transaction

                if (oCurSch.Principal == oCurTrn.Principal)
                {
                    ScheduleTransactions.Add(new ScheduleTransaction {
                        FeesDelta      = -oCurTrn.Fees,
                        InterestDelta  = -oCurTrn.Interest,
                        PrincipalDelta = -oCurSch.Principal,
                        Schedule       = oCurSch,
                        Status         = GetStatus(oCurSch, oCurTrn),
                        Transaction    = oCurTrn
                    });

                    if ((nCurSchedule == aryWorkingSet.Length - 1) || (nCurTransaction == aryTransactions.Length - 1))
                    {
                        break;
                    }

                    oCurSch = null;
                    oCurTrn = null;

                    nCurSchedule++;
                    nCurTransaction++;

                    continue;
                }                 // if schedule equal to transaction

                // if (oCurSch.Principal > oCurTrn.Principal) {

                ScheduleTransactions.Add(new ScheduleTransaction {
                    FeesDelta      = -oCurTrn.Fees,
                    InterestDelta  = -oCurTrn.Interest,
                    PrincipalDelta = -oCurTrn.Principal,
                    Schedule       = oCurSch,
                    Status         = GetStatus(oCurSch, oCurTrn),
                    Transaction    = oCurTrn
                });

                oCurSch.Principal -= oCurTrn.Principal;

                if (nCurTransaction == aryTransactions.Length - 1)
                {
                    break;
                }

                oCurTrn = null;

                nCurTransaction++;

                // } // if schedule greater than transaction
            }     // for each transaction
        }         // Calculate