private void RevertDataSet(GLBatchTDS AMainDS, GLBatchTDS ABackupDS, int ASelectRowInGrid = 0)
        {
            if ((ABackupDS != null) && (AMainDS != null))
            {
                AMainDS.RejectChanges();
                AMainDS.Merge(ABackupDS);

                if (ASelectRowInGrid > 0)
                {
                    SelectRowInGrid(ASelectRowInGrid);
                }
            }
        }
Ejemplo n.º 2
0
        public static void UpdateTotalsOfBatch(Int32 ALedgerNumber, Int32 ABatchNumber)
        {
            //TVerificationResultCollection AVerificationResult = new TVerificationResultCollection();
            GLBatchTDS glDS = new GLBatchTDS();

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

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

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

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

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

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

                    UpdateTotalsOfJournal(ref glDS, journalrow);

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

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

                glDS.AcceptChanges();
            }
            catch (Exception)
            {
                glDS.RejectChanges();
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// create a new recurring batch.
        /// it is already stored to the database, to avoid problems with LastBatchNumber
        /// </summary>
        public static GLBatchTDS CreateARecurringBatch(Int32 ALedgerNumber)
        {
            bool NewTransactionStarted = false;

            GLBatchTDS MainDS = null;
            GLBatchTDS Temp = null;

            //Error handling
            string ErrorContext = "Create a recurring Batch";
            string ErrorMessage = String.Empty;
            //Set default type as non-critical
            TResultSeverity ErrorType = TResultSeverity.Resv_Noncritical;
            TVerificationResultCollection VerificationResult = null;

            try
            {
                MainDS = new GLBatchTDS();
                Temp = new GLBatchTDS();

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

                ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                ARecurringBatchAccess.LoadViaALedger(Temp, ALedgerNumber, Transaction);

                DataView RecurringBatchDV = new DataView(Temp.ARecurringBatch);
                RecurringBatchDV.RowFilter = string.Empty;
                RecurringBatchDV.Sort = string.Format("{0} DESC",
                    ARecurringBatchTable.GetBatchNumberDBName());

                //Recurring batch numbers can be reused so check each time for current highest number
                if (RecurringBatchDV.Count > 0)
                {
                    MainDS.ALedger[0].LastRecurringBatchNumber = (int)(RecurringBatchDV[0][ARecurringBatchTable.GetBatchNumberDBName()]);
                }
                else
                {
                    MainDS.ALedger[0].LastRecurringBatchNumber = 0;
                }

                ARecurringBatchRow NewRow = MainDS.ARecurringBatch.NewRowTyped(true);
                NewRow.LedgerNumber = ALedgerNumber;
                NewRow.BatchNumber = ++MainDS.ALedger[0].LastRecurringBatchNumber;
                MainDS.ARecurringBatch.Rows.Add(NewRow);

                GLBatchTDSAccess.SubmitChanges(MainDS);

                MainDS.AcceptChanges();
                Temp.RejectChanges();
            }
            catch (Exception ex)
            {
                ErrorMessage =
                    String.Format(Catalog.GetString("Unknown error while creating a recurring batch for Ledger: {0}." +
                            Environment.NewLine + Environment.NewLine + ex.ToString()),
                        ALedgerNumber);
                ErrorType = TResultSeverity.Resv_Critical;
                VerificationResult = new TVerificationResultCollection();
                VerificationResult.Add(new TVerificationResult(ErrorContext, ErrorMessage, ErrorType));

                throw new EVerificationResultsException(ErrorMessage, VerificationResult, ex.InnerException);
            }
            finally
            {
                if (NewTransactionStarted)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }
            }

            return MainDS;
        }
        /// <summary>
        /// Method to cancel a specified journal
        /// </summary>
        /// <param name="AJournalRowToCancel">The row to cancel</param>
        /// <returns>True if the journal is cancelled.</returns>
        public bool CancelRow(GLBatchTDSAJournalRow AJournalRowToCancel)
        {
            bool CancellationSuccessful = false;

            if ((AJournalRowToCancel == null) || (AJournalRowToCancel.JournalStatus != MFinanceConstants.BATCH_UNPOSTED))
            {
                return(false);
            }

            int  CurrentBatchNo   = AJournalRowToCancel.BatchNumber;
            int  CurrentJournalNo = AJournalRowToCancel.JournalNumber;
            bool CurrentJournalTransactionsLoadedAndCurrent = false;

            string CancelMessage     = string.Empty;
            string CompletionMessage = string.Empty;

            CancelMessage = String.Format(Catalog.GetString("Are you sure you want to cancel GL Journal {0} in Batch {1}?"),
                                          CurrentJournalNo,
                                          CurrentBatchNo);

            if ((MessageBox.Show(CancelMessage,
                                 Catalog.GetString("Confirm Cancel"),
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question,
                                 MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes))
            {
                return(false);
            }

            //Backup the Dataset for reversion purposes
            GLBatchTDS BackupMainDS = null;

            try
            {
                FMyForm.Cursor = Cursors.WaitCursor;

                //Backup the Dataset for reversion purposes
                BackupMainDS = (GLBatchTDS)FMainDS.GetChangesTyped(false);

                //Don't run an inactive fields check on this batch
                FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary(CurrentBatchNo);

                //Check if current batch details are currently loaded
                CurrentJournalTransactionsLoadedAndCurrent = (FMyForm.GetTransactionsControl().FBatchNumber == CurrentBatchNo);

                //Save and check for inactive values in other unsaved Batches
                FPetraUtilsObject.SetChangedFlag();

                if (!FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction, false, !CurrentJournalTransactionsLoadedAndCurrent))
                {
                    FMyForm.GetBatchControl().UpdateUnpostedBatchDictionary();

                    CompletionMessage = String.Format(Catalog.GetString("Journal {0} in GL Batch {1} has not been cancelled."),
                                                      CurrentJournalNo,
                                                      CurrentBatchNo);

                    MessageBox.Show(CompletionMessage,
                                    Catalog.GetString("GL Journal Cancellation"),
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);

                    return(false);
                }

                //Remove any changes, which may cause validation issues, before cancelling
                FMyForm.GetJournalsControl().PrepareJournalDataForCancelling(CurrentBatchNo, CurrentJournalNo, true);

                if (CurrentJournalTransactionsLoadedAndCurrent)
                {
                    //Clear any transactions currently being edited in the Transaction Tab
                    FMyForm.GetTransactionsControl().ClearCurrentSelection(CurrentBatchNo);
                }

                //Delete transactions and attributes for current jouernal only
                FMyForm.GetTransactionsControl().DeleteTransactionData(CurrentBatchNo, CurrentJournalNo);

                //Edit current Journal
                decimal journalCreditTotal = AJournalRowToCancel.JournalCreditTotal;
                decimal journalDebitTotal  = AJournalRowToCancel.JournalDebitTotal;
                AJournalRowToCancel.BeginEdit();
                AJournalRowToCancel.JournalStatus         = MFinanceConstants.BATCH_CANCELLED;
                AJournalRowToCancel.LastTransactionNumber = 0;
                AJournalRowToCancel.JournalCreditTotal    = 0;
                AJournalRowToCancel.JournalDebitTotal     = 0;
                AJournalRowToCancel.EndEdit();

                //Edit current Batch
                ABatchRow CurrentBatchRow   = FMyForm.GetBatchControl().GetSelectedDetailRow();
                decimal   batchControlTotal = CurrentBatchRow.BatchControlTotal;
                CurrentBatchRow.BeginEdit();
                CurrentBatchRow.BatchCreditTotal  -= journalCreditTotal;
                CurrentBatchRow.BatchDebitTotal   -= journalDebitTotal;
                CurrentBatchRow.BatchControlTotal -= (batchControlTotal != 0 ? journalCreditTotal : 0);
                CurrentBatchRow.EndEdit();

                FPetraUtilsObject.SetChangedFlag();
                FMyForm.SaveChangesManual();

                CompletionMessage = String.Format(Catalog.GetString("Journal no.: {0} cancelled successfully."),
                                                  CurrentJournalNo);

                MessageBox.Show(CompletionMessage,
                                Catalog.GetString("Journal Cancelled"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);

                FMyForm.DisableTransactions();

                CancellationSuccessful = true;
            }
            catch (Exception ex)
            {
                //Revert to previous state
                if (BackupMainDS != null)
                {
                    FMainDS.RejectChanges();
                    FMainDS.Merge(BackupMainDS);

                    FMyForm.GetJournalsControl().ShowDetailsRefresh();
                }

                TLogging.LogException(ex, Utilities.GetMethodSignature());
                throw;
            }
            finally
            {
                FMyForm.Cursor = Cursors.Default;
            }

            return(CancellationSuccessful);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// create a new recurring batch.
        /// it is already stored to the database, to avoid problems with LastBatchNumber
        /// </summary>
        public static GLBatchTDS CreateARecurringBatch(Int32 ALedgerNumber)
        {
            #region Validate Arguments

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

            #endregion Validate Arguments

            GLBatchTDS MainDS = new GLBatchTDS();
            GLBatchTDS TempDS = new GLBatchTDS();

            TDBTransaction Transaction = null;
            bool SubmissionOK = false;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                    TEnforceIsolationLevel.eilMinimum,
                    ref Transaction,
                    ref SubmissionOK,
                    delegate
                    {
                        ALedgerAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, Transaction);

                        #region Validate Data

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

                        #endregion Validate Data

                        ARecurringBatchAccess.LoadViaALedger(TempDS, ALedgerNumber, Transaction);

                        DataView RecurringBatchDV = new DataView(TempDS.ARecurringBatch);
                        RecurringBatchDV.RowFilter = string.Empty;
                        RecurringBatchDV.Sort = string.Format("{0} DESC",
                            ARecurringBatchTable.GetBatchNumberDBName());

                        //Recurring batch numbers can be reused so check each time for current highest number
                        if (RecurringBatchDV.Count > 0)
                        {
                            MainDS.ALedger[0].LastRecurringBatchNumber = (int)(RecurringBatchDV[0][ARecurringBatchTable.GetBatchNumberDBName()]);
                        }
                        else
                        {
                            MainDS.ALedger[0].LastRecurringBatchNumber = 0;
                        }

                        ARecurringBatchRow NewRow = MainDS.ARecurringBatch.NewRowTyped(true);
                        NewRow.LedgerNumber = ALedgerNumber;
                        NewRow.BatchNumber = ++MainDS.ALedger[0].LastRecurringBatchNumber;
                        MainDS.ARecurringBatch.Rows.Add(NewRow);

                        //Empty the TempDS
                        TempDS.RejectChanges();

                        //Submit changes to MainDS
                        GLBatchTDSAccess.SubmitChanges(MainDS);

                        SubmissionOK = true;
                    });

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

            return MainDS;
        }