Esempio n. 1
0
        public static bool CanDeleteCorporateExchangeRate(DateTime ADateEffectiveFrom, string AIntlCurrency, string ATransactionCurrency)
        {
            bool           ReturnValue     = true;
            TDBTransaction ReadTransaction = new TDBTransaction();
            TDataBase      db = DBAccess.Connect("CanDeleteCorporateExchangeRate");

            db.ReadTransaction(
                ref ReadTransaction,
                delegate
            {
                // get accounting period for when the exchange rate is effective (if it exists)
                string Query = "SELECT * FROM a_accounting_period" +
                               " WHERE a_accounting_period.a_period_end_date_d >= '" + DataUtilities.DateToSQLString(ADateEffectiveFrom) + "'" +
                               " AND a_accounting_period.a_period_start_date_d <= '" + DataUtilities.DateToSQLString(ADateEffectiveFrom) + "'";

                AAccountingPeriodTable AccountingPeriodTable = new AAccountingPeriodTable();
                db.SelectDT(AccountingPeriodTable, Query, ReadTransaction);

                // no accounting period if effective in a year other that the current year
                if ((AccountingPeriodTable == null) || (AccountingPeriodTable.Rows.Count == 0))
                {
                    return;
                }

                AAccountingPeriodRow AccountingPeriodRow = AccountingPeriodTable[0];

                // search for batches for the found accounting period
                string Query2 = "SELECT CASE WHEN EXISTS (" +
                                "SELECT * FROM a_batch, a_journal, a_ledger" +
                                " WHERE a_batch.a_date_effective_d <= '" + DataUtilities.DateToSQLString(
                    AccountingPeriodRow.PeriodEndDate) + "'" +
                                " AND a_batch.a_date_effective_d >= '" + DataUtilities.DateToSQLString(
                    AccountingPeriodRow.PeriodStartDate) + "'" +
                                " AND a_journal.a_ledger_number_i = a_batch.a_ledger_number_i" +
                                " AND a_journal.a_batch_number_i = a_batch.a_batch_number_i" +
                                " AND a_ledger.a_ledger_number_i = a_batch.a_ledger_number_i" +
                                " AND ((a_journal.a_transaction_currency_c = '" + ATransactionCurrency + "'" +
                                " AND a_ledger.a_intl_currency_c = '" + AIntlCurrency + "')" +
                                " OR (a_journal.a_transaction_currency_c = '" + AIntlCurrency + "'" +
                                " AND a_ledger.a_intl_currency_c = '" + ATransactionCurrency + "'))" +
                                ") THEN 'TRUE'" +
                                " ELSE 'FALSE' END";

                DataTable DT = db.SelectDT(Query2, "temp", ReadTransaction);

                // a batch has been found
                if ((DT != null) && (DT.Rows.Count > 0) && (DT.Rows[0][0].ToString() == "TRUE"))
                {
                    ReturnValue = false;
                    return;
                }
            });

            return(ReturnValue);
        }