Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public void TestRecurringBatchLoadingRecalculations()
        {
            TVerificationResultCollection VerificationResult;

            Int64 RecipientKey;
            Int64 RealRecipientLedgerNumber;
            Int64 FalseRecipientLedgerNumber;
            Int32 RecurringGiftBatchNumber;

            //
            // Arrange: Create all data needed for this test (Recurring Gift Detail will have 'fake' RecipientLedgerNumber)
            //
            TestRecurringBatchSubmitRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber,
                                                           out FalseRecipientLedgerNumber, out RecurringGiftBatchNumber);

            //
            // Act: Load the batch
            //
            GiftBatchTDS GiftBatchDS = TGiftTransactionWebConnector.LoadARecurringGiftBatchAndRelatedData(FLedgerNumber, RecurringGiftBatchNumber);

            //
            // Assert
            //

            // Initial Assert: Tests that the load returns results
            Assert.IsNotNull(GiftBatchDS, "TestRecurringBatchLoadingRecalculations fail: Loading GiftBatch failed");
            Assert.IsNotNull(GiftBatchDS.ARecurringGiftDetail, "TestRecurringBatchLoadingRecalculations fail: Loading GiftBatch failed");

            // Primary Assert: Chaeck that the gift has the correct RecipientLedgerNumber
            TDBTransaction          Transaction            = null;
            ARecurringGiftDetailRow RecurringGiftDetailRow = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                RecurringGiftDetailRow =
                    ARecurringGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, RecurringGiftBatchNumber, 1, 1, Transaction)[0];
            });

            Assert.IsNotNull(
                RecurringGiftDetailRow, "TestRecurringBatchLoadingRecalculations fail: Obtaining RecurringGiftDetailRow from database failed");

            Assert.AreEqual(RealRecipientLedgerNumber, RecurringGiftDetailRow.RecipientLedgerNumber,
                            "TestRecurringBatchLoadingRecalculations fail: RecipientLedgerNumber for RecurringGiftDetailRow is incorrect");

            // Cleanup: Delete test records

            bool SubmissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  TEnforceIsolationLevel.eilMinimum,
                                                                  ref Transaction,
                                                                  ref SubmissionOK,
                                                                  delegate
            {
                ARecurringGiftDetailAccess.DeleteRow(ARecurringGiftDetailTable.TableId, RecurringGiftDetailRow, Transaction);
            });

            TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult);
            TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult);
            TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult);
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void TestRecurringBatchSubmitRecalculations()
        {
            TVerificationResultCollection VerificationResult;

            Int64 RecipientKey;
            Int64 RealRecipientLedgerNumber;
            Int64 FalseRecipientLedgerNumber;
            Int32 RecurringGiftBatchNumber;
            Int32 GiftBatchNumber = -1;

            //
            // Arrange: Create all data needed for this test (Recurring Gift Detail will have 'fake' RecipientLedgerNumber)
            //
            TestRecurringBatchSubmitRecalculations_Arrange(out RecipientKey, out RealRecipientLedgerNumber,
                                                           out FalseRecipientLedgerNumber, out RecurringGiftBatchNumber);

            //
            // Act: Submit the batch
            //

            Hashtable requestParams = new Hashtable();

            requestParams.Add("ALedgerNumber", FLedgerNumber);
            requestParams.Add("ABatchNumber", RecurringGiftBatchNumber);
            requestParams.Add("AEffectiveDate", DateTime.Today);
            requestParams.Add("AExchangeRateToBase", (decimal)1);
            requestParams.Add("AExchangeRateIntlToBase", (decimal)1);

            TGiftTransactionWebConnector.SubmitRecurringGiftBatch(requestParams);

            //
            // Assert
            //

            // Primary Assert: Chaeck that the RecurringGiftDetail and the newly created GiftDetail have the correct RecipientLedgerNumber
            TDBTransaction          Transaction            = null;
            ARecurringGiftDetailRow RecurringGiftDetailRow = null;
            AGiftDetailRow          GiftDetailRow          = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.Serializable,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                RecurringGiftDetailRow =
                    ARecurringGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, RecurringGiftBatchNumber, 1, 1, Transaction)[0];

                GiftBatchNumber = ALedgerAccess.LoadByPrimaryKey(FLedgerNumber, Transaction)[0].LastGiftBatchNumber;
                GiftDetailRow   = AGiftDetailAccess.LoadByPrimaryKey(FLedgerNumber, GiftBatchNumber, 1, 1, Transaction)[0];
            });

            Assert.IsNotNull(
                RecurringGiftDetailRow, "TestRecurringBatchSubmitRecalculations fail: Obtaining RecurringGiftDetailRow from database failed");
            Assert.IsNotNull(
                GiftDetailRow, "TestRecurringBatchSubmitRecalculations fail: Obtaining GiftDetailRow from database failed");

            Assert.AreEqual(RealRecipientLedgerNumber, RecurringGiftDetailRow.RecipientLedgerNumber,
                            "TestRecurringBatchSubmitRecalculations fail: RecipientLedgerNumber for RecurringGiftDetailRow is incorrect");
            Assert.AreEqual(RealRecipientLedgerNumber, GiftDetailRow.RecipientLedgerNumber,
                            "TestRecurringBatchSubmitRecalculations fail: RecipientLedgerNumber for GiftDetailRow is incorrect");

            // Cleanup: Delete test records

            bool SubmissionOK = true;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable,
                                                                  TEnforceIsolationLevel.eilMinimum,
                                                                  ref Transaction,
                                                                  ref SubmissionOK,
                                                                  delegate
            {
                AGiftDetailAccess.DeleteRow(AGiftDetailTable.TableId, GiftDetailRow, Transaction);
                ARecurringGiftDetailAccess.DeleteRow(ARecurringGiftDetailTable.TableId, RecurringGiftDetailRow, Transaction);
            });

            TPartnerWebConnector.DeletePartner(RecipientKey, out VerificationResult);
            TPartnerWebConnector.DeletePartner(RealRecipientLedgerNumber, out VerificationResult);
            TPartnerWebConnector.DeletePartner(FalseRecipientLedgerNumber, out VerificationResult);
        }