public static void SetLastReceiptNumber(Int32 ALedgerNumber, Int32 AReceiptNumber) { TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); ALedgerTable LedgerTbl; try { LedgerTbl = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, ReadWriteTransaction); if (LedgerTbl.Rows.Count > 0) { LedgerTbl[0].LastHeaderRNumber = AReceiptNumber; ALedgerAccess.SubmitChanges(LedgerTbl, ReadWriteTransaction); DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the setting of the last Receipt Number:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } }
private void CommitLedgerChange() { TDBTransaction Transaction = null; Boolean SubmissionOK = false; try { DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { ALedgerAccess.SubmitChanges(FLedgerTbl, Transaction); SubmissionOK = true; }); FLedgerTbl.AcceptChanges(); } catch (Exception ex) { TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}", Utilities.GetMethodSignature(), Environment.NewLine, ex.Message)); throw ex; } GetDataRow(); }
public void TearDown() { // Delete our working test rows foreach (int LedgerNum in FTestLedgerList) { DeleteTestRowIfExists(LedgerNum); } ALedgerAccess.SubmitChanges(FMainDS.ALedger, null); // Disconnect TPetraServerConnector.Disconnect(); }
public void Init() { TPetraServerConnector.Connect("../../etc/TestServer.config"); // These will be our test ledger numbers FTestLedgerList.AddRange(new int[] { 9997, 9998, 9999 }); // Load existing data FMainDS = new GLSetupTDS(); try { TDBTransaction transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("Init"); db.ReadTransaction( ref transaction, delegate { ALedgerAccess.LoadAll(FMainDS, transaction); }); // Check that our test rows are not in the database already if (!FindTestRows(FTestLedgerList)) { // Get the initial number of available ledgers FInitialLedgerCount = TGLSetupWebConnector.GetAvailableLedgers().DefaultView.Count; bool SubmitOK = true; db.WriteTransaction( ref transaction, ref SubmitOK, delegate { // Add our test rows AddTestRow(FTestLedgerList[0], "NUnitTestLedger1", false); AddTestRow(FTestLedgerList[1], "NUnitTestLedger2", true, "JPY"); AddTestRow(FTestLedgerList[2], "NUnitTestLedger2", true); // Save these new rows ALedgerAccess.SubmitChanges(FMainDS.ALedger, transaction); FMainDS.AcceptChanges(); }); FInitSucceeded = true; } } catch (Exception ex) { FInitExceptionMessage = ex.Message; } }
private void CommitLedgerChange() { bool NewTransaction; TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, out NewTransaction); ALedgerAccess.SubmitChanges(FLedgerTbl, Transaction); FLedgerTbl.AcceptChanges(); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); GetDataRow(); } }
public void Init() { TPetraServerConnector.Connect("../../etc/TestServer.config"); // These will be our test ledger numbers FTestLedgerList.AddRange(new int[] { 9997, 9998, 9999 }); // Load existing data FMainDS = new GLSetupTDS(); try { TDBTransaction transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref transaction, delegate { ALedgerAccess.LoadAll(FMainDS, transaction); }); // Check that our test rows are not in the database already if (!FindTestRows(FTestLedgerList)) { // Get the initial number of available ledgers FInitialLedgerCount = TGLSetupWebConnector.GetAvailableLedgers().DefaultView.Count; // Add our test rows AddTestRow(FTestLedgerList[0], "NUnitTestLedger1", false); AddTestRow(FTestLedgerList[1], "NUnitTestLedger2", true, "JPY"); AddTestRow(FTestLedgerList[2], "NUnitTestLedger2", true); // Save these new rows ALedgerAccess.SubmitChanges(FMainDS.ALedger, null); FMainDS.AcceptChanges(); FInitSucceeded = true; } } catch (Exception ex) { FInitExceptionMessage = ex.Message; } }
private void CommitLedgerChange() { TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("CommitLedgerChange", FDataBase); Boolean SubmissionOK = false; try { db.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { ALedgerAccess.SubmitChanges(FLedgerTbl, Transaction); SubmissionOK = true; }); FLedgerTbl.AcceptChanges(); } catch (Exception ex) { TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}", Utilities.GetMethodSignature(), Environment.NewLine, ex.Message)); throw; } if (FDataBase == null) { db.CloseDBConnection(); } GetDataRow(); if (FDataBase == null) { db.CloseDBConnection(); } }
public void TearDown() { // Delete our working test rows foreach (int LedgerNum in FTestLedgerList) { DeleteTestRowIfExists(LedgerNum); } TDBTransaction transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("TearDown"); bool SubmitOK = true; db.WriteTransaction( ref transaction, ref SubmitOK, delegate { ALedgerAccess.SubmitChanges(FMainDS.ALedger, transaction); }); // Disconnect TPetraServerConnector.Disconnect(); }
public static bool GiftRevertAdjust(Hashtable requestParams, out TVerificationResultCollection AMessages) { AMessages = new TVerificationResultCollection(); Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"]; Boolean batchSelected = (Boolean)requestParams["NewBatchSelected"]; Int32 ANewBatchNumber = 0; bool TaxDeductiblePercentageEnabled = Convert.ToBoolean( TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_TAXDEDUCTIBLEPERCENTAGE, "FALSE")); if (batchSelected) { ANewBatchNumber = (Int32)requestParams["NewBatchNumber"]; } String Function = (String)requestParams["Function"]; Int32 AGiftDetailNumber = (Int32)requestParams["GiftDetailNumber"]; Int32 AGiftNumber = (Int32)requestParams["GiftNumber"]; Int32 ABatchNumber = (Int32)requestParams["BatchNumber"]; //decimal batchHashTotal = 0; decimal batchGiftTotal = 0; GiftBatchTDS MainDS = new GiftBatchTDS(); TDBTransaction Transaction = null; DateTime ADateEffective; Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { ALedgerTable LedgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; if (!batchSelected) { ADateEffective = (DateTime)requestParams["GlEffectiveDate"]; AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); AGiftBatchRow oldGiftBatch = MainDS.AGiftBatch[0]; TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref Transaction, ref LedgerTable, ALedgerNumber, ADateEffective); giftBatch = MainDS.AGiftBatch[1]; giftBatch.BankAccountCode = oldGiftBatch.BankAccountCode; giftBatch.BankCostCentre = oldGiftBatch.BankCostCentre; giftBatch.CurrencyCode = oldGiftBatch.CurrencyCode; giftBatch.ExchangeRateToBase = oldGiftBatch.ExchangeRateToBase; giftBatch.MethodOfPaymentCode = oldGiftBatch.MethodOfPaymentCode; giftBatch.HashTotal = 0; if (giftBatch.MethodOfPaymentCode.Length == 0) { giftBatch.SetMethodOfPaymentCodeNull(); } giftBatch.BankCostCentre = oldGiftBatch.BankCostCentre; giftBatch.GiftType = oldGiftBatch.GiftType; if (Function.Equals("AdjustGift")) { giftBatch.BatchDescription = Catalog.GetString("Gift Adjustment"); } else { giftBatch.BatchDescription = Catalog.GetString("Reverse Gift"); } } else { AGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = MainDS.AGiftBatch[0]; ADateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrive the existing batch total batchGiftTotal = giftBatch.BatchTotal; } if (Function.Equals("ReverseGiftBatch")) { AGiftAccess.LoadViaAGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); foreach (AGiftRow gift in MainDS.AGift.Rows) { AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, gift.GiftTransactionNumber, Transaction); } } else { AGiftAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction); if (Function.Equals("ReverseGiftDetail")) { AGiftDetailAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, AGiftDetailNumber, Transaction); } else { AGiftDetailAccess.LoadViaAGift(MainDS, ALedgerNumber, ABatchNumber, AGiftNumber, Transaction); } } //assuming new elements are added after these static borders int cycle = 0; MainDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); MainDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); do { foreach (DataRowView giftRow in MainDS.AGift.DefaultView) { AGiftRow oldGift = (AGiftRow)giftRow.Row; if ((oldGift.BatchNumber == ABatchNumber) && (oldGift.LedgerNumber == ALedgerNumber) && (Function.Equals("ReverseGiftBatch") || (oldGift.GiftTransactionNumber == AGiftNumber))) { AGiftRow gift = MainDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; gift.DateEntered = ADateEffective; gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LastDetailNumber = 0; MainDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in MainDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == ABatchNumber) && (oldGiftDetail.LedgerNumber == ALedgerNumber) && (!Function.Equals("ReverseGiftDetail") || (oldGiftDetail.DetailNumber == AGiftDetailNumber))) { if ((cycle == 0) && oldGiftDetail.ModifiedDetail) { AMessages.Add(new TVerificationResult( String.Format(Catalog.GetString("Cannot reverse or adjust Gift {0} with Detail {1} in Batch {2}"), oldGiftDetail.GiftTransactionNumber, oldGiftDetail.DetailNumber, oldGiftDetail.BatchNumber), String.Format(Catalog.GetString("It was already adjusted or reversed.")), TResultSeverity.Resv_Critical)); DBAccess.GDBAccessObj.RollbackTransaction(); return(false); } AGiftDetailRow giftDetail = MainDS.AGiftDetail.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGiftDetail, giftDetail); giftDetail.DetailNumber = ++gift.LastDetailNumber; giftDetail.LedgerNumber = gift.LedgerNumber; giftDetail.BatchNumber = giftBatch.BatchNumber; giftDetail.GiftTransactionNumber = gift.GiftTransactionNumber; //Identify the reversal source giftDetail.ModifiedDetailKey = "|" + oldGiftDetail.BatchNumber.ToString() + "|" + oldGiftDetail.GiftTransactionNumber.ToString() + "|" + oldGiftDetail.DetailNumber.ToString(); decimal signum = (cycle == 0) ? -1 : 1; giftDetail.GiftTransactionAmount = signum * oldGiftDetail.GiftTransactionAmount; batchGiftTotal += giftDetail.GiftTransactionAmount; giftDetail.GiftAmount = signum * oldGiftDetail.GiftAmount; giftDetail.GiftAmountIntl = signum * oldGiftDetail.GiftAmountIntl; if (TaxDeductiblePercentageEnabled) { giftDetail.TaxDeductibleAmount = signum * oldGiftDetail.TaxDeductibleAmount; giftDetail.TaxDeductibleAmountBase = signum * oldGiftDetail.TaxDeductibleAmountBase; giftDetail.TaxDeductibleAmountIntl = signum * oldGiftDetail.TaxDeductibleAmountIntl; giftDetail.NonDeductibleAmount = signum * oldGiftDetail.NonDeductibleAmount; giftDetail.NonDeductibleAmountBase = signum * oldGiftDetail.NonDeductibleAmountBase; giftDetail.NonDeductibleAmountIntl = signum * oldGiftDetail.NonDeductibleAmountIntl; } giftDetail.GiftCommentOne = (String)requestParams["ReversalCommentOne"]; giftDetail.GiftCommentTwo = (String)requestParams["ReversalCommentTwo"]; giftDetail.GiftCommentThree = (String)requestParams["ReversalCommentThree"]; giftDetail.CommentOneType = (String)requestParams["ReversalCommentOneType"]; giftDetail.CommentTwoType = (String)requestParams["ReversalCommentTwoType"]; giftDetail.CommentThreeType = (String)requestParams["ReversalCommentThreeType"]; // This is used to mark both as a Reverted giftDetails, except the adjusted (new) gift giftDetail.ModifiedDetail = (cycle == 0); oldGiftDetail.ModifiedDetail = (cycle == 0); MainDS.AGiftDetail.Rows.Add(giftDetail); } } } } cycle++; } while ((cycle < 2) && Function.Equals("AdjustGift")); //When reversing into a new or existing batch, set batch total if (!Function.Equals("AdjustGift")) { giftBatch.BatchTotal = batchGiftTotal; } // save everything at the end AGiftBatchAccess.SubmitChanges(MainDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(LedgerTable, Transaction); AGiftAccess.SubmitChanges(MainDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(MainDS.AGiftDetail, Transaction); MainDS.AGiftBatch.AcceptChanges(); DBAccess.GDBAccessObj.CommitTransaction(); return(true); } catch (Exception Exc) { TLogging.Log("An Exception occured while performing Gift Reverse/Adjust:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), Exc); } }
public static TSubmitChangesResult SaveData(string ATablename, ref TTypedDataTable ASubmitTable, out TVerificationResultCollection AVerificationResult, TDBTransaction AWriteTransaction) { AVerificationResult = null; // TODO: check write permissions string context = string.Format("SaveData {0}", SharedConstants.MODULE_ACCESS_MANAGER); if (ASubmitTable != null) { AVerificationResult = new TVerificationResultCollection(); try { if (ATablename == AAccountingPeriodTable.GetTableDBName()) { AAccountingPeriodAccess.SubmitChanges((AAccountingPeriodTable)ASubmitTable, AWriteTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.AccountingPeriodList.ToString()); } else if (ATablename == ACurrencyTable.GetTableDBName()) { ACurrencyAccess.SubmitChanges((ACurrencyTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions( string.Format("AND({0},{1})", SharedConstants.PETRAGROUP_FINANCE1, SharedConstants.PETRAMODULE_FINEXRATE), context); ADailyExchangeRateAccess.SubmitChanges((ADailyExchangeRateTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { // AlanP: I don't think this is used any more. There is a TDS Save method instead ACorporateExchangeRateAccess.SubmitChanges((ACorporateExchangeRateTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { ACurrencyLanguageAccess.SubmitChanges((ACurrencyLanguageTable)ASubmitTable, AWriteTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { AFeesPayableAccess.SubmitChanges((AFeesPayableTable)ASubmitTable, AWriteTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.FeesPayableList.ToString()); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { AFeesReceivableAccess.SubmitChanges((AFeesReceivableTable)ASubmitTable, AWriteTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.FeesReceivableList.ToString()); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Setup - please do not remove // The method is not required for changes made to the gift batch screens, which use a TDS AGiftBatchAccess.SubmitChanges((AGiftBatchTable)ASubmitTable, AWriteTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Setup - please do not remove // The method is not required for changes made to the journal screens, which use a TDS AJournalAccess.SubmitChanges((AJournalTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ARecurringJournalTable.GetTableDBName()) { // This method is called from Submit Recurring GL Batch form - please do not remove // The method is not required for changes made to the journal screens, which use a TDS ARecurringJournalAccess.SubmitChanges((ARecurringJournalTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Testing - please do not remove ALedgerAccess.SubmitChanges((ALedgerTable)ASubmitTable, AWriteTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { AAnalysisTypeAccess.SubmitChanges((AAnalysisTypeTable)ASubmitTable, AWriteTransaction); } else if (ATablename == ASuspenseAccountTable.GetTableDBName()) { ASuspenseAccountAccess.SubmitChanges((ASuspenseAccountTable)ASubmitTable, AWriteTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.SuspenseAccountList.ToString()); } else if (ATablename == PcAttendeeTable.GetTableDBName()) { PcAttendeeAccess.SubmitChanges((PcAttendeeTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PcConferenceTable.GetTableDBName()) { PcConferenceAccess.SubmitChanges((PcConferenceTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { PcConferenceCostAccess.SubmitChanges((PcConferenceCostTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { PcEarlyLateAccess.SubmitChanges((PcEarlyLateTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { PcSupplementAccess.SubmitChanges((PcSupplementTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { PcDiscountAccess.SubmitChanges((PcDiscountTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { ValidateInternationalPostalType(ref AVerificationResult, ASubmitTable); ValidateInternationalPostalTypeManual(ref AVerificationResult, ASubmitTable); if (TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult)) { PInternationalPostalTypeAccess.SubmitChanges((PInternationalPostalTypeTable)ASubmitTable, AWriteTransaction); } } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { PtApplicationTypeAccess.SubmitChanges((PtApplicationTypeTable)ASubmitTable, AWriteTransaction); // mark dependent lists for needing to be refreshed since there was a change in base list TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheablePersonTablesEnum.EventApplicationTypeList.ToString()); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheablePersonTablesEnum.FieldApplicationTypeList.ToString()); } else if (ATablename == PFormTable.GetTableDBName()) { PFormAccess.SubmitChanges((PFormTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { PFormalityAccess.SubmitChanges((PFormalityTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { PMailingAccess.SubmitChanges((PMailingTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { PPartnerGiftDestinationAccess.SubmitChanges((PPartnerGiftDestinationTable)ASubmitTable, AWriteTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { PmDocumentTypeAccess.SubmitChanges((PmDocumentTypeTable)ASubmitTable, AWriteTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { SGroupAccess.SubmitChanges((SGroupTable)ASubmitTable, AWriteTransaction); } else if (ATablename == SSystemDefaultsTable.GetTableDBName()) { SSystemDefaultsAccess.SubmitChanges((SSystemDefaultsTable)ASubmitTable, AWriteTransaction); } else if (ATablename == SSystemDefaultsGuiTable.GetTableDBName()) { SSystemDefaultsGuiAccess.SubmitChanges((SSystemDefaultsGuiTable)ASubmitTable, AWriteTransaction); } else { throw new EOPAppException("TCommonDataReader.SaveData: unknown table '" + ATablename + "'"); } } catch (Exception Exc) { AVerificationResult.Add( new TVerificationResult(null, "Cannot SubmitChanges:" + Environment.NewLine + Exc.Message, "UNDEFINED", TResultSeverity.Resv_Critical)); } } if ((AVerificationResult != null) && (AVerificationResult.Count > 0)) { // Downgrade TScreenVerificationResults to TVerificationResults in order to allow // Serialisation (needed for .NET Remoting). TVerificationResultCollection.DowngradeScreenVerificationResults(AVerificationResult); return(AVerificationResult.HasCriticalErrors ? TSubmitChangesResult.scrError : TSubmitChangesResult.scrOK); } return(TSubmitChangesResult.scrOK); }
private static GiftBatchTDS CreateGiftBatches(SortedList <DateTime, List <XmlNode> > AGiftsPerDate, int APeriodNumber) { GiftBatchTDS MainDS = new GiftBatchTDS(); ALedgerTable LedgerTable = null; TDBTransaction ReadTransaction = new TDBTransaction(); DBAccess.ReadTransaction(ref ReadTransaction, delegate { TDataBase db = ReadTransaction.DataBaseObj; // get a list of potential donors (all class FAMILY) string sqlGetFamilyPartnerKeys = "SELECT p_partner_key_n FROM PUB_p_family"; DataTable FamilyKeys = db.SelectDT(sqlGetFamilyPartnerKeys, "keys", ReadTransaction); // get a list of workers (all class FAMILY, with special type WORKER) string sqlGetWorkerPartnerKeys = "SELECT PUB_p_family.p_partner_key_n FROM PUB_p_family, PUB_p_partner_type WHERE PUB_p_partner_type.p_partner_key_n = PUB_p_family.p_partner_key_n AND p_type_code_c = 'WORKER'"; DataTable WorkerKeys = db.SelectDT(sqlGetWorkerPartnerKeys, "keys", ReadTransaction); // get a list of fields (all class UNIT, with unit type F) string sqlGetFieldPartnerKeys = String.Format( "SELECT U.p_partner_key_n FROM PUB_p_unit U WHERE u_unit_type_code_c = 'F' AND EXISTS (SELECT * FROM PUB_a_valid_ledger_number V WHERE V.a_ledger_number_i = {0} AND V.p_partner_key_n = U.p_partner_key_n)", FLedgerNumber); DataTable FieldKeys = db.SelectDT(sqlGetFieldPartnerKeys, "keys", ReadTransaction); // get a list of key ministries (all class UNIT, with unit type KEY-MIN), and their field ledger number and cost centre code string sqlGetKeyMinPartnerKeys = "SELECT u.p_partner_key_n, us.um_parent_unit_key_n, vl.a_cost_centre_code_c " + "FROM PUB_p_unit u, PUB_um_unit_structure us, PUB_a_valid_ledger_number vl " + "WHERE u.u_unit_type_code_c = 'KEY-MIN' " + "AND us.um_child_unit_key_n = u.p_partner_key_n " + "AND vl.p_partner_key_n = us.um_parent_unit_key_n " + "AND vl.a_ledger_number_i = " + FLedgerNumber.ToString(); DataTable KeyMinistries = db.SelectDT(sqlGetKeyMinPartnerKeys, "keys", ReadTransaction); LedgerTable = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, ReadTransaction); AAccountingPeriodRow AccountingPeriodRow = AAccountingPeriodAccess.LoadByPrimaryKey(FLedgerNumber, APeriodNumber, ReadTransaction)[0]; // create a gift batch for each day. // TODO: could create one batch per month, if there are not so many gifts (less than 100 per month) foreach (DateTime GlEffectiveDate in AGiftsPerDate.Keys) { if ((GlEffectiveDate.CompareTo(AccountingPeriodRow.PeriodStartDate) < 0) || (GlEffectiveDate.CompareTo(AccountingPeriodRow.PeriodEndDate) > 0)) { // only create gifts in that period continue; } AGiftBatchRow giftBatch = TGiftBatchFunctions.CreateANewGiftBatchRow(ref MainDS, ref ReadTransaction, ref LedgerTable, FLedgerNumber, GlEffectiveDate); TLogging.LogAtLevel(1, "create gift batch for " + GlEffectiveDate.ToShortDateString()); giftBatch.BatchDescription = "Benerator Batch for " + GlEffectiveDate.ToShortDateString(); giftBatch.BatchTotal = 0.0m; foreach (XmlNode RecordNode in AGiftsPerDate[GlEffectiveDate]) { AGiftRow gift = MainDS.AGift.NewRowTyped(); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; gift.DateEntered = GlEffectiveDate; // set donorKey int donorID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "donor")) % FamilyKeys.Rows.Count; gift.DonorKey = Convert.ToInt64(FamilyKeys.Rows[donorID].ItemArray[0]); // calculate gift detail information int countDetails = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "splitgift")); for (int counter = 1; counter <= countDetails; counter++) { AGiftDetailRow giftDetail = MainDS.AGiftDetail.NewRowTyped(); giftDetail.LedgerNumber = gift.LedgerNumber; giftDetail.BatchNumber = gift.BatchNumber; giftDetail.GiftTransactionNumber = gift.GiftTransactionNumber; giftDetail.MotivationGroupCode = "GIFT"; giftDetail.GiftTransactionAmount = Convert.ToDecimal(TXMLParser.GetAttribute(RecordNode, "amount_" + counter.ToString())); giftDetail.GiftAmount = giftDetail.GiftTransactionAmount; giftBatch.BatchTotal += giftDetail.GiftAmount; string motivation = TXMLParser.GetAttribute(RecordNode, "motivation_" + counter.ToString()); if (motivation == "SUPPORT") { if (WorkerKeys.Rows.Count == 0) { continue; } giftDetail.MotivationDetailCode = "SUPPORT"; int recipientID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_support_" + counter.ToString())) % WorkerKeys.Rows.Count; giftDetail.RecipientKey = Convert.ToInt64(WorkerKeys.Rows[recipientID].ItemArray[0]); giftDetail.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(giftDetail.RecipientKey, giftBatch.GlEffectiveDate); // ignore this gift detail, if there is no valid commitment period for the worker if (giftDetail.RecipientLedgerNumber == 0) { continue; } } else if (motivation == "FIELD") { if (FieldKeys.Rows.Count == 0) { continue; } giftDetail.MotivationDetailCode = "FIELD"; int recipientID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_field_" + counter.ToString())) % FieldKeys.Rows.Count; giftDetail.RecipientKey = Convert.ToInt64(FieldKeys.Rows[recipientID].ItemArray[0]); giftDetail.RecipientLedgerNumber = giftDetail.RecipientKey; giftDetail.CostCentreCode = (giftDetail.RecipientKey / 10000).ToString("0000"); } else if (motivation == "KEYMIN") { if (KeyMinistries.Rows.Count == 0) { continue; } giftDetail.MotivationDetailCode = "KEYMIN"; int recipientID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "recipient_keymin_" + counter.ToString())) % KeyMinistries.Rows.Count; giftDetail.RecipientKey = Convert.ToInt64(KeyMinistries.Rows[recipientID].ItemArray[0]); giftDetail.RecipientLedgerNumber = Convert.ToInt64(KeyMinistries.Rows[recipientID].ItemArray[1]); // TTransactionWebConnector.GetRecipientFundNumber(giftDetail.RecipientKey); giftDetail.CostCentreCode = KeyMinistries.Rows[recipientID].ItemArray[2].ToString(); // TTransactionWebConnector.IdentifyPartnerCostCentre(FLedgerNumber, giftDetail.RecipientLedgerNumber); } giftDetail.DetailNumber = gift.LastDetailNumber + 1; MainDS.AGiftDetail.Rows.Add(giftDetail); gift.LastDetailNumber = giftDetail.DetailNumber; } if (gift.LastDetailNumber > 0) { MainDS.AGift.Rows.Add(gift); giftBatch.LastGiftNumber = gift.GiftTransactionNumber; } if (giftBatch.LastGiftNumber >= MaxGiftsPerBatch) { break; } } if (TLogging.DebugLevel > 0) { TLogging.Log( GlEffectiveDate.ToShortDateString() + " " + giftBatch.LastGiftNumber.ToString()); } } }); // need to save the last gift batch number in a_ledger if (LedgerTable != null) { TDBTransaction WriteTransaction = new TDBTransaction(); bool SubmissionOk = false; DBAccess.WriteTransaction(ref WriteTransaction, ref SubmissionOk, delegate { ALedgerAccess.SubmitChanges(LedgerTable, WriteTransaction); SubmissionOk = true; }); if (!SubmissionOk) { TLogging.Log("An Exception occured during the creation of Gift Batches" + Environment.NewLine); } } return(MainDS); }
public static bool GiftRevertAdjust( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftDetailNumber, bool ABatchSelected, Int32 ANewBatchNumber, DateTime?ANewGLDateEffective, GiftAdjustmentFunctionEnum AFunction, bool ANoReceipt, Decimal ANewPct, out int AAdjustmentBatchNumber) { AAdjustmentBatchNumber = 0; int AdjustmentBatchNo = AAdjustmentBatchNumber; GiftBatchTDS GiftDS = new GiftBatchTDS(); decimal batchGiftTotal = 0; ANewBatchNumber = ABatchSelected ? ANewBatchNumber : 0; TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GiftRevertAdjust"); bool SubmissionOK = false; try { db.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { // load the original gifts and gift details AGiftAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction); AGiftDetailAccess.LoadViaAGiftBatch(GiftDS, ALedgerNumber, ABatchNumber, Transaction); ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; DateTime DateEffective; if (ANewGLDateEffective.HasValue) { DateEffective = ANewGLDateEffective.Value; } else { AGiftBatchTable OriginalGiftBatch = AGiftBatchAccess.LoadByPrimaryKey(ALedgerNumber, ABatchNumber, Transaction); DateEffective = OriginalGiftBatch[0].GlEffectiveDate; } // if we need to create a new gift batch if (!ABatchSelected) { giftBatch = CreateNewGiftBatch( ALedgerNumber, ABatchNumber, DateEffective, AFunction, ref GiftDS, ref ledgerTable, Transaction); } else // using an existing gift batch { AGiftBatchAccess.LoadByPrimaryKey(GiftDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = GiftDS.AGiftBatch[0]; DateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrieve the existing batch total batchGiftTotal = giftBatch.BatchTotal; } AdjustmentBatchNo = giftBatch.BatchNumber; //assuming new elements are added after these static borders GiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); GiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView giftRow in GiftDS.AGift.DefaultView) { int cycle = 0; // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed) do { AGiftRow oldGift = (AGiftRow)giftRow.Row; if (oldGift.RowState != DataRowState.Added) { AGiftRow gift = GiftDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; // keep the same DateEntered as in the original gift if it is in the same period as the batch if ((gift.DateEntered.Year != DateEffective.Year) || (gift.DateEntered.Month != DateEffective.Month)) { gift.DateEntered = DateEffective; } gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LinkToPreviousGift = (cycle != 0); gift.LastDetailNumber = 0; gift.FirstTimeGift = false; // do not print a receipt for reversed gifts if (cycle == 0) { gift.ReceiptPrinted = true; gift.PrintReceipt = false; } else { gift.ReceiptPrinted = false; gift.PrintReceipt = !ANoReceipt; } GiftDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in GiftDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; // if gift detail belongs to gift if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == oldGift.BatchNumber) && (AFunction != GiftAdjustmentFunctionEnum.ReverseGiftDetail) || (oldGiftDetail.DetailNumber == AGiftDetailNumber)) { AddDuplicateGiftDetailToGift(ref GiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction, AFunction, ANewPct); batchGiftTotal += ((cycle == 0) ? 0 : oldGiftDetail.GiftTransactionAmount); // original gift also gets marked as a reversal oldGiftDetail.ModifiedDetail = true; } } } cycle++; } while ((cycle < 2) && (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGift) || AFunction.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) || AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))); } //When reversing into a new or existing batch, set batch total giftBatch.BatchTotal = batchGiftTotal; // save everything at the end AGiftBatchAccess.SubmitChanges(GiftDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(ledgerTable, Transaction); AGiftAccess.SubmitChanges(GiftDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(GiftDS.AGiftDetail, Transaction); GiftDS.AGiftBatch.AcceptChanges(); SubmissionOK = true; }); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex); } AAdjustmentBatchNumber = AdjustmentBatchNo; db.CloseDBConnection(); return(SubmissionOK); }
public static TSubmitChangesResult SaveData(string ATablename, ref TTypedDataTable ASubmitTable, out TVerificationResultCollection AVerificationResult) { TDBTransaction SubmitChangesTransaction = null; bool SubmissionOK = false; TTypedDataTable SubmitTable = ASubmitTable; TVerificationResultCollection VerificationResult = null; // TODO: check write permissions if (ASubmitTable != null) { VerificationResult = new TVerificationResultCollection(); DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction, ref SubmissionOK, delegate { try { if (ATablename == AAccountingPeriodTable.GetTableDBName()) { AAccountingPeriodAccess.SubmitChanges((AAccountingPeriodTable)SubmitTable, SubmitChangesTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.AccountingPeriodList.ToString()); } else if (ATablename == ACurrencyTable.GetTableDBName()) { ACurrencyAccess.SubmitChanges((ACurrencyTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { ADailyExchangeRateAccess.SubmitChanges((ADailyExchangeRateTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { ACorporateExchangeRateAccess.SubmitChanges((ACorporateExchangeRateTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { ACurrencyLanguageAccess.SubmitChanges((ACurrencyLanguageTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { AFeesPayableAccess.SubmitChanges((AFeesPayableTable)SubmitTable, SubmitChangesTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.FeesPayableList.ToString()); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { AFeesReceivableAccess.SubmitChanges((AFeesReceivableTable)SubmitTable, SubmitChangesTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.FeesReceivableList.ToString()); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Setup - please do not remove // The method is not required for changes made to the gift batch screens, which use a TDS AGiftBatchAccess.SubmitChanges((AGiftBatchTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Setup - please do not remove // The method is not required for changes made to the journal screens, which use a TDS AJournalAccess.SubmitChanges((AJournalTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ARecurringJournalTable.GetTableDBName()) { // This method is called from Submit Recurring GL Batch form - please do not remove // The method is not required for changes made to the journal screens, which use a TDS ARecurringJournalAccess.SubmitChanges((ARecurringJournalTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { // This method is called from ADailyExchangeRate Testing - please do not remove ALedgerAccess.SubmitChanges((ALedgerTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { AAnalysisTypeAccess.SubmitChanges((AAnalysisTypeTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == ASuspenseAccountTable.GetTableDBName()) { ASuspenseAccountAccess.SubmitChanges((ASuspenseAccountTable)SubmitTable, SubmitChangesTransaction); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheableFinanceTablesEnum.SuspenseAccountList.ToString()); } else if (ATablename == PcAttendeeTable.GetTableDBName()) { PcAttendeeAccess.SubmitChanges((PcAttendeeTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PcConferenceTable.GetTableDBName()) { PcConferenceAccess.SubmitChanges((PcConferenceTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { PcConferenceCostAccess.SubmitChanges((PcConferenceCostTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { PcEarlyLateAccess.SubmitChanges((PcEarlyLateTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { PcSupplementAccess.SubmitChanges((PcSupplementTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { PcDiscountAccess.SubmitChanges((PcDiscountTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { ValidateInternationalPostalType(ref VerificationResult, SubmitTable); ValidateInternationalPostalTypeManual(ref VerificationResult, SubmitTable); if (TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { PInternationalPostalTypeAccess.SubmitChanges((PInternationalPostalTypeTable)SubmitTable, SubmitChangesTransaction); } } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { PtApplicationTypeAccess.SubmitChanges((PtApplicationTypeTable)SubmitTable, SubmitChangesTransaction); // mark dependent lists for needing to be refreshed since there was a change in base list TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheablePersonTablesEnum.EventApplicationTypeList.ToString()); TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing( TCacheablePersonTablesEnum.FieldApplicationTypeList.ToString()); } else if (ATablename == PFormTable.GetTableDBName()) { PFormAccess.SubmitChanges((PFormTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { PFormalityAccess.SubmitChanges((PFormalityTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { PMailingAccess.SubmitChanges((PMailingTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { PPartnerGiftDestinationAccess.SubmitChanges((PPartnerGiftDestinationTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { PmDocumentTypeAccess.SubmitChanges((PmDocumentTypeTable)SubmitTable, SubmitChangesTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { SGroupAccess.SubmitChanges((SGroupTable)SubmitTable, SubmitChangesTransaction); } else { throw new EOPAppException("TCommonDataReader.SaveData: unknown table '" + ATablename + "'"); } SubmissionOK = true; } catch (Exception Exc) { VerificationResult.Add( new TVerificationResult(null, "Cannot SubmitChanges:" + Environment.NewLine + Exc.Message, "UNDEFINED", TResultSeverity.Resv_Critical)); } }); } ASubmitTable = SubmitTable; AVerificationResult = VerificationResult; if ((AVerificationResult != null) && (AVerificationResult.Count > 0)) { // Downgrade TScreenVerificationResults to TVerificationResults in order to allow // Serialisation (needed for .NET Remoting). TVerificationResultCollection.DowngradeScreenVerificationResults(AVerificationResult); return(AVerificationResult.HasCriticalErrors ? TSubmitChangesResult.scrError : TSubmitChangesResult.scrOK); } return(TSubmitChangesResult.scrOK); }
public static bool GiftRevertAdjust(Hashtable requestParams, out int AAdjustmentBatchNumber, GiftBatchTDS AGiftDS) { AAdjustmentBatchNumber = 0; int AdjustmentBatchNo = AAdjustmentBatchNumber; if ((AGiftDS == null) || (AGiftDS.AGiftDetail == null) || (AGiftDS.AGiftDetail.Rows.Count == 0)) { TLogging.Log("Empty dataset sent to GiftRevertAdjust"); return(false); } Int32 ALedgerNumber = (Int32)requestParams["ALedgerNumber"]; Boolean BatchSelected = (Boolean)requestParams["NewBatchSelected"]; GiftAdjustmentFunctionEnum Function = (GiftAdjustmentFunctionEnum)requestParams["Function"]; Int32 GiftDetailNumber = (Int32)requestParams["GiftDetailNumber"]; bool NoReceipt = (Boolean)requestParams["NoReceipt"]; DateTime DateEffective; decimal batchGiftTotal = 0; Int32 ANewBatchNumber = (BatchSelected ? (Int32)requestParams["NewBatchNumber"] : 0); TDBTransaction Transaction = null; bool SubmissionOK = false; try { DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { ALedgerTable ledgerTable = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, Transaction); AGiftBatchRow giftBatch; // if we need to create a new gift batch if (!BatchSelected) { giftBatch = CreateNewGiftBatch(requestParams, ref AGiftDS, out DateEffective, ref ledgerTable, Transaction); } else // using an existing gift batch { AGiftBatchAccess.LoadByPrimaryKey(AGiftDS, ALedgerNumber, ANewBatchNumber, Transaction); giftBatch = AGiftDS.AGiftBatch[0]; DateEffective = giftBatch.GlEffectiveDate; //If into an existing batch, then retrive the existing batch total batchGiftTotal = giftBatch.BatchTotal; } AdjustmentBatchNo = giftBatch.BatchNumber; //assuming new elements are added after these static borders AGiftDS.AGift.DefaultView.Sort = string.Format("{0}, {1}", AGiftTable.GetBatchNumberDBName(), AGiftTable.GetGiftTransactionNumberDBName()); AGiftDS.AGiftDetail.DefaultView.Sort = string.Format("{0}, {1}, {2}", AGiftDetailTable.GetBatchNumberDBName(), AGiftDetailTable.GetGiftTransactionNumberDBName(), AGiftDetailTable.GetDetailNumberDBName()); foreach (DataRowView giftRow in AGiftDS.AGift.DefaultView) { int cycle = 0; // first cycle creates gift reversal; second cycle creates new adjusted gift (if needed) do { AGiftRow oldGift = (AGiftRow)giftRow.Row; if (oldGift.RowState != DataRowState.Added) { AGiftRow gift = AGiftDS.AGift.NewRowTyped(true); DataUtilities.CopyAllColumnValuesWithoutPK(oldGift, gift); gift.LedgerNumber = giftBatch.LedgerNumber; gift.BatchNumber = giftBatch.BatchNumber; gift.DateEntered = DateEffective; gift.GiftTransactionNumber = giftBatch.LastGiftNumber + 1; giftBatch.LastGiftNumber++; gift.LinkToPreviousGift = (cycle != 0); gift.LastDetailNumber = 0; // do not print a receipt for reversed gifts if (cycle == 0) { gift.ReceiptPrinted = true; gift.PrintReceipt = false; } else { gift.ReceiptPrinted = false; gift.PrintReceipt = !NoReceipt; } AGiftDS.AGift.Rows.Add(gift); foreach (DataRowView giftDetailRow in AGiftDS.AGiftDetail.DefaultView) { AGiftDetailRow oldGiftDetail = (AGiftDetailRow)giftDetailRow.Row; // if gift detail belongs to gift if ((oldGiftDetail.GiftTransactionNumber == oldGift.GiftTransactionNumber) && (oldGiftDetail.BatchNumber == oldGift.BatchNumber) && (!Function.Equals(GiftAdjustmentFunctionEnum.ReverseGiftDetail) || (oldGiftDetail.DetailNumber == GiftDetailNumber))) { AddDuplicateGiftDetailToGift(ref AGiftDS, ref gift, oldGiftDetail, cycle == 0, Transaction, requestParams); batchGiftTotal += oldGiftDetail.GiftTransactionAmount * ((cycle == 0) ? -1 : 1); // original gift also gets marked as a reversal oldGiftDetail.ModifiedDetail = true; } } } cycle++; } while ((cycle < 2) && (Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift) || Function.Equals(GiftAdjustmentFunctionEnum.FieldAdjust) || Function.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust))); } //When reversing into a new or existing batch, set batch total if (!Function.Equals(GiftAdjustmentFunctionEnum.AdjustGift)) { giftBatch.BatchTotal = batchGiftTotal; } // save everything at the end AGiftBatchAccess.SubmitChanges(AGiftDS.AGiftBatch, Transaction); ALedgerAccess.SubmitChanges(ledgerTable, Transaction); AGiftAccess.SubmitChanges(AGiftDS.AGift, Transaction); AGiftDetailAccess.SubmitChanges(AGiftDS.AGiftDetail, Transaction); AGiftDS.AGiftBatch.AcceptChanges(); SubmissionOK = true; }); } catch (Exception ex) { TLogging.LogException(ex, Utilities.GetMethodSignature()); throw new EOPAppException(Catalog.GetString("Gift Reverse/Adjust failed."), ex); } AAdjustmentBatchNumber = AdjustmentBatchNo; return(SubmissionOK); }