/// <summary> /// Transits the shift object status and trigger associated operations. /// </summary> /// <param name="shift">The shift object.</param> public void TransitShiftStatus(Shift shift) { ThrowIf.Null(shift, "shift"); ShiftStatus toStatus = this.request.ToStatus; Action <Shift> nextAction; if (!this.transitions.TryGetValue(new KeyValuePair <ShiftStatus, ShiftStatus>(shift.Status, toStatus), out nextAction)) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidStatus, string.Format("Invalid status change request from {0} to {1}.", shift.Status, toStatus)); } // Validates if the shift status transition is allowable this.ValidateCanChangeStatus(shift); // Validate start amount and tender declaration if required if (toStatus == ShiftStatus.Closed) { ShiftCalculator.Calculate(this.request.RequestContext, shift, this.request.ShiftTerminalId, this.request.ShiftId); this.ValidateStartingAmountsAndTenderDeclarationForClose(shift); } ThrowIf.Null(nextAction, "nextAction"); nextAction.Invoke(shift); }
public static void Main(string[] args) { var periods = new List <Period> { new Period("1", Days.Workdays, TimeSpan.FromHours(0), TimeSpan.FromHours(7)), new Period("2", Days.Workdays, TimeSpan.FromHours(7), TimeSpan.FromHours(20)), new Period("3", Days.Workdays, TimeSpan.FromHours(20), TimeSpan.FromHours(22)), new Period("4", Days.Workdays, TimeSpan.FromHours(22), TimeSpan.FromHours(24)), new Period("5", Days.Weekend, TimeSpan.FromHours(0), TimeSpan.FromHours(7)), new Period("6", Days.Weekend, TimeSpan.FromHours(7), TimeSpan.FromHours(22)), new Period("7", Days.Weekend, TimeSpan.FromHours(22), TimeSpan.FromHours(24)), new Period("8", Days.Holiday, TimeSpan.FromHours(0), TimeSpan.FromHours(24)), }; var holidays = new List <DateTime> { new DateTime(2017, 1, 1), new DateTime(2017, 1, 3), new DateTime(2017, 1, 6), }; var sc = new ShiftCalculator(periods, holidays); var shiftperiods = sc.GetShiftPeriods(new DateTime(2016, 12, 31, 22, 00, 00), new DateTime(2017, 01, 07, 08, 00, 00)).ToList(); foreach (var sp in shiftperiods) { Console.WriteLine("{0} - {1} - {2} - {3:00.00}h", sp.Period.Name, sp.Period.Days, sp.Start, sp.Duration.TotalHours); } }
private GetReceiptServiceRequest CreateXZReportReceiptServiceRequest(GetXAndZReportReceiptRequest request) { ThrowIf.Null(request, "request"); Shift shift; var shiftId = request.ShiftId; var receiptType = request.ReceiptType; // Validates if the request is XReport or ZReport type if ((receiptType != ReceiptType.XReport) && (receiptType != ReceiptType.ZReport)) { throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ReceiptTypeNotSupported, "Only receipt types for X or Z reports are expected."); } if (receiptType == ReceiptType.XReport) { var terminalId = request.ShiftTerminalId; GetShiftDataRequest getShiftDataRequest = new GetShiftDataRequest(terminalId, shiftId); shift = this.Context.Execute <SingleEntityDataServiceResponse <Shift> >(getShiftDataRequest).Entity; // Validates if an open or blind-closed shift of the ShiftId can be found when requesting XReport if (shift == null || (shift.Status != ShiftStatus.Open && shift.Status != ShiftStatus.BlindClosed)) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftNotFound, string.Format("No open shift information can be found using the shift Id {0} on terminal {1} for X report.", shiftId, terminalId)); } // Calculates the shift information inorder to generate the X report ShiftCalculator.Calculate(this.Context, shift, shift.TerminalId, shift.ShiftId); } else { var terminalId = this.Context.GetTerminal().TerminalId; GetLastClosedShiftDataRequest getLastClosedShiftDataRequest = new GetLastClosedShiftDataRequest(terminalId); shift = this.Context.Execute <SingleEntityDataServiceResponse <Shift> >(getLastClosedShiftDataRequest).Entity; // Validates if a closed shift of the ShiftId can be found when requesting XReport if (shift == null || shift.Status != ShiftStatus.Closed) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftNotFound, string.Format("No closed shift information can be found using the shift Id {0} on terminal {1} for Z report.", shiftId, terminalId)); } } var getReceiptServiceRequest = new GetReceiptServiceRequest( shift, new List <ReceiptType>() { receiptType }.AsReadOnly(), request.HardwareProfileId); return(getReceiptServiceRequest); }
public void SpecificDateCalculateResultTest() { var shiftCalculator = new ShiftCalculator(); shiftCalculator.SetRules(new List <IShiftRuleBase>() { new OneShiftPerDayRule(), new ConsecutiveAfternoonShiftsRule(), new ConsecutiveDayShiftsEligibleForExemptionRule(), new EmployeeMinimumCompletedShiftsRule(), new WeekendsOffRule(), }); var employeesList = Enumerable.Range(1, 5).ToArray(); shiftCalculator.SetEmployeeIdList(employeesList); // Monday var dateToStart = new DateTime(2018, 8, 20).Date; var result = shiftCalculator.CalculateShiftsForEmployees(dateToStart, 7, 1, 2); // total shifts Assert.Equal(14, result.Count); // first day Assert.Equal(1, result[0].EmployeeId); Assert.Equal(2, result[1].EmployeeId); // third day Assert.Equal(4, result[4].EmployeeId); Assert.Equal(5, result[5].EmployeeId); // Weekends Assert.Null(result[10].EmployeeId); Assert.Null(result[11].EmployeeId); Assert.Null(result[12].EmployeeId); Assert.Null(result[13].EmployeeId); }