예제 #1
0
 public void TestConvertAmountToExternalCurrency()
 {
     _accountingServices = new OpenCBS.Services.Accounting.AccountingServices(DataUtil.TESTDB);
     OCurrency amount = 100;
     ExchangeRate rate = new ExchangeRate {Date = DateTime.Today, Rate = 3, Currency = new Currency {Id = 1}};
     Assert.AreEqual(33.3333m, _accountingServices.ConvertAmountToExternalCurrency(amount, rate).Value);
 }
 public LoanDisbursementForm(Loan pLoan)
 {
     _loan = pLoan;
     _exchangeRate = null;
     InitializeComponent();
     Initialization();
 }
예제 #3
0
 public FrmFundingLineEvent(FundingLine pFundingLine)
 {
     InitializeComponent();
     _FundingLine = pFundingLine;
     _exchangeRate=null;
     _fundingLineEvent = new FundingLineEvent();
     InitializeComboBoxDirections();
     dateTimePickerEvent.Value = TimeProvider.Now;
 }
예제 #4
0
		public ExchangeRateForm()
		{
            InitializeComponent();
		   
		    _exchangeRate = null;
		    _initializeDate = null;
		    _currency = null;
		    _date = TimeProvider.Today;
            mCRate.SetDate(_date); 
		    _InitializeSecurity();
         }
예제 #5
0
 public FrmFundingLineEvent(FundingLine pFundingLine)
 {
     InitializeComponent();
     _FundingLine = pFundingLine;
     _exchangeRate=null;
     _fundingLineEvent = new FundingLineEvent();
     InitializeComboBoxDirections();
     dateTimePickerEvent.Value = TimeProvider.Now;
     dateTimePickerEvent.Format = DateTimePickerFormat.Custom;
     dateTimePickerEvent.CustomFormat = ApplicationSettings.GetInstance("").SHORT_DATE_FORMAT;
 }
예제 #6
0
		public ExchangeRateForm(DateTime pDate, Currency pCurrency)
		{
            InitializeComponent();
            _exchangeRate = null;
		    _initializeDate = pDate;
		    _currency = pCurrency;
            _date = pDate;
            if(!mCRate.SelectionStart.Date.Equals(_date.Date))
                mCRate.SetDate(_date);
            _InitializeSecurity();
           
		}
        private bool InitializeLoanDisburseEvent()
        {
            try
            {
                _loanDisbursmentEvent = ServicesProvider.GetInstance().GetContractServices().DisburseSimulation(_loan,
                                                                                                                _alignInstallmentsDatesOnRealDisbursmentDate,
                                                                                                                _newStartDate,
                                                                                                                _disableFees);

                if (_loanDisbursmentEvent != null)
                {
                    _lbAmountValue.Text = _loanDisbursmentEvent.Amount.GetFormatedValue(_loan.UseCents);
                    lblAmountCurrency.Text = _loan.Product.Currency.Code;
                    _lbLoanCodeValue.Text = _loan.Code;
                    if (!_feeModified)
                        SetFeeAmount();
                    lblEntryFeeCurrency.Text = _loan.Product.Currency.Code;
                    InitializeExternalCurrency();
                }
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
                _exchangeRate = null;
                InitializeExternalCurrency();
                return false;
            }
            return true;
        }
        private bool CheckDateChange()
        {
            _exchangeRate = null;
            if (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies().Count == 1)
            {
                _exchangeRate = new ExchangeRate
                                    {
                                        Currency = _loan.Product.Currency,
                                        Date = _newStartDate,
                                        Rate = 1
                                    };
            }
            buttonSave.Enabled = false;

            try
            {
                if (!ServicesProvider.GetInstance().GetExchangeRateServices().RateExistsForEachCurrency
                         (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies(), _newStartDate))
                {
                    buttonAddExchangeRate.Enabled = lblPivotCurrency.Enabled;
                    var xrForm =
                        new ExchangeRateForm(new DateTime(_newStartDate.Year, _newStartDate.Month, _newStartDate.Day),
                                             _loan.Product.Currency);
                    xrForm.ShowDialog();
                }
                _exchangeRate = ServicesProvider.GetInstance().GetAccountingServices().FindExchangeRate(_newStartDate,
                                                                                                        _loan.Product.
                                                                                                            Currency);
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
            finally
            {
                if (_exchangeRate != null)
                {
                    buttonSave.Enabled = true;
                    lblPivotCurrency.Visible =
                        ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies().Count > 1 &&
                        !_loan.Product.Currency.IsPivot;
                    lblFeesCurrencyPivot.Visible = lblPivotCurrency.Visible;
                    buttonAddExchangeRate.Visible = false;
                }
                else
                {
                    buttonSave.Enabled = false;
                    buttonAddExchangeRate.Enabled = true;
                    lblPivotCurrency.Visible = true;
                    lblFeesCurrencyPivot.Visible = true;
                }
            }
            bool lde = InitializeLoanDisburseEvent();
            return lde;
        }
예제 #9
0
        private void SetExchangeRate()
        {
            _exchangeRate = null;
            if (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies().Count == 1)
            {
                _exchangeRate = new ExchangeRate
                                    {
                                        Currency = _loan.Product.Currency,
                                        Date = TimeProvider.Today,
                                        Rate = 1
                                    };
            }

            try
            {
                if (!ServicesProvider.GetInstance().GetExchangeRateServices().RateExistsForEachCurrency
                    (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies(), _date.Date))
                {
                    _btAddExchangeRate.Enabled = panelEC.Enabled = true;
                    ExchangeRateForm _xrForm = new ExchangeRateForm(new DateTime(_date.Year, _date.Month, _date.Day), _loan.Product.Currency);
                    _xrForm.ShowDialog();
                }
                _exchangeRate = ServicesProvider.GetInstance().GetAccountingServices().FindExchangeRate(_date.Date, _loan.Product.Currency);

            }
            catch(Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
            finally
            {
                if (_exchangeRate != null)
                {
                     panelEC.Visible = ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies().Count > 1 && !_loan.Product.Currency.IsPivot;
                    _btAddExchangeRate.Visible = false;
                }
                else
                {
                    panelEC.Visible = false;
                   _btAddExchangeRate.Enabled = true;
                }
                DisplayAmountLabel();
                DisplayInstallmentsAndEvent();

                if(!_manualAmountWasEntered)
                    nudICAmount.Value = _loan.CalculateAmountToRepaySpecifiedInstallment(_instalmentNumber, _date.Date, _disableFees, _manualPenalties,
                        _manualCommission, _disableInterests, _manualInterests, _keepExpectedInstallment).Value;

                SetAmount(nudICAmount, _loan.UseCents);
            }
        }
예제 #10
0
        public List<ExchangeRate> SelectRatesByDate(DateTime beginDate, DateTime endDate)
        {
            const string q =
                   @"SELECT
                     exchange_date,
                     exchange_rate,
                     currency_id,
                    is_pivot,
                    is_swapped,
                    name,
                    code
                  FROM ExchangeRates
                  INNER JOIN Currencies ON ExchangeRates.currency_id = Currencies.id
                  WHERE exchange_date BETWEEN @beginDate AND @endDate";

            List<ExchangeRate> rates;
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
            {
                c.AddParam("@beginDate", beginDate.Date);
                c.AddParam("@endDate", endDate.Date);
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    if (r == null || r.Empty) return null;

                    rates = new List<ExchangeRate>();
                    while (r.Read())
                    {
                        ExchangeRate newRate = new ExchangeRate
                        {
                            Date = r.GetDateTime("exchange_date"),
                            Rate = r.GetDouble("exchange_rate"),
                            Currency = new Currency
                            {
                                Id = r.GetInt("currency_id"),
                                IsPivot = r.GetBool("is_pivot"),
                                IsSwapped = r.GetBool("is_swapped"),
                                Name = r.GetString("name"),
                                Code = r.GetString("code")
                            }
                        };
                        rates.Add(newRate);
                    }
                }
            }
            return rates;
        }
예제 #11
0
        public List <Booking> GetBookings(AccountingRuleCollection rules,
                                          EventStock eventStock,
                                          List <Teller> tellers,
                                          List <PaymentMethod> paymentMethods,
                                          List <ExchangeRate> rates,
                                          List <FiscalYear> fiscalYears)
        {
            if (eventStock == null)
            {
                return(new List <Booking>());
            }

            rules.SortByOrder();
            eventStock.SortEventsById();
            bool isExported = false;
            var  bookings   = new List <Booking>();

            foreach (Event eventItem in eventStock)
            {
                ClosureStatus     = "Closure";
                ClosureStatusInfo = " ->" + eventItem.Code + "-" + eventItem.Id;

                var attributes = new List <EventAttribute>();
                List <ContractAccountingRule> rulesToApply =
                    rules.GetContractAccountingRules().Where(item => item.EventType.EventCode == eventItem.Code).ToList();

                rules.SortByOrder();
                List <ContractAccountingRule> orders = rulesToApply.GroupBy(a => a.Order).Select(g => g.Last()).ToList();

                foreach (ContractAccountingRule orderRule in orders)
                {
                    foreach (ContractAccountingRule rule in rulesToApply.Where(r => r.Order == orderRule.Order).ToList())
                    {
                        List <EventAttribute> evtAttributes = (from eventAtt in attributes
                                                               where eventAtt.Name == rule.EventAttribute.Name
                                                               select eventAtt).ToList();

                        if (rule.EventType.EventCode == eventItem.Code &&
                            evtAttributes.Count <= rulesToApply.Count(r => r.Order == orderRule.Order) - 1)
                        {
                            ContractAccountingRule tempRule = rule.Copy();

                            if (paymentMethods != null && eventItem.PaymentMethod != null)
                            {
                                tempRule = GetParentPaymentAccount(eventItem.PaymentMethod.Id, tempRule, paymentMethods);
                            }

                            // teller must be last
                            if (tellers != null && eventItem.TellerId != null)
                            {
                                //that copy is very important because the rule might be over written by payment method
                                tempRule = rule.Copy();
                                tempRule = GetParentTellerAccount(eventItem.TellerId, tempRule, tellers);
                            }

                            Booking b = GetBooking(tempRule, eventItem);
                            if (b != null && b.Amount > 0)
                            {
                                //setting fiscal year
                                if (fiscalYears != null)
                                {
                                    b.FiscalYear =
                                        fiscalYears
                                        .First(
                                            f =>
                                            f.OpenDate <= b.Date.Date &&
                                            (f.CloseDate == null || f.CloseDate >= b.Date.Date)
                                            );
                                }
                                //setting xrate
                                ExchangeRate rate = null;
                                if (rates != null)
                                {
                                    rate = rates.FirstOrDefault(r => r.Date.Date == b.Date.Date);
                                }

                                b.ExchangeRate = b.Currency.IsPivot ? 1 : rate == null ? 0 : rate.Rate;

                                isExported = true;
                                attributes.Add(tempRule.EventAttribute);
                                bookings.Add(b);
                            }
                        }
                    }
                }

                if (eventItem is TellerCashInEvent || eventItem is TellerCashOutEvent)
                {
                    bookings.Add(GetTellerBooking((TellerEvent)eventItem, tellers, fiscalYears));
                }

                eventItem.IsFired = false;
                eventItem.IsFired = isExported;
            }
            return(bookings);
        }
예제 #12
0
        public ExchangeRate FindExchangeRate(DateTime pDate, Currency pCurrency)
        {
            ExchangeRate exchangeRate = null;
            Currency pivot = new CurrencyServices(_user).GetPivot();

            if (!pivot.Equals(pCurrency))
            {
                if (new CurrencyServices(_user).FindAllCurrencies().Count > 1)
                {
                    exchangeRate = _exchangeRateServices.SelectExchangeRate(pDate.Date, pCurrency);
                    if (exchangeRate == null)
                        throw new OpenCbsExchangeRateException(OpenCbsExchangeRateExceptionEnum.ExchangeRateIsNull);
                }
            }
            else
            {
                exchangeRate = new ExchangeRate
                                   {
                                       Currency = pCurrency,
                                       Date = pDate,
                                       Rate = 1
                                   };
            }
            return exchangeRate;
        }
예제 #13
0
 public OCurrency ConvertAmountToExternalCurrency(OCurrency amount, ExchangeRate exchangeRate)
 {
     return amount * 1 / exchangeRate.Rate;
 }
예제 #14
0
        private void SetExchangeRate()
        {
            _exchangeRate = null;
               if (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies().Count == 1)
               {
               _exchangeRate = new ExchangeRate
               {
                   Currency = _FundingLine.Currency,
                   Date = dateTimePickerEvent.Value,
                   Rate = 1
               };
               }
               buttonSave.Enabled = false;

               DateTime _date = dateTimePickerEvent.Value;
               try
               {
               if (!ServicesProvider.GetInstance().GetExchangeRateServices().RateExistsForEachCurrency
                   (ServicesProvider.GetInstance().GetCurrencyServices().FindAllCurrencies(), _date.Date)
                   /*&& (User.CurrentUser.HasAdminRole || User.CurrentUser.HasSuperAdminRole)*/)
               {
                   buttonAddRate.Enabled = true;
                   var _xrForm =
                       new ExchangeRateForm(new DateTime(dateTimePickerEvent.Value.Year, _date.Month, _date.Day),
                           _FundingLine.Currency);
                   _xrForm.ShowDialog();
               }
               _exchangeRate = ServicesProvider.GetInstance().GetAccountingServices().FindExchangeRate(_date.Date, _FundingLine.Currency);
               }
               catch (Exception ex)
               {
               new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
               }
               finally
               {
               if (_exchangeRate != null)
               {
                   buttonSave.Enabled = true;
                   buttonAddRate.Visible = false;
               }
               else
               {
                   buttonSave.Enabled = false;
                   //buttonAddRate.Enabled = User.CurrentUser.isAdmin || User.CurrentUser.isSuperAdmin;
                   buttonAddRate.Enabled = true;
               }

               }
        }
예제 #15
0
        private void _CheckExchangeRate()
        {
            var selectedCur = cbCurrencies.SelectedItem as Currency;

            if (!ServicesProvider.GetInstance().GetCurrencyServices().GetPivot().Equals(selectedCur))
            {
                _rate = ServicesProvider.GetInstance().GetExchangeRateServices().SelectExchangeRate(DateTime.Now, selectedCur);
                
                while (_rate == null)
                {
                    var xrForm = new ExchangeRateForm(DateTime.Now, selectedCur);
                    xrForm.ShowDialog();
                    if (xrForm.ExchangeRate != null)
                    {
                        if (xrForm.ExchangeRate.Currency.Equals(selectedCur) &&
                            xrForm.ExchangeRate.Date.Day.Equals(DateTime.Now.Day))
                            _rate = xrForm.ExchangeRate;
                    }
                }
            }
            else
            {
                _rate = new ExchangeRate(){Rate = 1};
            }
        }
예제 #16
0
        public ExchangeRate FindLatestExchangeRate(DateTime pDate,Currency pCurrency)
        {
            ExchangeRate exchangeRate = null;
             Currency pivot = new CurrencyServices(_user).GetPivot();
            if (!pivot.Equals(pCurrency))
            {
                if (new CurrencyServices(_user).FindAllCurrencies().Count > 1)
                {
                    double rate = _exchangeRateServices.GetMostRecentlyRate(pDate,pCurrency);

                    exchangeRate = new ExchangeRate
                                       {
                                           Currency = pCurrency,
                                           Date = pDate,
                                           Rate = rate
                                       };
                }
            }
            else
            {
                exchangeRate = new ExchangeRate
                {
                    Currency = pCurrency,
                    Date = pDate,
                    Rate = 1
                };
            }
            return exchangeRate;
        }
예제 #17
0
        private void ButtonAddExchangeRateClick(object sender, EventArgs e)
        {
            ExchangeRateForm exchangeRate = new ExchangeRateForm(_newStartDate, _loan.Product.Currency);
            exchangeRate.ShowDialog();

            _exchangeRate = exchangeRate.ExchangeRate;
            InitializeExternalCurrency();
            buttonSave.Enabled = _exchangeRate != null;
        }
예제 #18
0
		private void buttonCancel_Click(object sender, EventArgs e)
		{
            if (_initializeDate.HasValue)
            {
                //check whether exchange rate exists for all currencies
                foreach (Currency _cur in comboBoxCurrencies.Items)
                {
                    if (ServicesProvider.GetInstance().GetExchangeRateServices().SelectExchangeRate(
                            _initializeDate.Value, _cur) != null)
                        continue;
                    MessageBox.Show(MultiLanguageStrings.GetString(Ressource.ExchangeRateForm,
                                                                   "RateIsNullForCurrency.Text") + _cur.Name);
                    return;

                }
                _exchangeRate = _currency == null
                                    ? ServicesProvider.GetInstance().GetExchangeRateServices().SelectExchangeRate(
                                          _initializeDate.Value, comboBoxCurrencies.SelectedItem as Currency)
                                    : (_currency.IsPivot
                                           ? new ExchangeRate
                                                 {
                                                     Currency = _currency,
                                                     Date = _initializeDate.Value,
                                                     Rate = 1
                                                 }
                                           : ServicesProvider.GetInstance().GetExchangeRateServices().SelectExchangeRate
                                                 (
                                                 _initializeDate.Value, _currency)
                                      );
            
            }
		    Close();
		}