Exemplo n.º 1
0
            private void InstantiateProducerParameters()
            {
                TradingName = "Test trading name";

                scheme = A.Fake <Scheme>();

                MemberUpload = new MemberUpload(
                    A.Dummy <Guid>(),
                    A.Dummy <string>(),
                    A.Dummy <List <MemberUploadError> >(),
                    A.Dummy <decimal>(),
                    A.Dummy <int>(),
                    scheme,
                    A.Dummy <string>(),
                    A.Dummy <string>(),
                    A.Dummy <bool>());

                ProducerCharges = new Dictionary <string, ProducerCharge>();
                ProducerCharges.Add(TradingName, new ProducerCharge()
                {
                    ChargeBandAmount = new ChargeBandAmount()
                });

                GeneratedPrns = new Queue <string>();
                A.CallTo(() => DataAccess.ComputePrns(A <int> ._)).Returns(GeneratedPrns);

                BrandNames = Enumerable.Empty <string>().ToArray();
                SicCodes   = Enumerable.Empty <string>().ToArray();

                ProducerBusiness = new producerBusinessType()
                {
                    correspondentForNotices = new optionalContactDetailsContainerType()
                    {
                    },
                    Item = new companyType()
                    {
                        registeredOffice = new contactDetailsContainerType()
                        {
                            contactDetails = new contactDetailsType()
                            {
                                address = new addressType()
                                {
                                    country = countryType.UKENGLAND
                                }
                            }
                        }
                    }
                };

                AuthorisedRepresentative = null;

                EEEPlacedOnMarketBandType = eeePlacedOnMarketBandType.Lessthan5TEEEplacedonmarket;
                SellingTechnique          = sellingTechniqueType.Both;
                ObligationType            = obligationTypeType.Both;
                AnnualTurnoverBandType    = annualTurnoverBandType.Greaterthanonemillionpounds;
                CeaseDate          = null;
                RegistrationNumber = "TestRegistrationNumber";
                AnnualTurnover     = 10;
                VatRegistered      = false;
                Status             = statusType.I;
            }
Exemplo n.º 2
0
        public async Task <IEnumerable <ProducerSubmission> > GenerateProducerData(schemeType scheme, MemberUpload memberUpload, Dictionary <string, ProducerCharge> producerCharges)
        {
            if (memberUpload.ComplianceYear == null)
            {
                string errorMessage = "Producers cannot be generated for a member upload "
                                      + "that does not have a compliance year.";
                throw new InvalidOperationException(errorMessage);
            }

            List <ProducerSubmission> producers = new List <ProducerSubmission>();

            int            numberOfPrnsNeeded = scheme.producerList.Count(p => p.status == statusType.I);
            Queue <string> generatedPrns      = await dataAccess.ComputePrns(numberOfPrnsNeeded);

            foreach (producerType producerData in scheme.producerList)
            {
                var producerName = producerData.GetProducerName();

                if (producerCharges == null)
                {
                    throw new ApplicationException("No charges have been supplied");
                }
                if (!producerCharges.ContainsKey(producerName))
                {
                    throw new ApplicationException(string.Format("No charges have been supplied for the {0}.", producerName));
                }
                var chargeBandAmount = producerCharges[producerName].ChargeBandAmount;
                var chargeThisUpdate = producerCharges[producerName].Amount;

                List <BrandName> brandNames = producerData.producerBrandNames.Select(name => new BrandName(name)).ToList();

                List <SICCode> codes = producerData.SICCodeList.Select(name => new SICCode(name)).ToList();

                ProducerBusiness producerBusiness = await SetProducerBusiness(producerData.producerBusiness);

                AuthorisedRepresentative authorisedRepresentative = await SetAuthorisedRepresentative(producerData.authorisedRepresentative);

                EEEPlacedOnMarketBandType eeebandType = Enumeration.FromValue <EEEPlacedOnMarketBandType>((int)producerData.eeePlacedOnMarketBand);

                SellingTechniqueType sellingTechniqueType = Enumeration.FromValue <SellingTechniqueType>((int)producerData.sellingTechnique);

                ObligationType obligationType = producerData.obligationType.ToDomainObligationType();

                AnnualTurnOverBandType annualturnoverType = Enumeration.FromValue <AnnualTurnOverBandType>((int)producerData.annualTurnoverBand);

                StatusType status = Enumeration.FromValue <StatusType>((int)producerData.status);

                DateTime?ceaseDate = null;
                if (producerData.ceaseToExistDateSpecified)
                {
                    ceaseDate = producerData.ceaseToExistDate;
                }

                RegisteredProducer registeredProducer = null;

                string producerRegistrationNo;
                switch (producerData.status)
                {
                case statusType.I:
                    producerRegistrationNo = generatedPrns.Dequeue();
                    break;

                case statusType.A:
                    producerRegistrationNo = producerData.registrationNo;

                    await EnsureProducerRegistrationNumberExists(producerRegistrationNo);

                    registeredProducer = await dataAccess.FetchRegisteredProducerOrDefault(
                        producerRegistrationNo,
                        memberUpload.ComplianceYear.Value,
                        memberUpload.Scheme.Id);

                    break;

                default:
                    throw new NotSupportedException();
                }

                if (registeredProducer == null)
                {
                    registeredProducer = new RegisteredProducer(
                        producerRegistrationNo,
                        memberUpload.ComplianceYear.Value,
                        memberUpload.Scheme);
                }

                ProducerSubmission producer = new ProducerSubmission(
                    registeredProducer,
                    memberUpload,
                    producerBusiness,
                    authorisedRepresentative,
                    SystemTime.UtcNow,
                    producerData.annualTurnover,
                    producerData.VATRegistered,
                    ceaseDate,
                    producerData.tradingName,
                    eeebandType,
                    sellingTechniqueType,
                    obligationType,
                    annualturnoverType,
                    brandNames,
                    codes,
                    chargeBandAmount,
                    chargeThisUpdate,
                    status);

                // modify producer data
                switch (producerData.status)
                {
                case statusType.A:

                    if (registeredProducer.CurrentSubmission == null)
                    {
                        producers.Add(producer);
                    }
                    else
                    {
                        if (!registeredProducer.CurrentSubmission.Equals(producer))
                        {
                            producers.Add(producer);
                        }
                        else
                        {
                            /*
                             * The producer's details are the same as the current submission for this
                             * registration so we don't need to update them.
                             */
                        }
                    }
                    break;

                case statusType.I:
                    producers.Add(producer);
                    break;
                }
            }

            return(producers);
        }