Esempio n. 1
0
        public async Task <ImportMovement> Create(Guid notificationId, int number, DateTime actualShipmentDate, DateTime?prenotificationDate)
        {
            if (!await numberValidator.Validate(notificationId, number))
            {
                throw new MovementNumberException("Cannot create an import movement with a conflicting movement number (" + number + ") for import notification: " + notificationId);
            }

            var notificationStatus = (await assessmentRepository.GetByNotification(notificationId)).Status;

            if (notificationStatus != ImportNotificationStatus.Consented)
            {
                throw new InvalidOperationException(
                          string.Format("Cannot create a movement for notification {0} because its status is {1}",
                                        notificationId, notificationStatus));
            }

            if (prenotificationDate.HasValue)
            {
                if (prenotificationDate > SystemTime.UtcNow.Date)
                {
                    throw new InvalidOperationException("The prenotification date cannot be in the future.");
                }
                if (actualShipmentDate < prenotificationDate)
                {
                    throw new InvalidOperationException("The actual date of shipment cannot be before the prenotification date.");
                }
                if (actualShipmentDate > prenotificationDate.Value.AddDays(60))
                {
                    throw new InvalidOperationException("The actual date of shipment should not be more than 30 calendar days after the prenotification date.");
                }
            }

            return(new ImportMovement(notificationId, number, actualShipmentDate));
        }
        public async Task <Unit> HandleAsync(SetNotificationFileClosedDate message)
        {
            var assessment = await repository.GetByNotification(message.ImportNotificationId);

            assessment.MarkFileClosed(message.Date);
            await context.SaveChangesAsync();

            return(Unit.Value);
        }
Esempio n. 3
0
        public async Task <Unit> HandleAsync(SetArchiveReference message)
        {
            var assessment = await repository.GetByNotification(message.NotificationId);

            assessment.SetArchiveReference(message.ArchiveReference);
            await context.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <ImportWithdrawn> Withdraw(Guid importNotificationId, DateTime date, string reasons)
        {
            var assessment = await assessmentRepository.GetByNotification(importNotificationId);

            var withdrawal = assessment.Withdraw(date, reasons);

            withdrawnRepository.Add(withdrawal);

            return(withdrawal);
        }
        public async Task <bool> HandleAsync(SetNotificationCompletedDate message)
        {
            var assessment = await repository.GetByNotification(message.ImportNotificationId);

            assessment.CompleteNotification(message.Date);

            await context.SaveChangesAsync();

            return(true);
        }
Esempio n. 6
0
        public async Task <KeyDatesOverrideData> HandleAsync(GetImportKeyDatesOverrideData message)
        {
            var assessment = await assessmentRepository.GetByNotification(message.NotificationId);

            var keyDates = await repository.GetKeyDatesForNotification(message.NotificationId);

            keyDates.DecisionRequiredByDate = await decisionRequiredBy.GetDecisionRequiredByDate(assessment);

            return(keyDates);
        }
        public async Task <bool> HandleAsync(SetAssessmentStartedDate message)
        {
            var assessment = await assessmentRepository.GetByNotification(message.ImportNotificationId);

            assessment.BeginAssessment(message.Date, message.NameOfOfficer);

            await context.SaveChangesAsync();

            return(true);
        }
Esempio n. 8
0
        public async Task <bool> HandleAsync(WithdrawConsentForImportNotification message)
        {
            var assessment = await repository.GetByNotification(message.Id);

            assessment.WithdrawConsent(message.Date, message.ReasonsForConsentWithdrawal);

            await context.SaveChangesAsync();

            return(true);
        }
Esempio n. 9
0
        public async Task <ImportObjection> Object(Guid notificationId, DateTime date, string reasons)
        {
            var assessment = await assessmentRepository.GetByNotification(notificationId);

            var objection = assessment.Object(date, reasons);

            objectionRepository.Add(objection);

            return(objection);
        }
Esempio n. 10
0
        public async Task Consent(Guid notificationId,
                                  DateRange dateRange,
                                  string conditions,
                                  DateTime consentedDate)
        {
            var assessment = await assessmentRepository.GetByNotification(notificationId);

            var consent = assessment.Consent(dateRange, conditions, userContext.UserId, consentedDate);

            consentRepository.Add(consent);
        }
        public async Task <bool> HandleAsync(CompleteDraftImportNotification message)
        {
            var draft = await draftImportNotificationRepository.Get(message.ImportNotificationId);

            var assessment =
                await importNotificationAssessmentRepository.GetByNotification(message.ImportNotificationId);

            var result = await importNotificationValidator.ValidateAsync(draft);

            if (result.IsValid && assessment.Status == ImportNotificationStatus.NotificationReceived)
            {
                var notification =
                    await importNotificationRepository.Get(message.ImportNotificationId);

                var exporter           = mapper.Map <Exporter>(draft.Exporter);
                var facilityCollection = mapper.Map <FacilityCollection>(draft.Facilities, draft.Preconsented);
                var importer           = mapper.Map <Importer>(draft.Importer);
                var producer           = mapper.Map <Producer>(draft.Producer);
                var shipment           = mapper.Map <Shipment>(draft.Shipment, draft.Preconsented);

                var transportRoute = new Domain.ImportNotification.TransportRoute(message.ImportNotificationId,
                                                                                  mapper.Map <StateOfExport>(draft.StateOfExport),
                                                                                  mapper.Map <StateOfImport>(draft.StateOfImport));

                if (!draft.TransitStates.HasNoTransitStates)
                {
                    transportRoute.SetTransitStates(
                        new TransitStateList(draft.TransitStates.TransitStates.Select(t => mapper.Map <TransitState>(t))));
                }

                var wasteOperation = mapper.Map <WasteOperation>(draft.WasteOperation, notification);
                var wasteType      = mapper.Map <Domain.ImportNotification.WasteType>(draft.WasteType, draft.ChemicalComposition.Composition);

                exporterRepository.Add(exporter);
                facilityRepository.Add(facilityCollection);
                importerRepository.Add(importer);
                producerRepository.Add(producer);
                shipmentRepository.Add(shipment);
                transportRouteRepository.Add(transportRoute);
                wasteOperationRepository.Add(wasteOperation);
                wasteTypeRepository.Add(wasteType);

                assessment.Submit();

                await context.SaveChangesAsync();
            }

            return(result.IsValid);
        }
        public async Task <Unit> HandleAsync(SetImportKeyDatesOverride message)
        {
            var assessment = await assessmentRepository.GetByNotification(message.Data.NotificationId);

            var currentDecisionRequiredByDate = await decisionRequiredBy.GetDecisionRequiredByDate(assessment);

            if (currentDecisionRequiredByDate != message.Data.DecisionRequiredByDate)
            {
                await repository.SetDecisionRequiredByDateForNotification(assessment.Id, message.Data.DecisionRequiredByDate);
            }

            await repository.SetKeyDatesForNotification(message.Data);

            return(Unit.Value);
        }
Esempio n. 13
0
        public async Task <ImportNotificationAssessmentDecisionData> HandleAsync(GetImportNotificationAssessmentDecisionData message)
        {
            var facilityCollection = await facilityRepository.GetByNotificationId(message.ImportNotificationId);

            var isPreconsented = facilityCollection == null ? (bool?)null : facilityCollection.AllFacilitiesPreconsented;
            var assessment     = await assessmentRepository.GetByNotification(message.ImportNotificationId);

            return(new ImportNotificationAssessmentDecisionData
            {
                Status = assessment.Status,
                AvailableDecisions = assessment.GetAvailableDecisions().ToArray(),
                AcknowledgedOnDate = assessment.Dates.AcknowledgedDate.GetValueOrDefault(),
                IsPreconsented = isPreconsented,
                NotificationReceivedDate = assessment.Dates.NotificationReceivedDate.GetValueOrDefault()
            });
        }
        public ImportMovementFactoryTests()
        {
            assessmentRepository = A.Fake<IImportNotificationAssessmentRepository>();
            validator = A.Fake<IImportMovementNumberValidator>();

            A.CallTo(() => validator.Validate(notificationId, A<int>.Ignored))
                .Returns(true);

            assessment = new ImportNotificationAssessment(notificationId);
            ObjectInstantiator<ImportNotificationAssessment>.SetProperty(x => x.Status,
                ImportNotificationStatus.Consented, assessment);

            A.CallTo(() => assessmentRepository.GetByNotification(notificationId))
                .Returns(assessment);

            factory = new ImportMovementFactory(validator, assessmentRepository);
        }
        public async Task <AccountOverviewData> HandleAsync(GetImportNotificationAccountOverview message)
        {
            var assessment = await notificationAssessmentRepository.GetByNotification(message.ImportNotificationId);

            var charge = await chargeCalculator.GetValue(message.ImportNotificationId);

            var transactions = await transactionRepository.GetTransactions(message.ImportNotificationId);

            var totalPaid = await transactionCalculator.TotalPaid(message.ImportNotificationId);

            return(new AccountOverviewData
            {
                TotalCharge = charge,
                TotalPaid = totalPaid,
                Transactions = transactions.Select(t => mapper.Map <TransactionRecordData>(t)).ToArray(),
                PaymentReceived = assessment.Dates.PaymentReceivedDate
            });
        }
Esempio n. 16
0
        public ImportMovementFactoryTests()
        {
            SystemTime.Freeze(Today);
            assessmentRepository = A.Fake <IImportNotificationAssessmentRepository>();
            validator            = A.Fake <IImportMovementNumberValidator>();

            A.CallTo(() => validator.Validate(notificationId, A <int> .Ignored))
            .Returns(true);

            assessment = new ImportNotificationAssessment(notificationId);
            ObjectInstantiator <ImportNotificationAssessment> .SetProperty(x => x.Status,
                                                                           ImportNotificationStatus.Consented, assessment);

            A.CallTo(() => assessmentRepository.GetByNotification(notificationId))
            .Returns(assessment);

            factory = new ImportMovementFactory(validator, assessmentRepository);
        }
        public ImportPaymentTransactionTests()
        {
            importNotificationTransactionRepository = A.Fake <IImportNotificationTransactionRepository>();
            importNotificationTransactionCalculator = A.Fake <IImportNotificationTransactionCalculator>();
            importNotificationAssessmentRepository  = A.Fake <IImportNotificationAssessmentRepository>();

            assessment = new ImportNotificationAssessment(notificationId);

            A.CallTo(() => importNotificationAssessmentRepository.GetByNotification(notificationId))
            .Returns(assessment);

            A.CallTo(() => importNotificationTransactionCalculator.Balance(notificationId))
            .Returns(1000);

            transaction = new ImportPaymentTransaction(
                importNotificationTransactionRepository,
                importNotificationTransactionCalculator,
                importNotificationAssessmentRepository);
        }
Esempio n. 18
0
        public async Task <KeyDatesData> HandleAsync(GetKeyDates message)
        {
            var notification = await notificationRepository.Get(message.ImportNotificationId);

            var consultation = await consultationRepository.GetByNotificationId(message.ImportNotificationId);

            var assessment = await notificationAssessmentRepository.GetByNotification(message.ImportNotificationId);

            var interimStatus = await interimStatusRepository.GetByNotificationId(message.ImportNotificationId);

            var decisions = await notificationAssessmentDecisionRepository.GetByImportNotificationId(message.ImportNotificationId);

            var paymentReceived = await transactionCalculator.PaymentReceivedDate(message.ImportNotificationId) ??
                                  await transactionCalculator.LatestPayment(message.ImportNotificationId);

            DateTime?paymentReceivedDate = null;

            if (paymentReceived != null)
            {
                paymentReceivedDate = paymentReceived.Date;
            }

            return(new KeyDatesData
            {
                NotificationReceived = assessment.Dates.NotificationReceivedDate,
                PaymentReceived = paymentReceivedDate,
                IsPaymentComplete = assessment.Dates.PaymentReceivedDate.HasValue &&
                                    await transactionCalculator.PaymentIsNowFullyReceived(message.ImportNotificationId, 0),
                NameOfOfficer = assessment.Dates.NameOfOfficer,
                AssessmentStarted = assessment.Dates.AssessmentStartedDate,
                NotificationCompletedDate = assessment.Dates.NotificationCompletedDate,
                AcknowlegedDate = assessment.Dates.AcknowledgedDate,
                DecisionRequiredByDate = await decisionRequiredBy.GetDecisionRequiredByDate(assessment),
                IsInterim = interimStatus.IsInterim,
                FileClosedDate = assessment.Dates.FileClosedDate,
                ArchiveReference = assessment.Dates.ArchiveReference,
                DecisionHistory = decisions ?? new List <NotificationAssessmentDecision>(),
                CompententAuthority = notification.CompetentAuthority,
                IsLocalAreaSet = consultation != null && consultation.LocalAreaId.HasValue,
                Status = assessment.Status
            });
        }
        public async Task <Guid> HandleAsync(CreateImportNotification message)
        {
            var user = await internalUserRepository.GetByUserId(userContext.UserId);

            var notification = new ImportNotification(message.NotificationType, user.CompetentAuthority, message.Number);

            await importNotificationRepository.Add(notification);

            await context.SaveChangesAsync();

            var assessment = await assessmentRepository.GetByNotification(notification.Id);

            assessment.Receive(message.ReceivedDate);

            interimStatusRepository.Add(new InterimStatus(notification.Id, message.IsInterim));

            await context.SaveChangesAsync();

            return(notification.Id);
        }
Esempio n. 20
0
        public async Task <NotificationInfo> HandleAsync(GetNotificationInfo message)
        {
            var id = await notificationApplicationRepository.GetIdOrDefault(message.Number);

            var importId = await importNotificationRepository.GetIdOrDefault(message.Number);

            if (!id.HasValue && !importId.HasValue)
            {
                return(new NotificationInfo
                {
                    IsExistingNotification = false
                });
            }

            if (id.HasValue)
            {
                var notificationAssessment = await notificationAssessmentRepository.GetByNotificationId(id.Value);

                return(new NotificationInfo
                {
                    IsExistingNotification = true,
                    Id = id.Value,
                    ExportNotificationStatus = notificationAssessment.Status,
                    TradeDirection = TradeDirection.Export
                });
            }
            else
            {
                var notificationAssessment = await importNotificationAssessmentRepository.GetByNotification(importId.Value);

                return(new NotificationInfo
                {
                    IsExistingNotification = true,
                    Id = importId.Value,
                    ImportNotificationStatus = notificationAssessment.Status,
                    TradeDirection = TradeDirection.Import
                });
            }
        }
Esempio n. 21
0
        private async Task UpdatePaymentReceivedDate(DateTime?paymentDate, Guid notificationId)
        {
            var assessment = await assessmentRepository.GetByNotification(notificationId);

            if (paymentDate != null)
            {
                if (assessment.Status == ImportNotificationStatus.AwaitingPayment)
                {
                    assessment.PaymentComplete(paymentDate.GetValueOrDefault());
                }
                else
                {
                    assessment.Dates.PaymentReceivedDate = paymentDate;
                }
            }
            else
            {
                if (assessment.Dates.PaymentReceivedDate.HasValue)
                {
                    assessment.Dates.PaymentReceivedDate = null;
                }
            }
        }
Esempio n. 22
0
        public ImportRefundTransactionTests()
        {
            transactionRepository = A.Fake <IImportNotificationTransactionRepository>();
            transactionCalculator = A.Fake <IImportNotificationTransactionCalculator>();
            assessmentRepository  = A.Fake <IImportNotificationAssessmentRepository>();
            refundTransaction     = new ImportRefundTransaction(transactionRepository, transactionCalculator, assessmentRepository);
            notificationId        = new Guid("DB476D01-2870-4322-8284-520B34D9667B");

            A.CallTo(() => transactionCalculator.TotalPaid(notificationId)).Returns(100);
            A.CallTo(() => transactionRepository.GetTransactions(notificationId))
            .Returns(new[]
            {
                ImportNotificationTransaction.PaymentRecord(notificationId, new DateTime(2015, 12, 1), 100,
                                                            PaymentMethod.Cheque, "12345", "comments"),
            });

            var assessment = new ImportNotificationAssessment(notificationId);

            A.CallTo(() => assessmentRepository.GetByNotification(notificationId))
            .Returns(assessment);

            SystemTime.Freeze(new DateTime(2016, 1, 1));
        }