private TVerificationResultCollection ReversePayment(int APaymentNumber, DateTime APeriodEndDate, List <int> ADocumentIds, AccountsPayableTDS AApDS) { string AssertFailMessage = "Failed to reverse AP payment: "; TVerificationResultCollection VerificationResult; List <Int32> glBatchNumbers; // "Un-pay" the specified invoice if (!TAPTransactionWebConnector.ReversePayment(FLedgerNumber, APaymentNumber, APeriodEndDate, out glBatchNumbers, out VerificationResult)) { Assert.Fail(AssertFailMessage + VerificationResult.BuildVerificationResultString()); } CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage); // Guard Assert // "Un-post" the specified invoice - returning it to "Approved" status! ADocumentIds[0] += 2; // The invoice I posted was reversed, and a duplicate now exists with an Id 2 greater than the original. return(PostAPDocument(AApDS, APeriodEndDate, ref ADocumentIds, true)); }
private static void ProcessDeletion(Form AMainWindow, Int32 ALedgerNumber, string ALedgerNameAndNumber) { TVerificationResultCollection VerificationResult; MethodInfo method; if (!TRemote.MFinance.Setup.WebConnectors.DeleteLedger(ALedgerNumber, out VerificationResult)) { MessageBox.Show( string.Format(Catalog.GetString("Deletion of Ledger '{0}' failed"), ALedgerNameAndNumber) + "\r\n\r\n" + VerificationResult.BuildVerificationResultString(), Catalog.GetString("Deletion failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show( string.Format(Catalog.GetString("Ledger '{0}' has been deleted"), ALedgerNameAndNumber), Catalog.GetString("Deletion successful"), MessageBoxButtons.OK, MessageBoxIcon.Information); } method = AMainWindow.GetType().GetMethod("ShowCurrentLedgerInfoInStatusBar"); if (method != null) { method.Invoke(AMainWindow, new object[] { }); } }
private TVerificationResultCollection PostAPDocument(AccountsPayableTDS AMainDS, DateTime APostingDate, ref List <int> ADocumentIds, bool AReversal = false) { string AssertFailMessage = AReversal ? "Failed to post AP document reversal: " : "Problems posting AP document: "; TVerificationResultCollection VerificationResult; if (!AReversal) { ADocumentIds.Add(AMainDS.AApDocument[0].ApDocumentId); } Int32 glBatchNumber; if (!TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber, ADocumentIds, APostingDate, AReversal, out glBatchNumber, out VerificationResult)) { Assert.Fail(AssertFailMessage + VerificationResult.BuildVerificationResultString()); } CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage); // Guard Assert return(VerificationResult); }
private static void ProcessDeletion(Form AMainWindow, Int64 AConferenceKey, string AConferenceName) { TVerificationResultCollection VerificationResult; MethodInfo method; if (!TRemote.MConference.Conference.WebConnectors.DeleteConference(AConferenceKey, out VerificationResult)) { MessageBox.Show( string.Format(Catalog.GetString("Deletion of Conference '{0}' failed"), AConferenceName) + "\r\n\r\n" + VerificationResult.BuildVerificationResultString(), Catalog.GetString("Deletion failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show( string.Format(Catalog.GetString("Conference '{0}' has been deleted"), AConferenceName), Catalog.GetString("Deletion successful"), MessageBoxButtons.OK, MessageBoxIcon.Information); } method = AMainWindow.GetType().GetMethod("ShowCurrentConferenceInfoInStatusBar"); if (method != null) { method.Invoke(AMainWindow, new object[] { }); } }
/// <summary> /// This will import a test gift batch, and post it. /// </summary> public static int ImportAndPostGiftBatch(DateTime AGiftDateEffective, TDataBase ADataBase) { TGiftImporting importer = new TGiftImporting(); string testFile = TAppSettingsManager.GetValue("GiftBatch.file", CommonNUnitFunctions.rootPath + "/csharp/ICT/Testing/lib/MFinance/SampleData/sampleGiftBatch.csv"); TLogging.Log(testFile); StreamReader sr = new StreamReader(testFile); string FileContent = sr.ReadToEnd(); sr.Close(); FileContent = FileContent.Replace("{ledgernumber}", FLedgerNumber.ToString()); FileContent = FileContent.Replace("{thisyear}-01-01", AGiftDateEffective.ToString("yyyy-MM-dd")); Hashtable parameters = new Hashtable(); parameters.Add("Delimiter", ","); parameters.Add("ALedgerNumber", FLedgerNumber); parameters.Add("DateFormatString", "yyyy-MM-dd"); parameters.Add("DatesMayBeIntegers", false); parameters.Add("NumberFormat", "American"); parameters.Add("NewLine", Environment.NewLine); TVerificationResultCollection VerificationResult; GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber; bool refreshRequired; importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out refreshRequired, out VerificationResult, ADataBase); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "error when importing gift batch:"); int BatchNumber = importer.GetLastGiftBatchNumber(); Assert.AreNotEqual(-1, BatchNumber, "Should have imported the gift batch and return a valid batch number"); Int32 generatedGlBatchNumber; if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out generatedGlBatchNumber, out VerificationResult, ADataBase)) { string VerifResStr; if (VerificationResult != null) { VerifResStr = ": " + VerificationResult.BuildVerificationResultString(); } else { VerifResStr = String.Empty; } Assert.Fail("Gift Batch was not posted" + VerifResStr); } return(BatchNumber); }
/// <summary> /// post and pay all invoices in the given period, but leave some (or none) unposted /// </summary> public static bool PostAndPayInvoices(int AYear, int APeriod, int ALeaveInvoicesUnposted = 0) { TLogging.LogAtLevel(1, "PostAndPayInvoices for year " + AYear.ToString() + " / period " + APeriod.ToString()); AccountsPayableTDS MainDS = new AccountsPayableTDS(); string sqlLoadDocuments = "SELECT * FROM PUB_a_ap_document WHERE a_ledger_number_i = ? AND a_date_issued_d >= ? AND a_date_issued_d <= ? AND a_document_status_c='APPROVED'"; DateTime PeriodStartDate, PeriodEndDate; TFinancialYear.GetStartAndEndDateOfPeriod(FLedgerNumber, APeriod, out PeriodStartDate, out PeriodEndDate, null); List <OdbcParameter> parameters = new List <OdbcParameter>(); OdbcParameter parameter; parameter = new OdbcParameter("ledgernumber", OdbcType.Int); parameter.Value = FLedgerNumber; parameters.Add(parameter); parameter = new OdbcParameter("startDate", OdbcType.DateTime); parameter.Value = PeriodStartDate; parameters.Add(parameter); parameter = new OdbcParameter("endDate", OdbcType.DateTime); parameter.Value = PeriodEndDate; parameters.Add(parameter); DBAccess.GDBAccessObj.SelectDT(MainDS.AApDocument, sqlLoadDocuments, null, parameters.ToArray(), -1, -1); int countUnPosted = MainDS.AApDocument.Count; List <int> DocumentIdsToPost = new List <int>(); foreach (AApDocumentRow invoice in MainDS.AApDocument.Rows) { if (countUnPosted <= ALeaveInvoicesUnposted) { break; } DocumentIdsToPost.Add(invoice.ApDocumentId); countUnPosted--; } TVerificationResultCollection VerificationResult; if ((DocumentIdsToPost.Count > 0) && !TAPTransactionWebConnector.PostAPDocuments(FLedgerNumber, DocumentIdsToPost, PeriodEndDate, false, out VerificationResult)) { TLogging.Log(VerificationResult.BuildVerificationResultString()); return(false); } // TODO pay the invoices as well return(true); }
/// <summary> /// Approve all tagged rows /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ApproveAllTagged(object sender, EventArgs e) { string MsgTitle = Catalog.GetString("Document Approval"); // I can only approve invoices that are OPEN. // This method is only enabled when the grid shows items for Approval List <int> ApproveTheseDocs = new List <int>(); foreach (DataRowView rv in grdInvoices.PagedDataTable.DefaultView) { if (rv.Row["Selected"].Equals(true)) { if (rv.Row["DocumentStatus"].ToString() == MFinanceConstants.AP_DOCUMENT_OPEN) { ApproveTheseDocs.Add(Convert.ToInt32(rv.Row["ApDocumentId"])); } else { MessageBox.Show(Catalog.GetString("Only OPEN documents can be approved."), MsgTitle); return; } } } if (ApproveTheseDocs.Count > 0) { string msg = String.Format(Catalog.GetString( "Are you sure that you want to approve the {0} tagged document(s)?"), ApproveTheseDocs.Count); if (MessageBox.Show(msg, MsgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } this.Cursor = Cursors.WaitCursor; TVerificationResultCollection VerificationResult; if (TRemote.MFinance.AP.WebConnectors.ApproveAPDocuments(FMainForm.LedgerNumber, ApproveTheseDocs, out VerificationResult)) { this.Cursor = Cursors.Default; FMainForm.IsInvoiceDataChanged = true; LoadInvoices(); MessageBox.Show(Catalog.GetString("The tagged documents have been approved successfully!"), MsgTitle); } else { MessageBox.Show(VerificationResult.BuildVerificationResultString(), MsgTitle); } this.Cursor = Cursors.Default; } else { MessageBox.Show(Catalog.GetString("There are no tagged invoices to be approved."), MsgTitle); } }
public void TestAnnualReceipt() { CommonNUnitFunctions.ResetDatabase(); // import a test gift batch TVerificationResultCollection VerificationResult; if (!ImportAndPostGiftBatch(FLedgerNumber, out VerificationResult)) { Assert.Fail("ImportAndPostGiftBatch failed: " + VerificationResult.BuildVerificationResultString()); } // TODO test reversed gifts string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptTemplate.html"); Encoding encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile); StreamReader sr = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false); string FileContent = sr.ReadToEnd(); sr.Close(); string formletterExpectedFile = TAppSettingsManager.GetValue("ReceiptExptected.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptExpected.html"); Catalog.Init("de-DE", "de-DE"); sr = new StreamReader(formletterExpectedFile, encodingOfHTMLfile, false); string ExpectedFormletterContent = sr.ReadToEnd(). Replace("#TODAY#", DateTime.Now.ToString("d. MMMM yyyy")). Replace("#THISYEAR#", DateTime.Today.Year.ToString()); sr.Close(); StreamWriter sw = new StreamWriter(formletterExpectedFile + ".updated", false, encodingOfHTMLfile); sw.WriteLine(ExpectedFormletterContent); sw.Close(); TLanguageCulture.SetLanguageAndCulture("de-DE", "de-DE"); //TODO: Calendar vs Financial Date Handling - Check if this should use financial year start/end and not assume calendar string receipts = TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31), FileContent); sw = new StreamWriter(formletterExpectedFile + ".new", false, encodingOfHTMLfile); sw.WriteLine(receipts); sw.WriteLine(); sw.Close(); Assert.IsTrue( TTextFile.SameContent(formletterExpectedFile + ".updated", formletterExpectedFile + ".new"), "receipt was not printed as expected, check " + formletterExpectedFile + ".new"); File.Delete(formletterExpectedFile + ".new"); File.Delete(formletterExpectedFile + ".updated"); }
/// <summary> /// Creates a AP document for the supplier specified with APartnerKey. /// </summary> /// <param name="APartnerKey"></param> /// <param name="AAmount"></param> /// <param name="AExchangeRatePosting"></param> /// <param name="ADocumentCode"></param> /// <param name="ANarrative"></param> /// <param name="AMainDS"></param> /// <param name="ADataBase"></param> /// <returns></returns> private TVerificationResultCollection CreateAPDocument(Int64 APartnerKey, decimal AAmount, decimal?AExchangeRatePosting, string ADocumentCode, string ANarrative, out AccountsPayableTDS AMainDS, TDataBase ADataBase) { string AssertFailMessage = "Problems saving AP document: "; TSubmitChangesResult SubmRes; TVerificationResultCollection VerificationResult; TDataBase db = DBAccess.Connect("CreateAPDocument", ADataBase); AMainDS = TAPTransactionWebConnector.CreateAApDocument(FLedgerNumber, APartnerKey, false, db); AccountsPayableTDS MainDS = AMainDS; TDBTransaction Transaction = new TDBTransaction(); db.ReadTransaction( ref Transaction, delegate { AApSupplierAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); }); AMainDS.AApDocument[0].DocumentCode = ADocumentCode + DateTime.Now.Ticks.ToString(); AMainDS.Merge(TAPTransactionWebConnector.CreateAApDocumentDetail( FLedgerNumber, AMainDS.AApDocument[0].ApDocumentId, AMainDS.AApSupplier[0].DefaultExpAccount, AMainDS.AApSupplier[0].DefaultCostCentre, AAmount, AMainDS.AApDocument[0].LastDetailNumber + 1)); AMainDS.AApDocument[0].LastDetailNumber++; AMainDS.AApDocument[0].TotalAmount = AAmount; AMainDS.AApDocument[0].DocumentStatus = MFinanceConstants.AP_DOCUMENT_APPROVED; AMainDS.AApDocumentDetail[0].Narrative = ANarrative; if (AExchangeRatePosting.HasValue) { AMainDS.AApDocument[0].ExchangeRateToBase = AExchangeRatePosting.Value; } SubmRes = TAPTransactionWebConnector.SaveAApDocument(ref AMainDS, out VerificationResult, db); if (SubmRes != TSubmitChangesResult.scrOK) { Assert.Fail(AssertFailMessage + String.Format(" - (SaveAApDocument return value: {0}) - ", SubmRes) + VerificationResult.BuildVerificationResultString()); } CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage); // Guard Assert return(VerificationResult); }
/// <summary> /// print single gift receipt /// </summary> //[Test] public void TestSingleReceipt() { CommonNUnitFunctions.ResetDatabase(); TPetraServerConnector.Connect("../../etc/TestServer.config"); // import a test gift batch TVerificationResultCollection VerificationResult; if (!TGiftAnnualReceiptTest.ImportAndPostGiftBatch(FLedgerNumber, out VerificationResult)) { Assert.Fail("ImportAndPostGiftBatch failed: " + VerificationResult.BuildVerificationResultString()); } string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/SingleGiftReceiptTemplate.html"); Encoding encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile); StreamReader sr = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false); string FileContent = sr.ReadToEnd(); sr.Close(); string formletterExpectedFile = TAppSettingsManager.GetValue("ReceiptExpected.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/SingleGiftReceiptExpected.html"); //TODO: Calendar vs Financial Date Handling - Check if this should use financial year start/end and not assume calendar string receipts; string receiptsPDF; bool result = TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual", new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31), FileContent, null, String.Empty, null, String.Empty, "de-DE", out receiptsPDF, out receipts); Assert.AreEqual(true, result, "receipt was empty"); StreamWriter sw = new StreamWriter(formletterExpectedFile + ".new", false, encodingOfHTMLfile); sw.WriteLine(receipts); sw.WriteLine(); sw.Close(); SortedList <string, string> ToReplace = new SortedList <string, string>(); ToReplace.Add("#TODAY#", DateTime.Now.ToString("d. MMMM yyyy")); ToReplace.Add("#THISYEAR#", DateTime.Today.Year.ToString()); Assert.IsTrue( TTextFile.SameContent(formletterExpectedFile, formletterExpectedFile + ".new", true, ToReplace, true), "receipt was not printed as expected, check " + formletterExpectedFile + ".new"); File.Delete(formletterExpectedFile + ".new"); }
private TVerificationResultCollection PayAPDocument(int AApDocumentId, decimal AAmount, string ABankAccount, string ACurrencyCode, DateTime APeriodEndDate, out int APaymentNumber, decimal?AExchangeRatePayment = null, TDataBase ADataBase = null) { string AssertFailMessage = "Problems paying AP document: "; TVerificationResultCollection VerificationResult; AccountsPayableTDS MainDS = new AccountsPayableTDS(); AApPaymentRow Payment = MainDS.AApPayment.NewRowTyped(); Payment.LedgerNumber = FLedgerNumber; Payment.PaymentNumber = -1; Payment.Amount = AAmount; Payment.BankAccount = ABankAccount; Payment.CurrencyCode = ACurrencyCode; if (AExchangeRatePayment.HasValue) { Payment.ExchangeRateToBase = AExchangeRatePayment.Value; } MainDS.AApPayment.Rows.Add(Payment); AApDocumentPaymentRow DocPayment = MainDS.AApDocumentPayment.NewRowTyped(); DocPayment.LedgerNumber = FLedgerNumber; DocPayment.ApDocumentId = AApDocumentId; DocPayment.Amount = AAmount; DocPayment.PaymentNumber = Payment.PaymentNumber; MainDS.AApDocumentPayment.Rows.Add(DocPayment); Int32 glBatchNumber; AccountsPayableTDSAApPaymentTable newPayments; if (!TAPTransactionWebConnector.PostAPPayments(ref MainDS, APeriodEndDate, out glBatchNumber, out newPayments, out VerificationResult, ADataBase)) { Assert.Fail(AssertFailMessage + VerificationResult.BuildVerificationResultString()); } CommonNUnitFunctions.EnsureNullOrEmptyVerificationResult(VerificationResult, AssertFailMessage); // Guard Assert APaymentNumber = DocPayment.PaymentNumber; return(VerificationResult); }
public void TestSingleReceipt() { CommonNUnitFunctions.ResetDatabase(); // import a test gift batch TVerificationResultCollection VerificationResult; if (!TGiftAnnualReceiptTest.ImportAndPostGiftBatch(FLedgerNumber, out VerificationResult)) { Assert.Fail("ImportAndPostGiftBatch failed: " + VerificationResult.BuildVerificationResultString()); } string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/SingleGiftReceiptTemplate.html"); Encoding encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile); StreamReader sr = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false); string FileContent = sr.ReadToEnd(); sr.Close(); string formletterExpectedFile = TAppSettingsManager.GetValue("ReceiptExptected.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/SingleGiftReceiptExpected.html"); Catalog.Init("de-DE", "de-DE"); TLanguageCulture.SetLanguageAndCulture("de-DE", "de-DE"); string receipts = TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31), FileContent); StreamWriter sw = new StreamWriter(formletterExpectedFile + ".new", false, encodingOfHTMLfile); sw.WriteLine(receipts); sw.WriteLine(); sw.Close(); SortedList <string, string> ToReplace = new SortedList <string, string>(); ToReplace.Add("#TODAY#", DateTime.Now.ToString("d. MMMM yyyy")); ToReplace.Add("#THISYEAR#", DateTime.Today.Year.ToString()); Assert.IsTrue( TTextFile.SameContent(formletterExpectedFile, formletterExpectedFile + ".new", true, ToReplace, true), "receipt was not printed as expected, check " + formletterExpectedFile + ".new"); File.Delete(formletterExpectedFile + ".new"); }
/// <summary> /// post all gift batches in the given period, but leave some (or none) unposted /// </summary> public static bool PostBatches(int AYear, int APeriod, int ALeaveBatchesUnposted, TDataBase ADataBase) { GiftBatchTDS MainDS = new GiftBatchTDS(); AGiftBatchRow GiftBatchTemplateRow = MainDS.AGiftBatch.NewRowTyped(false); GiftBatchTemplateRow.LedgerNumber = FLedgerNumber; GiftBatchTemplateRow.BatchYear = AYear; GiftBatchTemplateRow.BatchPeriod = APeriod; GiftBatchTemplateRow.BatchStatus = MFinanceConstants.BATCH_UNPOSTED; TDBTransaction Transaction = new TDBTransaction(); ADataBase.ReadTransaction(ref Transaction, delegate { AGiftBatchAccess.LoadUsingTemplate(MainDS, GiftBatchTemplateRow, Transaction); }); int countUnPosted = MainDS.AGiftBatch.Count; List <Int32> GiftBatchesToPost = new List <int>(); List <Int32> generatedGlBatches = new List <int>(); foreach (AGiftBatchRow batch in MainDS.AGiftBatch.Rows) { if (countUnPosted <= ALeaveBatchesUnposted) { break; } countUnPosted--; GiftBatchesToPost.Add(batch.BatchNumber); } TVerificationResultCollection VerificationResult; if (!TGiftTransactionWebConnector.PostGiftBatches(FLedgerNumber, GiftBatchesToPost, generatedGlBatches, out VerificationResult, ADataBase)) { TLogging.Log(VerificationResult.BuildVerificationResultString()); return(false); } return(true); }
private static void ProcessDeletion(Form AMainWindow, Int32 ALedgerNumber, string ALedgerNameAndNumber) { TVerificationResultCollection VerificationResult; MethodInfo method; if (!TRemote.MFinance.Setup.WebConnectors.DeleteLedger(ALedgerNumber, out VerificationResult)) { if (TVerificationHelper.ResultsContainErrorCode(VerificationResult, PetraErrorCodes.ERR_DB_SERIALIZATION_EXCEPTION)) { TConcurrentServerTransactions.ShowTransactionSerializationExceptionDialog(); } else { MessageBox.Show( string.Format(Catalog.GetString("Deletion of Ledger '{0}' failed"), ALedgerNameAndNumber) + "\r\n\r\n" + VerificationResult.BuildVerificationResultString(), Catalog.GetString("Deletion failed"), MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show( string.Format(Catalog.GetString("Ledger '{0}' has been deleted"), ALedgerNameAndNumber), Catalog.GetString("Deletion successful"), MessageBoxButtons.OK, MessageBoxIcon.Information); } method = AMainWindow.GetType().GetMethod("ShowCurrentLedgerInfoInStatusBar"); if (method != null) { method.Invoke(AMainWindow, new object[] { }); } }
private void ImportGiftBatch(DateTime AEffectiveDate) { TGiftImporting importer = new TGiftImporting(); string testFile = TAppSettingsManager.GetValue("GiftBatch.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/sampleGiftBatch.csv"); StreamReader sr = new StreamReader(testFile); string FileContent = sr.ReadToEnd(); FileContent = FileContent.Replace("{ledgernumber}", FLedgerNumber.ToString()); FileContent = FileContent.Replace("{thisyear}-01-01", AEffectiveDate.ToString("yyyy-MM-dd")); sr.Close(); Hashtable parameters = new Hashtable(); parameters.Add("Delimiter", ","); parameters.Add("ALedgerNumber", FLedgerNumber); parameters.Add("DateFormatString", "yyyy-MM-dd"); parameters.Add("NumberFormat", "American"); parameters.Add("NewLine", Environment.NewLine); TVerificationResultCollection VerificationResult; GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber; importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out VerificationResult); Assert.True(TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult), "Failed to import the test gift batch. The file contains critical error(s): " + VerificationResult.BuildVerificationResultString()); }
private void BtnOK_Click(System.Object sender, EventArgs e) { MethodInfo method; TVerificationResultCollection VerificationResult; if (!dtpCalendarStartDate.Date.HasValue) { MessageBox.Show(Catalog.GetString("Please supply valid Start date."), Catalog.GetString("Problem: No Ledger has been created"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (nudCurrentPeriod.Value > nudNumberOfPeriods.Value) { MessageBox.Show(Catalog.GetString("Current Period cannot be greater than Number of Periods!"), Catalog.GetString("Problem: No Ledger has been created"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (chkActivateGiftProcessing.Checked && ((txtStartingReceiptNumber.NumberValueInt == null) || (txtStartingReceiptNumber.NumberValueInt <= 0))) { MessageBox.Show(Catalog.GetString("Starting Receipt Number must be 1 or higher!"), Catalog.GetString("Problem: No Ledger has been created"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // check if a unit already exists that uses this ledger key; make sure name is identical String UnitName; TPartnerClass PartnerClass; Int64 PartnerKey = Convert.ToInt64(nudLedgerNumber.Value) * 1000000L; if (TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(PartnerKey, out UnitName, out PartnerClass, true)) { if (txtLedgerName.Text.Length == 0) { txtLedgerName.Text = UnitName; } else { if (UnitName != txtLedgerName.Text) { if (MessageBox.Show(String.Format(Catalog.GetString( "A Unit Partner record already exists for Ledger Number {0}!\r\n(Partner Key: {1} - Name: '{2}')\r\nYour suggested name '{3}' will automatically be changed to '{2}'.\r\n\r\nDo you still want to continue?"), nudLedgerNumber.Value.ToString(), PartnerKey.ToString(), UnitName, txtLedgerName.Text), Catalog.GetString("Problem: Ledger Name Mismatch"), MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { txtLedgerName.Text = UnitName; } else { return; } } } } else { if (txtLedgerName.Text.Length == 0) { MessageBox.Show( Catalog.GetString("Please enter a name for your ledger!"), Catalog.GetString("Problem: No Ledger has been created"), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Int32 StartingReceiptNumber = 1; if (txtStartingReceiptNumber.NumberValueInt != null) { StartingReceiptNumber = Convert.ToInt32(txtStartingReceiptNumber.NumberValueInt) - 1; } /* hourglass cursor */ System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; if (!TRemote.MFinance.Setup.WebConnectors.CreateNewLedger( Convert.ToInt32(nudLedgerNumber.Value), txtLedgerName.Text, cmbCountryCode.GetSelectedString(), cmbBaseCurrency.GetSelectedString(), cmbIntlCurrency.GetSelectedString(), dtpCalendarStartDate.Date.Value, Convert.ToInt32(nudNumberOfPeriods.Value), Convert.ToInt32(nudCurrentPeriod.Value), Convert.ToInt32(nudNumberOfFwdPostingPeriods.Value), rbtIchIsAsset.Checked, chkActivateGiftProcessing.Checked, StartingReceiptNumber, chkActivateAccountsPayable.Checked, out VerificationResult)) { /* normal mouse cursor */ System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; if (VerificationResult != null) { MessageBox.Show( VerificationResult.BuildVerificationResultString(), Catalog.GetString("Problem: No Ledger has been created")); } else { MessageBox.Show(Catalog.GetString("Problem: No Ledger has been created"), Catalog.GetString("Error")); } } else { /* normal mouse cursor */ System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; MessageBox.Show(String.Format(Catalog.GetString( "Ledger {0} ({1}) has been created successfully and is now the current Ledger.\r\n\r\nPermissions for users to be able to access this Ledger can be assigned in the System Manager Module."), txtLedgerName.Text, nudLedgerNumber.Value), Catalog.GetString("Success"), MessageBoxButtons.OK, MessageBoxIcon.Information); // reload permissions for user UserInfo.GUserInfo = TRemote.MSysMan.Security.UserManager.WebConnectors.ReloadCachedUserInfo(); // reload list of Ledger names TDataCache.TMFinance.RefreshCacheableFinanceTable(TCacheableFinanceTablesEnum.LedgerNameList); // reload navigation Form MainWindow = FPetraUtilsObject.GetCallerForm(); PropertyInfo CurrentLedgerProperty = MainWindow.GetType().GetProperty("CurrentLedger"); CurrentLedgerProperty.SetValue(MainWindow, Convert.ToInt32(nudLedgerNumber.Value), null); method = MainWindow.GetType().GetMethod("LoadNavigationUI"); if (method != null) { method.Invoke(MainWindow, new object[] { true }); } method = MainWindow.GetType().GetMethod("ShowCurrentLedgerInfoInStatusBar"); if (method != null) { method.Invoke(MainWindow, new object[] { }); } method = MainWindow.GetType().GetMethod("SelectFinanceFolder"); if (method != null) { method.Invoke(MainWindow, new object[] { }); } Close(); } }
/// <summary> /// Creates data needed to test posting recalculations /// </summary> /// <param name="ARecipientKey">Partner Key of the recipient.</param> /// <param name="ARealRecipientLedgerNumber">What the RecipientLedgerNumber should be.</param> /// <param name="AFalseRecipientLedgerNumber">What the RecipientLedgerNumber is.</param> /// <param name="ARecurringGiftBatchNumber">Batch Number.</param> private void TestRecurringBatchSubmitRecalculations_Arrange(out long ARecipientKey, out long ARealRecipientLedgerNumber, out long AFalseRecipientLedgerNumber, out Int32 ARecurringGiftBatchNumber) { TVerificationResultCollection VerificationResult; TSubmitChangesResult Result; DataSet ResponseDS; TPartnerEditUIConnector PartnerEditUIUIConnector = new TPartnerEditUIConnector(); GiftBatchTDS MainDS = new GiftBatchTDS(); PartnerEditTDS PartnerEditDS = new PartnerEditTDS(); // this is a family partner in the test database const Int64 DONORKEY = 43005001; // create a new recipient TCreateTestPartnerData.CreateNewFamilyPartner(PartnerEditDS); ARecipientKey = PartnerEditDS.PFamily[0].PartnerKey; // create two new Unit partners TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); AFalseRecipientLedgerNumber = PartnerEditDS.PPartner[0].PartnerKey; ARealRecipientLedgerNumber = PartnerEditDS.PPartner[1].PartnerKey; // create a Gift Destination for family PPartnerGiftDestinationRow GiftDestination = PartnerEditDS.PPartnerGiftDestination.NewRowTyped(true); GiftDestination.Key = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); GiftDestination.PartnerKey = ARecipientKey; GiftDestination.DateEffective = new DateTime(2011, 01, 01); GiftDestination.FieldKey = ARealRecipientLedgerNumber; PartnerEditDS.PPartnerGiftDestination.Rows.Add(GiftDestination); // Guard Assertions Assert.That(PartnerEditDS.PFamily[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[1], Is.Not.Null); // Submit the new PartnerEditTDS records to the database ResponseDS = new PartnerEditTDS(); Result = PartnerEditUIUIConnector.SubmitChanges(ref PartnerEditDS, ref ResponseDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SubmitChanges for PartnerEditDS failed: " + VerificationResult.BuildVerificationResultString()); // link unit to Cost Centre DataTable PartnerCostCentreTbl = TGLSetupWebConnector.LoadCostCentrePartnerLinks(FLedgerNumber, 0); DataRow PartnerCostCentreRow = PartnerCostCentreTbl.NewRow(); PartnerCostCentreRow["PartnerKey"] = ARealRecipientLedgerNumber; PartnerCostCentreRow["IsLinked"] = 4300; PartnerCostCentreTbl.Rows.Add(PartnerCostCentreRow); TGLSetupWebConnector.SaveCostCentrePartnerLinks(FLedgerNumber, PartnerCostCentreTbl); // create a new Recurring Gift Batch MainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); ARecurringGiftBatchNumber = MainDS.ARecurringGiftBatch[0].BatchNumber; // create a new recurring gifts ARecurringGiftRow RecurringGiftRow = MainDS.ARecurringGift.NewRowTyped(true); RecurringGiftRow.LedgerNumber = FLedgerNumber; RecurringGiftRow.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftRow.DonorKey = DONORKEY; RecurringGiftRow.GiftTransactionNumber = 1; RecurringGiftRow.LastDetailNumber = 1; MainDS.ARecurringGift.Rows.Add(RecurringGiftRow); // create a new RecurringGiftDetail ARecurringGiftDetailRow RecurringGiftDetail = MainDS.ARecurringGiftDetail.NewRowTyped(true); RecurringGiftDetail.LedgerNumber = FLedgerNumber; RecurringGiftDetail.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.DetailNumber = 1; RecurringGiftDetail.RecipientLedgerNumber = AFalseRecipientLedgerNumber; RecurringGiftDetail.GiftAmount = 100; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = ARecipientKey; MainDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); // Submit the new GiftBatchTDS records to the database Result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref MainDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SaveGiftBatchTDS failed: " + VerificationResult.BuildVerificationResultString()); }
public void TestBatchPostingRecalculations() { TVerificationResultCollection VerificationResult; Int64 RecipientKey; Int64 RealRecipientLedgerNumber; Int64 FalseRecipientLedgerNumber; const string REALCOSTCENTRECODE = "4300"; const string FALSECOSTCENTRECODE = "3500"; const string ACCOUNTCODE = "0100"; Int32 GiftBatchNumber; // // Arrange: Create all data needed for this test (Gift Details have 'fake' RecipientLedgerNumber and CostCentreCode) // TestBatchPostingRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber, out FalseRecipientLedgerNumber, REALCOSTCENTRECODE, FALSECOSTCENTRECODE, out GiftBatchNumber); // // Act: Post the batch // bool result = TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, GiftBatchNumber, out VerificationResult); // // Assert // // Initial Assert: Tests that the post returns positive Assert.AreEqual(true, result, "TestBatchPostingRecalculations fail: Posting GiftBatch failed: " + VerificationResult.BuildVerificationResultString()); // Primary Assert: Chaeck that the gifts have the correct RecipientLedgerNumber, CostCentreCode and Account TDBTransaction Transaction = null; AGiftDetailRow PositiveGiftDetailRow = null; AGiftDetailRow NegativeGiftDetailRow = null; ATransactionRow TransactionRow = null; Int32 GLBatchNumber = -1; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { PositiveGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 1, 1, Transaction)[0]; NegativeGiftDetailRow = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 2, 1, Transaction)[0]; GLBatchNumber = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, Transaction)[0].LastBatchNumber; TransactionRow = ATransactionAccess.LoadByPrimaryKey(FLedgerNumber, GLBatchNumber, 1, 1, Transaction)[0]; }); Assert.IsNotNull(PositiveGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining PositiveGiftDetailRow from database failed"); Assert.IsNotNull(NegativeGiftDetailRow, "TestBatchPostingRecalculations fail: Obtaining NegativeGiftDetailRow from database failed"); Assert.IsNotNull(TransactionRow, "TestBatchPostingRecalculations fail: Obtaining Transaction from database failed"); Assert.AreEqual(RealRecipientLedgerNumber, PositiveGiftDetailRow.RecipientLedgerNumber, "TestBatchPostingRecalculations fail: RecipientLedgerNumber for PositiveGiftDetailRow is incorrect"); Assert.AreEqual(FalseRecipientLedgerNumber, NegativeGiftDetailRow.RecipientLedgerNumber, "TestBatchPostingRecalculations fail: RecipientLedgerNumber for NegativeGiftDetailRow is incorrect"); Assert.AreEqual(REALCOSTCENTRECODE, PositiveGiftDetailRow.CostCentreCode, "TestBatchPostingRecalculations fail: CostCentreCode for PositiveGiftDetailRow is incorrect"); Assert.AreEqual(FALSECOSTCENTRECODE, NegativeGiftDetailRow.CostCentreCode, "TestBatchPostingRecalculations fail: CostCentreCode for NegativeGiftDetailRow is incorrect"); Assert.AreEqual(ACCOUNTCODE, TransactionRow.AccountCode, "TestBatchPostingRecalculations fail: AccountCode for PositiveGiftDetailRow is incorrect"); // Cleanup: Delete test records bool SubmissionOK = true; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK, delegate { AProcessedFeeAccess.DeleteUsingTemplate( new TSearchCriteria[] { new TSearchCriteria("a_ledger_number_i", FLedgerNumber), new TSearchCriteria("a_batch_number_i", GiftBatchNumber) }, Transaction); AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, PositiveGiftDetailRow, Transaction); AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, NegativeGiftDetailRow, Transaction); }); TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult); TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult); TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult); }
public void TestMultipleGifts() { // import the test gift batch, and post it TGiftImporting importer = new TGiftImporting(); string dirTestData = "../../csharp/ICT/Testing/lib/MFinance/server/BankImport/"; string testFile = dirTestData + "GiftBatch.csv"; StreamReader sr = new StreamReader(testFile); string FileContent = sr.ReadToEnd(); sr.Close(); FileContent = FileContent.Replace("2010-09-30", DateTime.Now.Year.ToString("0000") + "-09-30"); Hashtable parameters = new Hashtable(); parameters.Add("Delimiter", ","); parameters.Add("ALedgerNumber", FLedgerNumber); parameters.Add("DateFormatString", "yyyy-MM-dd"); parameters.Add("NumberFormat", "American"); parameters.Add("NewLine", Environment.NewLine); parameters.Add("DatesMayBeIntegers", false); TVerificationResultCollection VerificationResult; GiftBatchTDSAGiftDetailTable NeedRecipientLedgerNumber; bool refreshRequired; if (!importer.ImportGiftBatches(parameters, FileContent, out NeedRecipientLedgerNumber, out refreshRequired, out VerificationResult)) { Assert.Fail("Gift Batch was not imported: " + VerificationResult.BuildVerificationResultString()); } int BatchNumber = importer.GetLastGiftBatchNumber(); Assert.AreNotEqual(-1, BatchNumber, "Failed to import gift batch: " + VerificationResult.BuildVerificationResultString()); Int32 generatedGlBatchNumber; if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out generatedGlBatchNumber, out VerificationResult)) { Assert.Fail("Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString()); } // import the test csv file, will already do the training testFile = dirTestData + "BankStatement.csv"; sr = new StreamReader(testFile); FileContent = sr.ReadToEnd(); sr.Close(); FileContent = FileContent.Replace("30.09.2010", "30.09." + DateTime.Now.Year.ToString("0000")); Int32 StatementKey; BankImportTDS BankImportDS = TBankStatementImportCSV.ImportBankStatementHelper( FLedgerNumber, "6200", ";", "DMY", "European", "EUR", "unused,DateEffective,Description,Amount,Currency", "", "BankStatementSeptember.csv", FileContent); Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset september"); Assert.AreEqual(TSubmitChangesResult.scrOK, TBankStatementImport.StoreNewBankStatement( BankImportDS, out StatementKey), "save statement September"); // revert the gift batch, so that the training does not get confused if the test is run again; // the training needs only one gift batch for that date Hashtable requestParams = new Hashtable(); requestParams.Add("Function", GiftAdjustmentFunctionEnum.ReverseGiftBatch); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("BatchNumber", BatchNumber); requestParams.Add("GiftDetailNumber", -1); requestParams.Add("GiftNumber", -1); requestParams.Add("NewBatchSelected", false); requestParams.Add("NoReceipt", true); requestParams.Add("NewPct", 0.0m); requestParams.Add("UpdateTaxDeductiblePct", new System.Collections.Generic.List <string[]>()); requestParams.Add("GlEffectiveDate", new DateTime(DateTime.Now.Year, 09, 30)); requestParams.Add("AutoCompleteComments", false); requestParams.Add("ReversalCommentOne", String.Empty); requestParams.Add("ReversalCommentTwo", String.Empty); requestParams.Add("ReversalCommentThree", String.Empty); requestParams.Add("ReversalCommentOneType", String.Empty); requestParams.Add("ReversalCommentTwoType", String.Empty); requestParams.Add("ReversalCommentThreeType", String.Empty); int AdjustmentBatchNumber; bool BatchIsUnposted; GiftBatchTDS GiftReverseDS = TGiftTransactionWebConnector.LoadGiftTransactionsForBatch(FLedgerNumber, BatchNumber, out BatchIsUnposted); Assert.AreEqual(true, TAdjustmentWebConnector.GiftRevertAdjust(requestParams, out AdjustmentBatchNumber, GiftReverseDS), "reversing the gift batch"); if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, AdjustmentBatchNumber, out generatedGlBatchNumber, out VerificationResult)) { Assert.Fail("Gift Reverse Batch was not posted: " + VerificationResult.BuildVerificationResultString()); } // duplicate the bank import file, for the next month FileContent = FileContent.Replace("30.09." + DateTime.Now.Year.ToString("0000"), "30.10." + DateTime.Now.Year.ToString("0000")); BankImportDS = TBankStatementImportCSV.ImportBankStatementHelper( FLedgerNumber, "6200", ";", "DMY", "European", "EUR", "unused,DateEffective,Description,Amount,Currency", "", "BankStatementOctober.csv", FileContent); Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset october"); Assert.AreEqual(TSubmitChangesResult.scrOK, TBankStatementImport.StoreNewBankStatement( BankImportDS, out StatementKey), "save statement October"); // create gift batch from imported statement Int32 GiftBatchNumber; TBankImportWebConnector.CreateGiftBatch( FLedgerNumber, StatementKey, out VerificationResult, out GiftBatchNumber); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "cannot create gift batch from bank statement:"); // check if the gift batch is correct GiftBatchTDS GiftDS = TGiftTransactionWebConnector.LoadAGiftBatchAndRelatedData(FLedgerNumber, GiftBatchNumber); // since we are not able to match the split gifts, only 1 donation should be matched. // TODO: allow 2 gifts to be merged in OpenPetra, even when they come separate on the bank statement. // then 4 gifts could be matched. Assert.AreEqual(1, GiftDS.AGift.Rows.Count, "expected two matched gifts"); }
/// <summary> /// Saves the data to the server /// </summary> /// <param name="ATable">The typed table from the data set</param> /// <param name="ATableChanges">The changes table</param> /// <param name="ATableDbName">The server table name to write to</param> /// <returns></returns> public static bool SaveChanges(TTypedDataTable ATable, TTypedDataTable ATableChanges, string ATableDbName) { TSubmitChangesResult SubmissionResult; TVerificationResultCollection VerificationResult; if (ATableChanges == null) { // There is nothing to be saved. return(true); } // Submit changes to the PETRAServer try { SubmissionResult = TRemote.MCommon.DataReader.WebConnectors.SaveData(ATableDbName, ref ATableChanges, out VerificationResult); } catch (ESecurityDBTableAccessDeniedException) { Console.WriteLine("Error saving data prior to test: Access denied"); return(false); } catch (EDBConcurrencyException) { Console.WriteLine("Error saving data prior to test: Concurrency exception"); return(false); } catch (Exception Exp) { Console.WriteLine("Error saving data prior to test: General exception: {0}", Exp.Message); return(false); } switch (SubmissionResult) { case TSubmitChangesResult.scrOK: // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server ATable.AcceptChanges(); // Merge back with data from the Server (eg. for getting Sequence values) ATableChanges.AcceptChanges(); ATable.Merge(ATableChanges, false); // need to accept the new modification ID ATable.AcceptChanges(); return(true); case TSubmitChangesResult.scrNothingToBeSaved: return(true); case TSubmitChangesResult.scrError: Console.WriteLine( "Error saving data prior to test: Submission of data failed. " + VerificationResult.BuildVerificationResultString()); break; case TSubmitChangesResult.scrInfoNeeded: Console.WriteLine("Error saving data prior to test: Info Needed"); break; } return(false); }
public void TestAdjustGiftBatch() { int GiftBatchNumber = ImportAndPostGiftBatch(); TGet_GLM_Info getGLM_InfoBeforeTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300"); TGet_GLM_Info getGLM_InfoBeforeTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500"); string formletterTemplateFile = TAppSettingsManager.GetValue("ReceiptTemplate.file", "../../csharp/ICT/Testing/lib/MFinance/SampleData/AnnualReceiptTemplate.html"); Encoding encodingOfHTMLfile = TTextFile.GetFileEncoding(formletterTemplateFile); StreamReader sr = new StreamReader(formletterTemplateFile, encodingOfHTMLfile, false); string FileContent = sr.ReadToEnd(); sr.Close(); string receiptsBefore; string receiptsPDF; TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual", new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31), FileContent, null, String.Empty, null, String.Empty, "de-DE", out receiptsPDF, out receiptsBefore); Assert.AreNotEqual(0, receiptsBefore.Trim().Length, "old receipt must not be empty"); int AdjustBatchNumber; TAdjustmentWebConnector.GiftRevertAdjust(FLedgerNumber, GiftBatchNumber, -1, false, -1, DateTime.Today, GiftAdjustmentFunctionEnum.AdjustGift, false, -1.0m, out AdjustBatchNumber); bool BatchIsUnposted; string CurrencyCode; GiftBatchTDS BatchTDS = TGiftTransactionWebConnector.LoadGiftTransactionsForBatch( FLedgerNumber, AdjustBatchNumber, out BatchIsUnposted, out CurrencyCode); // find the transaction to modify Int32 ToModify = (BatchTDS.AGiftDetail[1].GiftTransactionNumber == 2)?1:0; // change the amount from 20 to 25 BatchTDS.AGiftDetail[ToModify].GiftTransactionAmount = 25; // the money should go to field 35 instead of field 73 BatchTDS.AGiftDetail[ToModify].RecipientKey = 35000000; // TODO change of donor // BatchTDS.Gift[1].DonorKey = TVerificationResultCollection VerificationResult; if (TGiftTransactionWebConnector.SaveGiftBatchTDS(ref BatchTDS, out VerificationResult) != TSubmitChangesResult.scrOK) { Assert.Fail("Adjustment Gift Batch was not saved: " + VerificationResult.BuildVerificationResultString()); } int generatedGlBatchNumber; if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, AdjustBatchNumber, out generatedGlBatchNumber, out VerificationResult)) { Assert.Fail("Adjustment Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString()); } TGet_GLM_Info getGLM_InfoAfterTest73 = new TGet_GLM_Info(FLedgerNumber, "0200", "7300"); TGet_GLM_Info getGLM_InfoAfterTest35 = new TGet_GLM_Info(FLedgerNumber, "0200", "3500"); // Test balance on the related account/Costcentre Assert.AreEqual(getGLM_InfoBeforeTest73.YtdActual - 20, getGLM_InfoAfterTest73.YtdActual, "The amount of 20 should be derived from the 73 costcentre"); Assert.AreEqual(getGLM_InfoBeforeTest35.YtdActual + 25, getGLM_InfoAfterTest35.YtdActual, "The amount of 25 should be added to the 35 costcentre"); // Test the number of rows on the gift receipt. // the difference should be 3 lines removed, 3 lines added. no double donations. string receiptsAfter; TReceiptingWebConnector.CreateAnnualGiftReceipts(FLedgerNumber, "Annual", new DateTime(DateTime.Today.Year, 1, 1), new DateTime(DateTime.Today.Year, 12, 31), FileContent, null, String.Empty, null, String.Empty, "de-DE", out receiptsPDF, out receiptsAfter); receiptsBefore = THttpBinarySerializer.DeserializeFromBase64(receiptsBefore); receiptsAfter = THttpBinarySerializer.DeserializeFromBase64(receiptsAfter); TLogging.Log("TestAdjustGiftBatch Diff:"); TLogging.Log(TTextFile.Diff(receiptsBefore, receiptsAfter)); string[] diff = TTextFile.Diff(receiptsBefore, receiptsAfter).Trim().Split(Environment.NewLine); Assert.AreEqual(6, diff.Length, "difference on receipts are 6 lines"); }
public void TestMultipleGifts() { // import the test gift batch, and post it TGiftImporting importer = new TGiftImporting(); string dirTestData = "../../csharp/ICT/Testing/lib/MFinance/server/BankImport/TestData/"; string testFile = dirTestData + "GiftBatch.csv"; StreamReader sr = new StreamReader(testFile); string FileContent = sr.ReadToEnd(); sr.Close(); FileContent = FileContent.Replace("2010-09-30", DateTime.Now.Year.ToString("0000") + "-09-30"); Hashtable parameters = new Hashtable(); parameters.Add("Delimiter", ","); parameters.Add("ALedgerNumber", FLedgerNumber); parameters.Add("DateFormatString", "yyyy-MM-dd"); parameters.Add("NumberFormat", "American"); parameters.Add("NewLine", Environment.NewLine); TVerificationResultCollection VerificationResult; importer.ImportGiftBatches(parameters, FileContent, out VerificationResult); int BatchNumber = importer.GetLastGiftBatchNumber(); Assert.AreNotEqual(-1, BatchNumber, "Failed to import gift batch: " + VerificationResult.BuildVerificationResultString()); if (!TGiftTransactionWebConnector.PostGiftBatch(FLedgerNumber, BatchNumber, out VerificationResult)) { Assert.Fail("Gift Batch was not posted: " + VerificationResult.BuildVerificationResultString()); } // import the test csv file, will already do the training TBankStatementImport import = new TBankStatementImport(); testFile = dirTestData + "BankStatement.csv"; sr = new StreamReader(testFile); FileContent = sr.ReadToEnd(); sr.Close(); FileContent = FileContent.Replace("30.09.2010", "30.09." + DateTime.Now.Year.ToString("0000")); Int32 StatementKey; BankImportTDS BankImportDS = import.ImportBankStatementNonInteractive( FLedgerNumber, "6200", ";", "DMY", TDlgSelectCSVSeparator.NUMBERFORMAT_EUROPEAN, "unused,DateEffective,Description,Amount,Currency", "BankStatementSeptember.csv", FileContent); Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset september"); Assert.AreEqual(TSubmitChangesResult.scrOK, TBankImportWebConnector.StoreNewBankStatement( BankImportDS, out StatementKey), "save statement September"); // revert the gift batch, so that the training does not get confused if the test is run again; // the training needs only one gift batch for that date Hashtable requestParams = new Hashtable(); requestParams.Add("Function", "ReverseGiftBatch"); requestParams.Add("ALedgerNumber", FLedgerNumber); requestParams.Add("BatchNumber", BatchNumber); requestParams.Add("GiftDetailNumber", -1); requestParams.Add("GiftNumber", -1); requestParams.Add("NewBatchSelected", false); requestParams.Add("GlEffectiveDate", new DateTime(DateTime.Now.Year, 09, 30)); Assert.AreEqual(true, TAdjustmentWebConnector.GiftRevertAdjust(requestParams, out VerificationResult), "reversing the gift batch"); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "Gift Batch was not reverted:"); // duplicate the bank import file, for the next month FileContent = FileContent.Replace("30.09." + DateTime.Now.Year.ToString("0000"), "30.10." + DateTime.Now.Year.ToString("0000")); BankImportDS = import.ImportBankStatementNonInteractive( FLedgerNumber, "6200", ";", "DMY", TDlgSelectCSVSeparator.NUMBERFORMAT_EUROPEAN, "unused,DateEffective,Description,Amount,Currency", "BankStatementOcotober.csv", FileContent); Assert.AreNotEqual(null, BankImportDS, "valid bank import dataset october"); Assert.AreEqual(TSubmitChangesResult.scrOK, TBankImportWebConnector.StoreNewBankStatement( BankImportDS, out StatementKey), "save statement October"); // create gift batch from imported statement Int32 GiftBatchNumber = TBankImportWebConnector.CreateGiftBatch( FLedgerNumber, StatementKey, -1, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "cannot create gift batch from bank statement:"); // check if the gift batch is correct GiftBatchTDS GiftDS = TGiftTransactionWebConnector.LoadGiftBatchData(FLedgerNumber, GiftBatchNumber); // since we are not able to match the split gift, only 2 gifts should be matched. // TODO: allow 2 gifts to be merged in OpenPetra, even when they come separate on the bank statement. // then 4 gifts could be matched. Assert.AreEqual(2, GiftDS.AGift.Rows.Count, "expected two matched gifts"); }