/// <summary> /// create a new batch with a consecutive batch number in the ledger /// for call inside a server function /// for performance reasons submitting (save the data in the database) is done later (not here) /// </summary> /// <param name="MainDS"></param> /// <param name="Transaction"></param> /// <param name="LedgerTable"></param> /// <param name="ALedgerNumber"></param> /// <returns>the new gift batch row</returns> public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS MainDS, ref TDBTransaction Transaction, ref ALedgerTable LedgerTable, Int32 ALedgerNumber) { GiftBatchTDS Temp = new GiftBatchTDS(); ARecurringGiftBatchAccess.LoadViaALedger(Temp, LedgerTable[0].LedgerNumber, Transaction); DataView RecurringGiftBatchDV = new DataView(Temp.ARecurringGiftBatch); RecurringGiftBatchDV.RowFilter = string.Empty; RecurringGiftBatchDV.Sort = string.Format("{0} DESC", ARecurringGiftBatchTable.GetBatchNumberDBName()); //Recurring batch numbers can be reused so check each time for current highest number if (RecurringGiftBatchDV.Count > 0) { LedgerTable[0].LastRecGiftBatchNumber = (int)(RecurringGiftBatchDV[0][ARecurringGiftBatchTable.GetBatchNumberDBName()]); } else { LedgerTable[0].LastRecGiftBatchNumber = 0; } ARecurringGiftBatchRow NewRow = MainDS.ARecurringGiftBatch.NewRowTyped(true); NewRow.LedgerNumber = ALedgerNumber; NewRow.BatchNumber = ++LedgerTable[0].LastRecGiftBatchNumber; NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description"); NewRow.BankAccountCode = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber); NewRow.BankCostCentre = TLedgerInfo.GetStandardCostCentre(ALedgerNumber); NewRow.CurrencyCode = LedgerTable[0].BaseCurrency; MainDS.ARecurringGiftBatch.Rows.Add(NewRow); return(NewRow); }
/// <summary> /// create a new batch with a consecutive batch number in the ledger /// for call inside a server function /// for performance reasons submitting (save the data in the database) is done later (not here) /// </summary> /// <param name="AMainDS"></param> /// <param name="ATransaction"></param> /// <param name="ALedgerTbl"></param> /// <param name="ALedgerNumber"></param> /// <returns>the new gift batch row</returns> public static ARecurringGiftBatchRow CreateANewRecurringGiftBatchRow(ref GiftBatchTDS AMainDS, ref TDBTransaction ATransaction, ref ALedgerTable ALedgerTbl, Int32 ALedgerNumber) { #region Validate Arguments if (AMainDS == null) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Gift Batch dataset is NULL!"), Utilities.GetMethodName(true))); } else if (ATransaction == null) { throw new EFinanceSystemDBTransactionNullException(String.Format(Catalog.GetString( "Function:{0} - Database Transaction must not be NULL!"), Utilities.GetMethodName(true))); } else if ((ALedgerTbl == null) || (ALedgerTbl.Count == 0)) { throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString( "Function:{0} - The Ledger table is NULL or is empty!"), Utilities.GetMethodName(true))); } else if (ALedgerNumber <= 0) { throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString( "Function:{0} - The Ledger number must be greater than 0!"), Utilities.GetMethodName(true)), ALedgerNumber); } #endregion Validate Arguments GiftBatchTDS Temp = new GiftBatchTDS(); ARecurringGiftBatchAccess.LoadViaALedger(Temp, ALedgerNumber, ATransaction); DataView RecurringGiftBatchDV = new DataView(Temp.ARecurringGiftBatch); RecurringGiftBatchDV.RowFilter = string.Empty; RecurringGiftBatchDV.Sort = string.Format("{0} DESC", ARecurringGiftBatchTable.GetBatchNumberDBName()); //Recurring batch numbers can be reused so check each time for current highest number if (RecurringGiftBatchDV.Count > 0) { ALedgerTbl[0].LastRecGiftBatchNumber = (int)(RecurringGiftBatchDV[0][ARecurringGiftBatchTable.GetBatchNumberDBName()]); } else { ALedgerTbl[0].LastRecGiftBatchNumber = 0; } ARecurringGiftBatchRow NewRow = AMainDS.ARecurringGiftBatch.NewRowTyped(true); NewRow.LedgerNumber = ALedgerNumber; NewRow.BatchNumber = ++ALedgerTbl[0].LastRecGiftBatchNumber; NewRow.BatchDescription = Catalog.GetString("Please enter recurring batch description"); NewRow.BankAccountCode = TLedgerInfo.GetDefaultBankAccount(ALedgerNumber); NewRow.BankCostCentre = TLedgerInfo.GetStandardCostCentre(ALedgerNumber); NewRow.CurrencyCode = ALedgerTbl[0].BaseCurrency; AMainDS.ARecurringGiftBatch.Rows.Add(NewRow); return(NewRow); }
public static bool DeleteSponsorshipRecurringGift( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftTransactionNumber, Int32 ADetailNumber, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); TDBTransaction Transaction = new TDBTransaction(); SponsorshipTDS MainDS = new SponsorshipTDS(); TDataBase DB = DBAccess.Connect("DeleteRecurringGift"); // load batches and their transactions based on their id / batch number DB.ReadTransaction(ref Transaction, delegate { ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); }); try { bool LastDetail = true; ARecurringGiftDetailRow DetailToDelete = null; ARecurringGiftRow GiftToDelete = null; foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows) { if (CheckGiftDetailRow.GiftTransactionNumber == AGiftTransactionNumber) { if (CheckGiftDetailRow.DetailNumber == ADetailNumber) { DetailToDelete = CheckGiftDetailRow; DetailToDelete.DetailNumber = 20000; } else { LastDetail = false; if (CheckGiftDetailRow.DetailNumber > ADetailNumber) { CheckGiftDetailRow.DetailNumber--; } } } } foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows) { if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber) { if (LastDetail) { GiftToDelete = CheckGiftRow; } else { CheckGiftRow.LastDetailNumber--; } } } // delete the detail if (DetailToDelete != null) { DetailToDelete.Delete(); } // delete the gift if (GiftToDelete != null) { // we keep the gift transaction numbers, and live with gaps. GiftToDelete.Delete(); } SponsorshipTDSAccess.SubmitChanges(MainDS, DB); return(true); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } finally { DB.CloseDBConnection(); } }
public static bool MaintainSponsorshipRecurringGifts( Int32 ALedgerNumber, Int32 ABatchNumber, Int32 AGiftTransactionNumber, Int32 ADetailNumber, Int64 ARecipientKey, Int64 ADonorKey, String AMotivationGroupCode, String AMotivationDetailCode, decimal AGiftAmount, DateTime AStartDonations, DateTime?AEndDonations, out TVerificationResultCollection AVerificationResult) { AVerificationResult = new TVerificationResultCollection(); if (ADonorKey <= 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the donor", "", "MaintainChildren.ErrMissingDonor", TResultSeverity.Resv_Critical)); } if (AGiftAmount <= 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid amount", "", "MaintainChildren.ErrMissingAmount", TResultSeverity.Resv_Critical)); } if ((AMotivationDetailCode == "") || (AMotivationDetailCode == null)) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the motivation", "", "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical)); } if (AVerificationResult.HasCriticalErrors) { return(false); } TDBTransaction Transaction = new TDBTransaction(); SponsorshipTDS MainDS = new SponsorshipTDS(); TDataBase DB = DBAccess.Connect("MaintainRecurringGifts"); bool MotivationExists = false; // load batches and their transactions based on their id / batch number DB.ReadTransaction(ref Transaction, delegate { // we overwrite the user input, since the user can't really send the right batch number on create ABatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction); ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction); MotivationExists = AMotivationDetailAccess.Exists(ALedgerNumber, AMotivationGroupCode, AMotivationDetailCode, Transaction); }); if (!MotivationExists) { AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid motivation", "", "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical)); return(false); } // try to get a row with requested id, aka edit else make a new ARecurringGiftRow EditGiftRow = null; foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows) { if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber) { EditGiftRow = CheckGiftRow; break; } } // we did not find a Transaction in this Batch, so we create one if (EditGiftRow == null) { // TODO: we could look for a gift transaction of the same donor??? EditGiftRow = MainDS.ARecurringGift.NewRowTyped(true); EditGiftRow.DonorKey = ADonorKey; EditGiftRow.BatchNumber = ABatchNumber; EditGiftRow.LedgerNumber = ALedgerNumber; EditGiftRow.GiftTransactionNumber = MainDS.ARecurringGiftBatch[0].LastGiftNumber + 1; MainDS.ARecurringGiftBatch[0].LastGiftNumber++; MainDS.ARecurringGift.Rows.Add(EditGiftRow); } // load stuff based on the current edit row DB.ReadTransaction(ref Transaction, delegate { ARecurringGiftDetailAccess.LoadViaARecurringGift(MainDS, ALedgerNumber, ABatchNumber, EditGiftRow.GiftTransactionNumber, Transaction); }); DB.CloseDBConnection(); // try to get a row with requested id, aka edit else make a new ARecurringGiftDetailRow EditGiftDetailRow = null; foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows) { if (CheckGiftDetailRow.DetailNumber == ADetailNumber) { EditGiftDetailRow = CheckGiftDetailRow; break; } } // none found, make one if (EditGiftDetailRow == null) { EditGiftDetailRow = MainDS.ARecurringGiftDetail.NewRowTyped(true); EditGiftDetailRow.LedgerNumber = ALedgerNumber; EditGiftDetailRow.BatchNumber = ABatchNumber; EditGiftDetailRow.RecipientKey = ARecipientKey; EditGiftDetailRow.GiftTransactionNumber = EditGiftRow.GiftTransactionNumber; EditGiftDetailRow.DetailNumber = EditGiftRow.LastDetailNumber + 1; EditGiftRow.LastDetailNumber++; MainDS.ARecurringGiftDetail.Rows.Add(EditGiftDetailRow); } EditGiftRow.DonorKey = ADonorKey; EditGiftDetailRow.GiftAmount = AGiftAmount; EditGiftDetailRow.MotivationGroupCode = AMotivationGroupCode; EditGiftDetailRow.MotivationDetailCode = AMotivationDetailCode; EditGiftDetailRow.EndDonations = AEndDonations; EditGiftDetailRow.StartDonations = AStartDonations; try { SponsorshipTDSAccess.SubmitChanges(MainDS); return(true); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } }
public static SponsorshipTDS GetChildDetails(Int64 APartnerKey, Int32 ALedgerNumber, bool AWithPhoto, out string ASponsorshipStatus) { SponsorshipTDS MainDS = new SponsorshipTDS(); TDBTransaction Transaction = new TDBTransaction(); DBAccess.ReadTransaction(ref Transaction, delegate { PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PPartnerReminderAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); if (!AWithPhoto && (MainDS.PFamily.Rows.Count == 1)) { MainDS.PFamily[0].Photo = ""; } int SponsorshipBatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction); if (SponsorshipBatchNumber > -1) { ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); GiftBatchTDS GiftDS = new GiftBatchTDS(); TGiftTransactionWebConnector.LoadGiftDonorRelatedData(GiftDS, true, ALedgerNumber, SponsorshipBatchNumber, Transaction); for (int i = 0; i < MainDS.ARecurringGiftDetail.Count;) { SponsorshipTDSARecurringGiftDetailRow gdr = MainDS.ARecurringGiftDetail[i]; // drop all recurring gift details, that are not related to this child (RecipientKey) if (gdr.RecipientKey != APartnerKey) { MainDS.ARecurringGiftDetail.Rows.RemoveAt(i); } else { i++; // set the donor key from the appropriate recurring gift MainDS.ARecurringGift.DefaultView.RowFilter = String.Format("{0} = {1}", ARecurringGiftTable.GetGiftTransactionNumberDBName(), gdr.GiftTransactionNumber); // there should be only one row foreach (DataRowView drv in MainDS.ARecurringGift.DefaultView) { ARecurringGiftRow recurrGiftRow = (ARecurringGiftRow)drv.Row; gdr.DonorKey = recurrGiftRow.DonorKey; PPartnerRow donorRow = (PPartnerRow)GiftDS.DonorPartners.Rows.Find(recurrGiftRow.DonorKey); gdr.DonorName = donorRow.PartnerShortName; gdr.CurrencyCode = MainDS.ARecurringGiftBatch[0].CurrencyCode; } } } // drop all unrelated gift rows, that don't have a detail for this child for (int i = 0; i < MainDS.ARecurringGift.Count;) { ARecurringGiftRow gr = MainDS.ARecurringGift[0]; MainDS.ARecurringGiftDetail.DefaultView.RowFilter = String.Format("{0} = {1}", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), gr.GiftTransactionNumber); if (MainDS.ARecurringGiftDetail.DefaultView.Count == 0) { MainDS.ARecurringGift.Rows.RemoveAt(i); } else { i++; } } } }); bool isSponsoredChild = false; ASponsorshipStatus = "[N/A]"; foreach (PPartnerTypeRow type in MainDS.PPartnerType.Rows) { if (type.TypeCode == "CHILDREN_HOME" || type.TypeCode == "HOME_BASED" || type.TypeCode == "BOARDING_SCHOOL" || type.TypeCode == "PREVIOUS_CHILD" || type.TypeCode == "CHILD_DIED") { isSponsoredChild = true; } ASponsorshipStatus = type.TypeCode; } if (!isSponsoredChild) { return(new SponsorshipTDS()); } return(MainDS); }