Esempio n. 1
0
        /// <summary>
        /// make sure the correct transaction number is assigned and the journal.lastTransactionNumber is updated
        /// </summary>
        /// <param name="ANewRow">returns the modified new transaction row</param>
        /// <param name="ARefTransactionRow">this can be null; otherwise this is the transaction that the Attribute should belong to</param>
        public void NewRowManual(ref ARecurringTransAnalAttribRow ANewRow, ARecurringTransactionRow ARefTransactionRow)
        {
            if (ARefTransactionRow == null)
            {
                ARefTransactionRow = GetTransactionRow();
            }

            ANewRow.LedgerNumber      = ARefTransactionRow.LedgerNumber;
            ANewRow.BatchNumber       = ARefTransactionRow.BatchNumber;
            ANewRow.JournalNumber     = ARefTransactionRow.JournalNumber;
            ANewRow.TransactionNumber = ARefTransactionRow.TransactionNumber;
        }
Esempio n. 2
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.BeginEdit();
                ACurrentJournal.LastTransactionNumber = ActualLastTransNumber;
                ACurrentJournal.EndEdit();
                RowUpdated = true;
            }

            return(RowUpdated);
        }
Esempio n. 3
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 ShowDetailsManual(ARecurringTransactionRow ARow)
        {
            grdDetails.TabStop = (ARow != null);
            grdAnalAttributes.Enabled = (ARow != null);

            if (ARow == null)
            {
                FTransactionNumber = -1;
                ClearControls();
                btnNew.Focus();
                return;
            }

            FTransactionNumber = ARow.TransactionNumber;

            if (ARow.DebitCreditIndicator)
            {
                txtDebitAmount.NumberValueDecimal = ARow.TransactionAmount;
                txtCreditAmount.NumberValueDecimal = 0;
            }
            else
            {
                txtDebitAmount.NumberValueDecimal = 0;
                txtCreditAmount.NumberValueDecimal = ARow.TransactionAmount;
            }

            RefreshAnalysisAttributesGrid();
        }
        private void ValidateDataDetailsManual(ARecurringTransactionRow ARow)
        {
            //Can be called from outside, so need to update fields
            FBatchRow = GetBatchRow();

            if (FBatchRow == null)
            {
                return;
            }

            FJournalRow = GetJournalRow();

            if (FJournalRow != null)
            {
                FJournalNumber = FJournalRow.JournalNumber;
            }

            if ((ARow == null) || (FBatchRow.BatchNumber != ARow.BatchNumber))
            {
                return;
            }

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            Control controlToPass = null;

            //Local validation
            if (((txtDebitAmount.NumberValueDecimal.Value == 0)
                 && (txtCreditAmount.NumberValueDecimal.Value == 0))
                || (txtDebitAmount.NumberValueDecimal.Value < 0))
            {
                controlToPass = txtDebitAmount;
            }
            else if (txtCreditAmount.NumberValueDecimal.Value < 0)
            {
                controlToPass = txtCreditAmount;
            }
            else if (TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_GLREFMANDATORY, "no") == "yes")
            {
                controlToPass = txtDetailReference;
            }
            else if ((VerificationResultCollection.Count == 1)
                     && (VerificationResultCollection[0].ResultCode == CommonErrorCodes.ERR_INVALIDNUMBER))
            {
                //The amount controls register as invalid even when value is correct. Need to reset
                //  Verifications accordingly.
                FPetraUtilsObject.VerificationResultCollection.Clear();
            }

            TSharedFinanceValidation_GL.ValidateRecurringGLDetailManual(this, FBatchRow, ARow, controlToPass, ref VerificationResultCollection,
                FValidationControlsDict);

            if ((FPreviouslySelectedDetailRow != null)
                && !FAnalysisAttributesLogic.AccountRecurringAnalysisAttributeCountIsCorrect(
                    FPreviouslySelectedDetailRow.TransactionNumber,
                    FPreviouslySelectedDetailRow.AccountCode,
                    FMainDS))
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnAccountCodeId];
                ValidationContext = "unused because of OverrideResultText";

                // This code is only running because of failure, so cause an error to occur.
                VerificationResult = TStringChecks.StringMustNotBeEmpty("",
                    ValidationContext.ToString(),
                    this, ValidationColumn, null);
                VerificationResult.OverrideResultText(String.Format(
                        "A value must be entered for 'Analysis Attributes' for Account Code {0} in Transaction {1}.",
                        ARow.AccountCode,
                        ARow.TransactionNumber));
                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }

            String ValueRequiredForType;

            if ((FPreviouslySelectedDetailRow != null)
                && !FAnalysisAttributesLogic.AccountRecurringAnalysisAttributesValuesExist(
                    FPreviouslySelectedDetailRow.TransactionNumber,
                    FPreviouslySelectedDetailRow.AccountCode,
                    FMainDS,
                    out ValueRequiredForType))
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnAccountCodeId];
                ValidationContext = String.Format("Analysis code {0} for Account Code {1} in Transaction {2}",
                    ValueRequiredForType,
                    ARow.AccountCode,
                    ARow.TransactionNumber);

                // This code is only running because of failure, so cause an error to occur.
                VerificationResult = TStringChecks.StringMustNotBeEmpty("",
                    ValidationContext.ToString(),
                    this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
        /// <summary>
        /// Code to be run after the deletion process
        /// </summary>
        /// <param name="ARowToDelete">the row that was/was to be deleted</param>
        /// <param name="AAllowDeletion">whether or not the user was permitted to delete</param>
        /// <param name="ADeletionPerformed">whether or not the deletion was performed successfully</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        private void PostDeleteManual(ARecurringTransactionRow ARowToDelete,
            bool AAllowDeletion,
            bool ADeletionPerformed,
            string ACompletionMessage)
        {
            if (ADeletionPerformed)
            {
                UpdateChangeableStatus();

                if (!pnlDetails.Enabled)
                {
                    ClearControls();
                }

                //Always update LastTransactionNumber first before updating totals
                GLRoutines.UpdateRecurringJournalLastTransaction(ref FMainDS, ref FJournalRow);
                UpdateTransactionTotals();

                if (((TFrmRecurringGLBatch) this.ParentForm).SaveChanges())
                {
                    //message to user
                    MessageBox.Show(ACompletionMessage,
                        Catalog.GetString("Deletion Successful"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(Catalog.GetString("Error attempting to save after deleting a recurring transaction!"),
                        "Deletion Unsuccessful",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Exclamation);
                }
            }
            else if (!AAllowDeletion && (ACompletionMessage.Length > 0))
            {
                //message to user
                MessageBox.Show(ACompletionMessage,
                    "Deletion not allowed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else if (!ADeletionPerformed && (ACompletionMessage.Length > 0))
            {
                //message to user
                MessageBox.Show(ACompletionMessage,
                    "Deletion failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
        private bool PreDeleteManual(ARecurringTransactionRow ARowToDelete, ref string ADeletionQuestion)
        {
            bool allowDeletion = true;

            if (FPreviouslySelectedDetailRow != null)
            {
                ADeletionQuestion = String.Format(Catalog.GetString("Are you sure you want to delete transaction no. {0} from recurring Journal {1}?"),
                    ARowToDelete.TransactionNumber,
                    ARowToDelete.JournalNumber);
            }

            return allowDeletion;
        }
        private void ProcessNewlyAddedJournalRowForDeletion(int AJournalNumberToDelete)
        {
            GLBatchTDS BackupDS = (GLBatchTDS)FMainDS.Copy();

            BackupDS.Merge(FMainDS);

            try
            {
                // Delete the associated recurring transaction analysis attributes
                DataView attributesDV = new DataView(FMainDS.ARecurringTransAnalAttrib);
                attributesDV.RowFilter = string.Format("{0}={1} And {2}={3}",
                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                       FBatchNumber,
                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                       AJournalNumberToDelete
                                                       );

                foreach (DataRowView attrDRV in attributesDV)
                {
                    ARecurringTransAnalAttribRow attrRow = (ARecurringTransAnalAttribRow)attrDRV.Row;
                    attrRow.Delete();
                }

                // Delete the associated recurring transactions
                DataView transactionsDV = new DataView(FMainDS.ARecurringTransaction);
                transactionsDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                         ARecurringTransactionTable.GetBatchNumberDBName(),
                                                         FBatchNumber,
                                                         ARecurringTransactionTable.GetJournalNumberDBName(),
                                                         AJournalNumberToDelete
                                                         );

                foreach (DataRowView transDRV in transactionsDV)
                {
                    ARecurringTransactionRow tranRow = (ARecurringTransactionRow)transDRV.Row;
                    tranRow.Delete();
                }

                // Delete the recurring journal
                DataView journalDV = new DataView(FMainDS.ARecurringJournal);
                journalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                    ARecurringJournalTable.GetBatchNumberDBName(),
                                                    FBatchNumber,
                                                    ARecurringJournalTable.GetJournalNumberDBName(),
                                                    AJournalNumberToDelete
                                                    );

                foreach (DataRowView journalDRV in journalDV)
                {
                    ARecurringJournalRow jrnlRow = (ARecurringJournalRow)journalDRV.Row;
                    jrnlRow.Delete();
                }

                //Renumber the journals, transactions and attributes
                DataView attributesDV2 = new DataView(FMainDS.ARecurringTransAnalAttrib);
                attributesDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                        ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                        FBatchNumber,
                                                        ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                        AJournalNumberToDelete);
                attributesDV2.Sort = String.Format("{0} ASC", ARecurringTransAnalAttribTable.GetJournalNumberDBName());

                foreach (DataRowView attrDRV in attributesDV2)
                {
                    ARecurringTransAnalAttribRow attrRow = (ARecurringTransAnalAttribRow)attrDRV.Row;
                    attrRow.JournalNumber--;
                }

                DataView transactionsDV2 = new DataView(FMainDS.ARecurringTransaction);
                transactionsDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                          ARecurringTransactionTable.GetBatchNumberDBName(),
                                                          FBatchNumber,
                                                          ARecurringTransactionTable.GetJournalNumberDBName(),
                                                          AJournalNumberToDelete);
                transactionsDV2.Sort = String.Format("{0} ASC", ARecurringTransactionTable.GetJournalNumberDBName());

                foreach (DataRowView transDRV in transactionsDV2)
                {
                    ARecurringTransactionRow tranRow = (ARecurringTransactionRow)transDRV.Row;
                    tranRow.JournalNumber--;
                }

                DataView journalDV2 = new DataView(FMainDS.ARecurringJournal);
                journalDV2.RowFilter = string.Format("{0}={1} And {2}>{3}",
                                                     ARecurringJournalTable.GetBatchNumberDBName(),
                                                     FBatchNumber,
                                                     ARecurringJournalTable.GetJournalNumberDBName(),
                                                     AJournalNumberToDelete);
                journalDV2.Sort = String.Format("{0} ASC", ARecurringJournalTable.GetJournalNumberDBName());

                foreach (DataRowView jrnlDRV in journalDV2)
                {
                    ARecurringJournalRow jrnlRow = (ARecurringJournalRow)jrnlDRV.Row;
                    jrnlRow.JournalNumber--;
                }
            }
            catch (Exception ex)
            {
                FMainDS.Merge(BackupDS);

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
        }
        private void ValidateDataDetailsManual(ARecurringTransactionRow ARow)
        {
            if ((ARow == null) || (GetRecurringBatchRow() == null))
            {
                return;
            }

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            Control controlToPass = null;

            //Local validation
            if (((txtDebitAmount.NumberValueDecimal.Value == 0)
                 && (txtCreditAmount.NumberValueDecimal.Value == 0))
                || (txtDebitAmount.NumberValueDecimal.Value < 0))
            {
                controlToPass = txtDebitAmount;
            }
            else if (txtCreditAmount.NumberValueDecimal.Value < 0)
            {
                controlToPass = txtCreditAmount;
            }
            else if (TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_GLREFMANDATORY, "no") == "yes")
            {
                controlToPass = txtDetailReference;
            }

            if ((controlToPass == null) || (controlToPass == txtDetailReference))
            {
                //This is needed because the above runs many times during setting up the form
                VerificationResultCollection.Clear();
            }

            TSharedFinanceValidation_GL.ValidateRecurringGLDetailManual(this, FBatchRow, ARow, controlToPass, ref VerificationResultCollection,
                FValidationControlsDict);

            if ((FPreviouslySelectedDetailRow != null)
                && !FAnalysisAttributesLogic.AccountRecurringAnalysisAttributeCountIsCorrect(
                    FPreviouslySelectedDetailRow.TransactionNumber,
                    FPreviouslySelectedDetailRow.AccountCode,
                    FMainDS))
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnAccountCodeId];
                ValidationContext = "unused because of OverrideResultText";

                // This code is only running because of failure, so cause an error to occur.
                VerificationResult = TStringChecks.StringMustNotBeEmpty("",
                    ValidationContext.ToString(),
                    this, ValidationColumn, null);
                VerificationResult.OverrideResultText(String.Format(
                        "A value must be entered for 'Analysis Attributes' for Account Code {0} in Transaction {1}.{2}{2}" +
                        "CLICK THE DOWN ARROW NEXT TO THE ACCOUNT CODE BOX TO OPEN THE LIST AND THEN RESELECT ACCOUNT CODE {0}",
                        ARow.AccountCode,
                        ARow.TransactionNumber,
                        Environment.NewLine));
                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }

            String ValueRequiredForType;

            if ((FPreviouslySelectedDetailRow != null)
                && !FAnalysisAttributesLogic.AccountRecurringAnalysisAttributesValuesExist(
                    FPreviouslySelectedDetailRow.TransactionNumber,
                    FPreviouslySelectedDetailRow.AccountCode,
                    FMainDS,
                    out ValueRequiredForType))
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnAccountCodeId];
                ValidationContext = String.Format("Analysis code {0} for Account Code {1} in Transaction {2}",
                    ValueRequiredForType,
                    ARow.AccountCode,
                    ARow.TransactionNumber);

                // This code is only running because of failure, so cause an error to occur.
                VerificationResult = TStringChecks.StringMustNotBeEmpty("",
                    ValidationContext.ToString(),
                    this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
        /// <summary>
        /// Deletes the current row and optionally populates a completion message
        /// </summary>
        /// <param name="ARowToDelete">the currently selected row to delete</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        /// <returns>true if row deletion is successful</returns>
        private bool DeleteRowManual(ARecurringTransactionRow ARowToDelete, ref string ACompletionMessage)
        {
            //Assign a default values
            bool deletionSuccessful = false;

            ACompletionMessage = string.Empty;

            if (ARowToDelete == null)
            {
                return deletionSuccessful;
            }

            bool newRecord = (ARowToDelete.RowState == DataRowState.Added);

            if (!newRecord && !((TFrmRecurringGLBatch) this.ParentForm).SaveChanges())
            {
                MessageBox.Show("Error in trying to save prior to deleting current recurring transaction!");
                return deletionSuccessful;
            }

            //Backup the Dataset for reversion purposes
            GLBatchTDS FTempDS = (GLBatchTDS)FMainDS.Copy();
            FTempDS.Merge(FMainDS);

            int transactionNumberToDelete = ARowToDelete.TransactionNumber;
            int lastTransactionNumber = FJournalRow.LastTransactionNumber;

            FMainDS.EnforceConstraints = false;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                // Delete on client side data through views that is already loaded. Data that is not
                // loaded yet will be deleted with cascading delete on server side so we don't have
                // to worry about this here.

                FAnalysisAttributesLogic.SetRecurringTransAnalAttributeDefaultView(FMainDS, transactionNumberToDelete);
                DataView attrView = FMainDS.ARecurringTransAnalAttrib.DefaultView;

                if (attrView.Count > 0)
                {
                    //Iterate through attributes and delete
                    ARecurringTransAnalAttribRow attrRowCurrent = null;

                    foreach (DataRowView gv in attrView)
                    {
                        attrRowCurrent = (ARecurringTransAnalAttribRow)gv.Row;
                        attrRowCurrent.Delete();
                    }
                }

                //Reduce those with higher transaction number by one
                attrView.RowFilter = String.Format("{0} = {1} AND {2} = {3} AND {4} > {5}",
                    ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                    FBatchNumber,
                    ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                    FJournalNumber,
                    ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                    transactionNumberToDelete);

                // Delete the associated transaction analysis attributes
                //  if attributes do exist, and renumber those above
                if (attrView.Count > 0)
                {
                    //Iterate through higher number attributes and transaction numbers and reduce by one
                    ARecurringTransAnalAttribRow attrRowCurrent = null;

                    foreach (DataRowView gv in attrView)
                    {
                        attrRowCurrent = (ARecurringTransAnalAttribRow)gv.Row;
                        attrRowCurrent.TransactionNumber--;
                    }
                }

                //Bubble the transaction to delete to the top
                DataView transView = new DataView(FMainDS.ARecurringTransaction);
                transView.RowFilter = String.Format("{0}={1} And {2}={3}",
                    ARecurringTransactionTable.GetBatchNumberDBName(),
                    FBatchNumber,
                    ARecurringTransactionTable.GetJournalNumberDBName(),
                    FJournalNumber);

                transView.Sort = String.Format("{0} ASC",
                    ARecurringTransactionTable.GetTransactionNumberDBName());

                ARecurringTransactionRow transRowToReceive = null;
                ARecurringTransactionRow transRowToCopyDown = null;
                ARecurringTransactionRow transRowCurrent = null;

                int currentTransNo = 0;

                foreach (DataRowView gv in transView)
                {
                    transRowCurrent = (ARecurringTransactionRow)gv.Row;

                    currentTransNo = transRowCurrent.TransactionNumber;

                    if (currentTransNo > transactionNumberToDelete)
                    {
                        transRowToCopyDown = transRowCurrent;

                        //Copy column values down
                        for (int j = 4; j < transRowToCopyDown.Table.Columns.Count; j++)
                        {
                            //Update all columns except the pk fields that remain the same
                            if (!transRowToCopyDown.Table.Columns[j].ColumnName.EndsWith("_text"))
                            {
                                // Don't include the columns that the filter uses for numeric textual comparison
                                transRowToReceive[j] = transRowToCopyDown[j];
                            }
                        }
                    }

                    if (currentTransNo == transView.Count)                         //Last row which is the row to be deleted
                    {
                        //Mark last record for deletion
                        transRowCurrent.SubType = MFinanceConstants.MARKED_FOR_DELETION;
                    }

                    //transRowToReceive will become previous row for next recursion
                    transRowToReceive = transRowCurrent;
                }

                if (newRecord && (transRowCurrent.SubType == MFinanceConstants.MARKED_FOR_DELETION))
                {
                    transRowCurrent.Delete();
                }

                FPreviouslySelectedDetailRow = null;

                FPetraUtilsObject.SetChangedFlag();

                //Try to save changes
                if (!((TFrmRecurringGLBatch) this.ParentForm).SaveChanges())
                {
                    throw new Exception("Unable to save after deleting a recurring transaction!");
                }

                ACompletionMessage = String.Format(Catalog.GetString("Recurring transaction no.: {0} deleted successfully."),
                    transactionNumberToDelete);

                deletionSuccessful = true;
            }
            catch (Exception ex)
            {
                ACompletionMessage = ex.Message;
                MessageBox.Show(ex.Message,
                    "Deletion Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                //Revert to previous state
                FMainDS.Merge(FTempDS);
            }
            finally
            {
                FMainDS.EnforceConstraints = true;
                SetTransactionDefaultView();
                FFilterAndFindObject.ApplyFilter();
                this.Cursor = Cursors.Default;
            }

            return deletionSuccessful;
        }
        /// <summary>
        /// Code to be run after the deletion process
        /// </summary>
        /// <param name="ARowToDelete">the row that was/was to be deleted</param>
        /// <param name="AAllowDeletion">whether or not the user was permitted to delete</param>
        /// <param name="ADeletionPerformed">whether or not the deletion was performed successfully</param>
        /// <param name="ACompletionMessage">if specified, is the deletion completion message</param>
        private void PostDeleteManual(ARecurringTransactionRow ARowToDelete,
            bool AAllowDeletion,
            bool ADeletionPerformed,
            string ACompletionMessage)
        {
            if (ADeletionPerformed)
            {
                SetJournalLastTransNumber();

                UpdateChangeableStatus();

                if (!pnlDetails.Enabled)
                {
                    ClearControls();
                }

                UpdateTransactionTotals();

                ((TFrmRecurringGLBatch) this.ParentForm).SaveChanges();

                //message to user
                MessageBox.Show(ACompletionMessage,
                    "Deletion Successful",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            else if (!AAllowDeletion && (ACompletionMessage.Length > 0))
            {
                //message to user
                MessageBox.Show(ACompletionMessage,
                    "Deletion not allowed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else if (!ADeletionPerformed && (ACompletionMessage.Length > 0))
            {
                //message to user
                MessageBox.Show(ACompletionMessage,
                    "Deletion failed",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Validates the recurring GL Detail data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ABatchRow">Manually added to bring over some GL Batch fields</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AControl"></param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        /// <returns>True if the validation found no data validation errors, otherwise false.</returns>
        public static bool ValidateRecurringGLDetailManual(object AContext,
            ARecurringBatchRow ABatchRow,
            ARecurringTransactionRow ARow,
            Control AControl,
            ref TVerificationResultCollection AVerificationResultCollection,
            TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;
            object ValidationContext;
            int VerifResultCollAddedCount = 0;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return true;
            }

            //TransactionAmount is not in the dictionary so had to pass the control directly
            //  also needed to handle reference
            if ((AControl != null) && AControl.Name.EndsWith("Amount"))
            {
                // 'GL amount must be non-zero
                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnTransactionAmountId];
                ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                    ARow.TransactionNumber,
                    ARow.BatchNumber,
                    ARow.JournalNumber);

                VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.TransactionAmount,
                    "Amount of " + ValidationContext,
                    AContext, ValidationColumn, AControl);

                if (VerificationResult != null)
                {
                    VerificationResult.SuppressValidationToolTip = true;
                }

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                {
                    VerifResultCollAddedCount++;
                }

                return VerifResultCollAddedCount == 0;
            }

            // Narrative must not be empty
            ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnNarrativeId];
            ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                ARow.TransactionNumber,
                ARow.BatchNumber,
                ARow.JournalNumber);

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Narrative,
                    "Narrative of " + ValidationContext,
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                {
                    VerifResultCollAddedCount++;
                }
            }

            if ((AControl != null) && AControl.Name.EndsWith("Reference"))
            {
                ValidationColumn = ARow.Table.Columns[ARecurringTransactionTable.ColumnReferenceId];
                ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                    ARow.TransactionNumber,
                    ARow.BatchNumber,
                    ARow.JournalNumber);

                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Reference,
                        "Reference of " + ValidationContext,
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn, true))
                    {
                        VerifResultCollAddedCount++;
                    }
                }
            }

            return VerifResultCollAddedCount == 0;
        }
        /// <summary>
        /// make sure the correct transaction number is assigned and the journal.lastTransactionNumber is updated
        /// </summary>
        /// <param name="ANewRow">returns the modified new transaction row</param>
        /// <param name="ARefTransactionRow">this can be null; otherwise this is the transaction that the Attribute should belong to</param>
        public void NewRowManual(ref ARecurringTransAnalAttribRow ANewRow, ARecurringTransactionRow ARefTransactionRow)
        {
            if (ARefTransactionRow == null)
            {
                ARefTransactionRow = GetTransactionRow();
            }

            ANewRow.LedgerNumber = ARefTransactionRow.LedgerNumber;
            ANewRow.BatchNumber = ARefTransactionRow.BatchNumber;
            ANewRow.JournalNumber = ARefTransactionRow.JournalNumber;
            ANewRow.TransactionNumber = ARefTransactionRow.TransactionNumber;
        }
        private void GetDetailDataFromControlsManual(ARecurringTransactionRow ARow)
        {
            if (ARow == null)
            {
                return;
            }

            Decimal OldTransactionAmount = ARow.TransactionAmount;
            bool OldDebitCreditIndicator = ARow.DebitCreditIndicator;

            GetDataForAmountFields(ARow);

            if ((OldTransactionAmount != Convert.ToDecimal(ARow.TransactionAmount))
                || (OldDebitCreditIndicator != ARow.DebitCreditIndicator))
            {
                UpdateTransactionTotals();
            }

            // If combobox to set analysis attribute value has focus when save button is pressed then currently
            // displayed value is not stored in database.
            // --> move focus to different field so that grid accepts value for storing in database
            if (FcmbAnalAttribValues.Control.Focused)
            {
                cmbDetailCostCentreCode.Focus();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Validates the recurring GL Detail data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ABatchRow">Manually added to bring over some GL Batch fields</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <returns>True if the validation found no data validation errors, otherwise false.</returns>
        public static bool ValidateRecurringGLDetailManual(object AContext,
                                                           ARecurringBatchRow ABatchRow,
                                                           ARecurringTransactionRow ARow,
                                                           ref TVerificationResultCollection AVerificationResultCollection)
        {
            DataColumn          ValidationColumn;
            TVerificationResult VerificationResult = null;
            object ValidationContext;
            int    VerifResultCollAddedCount = 0;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return(true);
            }

            //TransactionAmount is not in the dictionary so had to pass the control directly
            //  also needed to handle reference
            if (true)
            {
                // 'GL amount must be non-zero
                ValidationColumn  = ARow.Table.Columns[ARecurringTransactionTable.ColumnTransactionAmountId];
                ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                                                  ARow.TransactionNumber,
                                                  ARow.BatchNumber,
                                                  ARow.JournalNumber);

                VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.TransactionAmount,
                                                                        "Amount of " + ValidationContext,
                                                                        AContext, ValidationColumn);

                if (VerificationResult != null)
                {
                    VerificationResult.SuppressValidationToolTip = true;
                }

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult))
                {
                    VerifResultCollAddedCount++;
                }

                return(VerifResultCollAddedCount == 0);
            }

            // Narrative must not be empty
            ValidationColumn  = ARow.Table.Columns[ARecurringTransactionTable.ColumnNarrativeId];
            ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                                              ARow.TransactionNumber,
                                              ARow.BatchNumber,
                                              ARow.JournalNumber);

            if (true)
            {
                VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Narrative,
                                                                        "Narrative of " + ValidationContext,
                                                                        AContext, ValidationColumn);

                // Handle addition/removal to/from TVerificationResultCollection
                if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult))
                {
                    VerifResultCollAddedCount++;
                }
            }

            if (true)
            {
                ValidationColumn  = ARow.Table.Columns[ARecurringTransactionTable.ColumnReferenceId];
                ValidationContext = String.Format("Transaction number {0} (batch:{1} journal:{2})",
                                                  ARow.TransactionNumber,
                                                  ARow.BatchNumber,
                                                  ARow.JournalNumber);

                if (true)
                {
                    VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.Reference,
                                                                            "Reference of " + ValidationContext,
                                                                            AContext, ValidationColumn);

                    // Handle addition/removal to/from TVerificationResultCollection
                    if (AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult))
                    {
                        VerifResultCollAddedCount++;
                    }
                }
            }

            return(VerifResultCollAddedCount == 0);
        }
        private void GetDataForAmountFields(ARecurringTransactionRow ARow)
        {
            if (ARow == null)
            {
                return;
            }

            bool DebitCreditIndicator;
            decimal TransactionAmount;

            if ((txtDebitAmount.Text.Length == 0) && (txtDebitAmount.NumberValueDecimal.Value != 0))
            {
                txtDebitAmount.NumberValueDecimal = 0;
            }

            if ((txtCreditAmount.Text.Length == 0) && (txtCreditAmount.NumberValueDecimal.Value != 0))
            {
                txtCreditAmount.NumberValueDecimal = 0;
            }

            DebitCreditIndicator = (txtDebitAmount.NumberValueDecimal.Value > 0);

            if (ARow.DebitCreditIndicator != DebitCreditIndicator)
            {
                ARow.DebitCreditIndicator = DebitCreditIndicator;
            }

            if (ARow.DebitCreditIndicator)
            {
                TransactionAmount = Math.Abs(txtDebitAmount.NumberValueDecimal.Value);

                if (txtCreditAmount.NumberValueDecimal.Value != 0)
                {
                    txtCreditAmount.NumberValueDecimal = 0;
                }
            }
            else
            {
                TransactionAmount = Math.Abs(txtCreditAmount.NumberValueDecimal.Value);
            }

            if (ARow.TransactionAmount != TransactionAmount)
            {
                ARow.TransactionAmount = TransactionAmount;
            }
        }
Esempio n. 17
0
        private static bool UpdateRecurringJournalTotals(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 AmountsUpdated = false;

            decimal JournalDebitTotal      = 0.0M;
            decimal JournalDebitTotalBase  = 0.0M;
            decimal JournalCreditTotal     = 0.0M;
            decimal JournalCreditTotalBase = 0.0M;

            if (ACurrentJournal.IsJournalDebitTotalBaseNull()) //DBNull.Value.Equals(ACurrentJournal[GLBatchTDSARecurringJournalTable.ColumnJournalDebitTotalBaseId])
            {
                ACurrentJournal.JournalDebitTotalBase = 0;
                AmountsUpdated = true;
            }

            if (ACurrentJournal.IsJournalCreditTotalBaseNull()) //DBNull.Value.Equals(ACurrentJournal[GLBatchTDSARecurringJournalTable.ColumnJournalCreditTotalBaseId])
            {
                ACurrentJournal.JournalCreditTotalBase = 0;
                AmountsUpdated = true;
            }

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

            if ((TransDV.Count == 0) && (ACurrentJournal.LastTransactionNumber > 0))
            {
                //do not update totals as no transactions loaded as yet so no need to update journal total
                return(AmountsUpdated);
            }

            // transactions are filtered for this journal; add up the total amounts
            foreach (DataRowView drv in TransDV)
            {
                ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                if (transRow.DebitCreditIndicator)
                {
                    JournalDebitTotal     += transRow.TransactionAmount;
                    JournalDebitTotalBase += transRow.AmountInBaseCurrency;
                }
                else
                {
                    JournalCreditTotal     += transRow.TransactionAmount;
                    JournalCreditTotalBase += transRow.AmountInBaseCurrency;
                }
            }

            if ((ACurrentJournal.JournalDebitTotal != JournalDebitTotal) ||
                (ACurrentJournal.JournalDebitTotalBase != JournalDebitTotalBase) ||
                (ACurrentJournal.JournalCreditTotal != JournalCreditTotal) ||
                (ACurrentJournal.JournalCreditTotalBase != JournalCreditTotalBase))
            {
                ACurrentJournal.JournalDebitTotal      = JournalDebitTotal;
                ACurrentJournal.JournalDebitTotalBase  = JournalDebitTotalBase;
                ACurrentJournal.JournalCreditTotal     = JournalCreditTotal;
                ACurrentJournal.JournalCreditTotalBase = JournalCreditTotalBase;
                AmountsUpdated = true;
            }

            return(AmountsUpdated);
        }
        /// <summary>
        /// Undo all changes to the specified batch ready to cancel it.
        ///  This avoids unecessary validation errors when cancelling.
        /// </summary>
        /// <param name="ACurrentBatch"></param>
        /// <param name="AJournalToDelete"></param>
        /// <param name="ARedisplay"></param>
        public void PrepareJournalDataForDeleting(Int32 ACurrentBatch, Int32 AJournalToDelete, Boolean ARedisplay)
        {
            //This code will only be called when the Batch tab is active.

            DataView JournalDV   = new DataView(FMainDS.ARecurringJournal);
            DataView TransDV     = new DataView(FMainDS.ARecurringTransaction);
            DataView TransAnalDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            JournalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                ARecurringJournalTable.GetBatchNumberDBName(),
                                                ACurrentBatch,
                                                ARecurringJournalTable.GetJournalNumberDBName(),
                                                AJournalToDelete);

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

            TransAnalDV.RowFilter = String.Format("{0}={1} And {2}={3}",
                                                  ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                  ACurrentBatch,
                                                  ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                  AJournalToDelete);

            //Work from lowest level up
            if (TransAnalDV.Count > 0)
            {
                TransAnalDV.Sort = String.Format("{0}, {1}, {2}",
                                                 ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                 ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                 ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                foreach (DataRowView drv in TransAnalDV)
                {
                    ARecurringTransAnalAttribRow transAnalRow = (ARecurringTransAnalAttribRow)drv.Row;

                    if (transAnalRow.RowState == DataRowState.Added)
                    {
                        //Do nothing
                    }
                    else if (transAnalRow.RowState != DataRowState.Unchanged)
                    {
                        transAnalRow.RejectChanges();
                    }
                }
            }

            if (TransDV.Count > 0)
            {
                TransDV.Sort = String.Format("{0}, {1}",
                                             ARecurringTransactionTable.GetJournalNumberDBName(),
                                             ARecurringTransactionTable.GetTransactionNumberDBName());

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

                    if (transRow.RowState == DataRowState.Added)
                    {
                        //Do nothing
                    }
                    else if (transRow.RowState != DataRowState.Unchanged)
                    {
                        transRow.RejectChanges();
                    }
                }
            }

            if (JournalDV.Count > 0)
            {
                GLBatchTDSARecurringJournalRow journalRow = (GLBatchTDSARecurringJournalRow)JournalDV[0].Row;

                //No need to check for Added state as new batches are always saved
                // on creation

                if (journalRow.RowState != DataRowState.Unchanged)
                {
                    journalRow.RejectChanges();
                }

                if (ARedisplay)
                {
                    ShowDetails(journalRow);
                }
            }

            if (TransDV.Count == 0)
            {
                //Load all related data for batch ready to delete/cancel
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringTransactionAndRelatedTablesForJournal(FLedgerNumber, ACurrentBatch,
                                                                                                                    AJournalToDelete));
            }
        }
Esempio n. 19
0
        private bool AllowInactiveFieldValues()
        {
            bool RetVal = false;

            DataView TransDV  = new DataView(FMainDS.ARecurringTransaction);
            DataView AttribDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            try
            {
                TransDV.RowFilter = String.Format("{0}={1}",
                                                  ARecurringTransactionTable.GetBatchNumberDBName(),
                                                  FSelectedBatchNumber);
                AttribDV.RowFilter = String.Format("{0}={1}",
                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                   FSelectedBatchNumber);

                //Check for inactive data field values
                foreach (DataRowView drv in TransDV)
                {
                    ARecurringTransactionRow transRow = (ARecurringTransactionRow)drv.Row;

                    if (!AccountIsActive(transRow.AccountCode) || !CostCentreIsActive(transRow.CostCentreCode))
                    {
                        if (MessageBox.Show(String.Format(Catalog.GetString(
                                                              "Recurring batch no. {0} contains an inactive account or cost centre code in journal {1}, transaction {2}. Do you still want to submit the batch?"),
                                                          FSelectedBatchNumber,
                                                          transRow.JournalNumber,
                                                          transRow.TransactionNumber),
                                            Catalog.GetString("Inactive Account/Cost Centre Code"), MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return(RetVal);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                foreach (DataRowView drv2 in AttribDV)
                {
                    ARecurringTransAnalAttribRow analAttribRow = (ARecurringTransAnalAttribRow)drv2.Row;

                    if (!AnalysisCodeIsActive(analAttribRow.AccountCode,
                                              analAttribRow.AnalysisTypeCode) ||
                        !AnalysisAttributeValueIsActive(analAttribRow.AnalysisTypeCode, analAttribRow.AnalysisAttributeValue))
                    {
                        if (MessageBox.Show(String.Format(Catalog.GetString(
                                                              "Recurring batch no. {0} contains an inactive analysis attribute code/value in journal {1}, transaction {2}. Do you still want to submit the batch?"),
                                                          FSelectedBatchNumber,
                                                          analAttribRow.JournalNumber,
                                                          analAttribRow.TransactionNumber),
                                            Catalog.GetString("Inactive Analysis Attribute Code/Value"), MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Warning) == DialogResult.No)
                        {
                            return(RetVal);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                RetVal = true;
            }
            catch (Exception)
            {
                throw;
            }

            return(RetVal);
        }
        private void RenumberJournals()
        {
            bool JournalsRenumbered = false;

            DataView JrnlView  = new DataView(FMainDS.ARecurringJournal);
            DataView TransView = new DataView(FMainDS.ARecurringTransaction);
            DataView AttrView  = new DataView(FMainDS.ARecurringTransAnalAttrib);

            //Reduce all trans and journal data by 1 in JournalNumber field
            //Reduce those with higher transaction number by one
            JrnlView.RowFilter = String.Format("{0}={1} AND {2}>{3}",
                                               ARecurringJournalTable.GetBatchNumberDBName(),
                                               FBatchNumber,
                                               ARecurringJournalTable.GetJournalNumberDBName(),
                                               FJournalNumberToDelete);

            JrnlView.Sort = String.Format("{0} ASC",
                                          ARecurringJournalTable.GetJournalNumberDBName());

            JournalsRenumbered = (JrnlView.Count > 0);

            // Delete the associated transaction analysis attributes
            //  if attributes do exist, and renumber those above
            foreach (DataRowView jV in JrnlView)
            {
                GLBatchTDSARecurringJournalRow jrnlRowCurrent = (GLBatchTDSARecurringJournalRow)jV.Row;

                int currentJnrlNumber = jrnlRowCurrent.JournalNumber;

                //Copy current row down to fill gap and then delete it
                GLBatchTDSARecurringJournalRow newJrnlRow = FMainDS.ARecurringJournal.NewRowTyped(true);

                newJrnlRow.ItemArray = jrnlRowCurrent.ItemArray;

                //reduce journal number by 1 in the new row
                newJrnlRow.JournalNumber--;

                FMainDS.ARecurringJournal.Rows.Add(newJrnlRow);

                //Process Transactions
                TransView.RowFilter = String.Format("{0}={1} AND {2}={3}",
                                                    ARecurringTransactionTable.GetBatchNumberDBName(),
                                                    FBatchNumber,
                                                    ARecurringTransactionTable.GetJournalNumberDBName(),
                                                    currentJnrlNumber);

                TransView.Sort = String.Format("{0} ASC, {1} ASC",
                                               ARecurringTransactionTable.GetJournalNumberDBName(),
                                               ARecurringTransactionTable.GetTransactionNumberDBName());

                //Iterate through higher number attributes and transaction numbers and reduce by one
                ARecurringTransactionRow transRowCurrent = null;

                foreach (DataRowView gv in TransView)
                {
                    transRowCurrent = (ARecurringTransactionRow)gv.Row;

                    GLBatchTDSARecurringTransactionRow newTransRow = FMainDS.ARecurringTransaction.NewRowTyped(true);

                    newTransRow.ItemArray = transRowCurrent.ItemArray;

                    //reduce journal number by 1 in the new row
                    newTransRow.JournalNumber--;

                    FMainDS.ARecurringTransaction.Rows.Add(newTransRow);

                    //Repeat process for attributes that belong to current transaction
                    AttrView.RowFilter = String.Format("{0}={1} And {2}={3} And {4}={5}",
                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                       FBatchNumber,
                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                       currentJnrlNumber,
                                                       ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                       transRowCurrent.TransactionNumber);

                    AttrView.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC",
                                                  ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                  ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                                  ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                    // Delete the associated transaction analysis attributes
                    //  if attributes do exist, and renumber those above
                    if (AttrView.Count > 0)
                    {
                        //Iterate through higher number attributes and transaction numbers and reduce by one
                        ARecurringTransAnalAttribRow attrRowCurrent = null;

                        foreach (DataRowView rV in AttrView)
                        {
                            attrRowCurrent = (ARecurringTransAnalAttribRow)rV.Row;

                            ARecurringTransAnalAttribRow newAttrRow = FMainDS.ARecurringTransAnalAttrib.NewRowTyped(true);

                            newAttrRow.ItemArray = attrRowCurrent.ItemArray;

                            //reduce journal number by 1
                            newAttrRow.JournalNumber--;

                            FMainDS.ARecurringTransAnalAttrib.Rows.Add(newAttrRow);

                            attrRowCurrent.Delete();
                        }
                    }

                    transRowCurrent.Delete();
                }

                jrnlRowCurrent.Delete();
            }

            if (JournalsRenumbered)
            {
                FPetraUtilsObject.SetChangedFlag();
            }

            //Need to refresh FPreviouslySelectedDetailRow else it points to a deleted row
            SelectRowInGrid(grdDetails.GetFirstHighlightedRowIndex());
        }
Esempio n. 21
0
        private bool AllowInactiveFieldValues(int ABatchNumber)
        {
            bool RetVal = false;

            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();
            string VerificationMessage = string.Empty;

            DataView TransDV  = new DataView(FMainDS.ARecurringTransaction);
            DataView AttribDV = new DataView(FMainDS.ARecurringTransAnalAttrib);

            int TotalNumInactiveValues   = 0;
            int NumInactiveAccounts      = 0;
            int NumInactiveCostCentres   = 0;
            int NumInactiveAccountTypes  = 0;
            int NumInactiveAccountValues = 0;

            try
            {
                //Check for inactive account or cost centre codes
                TransDV.RowFilter = String.Format("{0}={1}",
                                                  ARecurringTransactionTable.GetBatchNumberDBName(),
                                                  ABatchNumber);
                TransDV.Sort = String.Format("{0} ASC, {1} ASC",
                                             ARecurringTransactionTable.GetJournalNumberDBName(),
                                             ARecurringTransactionTable.GetTransactionNumberDBName());

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

                    if (!AccountIsActive(transRow.AccountCode))
                    {
                        VerificationMessage += String.Format(" Account '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             transRow.AccountCode,
                                                             transRow.JournalNumber,
                                                             transRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccounts++;
                    }

                    if (!CostCentreIsActive(transRow.CostCentreCode))
                    {
                        VerificationMessage += String.Format(" Cost Centre '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             transRow.CostCentreCode,
                                                             transRow.JournalNumber,
                                                             transRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveCostCentres++;
                    }
                }

                //Check anlysis attributes
                AttribDV.RowFilter = String.Format("{0}={1}",
                                                   ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                   ABatchNumber);
                AttribDV.Sort = String.Format("{0} ASC, {1} ASC, {2} ASC",
                                              ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                              ARecurringTransAnalAttribTable.GetTransactionNumberDBName(),
                                              ARecurringTransAnalAttribTable.GetAnalysisTypeCodeDBName());

                foreach (DataRowView drv2 in AttribDV)
                {
                    ARecurringTransAnalAttribRow analAttribRow = (ARecurringTransAnalAttribRow)drv2.Row;

                    if (!AnalysisCodeIsActive(analAttribRow.AccountCode, analAttribRow.AnalysisTypeCode))
                    {
                        VerificationMessage += String.Format(" Analysis Code '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             analAttribRow.AnalysisTypeCode,
                                                             analAttribRow.JournalNumber,
                                                             analAttribRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccountTypes++;
                    }

                    if (!AnalysisAttributeValueIsActive(analAttribRow.AnalysisTypeCode, analAttribRow.AnalysisAttributeValue))
                    {
                        VerificationMessage += String.Format(" Analysis Value '{0}' in Journal:{1} Transaction:{2}.{3}",
                                                             analAttribRow.AnalysisAttributeValue,
                                                             analAttribRow.JournalNumber,
                                                             analAttribRow.TransactionNumber,
                                                             Environment.NewLine);

                        NumInactiveAccountValues++;
                    }
                }
            }
            catch (Exception ex)
            {
                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }

            TotalNumInactiveValues = (NumInactiveAccounts + NumInactiveCostCentres + NumInactiveAccountTypes + NumInactiveAccountValues);

            if (TotalNumInactiveValues > 0)
            {
                VerificationResult.Add(new TVerificationResult(string.Format(Catalog.GetString("Inactive Values:{0}"), Environment.NewLine),
                                                               VerificationMessage,
                                                               TResultSeverity.Resv_Noncritical));

                StringBuilder errorMessages = new StringBuilder();

                errorMessages.AppendFormat(Catalog.GetString("{0} inactive value(s) found in Recurring GL Batch {1}. Do you still want to submit?{2}"),
                                           TotalNumInactiveValues,
                                           ABatchNumber,
                                           Environment.NewLine);

                foreach (TVerificationResult message in VerificationResult)
                {
                    errorMessages.AppendFormat("{0}{1}",
                                               Environment.NewLine,
                                               message.ResultText);
                }

                TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FPetraUtilsObject.GetForm());

                RetVal = (extendedMessageBox.ShowDialog(errorMessages.ToString(),
                                                        Catalog.GetString("Submit Batch"), string.Empty,
                                                        TFrmExtendedMessageBox.TButtons.embbYesNo,
                                                        TFrmExtendedMessageBox.TIcon.embiQuestion) == TFrmExtendedMessageBox.TResult.embrYes);
            }
            else
            {
                RetVal = true;
            }

            return(RetVal);
        }