示例#1
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;
                    }

                    switch (member.Product.LoanType)
                    {
                    case OLoanTypes.All:
                        break;

                    case OLoanTypes.Flat:
                        member.Product.ScriptName = null;
                        break;

                    case OLoanTypes.DecliningFixedPrincipal:
                        member.Product.ScriptName = null;
                        break;

                    case OLoanTypes.DecliningFixedInstallments:
                        member.Product.ScriptName = null;
                        break;

                    case OLoanTypes.CustomLoanType:
                        break;

                    default:
                        break;
                    }

                    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();
            }
        }
        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().GetSavingServices().SaveContract(saving, (Client)member.Tiers);
                    saving = ServicesProvider.GetInstance().GetSavingServices().GetSaving(saving.Id);

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

                    saving = ServicesProvider.GetInstance().GetSavingServices().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();
            }
        }