Beispiel #1
0
        public async Task <PrenotificationContentRuleResult <PrenotificationContentRules> > GetResult(
            List <PrenotificationMovement> movements, Guid notificationId)
        {
            var shipment = await shipmentInfoRepository.GetByNotificationId(notificationId);

            var units          = shipment == null ? default(ShipmentQuantityUnits) : shipment.Units;
            var availableUnits = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(units).ToList();

            return(await Task.Run(() =>
            {
                var shipments =
                    movements.Where(
                        m =>
                        m.ShipmentNumber.HasValue &&
                        (!m.Unit.HasValue ||
                         availableUnits.All(u => u != m.Unit.Value)))
                    .GroupBy(x => x.ShipmentNumber)
                    .OrderBy(x => x.Key)
                    .Select(x => x.Key)
                    .ToList();

                var result = shipments.Any() ? MessageLevel.Error : MessageLevel.Success;
                var minShipment = shipments.FirstOrDefault() ?? 0;

                var shipmentNumbers = string.Join(", ", shipments);
                var errorMessage =
                    string.Format(
                        Prsd.Core.Helpers.EnumHelper.GetDisplayName(PrenotificationContentRules.QuantityUnit),
                        shipmentNumbers);

                return new PrenotificationContentRuleResult <PrenotificationContentRules>(PrenotificationContentRules.QuantityUnit, result, errorMessage, minShipment);
            }));
        }
        public CreateMovementsViewModel(ShipmentInfo shipmentInfo)
        {
            StartDate         = shipmentInfo.ShipmentDates.StartDate;
            EndDate           = shipmentInfo.ShipmentDates.EndDate;
            NotificationUnits = shipmentInfo.ShipmentQuantityUnits;
            AvailableUnits    = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(shipmentInfo.ShipmentQuantityUnits).ToList();

            var items = shipmentInfo.PackagingData.PackagingTypes
                        .Where(x => x != PackagingType.Other)
                        .Select(x => new SelectListItem
            {
                Text  = EnumHelper.GetDisplayName(x),
                Value = ((int)x).ToString()
            })
                        .ToList();

            if (shipmentInfo.PackagingData.PackagingTypes.Contains(PackagingType.Other))
            {
                items.Add(new SelectListItem
                {
                    Text = string.Format("{0} - {1}", EnumHelper.GetShortName(PackagingType.Other),
                                         shipmentInfo.PackagingData.OtherDescription),
                    Value = ((int)PackagingType.Other).ToString()
                });
            }

            PackagingTypes = new CheckBoxCollectionViewModel();
            PackagingTypes.ShowEnumValue  = true;
            PackagingTypes.PossibleValues = items;
        }
Beispiel #3
0
        private static ImportMovementReceiptData GetReceiptData(ImportMovementSummary source)
        {
            var possibleUnits = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(source.Units).ToArray();

            if (source.Rejection != null)
            {
                return(new ImportMovementReceiptData
                {
                    PossibleUnits = possibleUnits,
                    RejectionReason = source.Rejection.Reason,
                    ReceiptDate = source.Rejection.Date,
                    IsRejected = true
                });
            }

            if (source.Receipt != null)
            {
                return(new ImportMovementReceiptData
                {
                    PossibleUnits = possibleUnits,
                    ReceiptDate = source.Receipt.Date,
                    ActualQuantity = source.Receipt.Quantity,
                    IsReceived = true,
                    ReceiptUnits = source.Receipt.Unit
                });
            }

            return(new ImportMovementReceiptData
            {
                IsReceived = false,
                PossibleUnits = possibleUnits,
                NotificationUnit = source.Units
            });
        }
Beispiel #4
0
        public static decimal ConvertToTarget(ShipmentQuantityUnits source, ShipmentQuantityUnits target, decimal value, bool throwOnLossOfPrecision = true)
        {
            if (source == target)
            {
                return(value);
            }

            if (ShipmentQuantityUnitsMetadata.IsWeightUnit(source) && ShipmentQuantityUnitsMetadata.IsVolumeUnit(target))
            {
                ThrowOnInvalidConversion(source, target);
            }

            if (ShipmentQuantityUnitsMetadata.IsVolumeUnit(source) && ShipmentQuantityUnitsMetadata.IsWeightUnit(target))
            {
                ThrowOnInvalidConversion(source, target);
            }

            if (source == ShipmentQuantityUnits.Tonnes && target == ShipmentQuantityUnits.Kilograms)
            {
                return(TonnesToKilograms(value));
            }

            if (source == ShipmentQuantityUnits.CubicMetres && target == ShipmentQuantityUnits.Litres)
            {
                return(CubicMetersToLitres(value));
            }

            if (source == ShipmentQuantityUnits.Kilograms && target == ShipmentQuantityUnits.Tonnes)
            {
                var convertedValue = KilogramsToTonnes(value);

                if (WouldLosePrecision(convertedValue, throwOnLossOfPrecision))
                {
                    ThrowOnPrecisionLoss(source, target, value);
                }

                return(convertedValue);
            }

            if (source == ShipmentQuantityUnits.Litres && target == ShipmentQuantityUnits.CubicMetres)
            {
                var convertedValue = LitresToCubicMeters(value);

                if (WouldLosePrecision(convertedValue, throwOnLossOfPrecision))
                {
                    ThrowOnPrecisionLoss(source, target, value);
                }

                return(convertedValue);
            }

            ThrowOnInvalidConversion(source, target);

            throw new InvalidOperationException();
        }
        private decimal?GetIntendedTonnes(Shipment source)
        {
            if (!source.TotalQuantityUnitsId.HasValue ||
                !source.TotalQuantity.HasValue ||
                ShipmentQuantityUnitsMetadata.IsVolumeUnit(source.TotalQuantityUnitsId.Value))
            {
                return(null);
            }

            return(ShipmentQuantityUnitConverter.ConvertToTarget(source.TotalQuantityUnitsId.Value,
                                                                 ShipmentQuantityUnits.Tonnes,
                                                                 source.TotalQuantity.Value,
                                                                 false));
        }
        private decimal?GetActualCubicMetres(Shipment source)
        {
            if (!source.Units.HasValue ||
                !source.QuantityReceived.HasValue ||
                ShipmentQuantityUnitsMetadata.IsWeightUnit(source.Units.Value))
            {
                return(null);
            }

            return(ShipmentQuantityUnitConverter.ConvertToTarget(source.Units.Value,
                                                                 ShipmentQuantityUnits.CubicMetres,
                                                                 source.QuantityReceived.Value,
                                                                 false));
        }
Beispiel #7
0
        public async Task <MovementReceiptAndRecoveryData> HandleAsync(GetMovementReceiptAndRecoveryData message)
        {
            var movement = await movementRepository.GetById(message.MovementId);

            var notification = await notificationApplicationRepository.GetById(movement.NotificationId);

            var movementRejection = await movementRejectionRepository.GetByMovementIdOrDefault(movement.Id);

            var shipmentInfo = await shipmentInfoRepository.GetByNotificationId(notification.Id);

            var data = new MovementReceiptAndRecoveryData
            {
                Id                  = movement.Id,
                NotificationId      = notification.Id,
                Number              = movement.Number,
                PossibleUnits       = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(shipmentInfo.Units).ToArray(),
                ActualDate          = movement.Date,
                NotificationType    = notification.NotificationType,
                PrenotificationDate = movement.PrenotificationDate,
                NotificationUnits   = shipmentInfo.Units,
                Status              = movement.Status,
                Comments            = movement.Comments,
                StatsMarking        = movement.StatsMarking
            };

            if (movement.Receipt != null)
            {
                data.ReceiptDate    = movement.Receipt.Date;
                data.ActualQuantity = movement.Receipt.QuantityReceived.Quantity;
                data.ReceiptUnits   = movement.Receipt.QuantityReceived.Units;
                data.IsReceived     = true;
            }

            if (movement.CompletedReceipt != null)
            {
                data.OperationCompleteDate = movement.CompletedReceipt.Date;
                data.IsOperationCompleted  = true;
            }

            if (movementRejection != null)
            {
                data.RejectionReason = movementRejection.Reason;
                data.ReceiptDate     = movementRejection.Date;
                data.IsRejected      = true;
            }

            return(data);
        }
Beispiel #8
0
        public async Task <ActionResult> Create(Guid id, int?shipmentNumber = null)
        {
            var model = new CaptureViewModel();

            if (shipmentNumber.HasValue)
            {
                model.ShipmentNumber = shipmentNumber;
            }

            var result = await mediator.SendAsync(new GetNotificationDetails(id));

            model.Recovery.NotificationType = result.NotificationType;
            model.NotificationType          = result.NotificationType;
            //Set the units based on the notification Id
            var units = await mediator.SendAsync(new GetImportShipmentUnits(id));

            model.Receipt.PossibleUnits = ShipmentQuantityUnitsMetadata.GetUnitsOfThisType(units).ToArray();
            await UpdateSummary(model, id);

            return(View(model));
        }