Beispiel #1
0
        public void Init()
        {
            TPetraServerConnector.Connect("../../etc/TestServer.config");

            // These will be our test ledger numbers
            FTestLedgerList.AddRange(new int[] { 9997, 9998, 9999 });

            // Load existing data
            FMainDS = new GLSetupTDS();

            try
            {
                TDBTransaction transaction = new TDBTransaction();
                TDataBase      db          = DBAccess.Connect("Init");
                db.ReadTransaction(
                    ref transaction,
                    delegate
                {
                    ALedgerAccess.LoadAll(FMainDS, transaction);
                });

                // Check that our test rows are not in the database already
                if (!FindTestRows(FTestLedgerList))
                {
                    // Get the initial number of available ledgers
                    FInitialLedgerCount = TGLSetupWebConnector.GetAvailableLedgers().DefaultView.Count;

                    bool SubmitOK = true;
                    db.WriteTransaction(
                        ref transaction,
                        ref SubmitOK,
                        delegate
                    {
                        // Add our test rows
                        AddTestRow(FTestLedgerList[0], "NUnitTestLedger1", false);
                        AddTestRow(FTestLedgerList[1], "NUnitTestLedger2", true, "JPY");
                        AddTestRow(FTestLedgerList[2], "NUnitTestLedger2", true);

                        // Save these new rows
                        ALedgerAccess.SubmitChanges(FMainDS.ALedger, transaction);
                        FMainDS.AcceptChanges();
                    });

                    FInitSucceeded = true;
                }
            }
            catch (Exception ex)
            {
                FInitExceptionMessage = ex.Message;
            }
        }
        public void Init()
        {
            TPetraServerConnector.Connect("../../etc/TestServer.config");

            // These will be our test ledger numbers
            FTestLedgerList.AddRange(new int[] { 9997, 9998, 9999 });

            // Load existing data
            FMainDS = new GLSetupTDS();

            try
            {
                TDBTransaction transaction = null;
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref transaction,
                                                                          delegate
                {
                    ALedgerAccess.LoadAll(FMainDS, transaction);
                });

                // Check that our test rows are not in the database already
                if (!FindTestRows(FTestLedgerList))
                {
                    // Get the initial number of available ledgers
                    FInitialLedgerCount = TGLSetupWebConnector.GetAvailableLedgers().DefaultView.Count;

                    // Add our test rows
                    AddTestRow(FTestLedgerList[0], "NUnitTestLedger1", false);
                    AddTestRow(FTestLedgerList[1], "NUnitTestLedger2", true, "JPY");
                    AddTestRow(FTestLedgerList[2], "NUnitTestLedger2", true);

                    // Save these new rows
                    ALedgerAccess.SubmitChanges(FMainDS.ALedger, null);
                    FMainDS.AcceptChanges();

                    FInitSucceeded = true;
                }
            }
            catch (Exception ex)
            {
                FInitExceptionMessage = ex.Message;
            }
        }
        public void Init()
        {
            TPetraServerConnector.Connect("../../etc/TestServer.config");

            // These will be our test ledger numbers
            FTestLedgerList.AddRange(new int[] { 9997, 9998, 9999 });

            // Load existing data
            FMainDS = new GLSetupTDS();

            try
            {
                TDBTransaction transaction = null;
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref transaction,
                    delegate
                    {
                        ALedgerAccess.LoadAll(FMainDS, transaction);
                    });

                // Check that our test rows are not in the database already
                if (!FindTestRows(FTestLedgerList))
                {
                    // Get the initial number of available ledgers
                    FInitialLedgerCount = TGLSetupWebConnector.GetAvailableLedgers().DefaultView.Count;

                    // Add our test rows
                    AddTestRow(FTestLedgerList[0], "NUnitTestLedger1", false);
                    AddTestRow(FTestLedgerList[1], "NUnitTestLedger2", true, "JPY");
                    AddTestRow(FTestLedgerList[2], "NUnitTestLedger2", true);

                    // Save these new rows
                    ALedgerAccess.SubmitChanges(FMainDS.ALedger, null);
                    FMainDS.AcceptChanges();

                    FInitSucceeded = true;
                }
            }
            catch (Exception ex)
            {
                FInitExceptionMessage = ex.Message;
            }
        }
Beispiel #4
0
        public static GLSetupTDS LoadAAnalysisAttributes(Int32 ALedgerNumber, Boolean AActiveOnly = false)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GLSetupTDS MainDS = new GLSetupTDS();
            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        AAnalysisTypeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);

                        if (!AActiveOnly)
                        {
                            AFreeformAnalysisAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                            AAnalysisAttributeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        }
                        else
                        {
                            AFreeformAnalysisTable FFTable = new AFreeformAnalysisTable();
                            AFreeformAnalysisRow TemplateFFRow = FFTable.NewRowTyped(false);
                            TemplateFFRow.LedgerNumber = ALedgerNumber;
                            TemplateFFRow.Active = true;
                            AFreeformAnalysisAccess.LoadUsingTemplate(MainDS, TemplateFFRow, Transaction);

                            AAnalysisAttributeTable AATable = new AAnalysisAttributeTable();
                            AAnalysisAttributeRow TemplateAARow = AATable.NewRowTyped(false);
                            TemplateAARow.LedgerNumber = ALedgerNumber;
                            TemplateAARow.Active = true;
                            AAnalysisAttributeAccess.LoadUsingTemplate(MainDS, TemplateAARow, Transaction);
                        }
                    });

                MainDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Beispiel #5
0
        public static GLSetupTDS LoadAccountHierarchies(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GLSetupTDS MainDS = new GLSetupTDS();

            // create template for AGeneralLedgerMaster
            TCacheable CachePopulator = new TCacheable();

            System.Type TypeofTable = null;

            TDBTransaction Transaction = null;

            try
            {
                ALedgerTable ledger = (ALedgerTable)CachePopulator.GetCacheableTable(TCacheableFinanceTablesEnum.LedgerDetails,
                    "",
                    false,
                    ALedgerNumber,
                    out TypeofTable);

                #region Validate Data

                if ((ledger == null) || (ledger.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                            Utilities.GetMethodName(true),
                            ALedgerNumber));
                }

                #endregion Validate Data

                int year = ledger[0].CurrentFinancialYear;
                string costCentreCode = "[" + ALedgerNumber + "]";

                AGeneralLedgerMasterRow template = new AGeneralLedgerMasterTable().NewRowTyped(false);
                template.LedgerNumber = ALedgerNumber;
                template.Year = year;
                template.CostCentreCode = costCentreCode;

                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        ACurrencyAccess.LoadAll(MainDS, Transaction);
                        AAccountHierarchyAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AAccountHierarchyDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AAccountAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AAccountPropertyAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AAnalysisTypeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AAnalysisAttributeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AFreeformAnalysisAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AFeesReceivableAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AFeesPayableAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AGeneralLedgerMasterAccess.LoadUsingTemplate(MainDS, template, Transaction);
                        ASuspenseAccountAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    });

                // set Account BankAccountFlag if there exists a property
                foreach (AAccountPropertyRow accProp in MainDS.AAccountProperty.Rows)
                {
                    if ((accProp.PropertyCode == MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT) && (accProp.PropertyValue == "true"))
                    {
                        MainDS.AAccount.DefaultView.RowFilter = String.Format("{0}='{1}'",
                            AAccountTable.GetAccountCodeDBName(),
                            accProp.AccountCode);
                        GLSetupTDSAAccountRow acc = (GLSetupTDSAAccountRow)MainDS.AAccount.DefaultView[0].Row;
                        acc.BankAccountFlag = true;
                        MainDS.AAccount.DefaultView.RowFilter = "";
                    }
                }

                // set Account SuspenseAccountFlag if there exists a property
                foreach (ASuspenseAccountRow suspenseAccountRow in MainDS.ASuspenseAccount.Rows)
                {
                    GLSetupTDSAAccountRow AccountRow =
                        (GLSetupTDSAAccountRow)MainDS.AAccount.Rows.Find(new object[] { ALedgerNumber, suspenseAccountRow.SuspenseAccountCode });
                    AccountRow.SuspenseAccountFlag = true;
                }

                // Don't include any AnalysisType for which there are no values set
                MainDS.AFreeformAnalysis.DefaultView.Sort = AFreeformAnalysisTable.GetAnalysisTypeCodeDBName(); // "a_analysis_type_code_c";

                foreach (AAnalysisTypeRow typeRow in MainDS.AAnalysisType.Rows)
                {
                    Int32 Idx = MainDS.AFreeformAnalysis.DefaultView.Find(typeRow.AnalysisTypeCode);

                    if (Idx < 0)
                    {
                        typeRow.Delete();
                    }
                }

                // add the YTD Actuals to each account
                foreach (AGeneralLedgerMasterRow generalLedgerMasterRow in MainDS.AGeneralLedgerMaster.Rows)
                {
                    GLSetupTDSAAccountRow AccountRow =
                        (GLSetupTDSAAccountRow)MainDS.AAccount.Rows.Find(new object[] { ALedgerNumber, generalLedgerMasterRow.AccountCode });
                    AccountRow.YtdActualBase = generalLedgerMasterRow.YtdActualBase;

                    if (AccountRow.ForeignCurrencyFlag)
                    {
                        AccountRow.YtdActualForeign = generalLedgerMasterRow.YtdActualForeign;
                    }
                }

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Beispiel #6
0
        public static AFreeformAnalysisTable LoadAFreeformAnalysis(Int32 ALedgerNumber)
        {
            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    AFreeformAnalysisAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                });

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();
            AFreeformAnalysisTable myAT = MainDS.AFreeformAnalysis;
            return myAT;
        }
Beispiel #7
0
        public static GLSetupTDS LoadLedgerInfo(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - Ledger number must be greater than 0"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        AAccountingSystemParameterAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        AAccountingPeriodAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    });

                #region Validate Data

                if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                "Function:{0} Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                            Utilities.GetMethodName(true),
                            ALedgerNumber));
                }
                else if ((MainDS.AAccountingSystemParameter == null) || (MainDS.AAccountingSystemParameter.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                "Function:{0} - Accounting System Parameter data for Ledger number {1} does not exist or could not be accessed!"),
                            Utilities.GetMethodName(true),
                            ALedgerNumber));
                }
                else if ((MainDS.AAccountingPeriod == null) || (MainDS.AAccountingPeriod.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                "Function:{0} - Accounting Period data for Ledger number {1} does not exist or could not be accessed!"),
                            Utilities.GetMethodName(true),
                            ALedgerNumber));
                }

                #endregion Validate Data

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Beispiel #8
0
        public static GLSetupTDS LoadLedgerSettings(Int32 ALedgerNumber, out DateTime ACalendarStartDate,
            out bool ACurrencyChangeAllowed, out bool ACalendarChangeAllowed)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format("Function:{0} - Ledger number must be greater than 0",
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            ACalendarStartDate = DateTime.MinValue;
            ACurrencyChangeAllowed = false;
            ACalendarChangeAllowed = false;

            DateTime CalendarStartDate = ACalendarStartDate;
            bool CurrencyChangeAllowed = ACurrencyChangeAllowed;

            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        AAccountingSystemParameterAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        ALedgerInitFlagAccess.LoadViaALedger(MainDS, ALedgerNumber, null, Transaction);

                        #region Validate Data

                        //ALedgerInitFlag is optional so no need to check
                        //TODO confirm this

                        if ((MainDS.ALedger == null) || (MainDS.ALedger.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "Ledger Data for Ledger number {0} does not exist!"), ALedgerNumber));
                        }
                        else if ((MainDS.AAccountingSystemParameter == null) || (MainDS.AAccountingSystemParameter.Count == 0))
                        {
                            throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                        "AccountingSystemParameter Data for Ledger number {0} does not exist!"), ALedgerNumber));
                        }

                        #endregion Validate Data

                        // retrieve calendar start date (start date of financial year)
                        AAccountingPeriodTable CalendarTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, 1, Transaction);

                        if (CalendarTable.Count > 0)
                        {
                            CalendarStartDate = ((AAccountingPeriodRow)CalendarTable.Rows[0]).PeriodStartDate;
                        }

                        // now check if currency change would be allowed
                        CurrencyChangeAllowed = true;

                        if ((AJournalAccess.CountViaALedger(ALedgerNumber, Transaction) > 0)
                            || (AGiftBatchAccess.CountViaALedger(ALedgerNumber, Transaction) > 0))
                        {
                            // don't allow currency change if journals or gift batches exist
                            CurrencyChangeAllowed = false;
                        }

                        if (AGiftBatchAccess.CountViaALedger(ALedgerNumber, Transaction) > 0)
                        {
                            // don't allow currency change if journals exist
                            CurrencyChangeAllowed = false;
                        }

                        if (CurrencyChangeAllowed)
                        {
                            // don't allow currency change if there are foreign currency accounts for this ledger
                            AAccountTable TemplateTable;
                            AAccountRow TemplateRow;
                            StringCollection TemplateOperators;

                            TemplateTable = new AAccountTable();
                            TemplateRow = TemplateTable.NewRowTyped(false);
                            TemplateRow.LedgerNumber = ALedgerNumber;
                            TemplateRow.ForeignCurrencyFlag = true;
                            TemplateOperators = new StringCollection();
                            TemplateOperators.Add("=");

                            if (AAccountAccess.CountUsingTemplate(TemplateRow, TemplateOperators, Transaction) > 0)
                            {
                                CurrencyChangeAllowed = false;
                            }
                        }
                    });

                ACalendarStartDate = CalendarStartDate;
                ACurrencyChangeAllowed = CurrencyChangeAllowed;
                // now check if calendar change would be allowed
                ACalendarChangeAllowed = IsCalendarChangeAllowed(ALedgerNumber);

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (EFinanceSystemDataTableReturnedNoDataException ex)
            {
                throw new EFinanceSystemDataTableReturnedNoDataException(String.Format("Function:{0} - {1}",
                        Utilities.GetMethodName(true),
                        ex.Message));
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Beispiel #9
0
        public static GLSetupTDS LoadCostCentreHierarchy(Int32 ALedgerNumber)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }

            #endregion Validate Arguments

            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                        ACostCentreAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                        AValidLedgerNumberAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    });

                // Accept row changes here so that the Client gets 'unmodified' rows
                MainDS.AcceptChanges();

                // Remove all Tables that were not filled with data before remoting them.
                MainDS.RemoveEmptyTables();
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return MainDS;
        }
Beispiel #10
0
        public static GLSetupTDS LoadLedgerInfo(Int32 ALedgerNumber)
        {
            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    AAccountingSystemParameterAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    AAccountingPeriodAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                });

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return MainDS;
        }
Beispiel #11
0
        public static GLSetupTDS LoadAccountHierarchies(Int32 ALedgerNumber)
        {
            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    AAccountHierarchyAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AAccountHierarchyDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AAccountAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AAccountPropertyAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AAnalysisTypeAccess.LoadAll(MainDS, Transaction);
                    AAnalysisAttributeAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                    AFreeformAnalysisAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction);
                });

            // set Account BankAccountFlag if there exists a property
            foreach (AAccountPropertyRow accProp in MainDS.AAccountProperty.Rows)
            {
                if ((accProp.PropertyCode == MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT) && (accProp.PropertyValue == "true"))
                {
                    MainDS.AAccount.DefaultView.RowFilter = String.Format("{0}='{1}'",
                        AAccountTable.GetAccountCodeDBName(),
                        accProp.AccountCode);
                    GLSetupTDSAAccountRow acc = (GLSetupTDSAAccountRow)MainDS.AAccount.DefaultView[0].Row;
                    acc.BankAccountFlag = true;
                    MainDS.AAccount.DefaultView.RowFilter = "";
                }
            }

            // Don't include any AnalysisType for which there are no values set
            MainDS.AFreeformAnalysis.DefaultView.Sort = "a_analysis_type_code_c";

            foreach (AAnalysisTypeRow TypeRow in MainDS.AAnalysisType.Rows)
            {
                Int32 Idx = MainDS.AFreeformAnalysis.DefaultView.Find(TypeRow.AnalysisTypeCode);

                if (Idx < 0)
                {
                    TypeRow.Delete();
                }
            }

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return MainDS;
        }
Beispiel #12
0
        public static GLSetupTDS LoadLedgerSettings(Int32 ALedgerNumber, out DateTime ACalendarStartDate,
            out bool ACurrencyChangeAllowed, out bool ACalendarChangeAllowed)
        {
            ACalendarStartDate = DateTime.MinValue;
            ACurrencyChangeAllowed = false;
            ACalendarChangeAllowed = false;

            DateTime CalendarStartDate = ACalendarStartDate;
            bool CurrencyChangeAllowed = ACurrencyChangeAllowed;

            GLSetupTDS MainDS = new GLSetupTDS();

            TDBTransaction Transaction = null;
            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
                {
                    ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    AAccountingSystemParameterAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);
                    ALedgerInitFlagAccess.LoadViaALedger(MainDS, ALedgerNumber, null, Transaction);

                    // retrieve calendar start date (start date of financial year)
                    AAccountingPeriodTable CalendarTable = AAccountingPeriodAccess.LoadByPrimaryKey(ALedgerNumber, 1, Transaction);

                    if (CalendarTable.Count > 0)
                    {
                        CalendarStartDate = ((AAccountingPeriodRow)CalendarTable.Rows[0]).PeriodStartDate;
                    }

                    // now check if currency change would be allowed
                    CurrencyChangeAllowed = true;

                    if ((AJournalAccess.CountViaALedger(ALedgerNumber, Transaction) > 0)
                        || (AGiftBatchAccess.CountViaALedger(ALedgerNumber, Transaction) > 0))
                    {
                        // don't allow currency change if journals or gift batches exist
                        CurrencyChangeAllowed = false;
                    }

                    if (AGiftBatchAccess.CountViaALedger(ALedgerNumber, Transaction) > 0)
                    {
                        // don't allow currency change if journals exist
                        CurrencyChangeAllowed = false;
                    }

                    if (CurrencyChangeAllowed)
                    {
                        // don't allow currency change if there are foreign currency accounts for this ledger
                        AAccountTable TemplateTable;
                        AAccountRow TemplateRow;
                        StringCollection TemplateOperators;

                        TemplateTable = new AAccountTable();
                        TemplateRow = TemplateTable.NewRowTyped(false);
                        TemplateRow.LedgerNumber = ALedgerNumber;
                        TemplateRow.ForeignCurrencyFlag = true;
                        TemplateOperators = new StringCollection();
                        TemplateOperators.Add("=");

                        if (AAccountAccess.CountUsingTemplate(TemplateRow, TemplateOperators, Transaction) > 0)
                        {
                            CurrencyChangeAllowed = false;
                        }
                    }
                });

            ACalendarStartDate = CalendarStartDate;
            ACurrencyChangeAllowed = CurrencyChangeAllowed;
            // now check if calendar change would be allowed
            ACalendarChangeAllowed = IsCalendarChangeAllowed(ALedgerNumber);

            // Accept row changes here so that the Client gets 'unmodified' rows
            MainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            MainDS.RemoveEmptyTables();

            return MainDS;
        }