private Action CreateAction(RTTTripDetails details, Consignment consignment, RttSiteDefault site) { var action = new Action { Id = utils.CreateActionId(consignment, site), InternalReference = consignment.ConsignmentID.ToString(), Reference = consignment.ConsignmentNo?.Trim(), CreatedOn = details.TripDate.GetValueOrDefault(), ExpectedDelivery = details.TripDate, ClientId = site.Id, CustomerReference = consignment.Account.Acc_Id.ToString(), CustomerCode = consignment.Account.AccountNo?.Trim(), IsCod = false, AmountIncl = 0, Nature = EActionNature.Product, Weight = consignment.Parcels.Sum(p => p.ActualKG), Pieces = consignment.Parcels.Count, Volume = consignment.Parcels.Sum(p => p.Length * p.Height * p.Width), VolumetricMass = consignment.Parcels.Sum(p => p.VolumizerKG), HandlingUnitIds = consignment.Parcels.Select(p => $"{site.Id}/unit/{p.ParcelID?.Trim()}").ToList(), }; if (consignment.Parcels.Count == 0) { action.ActionTypeId = site.RttActionTypeCollection; action.ActionTypeName = "Collection"; } else { action.ActionTypeId = site.RttActionTypeDelivery; action.ActionTypeName = "Delivery"; } return(action); }
private Action CreateGroupAction(RTTTripDetails details, IGrouping <string, Consignment> group, RttSiteDefault site) { var action = new Action { Id = CreateActionId(group, site), InternalReference = group.Select(x => x.ConsignmentID).FirstOrDefault().ToString(), Reference = group.Select(x => GetGroupId(x)).FirstOrDefault().ToString(), CreatedOn = details.TripDate.GetValueOrDefault(), ExpectedDelivery = details.TripDate, ClientId = site.Id, CustomerReference = group.Select(x => x.ConsignmentID).FirstOrDefault().ToString(), CustomerCode = group.Select(x => x.Address.Addr_id).FirstOrDefault().ToString(), IsCod = false, AmountIncl = 0, Nature = EActionNature.Product, Weight = group.Sum(x => x.Parcels.Select(y => y.ActualKG).Sum()), Pieces = group.Select(x => x.TotalParcelCount).Sum(), VolumetricMass = group.Sum(x => x.Parcels.Select(y => y.VolumizerKG).Sum()), HandlingUnitIds = HandleGroup(group, site), Direction = EActionDirection.Outbound }; if (group.Select(x => x).FirstOrDefault().IsCollection()) { action.ActionTypeId = site.RttActionTypeCollection; action.ActionTypeName = "Collection"; } else { action.ActionTypeId = site.RttActionTypeDelivery; action.ActionTypeName = "Delivery"; } return(action); }
private ObservableCollection <ExtensionProperty> CreateRouteExtensions(RTTTripDetails trip) { if (trip.PlannedRoute == true) { return(new ObservableCollection <ExtensionProperty>() { new ExtensionProperty() { Key = "SizwePlannedStart", Value = trip.GetSizwePlannedStartDate() }, new ExtensionProperty() { Key = "SizwePlannedEnd", Value = trip.GetSizwePlannedEndDate() }, new ExtensionProperty() { Key = "SizwePlannedRouteId", Value = trip.GetSizwePlannedTripId() }, new ExtensionProperty() { Key = "PlannedVehicleClass", Value = trip.GetPlannedVehicleClass() } }); } return(null); }
public UploadModel Create(RTTTripDetails details, RttSiteDefault site) { var trips = details.Consignments.ToList(); var orderedList = trips.OrderBy(x => x.StopNumber).ToList(); var results = Translate(orderedList, site, details); return(results); }
public bool IsPlannedRoute(RTTTripDetails trip) { if (trip.PlannedRoute == true) { return(true); } return(false); }
public UploadModel Create(RTTTripDetails details, RttSiteDefault site) { var data = details.Consignments.OrderBy(x => x.StopNumber).ToList(); var orderedList = data.GroupBy(p => GetGroupId(p)).ToList(); var results = TranslateGrouping(details, orderedList, site); return(results); }
private bool CheckForInvalidTimes(RTTTripDetails details, Consignment consignment) { var minValue = DateTime.MinValue; if (consignment.PlannedStopArrivalTime == minValue || consignment.PlannedStopDepartureTime == minValue || details.PlannedTripStartAt == minValue || consignment.PlannedStopArrivalTime == null || consignment.PlannedStopDepartureTime == null || details.PlannedTripStartAt == null) { return(false); } return(true); }
private UploadModel Translate(List <Consignment> trip, RttSiteDefault site, RTTTripDetails details) { var route = new UploadModel(); if (site == null) { return(null); } foreach (var consignment in trip) { var action = CreateAction(details, consignment, site); consignment.Parcels.ForEach(p => route.Add(new HandlingUnit { Id = $"{site.Id}/unit/{p.ParcelID?.Trim()}", Barcode = p.Barcode, CustomerReference = p.ConsID.ToString(), Quantity = 1, Weight = p.ActualKG, Dimensions = new HandlingUnitDimensions { Height = p.Height, Length = p.Length, Width = p.Width }, Status = EHandlingUnitStatus.Pending })); route.Add(action); var sellTo = CreateSellTo(consignment, site); var deco = CreateDeco(consignment, site); route.Add(deco); var sellToTemp = CreateTempSellTo(consignment, site); route.Add(sellToTemp); var relationship = Relationship .Link(action) .To(sellToTemp) .At(deco); route.Add(relationship); } route.Add(new EntityContactsDescriptor { Authority = EAuthority.Trackmatic }); route.Route = CreateRoute(details, site); route.Route.Personnel.Add(new Personnel { Id = $"{site.Id}/personnel/{details.Driver.IDNo}", Name = details.Driver.Name?.Trim(), IdentityNumber = details.Driver.IDNo.ToString() }); return(route); }
private RouteModel CreateRoute(RTTTripDetails details, RttSiteDefault site) { var route = new RouteModel { Name = details.TripHeaderID, Id = $"{site.Id}/{details.TripHeaderID}", Registration = details.Vehicle.VehRegno.CleanVehicleReg(), Reference = details.TripHeaderID, Schedule = true, StartDate = details.TripDate.GetValueOrDefault().ToUniversalTime(), TemplateId = site.RttTemplateId }; return(route); }
public DateTime DeterminePlanModelDate(RTTTripDetails details) { var minValue = DateTime.MinValue; if (details.PlannedTripStartAt == minValue || details.PlannedTripStartAt == null) { return(details.TripDate.GetValueOrDefault().ToUniversalTime()); } if (details.PlannedTripStartAt.GetValueOrDefault().Year < 2000) { var tripDate = details.TripDate.GetValueOrDefault(); return(new DateTime(tripDate.Year, tripDate.Month, tripDate.Day, 8, 0, 0).ToUniversalTime()); } return(details.PlannedTripStartAt.GetValueOrDefault().ToUniversalTime()); }
private RouteModel CreateRoute(RTTTripDetails details, RttSiteDefault site) { var route = new RouteModel { Name = details.TripHeaderID, Id = $"{site.Id}/{details.TripHeaderID}", Registration = details.Vehicle.VehRegno.CleanVehicleReg(), Reference = details.TripHeaderID, Schedule = true, StartDate = CreateDefaultStartDate(details), TemplateId = site.RttTemplateId, Extensions = CreateRouteExtensions(details) }; return(route); }
private UploadModel TranslateGrouping(RTTTripDetails details, List <IGrouping <string, Consignment> > grouping, RttSiteDefault site) { var model = new UploadModel(); if (site == null) { return(null); } foreach (var group in grouping) { var route = CreateGroupRoute(details, site); var action = CreateGroupAction(details, group, site); var deco = CreateGroupDeco(group, site); var shipTo = CreateGroupShipTo(group, site); var sellTo = CreateGroupSellTo(group, site); model.Add(action); model.Add(deco); model.Add(shipTo); model.Add(sellTo); model.Route = route; var relationship = Relationship .Link(action) .To(shipTo) .At(deco) .SellTo(sellTo); model.Add(relationship); relationship.Mst = TimeSpan.FromMinutes(15); relationship.MstOverride = TimeSpan.FromMinutes(15); model = AddHandlingUnits(group, site, model); } return(model); }
public DateTime CreateDefaultStartDate(RTTTripDetails details) { var date = details.PlannedTripStartAt.GetValueOrDefault(); var tripDate = details.TripDate.GetValueOrDefault(); if (details.PlannedRoute == false) { if (tripDate.Hour >= 12 && tripDate.Hour <= 16) { return(new DateTime(tripDate.Year, tripDate.Month, tripDate.Day, 14, 0, 0).ToUniversalTime()); } if (tripDate.Hour > 18) { return(new DateTime(tripDate.Year, tripDate.Month, tripDate.Day, 8, 0, 0).ToUniversalTime().AddDays(1)); } return(new DateTime(tripDate.Year, tripDate.Month, tripDate.Day, 8, 0, 0).ToUniversalTime()); } if (date.Hour >= 12) { return(new DateTime(date.Year, date.Month, date.Day, 14, 0, 0).ToUniversalTime()); } return(new DateTime(date.Year, date.Month, date.Day, 8, 0, 0).ToUniversalTime()); }
private OLocation CreateDeco(Consignment consignment, RttSiteDefault site, RTTTripDetails trip) { var deco = new OLocation { Name = consignment.Address.Name?.Trim(), Id = utils.ResolveDecoId(consignment, site), ClientId = site.Id, Reference = consignment.Address.Addr_id.ToString(), DefaultStopTime = DetermineStopTime(consignment.PlannedStopOffloadDuration), Shape = EZoneShape.Radius, Coords = new SpecializedObservableCollection <OCoord> { new OCoord { Latitude = Convert.ToDouble(string.IsNullOrEmpty(consignment.Address.GpsLat) ? "0" : consignment.Address.GpsLat), Longitude = Convert.ToDouble(string.IsNullOrEmpty(consignment.Address.GpsLong) ? "0" : consignment.Address.GpsLong), Radius = 100 } }, StructuredAddress = new StructuredAddress { Street = consignment.Address.Address1?.Trim(), Suburb = consignment.Address.Suburb?.Trim(), City = consignment.Address.Town?.Trim(), PostalCode = consignment.Address.Postal?.Trim() }, Entrance = new OCoord { Latitude = Convert.ToDouble(string.IsNullOrEmpty(consignment.Address.GpsLat) ? "0" : consignment.Address.GpsLat), Longitude = Convert.ToDouble(string.IsNullOrEmpty(consignment.Address.GpsLong) ? "0" : consignment.Address.GpsLong), Radius = 100 }, Extensions = CreateStopExtensions(trip, consignment) }; return(deco); }
public static string GetSizwePlannedStartDate(this RTTTripDetails trip) { return(trip.PlannedTripStartAt.ToString()); }
public static string GetPlannedVehicleClass(this RTTTripDetails trip) { return(trip.Vehicle.VehType.ToString()); }
public static string GetSizwePlannedEndDate(this RTTTripDetails trip) { return(trip.Consignments.Last().PlannedStopArrivalTime.ToString()); }
public DateTime CreateDefaultStartDate(RTTTripDetails details) { var date = details.TripDate.GetValueOrDefault(); return(new DateTime(date.Year, date.Month, date.Day, 8, 0, 0).ToUniversalTime()); }
private UploadModel Translate(List <Consignment> trip, RttSiteDefault site, RTTTripDetails details) { var planModel = new PlanModel(); var route = new UploadModel(); var decosToCheck = trip.Where(x => x.ConsType.ToLower() != "depot").ToList(); decosToCheck.Add(trip[0]); var timeIsValid = decosToCheck.All(x => CheckForInvalidTimes(details, x)); var lastStopIsValid = IsLastStopInvalid(trip[trip.Count - 1]); var depots = trip.Where(x => x.ConsType.ToLower() == "depot").ToList(); if (timeIsValid && lastStopIsValid) { route.Add(site.StaticDeco); planModel.Stops.Add(new StopModel { LocationId = site.StaticDeco.Id, DueTime = depots[0].PlannedStopDepartureTime.GetValueOrDefault() }); } if (site == null) { return(null); } foreach (var consignment in trip) { if (consignment.ConsType.ToLower() == "depot") { continue; } var action = CreateAction(details, consignment, site); consignment.Parcels.ForEach(p => route.Add(new HandlingUnit { Id = $"{site.Id}/unit/{p.ParcelID?.Trim()}", Barcode = p.Barcode, CustomerReference = p.ConsID.ToString(), Quantity = 1, Weight = p.ActualKG, Dimensions = new HandlingUnitDimensions { Height = p.Height, Length = p.Length, Width = p.Width }, Status = EHandlingUnitStatus.Pending })); route.Add(action); var sellTo = CreateSellTo(consignment, site); var deco = CreateDeco(consignment, site, details); route.Add(deco); var shipTo = CreateShipTo(consignment.Address, site); route.Add(shipTo); route.Add(sellTo); var relationship = Relationship .Link(action) .To(shipTo) .At(deco) .SellTo(sellTo); route.Add(relationship); } foreach (var consignments in trip.Where(x => x.ConsType.ToLower() != "depot").GroupBy(x => x.Address.Addr_id)) { var stopModel = CreateStopModel(consignments.ToList(), site); planModel.Stops.Add(stopModel); } route.Add(new EntityContactsDescriptor { Authority = EAuthority.Trackmatic }); route.Add(new RelationshipMstDescriptor { Authority = EAuthority.Lob }); route.Add(new LocationDefaultStopTimeDescriptor { Authority = EAuthority.Lob }); route.Add(new LocationExtensionsDescriptor { Authority = EAuthority.Lob }); route.Route = CreateRoute(details, site); route.Route.Personnel.Add(new Personnel { Id = $"{site.Id}/personnel/{details.Driver.IDNo?.ToString()}", Name = details.Driver.Name?.Trim(), IdentityNumber = details.Driver.IDNo?.ToString() }); if (timeIsValid && lastStopIsValid) { planModel.Stops.Add(new StopModel { LocationId = site.StaticDeco.Id, DueTime = depots[1].PlannedStopArrivalTime.GetValueOrDefault() }); route.Plan = planModel; route.Route.StartDate = DeterminePlanModelDate(details); route.Route.IsLocked = true; } else { route = CreateUniqueStopTime(route, 8); } return(route); }
public static string GetSizwePlannedTripId(this RTTTripDetails trip) { return(trip.PlannedRouteID); }
private SpecializedObservableCollection <ExtensionProperty> CreateStopExtensions(RTTTripDetails trip, Consignment consignment) { if (trip.PlannedRoute == true) { return(new SpecializedObservableCollection <ExtensionProperty>() { new ExtensionProperty() { Key = "SizweOffloadStart", Value = consignment.GetSizwePlannedOffloadStart() }, new ExtensionProperty() { Key = "SizweOffloadEnd", Value = consignment.GetSizwePlannedOffloadEnd() }, new ExtensionProperty() { Key = "SizweOffloadDuration", Value = consignment.GetSizwePlannedOffloadDuration() }, new ExtensionProperty() { Key = "SizweDistance", Value = consignment.GetSizwePlannedDistance() }, new ExtensionProperty() { Key = "SizweAddressId", Value = consignment.GetSizweAddressId() }, }); } return(null); }