Ejemplo n.º 1
0
 public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
 {
     //Nothing to modify
     pInstallment.PaidFees += pFeesEvent;
     pAmountPaid -= pFeesEvent;
     pFeesEvent = 0;
 }
Ejemplo n.º 2
0
 public void RepayCommission(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     if (!_pCCO.CancelFees)
         AutomaticRepayMethod(pInstallment, ref pAmountPaid, ref pCommisionEvent);
     else
         ManualRepayMethod(pInstallment, ref pAmountPaid, ref pCommisionEvent);
 }
Ejemplo n.º 3
0
 private static void ManualRepayMethod(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     pInstallment.PaidCommissions = pCommisionEvent;
     pAmountPaid -= pCommisionEvent;
     pCommisionEvent = 0;
     //Nothing to modify
 }
        public CalculateInstallmentsStrategy(CalculateInstallmentsOptions pCio, int pStartInstallment, OCurrency pStartAmount, int pNumberOfInstallments, ApplicationSettings pGeneralSettings)
        {
            _generalSettings = pGeneralSettings;
            OCurrency initialOLBOfContractBeforeRescheduling = Loan.InitialOlbOfContractBeforeRescheduling;

            if (pCio.IsExotic)
            {
                if (pCio.LoanType == OLoanTypes.Flat)
                    _iCi = new Flat.ExoticStrategy(pCio.StartDate, pCio.Contract, _generalSettings);
                else
                    _iCi = new Declining.ExoticStrategy(pCio.StartDate, pCio.Contract, _generalSettings);
            }
            else
            {
                if (pCio.LoanType == OLoanTypes.Flat)
                    _iCi = new FlatStrategy(pCio.StartDate, pCio.Contract, _generalSettings, initialOLBOfContractBeforeRescheduling);
                else if (pCio.LoanType == OLoanTypes.DecliningFixedInstallments)
                {
                    if (pCio.Contract.InterestRate == 0)
                        _iCi = new FlatStrategy(pCio.StartDate, pCio.Contract, _generalSettings, initialOLBOfContractBeforeRescheduling);
                    else
                        _iCi = new FixedInstallmentStrategy(pCio.StartDate, pCio.Contract, pStartInstallment, pStartAmount, pNumberOfInstallments, _generalSettings);
                }
                else
                {
                    if (pCio.Contract.InterestRate == 0)
                        _iCi = new FlatStrategy(pCio.StartDate, pCio.Contract, _generalSettings, initialOLBOfContractBeforeRescheduling);
                    else
                        _iCi = new FixedPrincipalStrategy(pCio.StartDate, pCio.Contract, _generalSettings);
                }
            }
        }
Ejemplo n.º 5
0
        public FlatStrategy(DateTime pStartDate, Loan pContract, ApplicationSettings pGeneralSettings, OCurrency pInitialOLBOfContractBeforeRescheduling)
        {
            RoundingPoint = pContract.UseCents ? 2 : 0;

            _initialOLBOfContractBeforeRescheduling = pInitialOLBOfContractBeforeRescheduling;
            _contract = pContract;
            GeneralSettings = pGeneralSettings;
        }
Ejemplo n.º 6
0
 public BookingToView(OBookingDirections pDirection, OCurrency pAmount, DateTime pDate, double? pExchangeRate, string pContractCode, string pEventCode)
 {
     Direction = pDirection;
     _amount = pAmount;
     Date = pDate;
     _exchangeRate = pExchangeRate;
     ContractCode = pContractCode;
     EventCode = pEventCode;
 }
Ejemplo n.º 7
0
 public Cycle(int id, int loanCycle,  OCurrency min, OCurrency max, int cycleObjectId, int cycleId)
 {
     Id = id;
        LoanCycle = loanCycle;
        Min = min;
        Max = max;
        CycleObjectId = cycleObjectId;
        CycleId = cycleId;
 }
        public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid == 0) return;
            for(int i = 0 ; i < _contract.NbOfInstallments ; i++)
            {
                Installment installment = _contract.GetInstallment(i);
                if (!installment.IsRepaid && amountPaid > 0)
                {
                    //commission
                    _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);
                    if (amountPaid == 0) break;

                    //penalty
                    _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);
                    if (amountPaid == 0) break;

                    //Interests
                    if (amountPaid == 0) return;
                    _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,ref interestPrepayment);

                    //principal
                    if (amountPaid == 0)
                    {
                        _paidInstallments.Add(installment);
                        return;
                    }

                    OCurrency principalHasToPay = installment.CapitalRepayment - installment.PaidCapital;

                    if (AmountComparer.Compare(amountPaid, principalHasToPay) < 0)
                    {
                        installment.PaidCapital += amountPaid;
                        installment.PaidCapital = Math.Round(installment.PaidCapital.Value, 2);
                        principalEvent += amountPaid;
                        amountPaid = 0;
                    }
                    else if (AmountComparer.Compare(amountPaid, principalHasToPay) > 0)
                    {
                        installment.PaidCapital = installment.CapitalRepayment;
                        amountPaid -= principalHasToPay;
                        principalEvent += principalHasToPay;
                    }
                    else
                    {
                        installment.PaidCapital += amountPaid;
                        installment.PaidCapital = Math.Round(installment.PaidCapital.Value, 2);
                        principalEvent += amountPaid;
                        amountPaid = 0;
                    }

                    _paidInstallments.Add(installment);
                }
            }
        }
Ejemplo n.º 9
0
 public Account(string accountNumber, string localAccountNumber, string label, OCurrency   balance, string typeCode, bool debitPlus, OAccountCategories category, int pCurrencyId)
 {
     _number = accountNumber;
     LocalNumber = localAccountNumber;
     _label = label;
     _balance = balance;
     TypeCode = typeCode;
     _debitPlus = debitPlus;
     AccountCategory = category;
     CurrencyId = pCurrencyId;
 }
        /// <summary>
        /// This method recalculates installments for a declining rate exotic loan in case of over payment.
        /// </summary>
        public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            OCurrency totalAmount = 0;
            bool firstInstallmentToRepay = false;
            double baseTocalculatePrincipalCoeff = 0;

            if(amountPaid > 0)
            {
                for (int i = 0; i < _contract.NbOfInstallments; i++)
                {
                    Installment installment = _contract.GetInstallment(i);
                    if (installment.IsRepaid &&  installment.Number > _contract.GracePeriod)
                        baseTocalculatePrincipalCoeff += _contract.Product.ExoticProduct.GetExoticInstallment(i - _contract.GracePeriod.Value).PrincipalCoeff;
                }

                baseTocalculatePrincipalCoeff = 1 - baseTocalculatePrincipalCoeff;

                for(int i = 0;i < _contract.NbOfInstallments;i++)
                {
                    Installment installment = _contract.GetInstallment(i);
                    if(!installment.IsRepaid && installment.Number <= _contract.GracePeriod)  //during Grace Period
                    {
                        installment.OLB -= amountPaid;
                        installment.CapitalRepayment = 0;
                        installment.InterestsRepayment = Math.Round(installment.OLB.Value * Convert.ToDecimal(_contract.InterestRate),2);
                    }
                    else if(!installment.IsRepaid && !firstInstallmentToRepay)
                    {
                        ExoticInstallment exoticInstallment = _contract.Product.ExoticProduct.GetExoticInstallment(i - _contract.GracePeriod.Value);
                        firstInstallmentToRepay = true;
                        installment.OLB -= amountPaid;
                        totalAmount = installment.OLB;

                        installment.CapitalRepayment = Math.Round(totalAmount.Value * Convert.ToDecimal(exoticInstallment.PrincipalCoeff / baseTocalculatePrincipalCoeff),2);
                        installment.InterestsRepayment = Math.Round(installment.OLB.Value * Convert.ToDecimal(_contract.InterestRate),2);
                    }
                    else if(!installment.IsRepaid)
                    {
                        ExoticInstallment exoticInstallment = _contract.Product.ExoticProduct.GetExoticInstallment(i - _contract.GracePeriod.Value);
                        Installment _installment = _contract.GetInstallment(i - 1);
                        installment.OLB  = _installment.OLB - _installment.CapitalRepayment;

                        installment.CapitalRepayment = Math.Round(totalAmount.Value * Convert.ToDecimal(exoticInstallment.PrincipalCoeff / baseTocalculatePrincipalCoeff),2);
                        installment.InterestsRepayment = Math.Round(installment.OLB.Value * Convert.ToDecimal(_contract.InterestRate),2);
                    }

                    _paidInstallments.Add(installment);
                }

                principalEvent += amountPaid;
                amountPaid = 0;
            }
        }
Ejemplo n.º 11
0
 public Installment(DateTime pExpectedDate,OCurrency pInterestRepayment,OCurrency pCapitalRepayment,
                    OCurrency pAidCapital, OCurrency pAidInterests, OCurrency pAidFees, DateTime? pAidDate, int pNumber)
 {
     ExpectedDate = pExpectedDate;
     _interestsRepayment = pInterestRepayment;
     _capitalRepayment = pCapitalRepayment;
     _paidCapital = pAidCapital;
     _paidInterests = pAidInterests;
     _paidFees = pAidFees;
     PaidDate = pAidDate;
     Number = pNumber;
 }
Ejemplo n.º 12
0
        public FixedInstallmentStrategy(DateTime pStartDate, Loan pContract, int pStartInstallment, OCurrency pStartAmount, int pNumberOfInstalments, ApplicationSettings pGeneralSettings)
        {
            _contract = pContract;
            _startAmount = pStartAmount;
            _numberOfInstallmentsToPay = pNumberOfInstalments;
            RoundingPoint = pContract.UseCents ? 2 : 0;
            GeneralSettings = pGeneralSettings;

            //if(pGeneralSettings.UseCents)
            //    _iCs = new CentsUsed(pStartDate, pContract, pStartInstallment, pStartAmount, pNumberOfInstalments);
            //else
            //    _iCs = new CentsNotUsed(pStartDate, pContract, pStartInstallment, pStartAmount, pNumberOfInstalments);
        }
Ejemplo n.º 13
0
 public CreditContractOptions(OLoanTypes pLoanType, bool pKeepExpectedInstallments,
     bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount,
     bool pCancelInterests, OCurrency pManualInterestsAmount,
     OAnticipatedRepaymentPenaltiesBases pAnticipatedTotalRepaymentPenaltiesBase)
 {
     _loanType = pLoanType;
     _keepExpectedInstallments = pKeepExpectedInstallments;
     _cancelFees = pCancelFees;
     _manualFeesAmount = pManualFeesAmount;
     _manualCommissionAmount = pManualCommissionAmount;
     _cancelInterests = pCancelInterests;
     _manualInterestsAmount = pManualInterestsAmount;
     _anticipatedTotalRepaymentPenaltiesBase = pAnticipatedTotalRepaymentPenaltiesBase;
 }
Ejemplo n.º 14
0
 private static void AutomaticRepayMethod(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pCommisionEvent)
 {
     if (AmountComparer.Compare(pAmountPaid, pInstallment.CommissionsUnpaid) > 0)
     {
         pCommisionEvent += pInstallment.CommissionsUnpaid;
         pAmountPaid -= pInstallment.CommissionsUnpaid;
         pInstallment.PaidCommissions += pInstallment.CommissionsUnpaid;
         pInstallment.CommissionsUnpaid = 0;
     }
     else
     {
         pCommisionEvent += pAmountPaid;
         pInstallment.PaidCommissions += pAmountPaid;
         pInstallment.CommissionsUnpaid -= pAmountPaid;
         pAmountPaid = 0;
     }
 }
Ejemplo n.º 15
0
        public void Repay(ref OCurrency pAmountPaid, ref OCurrency pFeesEvent, ref OCurrency pCommissionsEvent, ref OCurrency pInterestEvent)
        {
            if (_cco.CancelFees && (_cco.ManualFeesAmount + _cco.ManualCommissionAmount) >= 0)
            {
                pCommissionsEvent = _cco.ManualCommissionAmount;
                pFeesEvent = _cco.ManualFeesAmount;

                if (AmountComparer.Compare(pAmountPaid, _cco.ManualFeesAmount + _cco.ManualCommissionAmount) > 0)
                {
                    //pAmountPaid -= _cco.ManualFeesAmount + _cco.ManualCommissionAmount;
                }
                else
                    pAmountPaid = 0;
            }

            if (_cco.KeepExpectedInstallments)
            {
                if (_cco.CancelInterests && _cco.ManualInterestsAmount >= 0)
                {
                    OCurrency manualInterestAmount = _cco.ManualInterestsAmount;
                    for(int i = 0;i<_contract.NbOfInstallments;i++)
                    {
                        Installment installment = _contract.GetInstallment(i);
                        if(!installment.IsRepaid && pAmountPaid > 0 && manualInterestAmount > 0)
                        {
                            OCurrency interestHasToPay = installment.InterestsRepayment - installment.PaidInterests;
                            if (AmountComparer.Compare(manualInterestAmount,interestHasToPay) > 0)
                            {
                                pInterestEvent += interestHasToPay;
                                installment.PaidInterests = installment.InterestsRepayment;
                                pAmountPaid -= interestHasToPay;
                                manualInterestAmount -= interestHasToPay;
                            }
                            else
                            {
                                pInterestEvent += manualInterestAmount;
                                installment.PaidInterests += manualInterestAmount;
                                pAmountPaid -= manualInterestAmount;
                                manualInterestAmount = 0;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
        {
            if (AmountComparer.Compare(pAmountPaid, pInstallment.FeesUnpaid) > 0)
            {
                pFeesEvent += pInstallment.FeesUnpaid;
                pAmountPaid -= pInstallment.FeesUnpaid;
                pInstallment.PaidFees += pInstallment.FeesUnpaid;
                pInstallment.FeesUnpaid = 0;

            }
            else
            {
                pFeesEvent += pAmountPaid;
                pInstallment.PaidFees += pAmountPaid;
                pInstallment.FeesUnpaid -= pAmountPaid;
                pAmountPaid = 0;
            }
        }
Ejemplo n.º 17
0
        public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pInterestEvent, ref OCurrency pInterestPrepayment)
        {
            if (AmountComparer.Compare(pAmountPaid, pInstallment.InterestsRepayment - pInstallment.PaidInterests) > 0)
            {
                OCurrency interestHasToPay = pInstallment.InterestsRepayment - pInstallment.PaidInterests;

                pAmountPaid -= interestHasToPay;
                pInterestEvent += interestHasToPay;
                pInterestPrepayment += interestHasToPay;
                pInstallment.PaidInterests += interestHasToPay;
            }
            else
            {
                pInstallment.PaidInterests += pAmountPaid;
                pInterestEvent += pAmountPaid;
                pInterestPrepayment += pAmountPaid;
                pAmountPaid = 0;
            }
        }
        public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            int installmentNumber = 0;
            OCurrency interest = 0;
            _contract.InstallmentList.Sort((x, y) => x.ExpectedDate.CompareTo(y.ExpectedDate));
            foreach (Installment installment in _contract.InstallmentList)
            {
                if (!installment.IsRepaid)
                {
                    if (_generalSettings.AccountingProcesses == OAccountingProcesses.Accrual)
                    {
                        interest = 0;
                        amountPaid -= interest;
                        interestEvent += interest;
                        installmentNumber = installment.Number;
                    }

                    principalEvent += amountPaid;
                    OCurrency startAmount = _contract.GetInstallment(installment.Number - 1).OLB - amountPaid;
                    amountPaid = 0;

                    if (installment.Number <= _contract.GracePeriod.Value)
                    {
                        _CalculateInstallments(installment.Number, startAmount, _contract.NbOfInstallments - _contract.GracePeriod.Value);
                    }
                    else
                    {
                        _CalculateInstallments(installment.Number, startAmount, _contract.NbOfInstallments - installment.Number + 1);
                    }
                    break;
                }

                _paidInstallments.Add(installment);
            }
            if (installmentNumber != 0)
            {
                _contract.GetInstallment(installmentNumber - 1).InterestsRepayment = interest;
                _contract.GetInstallment(installmentNumber - 1).PaidInterests = interest;
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// this method makes a debit operation on an account based on the debitPlus property of the account.
 /// </summary>
 /// <param name="amount">the amount to debit</param>
 public void Debit(OCurrency   amount)
 {
     if (_debitPlus)
         _balance += amount;
     else
         _balance -= amount;
 }
Ejemplo n.º 20
0
 public void UseManualInterestsAmount(OCurrency pAmount)
 {
     _manualInterestsAmount = _manualInterestsAmount - pAmount;
 }
 public void CalculateFees(DateTime pDate, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
 {
     //Nothing to calculate
 }
 public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
 {
     _repayNextInstallments.RepayNextInstallments(ref amountPaid, ref interestEvent, ref interestPrepayment, ref principalEvent, ref feesEvent, ref commissionsEvent);
     PaidInstallments = _repayNextInstallments.PaidInstallments;
 }
Ejemplo n.º 23
0
        private void CalculateDecliningFixedInstallments(int number, OCurrency interests)
        {
            Installment installment = _contract.GetInstallment(number - 1);
            OCurrency olb = _contract.CalculateActualOlb();
            OCurrency totalOlb = _contract.CalculateActualOlb();
            OCurrency installmentVpm = _contract.VPM(olb,_contract.InstallmentList.Count - number + 1).Value;
            OCurrency interestsRepayment;
            OCurrency capital;
            OCurrency capitalRepayment = olb / (_contract.InstallmentList.Count - number + 1);
            OCurrency _olb = 0;

            installment.CapitalRepayment = capitalRepayment;
            installment.PaidInterests = 0;
            installment.PaidCapital = 0;
            installment.PaidFees = 0;

            for (int i = number + 1; i <= _contract.InstallmentList.Count; i++)
            {
                installment = _contract.GetInstallment(i - 2);
                interestsRepayment = olb * _contract.InterestRate;

                installment.InterestsRepayment = Math.Round(Convert.ToDecimal(interestsRepayment.Value), 2);

                capital = installmentVpm - installment.InterestsRepayment;
                installment.CapitalRepayment = Math.Round(Convert.ToDecimal(capital.Value), 2);
                _olb += Math.Round(installment.CapitalRepayment.Value, 2);
                installment.OLB = olb;

                olb -= installment.CapitalRepayment;

                installment.PaidInterests = 0;
                installment.PaidCapital = 0;
                installment.PaidFees = 0;
            }

            installment = _contract.GetInstallment(number - 1);
            installment.InterestsRepayment = interests;

            installment = _contract.GetInstallment(_contract.InstallmentList.Count - 1);
            interestsRepayment = olb * _contract.InterestRate;
            capital = installmentVpm - interestsRepayment;

            installment.InterestsRepayment = Math.Round(Convert.ToDecimal(interestsRepayment.Value), 2);
            installment.CapitalRepayment = Math.Round(Convert.ToDecimal(capital.Value), 2);
            _olb += Math.Round(installment.CapitalRepayment.Value, 2);
            installment.CapitalRepayment = installment.CapitalRepayment - (_olb - totalOlb);
            installment.OLB = olb;
        }
Ejemplo n.º 24
0
        public OCurrency CalculateCommision(DateTime pDate, int pNumber, OPaymentType pPaymentType, OCurrency amount, ref bool calculated)
        {
            if (_contract.Product.AnticipatedPartialRepaymentPenaltiesBase == OAnticipatedRepaymentPenaltiesBases.PrepaidPrincipal
                && !calculated)
            {
                calculated = true;
                return amount * _contract.AnticipatedPartialRepaymentPenalties / (1 + _contract.AnticipatedPartialRepaymentPenalties);
            }

            if (_contract.Product.AnticipatedTotalRepaymentPenaltiesBase ==
                    OAnticipatedRepaymentPenaltiesBases.RemainingInterest && !calculated)
                {
                    return CalculationBaseForLateFees.AnticipateFeesBasedOnOverdueInterest(
                        _contract, pDate, pNumber, false,
                        _generalSettings, _nWds, pPaymentType);
                }

            return CalculationBaseForLateFees.AnticipateFeesBasedOnOlb(_contract, pDate, pNumber, false,
                                                                       _generalSettings, _nWds, pPaymentType);
        }
Ejemplo n.º 25
0
        public virtual List <SavingEvent> Transfer(ISavingsContract to, OCurrency amount, OCurrency fee, DateTime date, string description)
        {
            List <SavingEvent> events = new List <SavingEvent>(3);

            events.Add(DebitTransfer(to, amount, fee, date, description));
            events.Add(to.CreditTransfer(this, amount, date, description));
            if (GetBalance() < 0)
            {
                SavingOverdraftFeeEvent e = ChargeOverdraftFee(date, User.CurrentUser);
                events.Add(e);
            }
            return(events);
        }
Ejemplo n.º 26
0
        public virtual SavingEvent DebitTransfer(ISavingsContract to, OCurrency amount, OCurrency fee, DateTime date, string description)
        {
            SavingTransferEvent e;
            bool ib = Branch.Id != to.Branch.Id; // inter-branch

            if (ib)
            {
                e = new SavingDebitInterBranchTransferEvent();
            }
            else
            {
                e = new SavingDebitTransferEvent();
            }
            e.Description         = ib ? "Inter-branch transfer" : "Transfer";
            e.RelatedContractCode = to.Code;
            e.Amount      = amount;
            e.Fee         = fee;
            e.Date        = date;
            e.User        = User.CurrentUser;
            e.Description = description;
            e.ProductType = Product.GetType();
            e.Target      = this;
            Events.Add(e);
            return(e);
        }
Ejemplo n.º 27
0
        public virtual List <SavingEvent> RepayLoanFromSaving(Loan loan, int repaymentEventId, DateTime date, OCurrency amount, string description, User user, Teller teller)
        {
            var events   = new List <SavingEvent>();
            int?tellerId = null;

            if (teller != null && teller.Id != 0)
            {
                tellerId = teller.Id;
            }

            SavingEvent repaymentFromSavingEvent = new LoanRepaymentFromSavingEvent
            {
                Amount        = amount,
                Date          = date,
                Description   = description,
                User          = user,
                Cancelable    = false,
                TellerId      = tellerId,
                IsPending     = false,
                SavingsMethod = null,
                ProductType   = typeof(SavingsBookProduct),
                LoanEventId   = repaymentEventId
            };

            events.Add(repaymentFromSavingEvent);
            Events.Add(repaymentFromSavingEvent);
            return(events);
        }
Ejemplo n.º 28
0
        public virtual List <SavingEvent> FirstDeposit(OCurrency pInitialAmount, DateTime pCreationDate, OCurrency pEntryFees, User pUser, Teller teller)
        {
            List <SavingEvent> events = new List <SavingEvent>();

            int?tellerId = null;

            if (teller != null && teller.Id != 0)
            {
                tellerId = teller.Id;
            }

            SavingInitialDepositEvent initialEvent = new SavingInitialDepositEvent
            {
                Amount      = pInitialAmount,
                Date        = pCreationDate,
                Description = "First deposit",
                User        = pUser,
                Fee         = pEntryFees,
                TellerId    = tellerId,
                ProductType = typeof(SavingsBookProduct)
            };

            Events.Add(initialEvent);
            events.Add(initialEvent);

            CreationDate = pCreationDate;

            return(events);
        }
Ejemplo n.º 29
0
 public void RepayFees(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pFeesEvent)
 {
     _methodToCalculateFees.Repay(pInstallment, ref pAmountPaid, ref pFeesEvent);
 }
Ejemplo n.º 30
0
 public OCurrency ConvertAmountToExternalCurrency(OCurrency amount, ExchangeRate exchangeRate)
 {
     return(amount * 1 / exchangeRate.Rate);
 }
Ejemplo n.º 31
0
        private static CalculateMaximumAmountToRepayStrategy _MaximumAmountToRepay(Loan pContract, bool pCancelFees, OCurrency pManualFeesAmount, OCurrency pManualCommissionAmount, bool pCancelInterest, OCurrency pManualInterestAmount)
        {
            CreditContractOptions cCO = new CreditContractOptions(pContract.Product.LoanType, pContract.Product.KeepExpectedInstallment, pCancelFees,
                                                                  pManualFeesAmount, pManualCommissionAmount,
                                                                  pCancelInterest, pManualInterestAmount, pContract.Product.AnticipatedTotalRepaymentPenaltiesBase);

            return(new CalculateMaximumAmountToRepayStrategy(cCO, pContract, new User(), ApplicationSettings.GetInstance(""), NonWorkingDateSingleton.GetInstance("")));
        }
Ejemplo n.º 32
0
        private void LoadContracts()
        {
            int loans = 0;

            lvContracts.Items.Clear();

            PaymentMethod paymentMethod =
                ServicesProvider.GetInstance().GetPaymentMethodServices().GetPaymentMethodById(1);

            foreach (VillageMember member in _village.Members)
            {
                foreach (Loan loan in member.ActiveLoans)
                {
                    if (null == loan || loan.ContractStatus != OContractStatus.Active)
                    {
                        continue;
                    }
                    if (loan.NsgID != _village.Id)
                    {
                        continue;
                    }

                    var         result      = new KeyValuePair <Loan, RepaymentEvent>();
                    Installment installment = loan.GetFirstUnpaidInstallment();

                    if (null == installment)
                    {
                        continue;
                    }

                    loans++;

                    Person       person = member.Tiers as Person;
                    ListViewItem item   = new ListViewItem(person.Name)
                    {
                        Tag = loan
                    };
                    item.SubItems.Add(loan.Code);

                    OCurrency principalHasToPay = result.Value == null
                                                      ? installment.PrincipalHasToPay
                                                      : (result.Value).Principal;

                    ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem
                    {
                        Text = principalHasToPay.GetFormatedValue(
                            loan.UseCents),
                        Tag = principalHasToPay
                    };
                    item.SubItems.Add(subitem);

                    OCurrency interestHasToPay = result.Value == null
                                                      ? installment.InterestHasToPay
                                                      : (result.Value).Interests;

                    subitem = new ListViewItem.ListViewSubItem
                    {
                        Text = interestHasToPay.GetFormatedValue(loan.UseCents),
                        Tag  = interestHasToPay
                    };
                    item.SubItems.Add(subitem);

                    subitem = new ListViewItem.ListViewSubItem();
                    OCurrency penalties = loan.CalculateDuePenaltiesForInstallment(installment.Number,
                                                                                   TimeProvider.Today);
                    subitem.Text = penalties.GetFormatedValue(loan.UseCents);
                    subitem.Tag  = penalties;
                    item.SubItems.Add(subitem);

                    subitem = new ListViewItem.ListViewSubItem();
                    OCurrency total = principalHasToPay + interestHasToPay + penalties;
                    subitem.Text = total.GetFormatedValue(loan.UseCents);
                    subitem.Tag  = total;
                    item.SubItems.Add(subitem);

                    subitem = new ListViewItem.ListViewSubItem();
                    OCurrency olb = ServicesProvider.GetInstance().GetGeneralSettings().IsOlbBeforeRepayment
                                        ? installment.OLB
                                        : installment.OLBAfterRepayment;
                    subitem.Text = olb.GetFormatedValue(loan.UseCents);
                    subitem.Tag  = olb;
                    item.SubItems.Add(subitem);

                    OCurrency dueInterest = 0;
                    foreach (Installment installmentItem in loan.InstallmentList)
                    {
                        if (!installmentItem.IsRepaid)
                        {
                            dueInterest += installmentItem.InterestsRepayment - installmentItem.PaidInterests;
                        }
                    }

                    subitem = new ListViewItem.ListViewSubItem
                    {
                        Text = dueInterest.GetFormatedValue(loan.UseCents),
                        Tag  = dueInterest
                    };
                    item.SubItems.Add(subitem);

                    subitem = new ListViewItem.ListViewSubItem
                    {
                        Text = loan.Product.Currency.Code,
                        Tag  = loan.Product.Currency
                    };
                    item.SubItems.Add(subitem);

                    cbItem.SelectedIndex = 0;

                    subitem = new ListViewItem.ListViewSubItem
                    {
                        Text = cbItem.SelectedItem.ToString(),
                        Tag  = cbItem.SelectedItem
                    };
                    item.SubItems.Add(subitem);

                    subitem = new ListViewItem.ListViewSubItem();
                    item.SubItems.Add(subitem);

                    lvContracts.Items.Add(item);
                }
            }

            if (0 == loans)
            {
                btnOK.Enabled = false;
                return;
            }

            _itemTotal.SubItems.Add("");
            _itemTotal.SubItems.Add("0");
            _itemTotal.SubItems.Add("0");
            _itemTotal.SubItems.Add("0");
            _itemTotal.SubItems.Add("0");
            _itemTotal.SubItems.Add("");
            _itemTotal.SubItems.Add("");
            _itemTotal.SubItems.Add("");
            _itemTotal.SubItems.Add("");

            lvContracts.Items.Add(_itemTotal);
        }
Ejemplo n.º 33
0
        private void BtnOkClick(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lvContracts.Items)
            {
                if (item == _itemTotal)
                {
                    continue;
                }
                if (!item.Checked)
                {
                    continue;
                }
                var           loan         = item.Tag as Loan;
                VillageMember activeMember = null;
                int           index        = 0;
                foreach (VillageMember member in _village.Members)
                {
                    int tIndex = member.ActiveLoans.IndexOf(loan);
                    if (tIndex > -1)
                    {
                        activeMember = member;
                        index        = tIndex;
                    }
                }

                if (activeMember != null)
                {
                    Person person = activeMember.Tiers as Person;
                    if (loan != null)
                    {
                        int       number = loan.GetFirstUnpaidInstallment().Number;
                        OCurrency total  = (OCurrency)item.SubItems[5].Tag;
                        bool      doProportionPayment = cbItem.SelectedIndex == 2;
                        OCurrency penalties           = (OCurrency)item.SubItems[4].Tag;
                        bool      disableFees         = penalties != loan.CalculateDuePenaltiesForInstallment(number, TimeProvider.Today);
                        string    comment             = item.SubItems[10].Text;

                        PaymentMethod paymentMethod = ServicesProvider.GetInstance().GetPaymentMethodServices().GetPaymentMethodById(1);

                        try
                        {
                            activeMember.ActiveLoans[index] =
                                ServicesProvider.GetInstance().GetContractServices().Repay(loan,
                                                                                           person,
                                                                                           number,
                                                                                           TimeProvider.Today,
                                                                                           total,
                                                                                           disableFees,
                                                                                           penalties,
                                                                                           0,
                                                                                           false,
                                                                                           0,
                                                                                           true,
                                                                                           doProportionPayment,
                                                                                           paymentMethod,
                                                                                           comment,
                                                                                           false);
                        }
                        catch (Exception ex)
                        {
                            new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                        }
                    }
                }

                if (loan != null)
                {
                    if (loan.Closed)
                    {
                        if (activeMember != null)
                        {
                            activeMember.ActiveLoans[index] = null;
                        }
                    }
                }
            }

            if (_AllContractsClosed())
            {
                _village.Active = false;
                ServicesProvider.GetInstance().GetContractServices().UpdateVillageStatus(_village);
            }
        }
Ejemplo n.º 34
0
//        public virtual List<SavingEvent> RefusePendingDeposit(OCurrency pAmount, DateTime pDate, User pUser, string pDescription, OPaymentMethods method, int? pendingEventId)
//        {
//            throw new NotImplementedException();
//        }

        public virtual List <SavingEvent> RefusePendingDeposit(OCurrency pAmount, DateTime pDate, User pUser, string pDescription, OSavingsMethods method, int?pendingEventId)
        {
            throw new NotImplementedException();
        }
Ejemplo n.º 35
0
        public void RepayPartialAnticipateInstallments(DateTime pDate, ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid == 0) return;
            Installment installment = null;

            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                installment = _contract.GetInstallment(i);
                if (installment.IsRepaid && installment.ExpectedDate > pDate && !_cCo.KeepExpectedInstallments)
                {
                    #region 1 (installment.FeesUnpaid != 0)
                    if (installment.FeesUnpaid != 0 || installment.CommissionsUnpaid != 0 || installment.NotPaidYet)
                    {
                        //commission
                        if (amountPaid == 0) break;
                        _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                        //fee
                        if (amountPaid == 0) break;
                        _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                        //interest
                        OCurrency interestPrepayment = 0;
                        _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,
                                                             ref interestPrepayment);

                        //principal
                        RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                        PaidIstallments.Add(installment);

                        if (amountPaid == 0) break;
                    }
                    #endregion
                    #region 2 (installment.CommissionsUnpaid != 0)
                    //if (installment.CommissionsUnpaid != 0)
                    //{
                    //    //commission
                    //    if (amountPaid == 0) break;
                    //    _MethodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                    //    //fee
                    //    if (amountPaid == 0) break;
                    //    _MethodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                    //    //interest
                    //    OCurrency interestPrepayment = 0;
                    //    _MethodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,
                    //                                         ref interestPrepayment);
                    //    if (amountPaid == 0) break;

                    //    //principal
                    //    RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                    //    PaidIstallments.Add(installment);

                    //    if (amountPaid == 0) break;
                    //}
                    //#endregion
                    //#region 3 (installment.NotPaidYet)
                    //if (installment.NotPaidYet)
                    //{
                    //    //commission
                    //    if (amountPaid == 0) break;
                    //    _MethodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                    //    //fee
                    //    if (amountPaid == 0) break;
                    //    _MethodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                    //    //interest
                    //    OCurrency interestPrepayment = 0;
                    //    _MethodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent, ref interestPrepayment);

                    //    //principal
                    //    RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                    //    PaidIstallments.Add(installment);

                    //    if (amountPaid == 0) break;
                    //}
                    #endregion
                }

                if (!installment.IsRepaid && !_cCo.KeepExpectedInstallments)
                {
                    #region 1 (installment.ExpectedDate <= pDate || installment.ExpectedDate > pDate)
                    if (installment.ExpectedDate <= pDate || installment.ExpectedDate > pDate)
                    {
                        //commission
                        if (amountPaid == 0) break;
                        _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                        //fee
                        if (amountPaid == 0) break;
                        _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                        //interest
                        OCurrency interestPrepayment = 0;
                        _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,
                                                             ref interestPrepayment);

                        RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                        PaidIstallments.Add(installment);

                        if (amountPaid == 0) break;
                    }
                    #endregion
                }
            }

            if (installment != null)
            {
                CalculateRemainsInstallmentAfterApr(installment.Number, pDate);
                for (int i = installment.Number; i < _contract.NbOfInstallments; i++)
                {
                    _contract.GetInstallment(i).FeesUnpaid = 0;
                }
            }
        }
Ejemplo n.º 36
0
 public virtual List <SavingEvent> Reopen(OCurrency pAmount, DateTime pDate, User pUser, string pDescription, bool pIsDesactivateFees)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 37
0
        private void RepayPrincipal(int pNumber, ref OCurrency pAmountPaid, ref OCurrency principalEvent, DateTime pDate)
        {
            foreach (Installment installment in _contract.InstallmentList)
            {
                if (installment.Number >= pNumber)
                {
                    if (_contract.EscapedMember != null)
                    {
                        installment.PaidCapital += pAmountPaid;
                        installment.PaidCapital = Math.Round(installment.PaidCapital.Value, 2);
                        principalEvent += pAmountPaid;

                        pAmountPaid = 0;
                    }
                    else
                    {
                        if (AmountComparer.Compare(pAmountPaid, installment.CapitalRepayment - installment.PaidCapital) > 0)
                        {
                            OCurrency principalHasToPay = installment.CapitalRepayment - installment.PaidCapital;
                            installment.PaidCapital = installment.CapitalRepayment;
                            pAmountPaid -= principalHasToPay;
                            principalEvent += principalHasToPay;

                            if (installment.ExpectedDate <= pDate)
                                break;
                        }
                        else
                        {
                            installment.PaidCapital += pAmountPaid;
                            installment.PaidCapital = Math.Round(installment.PaidCapital.Value, 2);
                            principalEvent += pAmountPaid;

                            pAmountPaid = 0;

                            if (installment.ExpectedDate <= pDate)
                                break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 38
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!_nsgForm.Save())
            {
                return;
            }

            bool             isError = false;
            ISavingsContract saving  = null;

            try
            {
                foreach (ListViewItem item in lvMembers.Items)
                {
                    if (item == _itemTotal)
                    {
                        continue;
                    }
                    if (!item.Checked)
                    {
                        continue;
                    }
                    var     member = item.Tag as VillageMember;
                    IClient client = member.Tiers;

                    OCurrency initialAmount = (OCurrency)item.SubItems[idxInitialAmount].Tag;
                    double    interestRate  = (double)item.SubItems[idxInterestRate].Tag;
                    OCurrency entryFees     = (OCurrency)item.SubItems[idxEntryFees].Tag;

                    if (_product is SavingsBookProduct)
                    {
                        SavingsBookProduct sbp               = (SavingsBookProduct)_product;
                        decimal            withdrawFees      = (decimal)item.SubItems[idxWithdrawFees].Tag;
                        decimal            transferFees      = (decimal)item.SubItems[idxTransferFees].Tag;
                        decimal            ibtFees           = Convert.ToDecimal(item.SubItems[idxIbtFees].Tag);
                        decimal            depositFees       = (decimal)item.SubItems[idxDepositFees].Tag;
                        decimal            chequeDepositFees = (decimal)item.SubItems[idxChequeDepositFees].Tag;
                        decimal            closeFees         = (decimal)item.SubItems[idxCloseFees].Tag;
                        decimal            managementFees    = (decimal)item.SubItems[idxManagementFees].Tag;
                        decimal            overdraftFees     = (decimal)item.SubItems[idxOverdraftFees].Tag;
                        decimal            agioFees          = (decimal)item.SubItems[idxAgioFees].Tag;
                        decimal            reopenFees        = (decimal)item.SubItems[idxReopenFees].Tag;

                        saving = new SavingBookContract(ServicesProvider.GetInstance().GetGeneralSettings(),
                                                        User.CurrentUser, TimeProvider.Today, sbp, client)
                        {
                            InterestRate = interestRate / 100
                        };
                        SavingBookContract s = (SavingBookContract)saving;

                        if (sbp.WithdrawFeesType == OSavingsFeesType.Flat)
                        {
                            s.FlatWithdrawFees = withdrawFees;
                        }
                        else
                        {
                            s.RateWithdrawFees = (double)withdrawFees / 100;
                        }

                        if (sbp.TransferFeesType == OSavingsFeesType.Flat)
                        {
                            s.FlatTransferFees = transferFees;
                        }
                        else
                        {
                            s.RateTransferFees = (double)transferFees / 100;
                        }

                        if (sbp.InterBranchTransferFee.IsFlat)
                        {
                            s.FlatInterBranchTransferFee = ibtFees;
                        }
                        else
                        {
                            s.RateInterBranchTransferFee = Convert.ToDouble(ibtFees);
                        }

                        s.DepositFees       = depositFees;
                        s.ChequeDepositFees = chequeDepositFees;
                        s.CloseFees         = closeFees;
                        s.ManagementFees    = managementFees;
                        s.OverdraftFees     = overdraftFees;
                        s.AgioFees          = (double)agioFees / 100;
                        s.ReopenFees        = reopenFees;
                    }

                    saving.SavingsOfficer = _village.LoanOfficer;
                    saving.InitialAmount  = initialAmount;
                    saving.EntryFees      = entryFees;
                    saving.NsgID          = _village.Id;
                    saving.Id             = ServicesProvider.GetInstance().GetAccountServices().SaveContract(saving, (Client)member.Tiers);
                    saving = ServicesProvider.GetInstance().GetAccountServices().GetSaving(saving.Id);

                    ServicesProvider.GetInstance().GetAccountServices().FirstDeposit(saving, initialAmount, TimeProvider.Now, entryFees,
                                                                                     User.CurrentUser, Teller.CurrentTeller);
                    ServicesProvider.GetInstance().GetAccountServices().UpdateInitialData(saving.Id, initialAmount, entryFees);

                    saving = ServicesProvider.GetInstance().GetAccountServices().GetSaving(saving.Id);
                    ((Client)member.Tiers).AddSaving(saving);
                }
            }
            catch (Exception ex)
            {
                isError = true;
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
            finally
            {
                InitializeControls();
            }

            if (!isError)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
        private void _CalculateInstallments(int pStartInstallment, OCurrency pStartAmount, int pNumberOfInstallmentsToPay)
        {
            OCurrency olb = pStartAmount;
            OCurrency sumOfPrincipal = 0;
            int installmentNumber = 0;

            for (int number = pStartInstallment; number <= _contract.NbOfInstallments; number++)
            {
                Installment installment = _contract.GetInstallment(number - 1);
                installment.InterestsRepayment = Math.Ceiling(pStartAmount.Value * Convert.ToDecimal(_contract.InterestRate));

                if (installment.Number <= _contract.GracePeriod)
                {
                    installment.CapitalRepayment = 0;
                    installment.OLB = olb;
                }
                else
                {
                    installment.CapitalRepayment = decimal.Round((pStartAmount.Value - sumOfPrincipal.Value) / (pNumberOfInstallmentsToPay - installmentNumber), 0);
                    sumOfPrincipal += installment.CapitalRepayment;
                    installmentNumber++;
                }

                installment.OLB = olb;
                olb -= installment.CapitalRepayment;
            }
        }
Ejemplo n.º 40
0
        private void InitializeControls()
        {
            udInitialAmount.Minimum = _product.InitialAmountMin.Value;
            udInitialAmount.Maximum = _product.InitialAmountMax.Value;

            if (!_product.InterestRate.HasValue)
            {
                _defaultInterestRate   = _product.InterestRateMin.Value * 100;
                udInterestRate.Minimum = (decimal)_product.InterestRateMin * 100;
                udInterestRate.Maximum = (decimal)_product.InterestRateMax * 100;
            }
            else
            {
                _defaultInterestRate = _product.InterestRate.Value * 100;
            }

            if (!_product.EntryFees.HasValue)
            {
                _defaultEntryFees   = _product.EntryFeesMin;
                udEntryFees.Minimum = _product.EntryFeesMin.Value;
                udEntryFees.Maximum = _product.EntryFeesMax.Value;
            }
            else
            {
                _defaultEntryFees = _product.EntryFees;
            }

            if (_product is SavingsBookProduct)
            {
                SavingsBookProduct sbp = (SavingsBookProduct)_product;
                lvMembers.Columns.Remove(chLoan);
                if (sbp.WithdrawFeesType == OSavingsFeesType.Flat)
                {
                    if (!sbp.FlatWithdrawFees.HasValue)
                    {
                        _defaultWithdrawFees   = sbp.FlatWithdrawFeesMin.Value;
                        udWithdrawFees.Minimum = sbp.FlatWithdrawFeesMin.Value;
                        udWithdrawFees.Maximum = sbp.FlatWithdrawFeesMax.Value;
                    }
                    else
                    {
                        _defaultWithdrawFees = sbp.FlatWithdrawFees.Value;
                    }
                }
                else
                {
                    if (!sbp.RateWithdrawFees.HasValue)
                    {
                        _defaultWithdrawFees   = (decimal)sbp.RateWithdrawFeesMin.Value * 100;
                        udWithdrawFees.Minimum = (decimal)sbp.RateWithdrawFeesMin.Value * 100;
                        udWithdrawFees.Maximum = (decimal)sbp.RateWithdrawFeesMax.Value * 100;
                    }
                    else
                    {
                        _defaultWithdrawFees = (decimal)sbp.RateWithdrawFees.Value * 100;
                    }
                }

                if (sbp.TransferFeesType == OSavingsFeesType.Flat)
                {
                    if (!sbp.FlatTransferFees.HasValue)
                    {
                        _defaultTransferFees   = sbp.FlatTransferFeesMin.Value;
                        udTransferFees.Minimum = sbp.FlatTransferFeesMin.Value;
                        udTransferFees.Maximum = sbp.FlatTransferFeesMax.Value;
                    }
                    else
                    {
                        _defaultTransferFees = sbp.FlatTransferFees.Value;
                    }
                }
                else
                {
                    if (!sbp.RateTransferFees.HasValue)
                    {
                        _defaultTransferFees   = (decimal)sbp.RateTransferFeesMin.Value * 100;
                        udTransferFees.Minimum = (decimal)sbp.RateTransferFeesMin.Value * 100;
                        udTransferFees.Maximum = (decimal)sbp.RateTransferFeesMax.Value * 100;
                    }
                    else
                    {
                        _defaultTransferFees = (decimal)sbp.RateTransferFees.Value * 100;
                    }
                }

                if (sbp.InterBranchTransferFee.IsRange)
                {
                    _defaultIbtFees      = sbp.InterBranchTransferFee.Min.Value;
                    nudIbtFees.Minimum   = sbp.InterBranchTransferFee.Min.Value;
                    nudIbtFees.Maximum   = sbp.InterBranchTransferFee.Max.Value;
                    nudIbtFees.Increment = sbp.InterBranchTransferFee.IsFlat ? 1 : 0.01m;
                }
                else
                {
                    _defaultIbtFees    = sbp.InterBranchTransferFee.Value.Value;
                    nudIbtFees.Minimum = _defaultIbtFees;
                    nudIbtFees.Maximum = _defaultIbtFees;
                }

                // Deposit fees
                if (!sbp.DepositFees.HasValue)
                {
                    _defaultDepositFees   = sbp.DepositFeesMin.Value;
                    udDepositFees.Minimum = sbp.DepositFeesMin.Value;
                    udDepositFees.Maximum = sbp.DepositFeesMax.Value;
                }
                else
                {
                    _defaultDepositFees = sbp.DepositFees.Value;
                }

                // Cheque deposit fees
                if (!sbp.ChequeDepositFees.HasValue)
                {
                    _defaultChequeDepositFees   = sbp.ChequeDepositFeesMin.Value;
                    udChequeDepositFees.Minimum = sbp.ChequeDepositFeesMin.Value;
                    udChequeDepositFees.Maximum = sbp.ChequeDepositFeesMax.Value;
                }
                else
                {
                    _defaultChequeDepositFees = sbp.ChequeDepositFees.Value;
                }

                // Close fees
                if (!sbp.CloseFees.HasValue)
                {
                    _defaultCloseFees   = sbp.CloseFeesMin.Value;
                    udCloseFees.Minimum = sbp.CloseFeesMin.Value;
                    udCloseFees.Maximum = sbp.CloseFeesMax.Value;
                }
                else
                {
                    _defaultCloseFees = sbp.CloseFees.Value;
                }

                // Management
                if (!sbp.ManagementFees.HasValue)
                {
                    _defaultManagementFees   = sbp.ManagementFeesMin.Value;
                    udManagementFees.Minimum = sbp.ManagementFeesMin.Value;
                    udManagementFees.Maximum = sbp.ManagementFeesMax.Value;
                }
                else
                {
                    _defaultManagementFees = sbp.ManagementFees.Value;
                }

                // Overdraft
                if (!sbp.OverdraftFees.HasValue)
                {
                    _defaultOverdraftFees   = sbp.OverdraftFeesMin.Value;
                    udOverdraftFees.Minimum = sbp.OverdraftFeesMin.Value;
                    udOverdraftFees.Maximum = sbp.OverdraftFeesMax.Value;
                }
                else
                {
                    _defaultOverdraftFees = sbp.OverdraftFees.Value;
                }

                // Agio
                if (!sbp.AgioFees.HasValue)
                {
                    _defaultAgioFees   = (decimal)sbp.AgioFeesMin.Value * 100;
                    udAgioFees.Minimum = (decimal)sbp.AgioFeesMin.Value * 100;
                    udAgioFees.Maximum = (decimal)sbp.AgioFeesMax.Value * 100;
                }
                else
                {
                    _defaultAgioFees = (decimal)sbp.AgioFees.Value * 100;
                }

                // Reopen
                if (!sbp.ReopenFees.HasValue)
                {
                    _defaultReopenFees   = sbp.ReopenFeesMin.Value;
                    udReopenFees.Minimum = sbp.ReopenFeesMin.Value;
                    udReopenFees.Maximum = sbp.ReopenFeesMax.Value;
                }
                else
                {
                    _defaultReopenFees = sbp.ReopenFees.Value;
                }
            }

            lvMembers.Items.Clear();
            Color dfc = Color.Gray;
            Color fc  = Color.Black;
            Color bc  = Color.White;

            foreach (VillageMember member in _village.Members)
            {
                Person       person = (Person)member.Tiers;
                ListViewItem item   = new ListViewItem(person.Name)
                {
                    Tag = member
                };
                item.UseItemStyleForSubItems = false;
                item.SubItems.Add(person.IdentificationData);
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", fc, bc, item.Font));
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", fc, bc, item.Font));
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.InterestRate.HasValue ? dfc : fc, bc, item.Font));
                item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.EntryFees.HasValue ? dfc : fc, bc, item.Font));
                if (_product is SavingsBookProduct)
                {
                    SavingsBookProduct sbp = (SavingsBookProduct)_product;
                    if (sbp.WithdrawFeesType == OSavingsFeesType.Flat)
                    {
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "",
                                                                           sbp.FlatWithdrawFees.HasValue ? dfc : fc, bc, item.Font));
                    }
                    else
                    {
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "",
                                                                           sbp.RateWithdrawFees.HasValue ? dfc : fc, bc, item.Font));
                    }

                    if (sbp.TransferFeesType == OSavingsFeesType.Flat)
                    {
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "",
                                                                           sbp.FlatTransferFees.HasValue ? dfc : fc, bc, item.Font));
                    }
                    else
                    {
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "",
                                                                           sbp.RateTransferFees.HasValue ? dfc : fc, bc, item.Font));
                    }
                    LVSI lvsi = new LVSI(item, "", sbp.InterBranchTransferFee.IsRange ? fc : dfc, bc, item.Font);
                    item.SubItems.Add(lvsi);

                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.DepositFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.ChequeDepositFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.CloseFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.ManagementFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.OverdraftFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.AgioFees.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", sbp.ReopenFees.HasValue ? dfc : fc, bc, item.Font));
                }
                lvMembers.Items.Add(item);
                _hasMember = true;
            }

            if (0 == lvMembers.Items.Count)
            {
                btnSave.Enabled = false;
                return;
            }

            if (_hasMember)
            {
                OCurrency zero = 0m;
                _itemTotal.Text = GetString("total");
                _itemTotal.SubItems.Add("");
                _itemTotal.SubItems.Add("");
                _itemTotal.SubItems.Add(zero.GetFormatedValue(true));
                lvMembers.Items.Add(_itemTotal);
            }
            lvMembers.SubItemClicked       += lvMembers_SubItemClicked;
            lvMembers.SubItemEndEditing    += lvMembers_SubItemEndEditing;
            lvMembers.DoubleClickActivation = true;
        }
Ejemplo n.º 41
0
 private static void _AssertBadLoanRepaymentEvent(BadLoanRepaymentEvent pEvent, DateTime pDate, int pPastDueDays, OCurrency pPrincipal,
                                                  OCurrency pInterest, OCurrency pFees, int pInstallmentNumber)
 {
     _AssertRepaymentEvent(pEvent, "RBLE", pDate, pPastDueDays, pPrincipal, pInterest, pFees, pInstallmentNumber);
 }
Ejemplo n.º 42
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool isError = false;

            if (_CheckIfMoneyIsEnough())
            {
                if (!MessageBox.Show(MultiLanguageStrings.GetString(Ressource.VillageForm, "MoneyNotEnoughForAll.Text"), @"!",
                                     MessageBoxButtons.YesNo).Equals(DialogResult.Yes))
                {
                    return;
                }
            }

            if (_product.GracePeriod == null && !_CheckGracePeriod())
            {
                MessageBox.Show(MultiLanguageStrings.GetString(Ressource.VillageForm, "GracePeriodNotCorrect"),
                                MultiLanguageStrings.GetString(Ressource.VillageForm, "GracePeriod"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            foreach (ListViewItem item in lvMembers.Items)
            {
                if (item == _itemTotal)
                {
                    continue;
                }
                if (!item.Checked)
                {
                    continue;
                }
                if (_product.UseCompulsorySavings && item.SubItems[IdxCompulsorySavings].Tag == null)
                {
                    string text = string.Format(@"The loan of client '{0}' requires a compulsory savings account!", ((VillageMember)item.Tag).Tiers.Name);
                    MessageBox.Show(text, @"No compulsory savings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                /*if (item.SubItems[IdxPaymentMethod].Tag != null &&
                 *  item.SubItems[IdxPaymentMethod].Tag.ToString() == OPaymentMethods.Savings.ToString())
                 * {
                 *  if (_product.UseCompulsorySavings && item.SubItems[IdxCompulsorySavings].Tag == null)
                 *  {
                 *      string text = string.Format(@"The loan of client '{0}' requires a compulsory savings account!", ((VillageMember)item.Tag).Tiers.Name);
                 *      MessageBox.Show(text, @"No compulsory savings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 *      return;
                 *  }
                 * }*/
            }

            if (!_nsgForm.Save())
            {
                return;
            }

            Loan          loan = null;
            VillageMember member;

            try
            {
                foreach (ListViewItem item in lvMembers.Items)
                {
                    if (!item.Checked || item == _itemTotal)
                    {
                        continue;
                    }
                    member = item.Tag as VillageMember;
                    Project project;
                    if (null == member)
                    {
                        continue;
                    }

                    OCurrency amount       = (OCurrency)item.SubItems[IdxAmount].Tag;
                    decimal   interest     = (decimal)item.SubItems[IdxInterest].Tag;
                    int       gracePeriod  = (int)item.SubItems[IdxGracePeriod].Tag;
                    int       installments = (int)item.SubItems[IdxInstallments].Tag;
                    DateTime  date         = Convert.ToDateTime(item.SubItems[IdxCreationDate].Tag);

                    //creation of loan
                    loan = new Loan(_product,
                                    amount,
                                    interest,
                                    installments,
                                    gracePeriod,
                                    date,
                                    _village.MeetingDay,
                                    User.CurrentUser,
                                    ServicesProvider.GetInstance().GetGeneralSettings(),
                                    ServicesProvider.GetInstance().GetNonWorkingDate(),
                                    CoreDomainProvider.GetInstance().GetProvisioningTable(),
                                    CoreDomainProvider.GetInstance().GetChartOfAccounts())
                    {
                        NonRepaymentPenalties =
                        {
                            InitialAmount    = _product.NonRepaymentPenalties.InitialAmount ?? 0,
                            OLB              = _product.NonRepaymentPenalties.OLB ?? 0,
                            OverDuePrincipal = _product.NonRepaymentPenalties.OverDuePrincipal ?? 0,
                            OverDueInterest  = _product.NonRepaymentPenalties.OverDueInterest ?? 0
                        },
                        InstallmentType = _product.InstallmentType,
                        AnticipatedTotalRepaymentPenalties = 0,
                        FundingLine           = item.SubItems[IdxFundingLine].Tag as FundingLine,
                        LoanOfficer           = (User)item.SubItems[IdxLoanOfficer].Tag,
                        Synchronize           = false,
                        ContractStatus        = OContractStatus.Pending,
                        CreditCommitteeCode   = string.Empty,
                        GracePeriod           = gracePeriod,
                        GracePeriodOfLateFees = _product.GracePeriodOfLateFees,
                        AmountMin             = member.Product.AmountMin,
                        AmountMax             = member.Product.AmountMax,
                        InterestRateMin       = member.Product.InterestRateMin,
                        InterestRateMax       = member.Product.InterestRateMax,
                        NmbOfInstallmentsMin  = member.Product.NbOfInstallmentsMin,
                        NmbOfInstallmentsMax  = member.Product.NbOfInstallmentsMax,
                        ScheduleType          = member.Product.LoanType,
                        ScriptName            = member.Product.ScriptName
                    };
                    loan.InstallmentList =
                        ServicesProvider.GetInstance().GetContractServices().SimulateScheduleCreation(loan);
                    loan.LoanEntryFeesList = new List <LoanEntryFee>();
                    foreach (EntryFee fee in loan.Product.EntryFees)
                    {
                        LoanEntryFee loanEntryFee = new LoanEntryFee();
                        loanEntryFee.ProductEntryFee   = fee;
                        loanEntryFee.ProductEntryFeeId = (int)fee.Id;
                        if (fee.Value.HasValue)
                        {
                            loanEntryFee.FeeValue = (decimal)fee.Value;
                        }
                        else
                        {
                            loanEntryFee.FeeValue = (decimal)fee.Min;
                        }
                        loan.LoanEntryFeesList.Add(loanEntryFee);
                    }

                    var client = member.Tiers;
                    if (0 == client.Projects.Count)
                    {
                        project           = new Project("Village");
                        project.Name      = "Village";
                        project.Code      = "Village";
                        project.Aim       = "Village";
                        project.BeginDate = date;
                        project.Id        = ServicesProvider.GetInstance().GetProjectServices().SaveProject(project, client);
                        member.Tiers.AddProject(project);
                    }
                    project = client.Projects[0];

                    // Compulsory savings
                    if (_product.UseCompulsorySavings)
                    {
                        loan.CompulsorySavings           = (SavingBookContract)item.SubItems[IdxCompulsorySavings].Tag;
                        loan.CompulsorySavingsPercentage = (int)item.SubItems[IdxCompulsoryPercentage].Tag;
                    }
                    var person = client as Person;
                    if (person == null)
                    {
                        throw new ApplicationException("Member can not be other than person.");
                    }
                    loan.EconomicActivity =
                        ServicesProvider.GetInstance()
                        .GetEconomicActivityServices()
                        .FindAllEconomicActivities(true)
                        .FirstOrDefault();

                    ServicesProvider.GetInstance().GetContractServices().CheckLoanFilling(loan);
                    loan.NsgID = _village.Id;
                    ServicesProvider.GetInstance().GetContractServices().SaveLoan(ref loan, project.Id, ref client);
                    project.AddCredit(loan, loan.ClientType);
                    if (!_village.Active)
                    {
                        _village.Active = true;
                        ServicesProvider.GetInstance().GetContractServices().UpdateVillageStatus(_village);
                    }
                    loan.Closed   = false;
                    client.Active = true;
                    client.Status = OClientStatus.Active;
                    member.ActiveLoans.Add(loan);
                }
            }
            catch (Exception ex)
            {
                isError             = true;
                loan.ContractStatus = OContractStatus.Pending;
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }

            if (!isError)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Ejemplo n.º 43
0
 public void Repay(Installment pInstallment, ref OCurrency pAmountPaid, ref OCurrency pInterestEvent, ref OCurrency pInterestPrepayment)
 {
     //Nothing to modify
 }
Ejemplo n.º 44
0
 private void CloseAndTransfer(ISavingsContract from, ISavingsContract to, DateTime date, User pUser,
                               OCurrency amount, bool pIsDesactivateFees, Teller teller)
 {
     from.Transfer(to, amount, 0, date, "Closing transfer");
     from.Close(date, pUser, "Close savings contract", pIsDesactivateFees, teller, true);
 }
 public void RepayNextInstallments(ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency interestPrepayment, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
 {
     _repayNextInstallments.RepayNextInstallments(ref amountPaid, ref interestEvent,ref interestPrepayment, ref principalEvent, ref feesEvent, ref commissionsEvent);
     PaidInstallments = _repayNextInstallments.PaidInstallments;
 }
Ejemplo n.º 46
0
        public void Repay(ref OCurrency pAmountPaid, ref OCurrency pFeesEvent, ref OCurrency pCommissionsEvent, ref OCurrency pInterestEvent)
        {
            if (_cco.CancelFees && (_cco.ManualFeesAmount + _cco.ManualCommissionAmount) >= 0)
            {
                pCommissionsEvent = _cco.ManualCommissionAmount;
                pFeesEvent        = _cco.ManualFeesAmount;

                if (AmountComparer.Compare(pAmountPaid, _cco.ManualFeesAmount + _cco.ManualCommissionAmount) > 0)
                {
                    //pAmountPaid -= _cco.ManualFeesAmount + _cco.ManualCommissionAmount;
                }
                else
                {
                    pAmountPaid = 0;
                }
            }

            if (_cco.KeepExpectedInstallments)
            {
                if (_cco.CancelInterests && _cco.ManualInterestsAmount >= 0)
                {
                    OCurrency manualInterestAmount = _cco.ManualInterestsAmount;
                    for (int i = 0; i < _contract.NbOfInstallments; i++)
                    {
                        Installment installment = _contract.GetInstallment(i);
                        if (!installment.IsRepaid && pAmountPaid > 0 && manualInterestAmount > 0)
                        {
                            OCurrency interestHasToPay = installment.InterestsRepayment - installment.PaidInterests;
                            if (AmountComparer.Compare(manualInterestAmount, interestHasToPay) > 0)
                            {
                                pInterestEvent           += interestHasToPay;
                                installment.PaidInterests = installment.InterestsRepayment;
                                pAmountPaid          -= interestHasToPay;
                                manualInterestAmount -= interestHasToPay;
                            }
                            else
                            {
                                pInterestEvent            += manualInterestAmount;
                                installment.PaidInterests += manualInterestAmount;
                                pAmountPaid         -= manualInterestAmount;
                                manualInterestAmount = 0;
                            }

                            PaidIstallments.Add(installment);
                        }
                    }
                }
            }
        }
Ejemplo n.º 47
0
 private void InvalidateAmounts()
 {
     _amount            = null;
     _realAmount        = null;
     _anticipatedAmount = null;
 }
Ejemplo n.º 48
0
        private static void _AssertInstallment(Loan loan, int number, string date, OCurrency interest, OCurrency principal, OCurrency olb)
        {
            Installment i = loan.GetInstallment(number);

            Assert.AreEqual(DateTime.Parse(date), i.ExpectedDate);
            Assert.AreEqual(interest, i.InterestsRepayment);
            Assert.AreEqual(principal, i.CapitalRepayment);
            Assert.AreEqual(olb, i.OLB);
        }
Ejemplo n.º 49
0
 public void UseManualInterestsAmount(OCurrency pAmount)
 {
     _manualInterestsAmount = _manualInterestsAmount - pAmount;
 }
Ejemplo n.º 50
0
 private static void _AssertRepaymentEvent(RepaymentEvent pEvent, string pCode, DateTime pDate, int pPastDueDays, OCurrency pPrincipal,
                                                  OCurrency pInterest, OCurrency pFees, int pInstallmentNumber)
 {
     Assert.AreEqual(pCode, pEvent.Code);
     Assert.AreEqual(pDate, pEvent.Date);
     Assert.AreEqual(pPastDueDays, pEvent.PastDueDays);
     Assert.AreEqual(pPrincipal.Value, pEvent.Principal.Value);
     Assert.AreEqual(pInterest.Value, pEvent.Interests.Value);
     Assert.AreEqual(pFees.Value, pEvent.Fees.Value);
     Assert.AreEqual(pInstallmentNumber, pEvent.InstallmentNumber);
 }
Ejemplo n.º 51
0
        private void lvContracts_SubItemEndEditing(object sender, UserControl.SubItemEndEditingEventArgs e)
        {
            if (4 == e.SubItem && e.Item.Tag != null)
            {
                e.Item.SubItems[e.SubItem].Tag  = (OCurrency)decimal.Parse(e.DisplayText);
                e.Item.SubItems[e.SubItem].Text = e.DisplayText;
            }
            if (5 == e.SubItem && e.Item.Tag != null)
            {
                e.Item.SubItems[e.SubItem].Tag  = (OCurrency)decimal.Parse(e.DisplayText);
                e.Item.SubItems[e.SubItem].Text = e.DisplayText;
            }

            var loan = new Loan();

            if (4 == e.SubItem || 5 == e.SubItem || 9 == e.SubItem && e.Item.Tag != null)
            {
                loan = e.Item.Tag as Loan;
            }

            if (loan != null && loan.Id != 0)
            {
                Installment i           = loan.GetFirstUnpaidInstallment();
                bool        disableFees = false;
                var         result      = new KeyValuePair <Loan, RepaymentEvent>();

                OCurrency penalties = (OCurrency)e.Item.SubItems[4].Tag;
                OCurrency principal = result.Value == null ? i.PrincipalHasToPay : result.Value.Principal;
                OCurrency interest  = result.Value == null ? i.InterestHasToPay : result.Value.InterestPrepayment;
                OCurrency total;

                if (penalties != loan.CalculateDuePenaltiesForInstallment(i.Number, TimeProvider.Today))
                {
                    disableFees = true;
                }

                total = (OCurrency)e.Item.SubItems[5].Tag;
                if (e.SubItem == 5)
                {
                    if (total < 0)
                    {
                        throw new ArithmeticException("Total cannot be negative.");
                    }
                    if (total > penalties)
                    {
                        OCurrency remainder = total - penalties;
                        if (remainder > interest)
                        {
                            remainder -= interest;
                            principal  = remainder > principal ? principal : remainder;
                            remainder -= principal;
                            total      = principal + interest + penalties + remainder;
                        }
                        else
                        {
                            interest  = remainder;
                            principal = 0;
                        }
                    }
                    else
                    {
                        penalties = total;
                        principal = 0;
                        interest  = 0;
                    }
                }

                e.Item.SubItems[2].Text = principal.GetFormatedValue(loan.UseCents);
                e.Item.SubItems[2].Tag  = principal;
                e.Item.SubItems[3].Text = interest.GetFormatedValue(loan.UseCents);
                e.Item.SubItems[3].Tag  = interest;
                e.Item.SubItems[4].Text = penalties.GetFormatedValue(loan.UseCents);
                e.Item.SubItems[4].Tag  = penalties;
                e.Item.SubItems[5].Text = total.GetFormatedValue(loan.UseCents);
                e.Item.SubItems[5].Tag  = total;

                if (e.Item.SubItems.Count > 9)
                {
                    e.Item.SubItems[9].Tag = cbItem.SelectedItem;
                }

                if (5 == e.SubItem)
                {
                    e.DisplayText = total.GetFormatedValue(loan.UseCents);
                }

                if (9 == e.SubItem)
                {
                    e.DisplayText = cbItem.SelectedItem.ToString();
                }
                if (10 == e.SubItem)
                {
                    e.Item.SubItems[10].Text = e.DisplayText;
                }


                int paymentOption = cbItem.SelectedIndex + 1;

                KeyValuePair <Loan, RepaymentEvent> keyValuePair = CalculatePrincipalAndInterest(loan,
                                                                                                 total.Value,
                                                                                                 disableFees,
                                                                                                 penalties.Value,
                                                                                                 paymentOption);
                if (keyValuePair.Value != null)
                {
                    e.Item.SubItems[2].Text =
                        keyValuePair.Value.Principal.GetFormatedValue(loan.Product.UseCents);
                    e.Item.SubItems[2].Tag  = keyValuePair.Value.Principal;
                    e.Item.SubItems[3].Text =
                        keyValuePair.Value.Interests.GetFormatedValue(loan.Product.UseCents);
                    e.Item.SubItems[3].Tag  = keyValuePair.Value.Interests;
                    e.Item.SubItems[4].Text =
                        keyValuePair.Value.Penalties.GetFormatedValue(loan.Product.UseCents);
                    e.Item.SubItems[4].Tag = keyValuePair.Value.Penalties;
                }
            }
            UpdateTotal();
        }
Ejemplo n.º 52
0
 private static void _AssertWriteOffEvent(WriteOffEvent pEvent, DateTime pDate, OCurrency pOLB, OCurrency pAccruedInterests, OCurrency pAccruedPenalties,
     int pPastDueDays)
 {
     Assert.AreEqual("WROE", pEvent.Code);
     Assert.AreEqual(pDate, pEvent.Date);
     Assert.AreEqual(pPastDueDays, pEvent.PastDueDays);
     Assert.AreEqual(pOLB.Value, pEvent.OLB.Value);
     Assert.AreEqual(pAccruedInterests.Value, pEvent.AccruedInterests.Value);
     Assert.AreEqual(pAccruedPenalties.Value, pEvent.AccruedPenalties.Value);
 }
Ejemplo n.º 53
0
        public void RepayInstallments(DateTime pDate, ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid == 0) return;
            Installment installment = null;
            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                installment = _contract.GetInstallment(i);
                if (!installment.IsRepaid && installment.ExpectedDate <= pDate)
                {
                    OCurrency interestPrepayment = 0;
                    //commission
                    _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);
                    if (amountPaid == 0) break;

                    //penalty
                    _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);
                    if (amountPaid == 0) break;

                    //interest
                    if (amountPaid == 0) break;
                    _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent, ref interestPrepayment);

                    //principal
                    if (amountPaid == 0)
                    {
                        PaidIstallments.Add(installment);
                        break;
                    }

                    if (AmountComparer.Compare(amountPaid, installment.CapitalRepayment - installment.PaidCapital) > 0)
                    {
                        OCurrency principalHasToPay = installment.CapitalRepayment - installment.PaidCapital;
                        installment.PaidCapital = installment.CapitalRepayment;
                        amountPaid -= principalHasToPay;
                        principalEvent += principalHasToPay;
                    }
                    else
                    {
                        installment.PaidCapital += amountPaid;
                        principalEvent += amountPaid;
                        amountPaid = 0;
                    }

                    PaidIstallments.Add(installment);

                    if (amountPaid == 0)
                        break;
                }
            }

            if (installment != null)
            for(int i = installment.Number; i < _contract.NbOfInstallments; i++)
            {
                _contract.GetInstallment(i).FeesUnpaid = 0;
            }
        }
Ejemplo n.º 54
0
 private static void _AssertReschedulingLoanEvent(RescheduleLoanEvent pEvent, DateTime pDate, OCurrency pAmount, int pNbOfMaturity, int dateOffset)
 {
     Assert.AreEqual("ROLE", pEvent.Code);
     Assert.AreEqual(pDate, pEvent.Date);
     Assert.AreEqual(pAmount.Value, pEvent.Amount.Value);
     Assert.AreEqual(pNbOfMaturity, pEvent.NbOfMaturity);
 }
Ejemplo n.º 55
0
        public void RepayTotalAnticipateInstallments(DateTime pDate, ref OCurrency amountPaid, ref OCurrency interestEvent, ref OCurrency principalEvent, ref OCurrency feesEvent, ref OCurrency commissionsEvent)
        {
            if (amountPaid == 0) return;
            Installment installment = null;

            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                installment = _contract.GetInstallment(i);
                if(!installment.IsRepaid)
                {
                    #region 1 if (installment.ExpectedDate > pDate)
                    if (installment.ExpectedDate > pDate)
                    {
                        //commission
                        if (amountPaid == 0) break;
                        _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                        //fee
                        if (amountPaid == 0) break;
                        _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                        //interest
                        OCurrency interestPrepayment = 0;
                        _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,
                                                             ref interestPrepayment);
                        //principal
                        principalEvent += amountPaid;

                        if (installment.Number != _contract.NbOfInstallments)
                        {
                            OCurrency rpePrincipal = 0;
                            foreach (RepaymentEvent rpe in _contract.Events.GetLoanRepaymentEvents())
                            {
                                if (rpe.InstallmentNumber == installment.Number && !rpe.Deleted)
                                {
                                    rpePrincipal += rpe.Principal;
                                }
                            }

                            if (installment.PaidCapital == rpePrincipal)
                            {
                                rpePrincipal = 0;
                            }

                            installment.PaidCapital = amountPaid + installment.PaidCapital + rpePrincipal;
                            installment.CapitalRepayment = installment.PaidCapital;
                            installment.OLB = 0;
                        }
                        else
                        {
                            installment.PaidCapital = amountPaid;
                        }

                        amountPaid = 0;
                        PaidIstallments.Add(installment);
                        if (amountPaid == 0) break;
                    }
                    #endregion
                    #region 2 if (installment.ExpectedDate <= pDate)
                    if (installment.ExpectedDate <= pDate)
                    {
                        //commission
                        if (amountPaid == 0) break;
                        _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                        //fee
                        if (amountPaid == 0) break;
                        _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                        //interest
                        OCurrency interestPrepayment = 0;
                        _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent,
                                                             ref interestPrepayment);
                        //principal
                        RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                        PaidIstallments.Add(installment);
                        if (amountPaid == 0) break;
                    }
                    #endregion
                }

                #region 3 if (installment.IsRepaid && installment.ExpectedDate > pDate && installment.NotPaidYet)
                if (installment.IsRepaid && installment.ExpectedDate > pDate && installment.NotPaidYet)
                {
                    //commission
                    if (amountPaid == 0) break;
                    _methodToRepayCommission.RepayCommission(installment, ref amountPaid, ref commissionsEvent);

                    //fee
                    if (amountPaid == 0) break;
                    _methodToRepayFees.RepayFees(installment, ref amountPaid, ref feesEvent);

                    //interest
                    OCurrency interestPrepayment = 0;
                    _methodToRepayInterest.RepayInterest(installment, ref amountPaid, ref interestEvent, ref interestPrepayment);

                    //principal
                    RepayPrincipal(installment.Number, ref amountPaid, ref principalEvent, pDate);

                    PaidIstallments.Add(installment);

                    if (amountPaid == 0) break;
                }
                #endregion
            }

            if (installment != null)
            {
                CalculateRemainsInstallmentAfterAtr(installment.Number);
            }
        }
Ejemplo n.º 56
0
 private static void _AssertLoanInterestAccruingEvent(AccruedInterestEvent pEvent, DateTime pDate, OCurrency pInterestPrepayment, OCurrency pAccruedInterest, bool pRescheduled, 
     int pInstallmentNumber, bool pDeleted)
 {
     Assert.AreEqual("LIAE", pEvent.Code);
     Assert.AreEqual(pDate, pEvent.Date);
     Assert.AreEqual(pInterestPrepayment.Value, pEvent.Interest.Value);
     Assert.AreEqual(pAccruedInterest.Value, pEvent.AccruedInterest.Value);
     Assert.AreEqual(pRescheduled, pEvent.Rescheduled);
     Assert.AreEqual(pInstallmentNumber, pEvent.InstallmentNumber);
     Assert.AreEqual(pDeleted, pEvent.Deleted);
 }
Ejemplo n.º 57
0
        public void CalculateAnticipateRepayment(DateTime pDate, OPaymentType pPaymentType, OCurrency paidAmount)
        {
            Installment installment = null;
            OCurrency interests = 0;
            OCurrency commission = 0;
            Installment priorInstallment;
            bool calculated = false;
            OCurrency aTprComission = 0;
            OCurrency willBePaidAmount = 0;
            //to calculate what will be paid before apr or atr
            foreach (Installment willBePaidInstallment in _contract.InstallmentList)
            {
                if(!willBePaidInstallment.IsRepaid && willBePaidInstallment.ExpectedDate <= pDate)
                {
                    willBePaidAmount += willBePaidInstallment.InterestsRepayment - willBePaidInstallment.PaidInterests;
                    willBePaidAmount += willBePaidInstallment.CapitalRepayment - willBePaidInstallment.PaidCapital;
                    willBePaidAmount += willBePaidInstallment.FeesUnpaid;
                }
            }

            for (int i = 0; i < _contract.NbOfInstallments; i++)
            {
                Installment getInstallment = _contract.GetInstallment(i);

                if (!getInstallment.IsRepaid && getInstallment.ExpectedDate > pDate
                    || (getInstallment.ExpectedDate == pDate && _contract.EscapedMember != null))
                {
                    if (installment == null)
                    {
                        installment = getInstallment;

                        if (_generalSettings.AccountingProcesses == OAccountingProcesses.Accrual)
                        {
                            DateTime expectedDate;
                            //int daysInTheInstallment = _contract.NumberOfDaysInTheInstallment(installment.Number, pDate);

                            int daysInTheInstallment = installment.Number == 1
                                                       ? (installment.ExpectedDate - _contract.StartDate).Days
                                                       : (installment.ExpectedDate -
                                                          _contract.GetInstallment(installment.Number - 2).ExpectedDate)
                                                             .Days;

                            if (i == 0)
                            {
                                expectedDate = _contract.StartDate;
                            }
                            else
                            {
                                priorInstallment = _contract.GetInstallment(i - 1);
                                expectedDate = priorInstallment.ExpectedDate;

                                if(_contract.GetLastRepaymentDate() > expectedDate)
                                {
                                    expectedDate = _contract.GetLastRepaymentDate();
                                    daysInTheInstallment = (installment.ExpectedDate - expectedDate).Days;
                                }
                            }

                            if(getInstallment.ExpectedDate == pDate && _contract.EscapedMember != null)
                            {
                                expectedDate = getInstallment.ExpectedDate;
                            }

                            int daySpan = (pDate - expectedDate).Days < 0 ? 0 : (pDate - expectedDate).Days;

                            if (_contract.EscapedMember != null)
                            {
                                //calculate new interes for the person of the group
                                OCurrency amount = _contract.Product.LoanType == OLoanTypes.Flat
                                                  ? _contract.Amount
                                                  : _contract.GetOlb();

                                if (daySpan != 0)
                                {
                                    interests = (amount*_contract.EscapedMember.LoanShareAmount/_contract.Amount)*
                                                daySpan/
                                                daysInTheInstallment*_contract.InterestRate;
                                }
                                else
                                {
                                    interests = (amount * _contract.EscapedMember.LoanShareAmount / _contract.Amount) * _contract.InterestRate;
                                }
                            }
                            else
                            {
                                interests = installment.InterestsRepayment * daySpan / daysInTheInstallment;
                                if (installment.PaidInterests > interests)
                                {
                                    interests = 0;
                                    installment.PaidInterests = 0;
                                }
                            }

                        }
                        else
                        {
                            if (_contract.EscapedMember != null)
                            {
                                if (installment.ExpectedDate == pDate)
                                {
                                    OCurrency amount = _contract.Product.LoanType == OLoanTypes.Flat
                                                           ? _contract.Amount
                                                           : _contract.GetOlb();

                                    interests = (amount*_contract.EscapedMember.LoanShareAmount/_contract.Amount)*
                                                _contract.InterestRate;
                                }
                            }
                            else
                            {

                                interests = installment.InterestsRepayment == installment.PaidInterests
                                                ? installment.InterestsRepayment
                                                : (installment.ExpectedDate > pDate ? 0 : installment.InterestsRepayment);
                            }
                        }
                    }

                    commission += CalculateCommision(pDate, getInstallment.Number, pPaymentType, paidAmount - interests - willBePaidAmount, ref calculated);

                    if (getInstallment.ExpectedDate == pDate && _contract.EscapedMember != null && _contract.Product.AnticipatedTotalRepaymentPenaltiesBase != OAnticipatedRepaymentPenaltiesBases.RemainingInterest)
                        aTprComission = commission;

                    if (getInstallment.ExpectedDate > pDate && _contract.EscapedMember != null && aTprComission > 0 && _contract.Product.AnticipatedTotalRepaymentPenaltiesBase != OAnticipatedRepaymentPenaltiesBases.RemainingInterest)
                        commission = aTprComission;

                    if (_generalSettings.AccountingProcesses == OAccountingProcesses.Cash)
                    {
                        if (installment.PaidInterests > interests)
                        {
                            interests = 0;
                            installment.PaidInterests = 0;
                        }
                    }

                    foreach (RepaymentEvent rPayment in _contract.Events.GetRepaymentEvents())
                    {
                        if (rPayment.Date == pDate && installment.Number == rPayment.InstallmentNumber)
                        {
                            installment.FeesUnpaid = 0;
                        }
                    }
                }
            }

            if (installment != null)
            {
                if (interests == 0 && installment.PaidInterests == 0)
                    installment.NotPaidYet = true;

                installment.InterestsRepayment = _contract.UseCents ? Math.Round(interests.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(interests.Value, 0, MidpointRounding.AwayFromZero);
                installment.CommissionsUnpaid = _contract.UseCents ? Math.Round(commission.Value, 2, MidpointRounding.AwayFromZero) : Math.Round(commission.Value, 0, MidpointRounding.AwayFromZero);
            }
        }
Ejemplo n.º 58
0
 private static void _AssertLoanDisbursmentEvent(LoanDisbursmentEvent pEvent, DateTime pDate, OCurrency pAmount, OCurrency pCommission)
 {
     Assert.AreEqual("LODE", pEvent.Code);
     Assert.AreEqual(pDate, pEvent.Date);
     Assert.AreEqual(pAmount.Value, pEvent.Amount.Value);
 }
Ejemplo n.º 59
0
        private void InitializeControls()
        {
            lvMembers.Items.Clear();
            Color dfc = Color.Gray;
            Color fc  = Color.Black;
            Color bc  = Color.White;

            _fLServices.EmptyTemporaryFLAmountsStorage();

            dtCreationDate.Format       = DateTimePickerFormat.Custom;
            dtCreationDate.CustomFormat = ApplicationSettings.GetInstance("").SHORT_DATE_FORMAT;

            ApplicationSettings generalParameters = ApplicationSettings.GetInstance("");

            decimalPlaces = generalParameters.InterestRateDecimalPlaces;
            ProductServices productServices = ServicesProvider.GetInstance().GetProductServices();
            List <Loan>     listLoan;

            foreach (VillageMember member in _village.Members)
            {
                listLoan = member.ActiveLoans;
                if (listLoan.Count != 0 && !generalParameters.IsAllowMultipleLoans)
                {
                    continue;
                }

                _hasMember = true;
                Person person = (Person)member.Tiers;

                if (_product.CycleId != null)
                {
                    productServices.SetVillageMemberCycleParams(member, _product.Id, person.LoanCycle);
                }
                else
                {
                    member.Product = _product;
                }

                ListViewItem item = new ListViewItem(person.Name)
                {
                    Tag = member
                };
                if (_product.CycleId != null)
                {
                    item.SubItems.Add(person.IdentificationData);
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", member.Product.Amount.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(member.Product.Currency.Code);
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", member.Product.InterestRate.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", member.Product.GracePeriod.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", member.Product.NbOfInstallments.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", true ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add("");
                    item.SubItems.Add("");
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", member.Product.Amount.HasValue ? dfc : fc, bc, item.Font));
                    if (_product.UseCompulsorySavings)
                    {
                        item.SubItems.Add("");
                        item.SubItems.Add(
                            new ListViewItem.ListViewSubItem(item, "", member.Product.CompulsoryAmount.HasValue ? dfc : fc, bc, item.Font));
                    }
                    lvMembers.Items.Add(item);
                    item.SubItems[IdxAmount].Tag       = member.Product.AmountMin;
                    item.SubItems[IdxInterest].Tag     = member.Product.InterestRateMin;
                    item.SubItems[IdxInstallments].Tag = member.Product.NbOfInstallmentsMin;
                    item.SubItems[IdxCurrency].Tag     = member.Product.Currency;
                }
                else
                {
                    item.SubItems.Add(person.IdentificationData);
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.Amount.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(_product.Currency.Code);
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.InterestRate.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.GracePeriod.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.NbOfInstallments.HasValue ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", true ? dfc : fc, bc, item.Font));
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", dfc, bc, item.Font));
                    item.SubItems.Add("");
                    item.SubItems.Add("");
                    item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.Amount.HasValue ? dfc : fc, bc, item.Font));
                    if (_product.UseCompulsorySavings)
                    {
                        item.SubItems.Add("");
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, "", _product.CompulsoryAmount.HasValue ? dfc : fc, bc, item.Font));
                    }
                    lvMembers.Items.Add(item);
                    item.SubItems[IdxCurrency].Tag = member.Product.Currency;
                }
            }
            if (_hasMember)
            {
                OCurrency zero = 0m;
                _itemTotal.Text = GetString("Total");
                _itemTotal.SubItems.Add("");
                _itemTotal.SubItems.Add(zero.GetFormatedValue(true));
                _itemTotal.SubItems.Add("");
                lvMembers.Items.Add(_itemTotal);
            }
            lvMembers.SubItemClicked       += lvMembers_SubItemClicked;
            lvMembers.SubItemEndEditing    += lvMembers_SubItemEndEditing;
            lvMembers.DoubleClickActivation = true;

            if (!_product.GracePeriod.HasValue)
            {
                udGracePeriod.Minimum = _product.GracePeriodMin ?? 0;
                udGracePeriod.Maximum = _product.GracePeriodMax ?? 0;
            }

            if (_product.CycleId == null)
            {
                if (!_product.NbOfInstallments.HasValue)
                {
                    udInstallments.Minimum = _product.NbOfInstallmentsMin ?? 0;
                    udInstallments.Maximum = _product.NbOfInstallmentsMax ?? 0;
                }
            }

            List <User> users = ServicesProvider.GetInstance().GetUserServices().FindAll(false);

            foreach (User user in users)
            {
                cbLoanOfficer.Items.Add(user);
            }

            List <FundingLine> lines = ServicesProvider.GetInstance().GetFundingLinesServices().SelectFundingLines();

            foreach (FundingLine line in lines)
            {
                cbFundingLine.Items.Add(line);
            }

            // Compulsory savings
            if (_product.UseCompulsorySavings)
            {
                if (!_product.CompulsoryAmount.HasValue)
                {
                    udCompulsoryPercentage.Minimum = _product.CompulsoryAmountMin ?? 0;
                    udCompulsoryPercentage.Maximum = _product.CompulsoryAmountMax ?? 0;
                }
            }
        }
 private static void _AssertSelectedViewableBooking(BookingToView pBooking, OBookingDirections pDirection, OCurrency pAmount, DateTime pDate,
                                                    double?pExchangeRate, string pContractCode, string pEventCode)
 {
     Assert.AreEqual(pDirection, pBooking.Direction);
     Assert.AreEqual(pAmount.Value, pBooking.AmountInternal.Value);
     Assert.AreEqual(pDate, pBooking.Date);
     Assert.AreEqual(pExchangeRate, pBooking.ExchangeRate);
     Assert.AreEqual(pContractCode, pBooking.ContractCode);
     Assert.AreEqual(pEventCode, pBooking.EventCode);
 }