/// <summary>
        /// Main entry point for calculating the accommodation report.
        /// This must be called for each partner in each conference.
        /// </summary>
        /// <param name="AConferenceKey">Conference Key of the current conference to examine</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="APartnerKey">Partner Key of the current partner to examine</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>
        public bool CalculatePartnerAccom(long AConferenceKey,
                                          DateTime AStartDate, DateTime AEndDate,
                                          DateTime AFromDate, DateTime AToDate,
                                          long APartnerKey, string AReportDetail,
                                          ref TRptSituation ASituation)
        {
            PcAttendeeTable             AttendeeTable;
            PcAttendeeRow               AttendeeRow = null;
            PmShortTermApplicationTable ShortTermTable;
            PmShortTermApplicationTable TmpTable = new PmShortTermApplicationTable();
            PmShortTermApplicationRow   TemplateRow;


            TemplateRow                   = TmpTable.NewRowTyped(false);
            TemplateRow.PartnerKey        = APartnerKey;
            TemplateRow.StConfirmedOption = AConferenceKey;

            if (FAccommodationTable == null)
            {
                InitAccomTable(AFromDate, AToDate);
            }

            AttendeeTable = PcAttendeeAccess.LoadByPrimaryKey(AConferenceKey, APartnerKey, ASituation.GetDatabaseConnection().Transaction);

            if (AttendeeTable.Rows.Count > 0)
            {
                AttendeeRow = (PcAttendeeRow)AttendeeTable.Rows[0];
            }

            ShortTermTable = PmShortTermApplicationAccess.LoadUsingTemplate(TemplateRow, ASituation.GetDatabaseConnection().Transaction);

            foreach (DataRow Row in ShortTermTable.Rows)
            {
                AddPartnerToAccom((PmShortTermApplicationRow)Row, AttendeeRow, AStartDate, AEndDate,
                                  AFromDate, AToDate, AReportDetail, ref ASituation);
            }

            return(true);
        }
        /// <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;
        }
Пример #3
0
        /// <summary>
        /// return a list of all applicants for a given event,
        /// but if AConferenceOrganisingOffice is false,
        /// consider only the registration office that the user has permissions for, ie. Module REG-00xx0000000
        /// </summary>
        /// <param name="AMainDS"></param>
        /// <param name="AEventPartnerKey">The ConferenceKey</param>
        /// <param name="AEventCode">The OutreachPrefix</param>
        /// <param name="AApplicationStatus"></param>
        /// <param name="ARegistrationOffice">if -1, then show all offices that the user has permission for</param>
        /// <param name="AConferenceOrganisingOffice">if true, all offices are considered</param>
        /// <param name="ARole"></param>
        /// <param name="AClearJSONData"></param>
        /// <returns></returns>
        public static bool GetApplications(
            ref ConferenceApplicationTDS AMainDS,
            Int64 AEventPartnerKey,
            string AEventCode,
            string AApplicationStatus,
            Int64 ARegistrationOffice,
            bool AConferenceOrganisingOffice,
            string ARole,
            bool AClearJSONData)
        {
            TDBTransaction           Transaction = null;
            ConferenceApplicationTDS MainDS      = new ConferenceApplicationTDS();

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(
                IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum,
                ref Transaction,
                delegate
            {
                // load all attendees of this conference.
                // only load once: GetApplications might be called for several application stati
                if (MainDS.PcAttendee.Rows.Count == 0)
                {
                    PcAttendeeRow templateAttendeeRow = MainDS.PcAttendee.NewRowTyped(false);
                    templateAttendeeRow.ConferenceKey = AEventPartnerKey;
                    PcAttendeeAccess.LoadUsingTemplate(MainDS, templateAttendeeRow, Transaction);
                    MainDS.PcAttendee.DefaultView.Sort = PcAttendeeTable.GetPartnerKeyDBName();
                }

                if (AConferenceOrganisingOffice && (ARegistrationOffice == -1))
                {
                    // avoid duplicates, who are registered by one office, but charged to another office
                    GetApplications(ref MainDS, AEventCode, -1, AApplicationStatus, ARole, AClearJSONData, Transaction);
                }
                else
                {
                    List <Int64> AllowedRegistrationOffices = GetRegistrationOfficeKeysOfUser(Transaction);

                    foreach (Int64 RegistrationOffice in AllowedRegistrationOffices)
                    {
                        if ((ARegistrationOffice == RegistrationOffice) || (ARegistrationOffice == -1))
                        {
                            GetApplications(ref MainDS, AEventCode, RegistrationOffice, AApplicationStatus, ARole, AClearJSONData, Transaction);
                        }
                    }
                }

                // required for DefaultView.Find
                MainDS.PmShortTermApplication.DefaultView.Sort =
                    PmShortTermApplicationTable.GetStConfirmedOptionDBName() + "," +
                    PmShortTermApplicationTable.GetPartnerKeyDBName();
                MainDS.PmGeneralApplication.DefaultView.Sort =
                    PmGeneralApplicationTable.GetPartnerKeyDBName() + "," +
                    PmGeneralApplicationTable.GetApplicationKeyDBName() + "," +
                    PmGeneralApplicationTable.GetRegistrationOfficeDBName();
                MainDS.PDataLabelValuePartner.DefaultView.Sort = PDataLabelValuePartnerTable.GetDataLabelKeyDBName() + "," +
                                                                 PDataLabelValuePartnerTable.GetPartnerKeyDBName();
                MainDS.PDataLabel.DefaultView.Sort = PDataLabelTable.GetTextDBName();
            });

            AMainDS = MainDS;

            if (AMainDS.HasChanges())
            {
                AMainDS.EnforceConstraints = false;
                AMainDS.AcceptChanges();
            }

            return(true);
        }
Пример #4
0
        /// <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>
        /// 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);
        }