Beispiel #1
0
        private void CurrencyCodeChanged(object sender, EventArgs e)
        {
            if (FPreviouslySelectedDetailRow == null)
            {
                return;
            }

            FCurrencyCodeForJournals = cmbDetailTransactionCurrency.GetSelectedString();

            DataView CurrentJournalsDV = new DataView(FMainDS.ARecurringJournal);

            CurrentJournalsDV.RowFilter = string.Format("{0}={1}",
                                                        ARecurringJournalTable.GetBatchNumberDBName(),
                                                        FBatchNumber);

            if (CurrentJournalsDV.Count > 1)
            {
                foreach (DataRowView drv in CurrentJournalsDV)
                {
                    ARecurringJournalRow rjr = (ARecurringJournalRow)drv.Row;

                    rjr.TransactionCurrency = FCurrencyCodeForJournals;
                }
            }
        }
        /// <summary>
        /// update the journal header fields from a batch
        /// </summary>
        /// <param name="ABatchRowToUpdate"></param>
        public void UpdateHeaderTotals(ARecurringBatchRow ABatchRowToUpdate)
        {
            decimal SumDebits  = 0.0M;
            decimal SumCredits = 0.0M;

            DataView JournalDV = new DataView(FMainDS.ARecurringJournal);

            JournalDV.RowFilter = String.Format("{0}={1}",
                                                ARecurringJournalTable.GetBatchNumberDBName(),
                                                ABatchRowToUpdate.BatchNumber);
            JournalDV.RowStateFilter = DataViewRowState.CurrentRows;

            foreach (DataRowView v in JournalDV)
            {
                ARecurringJournalRow r = (ARecurringJournalRow)v.Row;

                SumCredits += r.JournalCreditTotal;
                SumDebits  += r.JournalDebitTotal;
            }

            FPetraUtilsObject.DisableDataChangedEvent();

            txtDebit.NumberValueDecimal   = SumDebits;
            txtCredit.NumberValueDecimal  = SumCredits;
            txtControl.NumberValueDecimal = ABatchRowToUpdate.BatchControlTotal;

            FPetraUtilsObject.EnableDataChangedEvent();
        }
Beispiel #3
0
        /// <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(ARecurringJournalRow ARowToDelete,
                                      bool AAllowDeletion,
                                      bool ADeletionPerformed,
                                      string ACompletionMessage)
        {
            /*Code to execute after the delete has occurred*/
            if (ADeletionPerformed && (ACompletionMessage.Length > 0))
            {
                RenumberJournals();
                SetBatchLastJournalNumber();
                UpdateHeaderTotals(GetBatchRow());

                if (((TFrmRecurringGLBatch)this.ParentForm).SaveChanges())
                {
                    MessageBox.Show(ACompletionMessage, Catalog.GetString("Deletion Completed"));
                }
                else
                {
                    MessageBox.Show(
                        "Unable to save after deletion and renumbering remaining recurring journals! Try saving manually and closing and reopening the form.");
                }
            }

            if (!pnlDetails.Enabled)         //set by FocusedRowChanged if grdDetails.Rows.Count < 2
            {
                ClearControls();
            }

            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions((grdDetails.Rows.Count > 1));
        }
        private void ValidateDataDetailsManual(ARecurringJournalRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedFinanceValidation_GL.ValidateRecurringGLJournalManual(this, ARow, ref VerificationResultCollection,
                                                                         FValidationControlsDict);

            //TODO: remove this once database definition is set for Batch Description to be NOT NULL
            // Description is mandatory then make sure it is set
            if (txtDetailJournalDescription.Text.Length == 0)
            {
                DataColumn          ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn  = ARow.Table.Columns[ARecurringJournalTable.ColumnJournalDescriptionId];
                ValidationContext = String.Format("Recurring Batch no.: {0}, Journal no.: {1}",
                                                  ARow.BatchNumber,
                                                  ARow.JournalNumber);

                VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.JournalDescription,
                                                                        "Description of " + ValidationContext,
                                                                        this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
 private void GetDetailsFromControlsManual(ARecurringJournalRow ARow)
 {
     if (ARow == null)
     {
         return;
     }
 }
        private void LoadJournals()
        {
            FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournal(FLedgerNumber, FBatchNumber));

            DataView JournalDV = new DataView(FMainDS.ARecurringJournal);

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

            //Populate the dictionary with all journal currencies
            if (JournalDV.Count > 0)
            {
                string  currencyCode = string.Empty;
                decimal exchangeRate = 0;

                foreach (DataRowView drv in JournalDV)
                {
                    ARecurringJournalRow jr = (ARecurringJournalRow)drv.Row;

                    currencyCode = jr.TransactionCurrency;
                    exchangeRate = (currencyCode == FBaseCurrencyCode) ? 1 : 0;

                    if (!FExchangeRateDictionary.ContainsKey(currencyCode))
                    {
                        FExchangeRateDictionary.Add(currencyCode, exchangeRate);
                    }

                    jr.ExchangeRateToBase = exchangeRate;
                }
            }

            SelectRowInGrid(1);
        }
        /// initialise some comboboxes
        private void BeforeShowDetailsManual(ARecurringJournalRow ARow)
        {
            // SubSystemCode: the user can only select GL, but the system can generate eg. AP journals or GR journals
            this.cmbDetailSubSystemCode.Items.Clear();
            this.cmbDetailSubSystemCode.Items.AddRange(new object[] { ARow.SubSystemCode });

            TFinanceControls.InitialiseTransactionTypeList(ref cmbDetailTransactionTypeCode, FLedgerNumber, ARow.SubSystemCode);
        }
Beispiel #8
0
        /// <summary>
        /// Validates the recurring GL Journal data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</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 ValidateRecurringGLJournalManual(object AContext, ARecurringJournalRow ARow,
                                                            ref TVerificationResultCollection AVerificationResultCollection)
        {
            int VerifResultCollAddedCount = 0;

            //TODO - nothing to add

            return(VerifResultCollAddedCount == 0);
        }
        /// <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(ARecurringJournalRow ARowToDelete,
                                      bool AAllowDeletion,
                                      bool ADeletionPerformed,
                                      string ACompletionMessage)
        {
            /*Code to execute after the delete has occurred*/

            TFrmRecurringGLBatch FMyForm = (TFrmRecurringGLBatch)this.ParentForm;

            try
            {
                if (ADeletionPerformed)
                {
                    UpdateChangeableStatus();

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

                    //Always update LastTransactionNumber first before updating totals
                    GLRoutines.UpdateRecurringBatchLastJournal(ref FMainDS, ref FBatchRow);
                    GLRoutines.UpdateRecurringBatchTotals(ref FMainDS, ref FBatchRow);
                    UpdateHeaderTotals(FBatchRow);

                    FMyForm.SaveChangesManual();

                    MessageBox.Show(ACompletionMessage,
                                    Catalog.GetString("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);
                }
            }
            finally
            {
                FMyForm.FCurrentGLBatchAction = TGLBatchEnums.GLBatchAction.NONE;
            }

            //Enable Transaction tab accordingly
            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions((grdDetails.Rows.Count > 1));
        }
        private void ShowDetailsManual(ARecurringJournalRow ARow)
        {
            bool JournalRowIsNull = (ARow == null);

            grdDetails.TabStop = (!JournalRowIsNull);

            if (JournalRowIsNull)
            {
                return;
            }

            btnGetSetExchangeRate.Enabled = (ARow.TransactionCurrency != FBaseCurrencyCode);
        }
        private bool PreDeleteManual(ARecurringJournalRow ARowToDelete, ref string ADeletionQuestion)
        {
            bool allowDeletion = true;

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

            return(allowDeletion);
        }
        private void ShowDetailsManual(ARecurringJournalRow ARow)
        {
            bool JournalRowIsNull = (ARow == null);

            grdDetails.TabStop = (!JournalRowIsNull);

            //Enable the transactions tab accordingly
            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions(!JournalRowIsNull);

            UpdateChangeableStatus();

            if (JournalRowIsNull)
            {
                btnAdd.Focus();
            }
        }
Beispiel #13
0
        private void SetBatchLastJournalNumber()
        {
            DataView JournalDV = new DataView(FMainDS.ARecurringJournal);

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

            JournalDV.Sort = String.Format("{0} DESC",
                                           ARecurringJournalTable.GetJournalNumberDBName()
                                           );

            if (JournalDV.Count > 0)
            {
                ARecurringJournalRow jrnlRow = (ARecurringJournalRow)JournalDV[0].Row;
                GetBatchRow().LastJournal = jrnlRow.JournalNumber;
            }
            else
            {
                GetBatchRow().LastJournal = 0;
            }
        }
        private void SetCurrencyControls()
        {
            FBaseCurrencyCode = FMainDS.ALedger[0].BaseCurrency;

            DataView JournalDV = new DataView(FMainDS.ARecurringJournal);

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

            if (JournalDV.Count == 0)
            {
                //Submitting an empty batch
                FCurrencyCode = FBaseCurrencyCode;
            }
            else
            {
                // All Journals in a recurring batch have the same currency code
                ARecurringJournalRow jr = (ARecurringJournalRow)JournalDV[0].Row;

                FCurrencyCode = jr.TransactionCurrency;
            }

            txtCurrencyCodeFrom.Text = FCurrencyCode;
            txtCurrencyCodeTo.Text   = FBaseCurrencyCode;

            if (FCurrencyCode == FBaseCurrencyCode)
            {
                txtExchangeRateToBase.Enabled   = false;
                txtExchangeRateToBase.BackColor = Color.LightPink;
            }
            else
            {
                txtExchangeRateToBase.Enabled   = true;
                txtExchangeRateToBase.BackColor = Color.Empty;
            }

            LookupCurrencyExchangeRates(DateTime.Now);
        }
        private void SetRateForSameCurrency(String ACurrencyCode, Decimal AExchangeRate, Int32 ARecurringJournalNumber)
        {
            DataView JournalCurrencyDV = new DataView(FMainDS.ARecurringJournal);

            JournalCurrencyDV.RowFilter = string.Format("{0}={1} And {2}<>{3} And {4}='{5}'",
                                                        ARecurringJournalTable.GetBatchNumberDBName(),
                                                        FBatchNumber,
                                                        ARecurringJournalTable.GetJournalNumberDBName(),
                                                        ARecurringJournalNumber,
                                                        ARecurringJournalTable.GetTransactionCurrencyDBName(),
                                                        ACurrencyCode);

            if (JournalCurrencyDV.Count > 0)
            {
                foreach (DataRowView drv in JournalCurrencyDV)
                {
                    ARecurringJournalRow jr = (ARecurringJournalRow)drv.Row;

                    jr.ExchangeRateToBase = AExchangeRate;
                }
            }

            SaveChanges();
        }
        private void ValidateDataDetailsManual(ARecurringJournalRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            // Description is mandatory then make sure it is set
            if (ARow.ExchangeRateToBase <= 0)
            {
                DataColumn          ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn  = ARow.Table.Columns[ARecurringJournalTable.ColumnExchangeRateToBaseId];
                ValidationContext = String.Format("Recurring Batch no.: {0}, Journal no.: {1}",
                                                  ARow.BatchNumber,
                                                  ARow.JournalNumber);

                VerificationResult = TNumericalChecks.IsNegativeOrZeroDecimal(ARow.ExchangeRateToBase,
                                                                              "Exchange rate of " + ValidationContext,
                                                                              this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
Beispiel #17
0
        /// <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(ARecurringJournalRow ARowToDelete, ref string ACompletionMessage)
        {
            int batchNumber = ARowToDelete.BatchNumber;

            FJournalNumberToDelete = ARowToDelete.JournalNumber;
            bool deletionSuccessful = false;

            // 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.

            ACompletionMessage = String.Format(Catalog.GetString("Journal no.: {0} deleted successfully."),
                                               FJournalNumberToDelete);

            try
            {
                //clear any transactions currently being editied in the Transaction Tab
                ((TFrmRecurringGLBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection();

                // Delete the associated recurring transaction analysis attributes
                DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);
                viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                       ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                                       batchNumber,
                                                                       ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                                                                       FJournalNumberToDelete
                                                                       );

                foreach (DataRowView row in viewRecurringTransAnalAttrib)
                {
                    row.Delete();
                }

                // Delete the associated recurring transactions
                DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);
                viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                                                                   ARecurringTransactionTable.GetBatchNumberDBName(),
                                                                   batchNumber,
                                                                   ARecurringTransactionTable.GetJournalNumberDBName(),
                                                                   FJournalNumberToDelete
                                                                   );

                foreach (DataRowView row in viewRecurringTransaction)
                {
                    row.Delete();
                }

                // Delete the recurring batch row.
                ARowToDelete.Delete();

                FPreviouslySelectedDetailRow = null;

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

            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(ARecurringJournalRow ARowToDelete,
            bool AAllowDeletion,
            bool ADeletionPerformed,
            string ACompletionMessage)
        {
            /*Code to execute after the delete has occurred*/
            if (ADeletionPerformed && (ACompletionMessage.Length > 0))
            {
                RenumberJournals();
                SetBatchLastJournalNumber();
                UpdateHeaderTotals(GetBatchRow());

                if (((TFrmRecurringGLBatch) this.ParentForm).SaveChanges())
                {
                    MessageBox.Show(ACompletionMessage, Catalog.GetString("Deletion Completed"));
                }
                else
                {
                    MessageBox.Show(
                        "Unable to save after deletion and renumbering remaining recurring journals! Try saving manually and closing and reopening the form.");
                }
            }

            if (!pnlDetails.Enabled)         //set by FocusedRowChanged if grdDetails.Rows.Count < 2
            {
                ClearControls();
            }

            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions((grdDetails.Rows.Count > 1));
        }
        private void ValidateDataDetailsManual(ARecurringJournalRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            TSharedFinanceValidation_GL.ValidateRecurringGLJournalManual(this, ARow, ref VerificationResultCollection,
                FValidationControlsDict);

            //TODO: remove this once database definition is set for Batch Description to be NOT NULL
            // Description is mandatory then make sure it is set
            if (txtDetailJournalDescription.Text.Length == 0)
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringJournalTable.ColumnJournalDescriptionId];
                ValidationContext = String.Format("Recurring Batch no.: {0}, Journal no.: {1}",
                    ARow.BatchNumber,
                    ARow.JournalNumber);

                VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.JournalDescription,
                    "Description of " + ValidationContext,
                    this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
Beispiel #20
0
        /// <summary>
        /// load the journals into the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        public void LoadJournals(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            bool FirstRun     = (FLedgerNumber != ALedgerNumber);
            bool BatchChanged = (FBatchNumber != ABatchNumber);

            FJournalsLoaded = false;
            FBatchRow       = GetBatchRow();

            if (FBatchRow == null)
            {
                return;
            }

            //Check if same Journals as previously selected
            if (!FirstRun && !BatchChanged)
            {
                if (GetSelectedRowIndex() > 0)
                {
                    GetDetailsFromControls(GetSelectedDetailRow());
                }
            }
            else
            {
                // a different journal
                FLedgerNumber = ALedgerNumber;
                FBatchNumber  = ABatchNumber;

                SetJournalDefaultView();
                FPreviouslySelectedDetailRow = null;

                if (FMainDS.ARecurringJournal.DefaultView.Count == 0)
                {
                    FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournalAndContent(ALedgerNumber, ABatchNumber));
                }

                ShowData();

                // Now set up the complete current filter
                FFilterAndFindObject.ApplyFilter();
            }

            //Check for incorrect Exchange rate to base
            foreach (DataRowView drv in FMainDS.ARecurringJournal.DefaultView)
            {
                ARecurringJournalRow rjr = (ARecurringJournalRow)drv.Row;

                if (rjr.ExchangeRateToBase == 0)
                {
                    rjr.ExchangeRateToBase       = 1;
                    FPetraUtilsObject.HasChanges = true;
                }
            }

            FJournalsLoaded = true;

            //This will also call UpdateChangeableStatus
            SelectRowInGrid((BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow);

            UpdateRecordNumberDisplay();
            FFilterAndFindObject.SetRecordNumberDisplayProperties();
        }
        private void ValidateDataDetailsManual(ARecurringJournalRow ARow)
        {
            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;

            // Description is mandatory then make sure it is set
            if (ARow.ExchangeRateToBase <= 0)
            {
                DataColumn ValidationColumn;
                TVerificationResult VerificationResult = null;
                object ValidationContext;

                ValidationColumn = ARow.Table.Columns[ARecurringJournalTable.ColumnExchangeRateToBaseId];
                ValidationContext = String.Format("Recurring Batch no.: {0}, Journal no.: {1}",
                    ARow.BatchNumber,
                    ARow.JournalNumber);

                VerificationResult = TNumericalChecks.IsNegativeOrZeroDecimal(ARow.ExchangeRateToBase,
                    "Exchange rate of " + ValidationContext,
                    this, ValidationColumn, null);

                // Handle addition/removal to/from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, true);
            }
        }
        private void ShowDetailsManual(ARecurringJournalRow ARow)
        {
            bool JournalRowIsNull = (ARow == null);

            grdDetails.TabStop = (!JournalRowIsNull);

            if (JournalRowIsNull)
            {
                return;
            }

            btnGetSetExchangeRate.Enabled = (ARow.TransactionCurrency != FBaseCurrencyCode);
        }
        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 bool PreDeleteManual(ARecurringJournalRow ARowToDelete, ref string ADeletionQuestion)
        {
            bool allowDeletion = true;

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

            return allowDeletion;
        }
        /// <summary>
        /// this submits the given Batch number
        /// Each line starts with a type specifier, B for batch, J for journal, T for transaction
        /// </summary>
        private void SubmitBatch(object sender, EventArgs e)
        {
            String SubmitErrorMessage = string.Empty;
            String ErrorMessageTitle  = "Submit Recurring Batch " + FBatchNumber.ToString();

            if ((dtpEffectiveDate.Date < FStartDateCurrentPeriod) ||
                (dtpEffectiveDate.Date > FEndDateLastForwardingPeriod))
            {
                SubmitErrorMessage =
                    String.Format(Catalog.GetString("The batch date is outside the allowed posting period start/end date range: {0} to {1}"),
                                  FStartDateCurrentPeriod.ToShortDateString(),
                                  FEndDateLastForwardingPeriod.ToShortDateString());

                MessageBox.Show(SubmitErrorMessage, ErrorMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                dtpEffectiveDate.Focus();
                dtpEffectiveDate.SelectAll();
                return;
            }

            // Check for any non-set exchange rates:
            DataView JournalDV = new DataView(FMainDS.ARecurringJournal);

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

            if (JournalDV.Count > 0)
            {
                string currencyCode      = string.Empty;
                bool   isForeignCurrency = false;

                foreach (DataRowView drv in JournalDV)
                {
                    ARecurringJournalRow jr = (ARecurringJournalRow)drv.Row;

                    currencyCode      = jr.TransactionCurrency;
                    isForeignCurrency = (currencyCode != FBaseCurrencyCode);

                    if (isForeignCurrency && (jr.ExchangeRateToBase <= 0))
                    {
                        if (SubmitErrorMessage.Length == 0)
                        {
                            SubmitErrorMessage = Catalog.GetString("The following foreign currency Journals need a valid exchange rate:") +
                                                 Environment.NewLine;
                        }

                        SubmitErrorMessage += string.Format("{0}Journal no.: {1:00} requires a rate for {2} to {3}",
                                                            Environment.NewLine,
                                                            jr.JournalNumber,
                                                            jr.TransactionCurrency,
                                                            FBaseCurrencyCode);
                    }
                    else if (isForeignCurrency)
                    {
                        FExchangeRateDictionary[currencyCode] = jr.ExchangeRateToBase;
                    }
                }

                if (SubmitErrorMessage.Length > 0)
                {
                    MessageBox.Show(SubmitErrorMessage, ErrorMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }

            Hashtable requestParams = new Hashtable();

            requestParams.Add("ALedgerNumber", FLedgerNumber);
            requestParams.Add("ABatchNumber", FBatchNumber);
            requestParams.Add("AEffectiveDate", dtpEffectiveDate.Date.Value);
            requestParams.Add("AExchangeRateIntlToBase", FExchangeRateIntlToBase);

            TVerificationResultCollection Verifications = new TVerificationResultCollection();
            Int32 NewGLBatchNumber = TRemote.MFinance.GL.WebConnectors.SubmitRecurringGLBatch(ref FMainDS,
                                                                                              requestParams,
                                                                                              ref FExchangeRateDictionary,
                                                                                              ref Verifications);

            if (NewGLBatchNumber > 0)
            {
                MessageBox.Show(String.Format(Catalog.GetString("Your Recurring GL Batch was submitted successfully as new GL Batch: {0}!"),
                                              NewGLBatchNumber),
                                Catalog.GetString("Success"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                string errorMessages = String.Empty;

                foreach (TVerificationResult verif in Verifications)
                {
                    errorMessages += "[" + verif.ResultContext + "] " +
                                     verif.ResultTextCaption + ": " +
                                     verif.ResultText + Environment.NewLine;
                }

                MessageBox.Show(errorMessages, Catalog.GetString("Recurring GL Batch Submit failed"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            Close();
        }
Beispiel #26
0
        /// <summary>
        /// Undo all changes to the specified batch ready to cancel it.
        ///  This avoids unecessary validation errors when cancelling.
        /// </summary>
        /// <param name="ABatchToDelete"></param>
        /// <param name="ARedisplay"></param>
        public void PrepareBatchDataForDeleting(Int32 ABatchToDelete, Boolean ARedisplay)
        {
            //This code will only be called when the Batch tab is active.

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

            GLBatchDV.RowFilter = String.Format("{0}={1}",
                                                ARecurringBatchTable.GetBatchNumberDBName(),
                                                ABatchToDelete);

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

            TransDV.RowFilter = String.Format("{0}={1}",
                                              ARecurringTransactionTable.GetBatchNumberDBName(),
                                              ABatchToDelete);

            TransAnalDV.RowFilter = String.Format("{0}={1}",
                                                  ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                                                  ABatchToDelete);

            //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)
            {
                JournalDV.Sort = String.Format("{0}", ARecurringJournalTable.GetJournalNumberDBName());

                foreach (DataRowView drv in JournalDV)
                {
                    ARecurringJournalRow journalRow = (ARecurringJournalRow)drv.Row;

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

            if (GLBatchDV.Count > 0)
            {
                ARecurringBatchRow batchRow = (ARecurringBatchRow)GLBatchDV[0].Row;

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

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

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

            if (TransDV.Count == 0)
            {
                //Load all related data for batch ready to delete/cancel
                FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournalAndRelatedTablesForBatch(FLedgerNumber, ABatchToDelete));
            }
        }
        private void ShowDetailsManual(ARecurringJournalRow ARow)
        {
            bool JournalRowIsNull = (ARow == null);

            grdDetails.TabStop = (!JournalRowIsNull);

            if (JournalRowIsNull)
            {
                btnAdd.Focus();
                FCurrencyCodeForJournals = string.Empty;
            }
            else
            {
                FCurrencyCodeForJournals = ARow.TransactionCurrency;
            }

            //Enable the transactions tab accordingly
            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions(!JournalRowIsNull);

            UpdateChangeableStatus();
        }
Beispiel #28
0
        /// <summary>
        /// Validates the recurring GL Journal data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</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>
        /// <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 ValidateRecurringGLJournalManual(object AContext, ARecurringJournalRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            int VerifResultCollAddedCount = 0;

            //TODO - nothing to add

            return VerifResultCollAddedCount == 0;
        }
        /// <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(ARecurringJournalRow ARowToDelete, ref string ACompletionMessage)
        {
            int batchNumber = ARowToDelete.BatchNumber;

            FJournalNumberToDelete = ARowToDelete.JournalNumber;
            bool deletionSuccessful = false;

            // 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.

            ACompletionMessage = String.Format(Catalog.GetString("Journal no.: {0} deleted successfully."),
                FJournalNumberToDelete);

            try
            {
                //clear any transactions currently being editied in the Transaction Tab
                ((TFrmRecurringGLBatch)ParentForm).GetTransactionsControl().ClearCurrentSelection();

                // Delete the associated recurring transaction analysis attributes
                DataView viewRecurringTransAnalAttrib = new DataView(FMainDS.ARecurringTransAnalAttrib);
                viewRecurringTransAnalAttrib.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                    ARecurringTransAnalAttribTable.GetBatchNumberDBName(),
                    batchNumber,
                    ARecurringTransAnalAttribTable.GetJournalNumberDBName(),
                    FJournalNumberToDelete
                    );

                foreach (DataRowView row in viewRecurringTransAnalAttrib)
                {
                    row.Delete();
                }

                // Delete the associated recurring transactions
                DataView viewRecurringTransaction = new DataView(FMainDS.ARecurringTransaction);
                viewRecurringTransaction.RowFilter = String.Format("{0} = {1} AND {2} = {3}",
                    ARecurringTransactionTable.GetBatchNumberDBName(),
                    batchNumber,
                    ARecurringTransactionTable.GetJournalNumberDBName(),
                    FJournalNumberToDelete
                    );

                foreach (DataRowView row in viewRecurringTransaction)
                {
                    row.Delete();
                }

                // Delete the recurring batch row.
                ARowToDelete.Delete();

                FPreviouslySelectedDetailRow = null;

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

            return deletionSuccessful;
        }
 private void GetDetailsFromControlsManual(ARecurringJournalRow ARow)
 {
     if (ARow == null)
     {
         return;
     }
 }
        /// initialise some comboboxes
        private void BeforeShowDetailsManual(ARecurringJournalRow ARow)
        {
            // SubSystemCode: the user can only select GL, but the system can generate eg. AP journals or GR journals
            this.cmbDetailSubSystemCode.Items.Clear();
            this.cmbDetailSubSystemCode.Items.AddRange(new object[] { ARow.SubSystemCode });

            //TFinanceControls.InitialiseTransactionTypeList(ref cmbDetailTransactionTypeCode, FLedgerNumber, ARow.SubSystemCode);
        }
        /// <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="ARefJournalRow">this can be null; otherwise this is the journal that the transaction should belong to</param>
        public void NewRowManual(ref GLBatchTDSARecurringTransactionRow ANewRow, ARecurringJournalRow ARefJournalRow)
        {
            if (ARefJournalRow == null)
            {
                ARefJournalRow = FJournalRow;
            }

            ANewRow.LedgerNumber = ARefJournalRow.LedgerNumber;
            ANewRow.BatchNumber = ARefJournalRow.BatchNumber;
            ANewRow.JournalNumber = ARefJournalRow.JournalNumber;
            ANewRow.TransactionNumber = ++ARefJournalRow.LastTransactionNumber;
            ANewRow.TransactionDate = FBatchRow.DateEffective;
            ANewRow.ExchangeRateToBase = FJournalRow.ExchangeRateToBase;

            if (FPreviouslySelectedDetailRow != null)
            {
                ANewRow.CostCentreCode = FPreviouslySelectedDetailRow.CostCentreCode;
                ANewRow.Narrative = FPreviouslySelectedDetailRow.Narrative;
                ANewRow.Reference = FPreviouslySelectedDetailRow.Reference;
            }
        }
        /// <summary>
        /// load the journals into the grid
        /// </summary>
        /// <param name="ACurrentBatchRow"></param>
        public void LoadJournals(ARecurringBatchRow ACurrentBatchRow)
        {
            FJournalsLoaded = false;

            FBatchRow = ACurrentBatchRow;

            if (FBatchRow == null)
            {
                return;
            }

            Int32 CurrentLedgerNumber = ACurrentBatchRow.LedgerNumber;
            Int32 CurrentBatchNumber  = ACurrentBatchRow.BatchNumber;

            bool FirstRun     = (FLedgerNumber != CurrentLedgerNumber);
            bool BatchChanged = (FBatchNumber != CurrentBatchNumber);

            if (FirstRun)
            {
                FLedgerNumber = CurrentLedgerNumber;
            }

            if (BatchChanged)
            {
                FBatchNumber = CurrentBatchNumber;
            }

            //Check if same Journals as previously selected
            if (!(FirstRun || BatchChanged))
            {
                //Need to reconnect FPrev in some circumstances
                if (FPreviouslySelectedDetailRow == null)
                {
                    DataRowView rowView = (DataRowView)grdDetails.Rows.IndexToDataSourceRow(FPrevRowChangedRow);

                    if (rowView != null)
                    {
                        FPreviouslySelectedDetailRow = (GLBatchTDSARecurringJournalRow)(rowView.Row);
                    }
                }

                if (GetSelectedRowIndex() > 0)
                {
                    GetDetailsFromControls(GetSelectedDetailRow());
                }
            }
            else
            {
                // a different journal
                SetJournalDefaultView();
                FPreviouslySelectedDetailRow = null;

                //Load Journals
                if (FMainDS.ARecurringJournal.DefaultView.Count == 0)
                {
                    FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadARecurringJournal(FLedgerNumber, FBatchNumber));
                }

                //Ensure Last Batch Number is correct, needed to correct old Petra data
                if ((FBatchRow.LastJournal != FMainDS.ARecurringJournal.DefaultView.Count) &&
                    GLRoutines.UpdateRecurringBatchLastJournal(ref FMainDS, ref FBatchRow))
                {
                    FPetraUtilsObject.SetChangedFlag();
                }

                ShowData();

                // Now set up the complete current filter
                FFilterAndFindObject.FilterPanelControls.SetBaseFilter(FMainDS.ARecurringJournal.DefaultView.RowFilter, true);
                FFilterAndFindObject.ApplyFilter();
            }

            int nRowToSelect = (BatchChanged || FirstRun) ? 1 : FPrevRowChangedRow;

            //This will also call UpdateChangeableStatus
            SelectRowInGrid(nRowToSelect);

            UpdateRecordNumberDisplay();
            FFilterAndFindObject.SetRecordNumberDisplayProperties();

            //Check for incorrect Exchange rate to base
            foreach (DataRowView drv in FMainDS.ARecurringJournal.DefaultView)
            {
                ARecurringJournalRow rjr = (ARecurringJournalRow)drv.Row;

                if (rjr.ExchangeRateToBase == 0)
                {
                    rjr.ExchangeRateToBase       = 1;
                    FPetraUtilsObject.HasChanges = true;
                }
            }

            FJournalsLoaded = true;

            //Check on batch totals
            if (GLRoutines.UpdateRecurringBatchTotals(ref FMainDS, ref FBatchRow))
            {
                FPetraUtilsObject.SetChangedFlag();
            }
        }
        /// <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(ARecurringJournalRow ARowToDelete,
            bool AAllowDeletion,
            bool ADeletionPerformed,
            string ACompletionMessage)
        {
            /*Code to execute after the delete has occurred*/
            if (ADeletionPerformed)
            {
                UpdateChangeableStatus();

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

                //Always update LastTransactionNumber first before updating totals
                GLRoutines.UpdateRecurringBatchLastJournal(ref FMainDS, ref FBatchRow);
                GLRoutines.UpdateRecurringBatchTotals(ref FMainDS, ref FBatchRow);

                if (((TFrmRecurringGLBatch) this.ParentForm).SaveChanges())
                {
                    UpdateHeaderTotals(FBatchRow);

                    MessageBox.Show(ACompletionMessage,
                        Catalog.GetString("Deletion Successful"),
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(Catalog.GetString("Error attempting to save after deleting a recurring Journal!"),
                        "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);
            }

            //Enable Transaction tab accordingly
            ((TFrmRecurringGLBatch)ParentForm).EnableTransactions((grdDetails.Rows.Count > 1));
        }