Пример #1
0
        public List <EmployeeWeek> BuildEmployeeWeeks(long storeid, long worldid, DateTime aBegin, DateTime aEnd, bool bPlanning)
        {
            Store store = ServerEnvironment.StoreService.FindById(storeid);

            if (store == null)
            {
                return(null);
            }
            long countryid = store.CountryID;
            bool IsAustria = store.CountryID == ServerEnvironment.CountryService.AustriaCountryID;


            // list of all employee for storeid and world
            IList employees = EmployeeService.EmployeeDao.GetPlanningEmployeesByWorld(storeid, worldid, aBegin, aEnd);

            if (employees == null && employees.Count == 0)
            {
                return(null);
            }

            long[] ids = new long[employees.Count];
            for (int i = 0; i < employees.Count; i++)
            {
                ids[i] = (employees[i] as Employee).ID;
            }

            EmployeeRelationService relationService = EmployeeService.EmployeeRelationService as EmployeeRelationService;

            List <EmployeeRelation> emplRelations = relationService.GetEmployeeRelationsByEmployeeIds(ids, aBegin, aEnd);

            //CountryStoreWorldManager swmanager = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
            //swmanager.StoreId = storeid;
            if (swCountryManager == null)
            {
                //long countryid = EmployeeService.StoreService.GetCountryByStoreId(storeid);
                swCountryManager           = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
                swCountryManager.CountryId = countryid;
            }

            List <EmployeeLongTimeAbsence> emplLongTimeAbsences =
                EmployeeService.EmployeeLongTimeAbsenceService.GetEmployeesHasLongTimeAbsence(ids, aBegin, aEnd);

            EmployeeLongTimeAbsenceIndexer absenceIndexer = new EmployeeLongTimeAbsenceIndexer(emplLongTimeAbsences);

            DictionListEmployeeRelations relationIndexer = new DictionListEmployeeRelations(emplRelations);

            List <EmployeeContract> contracts = EmployeeService.EmployeeContractService.GetEmployeeContracts(ids, aBegin, aEnd);

            ContractIndexer = new DictionListEmployeesContract(contracts);


            // applly relations
            EmployeeRelation relationWorld     = null;
            bool             bExistsRelation   = false;
            bool             bExistsContract   = false;
            bool             bNotExistsAbsence = true;

            _listweeks = new List <EmployeeWeek>();
            EmployeeWeek emplWeek = null;


            foreach (Employee empl in employees)
            {
                emplWeek           = new EmployeeWeek(empl.ID, empl.FullName, aBegin, aEnd, empl.OrderHwgrID.HasValue ? empl.OrderHwgrID.Value : 0);
                emplWeek.LastSaldo = (int)Math.Round(empl.BalanceHours);
                bExistsRelation    = false;

                foreach (EmployeeDay d in emplWeek.DaysList)
                {
                    relationWorld = relationIndexer.GetRelationEntity(empl.ID, d.Date);
                    if (relationWorld != null)
                    {
                        d.StoreWorldId = swCountryManager.GetStoreWorldIdByStoreAndWorldId(relationWorld.StoreID, relationWorld.WorldID.Value);
                        d.StoreId      = relationWorld.StoreID;
                    }

                    bExistsRelation |= d.HasRelation;
                }
                if (bExistsRelation)
                {
                    bExistsContract = ContractIndexer.FillEmployeeWeek(emplWeek);
                    if (bExistsContract)
                    {
                        bNotExistsAbsence = absenceIndexer.FillEmployeeWeek(emplWeek);

                        if (bNotExistsAbsence)
                        {
                            _listweeks.Add(emplWeek);
                        }
                    }
                }
            }

            FillEmployeeDayByStoreDay(storeid, aBegin, aEnd);

            _dictionWeek = EmployeeWeekProcessor.GetDictionary(_listweeks);
            _employeeids = EmployeeWeekProcessor.GetEmployeeIds(_listweeks);


            if (bPlanning)
            {
                FillPlanningEmployeeWeeks(storeid, worldid, aBegin, aEnd);
            }
            else
            {
                FillActualEmployeeWeeks(storeid, worldid, aBegin, aEnd);
            }

            //LastSaldoBuilder saldoBuilder = new LastSaldoBuilder();
            LastSaldoBuilder saldoBuilder = (IsAustria) ? new LastSaldoBuilderAustria() : new LastSaldoBuilder();



            saldoBuilder.FillLastSaldo(_dictionWeek, _employeeids, aBegin, bPlanning);

            EmployeeMonthWorkingTime monthData = new EmployeeMonthWorkingTime(EmployeeService.EmployeeTimeService as EmployeeTimeService);

            monthData.IsPlanning    = bPlanning;
            monthData.CurrentMonday = aBegin;
            CacheEmployeesAllIn managerAllIn = new CacheEmployeesAllIn();

            managerAllIn.LoadByStoreRelation(storeid);

            foreach (EmployeeWeek ew in _listweeks)
            {
                ew.WorkingTimeByMonth = monthData.GetMonthWorkingTime(ew.EmployeeId);
                ew.CountSaturday      = (byte)monthData.CountSaturday;
                ew.CountSunday        = (byte)monthData.CountSunday;

                ew.WorkingDaysBefore = (byte)monthData.WorkingDaysBefore;
                ew.WorkingDaysAfter  = (byte)monthData.WorkingDaysAfter;
                ew.AllIn             = managerAllIn.GetAllIn(ew.EmployeeId, aBegin, aEnd);
            }

            return(_listweeks);
        }
Пример #2
0
        public List<EmployeeWeek> BuildEmployeeWeeks(long storeid, long worldid, DateTime aBegin, DateTime aEnd, bool bPlanning)
        {
            Store store = ServerEnvironment.StoreService.FindById(storeid);

            if (store == null)
                return null;
            long countryid = store.CountryID;
            bool IsAustria = store.CountryID == ServerEnvironment.CountryService.AustriaCountryID;

            // list of all employee for storeid and world
            IList employees = EmployeeService.EmployeeDao.GetPlanningEmployeesByWorld(storeid, worldid, aBegin, aEnd);

            if (employees == null && employees.Count == 0) return null;

            long[] ids = new long[employees.Count];
            for (int i = 0; i < employees.Count; i++)
            {
                ids[i] = (employees[i] as Employee).ID;
            }

            EmployeeRelationService relationService = EmployeeService.EmployeeRelationService as EmployeeRelationService;

            List<EmployeeRelation> emplRelations = relationService.GetEmployeeRelationsByEmployeeIds(ids, aBegin, aEnd);

            //CountryStoreWorldManager swmanager = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
            //swmanager.StoreId = storeid;
            if (swCountryManager == null)
            {
                //long countryid = EmployeeService.StoreService.GetCountryByStoreId(storeid);
                swCountryManager = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
                swCountryManager.CountryId = countryid;
            }

            List<EmployeeLongTimeAbsence> emplLongTimeAbsences =
                EmployeeService.EmployeeLongTimeAbsenceService.GetEmployeesHasLongTimeAbsence(ids, aBegin, aEnd);

            EmployeeLongTimeAbsenceIndexer absenceIndexer = new EmployeeLongTimeAbsenceIndexer(emplLongTimeAbsences);

            DictionListEmployeeRelations relationIndexer = new DictionListEmployeeRelations(emplRelations);

            List<EmployeeContract> contracts = EmployeeService.EmployeeContractService.GetEmployeeContracts(ids, aBegin, aEnd);
            ContractIndexer = new DictionListEmployeesContract(contracts);

            // applly relations
            EmployeeRelation relationWorld = null;
            bool bExistsRelation = false;
            bool bExistsContract = false;
            bool bNotExistsAbsence = true;

            _listweeks = new List<EmployeeWeek>();
            EmployeeWeek emplWeek = null;

            foreach (Employee empl in employees)
            {
                emplWeek = new EmployeeWeek(empl.ID, empl.FullName, aBegin, aEnd, empl.OrderHwgrID.HasValue ? empl.OrderHwgrID.Value : 0);
                emplWeek.LastSaldo = (int)Math.Round(empl.BalanceHours);
                bExistsRelation = false;

                foreach (EmployeeDay d in emplWeek.DaysList)
                {
                    relationWorld = relationIndexer.GetRelationEntity(empl.ID, d.Date);
                    if (relationWorld != null)
                    {
                        d.StoreWorldId = swCountryManager.GetStoreWorldIdByStoreAndWorldId (relationWorld.StoreID, relationWorld.WorldID.Value);
                        d.StoreId = relationWorld.StoreID;
                    }

                    bExistsRelation |= d.HasRelation;
                }
                if (bExistsRelation)
                {
                    bExistsContract = ContractIndexer.FillEmployeeWeek(emplWeek);
                    if (bExistsContract)
                    {
                        bNotExistsAbsence = absenceIndexer.FillEmployeeWeek(emplWeek);

                        if (bNotExistsAbsence)
                        {
                            _listweeks.Add(emplWeek);
                        }
                    }
                }
            }

            FillEmployeeDayByStoreDay(storeid, aBegin, aEnd);

            _dictionWeek = EmployeeWeekProcessor.GetDictionary(_listweeks);
            _employeeids = EmployeeWeekProcessor.GetEmployeeIds(_listweeks);

            if (bPlanning)
                FillPlanningEmployeeWeeks(storeid, worldid, aBegin, aEnd);
            else
                FillActualEmployeeWeeks(storeid, worldid, aBegin, aEnd);

            //LastSaldoBuilder saldoBuilder = new LastSaldoBuilder();
            LastSaldoBuilder saldoBuilder = (IsAustria) ? new LastSaldoBuilderAustria() : new LastSaldoBuilder();

            saldoBuilder.FillLastSaldo(_dictionWeek, _employeeids, aBegin, bPlanning);

            EmployeeMonthWorkingTime monthData = new EmployeeMonthWorkingTime(EmployeeService.EmployeeTimeService as EmployeeTimeService);
            monthData.IsPlanning = bPlanning;
            monthData.CurrentMonday = aBegin;
            CacheEmployeesAllIn managerAllIn = new CacheEmployeesAllIn();
            managerAllIn.LoadByStoreRelation(storeid);

            foreach (EmployeeWeek ew in _listweeks)
            {
               ew.WorkingTimeByMonth = monthData.GetMonthWorkingTime(ew.EmployeeId);
               ew.CountSaturday = (byte)monthData.CountSaturday;
               ew.CountSunday = (byte)monthData.CountSunday;

               ew.WorkingDaysBefore = (byte)monthData.WorkingDaysBefore;
               ew.WorkingDaysAfter = (byte)monthData.WorkingDaysAfter;
               ew.AllIn = managerAllIn.GetAllIn(ew.EmployeeId, aBegin, aEnd);

            }

            return _listweeks;
        }