Exemplo n.º 1
0
 private void btnLoanShares_Click(object sender, EventArgs e)
 {
     OCurrency oldAmount = null == _credit ? null : _credit.Amount;
     if (!oldAmount.HasValue)
     {
         oldAmount = ServicesHelper.ConvertStringToDecimal(nudLoanAmount.Text, null == _credit ? false : _credit.Product.UseCents);
     }
     _credit = Preview();
     if (null == _credit) return;
     if ((0 == _loanShares.Count || oldAmount != _credit.Amount) && _group.Members.Count > 0)
     {
         _loanShares.Clear();
         InitializeLoanShares();
     }
     _credit.LoanShares = _loanShares;
     LoanSharesForm frm = new LoanSharesForm(_credit, _group);
     if (DialogResult.OK != frm.ShowDialog()) return;
     if (_credit.Id > 0)
     {
         ServicesProvider.GetInstance().GetContractServices().UpdateLoanShares(_credit,
                                                                _groupUserControl.Group.Id);
     }
 }
Exemplo n.º 2
0
        private void buttonLoanDisbursment_Click(object sender, EventArgs e)
        {
            // Collateral & Guarantor
            if (_credit.Product.UseGuarantorCollateral)
            {
                if (!_credit.Product.SetSeparateGuarantorCollateral)
                {
                    if (_totalCollateralAmount + _totalGuarantorAmount <
                        _credit.Amount.Value * _credit.Product.PercentageTotalGuarantorCollateral / 100)
                    {
                        var message = string.Format(ML.GetString(Ressource.ClientForm, "CollateralGuarantorAmountIsNotEnough"),
                                        ServicesHelper.ConvertDecimalToString(_credit.Amount.Value * _credit.Product.PercentageTotalGuarantorCollateral / 100),
                                        _credit.Product.PercentageTotalGuarantorCollateral);
                        Fail(message);
                        return;
                    }
                }
                else
                {
                    if (_totalGuarantorAmount < _credit.Amount.Value * _credit.Product.PercentageSeparateGuarantour / 100)
                    {
                        var message = string.Format(ML.GetString(Ressource.ClientForm, "GuarantorAmountIsNotEnough"),
                                        ServicesHelper.ConvertDecimalToString(_credit.Amount.Value * _credit.Product.PercentageSeparateGuarantour / 100),
                                        _credit.Product.PercentageSeparateGuarantour);
                        Fail(message);
                        return;
                    }

                    if (_totalCollateralAmount < _credit.Amount.Value * _credit.Product.PercentageSeparateCollateral / 100)
                    {
                        var message = string.Format(ML.GetString(Ressource.ClientForm, "CollateralAmountIsNotEnough"),
                                        ServicesHelper.ConvertDecimalToString(_credit.Amount.Value * _credit.Product.PercentageSeparateCollateral / 100),
                                        _credit.Product.PercentageSeparateCollateral);
                        Fail(message);

                        return;
                    }
                }
            }

            // Compulsory savings
            if (_credit.Product.UseCompulsorySavings)
            {
                _credit.CompulsorySavings = SavingServices.GetSavingForLoan(_credit.Id, true);
                if (_credit.CompulsorySavings != null)
                {
                    decimal savingsBalance = 0;
                    decimal totalAmountPercentage = 0;
                    savingsBalance = _credit.CompulsorySavings.GetBalance().Value;

                    foreach (Loan assosiatedLoan in _credit.CompulsorySavings.Loans)
                    {
                        if (assosiatedLoan.CompulsorySavingsPercentage != null && (assosiatedLoan.ContractStatus == OContractStatus.Active ||
                            assosiatedLoan.ContractStatus == OContractStatus.Validated))
                            totalAmountPercentage += (assosiatedLoan.Amount.Value * ((decimal)assosiatedLoan.CompulsorySavingsPercentage / 100));
                    }
                    if (totalAmountPercentage > savingsBalance)
                    {
                        var message = string.Format(ML.GetString(Ressource.ClientForm, "BalanceIsNotEnough"),
                            new OCurrency(savingsBalance).GetFormatedValue(_credit.Product.UseCents),
                            new OCurrency(totalAmountPercentage).GetFormatedValue(_credit.Product.UseCents));
                        Fail(message);
                        return;
                    }
                }
                else
                {
                    Fail(MultiLanguageStrings.GetString(Ressource.ClientForm, "LoanRequiresCompulsory"));
                    return;
                }
            }

            // Group
            if (_group != null)
            {
                //update loan shares from database
                if (_credit.Id > 0 && 0 == _loanShares.Count)
                {
                    _loanShares = ServicesProvider.GetInstance().GetContractServices().GetLoanShares(_credit.Id);
                }

                _credit = Preview();

                if (_loanShares.Count == 0 || _group.Members.Count != _loanShares.Count)
                    InitializeLoanShares();
                else
                    _credit.LoanShares = _loanShares;

                if (_group != null && !AreSharesUpToDate())
                {
                    LoanSharesForm frm = new LoanSharesForm(_credit, _group);
                    if (frm.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                }
            }

            Disburse();
        }
Exemplo n.º 3
0
        private void buttonLoanSave_Click(object sender, EventArgs e)
        {
            if (!btnSaveLoan.Enabled || !btnUpdateSettings.Enabled)
            {
                if (!btnSaveLoan.Enabled)
                    tabControlPerson.SelectedTab = tabPageLoansDetails;
                else if (!btnUpdateSettings.Enabled)
                    tabControlPerson.SelectedTab = tabPageAdvancedSettings;
                Fail(ML.GetString(Ressource.ClientForm, "ParametersAreWrong"));
                return;
            }

            _credit = Preview();

            // Compulsory savings
            if (_credit != null)
            {
                if (_credit.Product.UseCompulsorySavings && sender == btnUpdateSettings)
                {
                    if (_credit.CompulsorySavings == null)
                    {
                        Fail(ML.GetString(Ressource.ClientForm, "CumpolsorySavingIsMandatory"));
                        return;
                    }
                }

                if (_group != null && !AreSharesUpToDate())
                {
                    // Opening loan shares

                    //update loan shares from database
                    if (_credit.Id > 0 && 0 == _loanShares.Count)
                        _loanShares = ServicesProvider.GetInstance().GetContractServices().GetLoanShares(_credit.Id);

                    OCurrency sum = _loanShares.Sum(item => item.Amount.Value);
                    if (_loanShares.Count == 0 || sum != _credit.Amount)
                        InitializeLoanShares();

                    _credit.LoanShares = _loanShares;

                    var frm = new LoanSharesForm(_credit, _group);
                    if (DialogResult.OK != frm.ShowDialog())
                        return;
                }
            }

            if (_credit != null)
                SaveContract();
        }