private static void GenerateCommitmentRecord( XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS, PersonnelTDS APersonnelDS, DataTable AFieldKeys) { DataView FamilyView = new DataView(AMainDS.PPerson); FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString(); FamilyView.Sort = PPersonTable.GetFamilyIdDBName(); PPersonRow firstPerson = (PPersonRow)FamilyView[0].Row; int FieldID = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "fieldCommitment")) % AFieldKeys.Rows.Count; long FieldPartnerKey = Convert.ToInt64(AFieldKeys.Rows[FieldID].ItemArray[0]); PPartnerGiftDestinationRow giftDestination = AMainDS.PPartnerGiftDestination.NewRowTyped(); if (NextKeyForGiftDestination == -1) { NextKeyForGiftDestination = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); } else { NextKeyForGiftDestination++; } giftDestination.Key = NextKeyForGiftDestination; giftDestination.FieldKey = FieldPartnerKey; giftDestination.PartnerKey = AFamilyRow.PartnerKey; giftDestination.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; giftDestination.DateEffective = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment")); PmStaffDataRow staffData = APersonnelDS.PmStaffData.NewRowTyped(); staffData.SiteKey = DomainManager.GSiteKey; staffData.Key = (APersonnelDS.PmStaffData.Count + 1) * -1; staffData.PartnerKey = firstPerson.PartnerKey; staffData.ReceivingField = FieldPartnerKey; // TODO: could add foreign nationals staffData.HomeOffice = DomainManager.GSiteKey; staffData.OfficeRecruitedBy = DomainManager.GSiteKey; staffData.StartOfCommitment = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment")); int LengthCommitment = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "lengthCommitment")); staffData.StatusCode = "LONG-TERMER"; if (LengthCommitment > 0) { string LengthCommitmentUnit = TXMLParser.GetAttribute(ACurrentNode, "lengthCommitmentUnit"); if (LengthCommitmentUnit == "week") { staffData.StatusCode = "SHORT-TERMER"; staffData.EndOfCommitment = staffData.StartOfCommitment.AddDays(7 * LengthCommitment); } else if (LengthCommitmentUnit == "month") { staffData.StatusCode = "SHORT-TERMER"; staffData.EndOfCommitment = staffData.StartOfCommitment.AddMonths(LengthCommitment); } else if (LengthCommitmentUnit == "year") { if (LengthCommitment < 3) { staffData.StatusCode = "WORKER"; } staffData.EndOfCommitment = staffData.StartOfCommitment.AddYears(LengthCommitment); } } APersonnelDS.PmStaffData.Rows.Add(staffData); giftDestination.DateExpires = staffData.EndOfCommitment; if (AMainDS.PPartnerGiftDestination == null) { AMainDS.PPartnerGiftDestination.Merge(new PPartnerGiftDestinationTable()); } AMainDS.PPartnerGiftDestination.Rows.Add(giftDestination); // TODO depending on start and end date of commitment, set EX-WORKER or no special type yet at all string SpecialType = MPartnerConstants.PARTNERTYPE_WORKER; if (!staffData.IsEndOfCommitmentNull() && (staffData.EndOfCommitment < DateTime.Today)) { SpecialType = MPartnerConstants.PARTNERTYPE_EX_WORKER; } if (SpecialType != string.Empty) { // create special type for family partner PPartnerTypeRow PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = AFamilyRow.PartnerKey; PartnerTypeRow.TypeCode = SpecialType; AMainDS.PPartnerType.Rows.Add(PartnerTypeRow); // set special type WORKER for the parents for (int countPerson = 0; countPerson < FamilyView.Count && countPerson < 2; countPerson++) { PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row; // create special type for the person partners PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = personRow.PartnerKey; PartnerTypeRow.TypeCode = SpecialType; AMainDS.PPartnerType.Rows.Add(PartnerTypeRow); } } }
/// <summary> /// Creates data needed to test posting recalculations /// </summary> /// <param name="ARecipientKey">Partner Key of the recipient.</param> /// <param name="ARealRecipientLedgerNumber">What the RecipientLedgerNumber should be.</param> /// <param name="AFalseRecipientLedgerNumber">What the RecipientLedgerNumber is.</param> /// <param name="ARecurringGiftBatchNumber">Batch Number.</param> private void TestRecurringBatchSubmitRecalculations_Arrange(out long ARecipientKey, out long ARealRecipientLedgerNumber, out long AFalseRecipientLedgerNumber, out Int32 ARecurringGiftBatchNumber) { TVerificationResultCollection VerificationResult; TSubmitChangesResult Result; DataSet ResponseDS; TPartnerEditUIConnector PartnerEditUIUIConnector = new TPartnerEditUIConnector(); GiftBatchTDS MainDS = new GiftBatchTDS(); PartnerEditTDS PartnerEditDS = new PartnerEditTDS(); // this is a family partner in the test database const Int64 DONORKEY = 43005001; // create a new recipient TCreateTestPartnerData.CreateNewFamilyPartner(PartnerEditDS); ARecipientKey = PartnerEditDS.PFamily[0].PartnerKey; // create two new Unit partners TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); TCreateTestPartnerData.CreateNewUnitPartner(PartnerEditDS); AFalseRecipientLedgerNumber = PartnerEditDS.PPartner[0].PartnerKey; ARealRecipientLedgerNumber = PartnerEditDS.PPartner[1].PartnerKey; // create a Gift Destination for family PPartnerGiftDestinationRow GiftDestination = PartnerEditDS.PPartnerGiftDestination.NewRowTyped(true); GiftDestination.Key = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); GiftDestination.PartnerKey = ARecipientKey; GiftDestination.DateEffective = new DateTime(2011, 01, 01); GiftDestination.FieldKey = ARealRecipientLedgerNumber; PartnerEditDS.PPartnerGiftDestination.Rows.Add(GiftDestination); // Guard Assertions Assert.That(PartnerEditDS.PFamily[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[0], Is.Not.Null); Assert.That(PartnerEditDS.PPartner[1], Is.Not.Null); // Submit the new PartnerEditTDS records to the database ResponseDS = new PartnerEditTDS(); Result = PartnerEditUIUIConnector.SubmitChanges(ref PartnerEditDS, ref ResponseDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SubmitChanges for PartnerEditDS failed: " + VerificationResult.BuildVerificationResultString()); // link unit to Cost Centre DataTable PartnerCostCentreTbl = TGLSetupWebConnector.LoadCostCentrePartnerLinks(FLedgerNumber, 0); DataRow PartnerCostCentreRow = PartnerCostCentreTbl.NewRow(); PartnerCostCentreRow["PartnerKey"] = ARealRecipientLedgerNumber; PartnerCostCentreRow["IsLinked"] = 4300; PartnerCostCentreTbl.Rows.Add(PartnerCostCentreRow); TGLSetupWebConnector.SaveCostCentrePartnerLinks(FLedgerNumber, PartnerCostCentreTbl); // create a new Recurring Gift Batch MainDS = TGiftTransactionWebConnector.CreateARecurringGiftBatch(FLedgerNumber); ARecurringGiftBatchNumber = MainDS.ARecurringGiftBatch[0].BatchNumber; // create a new recurring gifts ARecurringGiftRow RecurringGiftRow = MainDS.ARecurringGift.NewRowTyped(true); RecurringGiftRow.LedgerNumber = FLedgerNumber; RecurringGiftRow.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftRow.DonorKey = DONORKEY; RecurringGiftRow.GiftTransactionNumber = 1; RecurringGiftRow.LastDetailNumber = 1; MainDS.ARecurringGift.Rows.Add(RecurringGiftRow); // create a new RecurringGiftDetail ARecurringGiftDetailRow RecurringGiftDetail = MainDS.ARecurringGiftDetail.NewRowTyped(true); RecurringGiftDetail.LedgerNumber = FLedgerNumber; RecurringGiftDetail.BatchNumber = ARecurringGiftBatchNumber; RecurringGiftDetail.GiftTransactionNumber = 1; RecurringGiftDetail.DetailNumber = 1; RecurringGiftDetail.RecipientLedgerNumber = AFalseRecipientLedgerNumber; RecurringGiftDetail.GiftAmount = 100; RecurringGiftDetail.MotivationGroupCode = "GIFT"; RecurringGiftDetail.MotivationDetailCode = "SUPPORT"; RecurringGiftDetail.RecipientKey = ARecipientKey; MainDS.ARecurringGiftDetail.Rows.Add(RecurringGiftDetail); // Submit the new GiftBatchTDS records to the database Result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref MainDS, out VerificationResult); // Guard Assertion Assert.That(Result, Is.EqualTo( TSubmitChangesResult.scrOK), "SaveGiftBatchTDS failed: " + VerificationResult.BuildVerificationResultString()); }