Ejemplo n.º 1
0
        public async Task <ActionResult> DownloadFile(SpecifyOptionsViewModel viewModel)
        {
            if (!await CheckOrganisationExists(viewModel.OrganisationID))
            {
                return(RedirectToAction("SelectOrganisation"));
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("SpecifyOptions", new { viewModel.OrganisationID }));
            }

            TestFileSettings settings = new TestFileSettings(
                viewModel.OrganisationID,
                new Quarter(viewModel.ComplianceYear, viewModel.Quarter));

            settings.NumberOfAatfs    = viewModel.NumberOfAatfs;
            settings.NumberOfAes      = viewModel.NumberOfAes;
            settings.AllProducers     = viewModel.AllProducers;
            settings.NumberOfProduces = viewModel.NumberOfProducers;

            FileInfo xmlFile = await GenerateXml(settings);

            ContentDisposition cd = new ContentDisposition
            {
                FileName = xmlFile.FileName,
                Inline   = false,
            };

            Response.AppendHeader("Content-Disposition", cd.ToString());

            return(File(xmlFile.Data, "application/xml"));
        }
Ejemplo n.º 2
0
 private async Task <FileInfo> GenerateXml(TestFileSettings settings)
 {
     using (IWeeeClient client = apiClient())
     {
         return(await client.SendAsync(
                    User.GetAccessToken(),
                    new CreateTestXmlFile(settings)));
     }
 }
Ejemplo n.º 3
0
 public CreateTestXmlFile(TestFileSettings settings)
 {
     Settings = settings;
 }
 private async Task<FileInfo> GenerateXml(TestFileSettings settings)
 {
     using (IWeeeClient client = apiClient())
     {
         return await client.SendAsync(
             User.GetAccessToken(), 
             new CreateTestXmlFile(settings));
     }
 }
        public async Task<ActionResult> DownloadFile(SpecifyOptionsViewModel viewModel)
        {
            if (!await CheckOrganisationExists(viewModel.OrganisationID))
            {
                return RedirectToAction("SelectOrganisation");
            }

            if (!ModelState.IsValid)
            {
                return RedirectToAction("SpecifyOptions", new { viewModel.OrganisationID });
            }

            TestFileSettings settings = new TestFileSettings(
                viewModel.OrganisationID,
                new Quarter(viewModel.ComplianceYear, viewModel.Quarter));

            settings.NumberOfAatfs = viewModel.NumberOfAatfs;
            settings.NumberOfAes = viewModel.NumberOfAes;
            settings.AllProducers = viewModel.AllProducers;
            settings.NumberOfProduces = viewModel.NumberOfProducers;

            FileInfo xmlFile = await GenerateXml(settings);

            ContentDisposition cd = new ContentDisposition
            {
                FileName = xmlFile.FileName, 
                Inline = false, 
            };

            Response.AppendHeader("Content-Disposition", cd.ToString());

            return File(xmlFile.Data, "application/xml");
        }
        public async Task<DataReturnVersion> GenerateAsync(TestFileSettings settings)
        {
            if (settings.NumberOfAatfs < 0 || settings.NumberOfAatfs > 250)
            {
                throw new ArgumentOutOfRangeException("settings", "The number of AATFs specified in the settings number be in the range [0, 250].");
            }

            if (settings.NumberOfAes < 0 || settings.NumberOfAes > 50)
            {
                throw new ArgumentOutOfRangeException("settings", "The number of AEs specified in the settings number be in the range [0, 50].");
            }

            Domain.Scheme.Scheme scheme = await dataAccess.FetchSchemeAsync(settings.OrganisationID);

            Quarter quarter = new Quarter(
                settings.Quarter.Year,
                (QuarterType)settings.Quarter.Q);

            DataReturn dataReturn = new DataReturn(scheme, quarter);

            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            IEnumerable<ReturnItem> returnItemsCollectedFromDcf = CreateReturnItems(null);
            foreach (var returnItem in returnItemsCollectedFromDcf)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            int numberOfDeliveredToAatfs = settings.NumberOfAatfs;
            int aatfApprovalNumberSeedOffset = r.Next(250);

            List<string> aatfApprovalNumbers = new List<string>();
            for (int index = 0; index < numberOfDeliveredToAatfs; ++index)
            {
                int approvalNumberSeed = (index + aatfApprovalNumberSeedOffset) % 250;
                aatfApprovalNumbers.Add(GetAtfApprovalNumber(approvalNumberSeed));
            }

            IOrderedEnumerable<string> orderedAatfApprovalNumbers = aatfApprovalNumbers.OrderBy(x => x);

            foreach (string approvalNumber in orderedAatfApprovalNumbers)
            {
                var deliveredToAatfs = CreateDeliveredToAatfs(approvalNumber);
                foreach (var deliveredToAatf in deliveredToAatfs)
                {
                    dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount(deliveredToAatf);
                }
            }

            int numberOfDeliveredToAes = settings.NumberOfAes;
            int aaeApprovalNumberSeedOffset = r.Next(50);

            List<string> aaeApprovalNumbers = new List<string>();
            for (int index = 0; index < numberOfDeliveredToAes; ++index)
            {
                int approvalNumberSeed = (index + aaeApprovalNumberSeedOffset) % 250;
                aaeApprovalNumbers.Add(GetAeApprovalNumber(approvalNumberSeed));
            }

            IOrderedEnumerable<string> orderedAaeApprovalNumbers = aaeApprovalNumbers.OrderBy(x => x);

            foreach (string approvalNumber in orderedAaeApprovalNumbers)
            {
                var deliveredToAes = CreateDeliveredToAes(approvalNumber);
                foreach (var deliveredToAe in deliveredToAes)
                {
                    dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount(deliveredToAe);
                }
            }

            IEnumerable<ReturnItem> b2cWeeeFromDistributors = CreateReturnItems(ObligationType.B2C);
            foreach (var returnItem in b2cWeeeFromDistributors)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            IEnumerable<ReturnItem> b2cWeeeFromFinalHolders = CreateReturnItems(ObligationType.B2C);
            foreach (var returnItem in b2cWeeeFromFinalHolders)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.FinalHolder,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            IList<RegisteredProducer> registeredProducers = await dataAccess.FetchRegisteredProducersAsync(scheme, quarter.Year);

            int numberOfProducers;
            if (settings.AllProducers)
            {
                numberOfProducers = registeredProducers.Count;
            }
            else
            {
                numberOfProducers = Math.Min(settings.NumberOfProduces, registeredProducers.Count);
            }

            IOrderedEnumerable<RegisteredProducer> producersToInclude = registeredProducers
                .Shuffle()
                .Take(numberOfProducers)
                .OrderBy(x => x.ProducerRegistrationNumber);

            foreach (RegisteredProducer producerToInclude in producersToInclude)
            {
                var eeeOutputAmounts = CreateEeeOutputAmounts(producerToInclude);

                foreach (var eeeOutputAmount in eeeOutputAmounts)
                {
                    dataReturnVersion.EeeOutputReturnVersion.AddEeeOutputAmount(eeeOutputAmount);
                }
            }

            return dataReturnVersion;
        }
Ejemplo n.º 7
0
        public async Task <DataReturnVersion> GenerateAsync(TestFileSettings settings)
        {
            if (settings.NumberOfAatfs < 0 || settings.NumberOfAatfs > 250)
            {
                throw new ArgumentOutOfRangeException("settings", "The number of AATFs specified in the settings number be in the range [0, 250].");
            }

            if (settings.NumberOfAes < 0 || settings.NumberOfAes > 50)
            {
                throw new ArgumentOutOfRangeException("settings", "The number of AEs specified in the settings number be in the range [0, 50].");
            }

            Domain.Scheme.Scheme scheme = await dataAccess.FetchSchemeAsync(settings.OrganisationID);

            Quarter quarter = new Quarter(
                settings.Quarter.Year,
                (QuarterType)settings.Quarter.Q);

            DataReturn dataReturn = new DataReturn(scheme, quarter);

            DataReturnVersion dataReturnVersion = new DataReturnVersion(dataReturn);

            IEnumerable <ReturnItem> returnItemsCollectedFromDcf = CreateReturnItems(null);

            foreach (var returnItem in returnItemsCollectedFromDcf)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Dcf,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            int numberOfDeliveredToAatfs     = settings.NumberOfAatfs;
            int aatfApprovalNumberSeedOffset = r.Next(250);

            List <string> aatfApprovalNumbers = new List <string>();

            for (int index = 0; index < numberOfDeliveredToAatfs; ++index)
            {
                int approvalNumberSeed = (index + aatfApprovalNumberSeedOffset) % 250;
                aatfApprovalNumbers.Add(GetAtfApprovalNumber(approvalNumberSeed));
            }

            IOrderedEnumerable <string> orderedAatfApprovalNumbers = aatfApprovalNumbers.OrderBy(x => x);

            foreach (string approvalNumber in orderedAatfApprovalNumbers)
            {
                var deliveredToAatfs = CreateDeliveredToAatfs(approvalNumber);
                foreach (var deliveredToAatf in deliveredToAatfs)
                {
                    dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount(deliveredToAatf);
                }
            }

            int numberOfDeliveredToAes      = settings.NumberOfAes;
            int aaeApprovalNumberSeedOffset = r.Next(50);

            List <string> aaeApprovalNumbers = new List <string>();

            for (int index = 0; index < numberOfDeliveredToAes; ++index)
            {
                int approvalNumberSeed = (index + aaeApprovalNumberSeedOffset) % 250;
                aaeApprovalNumbers.Add(GetAeApprovalNumber(approvalNumberSeed));
            }

            IOrderedEnumerable <string> orderedAaeApprovalNumbers = aaeApprovalNumbers.OrderBy(x => x);

            foreach (string approvalNumber in orderedAaeApprovalNumbers)
            {
                var deliveredToAes = CreateDeliveredToAes(approvalNumber);
                foreach (var deliveredToAe in deliveredToAes)
                {
                    dataReturnVersion.WeeeDeliveredReturnVersion.AddWeeeDeliveredAmount(deliveredToAe);
                }
            }

            IEnumerable <ReturnItem> b2cWeeeFromDistributors = CreateReturnItems(ObligationType.B2C);

            foreach (var returnItem in b2cWeeeFromDistributors)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.Distributor,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            IEnumerable <ReturnItem> b2cWeeeFromFinalHolders = CreateReturnItems(ObligationType.B2C);

            foreach (var returnItem in b2cWeeeFromFinalHolders)
            {
                dataReturnVersion.WeeeCollectedReturnVersion.AddWeeeCollectedAmount(
                    new WeeeCollectedAmount(WeeeCollectedAmountSourceType.FinalHolder,
                                            returnItem.ObligationType,
                                            returnItem.WeeeCategory,
                                            returnItem.Tonnage));
            }

            IList <RegisteredProducer> registeredProducers = await dataAccess.FetchRegisteredProducersAsync(scheme, quarter.Year);

            int numberOfProducers;

            if (settings.AllProducers)
            {
                numberOfProducers = registeredProducers.Count;
            }
            else
            {
                numberOfProducers = Math.Min(settings.NumberOfProduces, registeredProducers.Count);
            }

            IOrderedEnumerable <RegisteredProducer> producersToInclude = registeredProducers
                                                                         .Shuffle()
                                                                         .Take(numberOfProducers)
                                                                         .OrderBy(x => x.ProducerRegistrationNumber);

            foreach (RegisteredProducer producerToInclude in producersToInclude)
            {
                var eeeOutputAmounts = CreateEeeOutputAmounts(producerToInclude);

                foreach (var eeeOutputAmount in eeeOutputAmounts)
                {
                    dataReturnVersion.EeeOutputReturnVersion.AddEeeOutputAmount(eeeOutputAmount);
                }
            }

            return(dataReturnVersion);
        }