public static bool GetGiftsForFieldChangeAdjustment(ref GiftBatchTDS AGiftDS, Int32 ALedgerNumber, Int64 ARecipientKey, DateTime AStartDate, DateTime AEndDate, Int64 AOldField, out TVerificationResultCollection AMessages) { TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GetGiftsForFieldChangeAdjustment"); GiftBatchTDS MainDS = new GiftBatchTDS(); AMessages = new TVerificationResultCollection(); db.ReadTransaction( ref Transaction, delegate { string SqlStmt = TDataBase.ReadSqlFile("Gift.GetGiftsToAdjustField.sql"); List <OdbcParameter> parameters = new List <OdbcParameter>(); OdbcParameter param = new OdbcParameter("LedgerNumber", OdbcType.Int); param.Value = ALedgerNumber; parameters.Add(param); param = new OdbcParameter("StartDate", OdbcType.Date); param.Value = AStartDate; parameters.Add(param); param = new OdbcParameter("EndDate", OdbcType.Date); param.Value = AEndDate; parameters.Add(param); param = new OdbcParameter("RecipientKey", OdbcType.BigInt); param.Value = ARecipientKey; parameters.Add(param); param = new OdbcParameter("OldField", OdbcType.BigInt); param.Value = AOldField; parameters.Add(param); db.Select(MainDS, SqlStmt, MainDS.AGiftDetail.TableName, Transaction, parameters.ToArray()); // get additional data foreach (GiftBatchTDSAGiftDetailRow Row in MainDS.AGiftDetail.Rows) { AGiftBatchAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Transaction); AGiftRow GiftRow = AGiftAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Row.GiftTransactionNumber, Transaction); Row.DateEntered = GiftRow.DateEntered; Row.DonorKey = GiftRow.DonorKey; Row.IchNumber = 0; Row.DonorName = PPartnerAccess.LoadByPrimaryKey(Row.DonorKey, Transaction)[0].PartnerShortName; } }); AGiftDS = MainDS; db.CloseDBConnection(); return(CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages)); }
/// create a new gift batch using some of the details of an existing gift batch private static AGiftBatchRow CreateNewGiftBatch( Int32 ALedgerNumber, Int32 ABatchNumber, DateTime ADateEffective, GiftAdjustmentFunctionEnum AFunction, ref GiftBatchTDS AMainDS, ref ALedgerTable ALedgerTable, TDBTransaction ATransaction) { AGiftBatchRow ReturnValue; AGiftBatchAccess.LoadByPrimaryKey(AMainDS, ALedgerNumber, ABatchNumber, ATransaction); AGiftBatchRow oldGiftBatch = AMainDS.AGiftBatch[0]; TGiftBatchFunctions.CreateANewGiftBatchRow(ref AMainDS, ref ATransaction, ref ALedgerTable, ALedgerNumber, ADateEffective); ReturnValue = AMainDS.AGiftBatch[1]; ReturnValue.BankAccountCode = oldGiftBatch.BankAccountCode; ReturnValue.BankCostCentre = oldGiftBatch.BankCostCentre; ReturnValue.CurrencyCode = oldGiftBatch.CurrencyCode; ReturnValue.ExchangeRateToBase = oldGiftBatch.ExchangeRateToBase; ReturnValue.MethodOfPaymentCode = oldGiftBatch.MethodOfPaymentCode; ReturnValue.HashTotal = 0; if (ReturnValue.MethodOfPaymentCode.Length == 0) { ReturnValue.SetMethodOfPaymentCodeNull(); } ReturnValue.BankCostCentre = oldGiftBatch.BankCostCentre; ReturnValue.GiftType = oldGiftBatch.GiftType; if (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGift)) { ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment"); } else if (AFunction.Equals(GiftAdjustmentFunctionEnum.AdjustGiftBatch)) { ReturnValue.BatchDescription = Catalog.GetString("Gift Batch Adjustment"); } else if (AFunction.Equals(GiftAdjustmentFunctionEnum.FieldAdjust)) { ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment (Field Change)"); } else if (AFunction.Equals(GiftAdjustmentFunctionEnum.TaxDeductiblePctAdjust)) { ReturnValue.BatchDescription = Catalog.GetString("Gift Adjustment (Tax Deductible Pct Change)"); } else { ReturnValue.BatchDescription = Catalog.GetString("Reverse Gift"); } return(ReturnValue); }
public void UpdateRecord() { TDBTransaction ReadTransaction = new TDBTransaction(); GiftBatchTDS MainDS = new GiftBatchTDS(); TDataBase db = DBAccess.Connect("test"); db.ReadTransaction(ref ReadTransaction, delegate { ALedgerAccess.LoadAll(MainDS, ReadTransaction); }); ReadTransaction.Rollback(); MainDS.ALedger[0].LastGiftBatchNumber++; AGiftBatchRow batch = MainDS.AGiftBatch.NewRowTyped(); batch.LedgerNumber = MainDS.ALedger[0].LedgerNumber; batch.BatchNumber = MainDS.ALedger[0].LastGiftBatchNumber; batch.BankAccountCode = "6000"; batch.BatchYear = 0; batch.BatchPeriod = 1; batch.CurrencyCode = "EUR"; batch.BatchDescription = "test"; batch.BankCostCentre = (MainDS.ALedger[0].LedgerNumber * 100).ToString("0000"); batch.LastGiftNumber = 0; batch.HashTotal = 83; MainDS.AGiftBatch.Rows.Add(batch); GiftBatchTDSAccess.SubmitChanges(MainDS); MainDS.AcceptChanges(); MainDS.AGiftBatch[0].BatchDescription = "test2"; GiftBatchTDSAccess.SubmitChanges(MainDS); TDBTransaction transaction = new TDBTransaction(); AGiftBatchTable batches = null; db.ReadTransaction( ref transaction, delegate { batches = AGiftBatchAccess.LoadByPrimaryKey(batch.LedgerNumber, batch.BatchNumber, transaction); }); // some problems with sqlite and datagrid Assert.AreEqual(typeof(decimal), batches[0][AGiftBatchTable.ColumnHashTotalId].GetType(), "type decimal"); Assert.AreEqual(83.0m, batches[0].HashTotal, "gift batch hashtotal does not equal"); }
public static bool GetGiftsForTaxDeductiblePctAdjustment(ref GiftBatchTDS AGiftDS, Int64 ARecipientKey, DateTime ADateFrom, decimal ANewPct, out TVerificationResultCollection AMessages) { TDBTransaction Transaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GetGiftsForTaxDeductiblePctAdjustment"); GiftBatchTDS MainDS = new GiftBatchTDS(); AMessages = new TVerificationResultCollection(); db.ReadTransaction(ref Transaction, delegate { string Query = "SELECT a_gift_detail.*" + " FROM a_gift_detail, a_gift_batch" + " WHERE a_gift_detail.p_recipient_key_n = " + ARecipientKey + " AND a_gift_detail.a_tax_deductible_pct_n <> " + ANewPct + " AND a_gift_detail.a_modified_detail_l <> true" + " AND a_gift_detail.a_tax_deductible_l = true" + " AND a_gift_batch.a_ledger_number_i = a_gift_detail.a_ledger_number_i" + " AND a_gift_batch.a_batch_number_i = a_gift_detail.a_batch_number_i" + " AND a_gift_batch.a_ledger_number_i = a_gift_detail.a_ledger_number_i" + " AND a_gift_batch.a_batch_status_c = 'Posted' " + " AND a_gift_batch.a_gl_effective_date_d >= '" + ADateFrom.ToString("yyyy-MM-dd") + "'"; db.Select(MainDS, Query, MainDS.AGiftDetail.TableName, Transaction); // get additional data foreach (GiftBatchTDSAGiftDetailRow Row in MainDS.AGiftDetail.Rows) { AGiftBatchAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Transaction); AGiftRow GiftRow = AGiftAccess.LoadByPrimaryKey(MainDS, Row.LedgerNumber, Row.BatchNumber, Row.GiftTransactionNumber, Transaction); Row.DateEntered = GiftRow.DateEntered; Row.DonorKey = GiftRow.DonorKey; Row.DonorName = PPartnerAccess.LoadByPrimaryKey(Row.DonorKey, Transaction)[0].PartnerShortName; } }); AGiftDS = MainDS; return(TAdjustmentWebConnector.CheckGiftsNotPreviouslyReversed(AGiftDS, out AMessages)); }
/// <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); }
public static Int32 FieldChangeAdjustment(Int32 ALedgerNumber, Int64 ARecipientKey, DateTime AStartDate, DateTime AEndDate, Int64 AOldField, DateTime ADateCorrection, bool AWithReceipt) { TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted); GiftBatchTDS oldGiftDS = new GiftBatchTDS(); try { // find all gifts that need reversing. // criteria: // posted gift batches only // no adjusted/reversed gifts // date of gift batch in specified date range // recipient field is the old field string SqlStmt = TDataBase.ReadSqlFile("Gift.GetGiftsToReverse.sql"); List <OdbcParameter> parameters = new List <OdbcParameter>(); OdbcParameter param = new OdbcParameter("LedgerNumber", OdbcType.Int); param.Value = ALedgerNumber; parameters.Add(param); param = new OdbcParameter("StartDate", OdbcType.Date); param.Value = AStartDate; parameters.Add(param); param = new OdbcParameter("EndDate", OdbcType.Date); param.Value = AEndDate; parameters.Add(param); param = new OdbcParameter("RecipientKey", OdbcType.BigInt); param.Value = ARecipientKey; parameters.Add(param); param = new OdbcParameter("OldField", OdbcType.BigInt); param.Value = AOldField; parameters.Add(param); DBAccess.GDBAccessObj.Select(oldGiftDS, SqlStmt, oldGiftDS.AGiftDetail.TableName, Transaction, parameters.ToArray()); // load the gift and the gift batch records if they have not been loaded yet foreach (AGiftDetailRow giftdetail in oldGiftDS.AGiftDetail.Rows) { oldGiftDS.AGift.DefaultView.RowFilter = String.Format("{0} = {1} and {2} = {3}", AGiftTable.GetBatchNumberDBName(), giftdetail.BatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), giftdetail.GiftTransactionNumber); if (oldGiftDS.AGift.DefaultView.Count == 0) { AGiftTable tempGiftTable = AGiftAccess.LoadByPrimaryKey(giftdetail.LedgerNumber, giftdetail.BatchNumber, giftdetail.GiftTransactionNumber, Transaction); oldGiftDS.AGift.Merge(tempGiftTable); } oldGiftDS.AGiftBatch.DefaultView.RowFilter = String.Format("{0} = {1}", AGiftTable.GetBatchNumberDBName(), giftdetail.BatchNumber); if (oldGiftDS.AGiftBatch.DefaultView.Count == 0) { AGiftBatchTable tempGiftBatchTable = AGiftBatchAccess.LoadByPrimaryKey(giftdetail.LedgerNumber, giftdetail.BatchNumber, Transaction); oldGiftDS.AGiftBatch.Merge(tempGiftBatchTable); } } DBAccess.GDBAccessObj.RollbackTransaction(); } catch (Exception) { DBAccess.GDBAccessObj.RollbackTransaction(); throw; } // we need to create a gift batch for each set of gifts with the same Currency, BankAccountCode, BankCostCentre, and Gift Type SortedList <string, GiftBatchTDS> NewGiftBatches = new SortedList <string, GiftBatchTDS>(); foreach (GiftBatchTDSAGiftDetailRow oldGiftDetail in oldGiftDS.AGiftDetail.Rows) { // get the gift batch row for this detail oldGiftDS.AGiftBatch.DefaultView.RowFilter = String.Format("{0} = {1}", AGiftTable.GetBatchNumberDBName(), oldGiftDetail.BatchNumber); AGiftBatchRow oldGiftBatch = (AGiftBatchRow)oldGiftDS.AGiftBatch.DefaultView[0].Row; GiftBatchTDS GiftDS = CreateNewGiftBatch(NewGiftBatches, oldGiftBatch, ADateCorrection); AGiftBatchRow giftbatchRow = GiftDS.AGiftBatch[0]; // get the gift row for this detail DataView v = oldGiftDS.AGift.DefaultView; v.RowFilter = String.Format("{0} = {1} and {2} = {3}", AGiftTable.GetBatchNumberDBName(), oldGiftDetail.BatchNumber, AGiftTable.GetGiftTransactionNumberDBName(), oldGiftDetail.GiftTransactionNumber); AGiftRow oldGift = (AGiftRow)v[0].Row; AGiftRow gift = GiftDS.AGift.NewRowTyped(); gift.LedgerNumber = giftbatchRow.LedgerNumber; gift.BatchNumber = giftbatchRow.BatchNumber; gift.GiftTransactionNumber = giftbatchRow.LastGiftNumber + 1; gift.DonorKey = oldGift.DonorKey; gift.DateEntered = ADateCorrection; giftbatchRow.LastGiftNumber++; GiftDS.AGift.Rows.Add(gift); if (!AWithReceipt) { gift.ReceiptLetterCode = "NO*RECET"; } // reverse the original gift GiftBatchTDSAGiftDetailRow detail = GiftDS.AGiftDetail.NewRowTyped(); DataUtilities.CopyAllColumnValues(oldGiftDetail, detail); detail.LedgerNumber = gift.LedgerNumber; detail.BatchNumber = gift.BatchNumber; detail.GiftTransactionNumber = gift.GiftTransactionNumber; detail.DetailNumber = gift.LastDetailNumber + 1; detail.GiftAmount = detail.GiftAmount * -1; detail.GiftAmountIntl = detail.GiftAmountIntl * -1; detail.GiftTransactionAmount = detail.GiftTransactionAmount * -1; gift.LastDetailNumber++; GiftDS.AGiftDetail.Rows.Add(detail); // create the detail for the corrected gift to the new field detail = GiftDS.AGiftDetail.NewRowTyped(); DataUtilities.CopyAllColumnValues(oldGiftDetail, detail); detail.LedgerNumber = gift.LedgerNumber; detail.BatchNumber = gift.BatchNumber; detail.GiftTransactionNumber = gift.GiftTransactionNumber; detail.DetailNumber = gift.LastDetailNumber + 1; detail.GiftCommentOne = String.Format(Catalog.GetString("posted on {0}"), oldGiftBatch.GlEffectiveDate.ToShortDateString()); gift.LastDetailNumber++; // TODO: calculate costcentre code from current commitment; this currently is done only at time of posting // detail.RecipientLedgerNumber = oldGiftDetail.RecipientLedgerNumber; // detail.CostCentreCode = oldGiftDetail.CostCentreCode; GiftDS.AGiftDetail.Rows.Add(detail); // TODO: how to make sure that the gl transaction is marked as System generated? avoid display on HOSA? // mark original gift detail as modified oldGiftDetail.ModifiedDetail = true; } TVerificationResultCollection VerificationResult; TSubmitChangesResult result = TSubmitChangesResult.scrOK; for (Int32 batchCounter = 0; batchCounter < NewGiftBatches.Count; batchCounter++) { if (result == TSubmitChangesResult.scrOK) { GiftBatchTDS GiftDS = NewGiftBatches.Values[batchCounter]; result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref GiftDS, out VerificationResult); } } if (result == TSubmitChangesResult.scrOK) { result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref oldGiftDS, out VerificationResult); if ((result == TSubmitChangesResult.scrOK) && (NewGiftBatches.Count > 0)) { return(NewGiftBatches.Values[0].AGiftBatch[0].BatchNumber); } } return(-1); }
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 void GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable, TDBTransaction AReadTransaction) { AResultTable = null; string context = string.Format("GetData {0}", SharedConstants.MODULE_ACCESS_MANAGER); // check access permissions for the current user TModuleAccessManager.CheckUserPermissionsForTable(ATablename, TTablePermissionEnum.eCanRead); // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { AResultTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { AResultTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { AResultTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { AResultTable = ACurrencyAccess.LoadAll(AReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { AResultTable = ADailyExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { AResultTable = ACorporateExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { AResultTable = ACurrencyLanguageAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { AResultTable = AFeesPayableAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { AResultTable = AFeesReceivableAccess.LoadAll(AReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { AResultTable = AAnalysisTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { AResultTable = AGiftBatchAccess.LoadAll(AReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { AResultTable = AJournalAccess.LoadAll(AReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { AResultTable = ALedgerAccess.LoadAll(AReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { AResultTable = MExtractMasterAccess.LoadAll(AReadTransaction); } else { AResultTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { AResultTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { AResultTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { AResultTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { AResultTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { AResultTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { AResultTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PCountryTable.GetTableDBName()) { AResultTable = PCountryAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormTable.GetTableDBName()) { string[] columns = TTypedDataTable.GetColumnStringList(PFormTable.TableId); StringCollection fieldList = new StringCollection(); for (int i = 0; i < columns.Length; i++) { // Do not load the template document - we don't display it and it is big! if (columns[i] != PFormTable.GetTemplateDocumentDBName()) { fieldList.Add(columns[i]); } } AResultTable = PFormAccess.LoadAll(fieldList, AReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { AResultTable = PInternationalPostalTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { AResultTable = PtApplicationTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { AResultTable = PFormalityAccess.LoadAll(AReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { AResultTable = PMailingAccess.LoadAll(AReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { AResultTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { AResultTable = PmDocumentTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SGroupAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SSystemDefaultsAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsGuiTable.GetTableDBName()) { AResultTable = SSystemDefaultsGuiAccess.LoadAll(AReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } // Accept row changes here so that the Client gets 'unmodified' rows AResultTable.AcceptChanges(); }
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); }
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); }
/// <summary> /// get more details of the last gift of the partner /// </summary> /// <param name="APartnerKey"></param> /// <param name="ALastGiftDate"></param> /// <param name="ALastGiftAmount"></param> /// <param name="ALastGiftGivenToPartnerKey"></param> /// <param name="ALastGiftRecipientLedger"></param> /// <param name="ALastGiftCurrencyCode"></param> /// <param name="ALastGiftDisplayFormat"></param> /// <param name="ALastGiftGivenToShortName"></param> /// <param name="ALastGiftRecipientLedgerShortName"></param> /// <param name="ARestrictedOrConfidentialGiftAccessDenied"></param> /// <returns></returns> public static Boolean GetLastGiftDetails(Int64 APartnerKey, out DateTime ALastGiftDate, out decimal ALastGiftAmount, out Int64 ALastGiftGivenToPartnerKey, out Int64 ALastGiftRecipientLedger, out String ALastGiftCurrencyCode, out String ALastGiftDisplayFormat, out String ALastGiftGivenToShortName, out String ALastGiftRecipientLedgerShortName, out Boolean ARestrictedOrConfidentialGiftAccessDenied) { DataSet LastGiftDS; AGiftDetailTable GiftDetailDT; SGroupGiftTable GroupGiftDT; SUserGroupTable UserGroupDT; AGiftRow GiftDR; AGiftBatchRow GiftBatchDR; AGiftDetailRow GiftDetailDR; ACurrencyRow CurrencyDR; Int16 Counter; Boolean AccessToGift = false; DataRow[] FoundUserGroups; ALastGiftAmount = 0; ALastGiftCurrencyCode = ""; ALastGiftDisplayFormat = ""; ALastGiftDate = DateTime.MinValue; ALastGiftGivenToPartnerKey = 0; ALastGiftGivenToShortName = ""; ALastGiftRecipientLedger = 0; ALastGiftRecipientLedgerShortName = ""; ARestrictedOrConfidentialGiftAccessDenied = false; DateTime tmpLastGiftDate = ALastGiftDate; decimal tmpLastGiftAmount = ALastGiftAmount; Int64 tmpLastGiftGivenToPartnerKey = ALastGiftGivenToPartnerKey; Int64 tmpLastGiftRecipientLedger = ALastGiftRecipientLedger; String tmpLastGiftCurrencyCode = ALastGiftCurrencyCode; String tmpLastGiftDisplayFormat = ALastGiftDisplayFormat; String tmpLastGiftGivenToShortName = ALastGiftGivenToShortName; String tmpLastGiftRecipientLedgerShortName = ALastGiftRecipientLedgerShortName; Boolean tmpRestrictedOrConfidentialGiftAccessDenied = ARestrictedOrConfidentialGiftAccessDenied; if ((!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapINQUIRE, AGiftTable.GetTableDBName()))) { // User hasn't got access to a_gift Table in the DB return(false); } // Set up temp DataSet LastGiftDS = new DataSet("LastGiftDetails"); LastGiftDS.Tables.Add(new AGiftTable()); LastGiftDS.Tables.Add(new AGiftBatchTable()); LastGiftDS.Tables.Add(new AGiftDetailTable()); LastGiftDS.Tables.Add(new ACurrencyTable()); LastGiftDS.Tables.Add(new PPartnerTable()); TDBTransaction Transaction = null; bool SubmissionOK = true; // Important: The IsolationLevel here needs to correspond with the IsolationLevel in the // Ict.Petra.Server.MPartner.Partner.UIConnectors.TPartnerEditUIConnector.LoadData Method // as otherwise the attempt of taking-out of a DB Transaction here will lead to Bug #4167! DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK, delegate { try { try { AGiftAccess.LoadViaPPartner(LastGiftDS, APartnerKey, null, Transaction, StringHelper.InitStrArr(new String[] { "ORDER BY", AGiftTable.GetDateEnteredDBName() + " DESC" }), 0, 1); } catch (ESecurityDBTableAccessDeniedException) { // User hasn't got access to a_gift Table in the DB return; } catch (Exception ex) { throw ex; } if (LastGiftDS.Tables[AGiftTable.GetTableName()].Rows.Count == 0) { // Partner hasn't given any Gift so far return; } // Get the last gift GiftDR = ((AGiftTable)LastGiftDS.Tables[AGiftTable.GetTableName()])[0]; if (GiftDR.Restricted) { AccessToGift = false; GroupGiftDT = SGroupGiftAccess.LoadViaAGift( GiftDR.LedgerNumber, GiftDR.BatchNumber, GiftDR.GiftTransactionNumber, Transaction); UserGroupDT = SUserGroupAccess.LoadViaSUser(UserInfo.GUserInfo.UserID, Transaction); // Loop over all rows of GroupGiftDT for (Counter = 0; Counter <= GroupGiftDT.Rows.Count - 1; Counter += 1) { // To be able to view a Gift, ReadAccess must be granted if (GroupGiftDT[Counter].ReadAccess) { // Find out whether the user has a row in s_user_group with the // GroupID of the GroupGift row FoundUserGroups = UserGroupDT.Select(SUserGroupTable.GetGroupIdDBName() + " = '" + GroupGiftDT[Counter].GroupId + "'"); if (FoundUserGroups.Length != 0) { // Access to gift can be granted AccessToGift = true; continue; // don't evaluate further GroupGiftDT rows } } } } else { AccessToGift = true; } if (AccessToGift) { tmpLastGiftDate = GiftDR.DateEntered; // Console.WriteLine('GiftDR.LedgerNumber: ' + GiftDR.LedgerNumber.ToString + '; ' + // 'GiftDR.BatchNumber: ' + GiftDR.BatchNumber.ToString); // Load Gift Batch AGiftBatchAccess.LoadByPrimaryKey(LastGiftDS, GiftDR.LedgerNumber, GiftDR.BatchNumber, StringHelper.InitStrArr(new String[] { AGiftBatchTable.GetCurrencyCodeDBName() }), Transaction, null, 0, 0); if (LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows.Count != 0) { GiftBatchDR = ((AGiftBatchRow)LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows[0]); tmpLastGiftCurrencyCode = GiftBatchDR.CurrencyCode; // Get Currency ACurrencyAccess.LoadByPrimaryKey(LastGiftDS, GiftBatchDR.CurrencyCode, Transaction); if (LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows.Count != 0) { CurrencyDR = (ACurrencyRow)(LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows[0]); tmpLastGiftCurrencyCode = CurrencyDR.CurrencyCode; tmpLastGiftDisplayFormat = CurrencyDR.DisplayFormat; } else { tmpLastGiftCurrencyCode = ""; tmpLastGiftDisplayFormat = ""; } } else { // missing Currency tmpLastGiftCurrencyCode = ""; tmpLastGiftDisplayFormat = ""; } // Load Gift Detail AGiftDetailAccess.LoadViaAGift(LastGiftDS, GiftDR.LedgerNumber, GiftDR.BatchNumber, GiftDR.GiftTransactionNumber, StringHelper.InitStrArr(new String[] { AGiftDetailTable.GetGiftTransactionAmountDBName(), AGiftDetailTable.GetRecipientKeyDBName(), AGiftDetailTable. GetRecipientLedgerNumberDBName(), AGiftDetailTable.GetConfidentialGiftFlagDBName() }), Transaction, null, 0, 0); GiftDetailDT = (AGiftDetailTable)LastGiftDS.Tables[AGiftDetailTable.GetTableName()]; if (GiftDetailDT.Rows.Count != 0) { if (GiftDR.LastDetailNumber > 1) { // Gift is a Split Gift tmpLastGiftAmount = 0; for (Counter = 0; Counter <= GiftDetailDT.Rows.Count - 1; Counter += 1) { GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[Counter]; // Check for confidential gift and whether the current user is allowed to see it if (GiftDetailDR.ConfidentialGiftFlag) { if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) || (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3)))) { // User isn't allowed to see the gift tmpRestrictedOrConfidentialGiftAccessDenied = true; tmpLastGiftAmount = 0; return; } } tmpLastGiftAmount = tmpLastGiftAmount + GiftDetailDR.GiftTransactionAmount; } tmpLastGiftGivenToShortName = ""; tmpLastGiftRecipientLedgerShortName = ""; tmpLastGiftGivenToPartnerKey = -1; tmpLastGiftRecipientLedger = -1; } else { // Gift isn't a Split Gift GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[0]; // Check for confidential gift and whether the current user is allowed to see it if (GiftDetailDR.ConfidentialGiftFlag) { if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) || (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3)))) { // User isn't allowed to see the gift tmpRestrictedOrConfidentialGiftAccessDenied = true; return; } } tmpLastGiftAmount = GiftDetailDR.GiftTransactionAmount; tmpLastGiftGivenToPartnerKey = GiftDetailDR.RecipientKey; // Get Partner ShortName PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientKey, StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0); if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0) { tmpLastGiftGivenToShortName = ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName; } else { // missing Partner tmpLastGiftGivenToShortName = ""; } // Get rid of last record because we are about to select again into the same DataTable... LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Clear(); // Get Recipient Ledger PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientLedgerNumber, StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0); if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0) { tmpLastGiftRecipientLedgerShortName = ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName; } else { // missing Ledger tmpLastGiftRecipientLedgerShortName = ""; } } } else { // missing Gift Detail tmpLastGiftAmount = 0; tmpLastGiftGivenToShortName = ""; tmpLastGiftRecipientLedgerShortName = ""; tmpLastGiftGivenToPartnerKey = -1; tmpLastGiftRecipientLedger = -1; } } else { // Gift is a restriced Gift and the current user isn't allowed to see it tmpRestrictedOrConfidentialGiftAccessDenied = true; } } finally { TLogging.LogAtLevel(7, "TGift.GetLastGiftDetails: committed own transaction."); } }); ALastGiftDate = tmpLastGiftDate; ALastGiftAmount = tmpLastGiftAmount; ALastGiftGivenToPartnerKey = tmpLastGiftGivenToPartnerKey; ALastGiftRecipientLedger = tmpLastGiftRecipientLedger; ALastGiftCurrencyCode = tmpLastGiftCurrencyCode; ALastGiftDisplayFormat = tmpLastGiftDisplayFormat; ALastGiftGivenToShortName = tmpLastGiftGivenToShortName; ALastGiftRecipientLedgerShortName = tmpLastGiftRecipientLedgerShortName; ARestrictedOrConfidentialGiftAccessDenied = tmpRestrictedOrConfidentialGiftAccessDenied; return(AccessToGift); }
public static bool GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable) { // TODO: check access permissions for the current user TDBTransaction ReadTransaction = null; TTypedDataTable tempTable = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { tempTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { tempTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { tempTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { tempTable = ACurrencyAccess.LoadAll(ReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { tempTable = ADailyExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { tempTable = ACorporateExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { tempTable = ACurrencyLanguageAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { tempTable = AFeesPayableAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { tempTable = AFeesReceivableAccess.LoadAll(ReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { tempTable = AAnalysisTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { tempTable = AGiftBatchAccess.LoadAll(ReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { tempTable = AJournalAccess.LoadAll(ReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { tempTable = ALedgerAccess.LoadAll(ReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { tempTable = MExtractMasterAccess.LoadAll(ReadTransaction); } else { tempTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { tempTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { tempTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { tempTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { tempTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { tempTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { tempTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PFormTable.GetTableDBName()) { string[] columns = TTypedDataTable.GetColumnStringList(PFormTable.TableId); StringCollection fieldList = new StringCollection(); for (int i = 0; i < columns.Length; i++) { // Do not load the template document - we don't display it and it is big! if (columns[i] != PFormTable.GetTemplateDocumentDBName()) { fieldList.Add(columns[i]); } } tempTable = PFormAccess.LoadAll(fieldList, ReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { tempTable = PInternationalPostalTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { tempTable = PtApplicationTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { tempTable = PFormalityAccess.LoadAll(ReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { tempTable = PMailingAccess.LoadAll(ReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { tempTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { tempTable = PmDocumentTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { tempTable = SGroupAccess.LoadAll(ReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } }); // Accept row changes here so that the Client gets 'unmodified' rows tempTable.AcceptChanges(); // return the table AResultTable = tempTable; return(true); }
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 GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable) { // TODO: check access permissions for the current user bool NewTransaction = false; TDBTransaction ReadTransaction; TTypedDataTable tempTable = null; try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { tempTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { tempTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { tempTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { tempTable = ACurrencyAccess.LoadAll(ReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { tempTable = ADailyExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { tempTable = ACorporateExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { tempTable = ACurrencyLanguageAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { tempTable = AFeesPayableAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { tempTable = AFeesReceivableAccess.LoadAll(ReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { tempTable = AAnalysisTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { tempTable = AGiftBatchAccess.LoadAll(ReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { tempTable = AJournalAccess.LoadAll(ReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { tempTable = ALedgerAccess.LoadAll(ReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { tempTable = MExtractMasterAccess.LoadAll(ReadTransaction); } else { tempTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { tempTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { tempTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { tempTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { tempTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { tempTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { tempTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { tempTable = PInternationalPostalTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { tempTable = PtApplicationTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { tempTable = PMailingAccess.LoadAll(ReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { tempTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { tempTable = PmDocumentTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { tempTable = SGroupAccess.LoadAll(ReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } } catch (Exception Exp) { DBAccess.GDBAccessObj.RollbackTransaction(); TLogging.Log("TCommonDataReader.GetData exception: " + Exp.ToString(), TLoggingType.ToLogfile); TLogging.Log(Exp.StackTrace, TLoggingType.ToLogfile); throw; } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TCommonDataReader.GetData: committed own transaction."); } } // Accept row changes here so that the Client gets 'unmodified' rows tempTable.AcceptChanges(); // return the table AResultTable = tempTable; return(true); }
/// <summary> /// ResetForwardPeriodBatches.RunOperation /// /// Reset period columns on batch, journal and gift batch tables for periods beyond end of the old year /// </summary> public override Int32 RunOperation() { Int32 JobSize = 0; bool NewTransaction; Boolean ShouldCommit = false; TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { String Query = "SELECT * FROM PUB_a_batch WHERE " + "a_ledger_number_i=" + FLedgerInfo.LedgerNumber + " AND a_batch_year_i=" + FOldYearNum + " AND a_batch_period_i>" + FLedgerInfo.NumberOfAccountingPeriods; ABatchTable BatchTbl = new ABatchTable(); DBAccess.GDBAccessObj.SelectDT(BatchTbl, Query, Transaction); if (BatchTbl.Rows.Count > 0) { JobSize = BatchTbl.Rows.Count; if (!FInfoMode) { foreach (ABatchRow BatchRow in BatchTbl.Rows) { BatchRow.BatchPeriod -= FLedgerInfo.NumberOfAccountingPeriods; BatchRow.BatchYear += 1; } ABatchAccess.SubmitChanges(BatchTbl, Transaction); ShouldCommit = true; } } Query = "SELECT PUB_a_journal.* FROM PUB_a_batch, PUB_a_journal WHERE " + " PUB_a_journal.a_ledger_number_i=" + FLedgerInfo.LedgerNumber + " AND PUB_a_batch.a_batch_number_i= PUB_a_journal.a_batch_number_i" + " AND PUB_a_batch.a_batch_year_i=" + FOldYearNum + " AND a_journal_period_i>" + FLedgerInfo.NumberOfAccountingPeriods; AJournalTable JournalTbl = new AJournalTable(); DBAccess.GDBAccessObj.SelectDT(JournalTbl, Query, Transaction); if (JournalTbl.Rows.Count > 0) { if (!FInfoMode) { foreach (AJournalRow JournalRow in JournalTbl.Rows) { JournalRow.JournalPeriod -= FLedgerInfo.NumberOfAccountingPeriods; } AJournalAccess.SubmitChanges(JournalTbl, Transaction); ShouldCommit = true; } } Query = "SELECT * FROM PUB_a_gift_batch WHERE " + " a_ledger_number_i=" + FLedgerInfo.LedgerNumber + " AND a_batch_year_i=" + FOldYearNum + " AND a_batch_period_i>" + FLedgerInfo.NumberOfAccountingPeriods; AGiftBatchTable GiftBatchTbl = new AGiftBatchTable(); DBAccess.GDBAccessObj.SelectDT(GiftBatchTbl, Query, Transaction); if (GiftBatchTbl.Rows.Count > 0) { JobSize += GiftBatchTbl.Rows.Count; if (!FInfoMode) { foreach (AGiftBatchRow GiftBatchRow in GiftBatchTbl.Rows) { GiftBatchRow.BatchPeriod -= FLedgerInfo.NumberOfAccountingPeriods; GiftBatchRow.BatchYear += 1; } AGiftBatchAccess.SubmitChanges(GiftBatchTbl, Transaction); ShouldCommit = true; } } } // try finally { if (NewTransaction) { if (ShouldCommit) { DBAccess.GDBAccessObj.CommitTransaction(); } else { DBAccess.GDBAccessObj.RollbackTransaction(); } } } return JobSize; }
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); }