protected static FR_L6LR_GLRS_M_1706 Execute(DbConnection Connection, DbTransaction Transaction, P_L6LR_GLRS_M_1706 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6LR_GLRS_M_1706();

            DateTime start = Parameter.StartDate;
            DateTime end   = Parameter.EndDate;
            #region  get events
            P_L5LR_EV_TSD_1047 param = new P_L5LR_EV_TSD_1047()
            {
                EndDate   = end,
                StartDate = start
            };
            L5LR_EV_TSD_1047[] Events = cls_Get_Events_for_Timespan_Data.Invoke(Connection, Transaction, param, securityTicket).Result;
            #endregion get events

            #region leave request duration
            var employeeAndLrData = cls_Get_Employees_And_LeaveRequestData_For_IDList.Invoke(Connection, Transaction, new P_L5EM_GEALRDFIDL_1138 {
                EmployeeIDList = new Guid[] { Parameter.ForPerson }
            }, securityTicket).Result.FirstOrDefault();
            L5_EM_GEWI_1628 intervalsActiveContract = cls_Get_Employee_WorktimeIntervals.Invoke(Connection, Transaction, securityTicket).Result.SingleOrDefault();

            double leaveDuration = new L6LR_GLR_ID_1339().duration(intervalsActiveContract, Events, Parameter.StartDate, Parameter.EndDate, employeeAndLrData.IsWorkTimeCalculated_InDays);

            #endregion leave request duration

            var contractToReason = employeeAndLrData.WorkingContract2LeaveRequest.Where(cr => cr.CMN_BPT_STA_AbsenceReasonID == Parameter.AbsenceResonID).FirstOrDefault();
            //var reasonsAndAdjustment = cls_Get_AbsenceReason_And_Adjustments_For_Employee.Invoke(Connection, Transaction, new P_L5EM_GARaAFE_1612 {AbsenceReason_ID = Parameter.AbsenceResonID }, securityTicket).Result;
            var calculationTimeframe = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.Where(x => x.CalculationTimeframe_StartDate.Year == Parameter.StartDate.Year).FirstOrDefault();
            P_L5EM_GEATFSbRTFE_1423 statisticsParameter = new P_L5EM_GEATFSbRTFE_1423
            {
                absenceReasonID = Parameter.AbsenceResonID,
                employeeID      = Parameter.ForPerson,
                timeFrameID     = calculationTimeframe.CMN_CAL_CalculationTimeframeID
            };
            L5EM_GEATFSbRTFE_1423 EmployeeStatistics = cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.Invoke(Connection, Transaction, statisticsParameter, securityTicket).Result;
            if (EmployeeStatistics == null)
            {
                EmployeeStatistics = new L5EM_GEATFSbRTFE_1423();
            }
            double adjustment = 0;
            if (contractToReason != null && contractToReason.Adjustments != null)
            {
                foreach (var adj in contractToReason.Adjustments)
                {
                    if (employeeAndLrData.IsWorkTimeCalculated_InDays)
                    {
                        adjustment += (double)adj.AbsenceTime_InMinutes / 60;
                        double hours = Math.Abs((double)adj.AbsenceTime_InMinutes / 60);
                        double days  = 0;
                        while (hours > 0)
                        {
                            foreach (var officehours in employeeAndLrData.WeeklyOfficeHours)
                            {
                                double dayDuration = (double)(officehours.TimeTo_InMinutes - officehours.TimeFrom_InMinutes) / 60;
                                hours -= dayDuration;
                                if (officehours.IsWholeDay)
                                {
                                    days += 1;
                                }
                                else
                                {
                                    days += 0.5;
                                }
                                if (hours <= 0)
                                {
                                    break;
                                }
                            }
                        }
                        adjustment = days;
                    }
                    else
                    {
                        adjustment += (double)adj.AbsenceTime_InMinutes / 60;
                    }
                }
            }
            if (contractToReason == null)
            {
                contractToReason = new L5EM_GEALRDFIDL_1138_WorkingContract2LeaveRequest();//fuj
            }

            #region assign result
            L6LR_GLRS_M_1706 Result = null;
            if (employeeAndLrData.IsWorkTimeCalculated_InDays)
            {
                Result = new L6LR_GLRS_M_1706
                {
                    FromLastyear    = EmployeeStatistics.R_AbsenceCarryOver_InDays,
                    PlannedAndTaken = EmployeeStatistics.R_RequestReservedAbsence_InDays + EmployeeStatistics.R_AbsenceTimeUsed_InDays - Parameter.SavedLeaveDuration,

                    FromThisYear     = contractToReason.ContractAllowedAbsence_per_Month,
                    ThisRequest      = leaveDuration,
                    isAllowedAbsence = contractToReason.IsAllowedAbsence,
                    adjustment       = adjustment,
                };
                Result.Remaining = (Result.FromLastyear + Result.FromThisYear) - (Result.PlannedAndTaken + Result.ThisRequest + Math.Abs(Result.adjustment));
            }
            else
            {
                Result = new L6LR_GLRS_M_1706
                {
                    FromLastyear    = EmployeeStatistics.R_AbsenceCarryOver_InHours,
                    PlannedAndTaken = EmployeeStatistics.R_RequestReservedAbsence_InHours + EmployeeStatistics.R_AbsenceTimeUsed_InHours - Parameter.SavedLeaveDuration,

                    FromThisYear     = contractToReason.ContractAllowedAbsence_per_Month,
                    ThisRequest      = leaveDuration,
                    isAllowedAbsence = contractToReason.IsAllowedAbsence,
                    adjustment       = adjustment,
                };
                Result.Remaining = (Result.FromLastyear + Result.FromThisYear) - (Result.PlannedAndTaken + Result.ThisRequest + Math.Abs(Result.adjustment));
            }
            returnValue.Result = Result;
            #endregion assign result
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 2
0
        protected static FR_L5EM_GEATFSbRTFE_1423 Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_GEATFSbRTFE_1423 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            var returnStatus = new FR_L5EM_GEATFSbRTFE_1423();

            DbCommand command = Connection.CreateCommand();

            command.Connection  = Connection;
            command.Transaction = Transaction;
            var commandLocation = "CL5_VacationPlanner_Contract.Atomic.Retrieval.SQL.cls_Get_Employee_AbsenceReason_TimeframeStatistic_byReasonTimeFrameEmployee.sql";

            command.CommandText = new System.IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(commandLocation)).ReadToEnd();
            CSV2Core_MySQL.Support.DBSQLSupport.SetParameter(command, "ticket", securityTicket);
            command.CommandTimeout = QueryTimeout;
            CSV2Core_MySQL.Support.DBSQLSupport.SetParameter(command, "employeeID", Parameter.employeeID);
            CSV2Core_MySQL.Support.DBSQLSupport.SetParameter(command, "timeFrameID", Parameter.timeFrameID);
            CSV2Core_MySQL.Support.DBSQLSupport.SetParameter(command, "absenceReasonID", Parameter.absenceReasonID);


            List <L5EM_GEATFSbRTFE_1423> results = new List <L5EM_GEATFSbRTFE_1423>();
            var loader = new CSV2Core_MySQL.Dictionaries.MultiTable.Loader.DictionaryLoader(Connection, Transaction);
            var reader = new CSV2Core_MySQL.Support.DBSQLReader(command.ExecuteReader());

            try
            {
                reader.SetOrdinals(new string[] { "CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID", "CalculationTimeframe_RefID", "Employee_RefID", "AbsenceReason_RefID", "R_AbsenceCarryOver_InHours", "R_AbsenceCarryOver_InDays", "R_AbsenceTimeUsed_InHours", "R_AbsenceTimeUsed_InDays", "R_RequestReservedAbsence_InHours", "R_RequestReservedAbsence_InDays", "R_TotalAllowedAbsenceTime_InHours", "R_TotalAllowedAbsenceTime_InDays" });
                while (reader.Read())
                {
                    L5EM_GEATFSbRTFE_1423 resultItem = new L5EM_GEATFSbRTFE_1423();
                    //0:Parameter CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID of type Guid
                    resultItem.CMN_BPT_EMP_Employee_AbsenceReason_TimeframeStatisticsID = reader.GetGuid(0);
                    //1:Parameter CalculationTimeframe_RefID of type Guid
                    resultItem.CalculationTimeframe_RefID = reader.GetGuid(1);
                    //2:Parameter Employee_RefID of type Guid
                    resultItem.Employee_RefID = reader.GetGuid(2);
                    //3:Parameter AbsenceReason_RefID of type Guid
                    resultItem.AbsenceReason_RefID = reader.GetGuid(3);
                    //4:Parameter R_AbsenceCarryOver_InHours of type double
                    resultItem.R_AbsenceCarryOver_InHours = reader.GetDouble(4);
                    //5:Parameter R_AbsenceCarryOver_InDays of type double
                    resultItem.R_AbsenceCarryOver_InDays = reader.GetDouble(5);
                    //6:Parameter R_AbsenceTimeUsed_InHours of type double
                    resultItem.R_AbsenceTimeUsed_InHours = reader.GetDouble(6);
                    //7:Parameter R_AbsenceTimeUsed_InDays of type double
                    resultItem.R_AbsenceTimeUsed_InDays = reader.GetDouble(7);
                    //8:Parameter R_RequestReservedAbsence_InHours of type double
                    resultItem.R_RequestReservedAbsence_InHours = reader.GetDouble(8);
                    //9:Parameter R_RequestReservedAbsence_InDays of type double
                    resultItem.R_RequestReservedAbsence_InDays = reader.GetDouble(9);
                    //10:Parameter R_TotalAllowedAbsenceTime_InHours of type double
                    resultItem.R_TotalAllowedAbsenceTime_InHours = reader.GetDouble(10);
                    //11:Parameter R_TotalAllowedAbsenceTime_InDays of type double
                    resultItem.R_TotalAllowedAbsenceTime_InDays = reader.GetDouble(11);

                    results.Add(resultItem);
                }
            }
            catch (Exception ex)
            {
                reader.Close();
                throw ex;
            }
            reader.Close();
            //Load all the dictionaries from the datatables
            loader.Load();

            returnStatus.Result = results.FirstOrDefault();
            return(returnStatus);
        }