public UploadModel AddHandlingUnits(IGrouping <string, Consignment> group, RttSiteDefault site, UploadModel model)
        {
            foreach (var consignment in group)
            {
                consignment.Parcels.ForEach(p =>
                                            model.Add(new HandlingUnit
                {
                    Id                = $"{site.Id}/unit/{p.ParcelID?.Trim()}",
                    Barcode           = p.Barcode?.Trim(),
                    CustomerReference = p.ConsID.ToString(),
                    InternalReference = consignment.ConsignmentNo,
                    Quantity          = 1,
                    Weight            = p.ActualKG,
                    Dimensions        = new HandlingUnitDimensions
                    {
                        Height = p.Height,
                        Length = p.Length,
                        Width  = p.Width
                    },
                    Status = EHandlingUnitStatus.Pending
                }));
            }

            return(model);
        }
예제 #2
0
        public static UploadModel CreateUploadModel(string filesLocation)
        {
            var model = new UploadModel();

            string[] fileList = Directory.GetFiles(filesLocation, "*.csv");

            foreach (var file in fileList)
            {
                string PathName  = file.ToString();
                string RouteName = (PathName.Substring(PathName.LastIndexOf("\\") + 1).Replace(".csv", ""));
                Console.WriteLine($"Reading file: {RouteName}");
                var superList = new List <string>();
                var content   = File.ReadAllText(file.ToString());

                if (content != null)
                {
                    var csvReader  = new CsvReader();
                    var lines      = csvReader.Read(content);
                    var routeLines = lines.Where(x => x != null).Select(x => new RouteLine(x)).ToList();
                    var superRoute = CreateRoute(RouteName);
                    model.Route = superRoute;

                    //Un-Comment when ordering by 4th column then by the 3rd column
                    //var orderedRouteList = routeLines.OrderBy(x => x.GetRound()).ThenBy(x => x.GetSeq());
                    foreach (var route in routeLines) // orderedRouteList)
                    {
                        var deco   = CreateDeco(route);
                        var entity = LookupEntity(route.GetAccNumber());
                        var action = CreateAction();

                        if (entity != null && deco.Id != null)
                        {
                            if (!model.Decos.Contains(deco))
                            {
                                model.Decos.Add(deco);
                                model.Entities.Add(entity);
                                model.Actions.Add(action);

                                var relationship = new Relationship();
                                relationship.DecoId   = deco.Id;
                                relationship.EntityId = entity.Id;
                                relationship.ActionId = action.Id;

                                model.Add(relationship);
                            }
                        }
                        else
                        {
                            superList.Add($"Entity Id: { route.GetAccNumber()} doesn't exist has or no ship-to location");
                        }
                    }
                }

                WriteToTextFile(superList, PathName, RouteName);
                CreateLatLonCsv(model, PathName, RouteName);
                var api    = CreateLogin("382");
                var upload = api.ExecuteRequest(new Upload(api.Context, model));
            }
            return(model);
        }
예제 #3
0
        public UploadModel CreateModel()
        {
            var model = new UploadModel();

            foreach (var invoice in _actions)
            {
                var action = CreateRouteAction(_site, invoice);
                model.Add(action);
                var entity = CreateRouteEntity(_site, invoice);
                model.Add(entity);
                var deco = CreateRouteDeco(_site, invoice);
                model.Add(deco);
                var relationship = Relationship.Link(action).To(entity).At(deco);
                model.Add(relationship);
            }

            return(model);
        }
        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);
        }
        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);
        }
예제 #6
0
        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);
        }