/// <summary> /// Adds the dates of one partner to the accommodation report /// </summary> /// <param name="AShortTermRow">The short term application row of the current partner</param> /// <param name="AAttendeeRow">The attendee row of the current partner</param> /// <param name="AStartDate">Start date of the conference</param> /// <param name="AEndDate">End date of the conference</param> /// <param name="AFromDate">Start date of the report</param> /// <param name="AToDate">End date of the report</param> /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param> /// <param name="ASituation">The current report situation</param> /// <returns></returns> private bool AddPartnerToAccom(PmShortTermApplicationRow AShortTermRow, PcAttendeeRow AAttendeeRow, DateTime AStartDate, DateTime AEndDate, DateTime AFromDate, DateTime AToDate, string AReportDetail, ref TRptSituation ASituation) { // if we have an actual arrival and departure date from the attendee row use it. if (AAttendeeRow != null) { if (!AAttendeeRow.IsActualArrNull()) { AShortTermRow.Arrival = AAttendeeRow.ActualArr; } if (!AAttendeeRow.IsActualDepNull()) { AShortTermRow.Departure = AAttendeeRow.ActualDep; } } if (AShortTermRow.IsArrivalNull()) { AShortTermRow.Arrival = AStartDate; } if (AShortTermRow.IsDepartureNull()) { AShortTermRow.Departure = AEndDate; } if ((AShortTermRow.Arrival <= AToDate) && (AShortTermRow.Departure >= AFromDate)) { // this short term application covers the dates we examine PcRoomAllocTable TempTable = new PcRoomAllocTable(); PcRoomAllocTable RoomAllocTable; PcRoomAllocRow TemplateRow = TempTable.NewRowTyped(false); TemplateRow.PartnerKey = AShortTermRow.PartnerKey; TemplateRow.ConferenceKey = AShortTermRow.StConfirmedOption; RoomAllocTable = PcRoomAllocAccess.LoadUsingTemplate(TemplateRow, ASituation.GetDatabaseConnection().Transaction); char Gender; int Age; string PartnerName; GetGenderAndAge(AShortTermRow.PartnerKey, AStartDate, out Gender, out Age, ref ASituation); PartnerName = TAccommodationReportCalculation.GetPartnerShortName(AShortTermRow.PartnerKey, ref ASituation); foreach (DataRow Row in RoomAllocTable.Rows) { CheckRoomAllocation((PcRoomAllocRow)Row, AShortTermRow, AFromDate, AToDate, AReportDetail, Gender, Age, PartnerName, ref ASituation); } if (RoomAllocTable.Rows.Count == 0) { AddNoRoomBooking(AShortTermRow, AFromDate, AToDate, Gender, PartnerName); } } return true; }
/// <summary> /// Load/Refresh all Attendees for a conference /// </summary> public static void RefreshAttendees(Int64 AConferenceKey) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = true; PcConferenceTable ConferenceTable; PUnitTable UnitTable; string OutreachPrefix = String.Empty; ConferenceApplicationTDS MainDS; // make sure outreach codes are up to date in case it has changed in Unit record RefreshOutreachCode(AConferenceKey); DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { ConferenceTable = new PcConferenceTable(); UnitTable = new PUnitTable(); MainDS = new ConferenceApplicationTDS(); // get the conference prefix which links all outreaches associated with a conference ConferenceTable = PcConferenceAccess.LoadByPrimaryKey(AConferenceKey, Transaction); if (ConferenceTable.Count == 0) { throw new Exception("Cannot find conference " + AConferenceKey.ToString("0000000000")); } OutreachPrefix = ConferenceTable[0].OutreachPrefix; // load application data for all conference attendees from db TApplicationManagement.GetApplications(ref MainDS, AConferenceKey, OutreachPrefix, "all", -1, true, null, false); // check a valid pcattendee record exists for each short term application foreach (PmShortTermApplicationRow ShortTermAppRow in MainDS.PmShortTermApplication.Rows) { if (!IsAttendeeValid(MainDS, OutreachPrefix, ShortTermAppRow.PartnerKey)) { // ignore deleted applications, or cancelled applications continue; } // update outreach code in application (it may have changed) UnitTable = PUnitAccess.LoadByPrimaryKey(ShortTermAppRow.StConfirmedOption, Transaction); ShortTermAppRow.ConfirmedOptionCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCode; // Do we have a record for this attendee yet? bool AttendeeRecordExists = false; if (MainDS.PcAttendee.Rows.Contains(new object[] { AConferenceKey, ShortTermAppRow.PartnerKey })) { AttendeeRecordExists = true; } // create a new PcAttendee record if one does not already exist for this attendee if (!AttendeeRecordExists) { PcAttendeeRow AttendeeRow = MainDS.PcAttendee.NewRowTyped(); AttendeeRow.ConferenceKey = AConferenceKey; AttendeeRow.PartnerKey = ShortTermAppRow.PartnerKey; if (ShortTermAppRow.ConfirmedOptionCode.Length >= 11) { AttendeeRow.OutreachType = ShortTermAppRow.ConfirmedOptionCode.Substring(5, 6); } PmGeneralApplicationRow GeneralAppRow = (PmGeneralApplicationRow)MainDS.PmGeneralApplication.Rows.Find( new object[] { ShortTermAppRow.PartnerKey, ShortTermAppRow.ApplicationKey, ShortTermAppRow.RegistrationOffice }); DateTime DateAccepted = GeneralAppRow.GenAppDate; if (!GeneralAppRow.IsGenAppSendFldAcceptDateNull()) { DateAccepted = GeneralAppRow.GenAppSendFldAcceptDate.Value; } else if (!GeneralAppRow.IsGenAppRecvgFldAcceptNull()) { DateAccepted = GeneralAppRow.GenAppRecvgFldAccept.Value; } AttendeeRow.Registered = DateAccepted; // TODO: in Petra 2.x, this was calculated from pm_staff_data AttendeeRow.HomeOfficeKey = ShortTermAppRow.RegistrationOffice; if (AttendeeRow.HomeOfficeKey == 0) { AttendeeRow.HomeOfficeKey = ((int)AttendeeRow.PartnerKey / 1000000) * 1000000; } MainDS.PcAttendee.Rows.Add(AttendeeRow); } } PcRoomAllocTable RoomAllocTable = null; PcExtraCostTable ExtraCostTable = null; // now check the other way: all attendees of this conference, are they still valid? foreach (PcAttendeeRow AttendeeRow in MainDS.PcAttendee.Rows) { if ((AttendeeRow.RowState != DataRowState.Added) && !IsAttendeeValid(MainDS, OutreachPrefix, AttendeeRow.PartnerKey)) { // remove their accommodation RoomAllocTable = PcRoomAllocAccess.LoadViaPcAttendee(AttendeeRow.ConferenceKey, AttendeeRow.PartnerKey, Transaction); foreach (DataRow Row in RoomAllocTable.Rows) { Row.Delete(); } if (RoomAllocTable != null) { PcRoomAllocAccess.SubmitChanges(RoomAllocTable, Transaction); } // remove any extra costs ExtraCostTable = PcExtraCostAccess.LoadViaPcAttendee(AttendeeRow.ConferenceKey, AttendeeRow.PartnerKey, Transaction); foreach (DataRow Row in ExtraCostTable.Rows) { Row.Delete(); } if (ExtraCostTable != null) { PcExtraCostAccess.SubmitChanges(ExtraCostTable, Transaction); } // remove attendee AttendeeRow.Delete(); } } int shorttermApplicationsCount = MainDS.PmShortTermApplication.Count; int attendeeCount = MainDS.PcAttendee.Count; MainDS.ThrowAwayAfterSubmitChanges = true; ConferenceApplicationTDSAccess.SubmitChanges(MainDS); }); }
/// <summary> /// Returns the room allocation for this attendee. /// </summary> /// <param name="ASituation"></param> /// <param name="APartnerKey"></param> /// <param name="AFromDate"></param> /// <param name="AToDate"></param> /// <returns></returns> private int GetRoomAllocatedNightsBetween(ref TRptSituation ASituation, long APartnerKey, DateTime AFromDate, DateTime AToDate) { PcRoomAllocTable RoomAllocTable = new PcRoomAllocTable(); PcRoomAllocRow TemplateRow = (PcRoomAllocRow)RoomAllocTable.NewRow(); TemplateRow.PartnerKey = APartnerKey; int Nights = 0; RoomAllocTable = PcRoomAllocAccess.LoadUsingTemplate(TemplateRow, ASituation.GetDatabaseConnection().Transaction); foreach (PcRoomAllocRow RoomAllocRow in RoomAllocTable.Rows) { if ((RoomAllocRow.Out.Value.CompareTo(AFromDate) < 1) || (RoomAllocRow.In.CompareTo(AToDate) > 0)) { continue; } if (RoomAllocRow.In.CompareTo(AFromDate) < 0) { RoomAllocRow.In = AFromDate; } if (RoomAllocRow.Out.Value.CompareTo(AToDate) > 0) { RoomAllocRow.Out = AToDate; } Nights = Nights + RoomAllocRow.Out.Value.Subtract(RoomAllocRow.In).Days; } if (Nights <= 0) { //If no accommodation allocated, charge for full period Nights = AToDate.Subtract(AFromDate).Days; } return Nights; }
/// <summary> /// Adds the dates of one partner to the accommodation report /// </summary> /// <param name="AShortTermRow">The short term application row of the current partner</param> /// <param name="AAttendeeRow">The attendee row of the current partner</param> /// <param name="AStartDate">Start date of the conference</param> /// <param name="AEndDate">End date of the conference</param> /// <param name="AFromDate">Start date of the report</param> /// <param name="AToDate">End date of the report</param> /// <param name="AReportDetail">Indicator of the details of the report. Possible options: Brief, Full, Detail</param> /// <param name="ASituation">The current report situation</param> /// <returns></returns> private bool AddPartnerToAccom(PmShortTermApplicationRow AShortTermRow, PcAttendeeRow AAttendeeRow, DateTime AStartDate, DateTime AEndDate, DateTime AFromDate, DateTime AToDate, string AReportDetail, ref TRptSituation ASituation) { // if we have an actual arrival and departure date from the attendee row use it. if (AAttendeeRow != null) { if (!AAttendeeRow.IsActualArrNull()) { AShortTermRow.Arrival = AAttendeeRow.ActualArr; } if (!AAttendeeRow.IsActualDepNull()) { AShortTermRow.Departure = AAttendeeRow.ActualDep; } } if (AShortTermRow.IsArrivalNull()) { AShortTermRow.Arrival = AStartDate; } if (AShortTermRow.IsDepartureNull()) { AShortTermRow.Departure = AEndDate; } if ((AShortTermRow.Arrival <= AToDate) && (AShortTermRow.Departure >= AFromDate)) { // this short term application covers the dates we examine PcRoomAllocTable TempTable = new PcRoomAllocTable(); PcRoomAllocTable RoomAllocTable; PcRoomAllocRow TemplateRow = TempTable.NewRowTyped(false); TemplateRow.PartnerKey = AShortTermRow.PartnerKey; TemplateRow.ConferenceKey = AShortTermRow.StConfirmedOption; RoomAllocTable = PcRoomAllocAccess.LoadUsingTemplate(TemplateRow, ASituation.GetDatabaseConnection().Transaction); char Gender; int Age; string PartnerName; GetGenderAndAge(AShortTermRow.PartnerKey, AStartDate, out Gender, out Age, ref ASituation); PartnerName = TAccommodationReportCalculation.GetPartnerShortName(AShortTermRow.PartnerKey, ref ASituation); foreach (DataRow Row in RoomAllocTable.Rows) { CheckRoomAllocation((PcRoomAllocRow)Row, AShortTermRow, AFromDate, AToDate, AReportDetail, Gender, Age, PartnerName, ref ASituation); } if (RoomAllocTable.Rows.Count == 0) { AddNoRoomBooking(AShortTermRow, AFromDate, AToDate, Gender, PartnerName); } } return(true); }