Esempio n. 1
0
        private void BSaveClick(object sender, EventArgs e)
        {
            nudAmount_ValueChanged(sender, e);
            bool pending = cbxPending.Visible && cbxPending.Checked;
            bool?local   = null;

            local = rbxLocal.Visible && rbxLocal.Checked;

            try
            {
                _date = new DateTime(dtpDate.Value.Year, dtpDate.Value.Month, dtpDate.Value.Day, TimeProvider.Now.Hour,
                                     TimeProvider.Now.Minute, TimeProvider.Now.Second);

                AccountServices savingServices = ServicesProvider.GetInstance().GetAccountServices();

                if (_saving.Events.Find(ev => ev.Code == OSavingEvents.SavingClosure &&
                                        ev.Date.Date >= _date.Date && ev is SavingClosureEvent) != null)
                {
                    savingServices.CanPostAfterClosureEvent();
                }

                List <SavingEvent> savingEvents = new List <SavingEvent>();

                if (_date.Date < TimeProvider.Today.Date)
                {
                    savingServices.PerformBackDateOperations(_date);
                }
                else if (_date.Date > TimeProvider.Today.Date)
                {
                    savingServices.PerformFutureDateOperations(_date);
                }

                if (_saving.HasPendingEvents())
                {
                    if (!savingServices.AllowOperationsDuringPendingDeposit())
                    {
                        return;
                    }
                }

                if ((_flatFees.HasValue && updAmountFees.Value != _flatFees) || (_rateFees.HasValue && updAmountFees.Value != (decimal)(_rateFees * 100)))
                {
                    if (!savingServices.AllowSettingSavingsOperationsFeesManually())
                    {
                        return;
                    }
                }

                switch (_bookingDirection)
                {
                case OSavingsOperation.Credit:
                {
                    OSavingsMethods savingsMethod =
                        (OSavingsMethods)
                        Enum.Parse(typeof(OSavingsMethods), "Cash");
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;
                    if (_saving is SavingBookContract)
                    {
                        if (savingsMethod == OSavingsMethods.Cheque)
                        {
                            ((SavingBookContract)_saving).ChequeDepositFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).DepositFees = updAmountFees.Value;
                        }

                        //modified
                        OCurrency dutyStampFeeMin = Convert.ToDecimal(ApplicationSettings.GetInstance("").GetSpecificParameter(OGeneralSettings.STAMP_DUTY_VALID_ABOVE));
                        if (_amount < dutyStampFeeMin)
                        {
                            ((SavingBookContract)_saving).DutyStampFees = 0;
                        }
                    }

                    savingEvents = savingServices.Deposit(_saving, _date, _amount, _description, _referenceNumber, User.CurrentUser, pending, local,
                                                          savingsMethod, paymentMethod, null, Teller.CurrentTeller);
                    break;
                }

                case OSavingsOperation.Debit:
                {
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatWithdrawFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateWithdrawFees = (double)(updAmountFees.Value / 100);
                        }


                        OCurrency _feesMin, _feesMax;
                        decimal   value = _flatAMFees.HasValue ? _flatAMFees.Value : ((decimal)(_rateAMFees)) * 100;

                        if (((SavingsBookProduct)_saving.Product).FlatAMFees.HasValue ||
                            ((SavingsBookProduct)_saving.Product).FlatAMFeesMin.HasValue)
                        {
                            if (((SavingsBookProduct)_saving).FlatAMFees.HasValue)
                            {
                                _feesMin = ((SavingsBookProduct)_saving.Product).FlatAMFees;
                                _feesMax = ((SavingsBookProduct)_saving.Product).FlatAMFees;
                            }
                            else
                            {
                                _feesMin = ((SavingsBookProduct)_saving.Product).FlatAMFeesMin;
                                _feesMax = ((SavingsBookProduct)_saving.Product).FlatAMFeesMax;
                            }

                            OCurrency amFee = value <_feesMin || value> _feesMax ? _feesMin : value;
                            ((SavingBookContract)_saving).FlatAMFees = amFee;
                        }
                        else
                        {
                            if (((SavingsBookProduct)_saving.Product).RateAMFees.HasValue)
                            {
                                _feesMin = (decimal)((SavingsBookProduct)_saving.Product).RateAMFees * 100;
                                _feesMax = (decimal)((SavingsBookProduct)_saving.Product).RateAMFees * 100;
                            }
                            else
                            {
                                _feesMin = (decimal)((SavingsBookProduct)_saving.Product).RateAMFeesMin * 100;
                                _feesMax = (decimal)((SavingsBookProduct)_saving.Product).RateAMFeesMax * 100;
                            }

                            var amFee = value <_feesMin || value> _feesMax ? _feesMin : value;
                            ((SavingBookContract)_saving).RateAMFees = (double)(amFee.Value / 100);
                        }
                    }

                    savingEvents = savingServices.Withdraw(_saving, _date, _amount, _description, _referenceNumber, User.CurrentUser,
                                                           Teller.CurrentTeller, paymentMethod);
                    break;
                }

                case OSavingsOperation.Transfer:
                {
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatTransferFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateTransferFees = (double)(updAmountFees.Value / 100);
                        }
                    }
                    decimal fee = nudTotalAmount.Value - nudAmount.Value;
                    savingEvents = savingServices.Transfer(_saving, _savingTarget, _date, _amount, fee, _description, _referenceNumber,
                                                           User.CurrentUser, false);
                    break;
                }

                case OSavingsOperation.SpecialOperation:
                {
                    OSavingsMethods savingsMethod =
                        (OSavingsMethods)
                        Enum.Parse(typeof(OSavingsMethods), ((PaymentMethod)cbSavingsMethod.SelectedItem).Name);
                    if (cbBookings.SelectedItem != null)
                    {
                        Booking booking = (Booking)cbBookings.SelectedItem;
                        booking.Branch = _saving.Branch;
                        savingServices.SpecialOperation(_saving, _date, _amount, _description, User.CurrentUser,
                                                        savingsMethod, rbxCredit.Checked, booking);
                        break;
                    }
                    throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.TransactionInvalid);
                }
                }


                try
                {
                    //slycode
                    MessagingService messagingService = new MessagingService(Person);

                    foreach (SavingEvent savingEvent in savingEvents)
                    {
                        if (!(savingEvent is SavingInstrumentFeeEvent ||
                              savingEvent is SavingSearchFeeEvent
                              //|| savingEvent is SavingDutyStampFeeEvent
                              || savingEvent is SavingAMFeeEvent))
                        {
                            messagingService.SendNotification(savingEvent, _saving, _bookingDirection.Description());
                        }
                    }
                }
                catch (Exception exc)
                {
                    new frmShowError(CustomExceptionHandler.ShowExceptionText(exc)).ShowDialog();
                }

                Close();
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }