public virtual DateTime convertSecToTime(int sec, DateTime?date) { DateHandler requestDate = new DateHandler(date); DateTime timeBegin = requestDate.StartOfDay(); return(timeBegin.AddSeconds(sec)); }
public virtual int convertTimeToSec(DateTime?date) { DateHandler requestDate = new DateHandler(date); DateTime timeBegin = requestDate.StartOfDay(); return((int)(((DateTime)date) - timeBegin).TotalSeconds); }
/// <summary> /// Delete the TimeSlots based in [slotLevel] that applies for the [fsTimeSlotRow]. /// </summary> public virtual void DeleteTimeSlotsByLevel(FSTimeSlot fsTimeSlotRow, int slotLevel) { using (var ts = new PXTransactionScope()) { List <object> cmdArg = new List <object>(); TimeSlotMaint timeSlotMaintGraph = PXGraph.CreateInstance <TimeSlotMaint>(); DateHandler dateHandler = new DateHandler(Convert.ToDateTime(fsTimeSlotRow.TimeStart)); PXSelectBase <FSTimeSlot> fsTimeSlotsBaseToDelete = new PXSelect <FSTimeSlot, Where < FSTimeSlot.branchID, Equal <Required <FSTimeSlot.branchID> >, And <FSTimeSlot.employeeID, Equal <Required <FSTimeSlot.employeeID> >, And <FSTimeSlot.slotLevel, Equal <Required <FSTimeSlot.slotLevel> >, And <FSTimeSlot.timeStart, GreaterEqual <Required <FSTimeSlot.timeStart> >, And <FSTimeSlot.timeStart, LessEqual <Required <FSTimeSlot.timeStart> > > > > > > > (timeSlotMaintGraph); cmdArg.Add(fsTimeSlotRow.BranchID); cmdArg.Add(fsTimeSlotRow.EmployeeID); cmdArg.Add(slotLevel); cmdArg.Add(dateHandler.StartOfDay()); cmdArg.Add(dateHandler.BeginOfNextDay()); if (fsTimeSlotRow.BranchLocationID != null) { fsTimeSlotsBaseToDelete.WhereAnd <Where <FSTimeSlot.branchLocationID, Equal <Required <FSTimeSlot.branchLocationID> > > >(); cmdArg.Add(fsTimeSlotRow.BranchLocationID); } var fsTimeSlotSet = fsTimeSlotsBaseToDelete.Select(cmdArg.ToArray()); foreach (FSTimeSlot fsTimeSlotRow_ToDelete in fsTimeSlotSet) { timeSlotMaintGraph.TimeSlotRecords.Delete(fsTimeSlotRow_ToDelete); } timeSlotMaintGraph.Save.Press(); ts.Complete(); } }
public virtual IEnumerable GenerateProjection(PXAdapter adapter) { if (RouteAppointmentForecastingFilter.Current != null && RouteAppointmentForecastingFilter.Current.DateBegin != null && RouteAppointmentForecastingFilter.Current.DateEnd != null && RouteAppointmentForecastingFilter.Current.DateBegin < RouteAppointmentForecastingFilter.Current.DateEnd) { DateTime beginFromFilter = RouteAppointmentForecastingFilter.Current.DateBegin.Value; DateTime endToFilter = RouteAppointmentForecastingFilter.Current.DateEnd.Value; string recordType = ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT; int?serviceID = RouteAppointmentForecastingFilter.Current.ServiceID; int?customerID = RouteAppointmentForecastingFilter.Current.CustomerID; int?customerLocationID = RouteAppointmentForecastingFilter.Current.CustomerLocationID; int?routeID = RouteAppointmentForecastingFilter.Current.RouteID; PXLongOperation.StartOperation( this, delegate { using (PXTransactionScope ts = new PXTransactionScope()) { if (beginFromFilter != null && endToFilter != null) { DateHandler requestDate = new DateHandler(endToFilter); var period = new Period((DateTime)beginFromFilter, (DateTime)endToFilter); List <Scheduler.Schedule> scheduleListToProcess = new List <Scheduler.Schedule>(); var generator = new TimeSlotGenerator(); var fsRouteContractScheduleRecords = PXSelectJoinGroupBy <FSRouteContractSchedule, InnerJoin <FSServiceContract, On <FSServiceContract.serviceContractID, Equal <FSRouteContractSchedule.entityID> >, InnerJoin <FSScheduleRoute, On <FSScheduleRoute.scheduleID, Equal <FSRouteContractSchedule.scheduleID> >, InnerJoin <FSScheduleDet, On <FSScheduleDet.scheduleID, Equal <FSRouteContractSchedule.scheduleID> > > > >, Where < FSRouteContractSchedule.entityType, Equal <FSSchedule.entityType.Contract>, And <FSServiceContract.recordType, Equal <FSServiceContract.recordType.RouteServiceContract>, And <FSRouteContractSchedule.active, Equal <True>, And <FSServiceContract.status, Equal <FSServiceContract.status.Active>, And <FSRouteContractSchedule.startDate, LessEqual <Required <FSRouteContractSchedule.startDate> >, And2 < Where < Required <FSScheduleDet.inventoryID>, IsNull, Or <FSScheduleDet.inventoryID, Equal <Required <FSScheduleDet.inventoryID> > > >, And2 < Where < Required <FSRouteContractSchedule.customerID>, IsNull, Or <FSRouteContractSchedule.customerID, Equal <Required <FSRouteContractSchedule.customerID> > > >, And2 < Where < Required <FSRouteContractSchedule.customerLocationID>, IsNull, Or <FSRouteContractSchedule.customerLocationID, Equal <Required <FSRouteContractSchedule.customerLocationID> > > >, And2 < Where < Required <FSScheduleRoute.dfltRouteID>, IsNull, Or <FSScheduleRoute.dfltRouteID, Equal <Required <FSScheduleRoute.dfltRouteID> > > >, And < Where <FSRouteContractSchedule.endDate, IsNull, Or <FSRouteContractSchedule.endDate, GreaterEqual <Required <FSRouteContractSchedule.startDate> > > > > > > > > > > > > >, Aggregate < GroupBy <FSRouteContractSchedule.scheduleID> > > .Select(this, beginFromFilter, serviceID, serviceID, customerID, customerID, customerLocationID, customerLocationID, routeID, routeID, endToFilter); foreach (FSRouteContractSchedule fsRouteContractScheduleRecord in fsRouteContractScheduleRecords) { List <Scheduler.Schedule> mapScheduleResults = MapFSScheduleToSchedule.convertFSScheduleToSchedule(RouteAppointmentForecastingFilter.Cache, fsRouteContractScheduleRecord, endToFilter, recordType); foreach (Scheduler.Schedule mapSchedule in mapScheduleResults) { scheduleListToProcess.Add(mapSchedule); } } if (recordType == ID.RecordType_ServiceContract.ROUTE_SERVICE_CONTRACT) { foreach (Scheduler.Schedule schedule in scheduleListToProcess) { schedule.Priority = (int?)RouteScheduleProcess.SetSchedulePriority(schedule, this); schedule.RouteInfoList = RouteScheduleProcess.getRouteListFromSchedule(schedule, this); } } List <TimeSlot> timeSlots = generator.GenerateCalendar(period, scheduleListToProcess); var fsRouteAppointmentForecastingRecords = PXSelect <FSRouteAppointmentForecasting, Where < FSRouteAppointmentForecasting.startDate, GreaterEqual <Required <FSRouteAppointmentForecasting.startDate> >, And < FSRouteAppointmentForecasting.startDate, LessEqual <Required <FSRouteAppointmentForecasting.startDate> > > > > .Select(this, beginFromFilter, endToFilter); PXCache <FSRouteAppointmentForecasting> cacheRouteForecasting = new PXCache <FSRouteAppointmentForecasting>(this); foreach (FSRouteAppointmentForecasting fsRouteAppointmentDetailProjectionRecord in fsRouteAppointmentForecastingRecords) { cacheRouteForecasting.PersistDeleted(fsRouteAppointmentDetailProjectionRecord); } foreach (TimeSlot timeSlot in timeSlots) { requestDate.setDate(timeSlot.DateTimeBegin); FSSchedule fsScheduleRow = ScheduleSelected.Select(timeSlot.ScheduleID); FSScheduleRoute fsScheduleRouteRow = ScheduleRouteSelected.Select(fsScheduleRow.ScheduleID); FSServiceContract fsServiceContractRow = ServiceContractSelected.Select(fsScheduleRow.EntityID); FSRouteAppointmentForecasting fsRouteAppointmentForecastingRow = new FSRouteAppointmentForecasting(); fsRouteAppointmentForecastingRow.RouteID = fsScheduleRouteRow.DfltRouteID; fsRouteAppointmentForecastingRow.StartDate = requestDate.StartOfDay(); fsRouteAppointmentForecastingRow.ScheduleID = fsScheduleRow.ScheduleID; fsRouteAppointmentForecastingRow.ServiceContractID = fsServiceContractRow.ServiceContractID; fsRouteAppointmentForecastingRow.CustomerLocationID = fsServiceContractRow.CustomerLocationID; fsRouteAppointmentForecastingRow.CustomerID = fsServiceContractRow.CustomerID; fsRouteAppointmentForecastingRow.SequenceOrder = int.Parse(fsScheduleRouteRow.GlobalSequence); cacheRouteForecasting.PersistInserted(fsRouteAppointmentForecastingRow); } } ts.Complete(); } }); } return(adapter.Get()); }
/// <summary> /// Creates the compressed Time Slots that applies for the [fsTimeSlotRow]. /// </summary> public virtual void CreateAndCompressedTimeSlots(FSTimeSlot fsTimeSlotRow, TimeSlotMaint timeSlotMaintGraph) { List <object> cmdArg = new List <object>(); List <FSTimeSlot> fsTimeSlotListToCompress = new List <FSTimeSlot>(); List <Scheduler.Slot> slotListToCompress = new List <Scheduler.Slot>(); var fsBranchLocationSet = PXSelect <FSBranchLocation, Where < FSBranchLocation.branchID, Equal <Required <FSBranchLocation.branchID> > >, OrderBy < Asc <FSBranchLocation.branchLocationID> > > .Select(timeSlotMaintGraph, fsTimeSlotRow.BranchID); DateHandler dateHandler = new DateHandler(SharedFunctions.TryParseHandlingDateTime(timeSlotMaintGraph.TimeSlotRecords.Cache, fsTimeSlotRow.TimeStart)); PXSelectBase <FSTimeSlot> fsTimeSlotsBaseToCompress = new PXSelect <FSTimeSlot, Where < FSTimeSlot.branchID, Equal <Required <FSTimeSlot.branchID> >, And <FSTimeSlot.employeeID, Equal <Required <FSTimeSlot.employeeID> >, And <FSTimeSlot.slotLevel, Equal <Required <FSTimeSlot.slotLevel> >, And <FSTimeSlot.timeStart, GreaterEqual <Required <FSTimeSlot.timeStart> >, And <FSTimeSlot.timeStart, LessEqual <Required <FSTimeSlot.timeStart> > > > > > > > (timeSlotMaintGraph); cmdArg.Add(fsTimeSlotRow.BranchID); cmdArg.Add(fsTimeSlotRow.EmployeeID); cmdArg.Add(ID.EmployeeTimeSlotLevel.BASE); cmdArg.Add(dateHandler.StartOfDay()); cmdArg.Add(dateHandler.BeginOfNextDay()); if (fsTimeSlotRow.BranchLocationID != null) { fsTimeSlotsBaseToCompress.WhereAnd <Where <FSTimeSlot.branchLocationID, Equal <Required <FSTimeSlot.branchLocationID> > > >(); cmdArg.Add(fsTimeSlotRow.BranchLocationID); } var fsTimeSlotSet = fsTimeSlotsBaseToCompress.Select(cmdArg.ToArray()); foreach (FSTimeSlot fsTimeSlotRow_ToCompress in fsTimeSlotSet) { fsTimeSlotListToCompress.Add(fsTimeSlotRow_ToCompress); } var groupedSlotList = fsTimeSlotListToCompress .GroupBy(u => u.BranchLocationID == null ? -1 : u.BranchLocationID) .Select(group => new { BranchLocationID = group.Key, FSTimeSlots = group.ToList() }) .OrderBy(group => group.BranchLocationID) .ToList(); List <Scheduler.Slot> compressedSlots = new List <Scheduler.Slot>(); foreach (FSBranchLocation fsBranchLocationRow in fsBranchLocationSet) { var existingBranchLocationList = groupedSlotList .Select(bl => new { BranchLocationID = bl.BranchLocationID, FSTimeSlot = bl.FSTimeSlots.ToList() }) .Where(S => S.BranchLocationID == fsBranchLocationRow.BranchLocationID).ToList(); fsTimeSlotListToCompress.Clear(); slotListToCompress.Clear(); if (existingBranchLocationList.Count > 0) { fsTimeSlotListToCompress = existingBranchLocationList[0].FSTimeSlot; } if (groupedSlotList.Count > 0 && groupedSlotList[0].BranchLocationID == -1) { fsTimeSlotListToCompress = fsTimeSlotListToCompress.Concat(groupedSlotList[0].FSTimeSlots).ToList(); } foreach (FSTimeSlot fsTimeSlotRow_ToCompress in fsTimeSlotListToCompress) { slotListToCompress.Add(ConvertFSTimeSlotToSlot(fsTimeSlotRow_ToCompress)); } if (slotListToCompress.Count > 0) { fsTimeSlotRow.BranchLocationID = fsBranchLocationRow.BranchLocationID; CreateCompressedSlots(CompressAndIntersectSlots(slotListToCompress).ToList(), fsTimeSlotRow); } } }