Пример #1
0
        public WorkOrder ToDomain(WorkOrderClass workOrderClass)
        {
            var workOrder = new WorkOrder(workOrderClass.Id)
            {
                UserCreated = workOrderClass.UserCreated,
                CreatedOn   = new CreatedOn(workOrderClass.CreatedOn),
                Version     = workOrderClass.Version,

                Order = new Order()
                {
                    Number = workOrderClass.OrderNumber,

                    Origin = new Origin()
                    {
                        Source      = workOrderClass.OrderOriginSource,
                        EntryNumber = workOrderClass.OrderOriginEntryNumber
                    },

                    Customer = new Customer()
                    {
                        Code           = workOrderClass.OrderCustomerCode,
                        ProductionSite = workOrderClass.OrderCustomerProductionSite,
                        Reference1     = workOrderClass.OrderCustomerReference1,
                        Reference2     = workOrderClass.OrderCustomerReference2,
                        Reference3     = workOrderClass.OrderCustomerReference3,
                        Reference4     = workOrderClass.OrderCustomerReference4,
                        Reference5     = workOrderClass.OrderCustomerReference5
                    },

                    Customs = new Customs()
                    {
                        CertificateOfOrigin = workOrderClass.OrderCustomsCertificateOfOrigin,
                        Document            = new Document()
                        {
                            Name   = workOrderClass.OrderCustomsDocumentName,
                            Number = workOrderClass.OrderCustomsDocumentNumber,
                            Office = workOrderClass.OrderCustomsDocumentOffice,
                            Date   = workOrderClass.OrderCustomsDocumentDate.HasValue ? new DateOn(workOrderClass.OrderCustomsDocumentDate.Value) : null,
                        }
                    },

                    Transport = new Transport()
                    {
                        Kind   = workOrderClass.OrderTransportKind,
                        Type   = workOrderClass.OrderTransportType,
                        Driver = new Driver()
                        {
                            Name = workOrderClass.OrderTransportDriverName,
                            Wait = (Wait)Enum.Parse(typeof(Wait), workOrderClass.OrderTransportDriverWait),
                        },
                        Delivery = new Delivery()
                        {
                            Eta       = workOrderClass.OrderTransportDeliveryEta.HasValue ? new DateOn(workOrderClass.OrderTransportDeliveryEta.Value) : null,
                            Lta       = workOrderClass.OrderTransportDeliveryLta.HasValue ? new DateOn(workOrderClass.OrderTransportDeliveryLta.Value) : null,
                            Place     = workOrderClass.OrderTransportDeliveryPlace,
                            Reference = workOrderClass.OrderTransportDeliveryReference
                        },
                        Loading = new Loading()
                        {
                            Eta       = workOrderClass.OrderTransportLoadingEta.HasValue ? new DateOn(workOrderClass.OrderTransportLoadingEta.Value) : null,
                            Lta       = workOrderClass.OrderTransportLoadingLta.HasValue ? new DateOn(workOrderClass.OrderTransportLoadingLta.Value) : null,
                            Place     = workOrderClass.OrderTransportLoadingPlace,
                            Reference = workOrderClass.OrderTransportLoadingReference
                        },
                        Truck = new Truck()
                        {
                            LicensePlateTruck   = workOrderClass.OrderTransportTruckLicensePlateTruck,
                            LicensePlateTrailer = workOrderClass.OrderTransportTruckLicensePlateTrailer
                        },
                        Container = new Container()
                        {
                            FreeUntilOnTerminal = new FreeUntilOnTerminal()
                            {
                                ShippingLine = workOrderClass.OrderTransportContainerFreeUntilOnTerminalShippingLine,
                                Customer     = workOrderClass.OrderTransportContainerFreeUntilOnTerminalCustomer
                            },
                            Number        = workOrderClass.OrderTransportContainerNumber,
                            Location      = workOrderClass.OrderTransportContainerLocation,
                            StackLocation = workOrderClass.OrderTransportContainerStackLocation
                        },
                        Railcar = new Railcar()
                        {
                            Number = workOrderClass.OrderTransportRailcarNumber
                        },
                        Ard = new Ard()
                        {
                            Reference1  = workOrderClass.OrderTransportArdReference1,
                            Reference2  = workOrderClass.OrderTransportArdReference2,
                            Reference3  = workOrderClass.OrderTransportArdReference3,
                            Reference4  = workOrderClass.OrderTransportArdReference4,
                            Reference5  = workOrderClass.OrderTransportArdReference5,
                            Reference6  = workOrderClass.OrderTransportArdReference6,
                            Reference7  = workOrderClass.OrderTransportArdReference7,
                            Reference8  = workOrderClass.OrderTransportArdReference8,
                            Reference9  = workOrderClass.OrderTransportArdReference9,
                            Reference10 = workOrderClass.OrderTransportArdReference10
                        },
                        Arrival = new Arrival()
                        {
                            Expected = workOrderClass.OrderTransportArrivalExpected.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalExpected.Value) : null,
                            Latest   = workOrderClass.OrderTransportArrivalLatest.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalLatest.Value) : null,
                            Arrived  = workOrderClass.OrderTransportArrivalArrived.HasValue ? new DateOn(workOrderClass.OrderTransportArrivalArrived.Value) : null,
                        },
                        BillOfLading = new BillOfLading()
                        {
                            Number      = workOrderClass.OrderTransportBillOfLadingNumber,
                            WeightNet   = workOrderClass.OrderTransportBillOfLadingWeightNet,
                            WeightGross = workOrderClass.OrderTransportBillOfLadingWeightGross
                        },
                        Carrier = new Carrier()
                        {
                            Booked  = workOrderClass.OrderTransportCarrierBooked,
                            Arrived = workOrderClass.OrderTransportCarrierArrived
                        },
                        Weighbridge = new Weighbridge()
                        {
                            Net   = workOrderClass.OrderTransportWeighbridgeNet,
                            Gross = workOrderClass.OrderTransportWeighbridgeGross
                        },
                        Seal = new Seal()
                        {
                            Seal1 = workOrderClass.OrderTransportSealSeal1,
                            Seal2 = workOrderClass.OrderTransportSealSeal2,
                            Seal3 = workOrderClass.OrderTransportSealSeal3
                        },
                        Adr = workOrderClass.OrderTransportAdr
                    },

                    Operation = new Operation()
                    {
                        Priority = new Priority()
                        {
                            Code  = workOrderClass.OrderOperationPriorityCode,
                            Value = workOrderClass.OrderOperationPriorityValue
                        },
                        Dispatch = new Dispatch()
                        {
                            Priority = workOrderClass.OrderOperationDispatchPriority,
                            To       = workOrderClass.OrderOperationDispatchTo,
                            Comment  = workOrderClass.OrderOperationDispatchComment
                        },

                        Type                  = OperationType.Parse(workOrderClass.OrderOperationType),
                        Name                  = workOrderClass.OrderOperationName,
                        Group                 = workOrderClass.OrderOperationGroup,
                        UnitPlanning          = workOrderClass.OrderOperationUnitPlanning,
                        TypePlanning          = workOrderClass.OrderOperationTypePlanning,
                        Site                  = workOrderClass.OrderOperationSite,
                        Zone                  = workOrderClass.OrderOperationZone,
                        OperationalDepartment = workOrderClass.OrderOperationOperationalDepartment,
                        DockingZone           = workOrderClass.OrderOperationDockingZone,
                        LoadingDock           = workOrderClass.OrderOperationLoadingDock,
                        ProductOverview       = workOrderClass.OrderOperationProductOverview,
                        LotbatchOverview      = workOrderClass.OrderOperationLotbatchOverview
                    },
                }
            };

            #region Units

            var units = new List <Unit>();

            foreach (var unitClass in workOrderClass.OrderUnits)
            {
                var products = new List <Product>();

                foreach (var productClass in unitClass.Products)
                {
                    var productRemarks = new List <string>();
                    foreach (var remarkComment in productClass.Remarks)
                    {
                        productRemarks.Add(remarkComment);
                    }

                    var safetyRemarks = new List <string>();
                    foreach (var safetyRemarkComment in productClass.SafetyRemarks)
                    {
                        safetyRemarks.Add(safetyRemarkComment);
                    }

                    var notes = new List <string>();
                    foreach (var noteComment in productClass.Notes)
                    {
                        notes.Add(noteComment);
                    }

                    var product = new Product(productClass.Id)
                    {
                        Remarks       = productRemarks,
                        SafetyRemarks = safetyRemarks,
                        Notes         = notes
                    };
                    product.SetConfiguration(
                        new Configuration(
                            code: productClass.ConfigurationCode,
                            description: productClass.ConfigurationDescription,
                            quantity: productClass.ConfigurationQuantity,
                            unitType: productClass.ConfigurationUnitType,
                            netPerUnit: productClass.ConfigurationNetPerUnit,
                            netPerUnitAlwaysDifferent: productClass.ConfigurationNetPerUnitAlwaysDifferent,
                            grossPerUnit: productClass.ConfigurationGrossPerUnit
                            )
                        );
                    product.SetCode(productClass.Code);
                    product.SetCustomer(productClass.Customer);
                    product.SetArrival(productClass.Arrival);
                    product.SetArticle(productClass.Article);
                    product.SetArticlePackagingCode(productClass.ArticlePackagingCode);
                    product.SetName(productClass.Name);
                    product.SetGtin(productClass.Gtin);
                    product.SetProductType(productClass.ProductType);
                    product.SetMaterialType(productClass.MaterialType);
                    product.SetColor(productClass.Color);
                    product.SetShape(productClass.Shape);
                    product.SetLotbatch(productClass.Lotbatch);
                    product.SetLotbatch2(productClass.Lotbatch2);
                    product.SetClientReference(productClass.ClientReference);
                    product.SetClientReference2(productClass.ClientReference2);
                    product.SetBestBeforeDate(productClass.BestBeforeDate.HasValue ? new DateOn(productClass.BestBeforeDate.Value) : null);
                    product.SetDateFifo(productClass.DateFifo.HasValue ? new DateOn(productClass.DateFifo.Value) : null);
                    product.SetCustomsDocument(productClass.CustomsDocument);
                    product.SetStorageStatus(productClass.StorageStatus);
                    product.SetStackheight(productClass.Stackheight);
                    product.SetLength(productClass.Length);
                    product.SetWidth(productClass.Width);
                    product.SetHeight(productClass.Height);
                    product.SetOriginalContainer(productClass.OriginalContainer);
                    product.SetQuantity(new Quantity(productClass.Quantity));
                    product.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(productClass.WeightNet)));
                    product.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(productClass.WeightGross)));
                    products.Add(product);
                }


                var unit     = new Unit(unitClass.Id, UnitType.Parse(unitClass.UnitType));
                var location = new Location(
                    new Warehouse(new Label(unitClass.LocationWarehouse)),
                    new Gate(new Label(unitClass.LocationGate)),
                    new Row(new Label(unitClass.LocationRow)),
                    new Position(new Label(unitClass.LocationPosition))
                    );
                unit.SetLocation(location);
                unit.SetGroup(new Group(
                                  key: unitClass.GroupKey,
                                  weightNet: unitClass.GroupWeightNet != null ? new Weight(_typeConverterProvider.ToFloat(unitClass.GroupWeightNet)) : null,
                                  weightGross: unitClass.GroupWeightGross != null ? new Weight(_typeConverterProvider.ToFloat(unitClass.GroupWeightGross)) : null
                                  )
                              );
                unit.SetMixed(new Mixed(key: unitClass.MixedKey, palletNumber: unitClass.MixedPalletNumber));
                unit.SetUnits(new Units(unitClass.Units));
                unit.SetIsPartial(unitClass.IsPartial);
                unit.SetQuantity(new Quantity(unitClass.Quantity));
                unit.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(unitClass.WeightNet)));
                unit.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(unitClass.WeightGross)));
                unit.SetPalletNumber(unitClass.PalletNumber);
                unit.SetSsccNumber(unitClass.SsccNumber);
                unit.SetProducts(products);
                units.Add(unit);
            }
            workOrder.Order.Units = new List <Unit>(units);

            #endregion

            var extraActivities = new List <ExtraActivity>();
            foreach (var extraActivityClass in workOrderClass.OrderOperationExtraActivities)
            {
                var extraActivity = new ExtraActivity()
                {
                    Code        = extraActivityClass.Code,
                    Activity    = extraActivityClass.Activity,
                    Description = extraActivityClass.Description,
                    IsExecuted  = extraActivityClass.IsExecuted,
                    Quantity    = extraActivityClass.Quantity,
                    Remark      = extraActivityClass.Remark
                };
                extraActivities.Add(extraActivity);
            }
            workOrder.Order.Operation.ExtraActivities = new List <ExtraActivity>(extraActivities);

            var operationalRemarks = new List <string>();
            foreach (var operationalRemark in workOrderClass.OrderOperationOperationalRemarks)
            {
                operationalRemarks.Add(operationalRemark);
            }
            workOrder.Order.Operation.OperationalRemarks = operationalRemarks;

            #region Operational

            var handledUnits = new List <HandledUnit>();
            foreach (var handledUnitClass in workOrderClass.OperationalUnits)
            {
                var sourceUnit  = workOrder.Order.Units.First(x => x.Id == handledUnitClass.SourceUnitId);
                var handledUnit = new HandledUnit(handledUnitClass.Id, sourceUnit);
                var operant     = new Operant(handledUnitClass.OperantId, new Login(handledUnitClass.OperantLogin));
                var location    = new Location(
                    new Warehouse(new Label(handledUnitClass.LocationWarehouse)),
                    new Gate(new Label(handledUnitClass.LocationGate)),
                    new Row(new Label(handledUnitClass.LocationRow)),
                    new Position(new Label(handledUnitClass.LocationPosition))
                    );
                handledUnit.SetOperant(operant);
                handledUnit.SetHandledOn(new HandledOn(handledUnitClass.HandledOn));
                handledUnit.SetLocation(location);
                handledUnit.SetUnits(new Units(handledUnitClass.Units));
                handledUnit.SetIsPartial(handledUnitClass.IsPartial);
                handledUnit.SetQuantity(new Quantity(handledUnitClass.Quantity));
                handledUnit.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(handledUnitClass.WeightNet)));
                handledUnit.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(handledUnitClass.WeightGross)));
                handledUnit.SetPalletNumber(handledUnitClass.PalletNumber);
                handledUnit.SetSsccNumber(handledUnitClass.SsccNumber);

                foreach (var goodClass in handledUnitClass.Products)
                {
                    var good = new Good(goodClass.Id);
                    good.SetConfiguration(
                        new Configuration(
                            code: goodClass.ConfigurationCode,
                            description: goodClass.ConfigurationDescription,
                            quantity: goodClass.ConfigurationQuantity,
                            unitType: goodClass.ConfigurationUnitType,
                            netPerUnit: goodClass.ConfigurationNetPerUnit,
                            netPerUnitAlwaysDifferent: goodClass.ConfigurationNetPerUnitAlwaysDifferent,
                            grossPerUnit: goodClass.ConfigurationGrossPerUnit
                            )
                        );
                    good.SetCode(goodClass.Code);
                    good.SetCustomer(goodClass.Customer);
                    good.SetArrival(goodClass.Arrival);
                    good.SetArticle(goodClass.Article);
                    good.SetArticlePackagingCode(goodClass.ArticlePackagingCode);
                    good.SetName(goodClass.Name);
                    good.SetGtin(goodClass.Gtin);
                    good.SetProductType(goodClass.ProductType);
                    good.SetMaterialType(goodClass.MaterialType);
                    good.SetColor(goodClass.Color);
                    good.SetShape(goodClass.Shape);
                    good.SetLotbatch(goodClass.Lotbatch);
                    good.SetLotbatch2(goodClass.Lotbatch2);
                    good.SetClientReference(goodClass.ClientReference);
                    good.SetClientReference2(goodClass.ClientReference2);
                    good.SetBestBeforeDate(goodClass.BestBeforeDate.HasValue ? new DateOn(goodClass.BestBeforeDate.Value) : null);
                    good.SetDateFifo(goodClass.DateFifo.HasValue ? new DateOn(goodClass.DateFifo.Value) : null);
                    good.SetCustomsDocument(goodClass.CustomsDocument);
                    good.SetStorageStatus(goodClass.StorageStatus);
                    good.SetStackheight(goodClass.Stackheight);
                    good.SetLength(goodClass.Length);
                    good.SetWidth(goodClass.Width);
                    good.SetHeight(goodClass.Height);
                    good.SetOriginalContainer(goodClass.OriginalContainer);
                    good.SetQuantity(new Quantity(goodClass.Quantity));
                    good.SetWeightNet(new Weight(_typeConverterProvider.ToFloat(goodClass.WeightNet)));
                    good.SetWeightGross(new Weight(_typeConverterProvider.ToFloat(goodClass.WeightGross)));

                    handledUnit.AddGood(good);
                }

                handledUnits.Add(handledUnit);
            }

            var remarks = new List <Remark>();
            foreach (var remarkClass in workOrderClass.OperationalRemarks)
            {
                var operantId    = remarkClass.OperantId;
                var operantLogin = remarkClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(remarkClass.CreatedOn);
                var text         = remarkClass.Text;
                var remark       = new Remark(operant, createdOn, text);

                remarks.Add(remark);
            }

            var pictures = new List <Picture>();
            foreach (var pictureClass in workOrderClass.OperationalPictures)
            {
                var operantId    = pictureClass.OperantId;
                var operantLogin = pictureClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(pictureClass.CreatedOn);
                var name         = pictureClass.Name;
                var picture      = new Picture(operant, createdOn, name);

                pictures.Add(picture);
            }

            var inputs = new List <Input>();
            foreach (var inputClass in workOrderClass.OperationalInputs)
            {
                var operantId    = inputClass.OperantId;
                var operantLogin = inputClass.OperantLogin;
                var operant      = new Operant(operantId, new Login(operantLogin));
                var createdOn    = new CreatedOn(inputClass.CreatedOn);
                var value        = inputClass.Value;
                var property     = inputClass.Property;
                var input        = new Input(operant, createdOn, value, property);

                inputs.Add(input);
            }

            var operational = new Operational(Status.Parse(workOrderClass.OperationalStatus));
            operational.SetOperant(workOrderClass.OperationalOperant);

            foreach (var handledUnit in handledUnits)
            {
                operational.AddHandledUnit(handledUnit);
            }

            foreach (var remark in remarks)
            {
                operational.AddRemark(remark);
            }

            foreach (var picture in pictures)
            {
                operational.AddPicture(picture);
            }

            foreach (var input in inputs)
            {
                operational.AddInput(input);
            }

            if (workOrderClass.OperationalStartedOn.HasValue)
            {
                operational.SetStartedOn(new DateOn(workOrderClass.OperationalStartedOn.Value));
            }

            workOrder.Operational = operational;

            #endregion

            return(workOrder);
        }