/// <summary>
        /// if the account code changes, analysis types/attributes  have to be updated
        /// </summary>
        private void AccountCodeDetailChanged(object sender, EventArgs e)
        {
            GLBatchTDS DS = null;
            int        TransactionNumber = 0;

            if (((TCmbAutoPopulated)sender).Name == cmbFromAccountCode.Name)
            {
                DS = FTempFromDS;
                TransactionNumber = FJournal.LastTransactionNumber + 1;
            }
            else
            {
                if (FPreviouslySelectedDetailRow == null)
                {
                    return;
                }

                DS = FMainDS;
                TransactionNumber = FCurrentTransactionNumber;
            }

            if (FPreviouslySelectedDetailRow != null)
            {
                FCurrentTransactionNumber = FPreviouslySelectedDetailRow.TransactionNumber;
            }

            FAnalysisAttributesLogic.TransAnalAttrRequiredUpdating(DS, null,
                                                                   ((TCmbAutoPopulated)sender).GetSelectedString(), TransactionNumber, false);
            RefreshAnalysisAttributesGrid((TCmbAutoPopulated)sender, DS);
        }
Ejemplo n.º 2
0
        private void InitBatchAndJournal()
        {
            F_GLDataset = TGLPosting.CreateABatch(F_LedgerNum);
            F_batch     = F_GLDataset.ABatch[0];
            F_batch.BatchDescription = Catalog.GetString("Period end revaluations");

            TAccountPeriodInfo accountingPeriodInfo = new TAccountPeriodInfo(F_LedgerNum);

            accountingPeriodInfo.AccountingPeriodNumber = F_batch.BatchPeriod;
            F_batch.DateEffective = accountingPeriodInfo.PeriodEndDate;

            F_batch.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;

            F_journal = F_GLDataset.AJournal.NewRowTyped();
            F_journal.LedgerNumber          = F_batch.LedgerNumber;
            F_journal.BatchNumber           = F_batch.BatchNumber;
            F_journal.JournalNumber         = 1;
            F_journal.DateEffective         = F_batch.DateEffective;
            F_journal.JournalPeriod         = F_batch.BatchPeriod;
            F_journal.TransactionCurrency   = F_BaseCurrency;
            F_journal.JournalDescription    = F_batch.BatchDescription;
            F_journal.TransactionTypeCode   = CommonAccountingTransactionTypesEnum.REVAL.ToString();
            F_journal.SubSystemCode         = CommonAccountingSubSystemsEnum.GL.ToString();
            F_journal.LastTransactionNumber = 0;
            F_journal.DateOfEntry           = DateTime.Now;
            F_journal.ExchangeRateToBase    = 1.0M;
            F_GLDataset.AJournal.Rows.Add(F_journal);
        }
Ejemplo n.º 3
0
        public void TestPrepareGLBatchForPostingArgumentValidation()
        {
            TVerificationResultCollection VerificationResult = null;
            TDBTransaction Transaction = null;
            GLBatchTDS     MainDS      = null;
            int            BatchPeriod = -1;

            string Message = "Validation failed for PrepareGLBatchForPosting with ledger number less than 1.";

            // Prepare GL Batch For Posting with ledger number less than 1
            try
            {
                TGLPosting.PrepareGLBatchForPosting(out MainDS, -1, 1, ref Transaction, out VerificationResult, null, ref BatchPeriod);
                Assert.Fail(Message);
            }
            catch (EFinanceSystemInvalidLedgerNumberException e)
            {
                Assert.AreEqual(-1, e.LedgerNumber, Message);
            }
            catch
            {
                Assert.Fail(Message);
            }

            Message = "Validation failed for PrepareGLBatchForPosting with batch number less than 1.";

            // Prepare GL Batch For Posting with batch number less than 1
            try
            {
                TGLPosting.PrepareGLBatchForPosting(out MainDS, 1, -1, ref Transaction, out VerificationResult, null, ref BatchPeriod);
                Assert.Fail(Message);
            }
            catch (EFinanceSystemInvalidBatchNumberException e)
            {
                Assert.AreEqual(1, e.LedgerNumber, Message);
                Assert.AreEqual(-1, e.BatchNumber, Message);
            }
            catch
            {
                Assert.Fail(Message);
            }

            Message = "Validation failed for PrepareGLBatchForPosting with null transaction.";

            // Prepare GL Batch For Posting with null transaction
            try
            {
                TGLPosting.PrepareGLBatchForPosting(out MainDS, 1, 1, ref Transaction, out VerificationResult, null, ref BatchPeriod);
                Assert.Fail(Message);
            }
            catch (EFinanceSystemDBTransactionNullException e)
            {
                Assert.AreEqual("Function:Prepare GL Batch For Posting - Database Transaction must not be NULL!", e.Message,
                                Message);
            }
            catch
            {
                Assert.Fail(Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Print or reprint the posting report for this batch.
        /// </summary>
        public static void PrintPostingRegister(Int32 ALedgerNumber, Int32 ABatchNumber, Boolean AEditTemplate = false)
        {
            FastReportsWrapper ReportingEngine = new FastReportsWrapper("Batch Posting Register");

            if (!ReportingEngine.LoadedOK)
            {
                ReportingEngine.ShowErrorPopup();
                return;
            }

            GLBatchTDS     BatchTDS  = TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(ALedgerNumber, ABatchNumber);
            TRptCalculator Calc      = new TRptCalculator();
            ALedgerRow     LedgerRow = BatchTDS.ALedger[0];

            //Call RegisterData to give the data to the template
            ReportingEngine.RegisterData(BatchTDS.ABatch, "ABatch");
            ReportingEngine.RegisterData(BatchTDS.AJournal, "AJournal");
            ReportingEngine.RegisterData(BatchTDS.ATransaction, "ATransaction");

            Calc.AddParameter("param_batch_number_i", ABatchNumber);
            Calc.AddParameter("param_ledger_number_i", ALedgerNumber);
            String LedgerName = TRemote.MFinance.Reporting.WebConnectors.GetLedgerName(ALedgerNumber);

            Calc.AddStringParameter("param_ledger_name", LedgerName);

            if (AEditTemplate)
            {
                ReportingEngine.DesignReport(Calc);
            }
            else
            {
                ReportingEngine.GenerateReport(Calc);
            }
        }
Ejemplo n.º 5
0
        } // AutoEmailReports

        /// <summary>Get all the data for the report</summary>
        /// <remarks>Called from the server during batch posting, and also from File/Print gui</remarks>
        /// <param name="ACalc"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <returns></returns>
        public Boolean RegisterBatchPostingData(TRptCalculator ACalc, Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            GLBatchTDS BatchTDS = TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(ALedgerNumber, ABatchNumber);

            if (BatchTDS.ABatch.Rows.Count < 1)
            {
                MessageBox.Show(Catalog.GetString("Batch not found"),
                                Catalog.GetString("Batch Posting Register"),
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            //Call RegisterData to give the data to the template
            RegisterData(BatchTDS.ABatch, "ABatch");
            RegisterData(BatchTDS.AJournal, "AJournal");
            RegisterData(BatchTDS.ATransaction, "ATransaction");
            RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList,
                                                                       ALedgerNumber), "AAccount");
            RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.CostCentreList,
                                                                       ALedgerNumber), "ACostCentre");

            ACalc.AddParameter("param_batch_number_i", ABatchNumber);
            ACalc.AddParameter("param_ledger_number_i", ALedgerNumber);
            String LedgerName = TRemote.MFinance.Reporting.WebConnectors.GetLedgerName(ALedgerNumber);

            ACalc.AddStringParameter("param_ledger_name", LedgerName);
            ACalc.AddStringParameter("param_linked_partner_cc", ""); // I may want to use this for auto_email, but usually it's unused.
            ACalc.AddParameter("param_currency_name",
                               TRemote.MFinance.Reporting.WebConnectors.GetTransactionCurrency(ALedgerNumber, ABatchNumber));
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Calculate the base amount for the transactions, and update the totals for the journals and the current batch
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ACurrentBatch"></param>
        public static void UpdateTotalsOfBatch(ref GLBatchTDS AMainDS,
                                               ABatchRow ACurrentBatch)
        {
            decimal BatchDebitTotal  = 0.0m;
            decimal BatchCreditTotal = 0.0m;

            DataView jnlDataView = new DataView(AMainDS.AJournal);

            jnlDataView.RowFilter = String.Format("{0}={1}",
                                                  AJournalTable.GetBatchNumberDBName(),
                                                  ACurrentBatch.BatchNumber);

            foreach (DataRowView journalView in jnlDataView)
            {
                GLBatchTDSAJournalRow journalRow = (GLBatchTDSAJournalRow)journalView.Row;

                UpdateTotalsOfJournal(ref AMainDS, ref journalRow);

                BatchDebitTotal  += journalRow.JournalDebitTotal;
                BatchCreditTotal += journalRow.JournalCreditTotal;
            }

            if ((ACurrentBatch.BatchDebitTotal != BatchDebitTotal) ||
                (ACurrentBatch.BatchCreditTotal != BatchCreditTotal))
            {
                ACurrentBatch.BatchDebitTotal  = BatchDebitTotal;
                ACurrentBatch.BatchCreditTotal = BatchCreditTotal;
            }
        }
Ejemplo n.º 7
0
        private string ValidateCorporateExchangeRate(GLBatchTDS ASubmitDS)
        {
            List <Int32> CheckedBatches          = new List <int>();
            Int32        BatchWithNoExchangeRate = -1;
            string       ErrorMessage            = string.Empty;

            WarnAboutMissingIntlExchangeRate = false;

            if (ASubmitDS.ABatch != null)
            {
                foreach (ABatchRow BatchRow in ASubmitDS.ABatch.Rows)
                {
                    // if batch hasn't been deleted or already checked
                    if ((BatchRow.RowState != DataRowState.Deleted) && !CheckedBatches.Contains(BatchRow.BatchNumber))
                    {
                        if (GetInternationalCurrencyExchangeRate(BatchRow.DateEffective, out ErrorMessage) == 0)
                        {
                            return(ErrorMessage);
                        }

                        BatchWithNoExchangeRate = BatchRow.BatchNumber;
                    }
                }
            }

            return(string.Empty);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Update the specified Journal's LastTransaction number. Assumes all necessary data is loaded for Journal
        /// </summary>
        /// <param name="AMainDS">ATransactions are filtered on current journal</param>
        /// <param name="ACurrentJournal"></param>
        /// <returns>false if no change to journal totals</returns>
        public static bool UpdateJournalLastTransaction(ref GLBatchTDS AMainDS,
                                                        ref GLBatchTDSAJournalRow ACurrentJournal)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString("Function:{0} - The GL Batch dataset is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ACurrentJournal == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Journal row does not exist or is empty!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ACurrentJournal.JournalStatus != MFinanceConstants.BATCH_UNPOSTED)
            {
                TLogging.Log(String.Format("Function:{0} - Tried to update totals for non-Unposted Batch:{1} and Journal:{2}",
                                           Utilities.GetMethodName(true),
                                           ACurrentJournal.BatchNumber,
                                           ACurrentJournal.JournalNumber));
                return(false);
            }

            #endregion Validate Arguments

            bool RowUpdated = false;

            int ActualLastTransNumber = 0;

            DataView TransDV = new DataView(AMainDS.ATransaction);
            TransDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                              ATransactionTable.GetBatchNumberDBName(),
                                              ACurrentJournal.BatchNumber,
                                              ATransactionTable.GetJournalNumberDBName(),
                                              ACurrentJournal.JournalNumber);

            TransDV.Sort = String.Format("{0} DESC",
                                         ATransactionTable.GetTransactionNumberDBName());

            foreach (DataRowView drv in TransDV)
            {
                ATransactionRow transRow = (ATransactionRow)drv.Row;

                //Run once only
                ActualLastTransNumber = transRow.TransactionNumber;
                break;
            }

            if (ACurrentJournal.LastTransactionNumber != ActualLastTransNumber)
            {
                ACurrentJournal.BeginEdit();
                ACurrentJournal.LastTransactionNumber = ActualLastTransNumber;
                ACurrentJournal.EndEdit();
                RowUpdated = true;
            }

            return(RowUpdated);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GLBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;

            FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GLBatches_Cancel(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber     = ALedgerNumber;
            FMainDS           = AMainDS;

            FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Update the specified Recurring Batch's LastJournal number. Assumes all necessary data is loaded for Batch
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ACurrentBatchRow"></param>
        /// <param name="AIncludeJournals"></param>
        /// <returns>false if no change to batch totals</returns>
        public static bool UpdateRecurringBatchLastJournal(ref GLBatchTDS AMainDS,
                                                           ref ARecurringBatchRow ACurrentBatchRow, Boolean AIncludeJournals = false)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString("Function:{0} - The GL Batch dataset is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ACurrentBatchRow == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Recurring GL Batch data row is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            bool RowUpdated = false;
            int  ActualLastJournalNumber = 0;

            DataView JournalDV = new DataView(AMainDS.ARecurringJournal);

            JournalDV.RowFilter = String.Format("{0}={1}",
                                                ARecurringJournalTable.GetBatchNumberDBName(),
                                                ACurrentBatchRow.BatchNumber);

            //Highest Journal number first
            JournalDV.Sort = String.Format("{0} DESC",
                                           ARecurringJournalTable.GetJournalNumberDBName());

            foreach (DataRowView journalView in JournalDV)
            {
                GLBatchTDSARecurringJournalRow journalRow = (GLBatchTDSARecurringJournalRow)journalView.Row;

                //Run once only
                if (ActualLastJournalNumber == 0)
                {
                    ActualLastJournalNumber = journalRow.JournalNumber;
                }

                if (AIncludeJournals && UpdateRecurringJournalLastTransaction(ref AMainDS, ref journalRow))
                {
                    RowUpdated = true;
                }
            }

            if (ACurrentBatchRow.LastJournal != ActualLastJournalNumber)
            {
                ACurrentBatchRow.BeginEdit();
                ACurrentBatchRow.LastJournal = ActualLastJournalNumber;
                ACurrentBatchRow.EndEdit();
                RowUpdated = true;
            }

            return(RowUpdated);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Calculate the base amount for the transactions, and update the totals for the journals and the current batch
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ACurrentBatchRow"></param>
        /// <param name="ACurrentJournalNumber"></param>
        /// <returns>false if no change to batch totals</returns>
        public static bool UpdateRecurringBatchTotals(ref GLBatchTDS AMainDS,
                                                      ref ARecurringBatchRow ACurrentBatchRow, Int32 ACurrentJournalNumber = 0)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Recurring GL Batch dataset is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ACurrentBatchRow == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Recurring GL Batch data row is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            bool AmountsUpdated = false;

            decimal BatchDebitTotal  = 0.0m;
            decimal BatchCreditTotal = 0.0m;

            DataView JournalDV = new DataView(AMainDS.ARecurringJournal);

            JournalDV.RowFilter = String.Format("{0}={1}",
                                                ARecurringJournalTable.GetBatchNumberDBName(),
                                                ACurrentBatchRow.BatchNumber);

            foreach (DataRowView journalView in JournalDV)
            {
                GLBatchTDSARecurringJournalRow journalRow = (GLBatchTDSARecurringJournalRow)journalView.Row;

                if (((ACurrentJournalNumber > 0) && (ACurrentJournalNumber == journalRow.JournalNumber)) ||
                    (ACurrentJournalNumber == 0))
                {
                    if ((UpdateRecurringJournalTotals(ref AMainDS, ref journalRow)))
                    {
                        AmountsUpdated = true;
                    }
                }

                BatchDebitTotal  += journalRow.JournalDebitTotal;
                BatchCreditTotal += journalRow.JournalCreditTotal;
            }

            if ((ACurrentBatchRow.BatchDebitTotal != BatchDebitTotal) ||
                (ACurrentBatchRow.BatchCreditTotal != BatchCreditTotal))
            {
                ACurrentBatchRow.BatchDebitTotal  = BatchDebitTotal;
                ACurrentBatchRow.BatchCreditTotal = BatchCreditTotal;
                AmountsUpdated = true;
            }

            return(AmountsUpdated);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GLBatches_Post(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS, IUC_GLBatches AUserControl)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber = ALedgerNumber;
            FMainDS = AMainDS;
            FMyUserControl = AUserControl;

            FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public TUC_GLBatches_Post(TFrmPetraEditUtils APetraUtilsObject, Int32 ALedgerNumber, GLBatchTDS AMainDS, IUC_GLBatches AUserControl)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FLedgerNumber     = ALedgerNumber;
            FMainDS           = AMainDS;
            FMyUserControl    = AUserControl;

            FMyForm = (TFrmGLBatch)FPetraUtilsObject.GetForm();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Need to ensure that the Analysis Attributes grid has all the entries
        /// that are required for the selected account.
        /// There may or may not already be attribute assignments for this transaction.
        /// </summary>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="ATransactionNumber"></param>
        public void ReconcileRecurringTransAnalysisAttributes(ref GLBatchTDS AGLBatchDS,
                                                              string AAccountCode,
                                                              int ATransactionNumber)
        {
            if (string.IsNullOrEmpty(AAccountCode))
            {
                return;
            }

            StringCollection RequiredAnalAttrCodes = TRemote.MFinance.Setup.WebConnectors.RequiredAnalysisAttributesForAccount(FLedgerNumber,
                                                                                                                               AAccountCode, false);

            SetRecurringTransAnalAttributeDefaultView(AGLBatchDS, ATransactionNumber,
                                                      TAnalysisAttributes.ConvertStringCollectionToCSV(RequiredAnalAttrCodes, "'"));

            // If the AnalysisType list I'm currently using is the same as the list of required types, I can keep it (with any existing values).
            bool existingListIsOk = (RequiredAnalAttrCodes.Count == AGLBatchDS.ARecurringTransAnalAttrib.DefaultView.Count);

            if (existingListIsOk)
            {
                foreach (DataRowView rv in AGLBatchDS.ARecurringTransAnalAttrib.DefaultView)
                {
                    ARecurringTransAnalAttribRow row = (ARecurringTransAnalAttribRow)rv.Row;

                    if (!RequiredAnalAttrCodes.Contains(row.AnalysisTypeCode))
                    {
                        existingListIsOk = false;
                        break;
                    }
                }
            }

            if (existingListIsOk)
            {
                return;
            }

            // Delete any existing Analysis Type records and re-create the list (Removing any prior selections by the user).
            foreach (DataRowView rv in AGLBatchDS.ARecurringTransAnalAttrib.DefaultView)
            {
                ARecurringTransAnalAttribRow attrRowCurrent = (ARecurringTransAnalAttribRow)rv.Row;
                attrRowCurrent.Delete();
            }

            foreach (String analysisTypeCode in RequiredAnalAttrCodes)
            {
                ARecurringTransAnalAttribRow newRow = AGLBatchDS.ARecurringTransAnalAttrib.NewRowTyped(true);
                newRow.LedgerNumber      = FLedgerNumber;
                newRow.BatchNumber       = FBatchNumber;
                newRow.JournalNumber     = FJournalNumber;
                newRow.TransactionNumber = ATransactionNumber;
                newRow.AnalysisTypeCode  = analysisTypeCode;
                newRow.AccountCode       = AAccountCode;

                AGLBatchDS.ARecurringTransAnalAttrib.Rows.Add(newRow);
            }
        }
Ejemplo n.º 16
0
 private void TCommonAccountingTool_(string ABatchDescription)
 {
     FBatchTDS                  = TGLPosting.CreateABatch(FLedgerInfo.LedgerNumber);
     FBaseCurrencyInfo          = new TCurrencyInfo(FLedgerInfo.BaseCurrency);
     FBatchRow                  = FBatchTDS.ABatch[0];
     FBatchRow.BatchDescription = ABatchDescription;
     FBatchRow.BatchStatus      = MFinanceConstants.BATCH_UNPOSTED;
     FBatchNumber               = FBatchRow.BatchNumber;
     FJournalCount              = 0;
     blnReadyForTransaction     = false;
     blnInitBatchDate           = true;
 }
Ejemplo n.º 17
0
 private void TCommonAccountingTool_(string ABatchDescription)
 {
     FBatchTDS = TGLPosting.CreateABatch(FLedgerInfo.LedgerNumber);
     FBaseCurrencyInfo = new TCurrencyInfo(FLedgerInfo.BaseCurrency);
     FBatchRow = FBatchTDS.ABatch[0];
     FBatchRow.BatchDescription = ABatchDescription;
     FBatchRow.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;
     FBatchNumber = FBatchRow.BatchNumber;
     FJournalCount = 0;
     blnReadyForTransaction = false;
     blnInitBatchDate = true;
 }
        private void RevertDataSet(GLBatchTDS AMainDS, GLBatchTDS ABackupDS, int ASelectRowInGrid = 0)
        {
            if ((ABackupDS != null) && (AMainDS != null))
            {
                AMainDS.RejectChanges();
                AMainDS.Merge(ABackupDS);

                if (ASelectRowInGrid > 0)
                {
                    SelectRowInGrid(ASelectRowInGrid);
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Update the specified recurring Journal's LastTransaction number. Assumes all necessary data is loaded for Journal
        /// </summary>
        /// <param name="AMainDS">ATransactions are filtered on current journal</param>
        /// <param name="ACurrentJournal"></param>
        /// <returns>false if no change to journal totals</returns>
        public static bool UpdateRecurringJournalLastTransaction(ref GLBatchTDS AMainDS,
                                                                 ref GLBatchTDSARecurringJournalRow ACurrentJournal)
        {
            #region Validate Arguments

            if (AMainDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString("Function:{0} - The GL Batch dataset is null!"),
                                                                                     Utilities.GetMethodName(true)));
            }
            else if (ACurrentJournal == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString(
                                                                                         "Function:{0} - The Recurring Journal row does not exist or is empty!"),
                                                                                     Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            bool RowUpdated = false;

            int ActualLastTransNumber = 0;

            DataView TransDV = new DataView(AMainDS.ARecurringTransaction);

            TransDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                              ARecurringTransactionTable.GetBatchNumberDBName(),
                                              ACurrentJournal.BatchNumber,
                                              ARecurringTransactionTable.GetJournalNumberDBName(),
                                              ACurrentJournal.JournalNumber);

            TransDV.Sort = String.Format("{0} DESC",
                                         ARecurringTransactionTable.GetTransactionNumberDBName());

            foreach (DataRowView drv in TransDV)
            {
                ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                //Run once only
                ActualLastTransNumber = transRow.TransactionNumber;
                break;
            }

            if (ACurrentJournal.LastTransactionNumber != ActualLastTransNumber)
            {
                ACurrentJournal.LastTransactionNumber = ActualLastTransNumber;
                RowUpdated = true;
            }

            return(RowUpdated);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Calculate the base amount for the transactions, and update the totals for the current journal
        /// NOTE this no longer calculates AmountInBaseCurrency
        /// ALSO - since the ExchangeRateToBase field is no longer used here, the code that asserts it to be valid is commented out.
        /// </summary>
        /// <param name="AMainDS">ATransactions are filtered on current journal</param>
        /// <param name="ACurrentJournal"></param>
        public static void UpdateTotalsOfRecurringJournal(ref GLBatchTDS AMainDS,
                                                          ref GLBatchTDSARecurringJournalRow ACurrentJournal)
        {
            if (ACurrentJournal == null)
            {
                return;
            }

            /* // Since I'm not using ExchangeRateToBase, I don't need to check that it's valid:
             *
             * if ((ACurrentJournal.ExchangeRateToBase == 0.0m)
             *  && (ACurrentJournal.TransactionTypeCode != CommonAccountingTransactionTypesEnum.REVAL.ToString()))
             * {
             *  throw new Exception(String.Format("Recurring Batch {0} Journal {1} has invalid exchange rate to base",
             *          ACurrentJournal.BatchNumber,
             *          ACurrentJournal.JournalNumber));
             * }
             */

            ACurrentJournal.JournalDebitTotal      = 0.0M;
            ACurrentJournal.JournalDebitTotalBase  = 0.0M;
            ACurrentJournal.JournalCreditTotal     = 0.0M;
            ACurrentJournal.JournalCreditTotalBase = 0.0M;

            DataView trnsDataView = new DataView(AMainDS.ARecurringTransaction);

            trnsDataView.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                   ARecurringTransactionTable.GetBatchNumberDBName(),
                                                   ACurrentJournal.BatchNumber,
                                                   ARecurringTransactionTable.GetJournalNumberDBName(),
                                                   ACurrentJournal.JournalNumber);

            // transactions are filtered for this journal; add up the total amounts
            foreach (DataRowView v in trnsDataView)
            {
                ARecurringTransactionRow r = (ARecurringTransactionRow)v.Row;

                if (r.DebitCreditIndicator)
                {
                    ACurrentJournal.JournalDebitTotal     += r.TransactionAmount;
                    ACurrentJournal.JournalDebitTotalBase += r.AmountInBaseCurrency;
                }
                else
                {
                    ACurrentJournal.JournalCreditTotal     += r.TransactionAmount;
                    ACurrentJournal.JournalCreditTotalBase += r.AmountInBaseCurrency;
                }
            }
        }
        private void RefreshAnalysisAttributesGrid(TCmbAutoPopulated ACombo, GLBatchTDS ADS)
        {
            TSgrdDataGridPaged Grid = null;
            int TransactionNumber   = 0;

            if (ACombo.Name == cmbFromAccountCode.Name)
            {
                Grid = grdFromAnalAttributes;
                TransactionNumber = FJournal.LastTransactionNumber + 1;
            }
            else
            {
                Grid = grdToAnalAttributes;
                TransactionNumber = FCurrentTransactionNumber;
            }

            //Empty the grid
            ADS.ATransAnalAttrib.DefaultView.RowFilter = "1=2";
            FPSAttributesRow = null;

            if (!TRemote.MFinance.Setup.WebConnectors.AccountHasAnalysisAttributes(FLedgerNumber, ACombo.GetSelectedString(),
                                                                                   true))
            {
                if (Grid.Enabled)
                {
                    Grid.Enabled = false;
                }

                return;
            }
            else
            {
                if (!Grid.Enabled)
                {
                    Grid.Enabled = true;
                }
            }

            FAnalysisAttributesLogic.SetTransAnalAttributeDefaultView(ADS, TransactionNumber);

            Grid.DataSource = new DevAge.ComponentModel.BoundDataView(ADS.ATransAnalAttrib.DefaultView);

            if (Grid.Rows.Count > 1)
            {
                Grid.SelectRowWithoutFocus(1);
                AnalysisAttributesGrid_RowSelected(Grid, null);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Used for the validation of Analysis Attributes
        /// </summary>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="AGLBatchDS"></param>
        /// <param name="ValueRequiredForType"></param>
        /// <param name="AIsUnposted"></param>
        /// <returns></returns>
        public bool AccountAnalysisAttributesValuesExist(int ATransactionNumber,
                                                         string AAccountCode,
                                                         GLBatchTDS AGLBatchDS,
                                                         out String ValueRequiredForType,
                                                         bool AIsUnposted = true)
        {
            ValueRequiredForType = "";

            if (!AIsUnposted || string.IsNullOrEmpty(AAccountCode) || (AGLBatchDS.ATransAnalAttrib.DefaultView.Count == 0))
            {
                return(true);
            }

            StringCollection RequiredAnalAttrCodes = TRemote.MFinance.Setup.WebConnectors.RequiredAnalysisAttributesForAccount(FLedgerNumber,
                                                                                                                               AAccountCode, true);

            string AnalysisCodeFilterValues = TAnalysisAttributes.ConvertStringCollectionToCSV(RequiredAnalAttrCodes, "'");

            DataView analAttrib = new DataView(AGLBatchDS.ATransAnalAttrib);

            analAttrib.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6} IN ({7})",
                                                 ATransAnalAttribTable.GetBatchNumberDBName(),
                                                 FBatchNumber,
                                                 ATransAnalAttribTable.GetJournalNumberDBName(),
                                                 FJournalNumber,
                                                 ATransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ATransactionNumber,
                                                 ATransAnalAttribTable.GetAnalysisTypeCodeDBName(),
                                                 AnalysisCodeFilterValues);

            foreach (DataRowView drv in analAttrib)
            {
                ATransAnalAttribRow rw = (ATransAnalAttribRow)drv.Row;

                string analysisCode = rw.AnalysisTypeCode;

                if (TRemote.MFinance.Setup.WebConnectors.AccountAnalysisAttributeRequiresValues(FLedgerNumber, analysisCode, true))
                {
                    if (rw.IsAnalysisAttributeValueNull() || (rw.AnalysisAttributeValue == string.Empty))
                    {
                        ValueRequiredForType = rw.AnalysisTypeCode;
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 23
0
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GLBatchTDS SubmitDS, out TVerificationResultCollection VerificationResult)
        {
            FLatestSaveIncludedForex = false;

            if (SubmitDS.AJournal != null)
            {
                // Check whether we are saving any rows that are in foreign currency
                DataView dv = new DataView(SubmitDS.AJournal,
                                           String.Format("{0}<>{1}", AJournalTable.GetTransactionCurrencyDBName(), AJournalTable.GetBaseCurrencyDBName()),
                                           String.Empty, DataViewRowState.CurrentRows);
                FLatestSaveIncludedForex = (dv.Count > 0);
            }

            // Now do the standard call to save the changes
            return(TRemote.MFinance.GL.WebConnectors.SaveGLBatchTDS(ref SubmitDS, out VerificationResult));
        }
Ejemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AActiveOnly"></param>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAnalysisCodeFilterValues"></param>
        public void SetTransAnalAttributeDefaultView(GLBatchTDS AGLBatchDS,
                                                     bool AActiveOnly,
                                                     Int32 ATransactionNumber         = 0,
                                                     String AAnalysisCodeFilterValues = "")
        {
            if (FBatchNumber != -1)
            {
                if (ATransactionNumber > 0)
                {
                    if (AActiveOnly && (AAnalysisCodeFilterValues.Length > 0))
                    {
                        AGLBatchDS.ATransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6} IN ({7})",
                                                                                          ATransAnalAttribTable.GetBatchNumberDBName(),
                                                                                          FBatchNumber,
                                                                                          ATransAnalAttribTable.GetJournalNumberDBName(),
                                                                                          FJournalNumber,
                                                                                          ATransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                          ATransactionNumber,
                                                                                          ATransAnalAttribTable.GetAnalysisTypeCodeDBName(),
                                                                                          AAnalysisCodeFilterValues);
                    }
                    else
                    {
                        AGLBatchDS.ATransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5}",
                                                                                          ATransAnalAttribTable.GetBatchNumberDBName(),
                                                                                          FBatchNumber,
                                                                                          ATransAnalAttribTable.GetJournalNumberDBName(),
                                                                                          FJournalNumber,
                                                                                          ATransAnalAttribTable.GetTransactionNumberDBName(),
                                                                                          ATransactionNumber);
                    }
                }
                else
                {
                    AGLBatchDS.ATransAnalAttrib.DefaultView.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                                                      ATransAnalAttribTable.GetBatchNumberDBName(),
                                                                                      FBatchNumber,
                                                                                      ATransAnalAttribTable.GetJournalNumberDBName(),
                                                                                      FJournalNumber);
                }

                AGLBatchDS.ATransAnalAttrib.DefaultView.Sort = String.Format("{0} ASC, {1} ASC",
                                                                             ATransAnalAttribTable.GetTransactionNumberDBName(),
                                                                             ATransAnalAttribTable.GetAnalysisTypeCodeDBName()
                                                                             );
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ALedgerNumber">Ledger number</param>
        /// <param name="AMainDS">The main data set</param>
        /// <param name="AFilterFindPanelObject">The filter panel control object</param>
        public TUC_GLBatches_LoadAndFilter(int ALedgerNumber, GLBatchTDS AMainDS, TFilterAndFindPanel AFilterFindPanelObject)
        {
            FFilterFindPanelObject = AFilterFindPanelObject;
            FMainDS       = AMainDS;
            FLedgerNumber = ALedgerNumber;

            FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding");
            FcmbPeriod     = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod");
            FrbtEditing    = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing");
            FrbtPosting    = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting");
            FrbtAll        = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll");

            TFinanceControls.InitialiseAvailableFinancialYearsList(ref FcmbYearEnding, FLedgerNumber, false, true);
            //TLogging.Log("GL Financial Years completed");
            FrbtEditing.Checked = true;
            //TLogging.Log("Editing checkbox selected");
        }
Ejemplo n.º 26
0
        //
        // Returns True if the data apparently loaded OK and the report should be printed.
        private bool LoadReportData(TRptCalculator ACalc)
        {
            GLBatchTDS BatchTDS = null;

            try
            {
                BatchTDS = TRemote.MFinance.GL.WebConnectors.LoadABatchAndRelatedTablesUsingPrivateDb(FLedgerNumber, FBatchNumber);
            }
            catch
            {
            }         // Ignore this error and instead detect the empty batch, below:

            if ((BatchTDS == null) || (BatchTDS.ABatch == null) || (BatchTDS.ABatch.Rows.Count < 1))
            {
                return(false);
            }

            //Call RegisterData to give the data to the template
            FPetraUtilsObject.FFastReportsPlugin.RegisterData(BatchTDS.ABatch, "ABatch");
            FPetraUtilsObject.FFastReportsPlugin.RegisterData(BatchTDS.AJournal, "AJournal");
            FPetraUtilsObject.FFastReportsPlugin.RegisterData(BatchTDS.ATransaction, "ATransaction");
            FPetraUtilsObject.FFastReportsPlugin.RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList,
                                                                                                            FLedgerNumber), "AAccount");
            FPetraUtilsObject.FFastReportsPlugin.RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.
                                                                                                            CostCentreList,
                                                                                                            FLedgerNumber), "ACostCentre");

            ACalc.AddParameter("param_batch_number_i", FBatchNumber);
            ACalc.AddParameter("param_ledger_number_i", FLedgerNumber);
            String LedgerName = TRemote.MFinance.Reporting.WebConnectors.GetLedgerName(FLedgerNumber);

            ACalc.AddStringParameter("param_ledger_name", LedgerName);
            ALedgerTable LedgerTable = (ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails,
                                                                                                   FLedgerNumber);

            ACalc.AddStringParameter("param_linked_partner_cc", ""); // I may want to use this for auto_email, but usually it's unused.
            ACalc.AddParameter("param_currency_name", LedgerTable[0].BaseCurrency);

            if (this.IsDisposed) // If the form is closed, exit immediately!
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 27
0
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GLBatchTDS SubmitDS, out TVerificationResultCollection AVerificationResult)
        {
            FLatestSaveIncludedForex = false;

            if (SubmitDS.AJournal != null)
            {
                // Check whether we are saving any rows that are in foreign currency
                foreach (AJournalRow row in SubmitDS.AJournal.Rows)
                {
                    if (row.BaseCurrency != row.TransactionCurrency)
                    {
                        FLatestSaveIncludedForex = true;
                        break;
                    }
                }
            }

            //Do only at posting and when first entering transactions
            //---------------------------------------------------------
            // Check if corporate exchange rate exists for any new batches or modified batches.
            // Note: all previously saved batches will have an exchange rate for that saved batch date as
            // it is impossible to delete a corporate exchange rate if batches exist that need it.
            //string ErrorMessage = ValidateCorporateExchangeRate(SubmitDS);

            //if (!string.IsNullOrEmpty(ErrorMessage))
            //{
            //    AVerificationResult = new TVerificationResultCollection();
            //    TScreenVerificationResult Verification = null;

            //    Verification = new TScreenVerificationResult(
            //        new TVerificationResult(this, ErrorMessage, TResultSeverity.Resv_Noncritical),
            //        null, null);

            //    // Handle addition/removal to/from TVerificationResultCollection
            //    AVerificationResult.Auto_Add_Or_AddOrRemove(this, Verification, null, true);

            //    return TSubmitChangesResult.scrError;
            //}

            // Now do the standard call to save the changes
            return(TRemote.MFinance.GL.WebConnectors.SaveGLBatchTDS(ref SubmitDS, out AVerificationResult));
        }
Ejemplo n.º 28
0
        public void TestPrepareGLBatchForPostingArgumentValidation()
        {
            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();
            TDataBase      db          = DBAccess.Connect("TestPrepareGLBatchForPostingArgumentValidation");
            TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted);
            GLBatchTDS     MainDS      = null;
            int            BatchPeriod = -1;

            string Message = "Validation failed for PrepareGLBatchForPosting with ledger number less than 1.";

            // Prepare GL Batch For Posting with ledger number less than 1
            try
            {
                TGLPosting.PrepareGLBatchForPosting(out MainDS, -1, 1, ref Transaction, out VerificationResult, null, ref BatchPeriod);
                Assert.Fail(Message);
            }
            catch (EFinanceSystemInvalidLedgerNumberException e)
            {
                Assert.AreEqual(-1, e.LedgerNumber, Message);
            }
            catch
            {
                Assert.Fail(Message);
            }

            // Prepare GL Batch For Posting with batch number less than 1
            Message = "Validation failed for PrepareGLBatchForPosting with batch number less than 1.";
            try
            {
                TGLPosting.PrepareGLBatchForPosting(out MainDS, 43, -1, ref Transaction, out VerificationResult, null, ref BatchPeriod);
                Assert.Fail(Message);
            }
            catch (EFinanceSystemInvalidBatchNumberException e)
            {
                Assert.AreEqual(43, e.LedgerNumber, Message);
                Assert.AreEqual(-1, e.BatchNumber, Message);
            }
            catch
            {
                Assert.Fail(Message);
            }
        }
Ejemplo n.º 29
0
        private Boolean CloseSaveAndPost_(TVerificationResultCollection AVerifications)
        {
            if (FJournalCount != 0)
            {
                // The checksum of the "last journal" is used to update the checksum of the batch.
                FBatchRow.BatchControlTotal += FJournalRow.JournalDebitTotal - FJournalRow.JournalCreditTotal;
            }

            FBatchTDS.ThrowAwayAfterSubmitChanges = true;
            GLBatchTDSAccess.SubmitChanges(FBatchTDS);

            Boolean PostedOk = TGLPosting.PostGLBatch(
                FLedgerInfo.LedgerNumber, FBatchNumber, out AVerifications);

            // Make sure that this object cannot be used for another posting ...
            FBatchTDS   = null;
            FBatchRow   = null;
            FJournalRow = null;
            return(PostedOk);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Calculate the base amount for the transactions, and update the totals for the journals and the current batch
        ///   Assumes that all transactions for the journal are already loaded.
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="ACurrentBatch"></param>
        /// <param name="ACurrentJournal"></param>
        public static void UpdateTotalsOfBatchForJournal(ref GLBatchTDS AMainDS,
                                                         ABatchRow ACurrentBatch, GLBatchTDSAJournalRow ACurrentJournal)
        {
            //Save current values
            decimal JournalDebitTotal  = ACurrentJournal.JournalDebitTotal;
            decimal JournalCreditTotal = ACurrentJournal.JournalCreditTotal;

            bool JournalUpdated;

            UpdateTotalsOfJournal(ref AMainDS, ref ACurrentJournal, out JournalUpdated);

            if (JournalUpdated)
            {
                //Subtract old amounts
                ACurrentBatch.BatchDebitTotal  -= JournalDebitTotal;
                ACurrentBatch.BatchCreditTotal -= JournalCreditTotal;
                //Add updated Journals amounts
                ACurrentBatch.BatchDebitTotal  += ACurrentJournal.JournalDebitTotal;
                ACurrentBatch.BatchCreditTotal += ACurrentJournal.JournalCreditTotal;
            }
        }
Ejemplo n.º 31
0
        /// <summary>Get all the data for the report</summary>
        /// <remarks>Called from the server during batch posting, and also from File/Print gui</remarks>
        /// <param name="ACalc"></param>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <returns></returns>
        public Boolean RegisterBatchPostingData(TRptCalculator ACalc, Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            GLBatchTDS BatchTDS = null;

            try
            {
                BatchTDS = TRemote.MFinance.GL.WebConnectors.LoadABatchAndContentUsingPrivateDb(ALedgerNumber, ABatchNumber);
            }
            catch
            {
            }         // Ignore this error and instead detect the empty batch, below:

            if ((BatchTDS == null) || (BatchTDS.ABatch == null) || (BatchTDS.ABatch.Rows.Count < 1))
            {
                ShowBadBatchNumMessageInUiThread(ABatchNumber);
                return(false);
            }

            //Call RegisterData to give the data to the template
            RegisterData(BatchTDS.ABatch, "ABatch");
            RegisterData(BatchTDS.AJournal, "AJournal");
            RegisterData(BatchTDS.ATransaction, "ATransaction");
            RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList,
                                                                       ALedgerNumber), "AAccount");
            RegisterData(TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.CostCentreList,
                                                                       ALedgerNumber), "ACostCentre");

            ACalc.AddParameter("param_batch_number_i", ABatchNumber);
            ACalc.AddParameter("param_ledger_number_i", ALedgerNumber);
            String LedgerName = TRemote.MFinance.Reporting.WebConnectors.GetLedgerName(ALedgerNumber);

            ACalc.AddStringParameter("param_ledger_name", LedgerName);
            ALedgerTable LedgerTable = (ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails);

            ACalc.AddStringParameter("param_linked_partner_cc", ""); // I may want to use this for auto_email, but usually it's unused.
            ACalc.AddParameter("param_currency_name", LedgerTable[0].BaseCurrency);
            return(true);
        }
Ejemplo n.º 32
0
        private void InitBatchAndJournal(decimal AExchangeRate, string ACurrencyCode)
        {
            F_GLDataset = TGLPosting.CreateABatch(F_LedgerNum, false, true);
            F_batch     = F_GLDataset.ABatch[0];
            F_batch.BatchDescription = Catalog.GetString("Period end revaluations");

            TAccountPeriodInfo accountingPeriodInfo = new TAccountPeriodInfo(F_LedgerNum);

            accountingPeriodInfo.AccountingPeriodNumber = F_batch.BatchPeriod;
            F_batch.DateEffective = accountingPeriodInfo.PeriodEndDate;

            F_batch.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;

            F_journal = F_GLDataset.AJournal.NewRowTyped();
            F_journal.LedgerNumber          = F_batch.LedgerNumber;
            F_journal.BatchNumber           = F_batch.BatchNumber;
            F_journal.JournalNumber         = 1;
            F_journal.DateEffective         = F_batch.DateEffective;
            F_journal.ExchangeRateTime      = 14400;        // revaluations are typically later than 'new rates'
            F_journal.JournalPeriod         = F_batch.BatchPeriod;
            F_journal.TransactionCurrency   = F_BaseCurrency;
            F_journal.JournalDescription    = F_batch.BatchDescription;
            F_journal.TransactionTypeCode   = CommonAccountingTransactionTypesEnum.REVAL.ToString();
            F_journal.SubSystemCode         = CommonAccountingSubSystemsEnum.GL.ToString();
            F_journal.LastTransactionNumber = 0;
            F_journal.DateOfEntry           = DateTime.Now;
            F_journal.ExchangeRateToBase    = 1.0M;
            F_GLDataset.AJournal.Rows.Add(F_journal);

            ARevaluationRow revalRow = F_GLDataset.ARevaluation.NewRowTyped();

            revalRow.LedgerNumber        = F_journal.LedgerNumber;
            revalRow.BatchNumber         = F_journal.BatchNumber;
            revalRow.JournalNumber       = F_journal.JournalNumber;
            revalRow.ExchangeRateToBase  = AExchangeRate;
            revalRow.RevaluationCurrency = ACurrencyCode;
            F_GLDataset.ARevaluation.Rows.Add(revalRow);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Used for the validation of Analysis Attributes
        /// </summary>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AIsUnposted"></param>
        /// <returns></returns>
        public bool AccountAnalysisAttributeCountIsCorrect(int ATransactionNumber,
                                                           string AAccountCode,
                                                           GLBatchTDS AGLBatchDS,
                                                           bool AIsUnposted = true)
        {
            bool RetVal = true;

            if (!AIsUnposted || string.IsNullOrEmpty(AAccountCode))
            {
                return(RetVal);
            }

            int NumberOfAttributes = 0;

            TRemote.MFinance.Setup.WebConnectors.AccountHasAnalysisAttributes(FLedgerNumber, AAccountCode, out NumberOfAttributes, true);

            if (NumberOfAttributes == 0)
            {
                return(RetVal);
            }

            DataView analAttrib = new DataView(AGLBatchDS.ATransAnalAttrib);

            analAttrib.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6}={7}",
                                                 ATransAnalAttribTable.GetBatchNumberDBName(),
                                                 FBatchNumber,
                                                 ATransAnalAttribTable.GetJournalNumberDBName(),
                                                 FJournalNumber,
                                                 ATransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ATransactionNumber,
                                                 ATransAnalAttribTable.GetAccountCodeDBName(),
                                                 AAccountCode);

            RetVal = (analAttrib.Count == NumberOfAttributes);

            return(RetVal);
        }
Ejemplo n.º 34
0
        public static GLBatchTDS LoadARecurringTransactionARecurringTransAnalAttrib(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AJournalNumber)
        {
            string strAnalAttr = string.Empty;
            bool newTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out newTransaction);

            GLBatchTDS MainDS = new GLBatchTDS();

            ARecurringTransactionAccess.LoadViaARecurringJournal(MainDS, ALedgerNumber, ABatchNumber, AJournalNumber, Transaction);

            ARecurringTransAnalAttribAccess.LoadViaARecurringJournal(MainDS, ALedgerNumber, ABatchNumber, AJournalNumber, Transaction);

            foreach (GLBatchTDSARecurringTransactionRow transRow in MainDS.ARecurringTransaction.Rows)
            {
                MainDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = String.Format("{0} = {1}",
                    ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                    transRow.TransactionNumber);

                foreach (DataRowView rv in MainDS.ARecurringTransAnalAttrib.DefaultView)
                {
                    ARecurringTransAnalAttribRow Row = (ARecurringTransAnalAttribRow)rv.Row;

                    if (strAnalAttr.Length > 0)
                    {
                        strAnalAttr += ", ";
                    }

                    strAnalAttr += (Row.AnalysisTypeCode + "=" + Row.AnalysisAttributeValue);
                }

                transRow.AnalysisAttributes = strAnalAttr;

                //clear the attributes string and table
                strAnalAttr = string.Empty;
            }

            MainDS.ARecurringTransAnalAttrib.DefaultView.RowFilter = string.Empty;

            if (newTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
Ejemplo n.º 35
0
        private static void CheckRecurringTransAnalysisAttributes(ref GLBatchTDS AInspectDS,
            int ALedgerNumber,
            int ABatchNumber,
            int AJournalNumber,
            ref TSubmitChangesResult ASubmissionResult)
        {
            //check if the necessary rows for the given account are there, automatically add/update account
            GLSetupTDS glSetupCacheDS = LoadAAnalysisAttributes(ALedgerNumber);

            //Account Number for AnalysisTable lookup
            int currentTransactionNumber = 0;
            string currentTransAccountCode = String.Empty;

            if (glSetupCacheDS == null)
            {
                return;
            }

            //Reference all transactions in dataset
            DataView allTransView = AInspectDS.ARecurringTransaction.DefaultView;
            DataView transAnalAttrView = AInspectDS.ARecurringTransAnalAttrib.DefaultView;

            transAnalAttrView.RowFilter = string.Empty;

            allTransView.RowFilter = String.Format("{0}={1} and {2}={3}",
                ARecurringTransactionTable.GetBatchNumberDBName(),
                ABatchNumber,
                ARecurringTransactionTable.GetJournalNumberDBName(),
                AJournalNumber);

            foreach (DataRowView transRowView in allTransView)
            {
                ARecurringTransactionRow currentTransactionRow = (ARecurringTransactionRow)transRowView.Row;

                currentTransactionNumber = currentTransactionRow.TransactionNumber;
                currentTransAccountCode = currentTransactionRow.AccountCode;

                //If this account code is used need to delete it from TransAnal table.
                //Delete any existing rows with old code
                transAnalAttrView.RowFilter = String.Format("{0} = {1} AND {2} = {3} AND {4} = {5} AND {6} <> '{7}'",
                    ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                    ABatchNumber,
                    ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                    AJournalNumber,
                    ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                    currentTransactionNumber,
                    ARecurringTransAnalAttribTable.GetAccountCodeDBName(),
                    currentTransAccountCode);

                foreach (DataRowView dv in transAnalAttrView)
                {
                    ARecurringTransAnalAttribRow tr = (ARecurringTransAnalAttribRow)dv.Row;

                    tr.Delete();
                }

                transAnalAttrView.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5}",
                    ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                    ABatchNumber,
                    ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                    AJournalNumber,
                    ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                    currentTransactionNumber);

                //Retrieve the analysis attributes for the supplied account
                DataView analAttrView = glSetupCacheDS.AAnalysisAttribute.DefaultView;
                analAttrView.RowFilter = String.Format("{0} = '{1}'",
                    AAnalysisAttributeTable.GetAccountCodeDBName(),
                    currentTransAccountCode);

                if (analAttrView.Count > 0)
                {
                    for (int i = 0; i < analAttrView.Count; i++)
                    {
                        //Read the Type Code for each attribute row
                        AAnalysisAttributeRow analAttrRow = (AAnalysisAttributeRow)analAttrView[i].Row;
                        string analysisTypeCode = analAttrRow.AnalysisTypeCode;

                        //Check if the attribute type code exists in the Transaction Analysis Attributes table
                        ARecurringTransAnalAttribRow transAnalAttrRow =
                            (ARecurringTransAnalAttribRow)AInspectDS.ARecurringTransAnalAttrib.Rows.Find(new object[] { ALedgerNumber, ABatchNumber,
                                                                                                                        AJournalNumber,
                                                                                                                        currentTransactionNumber,
                                                                                                                        analysisTypeCode });

                        if (transAnalAttrRow == null)
                        {
                            //Create a new TypeCode for this account
                            ARecurringTransAnalAttribRow newRow = AInspectDS.ARecurringTransAnalAttrib.NewRowTyped(true);
                            newRow.LedgerNumber = ALedgerNumber;
                            newRow.BatchNumber = ABatchNumber;
                            newRow.JournalNumber = AJournalNumber;
                            newRow.TransactionNumber = currentTransactionNumber;
                            newRow.AnalysisTypeCode = analysisTypeCode;
                            newRow.AccountCode = currentTransAccountCode;

                            AInspectDS.ARecurringTransAnalAttrib.Rows.Add(newRow);
                        }
                        else if (transAnalAttrRow.AccountCode != currentTransAccountCode)
                        {
                            //Check account code is correct
                            transAnalAttrRow.AccountCode = currentTransAccountCode;
                        }
                    }
                }

                GLBatchTDSAccess.SubmitChanges(AInspectDS);

                ASubmissionResult = TSubmitChangesResult.scrOK;

                AInspectDS.ARecurringTransAnalAttrib.AcceptChanges();
            }

            transAnalAttrView.RowFilter = string.Empty;
        }
        private void SetupAnalysisAttributeGrid(TSgrdDataGridPaged AGrid, ref SourceGrid.Cells.Editors.ComboBox AGridCombo)
        {
            AGrid.DataSource = null;
            GLBatchTDS DS = null;
            SourceGrid.Cells.Editors.ComboBox ATempCombo = null;

            if (AGrid.Name == grdFromAnalAttributes.Name)
            {
                FTempFromDS = (GLBatchTDS)FMainDS.Clone();
                DS = FTempFromDS;
            }
            else
            {
                DS = FMainDS;
            }

            if (AGrid.Columns.Count == 0)
            {
                ATempCombo = new SourceGrid.Cells.Editors.ComboBox(typeof(string));
                ATempCombo.EnableEdit = true;
                ATempCombo.EditableMode = EditableMode.Focus;
                AGrid.Columns.Clear();
                AGrid.AddTextColumn(Catalog.GetString("Type"), FMainDS.ATransAnalAttrib.ColumnAnalysisTypeCode, 99);
                AGrid.AddTextColumn(Catalog.GetString("Value"),
                    DS.ATransAnalAttrib.Columns[ATransAnalAttribTable.GetAnalysisAttributeValueDBName()], 150,
                    ATempCombo);
            }

            FAnalysisAttributesLogic.SetTransAnalAttributeDefaultView(DS, true);
            DS.ATransAnalAttrib.DefaultView.AllowNew = false;
            AGrid.DataSource = new DevAge.ComponentModel.BoundDataView(DS.ATransAnalAttrib.DefaultView);
            AGrid.SetHeaderTooltip(0, Catalog.GetString("Type"));
            AGrid.SetHeaderTooltip(1, Catalog.GetString("Value"));

            AGrid.Selection.SelectionChanged += AnalysisAttributesGrid_RowSelected;

            //Prepare Analysis attributes grid to highlight inactive analysis codes
            // Create a cell view for special conditions
            SourceGrid.Cells.Views.Cell strikeoutCell2 = new SourceGrid.Cells.Views.Cell();
            strikeoutCell2.Font = new System.Drawing.Font(AGrid.Font, FontStyle.Strikeout);

            // Create a condition, apply the view when true, and assign a delegate to handle it
            SourceGrid.Conditions.ConditionView conditionAnalysisCodeActive = new SourceGrid.Conditions.ConditionView(strikeoutCell2);
            conditionAnalysisCodeActive.EvaluateFunction = delegate(SourceGrid.DataGridColumn column2, int gridRow2, object itemRow2)
            {
                DataRowView row2 = (DataRowView)itemRow2;
                string analysisCode = row2[ATransAnalAttribTable.ColumnAnalysisTypeCodeId].ToString();

                if (AGrid.Name == grdFromAnalAttributes.Name)
                {
                    return !FAnalysisAttributesLogic.AnalysisCodeIsActive(
                        FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString(), FCacheDS.AAnalysisAttribute,
                        analysisCode);
                }

                return !FAnalysisAttributesLogic.AnalysisCodeIsActive(
                    cmbDetailAccountCode.GetSelectedString(), FCacheDS.AAnalysisAttribute, analysisCode);
            };

            // Create a condition, apply the view when true, and assign a delegate to handle it
            SourceGrid.Conditions.ConditionView conditionAnalysisAttributeValueActive = new SourceGrid.Conditions.ConditionView(strikeoutCell2);
            conditionAnalysisAttributeValueActive.EvaluateFunction = delegate(SourceGrid.DataGridColumn column2, int gridRow2, object itemRow2)
            {
                if (itemRow2 != null)
                {
                    DataRowView row2 = (DataRowView)itemRow2;
                    string analysisCode = row2[ATransAnalAttribTable.ColumnAnalysisTypeCodeId].ToString();
                    string analysisAttributeValue = row2[ATransAnalAttribTable.ColumnAnalysisAttributeValueId].ToString();
                    return !TAnalysisAttributes.AnalysisAttributeValueIsActive(ref ATempCombo,
                        FCacheDS.AFreeformAnalysis,
                        analysisCode,
                        analysisAttributeValue);
                }
                else
                {
                    return false;
                }
            };

            //Add conditions to columns
            int indexOfAnalysisCodeColumn = 0;
            int indexOfAnalysisAttributeValueColumn = 1;

            AGrid.Columns[indexOfAnalysisCodeColumn].Conditions.Add(conditionAnalysisCodeActive);
            AGrid.Columns[indexOfAnalysisAttributeValueColumn].Conditions.Add(conditionAnalysisAttributeValueActive);

            AGridCombo = ATempCombo;
        }
        private void RefreshAnalysisAttributesGrid(object sender, GLBatchTDS ADS)
        {
            TSgrdDataGridPaged Grid = null;
            int TransactionNumber = 0;
            string AccountCode = "";

            if ((sender as SourceGrid.Selection.RowSelection) != null)
            {
                Grid = grdFromAnalAttributes;
                TransactionNumber = FJournal.LastTransactionNumber + 1;
                AccountCode = FPreviouslySelectedAccountsRow[AGeneralLedgerMasterTable.GetAccountCodeDBName()].ToString();
            }
            else
            {
                Grid = grdToAnalAttributes;
                TransactionNumber = FCurrentTransactionNumber;
                AccountCode = cmbDetailAccountCode.GetSelectedString();
            }

            //Empty the grid
            ADS.ATransAnalAttrib.DefaultView.RowFilter = "1=2";
            FPSAttributesRow = null;

            if (!TRemote.MFinance.Setup.WebConnectors.AccountHasAnalysisAttributes(FLedgerNumber, AccountCode,
                    true))
            {
                if (Grid.Enabled)
                {
                    Grid.Enabled = false;
                }

                return;
            }
            else
            {
                if (!Grid.Enabled)
                {
                    Grid.Enabled = true;
                }
            }

            FAnalysisAttributesLogic.SetTransAnalAttributeDefaultView(ADS, true, TransactionNumber);

            Grid.DataSource = new DevAge.ComponentModel.BoundDataView(ADS.ATransAnalAttrib.DefaultView);

            if (Grid.Rows.Count > 1)
            {
                Grid.SelectRowWithoutFocus(1);
                AnalysisAttributesGrid_RowSelected(Grid, null);
            }
        }
Ejemplo n.º 38
0
        public static TSubmitChangesResult SaveGLBatchTDS(ref GLBatchTDS AInspectDS,
            out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = new TVerificationResultCollection();
            TVerificationResultCollection VerificationResult = AVerificationResult;

            // make sure that empty tables are removed
            AInspectDS = AInspectDS.GetChangesTyped(true);

            bool batchTableInDataSet = (AInspectDS.ABatch != null);
            bool journalTableInDataSet = (AInspectDS.AJournal != null);
            bool transTableInDataSet = (AInspectDS.ATransaction != null);
            bool attrTableInDataSet = (AInspectDS.ATransAnalAttrib != null);
            bool recurrBatchTableInDataSet = (AInspectDS.ARecurringBatch != null);
            bool recurrJournalTableInDataSet = (AInspectDS.ARecurringJournal != null);
            bool recurrTransTableInDataSet = (AInspectDS.ARecurringTransaction != null);

            //bool newTransaction = false;
            TDBTransaction Transaction = null;

            GLBatchTDS InspectDS = AInspectDS;

            // calculate debit and credit sums for journal and batch? but careful: we only have the changed parts!
            // no, we calculate the debit and credit sums before the posting, with GLRoutines.UpdateTotalsOfBatch

            // check added and modified and deleted rows: are they related to a posted or cancelled batch? we must not save adjusted posted batches!
            List <Int32>BatchNumbersInvolved = new List <int>();
            Int32 LedgerNumber = -1;

            //Check if saving recurring tables
            if (recurrBatchTableInDataSet
                || recurrJournalTableInDataSet
                || recurrTransTableInDataSet)
            {
                if (batchTableInDataSet || journalTableInDataSet || transTableInDataSet || attrTableInDataSet)
                {
                    throw new Exception(
                        "SaveGLBatchTDS: need to call GetChangesTyped before saving, otherwise confusion about recurring or normal gl batch");
                }

                return SaveRecurringGLBatchTDS(ref AInspectDS);
            }

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable,
                ref Transaction,
                delegate
                {
                    if (batchTableInDataSet)
                    {
                        LedgerNumber = ((ABatchRow)InspectDS.ABatch.Rows[0]).LedgerNumber;

                        foreach (ABatchRow batch in InspectDS.ABatch.Rows)
                        {
                            if (batch.RowState != DataRowState.Added)
                            {
                                Int32 BatchNumber;

                                try
                                {
                                    BatchNumber = batch.BatchNumber;
                                }
                                catch (Exception)
                                {
                                    // for deleted batches
                                    BatchNumber = (Int32)batch[ABatchTable.ColumnBatchNumberId, DataRowVersion.Original];
                                }

                                if (!BatchNumbersInvolved.Contains(BatchNumber))
                                {
                                    BatchNumbersInvolved.Add(BatchNumber);
                                }
                            }

                            int PeriodNumber, YearNr;

                            if (TFinancialYear.IsValidPostingPeriod(LedgerNumber,
                                    batch.DateEffective,
                                    out PeriodNumber,
                                    out YearNr,
                                    Transaction))
                            {
                                batch.BatchYear = YearNr;
                                batch.BatchPeriod = PeriodNumber;
                            }
                        }
                    }

                    if (journalTableInDataSet)
                    {
                        if (LedgerNumber == -1)
                        {
                            LedgerNumber = ((AJournalRow)InspectDS.AJournal.Rows[0]).LedgerNumber;
                        }

                        foreach (GLBatchTDSAJournalRow journal in InspectDS.AJournal.Rows)
                        {
                            Int32 BatchNumber;

                            try
                            {
                                BatchNumber = journal.BatchNumber;
                                LedgerNumber = journal.LedgerNumber;
                            }
                            catch (Exception)
                            {
                                // for deleted journals
                                BatchNumber = (Int32)journal[AJournalTable.ColumnBatchNumberId, DataRowVersion.Original];
                                LedgerNumber = (Int32)journal[AJournalTable.ColumnLedgerNumberId, DataRowVersion.Original];
                            }

                            if (!BatchNumbersInvolved.Contains(BatchNumber))
                            {
                                BatchNumbersInvolved.Add(BatchNumber);
                            }
                        }
                    }

                    if (transTableInDataSet)
                    {
                        if (LedgerNumber == -1)
                        {
                            LedgerNumber = ((ATransactionRow)InspectDS.ATransaction.Rows[0]).LedgerNumber;
                        }

                        GLPostingTDS TestAccountsAndCostCentres = new GLPostingTDS();

                        foreach (ATransactionRow transaction in InspectDS.ATransaction.Rows)
                        {
                            Int32 BatchNumber;

                            try
                            {
                                BatchNumber = transaction.BatchNumber;
                                LedgerNumber = transaction.LedgerNumber;

                                if (TestAccountsAndCostCentres.AAccount.Count == 0)
                                {
                                    AAccountAccess.LoadViaALedger(TestAccountsAndCostCentres, LedgerNumber, Transaction);
                                    ACostCentreAccess.LoadViaALedger(TestAccountsAndCostCentres, LedgerNumber, Transaction);
                                }

                                // TODO could check for active accounts and cost centres?

                                // check for valid accounts and cost centres
                                if (TestAccountsAndCostCentres.AAccount.Rows.Find(new object[] { LedgerNumber, transaction.AccountCode }) == null)
                                {
                                    VerificationResult.Add(new TVerificationResult(
                                            Catalog.GetString("Cannot save transaction"),
                                            String.Format(Catalog.GetString("Invalid account code {0} in batch {1}, journal {2}, transaction {3}"),
                                                transaction.AccountCode,
                                                transaction.BatchNumber,
                                                transaction.JournalNumber,
                                                transaction.TransactionNumber),
                                            TResultSeverity.Resv_Critical));
                                }

                                if (TestAccountsAndCostCentres.ACostCentre.Rows.Find(new object[] { LedgerNumber,
                                                                                                    transaction.CostCentreCode }) == null)
                                {
                                    VerificationResult.Add(new TVerificationResult(
                                            Catalog.GetString("Cannot save transaction"),
                                            String.Format(Catalog.GetString("Invalid cost centre code {0} in batch {1}, journal {2}, transaction {3}"),
                                                transaction.CostCentreCode,
                                                transaction.BatchNumber,
                                                transaction.JournalNumber,
                                                transaction.TransactionNumber),
                                            TResultSeverity.Resv_Critical));
                                }

                                // AmountInBaseCurrency must be greater than 0.
                                // Transaction amount can be 0 if ForexGain.
                                if (transaction.AmountInBaseCurrency <= 0)
                                {
                                    VerificationResult.Add(new TVerificationResult(
                                            Catalog.GetString("Cannot save transaction"),
                                            String.Format(Catalog.GetString("Invalid amount in batch {0}, journal {1}, transaction {2}. " +
                                                    "Either the debit amount or the credit amount needs to be greater than 0."),
                                                transaction.BatchNumber,
                                                transaction.JournalNumber,
                                                transaction.TransactionNumber),
                                            TResultSeverity.Resv_Critical));
                                }
                            }
                            catch (Exception)
                            {
                                // for deleted transactions
                                BatchNumber = (Int32)transaction[ATransactionTable.ColumnBatchNumberId, DataRowVersion.Original];
                                LedgerNumber = (Int32)transaction[ATransactionTable.ColumnLedgerNumberId, DataRowVersion.Original];
                            }

                            if (!BatchNumbersInvolved.Contains(BatchNumber))
                            {
                                BatchNumbersInvolved.Add(BatchNumber);
                            }
                        }
                    }

                    if (attrTableInDataSet)
                    {
                        foreach (ATransAnalAttribRow transAnalAttrib in InspectDS.ATransAnalAttrib.Rows)
                        {
                            Int32 BatchNumber;

                            if (transAnalAttrib.RowState != DataRowState.Deleted)
                            {
                                BatchNumber = transAnalAttrib.BatchNumber;

                                if (!BatchNumbersInvolved.Contains(BatchNumber))
                                {
                                    BatchNumbersInvolved.Add(BatchNumber);
                                }
                            }
                        }
                    }

                    // load previously stored batches and check for posted status
                    if (BatchNumbersInvolved.Count == 0)
                    {
                        VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"),
                                Catalog.GetString("Cannot save an empty Batch!"),
                                TResultSeverity.Resv_Critical));
                    }
                    else
                    {
                        string ListOfBatchNumbers = string.Empty;

                        foreach (Int32 BatchNumber in BatchNumbersInvolved)
                        {
                            ListOfBatchNumbers = StringHelper.AddCSV(ListOfBatchNumbers, BatchNumber.ToString());
                        }

                        string SQLStatement = "SELECT * " +
                                              " FROM PUB_" + ABatchTable.GetTableDBName() + " WHERE " + ABatchTable.GetLedgerNumberDBName() + " = " +
                                              LedgerNumber.ToString() +
                                              " AND " + ABatchTable.GetBatchNumberDBName() + " IN (" + ListOfBatchNumbers + ")";

                        GLBatchTDS BatchDS = new GLBatchTDS();

                        DBAccess.GDBAccessObj.Select(BatchDS, SQLStatement, BatchDS.ABatch.TableName, Transaction);

                        foreach (ABatchRow batch in BatchDS.ABatch.Rows)
                        {
                            if ((batch.BatchStatus == MFinanceConstants.BATCH_POSTED)
                                || (batch.BatchStatus == MFinanceConstants.BATCH_CANCELLED))
                            {
                                VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"),
                                        String.Format(Catalog.GetString("Cannot modify Batch {0} because it is {1}"),
                                            batch.BatchNumber, batch.BatchStatus),
                                        TResultSeverity.Resv_Critical));
                            }
                        }
                    }
                });

            AVerificationResult = VerificationResult;

            if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
            {
                return TSubmitChangesResult.scrError;
            }

            //Need to save changes before deleting any transactions
            GLBatchTDSAccess.SubmitChanges(AInspectDS);

            TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK;

            if ((transTableInDataSet) && (AInspectDS.ATransaction.Rows.Count > 0))
            {
                //Accept deletion of Attributes to allow deletion of transactions
                if (attrTableInDataSet)
                {
                    AInspectDS.ATransAnalAttrib.AcceptChanges();
                }

                AInspectDS.ATransaction.AcceptChanges();

                if (AInspectDS.ATransaction.Count > 0)
                {
                    ATransactionRow tranR = (ATransactionRow)AInspectDS.ATransaction.Rows[0];

                    Int32 currentLedger = tranR.LedgerNumber;
                    Int32 currentBatch = tranR.BatchNumber;
                    Int32 currentJournal = tranR.JournalNumber;
                    Int32 transToDelete = 0;

                    try
                    {
                        //Check if any records have been marked for deletion
                        DataRow[] foundTransactionForDeletion = AInspectDS.ATransaction.Select(String.Format("{0} = '{1}'",
                                ATransactionTable.GetSubTypeDBName(),
                                MFinanceConstants.MARKED_FOR_DELETION));

                        if (foundTransactionForDeletion.Length > 0)
                        {
                            ATransactionRow transRowClient = null;

                            for (int i = 0; i < foundTransactionForDeletion.Length; i++)
                            {
                                transRowClient = (ATransactionRow)foundTransactionForDeletion[i];

                                transToDelete = transRowClient.TransactionNumber;
                                TLogging.Log(String.Format("Transaction to Delete: {0} from Journal: {1} in Batch: {2}",
                                        transToDelete,
                                        currentJournal,
                                        currentBatch));

                                transRowClient.Delete();
                            }

                            //Submit all changes
                            GLBatchTDSAccess.SubmitChanges(AInspectDS);

                            SubmissionResult = TSubmitChangesResult.scrOK;
                        }
                    }
                    catch (Exception ex)
                    {
                        TLogging.Log("Saving DataSet: " + ex.Message);

                        TLogging.Log(String.Format("Error trying to save transaction: {0} in Journal: {1}, Batch: {2}",
                                transToDelete,
                                currentJournal,
                                currentBatch
                                ));

                        SubmissionResult = TSubmitChangesResult.scrError;
                    }
                }
            }

            return SubmissionResult;
        }
Ejemplo n.º 39
0
        public static GLBatchTDS LoadABatch(Int32 ALedgerNumber, int AYear, int APeriod)
        {
            GLBatchTDS MainDS = new GLBatchTDS();
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

            string FilterByPeriod = string.Empty;

            if (AYear > -1)
            {
                FilterByPeriod = String.Format(" AND PUB_{0}.{1} = {2}",
                    ABatchTable.GetTableDBName(),
                    ABatchTable.GetBatchYearDBName(),
                    AYear);

                if ((APeriod == 0) && (AYear == MainDS.ALedger[0].CurrentFinancialYear))
                {
                    //Return current and forwarding periods
                    FilterByPeriod += String.Format(" AND PUB_{0}.{1} >= {2}",
                        ABatchTable.GetTableDBName(),
                        ABatchTable.GetBatchPeriodDBName(),
                        MainDS.ALedger[0].CurrentPeriod);
                }
                else if (APeriod > 0)
                {
                    //Return only specified period
                    FilterByPeriod += String.Format(" AND PUB_{0}.{1} = {2}",
                        ABatchTable.GetTableDBName(),
                        ABatchTable.GetBatchPeriodDBName(),
                        APeriod);
                }
                else
                {
                    //Nothing to add, returns all periods
                }
            }

            string SelectClause =
                String.Format("SELECT * FROM PUB_{0} WHERE {1} = {2}",
                    ABatchTable.GetTableDBName(),
                    ABatchTable.GetLedgerNumberDBName(),
                    ALedgerNumber);

            DBAccess.GDBAccessObj.Select(MainDS, SelectClause + FilterByPeriod,
                MainDS.ABatch.TableName, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();
            return MainDS;
        }
Ejemplo n.º 40
0
        public static void UpdateTotalsOfBatch(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            //TVerificationResultCollection AVerificationResult = new TVerificationResultCollection();
            GLBatchTDS glDS = new GLBatchTDS();

            decimal sumDebits = 0.0M;
            decimal sumCredits = 0.0M;

            //Load all Batch, Journal and Transaction records
            glDS.Merge(LoadABatchAJournalATransaction(ALedgerNumber, ABatchNumber));

            if ((glDS.ABatch == null) || (glDS.ABatch.Count == 0))
            {
                return;
            }

            try
            {
                ABatchRow currentBatch = (ABatchRow)glDS.ABatch.Rows[0];

                glDS.AJournal.DefaultView.RowFilter = string.Empty;

                foreach (DataRowView journalview in glDS.AJournal.DefaultView)
                {
                    GLBatchTDSAJournalRow journalrow = (GLBatchTDSAJournalRow)journalview.Row;

                    UpdateTotalsOfJournal(ref glDS, journalrow);

                    sumDebits += journalrow.JournalDebitTotal;
                    sumCredits += journalrow.JournalCreditTotal;
                }

                currentBatch.BatchDebitTotal = sumDebits;
                currentBatch.BatchCreditTotal = sumCredits;
                currentBatch.BatchRunningTotal = Math.Round(sumDebits - sumCredits, 2);

                glDS.AcceptChanges();
            }
            catch (Exception)
            {
                glDS.RejectChanges();
                throw;
            }
        }
Ejemplo n.º 41
0
        public static void UpdateTotalsOfJournal(ref GLBatchTDS AMainDS,
            GLBatchTDSAJournalRow ACurrentJournal)
        {
            if (ACurrentJournal == null)
            {
                return;
            }

            if ((ACurrentJournal.ExchangeRateToBase == 0.0m)
                && (ACurrentJournal.TransactionTypeCode != CommonAccountingTransactionTypesEnum.REVAL.ToString()))
            {
                throw new Exception(String.Format("Batch {0} Journal {1} has invalid exchange rate to base",
                        ACurrentJournal.BatchNumber,
                        ACurrentJournal.JournalNumber));
            }

            ACurrentJournal.JournalDebitTotal = 0.0M;
            ACurrentJournal.JournalDebitTotalBase = 0.0M;
            ACurrentJournal.JournalCreditTotal = 0.0M;
            ACurrentJournal.JournalCreditTotalBase = 0.0M;

            DataView trnsDataView = new DataView(AMainDS.ATransaction);

            trnsDataView.RowFilter = String.Format("{0} = {1} And {2} = {3}",
                ATransactionTable.GetBatchNumberDBName(),
                ACurrentJournal.BatchNumber,
                ATransactionTable.GetJournalNumberDBName(),
                ACurrentJournal.JournalNumber);

            // transactions are filtered for this journal; add up the total amounts
            foreach (DataRowView v in trnsDataView)
            {
                ATransactionRow r = (ATransactionRow)v.Row;

                // recalculate the amount in base currency

                if (ACurrentJournal.TransactionTypeCode != CommonAccountingTransactionTypesEnum.REVAL.ToString())
                {
                    r.AmountInBaseCurrency = GLRoutines.Divide(r.TransactionAmount, ACurrentJournal.ExchangeRateToBase);
                }

                if (r.DebitCreditIndicator)
                {
                    ACurrentJournal.JournalDebitTotal += r.TransactionAmount;
                    ACurrentJournal.JournalDebitTotalBase += r.AmountInBaseCurrency;
                }
                else
                {
                    ACurrentJournal.JournalCreditTotal += r.TransactionAmount;
                    ACurrentJournal.JournalCreditTotalBase += r.AmountInBaseCurrency;
                }
            }
        }
Ejemplo n.º 42
0
        public static void UpdateTotalsOfBatch(ref GLBatchTDS AMainDS,
            ABatchRow ACurrentBatch)
        {
            decimal sumDebits = 0.0M;
            decimal sumCredits = 0.0M;

            DataView jnlDataView = new DataView(AMainDS.AJournal);

            jnlDataView.RowFilter = String.Format("{0}={1}",
                AJournalTable.GetBatchNumberDBName(),
                ACurrentBatch.BatchNumber);

            foreach (DataRowView journalview in jnlDataView)
            {
                GLBatchTDSAJournalRow journalrow = (GLBatchTDSAJournalRow)journalview.Row;

                UpdateTotalsOfJournal(ref AMainDS, journalrow);

                sumDebits += journalrow.JournalDebitTotal;
                sumCredits += journalrow.JournalCreditTotal;
            }

            ACurrentBatch.BatchDebitTotal = sumDebits;
            ACurrentBatch.BatchCreditTotal = sumCredits;
            ACurrentBatch.BatchRunningTotal = Math.Round(sumDebits - sumCredits, 2);
        }
Ejemplo n.º 43
0
        public static void UpdateTotalsOfBatchFromJournals(ref GLBatchTDS AMainDS,
            int ACurrentBatchNo, int ACurrentJournalNo = 0)
        {
            if ((AMainDS.ABatch == null) || (AMainDS.ABatch.Count == 0))
            {
                return;
            }

            int currentLedger = ((ABatchRow)AMainDS.ABatch.Rows[0]).LedgerNumber;

            decimal sumDebits = 0.0M;
            decimal sumCredits = 0.0M;

            //Locate the current Batch

            ABatchRow batchRow = (ABatchRow)AMainDS.ABatch.Rows.Find(new object[] { currentLedger, ACurrentBatchNo });

            if (batchRow == null)
            {
                return;
            }

            //If journal number is given, then update the specified journal according to the transaction values in the dataset
            if (ACurrentJournalNo > 0)
            {
                GLBatchTDSAJournalRow journalRow = (GLBatchTDSAJournalRow)AMainDS.AJournal.Rows.Find(new object[] { currentLedger, ACurrentBatchNo,
                                                                                                                    ACurrentJournalNo });

                if (journalRow != null)
                {
                    //Update the totals of the current journal from the transactions.
                    UpdateTotalsOfJournal(ref AMainDS, journalRow);
                }
            }

            //Iterate through all journals in the current Batch
            DataView jnlDataView = new DataView(AMainDS.AJournal);

            jnlDataView.RowFilter = String.Format("{0}={1}",
                AJournalTable.GetBatchNumberDBName(),
                ACurrentBatchNo);

            //Recalculate the Batch totals
            foreach (DataRowView journalview in jnlDataView)
            {
                GLBatchTDSAJournalRow journalrow = (GLBatchTDSAJournalRow)journalview.Row;

                sumDebits += journalrow.JournalDebitTotal;
                sumCredits += journalrow.JournalCreditTotal;
            }

            batchRow.BatchDebitTotal = sumDebits;
            batchRow.BatchCreditTotal = sumCredits;
            batchRow.BatchRunningTotal = Math.Round(sumDebits - sumCredits, 2);
        }
Ejemplo n.º 44
0
 public static bool GLBatchCanBeCancelled(out GLBatchTDS AMainDS,
     Int32 ALedgerNumber,
     Int32 ABatchNumber,
     out TVerificationResultCollection AVerifications)
 {
     return TGLPosting.GLBatchCanBeCancelled(out AMainDS, ALedgerNumber, ABatchNumber, out AVerifications);
 }
Ejemplo n.º 45
0
        public static void SubmitRecurringGLBatch(Hashtable requestParams)
        {
            Boolean NewTransaction = false;
            GLBatchTDS GLMainDS = new GLBatchTDS();
            ABatchRow BatchRow;
            Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"];
            Int32 ABatchNumber = (Int32)requestParams["ABatchNumber"];
            DateTime AEffectiveDate = (DateTime)requestParams["AEffectiveDate"];
            Decimal AExchangeRateToBase = (Decimal)requestParams["AExchangeRateToBase"];;

            Decimal AExchangeRateIntlToBase = (Decimal)requestParams["AExchangeRateIntlToBase"];
            int PeriodNumber, YearNr;

            bool TransactionInIntlCurrency = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            try
            {
                ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction);

                // make sure that recurring GL batch is fully loaded, including journals, transactions and attributes
                GLBatchTDS RGLMainDS = LoadARecurringBatchAndContent(ALedgerNumber, ABatchNumber);

                // Assuming all relevant data is loaded in FMainDS
                foreach (ARecurringBatchRow recBatch  in RGLMainDS.ARecurringBatch.Rows)
                {
                    if ((recBatch.BatchNumber == ABatchNumber) && (recBatch.LedgerNumber == ALedgerNumber))
                    {
                        GLMainDS = CreateABatch(ALedgerNumber);

                        BatchRow = (ABatchRow)GLMainDS.ABatch.Rows[0];
                        BatchRow.DateEffective = AEffectiveDate;
                        BatchRow.BatchDescription = recBatch.BatchDescription;
                        BatchRow.BatchControlTotal = recBatch.BatchControlTotal;
                        BatchRow.BatchRunningTotal = recBatch.BatchRunningTotal;
                        BatchRow.BatchCreditTotal = recBatch.BatchCreditTotal;
                        BatchRow.BatchDebitTotal = recBatch.BatchDebitTotal;

                        if (TFinancialYear.IsValidPostingPeriod(ALedgerNumber,
                                AEffectiveDate,
                                out PeriodNumber,
                                out YearNr,
                                Transaction))
                        {
                            BatchRow.BatchYear = YearNr;
                            BatchRow.BatchPeriod = PeriodNumber;
                        }

                        foreach (ARecurringJournalRow recJournal in RGLMainDS.ARecurringJournal.Rows)
                        {
                            if ((recJournal.BatchNumber == ABatchNumber) && (recJournal.LedgerNumber == ALedgerNumber))
                            {
                                // create the journal from recJournal
                                AJournalRow JournalRow = GLMainDS.AJournal.NewRowTyped();
                                JournalRow.LedgerNumber = BatchRow.LedgerNumber;
                                JournalRow.BatchNumber = BatchRow.BatchNumber;
                                JournalRow.JournalNumber = recJournal.JournalNumber;
                                JournalRow.JournalDescription = recJournal.JournalDescription;
                                JournalRow.SubSystemCode = recJournal.SubSystemCode;
                                JournalRow.TransactionTypeCode = recJournal.TransactionTypeCode;
                                JournalRow.TransactionCurrency = recJournal.TransactionCurrency;
                                JournalRow.JournalCreditTotal = recJournal.JournalCreditTotal;
                                JournalRow.JournalDebitTotal = recJournal.JournalDebitTotal;
                                JournalRow.ExchangeRateToBase = AExchangeRateToBase;
                                JournalRow.DateEffective = AEffectiveDate;
                                JournalRow.JournalPeriod = recJournal.JournalPeriod;

                                GLMainDS.AJournal.Rows.Add(JournalRow);

                                if (JournalRow.JournalNumber > BatchRow.LastJournal)
                                {
                                    BatchRow.LastJournal = JournalRow.JournalNumber;
                                }

                                TransactionInIntlCurrency = (JournalRow.TransactionCurrency == LedgerTable[0].IntlCurrency);                                //TODO (not here, but in the client or while posting) Check for expired key ministry (while
                                                                                                                                                            // Posting)

                                foreach (ARecurringTransactionRow recTransaction in RGLMainDS.ARecurringTransaction.Rows)
                                {
                                    if ((recTransaction.JournalNumber == recJournal.JournalNumber)
                                        && (recTransaction.BatchNumber == ABatchNumber)
                                        && (recTransaction.LedgerNumber == ALedgerNumber))
                                    {
                                        ATransactionRow TransactionRow = GLMainDS.ATransaction.NewRowTyped();
                                        TransactionRow.LedgerNumber = JournalRow.LedgerNumber;
                                        TransactionRow.BatchNumber = JournalRow.BatchNumber;
                                        TransactionRow.JournalNumber = JournalRow.JournalNumber;
                                        TransactionRow.TransactionNumber = recTransaction.TransactionNumber;

                                        if (TransactionRow.TransactionNumber > JournalRow.LastTransactionNumber)
                                        {
                                            JournalRow.LastTransactionNumber = TransactionRow.TransactionNumber;
                                        }

                                        TransactionRow.Narrative = recTransaction.Narrative;
                                        TransactionRow.AccountCode = recTransaction.AccountCode;
                                        TransactionRow.CostCentreCode = recTransaction.CostCentreCode;
                                        TransactionRow.TransactionAmount = recTransaction.TransactionAmount;
                                        TransactionRow.AmountInBaseCurrency = GLRoutines.Divide(recTransaction.TransactionAmount, AExchangeRateToBase);

                                        if (!TransactionInIntlCurrency)
                                        {
                                            TransactionRow.AmountInIntlCurrency = GLRoutines.Divide((decimal)TransactionRow.AmountInBaseCurrency,
                                                AExchangeRateIntlToBase);
                                        }
                                        else
                                        {
                                            TransactionRow.AmountInIntlCurrency = TransactionRow.TransactionAmount;
                                        }

                                        TransactionRow.TransactionDate = AEffectiveDate;
                                        TransactionRow.DebitCreditIndicator = recTransaction.DebitCreditIndicator;
                                        TransactionRow.HeaderNumber = recTransaction.HeaderNumber;
                                        TransactionRow.DetailNumber = recTransaction.DetailNumber;
                                        TransactionRow.SubType = recTransaction.SubType;
                                        TransactionRow.Reference = recTransaction.Reference;

                                        GLMainDS.ATransaction.Rows.Add(TransactionRow);

                                        foreach (ARecurringTransAnalAttribRow recAnalAttrib in RGLMainDS.ARecurringTransAnalAttrib.Rows)
                                        {
                                            if ((recAnalAttrib.TransactionNumber == recTransaction.TransactionNumber)
                                                && (recTransaction.JournalNumber == recJournal.JournalNumber)
                                                && (recTransaction.BatchNumber == ABatchNumber)
                                                && (recTransaction.LedgerNumber == ALedgerNumber))
                                            {
                                                ATransAnalAttribRow TransAnalAttribRow = GLMainDS.ATransAnalAttrib.NewRowTyped();

                                                TransAnalAttribRow.LedgerNumber = JournalRow.LedgerNumber;
                                                TransAnalAttribRow.BatchNumber = JournalRow.BatchNumber;
                                                TransAnalAttribRow.JournalNumber = JournalRow.JournalNumber;
                                                TransAnalAttribRow.TransactionNumber = recTransaction.TransactionNumber;
                                                TransAnalAttribRow.AnalysisTypeCode = recAnalAttrib.AnalysisTypeCode;

                                                TransAnalAttribRow.AccountCode = recAnalAttrib.AccountCode;
                                                TransAnalAttribRow.CostCentreCode = recAnalAttrib.CostCentreCode;
                                                TransAnalAttribRow.AnalysisAttributeValue = recAnalAttrib.AnalysisAttributeValue;

                                                GLMainDS.ATransAnalAttrib.Rows.Add(TransAnalAttribRow);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                ABatchAccess.SubmitChanges(GLMainDS.ABatch, Transaction);

                ALedgerAccess.SubmitChanges(LedgerTable, Transaction);

                AJournalAccess.SubmitChanges(GLMainDS.AJournal, Transaction);

                ATransactionAccess.SubmitChanges(GLMainDS.ATransaction, Transaction);

                ATransAnalAttribAccess.SubmitChanges(GLMainDS.ATransAnalAttrib, Transaction);

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }

                GLMainDS.AcceptChanges();
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the submission of a Recurring GL Batch:" + Environment.NewLine + Exc.ToString());

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }

                throw new EOPAppException("Error in SubmitRecurringGLBatch", Exc);
            }
        }
Ejemplo n.º 46
0
        private static TSubmitChangesResult SaveRecurringGLBatchTDS(ref GLBatchTDS AInspectDS)
        {
            Int32 LedgerNumber;
            Int32 BatchNumber;
            Int32 JournalNumber;
            Int32 TransactionNumber;
            Int32 Counter;

            bool recurrBatchTableInDataSet = (AInspectDS.ARecurringBatch != null);
            bool recurrJournalTableInDataSet = (AInspectDS.ARecurringJournal != null);
            bool recurrTransactionTableInDataSet = (AInspectDS.ARecurringTransaction != null);
            bool recurrTransAnalTableInDataSet = (AInspectDS.ARecurringTransAnalAttrib != null);

            TSubmitChangesResult SubmissionResult = new TSubmitChangesResult();

            ARecurringJournalTable JournalTable = new ARecurringJournalTable();
            ARecurringJournalRow TemplateJournalRow = JournalTable.NewRowTyped(false);

            ARecurringTransactionTable TransactionTable = new ARecurringTransactionTable();
            ARecurringTransactionRow TemplateTransactionRow = TransactionTable.NewRowTyped(false);

            ARecurringTransAnalAttribTable TransAnalAttribTable = new ARecurringTransAnalAttribTable();
            ARecurringTransAnalAttribRow TemplateTransAnalAttribRow = TransAnalAttribTable.NewRowTyped(false);

            GLBatchTDS DeletedDS = new GLBatchTDS();
            ARecurringTransAnalAttribTable DeletedTransAnalAttribTable;

            // in this method we also think about deleted batches, journals, transactions where subsequent information
            // had not been loaded yet: a type of cascading delete is being used (real cascading delete currently does
            // not go down the number of levels needed).

            TDBTransaction Transaction = null;
            GLBatchTDS InspectDS = AInspectDS;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable,
                ref Transaction,
                delegate
                {
                    if (recurrBatchTableInDataSet)
                    {
                        foreach (ARecurringBatchRow batch in InspectDS.ARecurringBatch.Rows)
                        {
                            if (batch.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)batch[ARecurringBatchTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)batch[ARecurringBatchTable.ColumnBatchNumberId, DataRowVersion.Original];

                                // load all depending journals, transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);

                                TemplateTransactionRow.LedgerNumber = LedgerNumber;
                                TemplateTransactionRow.BatchNumber = BatchNumber;
                                ARecurringTransactionAccess.LoadUsingTemplate(DeletedDS, TemplateTransactionRow, Transaction);

                                for (Counter = DeletedDS.ARecurringTransaction.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringTransaction.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringTransaction);

                                TemplateJournalRow.LedgerNumber = LedgerNumber;
                                TemplateJournalRow.BatchNumber = BatchNumber;
                                ARecurringJournalAccess.LoadUsingTemplate(DeletedDS, TemplateJournalRow, Transaction);

                                for (Counter = DeletedDS.ARecurringJournal.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringJournal.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringJournal);
                            }
                        }
                    }

                    if (recurrJournalTableInDataSet)
                    {
                        foreach (ARecurringJournalRow journal in InspectDS.ARecurringJournal.Rows)
                        {
                            if (journal.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)journal[ARecurringJournalTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)journal[ARecurringJournalTable.ColumnBatchNumberId, DataRowVersion.Original];
                                JournalNumber = (Int32)journal[ARecurringJournalTable.ColumnJournalNumberId, DataRowVersion.Original];

                                // load all depending transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                TemplateTransAnalAttribRow.JournalNumber = JournalNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);

                                TemplateTransactionRow.LedgerNumber = LedgerNumber;
                                TemplateTransactionRow.BatchNumber = BatchNumber;
                                TemplateTransactionRow.JournalNumber = JournalNumber;
                                ARecurringTransactionAccess.LoadUsingTemplate(DeletedDS, TemplateTransactionRow, Transaction);

                                for (Counter = DeletedDS.ARecurringTransaction.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedDS.ARecurringTransaction.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedDS.ARecurringTransaction);
                            }
                        }
                    }

                    if (recurrTransactionTableInDataSet)
                    {
                        foreach (ARecurringTransactionRow transaction in InspectDS.ARecurringTransaction.Rows)
                        {
                            if (transaction.RowState == DataRowState.Deleted)
                            {
                                // need to use this way of retrieving data from deleted rows
                                LedgerNumber = (Int32)transaction[ARecurringTransactionTable.ColumnLedgerNumberId, DataRowVersion.Original];
                                BatchNumber = (Int32)transaction[ARecurringTransactionTable.ColumnBatchNumberId, DataRowVersion.Original];
                                JournalNumber = (Int32)transaction[ARecurringTransactionTable.ColumnJournalNumberId, DataRowVersion.Original];
                                TransactionNumber = (Int32)transaction[ARecurringTransactionTable.ColumnTransactionNumberId, DataRowVersion.Original];

                                // load all depending transactions and attributes and make sure they are also deleted via the dataset
                                TemplateTransAnalAttribRow.LedgerNumber = LedgerNumber;
                                TemplateTransAnalAttribRow.BatchNumber = BatchNumber;
                                TemplateTransAnalAttribRow.JournalNumber = JournalNumber;
                                TemplateTransAnalAttribRow.TransactionNumber = TransactionNumber;
                                DeletedTransAnalAttribTable =
                                    ARecurringTransAnalAttribAccess.LoadUsingTemplate(TemplateTransAnalAttribRow, Transaction);

                                for (Counter = DeletedTransAnalAttribTable.Count - 1; Counter >= 0; Counter--)
                                {
                                    DeletedTransAnalAttribTable.Rows[Counter].Delete();
                                }

                                InspectDS.Merge(DeletedTransAnalAttribTable);
                            }
                        }
                    }
                });

            // now submit the changes
            GLBatchTDSAccess.SubmitChanges(AInspectDS);

            SubmissionResult = TSubmitChangesResult.scrOK;

            if (recurrTransactionTableInDataSet)
            {
                //Accept deletion of Attributes to allow deletion of transactions
                if (recurrTransAnalTableInDataSet)
                {
                    AInspectDS.ARecurringTransAnalAttrib.AcceptChanges();
                }

                AInspectDS.ARecurringTransaction.AcceptChanges();

                if (AInspectDS.ARecurringTransaction.Count > 0)
                {
                    ARecurringTransactionRow tranR = (ARecurringTransactionRow)AInspectDS.ARecurringTransaction.Rows[0];

                    Int32 currentLedger = tranR.LedgerNumber;
                    Int32 currentBatch = tranR.BatchNumber;
                    Int32 currentJournal = tranR.JournalNumber;
                    Int32 transToDelete = 0;

                    try
                    {
                        //Check if any records have been marked for deletion
                        DataRow[] foundTransactionForDeletion = AInspectDS.ARecurringTransaction.Select(String.Format("{0} = '{1}'",
                                ARecurringTransactionTable.GetSubTypeDBName(),
                                MFinanceConstants.MARKED_FOR_DELETION));

                        if (foundTransactionForDeletion.Length > 0)
                        {
                            ARecurringTransactionRow transRowClient = null;

                            for (int i = 0; i < foundTransactionForDeletion.Length; i++)
                            {
                                transRowClient = (ARecurringTransactionRow)foundTransactionForDeletion[i];

                                transToDelete = transRowClient.TransactionNumber;
                                TLogging.Log(String.Format("Recurring transaction to Delete: {0} from Journal: {1} in Batch: {2}",
                                        transToDelete,
                                        currentJournal,
                                        currentBatch));

                                transRowClient.Delete();
                            }

                            //save changes
                            GLBatchTDSAccess.SubmitChanges(AInspectDS);

                            SubmissionResult = TSubmitChangesResult.scrOK;
                        }
                    }
                    catch (Exception ex)
                    {
                        TLogging.Log("Saving DataSet: " + ex.Message);

                        TLogging.Log(String.Format("Error trying to save transaction: {0} in Journal: {1}, Batch: {2}",
                                transToDelete,
                                currentJournal,
                                currentBatch
                                ));

                        SubmissionResult = TSubmitChangesResult.scrError;
                    }
                }
            }

            return SubmissionResult;
        }
Ejemplo n.º 47
0
        public static GLBatchTDS LoadARecurringTransAnalAttrib(Int32 ALedgerNumber,
            Int32 ABatchNumber,
            Int32 AJournalNumber,
            Int32 ATransactionNumber)
        {
            Boolean NewTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            GLBatchTDS MainDS = new GLBatchTDS();

            ARecurringTransAnalAttribAccess.LoadViaARecurringTransaction(MainDS,
                ALedgerNumber,
                ABatchNumber,
                AJournalNumber,
                ATransactionNumber,
                Transaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
Ejemplo n.º 48
0
        public static GLBatchTDS LoadAJournal(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AJournalNumber)
        {
            GLBatchTDS MainDS = new GLBatchTDS();
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            AJournalAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AJournalNumber, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();
            return MainDS;
        }
Ejemplo n.º 49
0
        public static GLBatchTDS LoadARecurringTransAnalAttribForJournal(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AJournalNumber)
        {
            GLBatchTDS MainDS = new GLBatchTDS();
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            ARecurringTransAnalAttribAccess.LoadViaARecurringJournal(MainDS, ALedgerNumber, ABatchNumber, AJournalNumber, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();
            return MainDS;
        }
Ejemplo n.º 50
0
        public static GLBatchTDS LoadATransactionForBatch(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            GLBatchTDS MainDS = new GLBatchTDS();
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            ATransactionAccess.LoadViaABatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);

            DBAccess.GDBAccessObj.RollbackTransaction();
            return MainDS;
        }
Ejemplo n.º 51
0
        // This manual method lets us peek at the data that is about to be saved...
        // The data has already been collected from the contols and validated and there is definitely something to save...
        private TSubmitChangesResult StoreManualCode(ref GLBatchTDS SubmitDS, out TVerificationResultCollection VerificationResult)
        {
            FLatestSaveIncludedForex = false;

            if (SubmitDS.AJournal != null)
            {
                // Check whether we are saving any rows that are in foreign currency
                DataView dv = new DataView(SubmitDS.AJournal,
                    String.Format("{0}<>{1}", AJournalTable.GetTransactionCurrencyDBName(), AJournalTable.GetBaseCurrencyDBName()),
                    String.Empty, DataViewRowState.CurrentRows);
                FLatestSaveIncludedForex = (dv.Count > 0);
            }

            // Now do the standard call to save the changes
            return TRemote.MFinance.GL.WebConnectors.SaveGLBatchTDS(ref SubmitDS, out VerificationResult);
        }
Ejemplo n.º 52
0
        public static GLBatchTDS LoadATransAnalAttribForJournal(Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AJournalNumber)
        {
            GLBatchTDS MainDS = new GLBatchTDS();
            bool NewTransaction;
            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction);

            ATransAnalAttribAccess.LoadViaAJournal(MainDS, ALedgerNumber, ABatchNumber, AJournalNumber, Transaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="APetraUtilsObject">Reference to the PetraUtilsObject for the form</param>
        /// <param name="ALedgerNumber">Ledger number</param>
        /// <param name="AMainDS">The main data set</param>
        /// <param name="AFilterFindPanelObject">The filter panel control object</param>
        public TUC_GLBatches_LoadAndFilter(TFrmPetraEditUtils APetraUtilsObject,
            int ALedgerNumber,
            GLBatchTDS AMainDS,
            TFilterAndFindPanel AFilterFindPanelObject)
        {
            FPetraUtilsObject = APetraUtilsObject;
            FFilterFindPanelObject = AFilterFindPanelObject;
            FMainDS = AMainDS;
            FLedgerNumber = ALedgerNumber;

            FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding");
            FcmbPeriod = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod");
            FrbtEditing = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing");
            FrbtPosting = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting");
            FrbtAll = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll");

            TFinanceControls.InitialiseAvailableFinancialYearsList(ref FcmbYearEnding, FLedgerNumber, false, true);
            //TLogging.Log("GL Financial Years completed");
            FrbtEditing.Checked = true;
            //TLogging.Log("Editing checkbox selected");
        }
Ejemplo n.º 54
0
        public static GLBatchTDS LoadALedgerTable(Int32 ALedgerNumber)
        {
            GLBatchTDS MainDS = new GLBatchTDS();

            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            ALedgerAccess.LoadByPrimaryKey(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();

            DBAccess.GDBAccessObj.RollbackTransaction();

            return MainDS;
        }
 // This does nothing. We do not actually want to save any data here.
 private TSubmitChangesResult StoreManualCode(ref GLBatchTDS ASubmitChanges, out TVerificationResultCollection AVerificationResult)
 {
     AVerificationResult = null;
     return TSubmitChangesResult.scrOK;
 }
Ejemplo n.º 56
0
        public static GLBatchTDS LoadARecurringBatch(Int32 ALedgerNumber, TFinanceBatchFilterEnum AFilterBatchStatus)
        {
            Boolean NewTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            GLBatchTDS MainDS = new GLBatchTDS();

            ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

            string SelectClause =
                String.Format("SELECT * FROM PUB_{0} WHERE {1} = {2}",
                    ARecurringBatchTable.GetTableDBName(),
                    ARecurringBatchTable.GetLedgerNumberDBName(),
                    ALedgerNumber);

            string FilterByBatchStatus = string.Empty;

            if (AFilterBatchStatus == TFinanceBatchFilterEnum.fbfAll)
            {
                // FilterByBatchStatus is empty
            }
            else if ((AFilterBatchStatus & TFinanceBatchFilterEnum.fbfEditing) != 0)
            {
                FilterByBatchStatus =
                    string.Format(" AND {0} = '{1}'",
                        ARecurringBatchTable.GetBatchStatusDBName(),
                        MFinanceConstants.BATCH_UNPOSTED);
            }

            DBAccess.GDBAccessObj.Select(MainDS, SelectClause + FilterByBatchStatus,
                MainDS.ARecurringBatch.TableName, Transaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
Ejemplo n.º 57
0
        /// <summary>
        /// Used for the validation of Analysis Attributes
        /// </summary>
        /// <param name="ATransactionNumber"></param>
        /// <param name="AAccountCode"></param>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AValueRequiredForType"></param>
        /// <returns></returns>
        public bool AccountRecurringAnalysisAttributesValuesExist(int ATransactionNumber,
            string AAccountCode,
            GLBatchTDS AGLBatchDS,
            out String AValueRequiredForType)
        {
            AValueRequiredForType = string.Empty;

            if (string.IsNullOrEmpty(AAccountCode) || (AGLBatchDS.ATransAnalAttrib.DefaultView.Count == 0))
            {
                return true;
            }

            StringCollection RequiredAnalAttrCodes = TRemote.MFinance.Setup.WebConnectors.RequiredAnalysisAttributesForAccount(FLedgerNumber,
                AAccountCode, false);

            string AnalysisCodeFilterValues = TAnalysisAttributes.ConvertStringCollectionToCSV(RequiredAnalAttrCodes, "'");

            DataView analAttrib = new DataView(AGLBatchDS.ARecurringTransAnalAttrib);

            analAttrib.RowFilter = String.Format("{0}={1} AND {2}={3} AND {4}={5} AND {6} IN ({7})",
                ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                FBatchNumber,
                ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                FJournalNumber,
                ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                ATransactionNumber,
                ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName(),
                AnalysisCodeFilterValues);

            foreach (DataRowView drv in analAttrib)
            {
                ARecurringTransAnalAttribRow rw = (ARecurringTransAnalAttribRow)drv.Row;

                string analysisCode = rw.AnalysisTypeCode;

                if (TRemote.MFinance.Setup.WebConnectors.AccountAnalysisAttributeRequiresValues(FLedgerNumber, analysisCode, false))
                {
                    if (rw.IsAnalysisAttributeValueNull() || (rw.AnalysisAttributeValue == string.Empty))
                    {
                        AValueRequiredForType = rw.AnalysisTypeCode;
                        return false;
                    }
                }
            }

            return true;
        }
Ejemplo n.º 58
0
        public static GLBatchTDS LoadARecurringBatchAndContent(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            Boolean NewTransaction = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);


            GLBatchTDS MainDS = new GLBatchTDS();

            ARecurringBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);
            ARecurringJournalAccess.LoadViaARecurringBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);

            ARecurringTransactionTable TransactionTable = new ARecurringTransactionTable();
            ARecurringTransactionRow TemplateTransactionRow = TransactionTable.NewRowTyped(false);
            TemplateTransactionRow.LedgerNumber = ALedgerNumber;
            TemplateTransactionRow.BatchNumber = ABatchNumber;
            ARecurringTransactionAccess.LoadUsingTemplate(MainDS, TemplateTransactionRow, Transaction);

            ARecurringTransAnalAttribTable TransAnalAttribTable = new ARecurringTransAnalAttribTable();
            ARecurringTransAnalAttribRow TemplateTransAnalAttribRow = TransAnalAttribTable.NewRowTyped(false);
            TemplateTransAnalAttribRow.LedgerNumber = ALedgerNumber;
            TemplateTransAnalAttribRow.BatchNumber = ABatchNumber;
            ARecurringTransAnalAttribAccess.LoadUsingTemplate(MainDS, TemplateTransAnalAttribRow, Transaction);

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return MainDS;
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Export all the Data of the batches array list to a String
        /// </summary>
        /// <param name="Abatches"></param>
        /// <param name="ArequestParams"></param>
        /// <param name="AexportString"></param>
        /// <returns>false if batch does not exist at all</returns>
        public bool ExportAllGLBatchData(ArrayList Abatches, Hashtable ArequestParams, out String AexportString)
        {
            FStringWriter = new StringWriter();
            FMainDS = new GLBatchTDS();
            FDelimiter = (String)ArequestParams["Delimiter"];
            FLedgerNumber = (Int32)ArequestParams["ALedgerNumber"];
            FDateFormatString = (String)ArequestParams["DateFormatString"];
            FSummary = (bool)ArequestParams["Summary"];
            FUseBaseCurrency = (bool)ArequestParams["bUseBaseCurrency"];
            FBaseCurrency = (String)ArequestParams["BaseCurrency"];
            FDateForSummary = (DateTime)ArequestParams["DateForSummary"];
            String NumberFormat = (String)ArequestParams["NumberFormat"];
            FCultureInfo = new CultureInfo(NumberFormat.Equals("American") ? "en-US" : "de-DE");
            FTransactionsOnly = (bool)ArequestParams["TransactionsOnly"];
            FDontSummarize = (bool)ArequestParams["bDontSummarize"];
            FDontSummarizeAccount = (String)ArequestParams["DontSummarizeAccount"];

            SortedDictionary <String, AJournalSummaryRow>sdSummary = new SortedDictionary <String, AJournalSummaryRow>();

            TDBTransaction Transaction = null;
            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                delegate
                {
                    UInt32 progressCounter = 0;
                    UInt32 progressJournalCounter = 0;

                    TProgressTracker.InitProgressTracker(DomainManager.GClientID.ToString(),
                        Catalog.GetString("Exporting GL Batches"),
                        100);

                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                        Catalog.GetString("Retrieving records"),
                        10);

                    while (Abatches.Count > 0)
                    {
                        Int32 ABatchNumber = (Int32)Abatches[0];
                        ABatchAccess.LoadByPrimaryKey(FMainDS, FLedgerNumber, ABatchNumber, Transaction);
                        AJournalAccess.LoadViaABatch(FMainDS, FLedgerNumber, ABatchNumber, Transaction);

                        foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                        {
                            if (journal.BatchNumber.Equals(ABatchNumber) && journal.LedgerNumber.Equals(FLedgerNumber))
                            {
                                ATransactionAccess.LoadViaAJournal(FMainDS, journal.LedgerNumber,
                                    journal.BatchNumber,
                                    journal.JournalNumber,
                                    Transaction);
                            }
                        }

                        foreach (ATransactionRow trans in FMainDS.ATransaction.Rows)
                        {
                            if (trans.BatchNumber.Equals(ABatchNumber) && trans.LedgerNumber.Equals(FLedgerNumber))
                            {
                                ATransAnalAttribAccess.LoadViaATransaction(FMainDS, trans.LedgerNumber,
                                    trans.BatchNumber,
                                    trans.JournalNumber,
                                    trans.TransactionNumber,
                                    Transaction);
                            }
                        }

                        Abatches.RemoveAt(0);
                    }

                    UInt32 counter = 0;
                    AJournalSummaryRow journalSummary = null;

                    foreach (ABatchRow batch in FMainDS.ABatch.Rows)
                    {
                        progressCounter = 0;

                        TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                            String.Format(Catalog.GetString("Batch {0}"), batch.BatchNumber),
                            20);

                        if (!FTransactionsOnly & !FSummary)
                        {
                            WriteBatchLine(batch);
                        }

                        //foreach (AJournalRow journal in journalDS.AJournal.Rows)
                        foreach (AJournalRow journal in FMainDS.AJournal.Rows)
                        {
                            if (journal.BatchNumber.Equals(batch.BatchNumber) && journal.LedgerNumber.Equals(batch.LedgerNumber))
                            {
                                progressJournalCounter = 0;

                                TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                    String.Format(Catalog.GetString("Batch {0}, Journal {1}"), batch.BatchNumber, journal.JournalNumber),
                                    (progressCounter / 25 + 4) * 5 > 90 ? 90 : (progressCounter / 25 + 4) * 5);

                                if (FSummary)
                                {
                                    String mapCurrency = FUseBaseCurrency ? FBaseCurrency : journal.TransactionCurrency;
                                    decimal mapExchangeRateToBase = FUseBaseCurrency ? 1 : journal.ExchangeRateToBase;

                                    if (!sdSummary.TryGetValue(mapCurrency, out journalSummary))
                                    {
                                        journalSummary = new AJournalSummaryRow();
                                        sdSummary.Add(mapCurrency, journalSummary);
                                    }

                                    //overwrite always because we want to have the last
                                    journalSummary.ExchangeRateToBase = mapExchangeRateToBase;
                                    journalSummary.TransactionCurrency = mapCurrency;
                                }
                                else
                                {
                                    if (!FTransactionsOnly)
                                    {
                                        WriteJournalLine(journal);
                                    }
                                }

                                FMainDS.ATransaction.DefaultView.Sort = ATransactionTable.GetTransactionNumberDBName();
                                FMainDS.ATransaction.DefaultView.RowFilter =
                                    String.Format("{0}={1} and {2}={3} and {4}={5}",
                                        ATransactionTable.GetLedgerNumberDBName(),
                                        journal.LedgerNumber,
                                        ATransactionTable.GetBatchNumberDBName(),
                                        journal.BatchNumber,
                                        ATransactionTable.GetJournalNumberDBName(),
                                        journal.JournalNumber);

                                foreach (DataRowView dv in FMainDS.ATransaction.DefaultView)
                                {
                                    progressJournalCounter++;

                                    if (++progressCounter % 25 == 0)
                                    {
                                        TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                                            String.Format(Catalog.GetString(
                                                    "Batch {0}, Journal {1} - {2}"), batch.BatchNumber, journal.JournalNumber,
                                                progressJournalCounter),
                                            (progressCounter / 25 + 4) * 5 > 90 ? 90 : (progressCounter / 25 + 4) * 5);
                                    }

                                    ATransactionRow transactionRow = (ATransactionRow)dv.Row;

                                    if (FSummary)
                                    {
                                        ATransactionSummaryRow transactionSummary;
                                        counter++;
                                        String DictionaryKey = transactionRow.CostCentreCode + ";" + transactionRow.AccountCode;
                                        int signum = transactionRow.DebitCreditIndicator ? 1 : -1;
                                        bool bDontSummarizeAccount = FDontSummarize && FDontSummarizeAccount != null
                                                                     && FDontSummarizeAccount.Length > 0
                                                                     && transactionRow.AccountCode.Equals(FDontSummarizeAccount);

                                        if (bDontSummarizeAccount)
                                        {
                                            DictionaryKey += ";" + counter.ToString("X");
                                        }

                                        if (journalSummary.TransactionSummaries.TryGetValue(DictionaryKey, out transactionSummary))
                                        {
                                            transactionSummary.TransactionAmount += signum * transactionRow.TransactionAmount;
                                            transactionSummary.AmountInBaseCurrency += signum * transactionRow.AmountInBaseCurrency;
                                        }
                                        else
                                        {
                                            transactionSummary = new ATransactionSummaryRow();
                                            transactionSummary.CostCentreCode = transactionRow.CostCentreCode;
                                            transactionSummary.AccountCode = transactionRow.AccountCode;
                                            transactionSummary.TransactionAmount = signum * transactionRow.TransactionAmount;
                                            transactionSummary.AmountInBaseCurrency = signum * transactionRow.AmountInBaseCurrency;

                                            if (bDontSummarizeAccount)
                                            {
                                                transactionSummary.Narrative = transactionRow.Narrative;
                                                transactionSummary.Reference = transactionRow.Reference;
                                            }
                                            else
                                            {
                                                transactionSummary.Narrative = summarizedData;
                                                transactionSummary.Reference = "";
                                            }

                                            journalSummary.TransactionSummaries.Add(DictionaryKey, transactionSummary);
                                        }
                                    }
                                    else
                                    {
                                        WriteTransactionLine(transactionRow);
                                    }
                                }
                            }
                        }
                    }

                    if (FSummary)
                    {
                        TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                            Catalog.GetString("Summarising"),
                            95);

                        //To simplify matters this is always written even if there are no batches
                        if (!FTransactionsOnly)
                        {
                            // no batch summary line if only transactions are to be exported
                            WriteBatchSummaryLine();
                        }

                        foreach (KeyValuePair <string, AJournalSummaryRow>kvp in sdSummary)
                        {
                            if (!FTransactionsOnly)
                            {
                                // no journal summary line if only transactions are to be exported
                                WriteJournalSummaryLine(kvp.Value);
                            }

                            foreach (KeyValuePair <string, ATransactionSummaryRow>kvpt in kvp.Value.TransactionSummaries)
                            {
                                WriteTransactionSummaryLine(kvpt.Value);
                            }
                        }
                    }

                    TProgressTracker.SetCurrentState(DomainManager.GClientID.ToString(),
                        Catalog.GetString("GL batch export successful"),
                        100);

                    TProgressTracker.FinishJob(DomainManager.GClientID.ToString());
                });
            AexportString = FStringWriter.ToString();
            return true;
        } // Export All GLBatch Data
Ejemplo n.º 60
0
        private static void UpdateTotalsOfBatchesAndJournals(ref GLBatchTDS AInspectDS,
            Int32 ALedgerNumber,
            int[] ABatchNumbers,
            bool ABatchTableInDataSet,
            bool AJournalTableInDataSet)
        {
            Int32 currJournalNumber = -1;

            ABatchRow currentBatchRow = null;

            foreach (int currBatchNumber in ABatchNumbers)
            {
                if (!ABatchTableInDataSet && !AJournalTableInDataSet)
                {
                    if (AInspectDS.ATransaction.Count > 0)
                    {
                        AInspectDS.ATransaction.DefaultView.RowFilter = String.Format("{0} = {1}",
                            ATransactionTable.GetBatchNumberDBName(),
                            currBatchNumber);

                        List <int>journalNums = new List <int>();

                        foreach (DataRowView dr in AInspectDS.ATransaction.DefaultView)
                        {
                            ATransactionRow tr = (ATransactionRow)dr.Row;

                            currJournalNumber = tr.JournalNumber;

                            if (!journalNums.Contains(currJournalNumber))
                            {
                                journalNums.Add(currJournalNumber);
                            }
                        }

                        if (journalNums.Count == 1)
                        {
                            AInspectDS.Merge(LoadABatch(ALedgerNumber, currBatchNumber), true);
                            AInspectDS.Merge(LoadAJournalATransaction(ALedgerNumber, currBatchNumber, currJournalNumber), true);
                        }
                        else
                        {
                            //Multiple journals
                            AInspectDS.Merge(LoadABatchAJournalATransaction(ALedgerNumber, currBatchNumber), true);
                        }
                    }
                    else
                    {
                        AInspectDS.Merge(LoadABatchAJournalATransaction(ALedgerNumber, currBatchNumber), true);
                    }
                }
                else if (!ABatchTableInDataSet)
                {
                    AInspectDS.AJournal.DefaultView.RowFilter = String.Format("{0} = {1}",
                        AJournalTable.GetBatchNumberDBName(),
                        currBatchNumber);

                    if (AInspectDS.AJournal.DefaultView.Count == 1)
                    {
                        currJournalNumber = ((AJournalRow)AInspectDS.AJournal.DefaultView[0].Row).JournalNumber;
                        AInspectDS.Merge(LoadABatch(ALedgerNumber, currBatchNumber), true);
                        AInspectDS.Merge(LoadAJournalATransaction(ALedgerNumber, currBatchNumber, currJournalNumber), true);
                    }
                    else
                    {
                        AInspectDS.Merge(LoadABatchAJournalATransaction(ALedgerNumber, currBatchNumber), true);
                    }
                }
                else if (!AJournalTableInDataSet)
                {
                    if (AInspectDS.ATransaction.Count > 0)
                    {
                        AInspectDS.ATransaction.DefaultView.RowFilter = String.Format("{0} = {1}",
                            ATransactionTable.GetBatchNumberDBName(),
                            currBatchNumber);

                        List <int>journalNums = new List <int>();

                        foreach (DataRowView dr in AInspectDS.ATransaction.DefaultView)
                        {
                            ATransactionRow tr = (ATransactionRow)dr.Row;

                            currJournalNumber = tr.JournalNumber;

                            if (!journalNums.Contains(currJournalNumber))
                            {
                                journalNums.Add(currJournalNumber);
                            }
                        }

                        if (journalNums.Count == 1)
                        {
                            AInspectDS.Merge(LoadAJournalATransaction(ALedgerNumber, currBatchNumber, currJournalNumber), true);
                        }
                        else
                        {
                            //Multiple journals
                            AInspectDS.Merge(LoadAJournalATransaction(ALedgerNumber, currBatchNumber), true);
                        }
                    }
                    else
                    {
                        AInspectDS.Merge(LoadAJournalATransaction(ALedgerNumber, currBatchNumber), true);
                    }
                }
                else
                {
                    AInspectDS.AJournal.DefaultView.RowFilter = String.Format("{0} = {1}",
                        AJournalTable.GetBatchNumberDBName(),
                        currBatchNumber);

                    if (AInspectDS.AJournal.DefaultView.Count == 1)
                    {
                        currJournalNumber = ((AJournalRow)AInspectDS.AJournal.DefaultView[0].Row).JournalNumber;
                        AInspectDS.Merge(LoadATransaction(ALedgerNumber, currBatchNumber, currJournalNumber), true);
                    }
                    else
                    {
                        //Multiple journals
                        AInspectDS.Merge(LoadATransactionForBatch(ALedgerNumber, currBatchNumber), true);
                    }
                }

                //Read current batch and update totals
                currentBatchRow = (ABatchRow)AInspectDS.ABatch.Rows.Find(new object[] { ALedgerNumber, currBatchNumber });

                UpdateTotalsOfBatch(ref AInspectDS, currentBatchRow);
            }
        }