private void RecalculateTransactionAmounts(decimal ANewExchangeRate = 0) { string CurrencyCode = FPreviouslySelectedDetailRow.CurrencyCode; DateTime EffectiveDate = FPreviouslySelectedDetailRow.GlEffectiveDate; if (ANewExchangeRate == 0) { if (CurrencyCode == FMainDS.ALedger[0].BaseCurrency) { ANewExchangeRate = 1; } else { ANewExchangeRate = TExchangeRateCache.GetDailyExchangeRate( CurrencyCode, FMainDS.ALedger[0].BaseCurrency, EffectiveDate); } } //Need to get the exchange rate FPreviouslySelectedDetailRow.ExchangeRateToBase = ANewExchangeRate; ((TFrmGiftBatch)ParentForm).GetTransactionsControl().UpdateCurrencySymbols(CurrencyCode); ((TFrmGiftBatch)ParentForm).GetTransactionsControl().UpdateBaseAmount(false); }
private void ResetCurrencyExchangeRate(object sender, EventArgs e) { bool CurrencyCodeHasChanged = false; if (FPetraUtilsObject.SuppressChangeDetection || (FPreviouslySelectedDetailRow == null) || (GetBatchRow().BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return; } CurrencyCodeHasChanged = (FTransactionCurrency != cmbDetailTransactionCurrency.GetSelectedString()); if (CurrencyCodeHasChanged) { FTransactionCurrency = cmbDetailTransactionCurrency.GetSelectedString(); FPreviouslySelectedDetailRow.TransactionCurrency = FTransactionCurrency; FPreviouslySelectedDetailRow.ExchangeRateToBase = TExchangeRateCache.GetDailyExchangeRate( FTransactionCurrency, FMainDS.ALedger[0].BaseCurrency, FBatchRow.DateEffective); if (FPreviouslySelectedDetailRow.ExchangeRateToBase > 0) { RefreshCurrencyAndExchangeRate(); } else { txtDetailExchangeRateToBase.NumberValueDecimal = 0M; btnGetSetExchangeRate.Enabled = true; } } }
private void LookupExchangeRate(Object sender, EventArgs e) { TFrmSetupDailyExchangeRate setupDailyExchangeRate = new TFrmSetupDailyExchangeRate(FPetraUtilsObject.GetForm()); decimal selectedExchangeRate; DateTime selectedEffectiveDate; int selectedEffectiveTime; if (setupDailyExchangeRate.ShowDialog( FLedgerNumber, DateTime.Now, txtCurrency.Text, 1.0m, out selectedExchangeRate, out selectedEffectiveDate, out selectedEffectiveTime) == DialogResult.Cancel) { return; } txtExchangeRate.NumberValueDecimal = selectedExchangeRate; // Put the rate in our client-side cache if (FLedgerRow != null) { TExchangeRateCache.SetDailyExchangeRate(txtCurrency.Text, FLedgerRow.BaseCurrency, selectedEffectiveDate, selectedExchangeRate); } }
private void LookupCurrencyExchangeRates(DateTime ADate) { FExchangeRateToBase = TExchangeRateCache.GetDailyExchangeRate( FBatchRow.CurrencyCode, FMainDS.ALedger[0].BaseCurrency, ADate, true); txtExchangeRateToBase.NumberValueDecimal = FExchangeRateToBase; FExchangeRateIntlToBase = InternationalCurrencyExchangeRate(ADate); }
private void LookupCurrencyExchangeRates(DateTime ADate) { FExchangeRateToBase = TExchangeRateCache.GetDailyExchangeRate( FCurrencyCode, FMainDS.ALedger[0].BaseCurrency, ADate); txtExchangeRateToBase.Text = FExchangeRateToBase.ToString(); FExchangeRateIntlToBase = InternationalCurrencyExchangeRate(ADate); }
private void RunOnceOnActivationManual() { rbtPayFullOutstandingAmount.CheckedChanged += new EventHandler(EnablePartialPayment); chkClaimDiscount.Visible = false; txtExchangeRate.TextChanged += new EventHandler(UpdateTotalAmount); ALedgerRow LedgerRow = ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FLedgerNumber))[0]; FCurrencyTable = (ACurrencyTable)TDataCache.TMCommon.GetCacheableCommonTable(TCacheableCommonTablesEnum.CurrencyCodeList); //txtExchangeRate.SetControlProperties(10); txtBaseAmount.CurrencyCode = LedgerRow.BaseCurrency; TExchangeRateCache.ResetCache(); FocusedRowChanged(null, null); }
private void LookupCurrencyExchangeRates(DateTime ADate, String ACurrencyCode) { decimal ExchangeRateToBase = 1; if (ACurrencyCode != FBaseCurrencyCode) { ExchangeRateToBase = TExchangeRateCache.GetDailyExchangeRate( ACurrencyCode, FBaseCurrencyCode, ADate, true); } if ((txtDetailExchangeRateToBase.NumberValueDecimal.Value != ExchangeRateToBase) || (FPreviouslySelectedDetailRow.ExchangeRateToBase != ExchangeRateToBase)) { txtDetailExchangeRateToBase.NumberValueDecimal = ExchangeRateToBase; FPreviouslySelectedDetailRow.ExchangeRateToBase = ExchangeRateToBase; } FExchangeRateIntlToBase = InternationalCurrencyExchangeRate(ADate); }
private void FocusedRowChanged(System.Object sender, SourceGrid.RowEventArgs e) { DataRowView[] SelectedGridRow = grdPayments.SelectedDataRowsAsDataRowView; if (SelectedGridRow.Length >= 1) { FSelectedPaymentRow = (AccountsPayableTDSAApPaymentRow)SelectedGridRow[0].Row; if (!FSelectedPaymentRow.IsSupplierKeyNull()) { AApSupplierRow supplier = TFrmAPMain.GetSupplier(FMainDS.AApSupplier, FSelectedPaymentRow.SupplierKey); txtCurrency.Text = supplier.CurrencyCode; decimal CurrentRate = TExchangeRateCache.GetDailyExchangeRate(supplier.CurrencyCode, FLedgerRow.BaseCurrency, DateTime.Now); txtExchangeRate.NumberValueDecimal = CurrentRate; cmbPaymentType.SetSelectedString(supplier.PaymentType); if (txtCurrency.Text == FLedgerRow.BaseCurrency) { txtExchangeRate.Enabled = false; btnLookupExchangeRate.Enabled = false; } else { txtExchangeRate.Enabled = true; btnLookupExchangeRate.Enabled = true; } } cmbBankAccount.SetSelectedString(FSelectedPaymentRow.BankAccount); FMainDS.AApDocumentPayment.DefaultView.RowFilter = AccountsPayableTDSAApDocumentPaymentTable.GetPaymentNumberDBName() + " = " + FSelectedPaymentRow.PaymentNumber.ToString(); grdDocuments.DataSource = new DevAge.ComponentModel.BoundDataView(FMainDS.AApDocumentPayment.DefaultView); grdDocuments.Refresh(); grdDocuments.Selection.SelectRow(1, true); FocusedRowChangedDetails(null, null); } }
/// load transactions from a CSV file into the currently selected batch private void CreateBatchFromCSVFile(string ADataFilename, XmlNode ARootNode, AJournalRow ARefJournalRow, Int32 AFirstTransactionRow, string ADefaultCostCentre, out DateTime ALatestTransactionDate) { StreamReader dataFile = new StreamReader(ADataFilename, System.Text.Encoding.Default); XmlNode ColumnsNode = TXMLParser.GetChild(ARootNode, "Columns"); string Separator = TXMLParser.GetAttribute(ARootNode, "Separator"); string DateFormat = TXMLParser.GetAttribute(ARootNode, "DateFormat"); string ThousandsSeparator = TXMLParser.GetAttribute(ARootNode, "ThousandsSeparator"); string DecimalSeparator = TXMLParser.GetAttribute(ARootNode, "DecimalSeparator"); Int32 lineCounter; // read headers for (lineCounter = 0; lineCounter < AFirstTransactionRow - 1; lineCounter++) { dataFile.ReadLine(); } decimal sumDebits = 0.0M; decimal sumCredits = 0.0M; ALatestTransactionDate = DateTime.MinValue; do { string line = dataFile.ReadLine(); lineCounter++; GLBatchTDSATransactionRow NewTransaction = FMainDS.ATransaction.NewRowTyped(true); FMyForm.GetTransactionsControl().NewRowManual(ref NewTransaction, ARefJournalRow); FMainDS.ATransaction.Rows.Add(NewTransaction); foreach (XmlNode ColumnNode in ColumnsNode.ChildNodes) { string Value = StringHelper.GetNextCSV(ref line, Separator); string UseAs = TXMLParser.GetAttribute(ColumnNode, "UseAs"); if (UseAs.ToLower() == "reference") { NewTransaction.Reference = Value; } else if (UseAs.ToLower() == "narrative") { NewTransaction.Narrative = Value; } else if (UseAs.ToLower() == "dateeffective") { NewTransaction.SetTransactionDateNull(); if (Value.Trim().ToString().Length > 0) { try { NewTransaction.TransactionDate = XmlConvert.ToDateTime(Value, DateFormat); if (NewTransaction.TransactionDate > ALatestTransactionDate) { ALatestTransactionDate = NewTransaction.TransactionDate; } } catch (Exception exp) { MessageBox.Show(Catalog.GetString("Problem with date in row " + lineCounter.ToString() + " Error: " + exp.Message)); } } } else if (UseAs.ToLower() == "account") { if (Value.Length > 0) { if (Value.Contains(" ")) { // cut off currency code; should have been defined in the data description file, for the whole batch Value = Value.Substring(0, Value.IndexOf(" ") - 1); } Value = Value.Replace(ThousandsSeparator, ""); Value = Value.Replace(DecimalSeparator, "."); NewTransaction.TransactionAmount = Convert.ToDecimal(Value, System.Globalization.CultureInfo.InvariantCulture); NewTransaction.CostCentreCode = ADefaultCostCentre; NewTransaction.AccountCode = ColumnNode.Name; NewTransaction.DebitCreditIndicator = true; if (TXMLParser.HasAttribute(ColumnNode, "CreditDebit") && (TXMLParser.GetAttribute(ColumnNode, "CreditDebit").ToLower() == "credit")) { NewTransaction.DebitCreditIndicator = false; } if (NewTransaction.TransactionAmount < 0) { NewTransaction.TransactionAmount *= -1.0M; NewTransaction.DebitCreditIndicator = !NewTransaction.DebitCreditIndicator; } if (TXMLParser.HasAttribute(ColumnNode, "AccountCode")) { NewTransaction.AccountCode = TXMLParser.GetAttribute(ColumnNode, "AccountCode"); } if (NewTransaction.DebitCreditIndicator) { sumDebits += NewTransaction.TransactionAmount; } else if (!NewTransaction.DebitCreditIndicator) { sumCredits += NewTransaction.TransactionAmount; } } } } if (!NewTransaction.IsTransactionDateNull()) { NewTransaction.AmountInBaseCurrency = GLRoutines.CurrencyMultiply(NewTransaction.TransactionAmount, TExchangeRateCache.GetDailyExchangeRate( ARefJournalRow.TransactionCurrency, FMainDS.ALedger[0].BaseCurrency, NewTransaction.TransactionDate, false)); // // The International currency calculation is changed to "Base -> International", because it's likely // we won't have a "Transaction -> International" conversion rate defined. // NewTransaction.AmountInIntlCurrency = GLRoutines.CurrencyMultiply(NewTransaction.AmountInBaseCurrency, TExchangeRateCache.GetDailyExchangeRate( FMainDS.ALedger[0].BaseCurrency, FMainDS.ALedger[0].IntlCurrency, NewTransaction.TransactionDate, false)); } } while (!dataFile.EndOfStream); // create a balancing transaction; not sure if this is needed at all??? if (Convert.ToDecimal(sumCredits - sumDebits) != 0) { GLBatchTDSATransactionRow BalancingTransaction = FMainDS.ATransaction.NewRowTyped(true); FMyForm.GetTransactionsControl().NewRowManual(ref BalancingTransaction, ARefJournalRow); FMainDS.ATransaction.Rows.Add(BalancingTransaction); BalancingTransaction.TransactionDate = ALatestTransactionDate; BalancingTransaction.DebitCreditIndicator = true; BalancingTransaction.TransactionAmount = sumCredits - sumDebits; if (BalancingTransaction.TransactionAmount < 0) { BalancingTransaction.TransactionAmount *= -1; BalancingTransaction.DebitCreditIndicator = !BalancingTransaction.DebitCreditIndicator; } if (BalancingTransaction.DebitCreditIndicator) { sumDebits += BalancingTransaction.TransactionAmount; } else { sumCredits += BalancingTransaction.TransactionAmount; } BalancingTransaction.AmountInIntlCurrency = GLRoutines.CurrencyMultiply(BalancingTransaction.TransactionAmount, TExchangeRateCache.GetDailyExchangeRate( ARefJournalRow.TransactionCurrency, FMainDS.ALedger[0].IntlCurrency, BalancingTransaction.TransactionDate, false)); BalancingTransaction.AmountInBaseCurrency = GLRoutines.CurrencyMultiply(BalancingTransaction.TransactionAmount, TExchangeRateCache.GetDailyExchangeRate( ARefJournalRow.TransactionCurrency, FMainDS.ALedger[0].BaseCurrency, BalancingTransaction.TransactionDate, false)); BalancingTransaction.Narrative = Catalog.GetString("Automatically generated balancing transaction"); BalancingTransaction.CostCentreCode = TXMLParser.GetAttribute(ARootNode, "CashCostCentre"); BalancingTransaction.AccountCode = TXMLParser.GetAttribute(ARootNode, "CashAccount"); } ARefJournalRow.JournalCreditTotal = sumCredits; ARefJournalRow.JournalDebitTotal = sumDebits; ARefJournalRow.JournalDescription = Path.GetFileNameWithoutExtension(ADataFilename); ABatchRow RefBatch = (ABatchRow)FMainDS.ABatch.Rows[FMainDS.ABatch.Rows.Count - 1]; RefBatch.BatchCreditTotal = sumCredits; RefBatch.BatchDebitTotal = sumDebits; // todo RefBatch.BatchControlTotal = sumCredits - sumDebits; // csv ! }
/// <summary> /// Reads the selected values from the controls, /// and stores them into the parameter system of FCalculator /// /// </summary> /// <param name="ACalculator"></param> /// <param name="AReportAction"></param> /// <returns>void</returns> public void ReadControls(TRptCalculator ACalculator, TReportActionEnum AReportAction) { int Year = 0; DateTime EndDate = DateTime.Now; DateTime StartDate = DateTime.Now; // TODO int DiffPeriod = 0; //(System.Int32)CbB_YearEndsOn.SelectedItem; // DiffPeriod = DiffPeriod - 12; ACalculator.AddParameter("param_diff_period_i", DiffPeriod); ACalculator.AddParameter("param_start_period_i", 0); ACalculator.AddParameter("param_end_period_i", 0); ACalculator.AddParameter("param_account_hierarchy_c", this.cmbAccountHierarchy.GetSelectedString()); String CurrencyName = ""; String CurrencySelection = this.cmbCurrency.GetSelectedString(); ACalculator.AddParameter("param_currency", CurrencySelection); if (CurrencySelection == Catalog.GetString("Base")) { CurrencyName = FLedgerRow.BaseCurrency; } else if (CurrencySelection == Catalog.GetString("International")) { CurrencyName = FLedgerRow.IntlCurrency; } ACalculator.AddParameter("param_currency_name", CurrencyName); ACalculator.AddParameter("param_period", rbtPeriod.Checked); ACalculator.AddParameter("param_period_breakdown", rbtBreakdown.Checked && rbtBreakdown.Visible); ACalculator.AddParameter("param_period_checked", rbtPeriod.Checked); ACalculator.AddParameter("param_date_checked", rbtDate.Checked); ACalculator.AddParameter("param_quarter_checked", rbtQuarter.Checked); if (rbtQuarter.Checked) { Year = cmbQuarterYear.GetSelectedInt32(); ACalculator.AddParameter("param_year_i", Year); ACalculator.AddParameter("param_real_year", cmbQuarterYear.GetSelectedString(1)); ACalculator.AddParameter("param_real_year_ending", cmbPeriodYear.GetSelectedString(2)); int Quarter = (Int32)StringHelper.TryStrToInt(txtQuarter.Text, 1); ACalculator.AddParameter("param_quarter", (System.Object)(Quarter)); ACalculator.AddParameter("param_start_period_i", (System.Object)(Quarter * 3 - 2)); ACalculator.AddParameter("param_end_period_i", (System.Object)(Quarter * 3)); ACalculator.AddParameter("param_start_date", TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, Quarter * 3 - 2)); EndDate = TRemote.MFinance.GL.WebConnectors.GetPeriodEndDate(FLedgerNumber, Year, DiffPeriod, Quarter * 3); ACalculator.AddParameter("param_end_date", EndDate); //VerificationResult = TFinancialPeriodChecks.ValidQuarter(DiffPeriod, Year, Quarter, "Quarter"); if (AReportAction == TReportActionEnum.raGenerate) { CheckQuarter(Year, Quarter); } dtpStartDate.Date = TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, (Quarter * 3 - 2)); dtpEndDate.Date = TRemote.MFinance.GL.WebConnectors.GetPeriodEndDate(FLedgerNumber, Year, DiffPeriod, Quarter * 3); } else if (rbtPeriod.Checked) { Year = cmbPeriodYear.GetSelectedInt32(); ACalculator.AddParameter("param_year_i", Year); ACalculator.AddParameter("param_real_year", cmbPeriodYear.GetSelectedString(1)); ACalculator.AddParameter("param_real_year_ending", cmbPeriodYear.GetSelectedString(2)); int EndPeriod = (Int32)StringHelper.TryStrToInt(txtEndPeriod.Text, 1); ACalculator.AddParameter("param_end_period_i", EndPeriod); StartDate = TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, EndPeriod); ACalculator.AddParameter("param_start_date", StartDate); EndDate = TRemote.MFinance.GL.WebConnectors.GetPeriodEndDate(FLedgerNumber, Year, DiffPeriod, EndPeriod); ACalculator.AddParameter("param_end_date", EndDate); CheckPeriod(Year, EndPeriod); dtpEndDate.Date = TRemote.MFinance.GL.WebConnectors.GetPeriodEndDate(FLedgerNumber, Year, DiffPeriod, EndPeriod); if (!OnlyEndPeriodShown) { int StartPeriod = (Int32)StringHelper.TryStrToInt(txtStartPeriod.Text, 1); ACalculator.AddParameter("param_start_period_i", StartPeriod); ACalculator.AddParameter("param_start_date", TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, StartPeriod)); if (AReportAction == TReportActionEnum.raGenerate) { CheckPeriod(Year, StartPeriod); if (StartPeriod > EndPeriod) { FPetraUtilsObject.AddVerificationResult(new TVerificationResult( Catalog.GetString("Start Period must not be bigger than End Period."), Catalog.GetString("Invalid Data entered."), TResultSeverity.Resv_Critical)); } } dtpStartDate.Date = TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, StartPeriod); } } else if (rbtDate.Checked) { if (dtpStartDate.Date.HasValue && dtpEndDate.Date.HasValue) { if (dtpStartDate.Date.Value > dtpEndDate.Date.Value) { FPetraUtilsObject.AddVerificationResult(new TVerificationResult( Catalog.GetString("Start Date must not be later than End Date"), Catalog.GetString("Invalid Data entered."), TResultSeverity.Resv_Critical)); } else { ACalculator.AddParameter("param_start_date", dtpStartDate.Date.Value); EndDate = dtpEndDate.Date.Value; ACalculator.AddParameter("param_end_date", EndDate); ACalculator.AddParameter("param_real_year", dtpEndDate.Date.Value.Year); } } } else if (rbtBreakdown.Checked) { Year = cmbBreakdownYear.GetSelectedInt32(); ACalculator.AddParameter("param_real_year", cmbBreakdownYear.GetSelectedString(1)); ACalculator.AddParameter("param_year_i", Year); ACalculator.AddParameter("param_start_date", TRemote.MFinance.GL.WebConnectors.GetPeriodStartDate(FLedgerNumber, Year, DiffPeriod, 1)); EndDate = TRemote.MFinance.GL.WebConnectors.GetPeriodEndDate(FLedgerNumber, Year, DiffPeriod, 12); ACalculator.AddParameter("param_end_date", EndDate); } // true if the selected date is in the current financial year ACalculator.AddParameter("param_current_financial_year", FLedgerRow.CurrentFinancialYear == Year); // // I may need to check whether the selected currency has an exchange rate I can use! if (CurrencyName == FLedgerRow.IntlCurrency) { Decimal IntlRate = TExchangeRateCache.GetDailyExchangeRate(FLedgerRow.BaseCurrency, FLedgerRow.IntlCurrency, EndDate); if (IntlRate == 0) // No exchange rate has been specified { FPetraUtilsObject.AddVerificationResult(new TVerificationResult( Catalog.GetString("International Exchange Rate"), Catalog.GetString("No Exchange Rate is available for the requested period."), TResultSeverity.Resv_Critical)); } } if (Year < 0) { FPetraUtilsObject.AddVerificationResult(new TVerificationResult( Catalog.GetString("Accounting Year was not specified"), Catalog.GetString("Invalid Data entered."), TResultSeverity.Resv_Critical)); } }