private void InitialiseLedgerControls() { //Set the valid date range label TLedgerSelection.GetCurrentPostingRangeDates(FLedgerNumber, out FStartDateCurrentPeriod, out FEndDateLastForwardingPeriod, out FDefaultDate); lblValidDateRange.Text = String.Format(Catalog.GetString("Valid between {0} and {1}"), StringHelper.DateToLocalizedString(FStartDateCurrentPeriod, false, false), StringHelper.DateToLocalizedString(FEndDateLastForwardingPeriod, false, false)); // Get the current year/period and pass on to the filter logic object ALedgerRow LedgerRow = ((ALedgerTable)TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerDetails, FLedgerNumber))[0]; FCurrentLedgerYear = LedgerRow.CurrentFinancialYear; FCurrentLedgerPeriod = LedgerRow.CurrentPeriod; FLoadAndFilterLogicObject.CurrentLedgerYear = FCurrentLedgerYear; FLoadAndFilterLogicObject.CurrentLedgerPeriod = FCurrentLedgerPeriod; TFrmGLBatch myParentForm = (TFrmGLBatch)this.ParentForm; myParentForm.GetJournalsControl().LedgerBaseCurrency = LedgerRow.BaseCurrency; }
/// <summary> /// Posts a batch /// </summary> /// <param name="ACurrentBatchRow">The data row corresponding to the batch to post</param> /// <param name="AEffectiveDate">The effective date for the batch</param> /// <param name="AStartDateCurrentPeriod">The earliest postable date</param> /// <param name="AEndDateLastForwardingPeriod">The latest postable date</param> /// <returns>True if the batch was successfully posted</returns> public bool PostBatch(ABatchRow ACurrentBatchRow, DateTime AEffectiveDate, DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod) { bool RetVal = false; if (!SaveBatchForPosting()) { return(RetVal); } // TODO: display progress of posting TVerificationResultCollection Verifications; int CurrentBatchNumber = ACurrentBatchRow.BatchNumber; if ((AEffectiveDate.Date < AStartDateCurrentPeriod) || (AEffectiveDate.Date > AEndDateLastForwardingPeriod)) { MessageBox.Show(String.Format(Catalog.GetString( "The Date Effective is outside the periods available for posting. Enter a date between {0:d} and {1:d}."), AStartDateCurrentPeriod, AEndDateLastForwardingPeriod)); return(RetVal); } if (MessageBox.Show(String.Format(Catalog.GetString("Are you sure you want to post batch {0}?"), CurrentBatchNumber), Catalog.GetString("Question"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes) { try { Cursor.Current = Cursors.WaitCursor; if (!TRemote.MFinance.GL.WebConnectors.PostGLBatch(FLedgerNumber, CurrentBatchNumber, out Verifications)) { string ErrorMessages = String.Empty; foreach (TVerificationResult verif in Verifications) { ErrorMessages += "[" + verif.ResultContext + "] " + verif.ResultTextCaption + ": " + verif.ResultText + Environment.NewLine; } System.Windows.Forms.MessageBox.Show(ErrorMessages, Catalog.GetString("Posting failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // I don't need to call this directly, because the server calls it: // TFrmGLBatch.PrintPostingRegister(FLedgerNumber, CurrentBatchNumber); // TODO: print reports on successfully posted batch MessageBox.Show(Catalog.GetString("The batch has been posted successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh the grid, to reflect that the batch has been posted FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(FLedgerNumber, CurrentBatchNumber)); // make sure that the current dataset is clean, // otherwise the next save would try to modify the posted batch, even though no values have been changed FMainDS.AcceptChanges(); // Ensure these tabs will ask the server for updates FMyForm.GetJournalsControl().ClearCurrentSelection(); FMyForm.GetTransactionsControl().ClearCurrentSelection(); FMyUserControl.UpdateDisplay(); RetVal = true; } } finally { Cursor.Current = Cursors.Default; } } return(RetVal); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ABatchRowToCancel">The row to cancel</param> /// <returns></returns> public bool CancelBatch(ABatchRow ABatchRowToCancel) { //Assign default value(s) bool CancellationSuccessful = false; if ((ABatchRowToCancel == null)) { return(CancellationSuccessful); } int CurrentBatchNumber = ABatchRowToCancel.BatchNumber; if ((MessageBox.Show(String.Format(Catalog.GetString("You have chosen to cancel this batch ({0}).\n\nDo you really want to cancel it?"), CurrentBatchNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)) { return(CancellationSuccessful); } //Backup the Dataset for reversion purposes GLBatchTDS BackupMainDS = (GLBatchTDS)FMainDS.Copy(); BackupMainDS.Merge(FMainDS); bool RowToDeleteIsNew = (ABatchRowToCancel.RowState == DataRowState.Added); if (!RowToDeleteIsNew) { //Remove any changes, which may cause validation issues, before cancelling FMyForm.GetBatchControl().UndoModifiedBatchRow(ABatchRowToCancel, true); if (!(FMyForm.SaveChanges())) { MessageBox.Show(Catalog.GetString("Error in trying to save prior to cancelling current Batch!"), Catalog.GetString("Cancellation Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(CancellationSuccessful); } } try { FMyForm.Cursor = Cursors.WaitCursor; //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //clear any journals currently being editied in the Journals Tab FMyForm.GetJournalsControl().ClearCurrentSelection(); //Clear Journals etc for current Batch FMainDS.ATransAnalAttrib.Clear(); FMainDS.ATransaction.Clear(); FMainDS.AJournal.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransaction(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransAnalAttribForBatch(FLedgerNumber, CurrentBatchNumber)); FMainDS.AcceptChanges(); //Delete transactions and analysis attributes for (int i = FMainDS.ATransAnalAttrib.Count - 1; i >= 0; i--) { FMainDS.ATransAnalAttrib[i].Delete(); } for (int i = FMainDS.ATransaction.Count - 1; i >= 0; i--) { FMainDS.ATransaction[i].Delete(); } //Update Journal totals and status foreach (AJournalRow journal in FMainDS.AJournal.Rows) { if (journal.BatchNumber == CurrentBatchNumber) { journal.BeginEdit(); journal.JournalStatus = MFinanceConstants.BATCH_CANCELLED; journal.JournalCreditTotal = 0; journal.JournalDebitTotal = 0; journal.LastTransactionNumber = 0; journal.EndEdit(); } } // Edit the batch row ABatchRowToCancel.BeginEdit(); ABatchRowToCancel.BatchCreditTotal = 0; ABatchRowToCancel.BatchDebitTotal = 0; ABatchRowToCancel.BatchControlTotal = 0; ABatchRowToCancel.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ABatchRowToCancel.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The batch has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); FMyForm.DisableTransactions(); FMyForm.DisableJournals(); } else { throw new Exception(Catalog.GetString("The batch failed to save after being cancelled! Reopen the form and retry.")); } CancellationSuccessful = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Cancellation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Revert to previous state FMainDS.Merge(BackupMainDS); } finally { FMyForm.Cursor = Cursors.Default; } return(CancellationSuccessful); }
/// <summary> /// Import a batch from a spreadsheet /// </summary> /// <param name="ACSVDataFileName"></param> /// <param name="ALatestTransactionDate"></param> /// <returns></returns> public bool ImportFromSpreadsheet(out string ACSVDataFileName, out DateTime ALatestTransactionDate) { ALatestTransactionDate = DateTime.MinValue; ACSVDataFileName = String.Empty; OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = Catalog.GetString("Import transactions from spreadsheet file"); dialog.Filter = Catalog.GetString("Spreadsheet files (*.csv)|*.csv"); if (dialog.ShowDialog() == DialogResult.OK) { string directory = Path.GetDirectoryName(dialog.FileName); string[] ymlFiles = Directory.GetFiles(directory, "*.yml"); string definitionFileName = String.Empty; if (ymlFiles.Length == 1) { definitionFileName = ymlFiles[0]; } else { // show another open file dialog for the description file OpenFileDialog dialogDefinitionFile = new OpenFileDialog(); dialogDefinitionFile.Title = Catalog.GetString("Please select a yml file that describes the content of the spreadsheet"); dialogDefinitionFile.Filter = Catalog.GetString("Data description files (*.yml)|*.yml"); if (dialogDefinitionFile.ShowDialog() == DialogResult.OK) { definitionFileName = dialogDefinitionFile.FileName; } } if (File.Exists(definitionFileName)) { TYml2Xml parser = new TYml2Xml(definitionFileName); XmlDocument dataDescription = parser.ParseYML2XML(); XmlNode RootNode = TXMLParser.FindNodeRecursive(dataDescription.DocumentElement, "RootNode"); Int32 FirstTransactionRow = TXMLParser.GetIntAttribute(RootNode, "FirstTransactionRow"); string DefaultCostCentre = TXMLParser.GetAttribute(RootNode, "CostCentre"); FMyUserControl.CreateNewABatch(); GLBatchTDSAJournalRow NewJournal = FMainDS.AJournal.NewRowTyped(true); FMyForm.GetJournalsControl().NewRowManual(ref NewJournal); FMainDS.AJournal.Rows.Add(NewJournal); NewJournal.TransactionCurrency = TXMLParser.GetAttribute(RootNode, "Currency"); if (Path.GetExtension(dialog.FileName).ToLower() == ".csv") { ACSVDataFileName = dialog.FileName; CreateBatchFromCSVFile(dialog.FileName, RootNode, NewJournal, FirstTransactionRow, DefaultCostCentre, out ALatestTransactionDate); return(true); } } } return(false); }
/// <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); }
/// <summary> /// Reverses the specified batch /// </summary> /// <param name="ACurrentBatchRow">The DataRow for the batch to be reversed</param> /// <param name="ADateForReverseBatch">The reversal date - this will get checked to ensure the date is valid</param> /// <param name="AStartDateCurrentPeriod">The earliest date that can be used as reversal date</param> /// <param name="AEndDateLastForwardingPeriod">The latest date that can be used as a reversal date</param> /// <returns></returns> public bool ReverseBatch(ABatchRow ACurrentBatchRow, DateTime ADateForReverseBatch, DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod) { //TODO: Allow the user in a dialog to specify the reverse date TVerificationResultCollection Verifications; if (FPetraUtilsObject.HasChanges) { // save first, then post if (!FMyForm.SaveChanges()) { // saving failed, therefore do not try to reverse MessageBox.Show(Catalog.GetString("The batch was not reversed due to problems during saving; ") + Environment.NewLine + Catalog.GetString("Please first save the batch, and then you can reverse it!"), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } try { FMyForm.Cursor = Cursors.WaitCursor; int SelectedBatchNumber = ACurrentBatchRow.BatchNumber; string Msg = string.Empty; // load journals belonging to batch GLBatchTDS TempDS = TRemote.MFinance.GL.WebConnectors.LoadAJournalAndContent(FLedgerNumber, ACurrentBatchRow.BatchNumber); FMainDS.Merge(TempDS); foreach (AJournalRow Journal in TempDS.AJournal.Rows) { // if at least one journal in the batch has already been reversed then confirm with user if (Journal.Reversed) { Msg = String.Format(Catalog.GetString("One or more of the Journals in Batch {0} have already been reversed. " + "Are you sure you want to continue?"), SelectedBatchNumber); break; } } if (Msg == string.Empty) { Msg = String.Format(Catalog.GetString("Are you sure you want to reverse Batch {0}?"), SelectedBatchNumber); } if (MessageBox.Show(Msg, Catalog.GetString("GL Batch Reversal"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { TFrmBatchDateDialog Form = new TFrmBatchDateDialog(FMyForm); Form.SetParameters(AStartDateCurrentPeriod, AEndDateLastForwardingPeriod, SelectedBatchNumber); if (Form.ShowDialog() == DialogResult.Cancel) { return(false); } ADateForReverseBatch = Form.BatchDate; int ReversalGLBatch; if (!TRemote.MFinance.GL.WebConnectors.ReverseBatch(FLedgerNumber, SelectedBatchNumber, ADateForReverseBatch, out ReversalGLBatch, out Verifications, false)) { string ErrorMessages = String.Empty; foreach (TVerificationResult verif in Verifications) { ErrorMessages += "[" + verif.ResultContext + "] " + verif.ResultTextCaption + ": " + verif.ResultText + Environment.NewLine; } System.Windows.Forms.MessageBox.Show(ErrorMessages, Catalog.GetString("Reversal failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show( String.Format(Catalog.GetString("A reversal batch has been created, with batch number {0}!"), ReversalGLBatch), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh the grid, to reflect that the batch has been reversed FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(FLedgerNumber, ReversalGLBatch)); // make sure that the current dataset is clean, // otherwise the next save would try to modify the posted batch, even though no values have been changed FMainDS.AcceptChanges(); // Ensure these tabs will ask the server for updates FMyForm.GetJournalsControl().ClearCurrentSelection(); FMyForm.GetTransactionsControl().ClearCurrentSelection(); FMyUserControl.UpdateDisplay(); return(true); } } } catch (Exception) { throw; } finally { FMyForm.Cursor = Cursors.Default; } return(false); }
/// <summary> /// Posts a batch /// </summary> /// <param name="ACurrentBatchRow">The data row corresponding to the batch to post</param> /// <param name="AEffectiveDate">The effective date for the batch</param> /// <param name="AStartDateCurrentPeriod">The earliest postable date</param> /// <param name="AEndDateLastForwardingPeriod">The latest postable date</param> /// <param name="AInactiveValuesWarningOnGLPosting">Warn of inactive values</param> /// <returns> /// True if the batch was successfully posted /// </returns> public bool PostBatch(ABatchRow ACurrentBatchRow, DateTime AEffectiveDate, DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod, bool AInactiveValuesWarningOnGLPosting = true) { bool RetVal = false; if (!SaveBatchForPosting()) { return(RetVal); } //Load all Batch data FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(FLedgerNumber, ACurrentBatchRow.BatchNumber)); if (FCacheDS == null) { FCacheDS = TRemote.MFinance.GL.WebConnectors.LoadAAnalysisAttributes(FLedgerNumber, false); } if (FAccountTable == null) { SetAccountCostCentreTableVariables(); } //Check for inactive values int NumInactiveValues = 0; if (AInactiveValuesWarningOnGLPosting && !AllowInactiveFieldValues(ACurrentBatchRow.BatchNumber, out NumInactiveValues)) { return(RetVal); } bool PostWithInactiveValues = (NumInactiveValues > 0); // TODO: display progress of posting TVerificationResultCollection Verifications; int CurrentBatchNumber = ACurrentBatchRow.BatchNumber; if ((AEffectiveDate.Date < AStartDateCurrentPeriod) || (AEffectiveDate.Date > AEndDateLastForwardingPeriod)) { MessageBox.Show(String.Format(Catalog.GetString( "The Date Effective is outside the periods available for posting. Enter a date between {0:d} and {1:d}."), AStartDateCurrentPeriod, AEndDateLastForwardingPeriod)); return(RetVal); } // check that a corportate exchange rate exists FMyForm.WarnAboutMissingIntlExchangeRate = true; if (FMyForm.GetInternationalCurrencyExchangeRate() == 0) { return(false); } if (PostWithInactiveValues || (MessageBox.Show(String.Format(Catalog.GetString("Are you sure you want to post GL batch {0}?"), CurrentBatchNumber), Catalog.GetString("Question"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)) { try { Cursor.Current = Cursors.WaitCursor; if (!TRemote.MFinance.GL.WebConnectors.PostGLBatch(FLedgerNumber, CurrentBatchNumber, out Verifications)) { string ErrorMessages = String.Empty; foreach (TVerificationResult verif in Verifications) { ErrorMessages += "[" + verif.ResultContext + "] " + verif.ResultTextCaption + ": " + verif.ResultText + Environment.NewLine; } System.Windows.Forms.MessageBox.Show(ErrorMessages, Catalog.GetString("Posting failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //I don't need to call this directly, because the server calls it: //TFrmGLBatch.PrintPostingRegister(FLedgerNumber, CurrentBatchNumber); // TODO: print reports on successfully posted batch MessageBox.Show(Catalog.GetString("The batch has been posted successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); // refresh the grid, to reflect that the batch has been posted FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndContent(FLedgerNumber, CurrentBatchNumber)); // make sure that the current dataset is clean, // otherwise the next save would try to modify the posted batch, even though no values have been changed FMainDS.AcceptChanges(); // Ensure these tabs will ask the server for updates FMyForm.GetJournalsControl().ClearCurrentSelection(); FMyForm.GetTransactionsControl().ClearCurrentSelection(); FMyUserControl.UpdateDisplay(); RetVal = true; } } catch (Exception ex) { string msg = (String.Format(Catalog.GetString("Unexpected error occurred during the posting of GL Batch {0}!{1}{1}{2}{1}{1}{3}"), CurrentBatchNumber, Environment.NewLine, ex.Message, ex.InnerException != null?ex.InnerException.Message:String.Empty)); TLogging.LogException(ex, Utilities.GetMethodSignature()); MessageBox.Show(msg, "Post GL Batch Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } } return(RetVal); }
/// <summary> /// Method to cancel a specified batch /// </summary> /// <param name="ACurrentBatchRow">The row to cancel</param> /// <param name="ABatchDescriptionTextBox">Pass a reference to a TextBox that is used to display the batch description text. This is required /// to ensure that validation passes when the cancelled batch is saved.</param> /// <returns></returns> public bool CancelBatch(ABatchRow ACurrentBatchRow, TextBox ABatchDescriptionTextBox) { if ((ACurrentBatchRow == null) || !FMyForm.SaveChanges()) { return(false); } int CurrentBatchNumber = ACurrentBatchRow.BatchNumber; if ((MessageBox.Show(String.Format(Catalog.GetString("You have chosen to cancel this batch ({0}).\n\nDo you really want to cancel it?"), CurrentBatchNumber), Catalog.GetString("Confirm Cancel"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)) { try { //clear any transactions currently being editied in the Transaction Tab FMyForm.GetTransactionsControl().ClearCurrentSelection(); //clear any journals currently being editied in the Journals Tab FMyForm.GetJournalsControl().ClearCurrentSelection(); //Clear Journals etc for current Batch FMainDS.ATransAnalAttrib.Clear(); FMainDS.ATransaction.Clear(); FMainDS.AJournal.Clear(); //Load tables afresh FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAJournal(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransactionForBatch(FLedgerNumber, CurrentBatchNumber)); FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadATransAnalAttribForBatch(FLedgerNumber, CurrentBatchNumber)); //Delete transactions for (int i = FMainDS.ATransAnalAttrib.Count - 1; i >= 0; i--) { FMainDS.ATransAnalAttrib[i].Delete(); } for (int i = FMainDS.ATransaction.Count - 1; i >= 0; i--) { FMainDS.ATransaction[i].Delete(); } //Update Journal totals and status foreach (AJournalRow journal in FMainDS.AJournal.Rows) { if (journal.BatchNumber == CurrentBatchNumber) { journal.BeginEdit(); journal.JournalStatus = MFinanceConstants.BATCH_CANCELLED; journal.JournalCreditTotal = 0; journal.JournalDebitTotal = 0; journal.EndEdit(); } } // Edit the batch row ACurrentBatchRow.BeginEdit(); //Ensure validation passes if (ACurrentBatchRow.BatchDescription.Length == 0) { ABatchDescriptionTextBox.Text = " "; } ACurrentBatchRow.BatchCreditTotal = 0; ACurrentBatchRow.BatchDebitTotal = 0; ACurrentBatchRow.BatchControlTotal = 0; ACurrentBatchRow.BatchStatus = MFinanceConstants.BATCH_CANCELLED; ACurrentBatchRow.EndEdit(); FPetraUtilsObject.SetChangedFlag(); //Need to call save if (FMyForm.SaveChanges()) { MessageBox.Show(Catalog.GetString("The batch has been cancelled successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } else { // saving failed, therefore do not try to post MessageBox.Show(Catalog.GetString( "The batch has been cancelled but there were problems during saving; ") + Environment.NewLine + Catalog.GetString("Please try and save the cancellation immediately."), Catalog.GetString("Failure"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return(false); }
/// <summary> /// Posts a batch /// </summary> /// <param name="ACurrentBatchRow">The data row corresponding to the batch to post</param> /// <param name="AEffectiveDate">The effective date for the batch</param> /// <param name="AStartDateCurrentPeriod">The earliest postable date</param> /// <param name="AEndDateLastForwardingPeriod">The latest postable date</param> /// <returns> /// True if the batch was successfully posted /// </returns> public bool PostBatch(ABatchRow ACurrentBatchRow, DateTime AEffectiveDate, DateTime AStartDateCurrentPeriod, DateTime AEndDateLastForwardingPeriod) { if ((ACurrentBatchRow == null) || (ACurrentBatchRow.BatchStatus != MFinanceConstants.BATCH_UNPOSTED)) { return(false); } int CurrentBatchNumber = ACurrentBatchRow.BatchNumber; //Make sure that all control data is in dataset FMyForm.GetLatestControlData(); if (FPetraUtilsObject.HasChanges) { //Keep this conditional check separate so that it only gets called when necessary // and doesn't result in the executon of the next else if which calls same method if (!FMyForm.SaveChangesManual(FMyForm.FCurrentGLBatchAction)) { return(false); } } //This has to be called here as if there are no changes then the DataSavingValidating method // which calls the method below, will not run. else if (!FMyForm.GetTransactionsControl().AllowInactiveFieldValues(FLedgerNumber, CurrentBatchNumber, FMyForm.FCurrentGLBatchAction)) { return(false); } //Load all Batch data FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndRelatedTables(FLedgerNumber, CurrentBatchNumber)); if (FCacheDS == null) { FCacheDS = TRemote.MFinance.GL.WebConnectors.LoadAAnalysisAttributes(FLedgerNumber, false); } if (FAccountTable == null) { SetAccountCostCentreTableVariables(); } if ((AEffectiveDate.Date < AStartDateCurrentPeriod) || (AEffectiveDate.Date > AEndDateLastForwardingPeriod)) { MessageBox.Show(String.Format(Catalog.GetString( "The Date Effective is outside the periods available for posting. Enter a date between {0:d} and {1:d}."), AStartDateCurrentPeriod, AEndDateLastForwardingPeriod)); return(false); } // check that a corportate exchange rate exists FMyForm.WarnAboutMissingIntlExchangeRate = true; if (FMyForm.GetInternationalCurrencyExchangeRate() == 0) { return(false); } if ((MessageBox.Show(String.Format(Catalog.GetString("Are you sure you want to post GL batch {0}?"), CurrentBatchNumber), Catalog.GetString("Question"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != System.Windows.Forms.DialogResult.Yes)) { return(false); } TVerificationResultCollection Verifications = new TVerificationResultCollection(); try { Cursor.Current = Cursors.WaitCursor; Thread postingThread = new Thread(() => PostGLBatch(CurrentBatchNumber, out Verifications)); postingThread.SetApartmentState(ApartmentState.STA); using (TProgressDialog dialog = new TProgressDialog(postingThread)) { dialog.ShowDialog(); } if (TVerificationHelper.ResultsContainErrorCode(Verifications, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); } else if (!TVerificationHelper.IsNullOrOnlyNonCritical(Verifications)) { TFrmExtendedMessageBox extendedMessageBox = new TFrmExtendedMessageBox(FMyForm); StringBuilder errorMessages = new StringBuilder(); int counter = 0; errorMessages.AppendLine(Catalog.GetString("________________________GL Posting Errors________________________")); errorMessages.AppendLine(); foreach (TVerificationResult verif in Verifications) { counter++; errorMessages.AppendLine(counter.ToString("000") + " - " + verif.ResultText); errorMessages.AppendLine(); } extendedMessageBox.ShowDialog(errorMessages.ToString(), Catalog.GetString("Post Batch Error"), string.Empty, TFrmExtendedMessageBox.TButtons.embbOK, TFrmExtendedMessageBox.TIcon.embiWarning); } else { MessageBox.Show(Catalog.GetString("The batch has been posted successfully!"), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); } // refresh the grid, to reflect that the batch has been posted (or even maybe had been posted by another user) FMainDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadABatchAndRelatedTables(FLedgerNumber, CurrentBatchNumber)); // make sure that the current dataset is clean, // otherwise the next save would try to modify the posted batch, even though no values have been changed FMainDS.AcceptChanges(); // Ensure these tabs will ask the server for updates FMyForm.GetTransactionsControl().ClearCurrentSelection(); FMyForm.GetJournalsControl().ClearCurrentSelection(); FMyUserControl.UpdateDisplay(); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw; } finally { Cursor.Current = Cursors.Default; } return(true); }