예제 #1
0
		public DayTrackViewModel(DayTimeTrack dayTimeTrack, TimeTrackFilter timeTrackFilter, ShortEmployee shortEmployee)
		{
			DayTimeTrack = dayTimeTrack;
			TimeTrackFilter = timeTrackFilter;
			ShortEmployee = shortEmployee;
			Update();
		}
		public TimeTrackPartDetailsViewModel(DayTimeTrack dayTimeTrack, ShortEmployee employee, TimeTrackDetailsViewModel parent, Guid? uid = null, TimeSpan? enterTime = null, TimeSpan? exitTime = null)
		{
			_DayTimeTrack = dayTimeTrack;
			_Employee = employee;
			_Parent = parent;
			if (uid != null)
			{
				UID = uid.Value;
				EnterTime = enterTime.Value;
				ExitTime = exitTime.Value;
				Title = "Редактировать проход";
			}
			else
			{
				UID = Guid.NewGuid();
				_IsNew = true;
				Title = "Добавить проход";
			}

			var schedule = ScheduleHelper.GetSingle(employee.ScheduleUID);
			if (schedule != null)
			{
				Zones = new ObservableCollection<TimeTrackZone>();

				var gkZones = GKManager.SKDZones.Where(x => schedule.Zones.Any(y => y.ZoneUID == x.UID));
				foreach (var zone in gkZones)
				{
					Zones.Add(new TimeTrackZone(zone));
				}

				SelectedZone = Zones.FirstOrDefault();
			}
		}
예제 #3
0
		public TimeTrackDetailsViewModel(DayTimeTrack dayTimeTrack, ShortEmployee shortEmployee)
		{
			dayTimeTrack.Calculate();

			Title = "Время сотрудника " + shortEmployee.FIO + " в течение дня " + dayTimeTrack.Date.Date.ToString("yyyy-MM-dd");
			AddCommand = new RelayCommand(OnAdd, CanAdd);
			EditCommand = new RelayCommand(OnEdit, CanEdit);
			RemoveCommand = new RelayCommand(OnRemove, CanRemove);
			AddFileCommand = new RelayCommand(OnAddFile, CanAddFile);
			OpenFileCommand = new RelayCommand(OnOpenFile, CanOpenFile);
			RemoveFileCommand = new RelayCommand(OnRemoveFile, CanRemoveFile);
			AddCustomPartCommand = new RelayCommand(OnAddCustomPart, CanAddPart);
			RemovePartCommand = new RelayCommand(OnRemovePart, CanEditRemovePart);
			EditPartCommand = new RelayCommand(OnEditPart, CanEditRemovePart);
			DayTimeTrack = dayTimeTrack;
			ShortEmployee = shortEmployee;

			DayTimeTrackParts = new ObservableCollection<DayTimeTrackPartViewModel>();
			foreach (var timeTrackPart in DayTimeTrack.RealTimeTrackParts)
			{
				var employeeTimeTrackPartViewModel = new DayTimeTrackPartViewModel(timeTrackPart);
				DayTimeTrackParts.Add(employeeTimeTrackPartViewModel);
			}

			Documents = new ObservableCollection<DocumentViewModel>();
			foreach (var document in dayTimeTrack.Documents)
			{
				if (document.EndDateTime > dayTimeTrack.Date.Date)
				{
					var documentViewModel = new DocumentViewModel(document);
					Documents.Add(documentViewModel);
				}
			}
		}
예제 #4
0
		public DayTimeTrack GetRealTimeTrack(Guid employeeUID, IEnumerable<ScheduleZone> scheduleZones, DateTime date, IEnumerable<PassJournal> passJournals)
		{
			var dayTimeTrack = new DayTimeTrack();
			dayTimeTrack.Date = date;

			foreach (var passJournal in passJournals.Where(x => x.EmployeeUID == employeeUID
				&& x.EnterTime != null && x.EnterTime.Date <= date.Date
				&& x.ExitTime != null && x.ExitTime.Value.Date >= date.Date
				&& scheduleZones.Select(scheduleZone => scheduleZone.ZoneUID).Contains(x.ZoneUID)).ToList())
			{
				var startTime = new TimeSpan();
				var endTime = new TimeSpan();
				var startsInPreviousDay = false;
				var endsInNextDay = false;
				var enterTime = passJournal.EnterTime;
				var exitTime = passJournal.ExitTime.Value;
				if (enterTime.Date == date && exitTime.Date >= date)
				{
					startTime = enterTime.TimeOfDay;
					if (exitTime.Date == date)
						endTime = exitTime.TimeOfDay;
					else if (exitTime.Date > date)
						endTime = TimeSpan.FromDays(1);
					endsInNextDay = exitTime.Date > date;
				}
				else if (enterTime.Date < date && exitTime.Date == date)
				{
					startTime = TimeSpan.Zero; ;
					endTime = exitTime.TimeOfDay;
					startsInPreviousDay = true;
				}
				else if (enterTime.Date < date && exitTime.Date > date)
				{
					startTime = TimeSpan.Zero; ;
					endTime = TimeSpan.FromDays(1);
					startsInPreviousDay = true;
					endsInNextDay = true;
				}

				if (passJournal.ExitTime.HasValue)
				{
					var timeTrackPart = new TimeTrackPart()
					{
						StartTime = startTime,
						EndTime = endTime,
						ZoneUID = passJournal.ZoneUID,
						PassJournalUID = passJournal.UID,
						StartsInPreviousDay = startsInPreviousDay,
						EndsInNextDay = endsInNextDay
					};
					dayTimeTrack.RealTimeTrackParts.Add(timeTrackPart);
				}
			}
			dayTimeTrack.RealTimeTrackParts = dayTimeTrack.RealTimeTrackParts.OrderBy(x => x.StartTime.Ticks).ToList();
			return dayTimeTrack;
		}
예제 #5
0
		public OperationResult<TimeTrackResult> GetTimeTracks(EmployeeFilter filter, DateTime startDate, DateTime endDate)
		{
			return DbServiceHelper.InTryCatch(() =>
			{
				var operationResult = DbService.EmployeeTranslator.ShortTranslator.Get(filter);
				if (operationResult.HasError)
					throw new Exception(operationResult.Error);
				var employees = DbService.EmployeeTranslator.GetFilteredTableItems(filter, GetEmployeeTableItems());
				var employeeUIDs = employees.Select(x => x.UID).ToList();
				var passJournals = Context.PassJournals.Where(x => x.EmployeeUID != null && employeeUIDs.Contains(x.EmployeeUID.Value)).ToList();
				var timeTrackResult = new TimeTrackResult();
				foreach (var employee in employees)
				{
					var timeTrackEmployeeResult = GetEmployeeTimeTrack(employee, startDate, endDate, passJournals);
					timeTrackEmployeeResult.ShortEmployee = DbService.EmployeeTranslator.ShortTranslator.Translate(employee);
					if (timeTrackEmployeeResult.Error != null)
					{
						for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
						{
							var dayTimeTrack = new DayTimeTrack();
							dayTimeTrack.Error = timeTrackEmployeeResult.Error;
							dayTimeTrack.Date = date;
							timeTrackEmployeeResult.DayTimeTracks.Add(dayTimeTrack);
						}
					}

					var documentsOperationResult = DbService.TimeTrackDocumentTranslator.Get(employee.UID, startDate, endDate, employee.TimeTrackDocuments);
					if (!documentsOperationResult.HasError)
					{
						var documents = documentsOperationResult.Result;
						foreach (var document in documents)
						{
							document.TimeTrackDocumentType = TimeTrackDocumentTypesCollection.TimeTrackDocumentTypes.FirstOrDefault(x => x.Code == document.DocumentCode);
							if (document.TimeTrackDocumentType == null)
							{
								var documentType = employee.Organisation.TimeTrackDocumnetTypes.FirstOrDefault(x => x.DocumentCode == document.DocumentCode);
								if (documentType != null)
								{
									document.TimeTrackDocumentType = DbService.TimeTrackDocumentTypeTranslator.Translate(documentType);
								}
							}
							if (document.TimeTrackDocumentType != null)
							{
								timeTrackEmployeeResult.Documents.Add(document);
							}
						}

						foreach (var document in timeTrackEmployeeResult.Documents)
						{
							for (DateTime date = document.StartDateTime; date < new DateTime(document.EndDateTime.Year, document.EndDateTime.Month, document.EndDateTime.Day).AddDays(1); date = date.AddDays(1))
							{
								var dayTimeTracks = timeTrackEmployeeResult.DayTimeTracks.FirstOrDefault(x => x.Date.Date == date.Date);
								if (dayTimeTracks != null)
								{
									dayTimeTracks.Documents.Add(document);
								}
							}
						}
					}

					timeTrackResult.TimeTrackEmployeeResults.Add(timeTrackEmployeeResult);
				}
				return timeTrackResult;
			});
		}