/// <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); }
public static TSubmitChangesResult SaveGLBatchTDS(ref GLBatchTDS AInspectDS, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); TVerificationResultCollection VerificationResult = AVerificationResult; // make sure that empty tables are removed AInspectDS = AInspectDS.GetChangesTyped(true); bool batchTableInDataSet = (AInspectDS.ABatch != null); bool journalTableInDataSet = (AInspectDS.AJournal != null); bool transTableInDataSet = (AInspectDS.ATransaction != null); bool attrTableInDataSet = (AInspectDS.ATransAnalAttrib != null); bool recurrBatchTableInDataSet = (AInspectDS.ARecurringBatch != null); bool recurrJournalTableInDataSet = (AInspectDS.ARecurringJournal != null); bool recurrTransTableInDataSet = (AInspectDS.ARecurringTransaction != null); //bool newTransaction = false; TDBTransaction Transaction = null; GLBatchTDS InspectDS = AInspectDS; // calculate debit and credit sums for journal and batch? but careful: we only have the changed parts! // no, we calculate the debit and credit sums before the posting, with GLRoutines.UpdateTotalsOfBatch // check added and modified and deleted rows: are they related to a posted or cancelled batch? we must not save adjusted posted batches! List <Int32>BatchNumbersInvolved = new List <int>(); Int32 LedgerNumber = -1; //Check if saving recurring tables if (recurrBatchTableInDataSet || recurrJournalTableInDataSet || recurrTransTableInDataSet) { if (batchTableInDataSet || journalTableInDataSet || transTableInDataSet || attrTableInDataSet) { throw new Exception( "SaveGLBatchTDS: need to call GetChangesTyped before saving, otherwise confusion about recurring or normal gl batch"); } return SaveRecurringGLBatchTDS(ref AInspectDS); } DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, ref Transaction, delegate { if (batchTableInDataSet) { LedgerNumber = ((ABatchRow)InspectDS.ABatch.Rows[0]).LedgerNumber; foreach (ABatchRow batch in InspectDS.ABatch.Rows) { if (batch.RowState != DataRowState.Added) { Int32 BatchNumber; try { BatchNumber = batch.BatchNumber; } catch (Exception) { // for deleted batches BatchNumber = (Int32)batch[ABatchTable.ColumnBatchNumberId, DataRowVersion.Original]; } if (!BatchNumbersInvolved.Contains(BatchNumber)) { BatchNumbersInvolved.Add(BatchNumber); } } int PeriodNumber, YearNr; if (TFinancialYear.IsValidPostingPeriod(LedgerNumber, batch.DateEffective, out PeriodNumber, out YearNr, Transaction)) { batch.BatchYear = YearNr; batch.BatchPeriod = PeriodNumber; } } } if (journalTableInDataSet) { if (LedgerNumber == -1) { LedgerNumber = ((AJournalRow)InspectDS.AJournal.Rows[0]).LedgerNumber; } foreach (GLBatchTDSAJournalRow journal in InspectDS.AJournal.Rows) { Int32 BatchNumber; try { BatchNumber = journal.BatchNumber; LedgerNumber = journal.LedgerNumber; } catch (Exception) { // for deleted journals BatchNumber = (Int32)journal[AJournalTable.ColumnBatchNumberId, DataRowVersion.Original]; LedgerNumber = (Int32)journal[AJournalTable.ColumnLedgerNumberId, DataRowVersion.Original]; } if (!BatchNumbersInvolved.Contains(BatchNumber)) { BatchNumbersInvolved.Add(BatchNumber); } } } if (transTableInDataSet) { if (LedgerNumber == -1) { LedgerNumber = ((ATransactionRow)InspectDS.ATransaction.Rows[0]).LedgerNumber; } GLPostingTDS TestAccountsAndCostCentres = new GLPostingTDS(); foreach (ATransactionRow transaction in InspectDS.ATransaction.Rows) { Int32 BatchNumber; try { BatchNumber = transaction.BatchNumber; LedgerNumber = transaction.LedgerNumber; if (TestAccountsAndCostCentres.AAccount.Count == 0) { AAccountAccess.LoadViaALedger(TestAccountsAndCostCentres, LedgerNumber, Transaction); ACostCentreAccess.LoadViaALedger(TestAccountsAndCostCentres, LedgerNumber, Transaction); } // TODO could check for active accounts and cost centres? // check for valid accounts and cost centres if (TestAccountsAndCostCentres.AAccount.Rows.Find(new object[] { LedgerNumber, transaction.AccountCode }) == null) { VerificationResult.Add(new TVerificationResult( Catalog.GetString("Cannot save transaction"), String.Format(Catalog.GetString("Invalid account code {0} in batch {1}, journal {2}, transaction {3}"), transaction.AccountCode, transaction.BatchNumber, transaction.JournalNumber, transaction.TransactionNumber), TResultSeverity.Resv_Critical)); } if (TestAccountsAndCostCentres.ACostCentre.Rows.Find(new object[] { LedgerNumber, transaction.CostCentreCode }) == null) { VerificationResult.Add(new TVerificationResult( Catalog.GetString("Cannot save transaction"), String.Format(Catalog.GetString("Invalid cost centre code {0} in batch {1}, journal {2}, transaction {3}"), transaction.CostCentreCode, transaction.BatchNumber, transaction.JournalNumber, transaction.TransactionNumber), TResultSeverity.Resv_Critical)); } // AmountInBaseCurrency must be greater than 0. // Transaction amount can be 0 if ForexGain. if (transaction.AmountInBaseCurrency <= 0) { VerificationResult.Add(new TVerificationResult( Catalog.GetString("Cannot save transaction"), String.Format(Catalog.GetString("Invalid amount in batch {0}, journal {1}, transaction {2}. " + "Either the debit amount or the credit amount needs to be greater than 0."), transaction.BatchNumber, transaction.JournalNumber, transaction.TransactionNumber), TResultSeverity.Resv_Critical)); } } catch (Exception) { // for deleted transactions BatchNumber = (Int32)transaction[ATransactionTable.ColumnBatchNumberId, DataRowVersion.Original]; LedgerNumber = (Int32)transaction[ATransactionTable.ColumnLedgerNumberId, DataRowVersion.Original]; } if (!BatchNumbersInvolved.Contains(BatchNumber)) { BatchNumbersInvolved.Add(BatchNumber); } } } if (attrTableInDataSet) { foreach (ATransAnalAttribRow transAnalAttrib in InspectDS.ATransAnalAttrib.Rows) { Int32 BatchNumber; if (transAnalAttrib.RowState != DataRowState.Deleted) { BatchNumber = transAnalAttrib.BatchNumber; if (!BatchNumbersInvolved.Contains(BatchNumber)) { BatchNumbersInvolved.Add(BatchNumber); } } } } // load previously stored batches and check for posted status if (BatchNumbersInvolved.Count == 0) { VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"), Catalog.GetString("Cannot save an empty Batch!"), TResultSeverity.Resv_Critical)); } else { string ListOfBatchNumbers = string.Empty; foreach (Int32 BatchNumber in BatchNumbersInvolved) { ListOfBatchNumbers = StringHelper.AddCSV(ListOfBatchNumbers, BatchNumber.ToString()); } string SQLStatement = "SELECT * " + " FROM PUB_" + ABatchTable.GetTableDBName() + " WHERE " + ABatchTable.GetLedgerNumberDBName() + " = " + LedgerNumber.ToString() + " AND " + ABatchTable.GetBatchNumberDBName() + " IN (" + ListOfBatchNumbers + ")"; GLBatchTDS BatchDS = new GLBatchTDS(); DBAccess.GDBAccessObj.Select(BatchDS, SQLStatement, BatchDS.ABatch.TableName, Transaction); foreach (ABatchRow batch in BatchDS.ABatch.Rows) { if ((batch.BatchStatus == MFinanceConstants.BATCH_POSTED) || (batch.BatchStatus == MFinanceConstants.BATCH_CANCELLED)) { VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"), String.Format(Catalog.GetString("Cannot modify Batch {0} because it is {1}"), batch.BatchNumber, batch.BatchStatus), TResultSeverity.Resv_Critical)); } } } }); AVerificationResult = VerificationResult; if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult)) { return TSubmitChangesResult.scrError; } //Need to save changes before deleting any transactions GLBatchTDSAccess.SubmitChanges(AInspectDS); TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK; if ((transTableInDataSet) && (AInspectDS.ATransaction.Rows.Count > 0)) { //Accept deletion of Attributes to allow deletion of transactions if (attrTableInDataSet) { AInspectDS.ATransAnalAttrib.AcceptChanges(); } AInspectDS.ATransaction.AcceptChanges(); if (AInspectDS.ATransaction.Count > 0) { ATransactionRow tranR = (ATransactionRow)AInspectDS.ATransaction.Rows[0]; Int32 currentLedger = tranR.LedgerNumber; Int32 currentBatch = tranR.BatchNumber; Int32 currentJournal = tranR.JournalNumber; Int32 transToDelete = 0; try { //Check if any records have been marked for deletion DataRow[] foundTransactionForDeletion = AInspectDS.ATransaction.Select(String.Format("{0} = '{1}'", ATransactionTable.GetSubTypeDBName(), MFinanceConstants.MARKED_FOR_DELETION)); if (foundTransactionForDeletion.Length > 0) { ATransactionRow transRowClient = null; for (int i = 0; i < foundTransactionForDeletion.Length; i++) { transRowClient = (ATransactionRow)foundTransactionForDeletion[i]; transToDelete = transRowClient.TransactionNumber; TLogging.Log(String.Format("Transaction to Delete: {0} from Journal: {1} in Batch: {2}", transToDelete, currentJournal, currentBatch)); transRowClient.Delete(); } //Submit all changes GLBatchTDSAccess.SubmitChanges(AInspectDS); SubmissionResult = TSubmitChangesResult.scrOK; } } catch (Exception ex) { TLogging.Log("Saving DataSet: " + ex.Message); TLogging.Log(String.Format("Error trying to save transaction: {0} in Journal: {1}, Batch: {2}", transToDelete, currentJournal, currentBatch )); SubmissionResult = TSubmitChangesResult.scrError; } } } return SubmissionResult; }
public static TSubmitChangesResult SaveGLBatchTDS(ref GLBatchTDS AInspectDS, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); TVerificationResultCollection VerificationResult = AVerificationResult; // make sure that empty tables are removed. This can return NULL!! AInspectDS = AInspectDS.GetChangesTyped(true); if (AInspectDS == null) { AVerificationResult.Add(new TVerificationResult( Catalog.GetString("Save GL Batch"), Catalog.GetString("No changes - nothing to do"), TResultSeverity.Resv_Info)); return TSubmitChangesResult.scrNothingToBeSaved; } bool AllValidationsOK = true; bool GLBatchTableInDataSet = (AInspectDS.ABatch != null && AInspectDS.ABatch.Count > 0); bool GLJournalTableInDataSet = (AInspectDS.AJournal != null && AInspectDS.AJournal.Count > 0); bool GLTransTableInDataSet = (AInspectDS.ATransaction != null && AInspectDS.ATransaction.Count > 0); bool GLTransAttrTableInDataSet = (AInspectDS.ATransAnalAttrib != null && AInspectDS.ATransAnalAttrib.Count > 0); bool RecurrGLBatchTableInDataSet = (AInspectDS.ARecurringBatch != null && AInspectDS.ARecurringBatch.Count > 0); bool RecurrGLJournalTableInDataSet = (AInspectDS.ARecurringJournal != null && AInspectDS.ARecurringJournal.Count > 0); bool RecurrGLTransTableInDataSet = (AInspectDS.ARecurringTransaction != null && AInspectDS.ARecurringTransaction.Count > 0); bool RecurrGLAttrTableInDataSet = (AInspectDS.ARecurringTransAnalAttrib != null && AInspectDS.ARecurringTransAnalAttrib.Count > 0); //Check if saving recurring tables if (RecurrGLBatchTableInDataSet || RecurrGLJournalTableInDataSet || RecurrGLTransTableInDataSet || RecurrGLAttrTableInDataSet) { if (GLBatchTableInDataSet || GLJournalTableInDataSet || GLTransTableInDataSet || GLTransAttrTableInDataSet) { throw new Exception(String.Format("Function:{0} - Recurring and normal GL data found in same changes batch!", Utilities.GetMethodName(true))); } return SaveRecurringGLBatchTDS(ref AInspectDS, ref AVerificationResult, RecurrGLBatchTableInDataSet, RecurrGLJournalTableInDataSet, RecurrGLTransTableInDataSet, RecurrGLAttrTableInDataSet); } else { if (!(GLBatchTableInDataSet || GLJournalTableInDataSet || GLTransTableInDataSet || GLTransAttrTableInDataSet)) { throw new Exception(String.Format("Function:{0} - No GL data changes to save!", Utilities.GetMethodName(true))); } } GLBatchTDS InspectDS = AInspectDS; List <Int32>ListAllGLBatchesToProcess = new List <int>(); Int32 LedgerNumber = -1; TDBTransaction Transaction = null; try { DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable, ref Transaction, delegate { if (GLBatchTableInDataSet) { DataView AllBatchesToProcess = new DataView(InspectDS.ABatch); AllBatchesToProcess.RowStateFilter = DataViewRowState.OriginalRows | DataViewRowState.Added; foreach (DataRowView drv in AllBatchesToProcess) { ABatchRow glbr = (ABatchRow)drv.Row; int batchNumber; if (glbr.RowState != DataRowState.Deleted) { LedgerNumber = glbr.LedgerNumber; batchNumber = glbr.BatchNumber; } else { LedgerNumber = (Int32)glbr[ABatchTable.ColumnLedgerNumberId, DataRowVersion.Original]; batchNumber = (Int32)glbr[ABatchTable.ColumnBatchNumberId, DataRowVersion.Original]; } if (!ListAllGLBatchesToProcess.Contains(batchNumber)) { ListAllGLBatchesToProcess.Add(batchNumber); } int periodNumber, yearNumber; if (TFinancialYear.IsValidPostingPeriod(LedgerNumber, glbr.DateEffective, out periodNumber, out yearNumber, Transaction)) { glbr.BatchYear = yearNumber; glbr.BatchPeriod = periodNumber; } } //TODO add validation as with gift //ValidateGiftDetail(ref AVerificationResult, AInspectDS.AGiftDetail); //ValidateGiftDetailManual(ref AVerificationResult, AInspectDS.AGiftDetail); if (!TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { AllValidationsOK = false; } } if (GLJournalTableInDataSet) { DataView AllBatchesToProcess = new DataView(InspectDS.AJournal); AllBatchesToProcess.RowStateFilter = DataViewRowState.OriginalRows | DataViewRowState.Added; foreach (DataRowView drv in AllBatchesToProcess) { GLBatchTDSAJournalRow gljr = (GLBatchTDSAJournalRow)drv.Row; int batchNumber; if (gljr.RowState != DataRowState.Deleted) { if (LedgerNumber == -1) { LedgerNumber = gljr.LedgerNumber; } batchNumber = gljr.BatchNumber; } else { if (LedgerNumber == -1) { LedgerNumber = (Int32)gljr[AJournalTable.ColumnLedgerNumberId, DataRowVersion.Original]; } batchNumber = (Int32)gljr[AJournalTable.ColumnBatchNumberId, DataRowVersion.Original]; } if (!ListAllGLBatchesToProcess.Contains(batchNumber)) { ListAllGLBatchesToProcess.Add(batchNumber); } } //TODO add validation as with gift //ValidateGiftDetail(ref AVerificationResult, AInspectDS.AGiftDetail); //ValidateGiftDetailManual(ref AVerificationResult, AInspectDS.AGiftDetail); if (!TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { AllValidationsOK = false; } } if (GLTransTableInDataSet) { DataView AllBatchesToProcess = new DataView(InspectDS.ATransaction); AllBatchesToProcess.RowStateFilter = DataViewRowState.OriginalRows | DataViewRowState.Added; GLPostingTDS accountsAndCostCentresDS = new GLPostingTDS(); foreach (DataRowView drv in AllBatchesToProcess) { ATransactionRow gltr = (ATransactionRow)drv.Row; int batchNumber; if (gltr.RowState != DataRowState.Deleted) { if (LedgerNumber == -1) { LedgerNumber = gltr.LedgerNumber; } batchNumber = gltr.BatchNumber; //Prepare to test for valid account and cost centre code if ((accountsAndCostCentresDS.AAccount == null) || (accountsAndCostCentresDS.AAccount.Count == 0)) { AAccountAccess.LoadViaALedger(accountsAndCostCentresDS, LedgerNumber, Transaction); ACostCentreAccess.LoadViaALedger(accountsAndCostCentresDS, LedgerNumber, Transaction); #region Validate Data if ((accountsAndCostCentresDS.AAccount == null) || (accountsAndCostCentresDS.AAccount.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Account data for Ledger number {1} does not exist or could not be accessed!"), Utilities.GetMethodName(true), LedgerNumber)); } else if ((accountsAndCostCentresDS.ACostCentre == null) || (accountsAndCostCentresDS.ACostCentre.Count == 0)) { throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString( "Function:{0} - Cost Centre data for Ledger number {1} does not exist or could not be accessed!"), Utilities.GetMethodName(true), LedgerNumber)); } #endregion Validate Data } CheckTransactionAccountAndCostCentre(LedgerNumber, ref accountsAndCostCentresDS, ref gltr, ref VerificationResult); } else { if (LedgerNumber == -1) { LedgerNumber = (Int32)gltr[ATransactionTable.ColumnLedgerNumberId, DataRowVersion.Original]; } batchNumber = (Int32)gltr[ATransactionTable.ColumnBatchNumberId, DataRowVersion.Original]; } if (!ListAllGLBatchesToProcess.Contains(batchNumber)) { ListAllGLBatchesToProcess.Add(batchNumber); } } //TODO add validation as with gift //ValidateGiftDetail(ref AVerificationResult, AInspectDS.AGiftDetail); //ValidateGiftDetailManual(ref AVerificationResult, AInspectDS.AGiftDetail); if (!TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { AllValidationsOK = false; } } if (GLTransAttrTableInDataSet) { DataView AllBatchesToProcess = new DataView(InspectDS.ATransAnalAttrib); AllBatchesToProcess.RowStateFilter = DataViewRowState.OriginalRows | DataViewRowState.Added; foreach (DataRowView drv in AllBatchesToProcess) { ATransAnalAttribRow glta = (ATransAnalAttribRow)drv.Row; int batchNumber; if (glta.RowState != DataRowState.Deleted) { if (LedgerNumber == -1) { LedgerNumber = glta.LedgerNumber; } batchNumber = glta.BatchNumber; } else { if (LedgerNumber == -1) { LedgerNumber = (Int32)glta[ATransAnalAttribTable.ColumnLedgerNumberId, DataRowVersion.Original]; } batchNumber = (Int32)glta[ATransAnalAttribTable.ColumnBatchNumberId, DataRowVersion.Original]; } if (!ListAllGLBatchesToProcess.Contains(batchNumber)) { ListAllGLBatchesToProcess.Add(batchNumber); } } //TODO add validation as with gift //ValidateGiftDetail(ref AVerificationResult, AInspectDS.AGiftDetail); //ValidateGiftDetailManual(ref AVerificationResult, AInspectDS.AGiftDetail); if (!TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { AllValidationsOK = false; } } // load previously stored batches and check for posted status if (ListAllGLBatchesToProcess.Count == 0) { VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"), Catalog.GetString("Cannot save an empty Batch!"), TResultSeverity.Resv_Critical)); } else { string listOfBatchNumbers = string.Empty; foreach (Int32 batchNumber in ListAllGLBatchesToProcess) { listOfBatchNumbers = StringHelper.AddCSV(listOfBatchNumbers, batchNumber.ToString()); } string SQLStatement = "SELECT * " + " FROM PUB_" + ABatchTable.GetTableDBName() + " WHERE " + ABatchTable.GetLedgerNumberDBName() + " = " + LedgerNumber.ToString() + " AND " + ABatchTable.GetBatchNumberDBName() + " IN (" + listOfBatchNumbers + ")"; GLBatchTDS BatchDS = new GLBatchTDS(); DBAccess.GDBAccessObj.Select(BatchDS, SQLStatement, BatchDS.ABatch.TableName, Transaction); foreach (ABatchRow batch in BatchDS.ABatch.Rows) { if ((batch.BatchStatus == MFinanceConstants.BATCH_POSTED) || (batch.BatchStatus == MFinanceConstants.BATCH_CANCELLED)) { VerificationResult.Add(new TVerificationResult(Catalog.GetString("Saving Batch"), String.Format(Catalog.GetString("Cannot modify Batch {0} because it is {1}"), batch.BatchNumber, batch.BatchStatus), TResultSeverity.Resv_Critical)); } } } }); } catch (Exception ex) { TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}", Utilities.GetMethodSignature(), Environment.NewLine, ex.Message)); throw ex; } if (AVerificationResult.Count > 0) { // Downgrade TScreenVerificationResults to TVerificationResults in order to allow // Serialisation (needed for .NET Remoting). TVerificationResultCollection.DowngradeScreenVerificationResults(AVerificationResult); } if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult)) { return TSubmitChangesResult.scrError; } TSubmitChangesResult SubmissionResult; if (AllValidationsOK) { //Need to save changes before deleting any transactions GLBatchTDSAccess.SubmitChanges(AInspectDS); SubmissionResult = TSubmitChangesResult.scrOK; } else { SubmissionResult = TSubmitChangesResult.scrError; } return SubmissionResult; }