Exemple #1
0
        private async Task GenerateInvoices(IList <Guid> packageIds, Payrun payrun, InvoiceTypes invoiceType)
        {
            var lastInvoiceNumber = await _invoiceGateway.GetInvoicesCountAsync();

            var iterations = Math.Ceiling((double)packageIds.Count / PackageBatchSize);

            for (var i = 0; i < iterations; i++)
            {
                var batchIds = packageIds.Skip(i * PackageBatchSize).Take(PackageBatchSize).ToList();
                var packages = await _carePackageGateway.GetListAsync(batchIds);

                var invoices = await _invoiceGenerator.GenerateAsync(packages, payrun.EndDate, invoiceType, lastInvoiceNumber);

                _logger.LogDebug("Generated invoices: {Invoices}", JsonConvert.SerializeObject(invoices, Formatting.Indented));

                foreach (var invoice in invoices)
                {
                    if (!invoice.Items.Any())
                    {
                        continue;
                    }

                    var payrunInvoice = new PayrunInvoice
                    {
                        Payrun        = payrun,
                        Invoice       = invoice,
                        InvoiceStatus = InvoiceStatus.Accepted
                    };

                    payrun.PayrunInvoices.Add(payrunInvoice);
                }

                lastInvoiceNumber += invoices.Count;
            }
        }
Exemple #2
0
        public ChangePayRunInvoiceStatusUseCaseTests()
        {
            _payRunGateway        = new Mock <IPayRunGateway>();
            _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();
            _dbManager            = new Mock <IDatabaseManager>();
            _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.WaitingForApproval);

            var fixture = new Fixture();

            _payrunInvoice = fixture.Build <PayrunInvoice>()
                             .OmitAutoProperties()
                             .With(pi => pi.PayrunId, _payrun.Id)
                             .With(pi => pi.InvoiceStatus, InvoiceStatus.Draft)
                             .Create();
            _payrun.PayrunInvoices.Add(_payrunInvoice);

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _payRunInvoiceGateway.Setup(g => g.GetPayRunInvoiceAsync(It.IsAny <Guid>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrunInvoice);

            _useCase = new ChangePayRunInvoiceStatusUseCase(_dbManager.Object, _payRunGateway.Object,
                                                            _payRunInvoiceGateway.Object);
        }
Exemple #3
0
        public HoldInvoiceUseCaseTests()
        {
            _dbManager            = new Mock <IDatabaseManager>();
            _heldInvoiceGateway   = new Mock <IHeldInvoiceGateway>();
            _payRunInvoiceGateway = new Mock <IPayRunInvoiceGateway>();
            _payRunGateway        = new Mock <IPayRunGateway>();

            _payrun = TestDataHelper.CreatePayRun(type: PayrunType.ResidentialRecurring, status: PayrunStatus.WaitingForApproval);

            var fixture = new Fixture();

            _payrunInvoice = fixture.Build <PayrunInvoice>()
                             .OmitAutoProperties()
                             .With(pi => pi.PayrunId, _payrun.Id)
                             .With(pi => pi.InvoiceStatus, InvoiceStatus.Draft)
                             .Create();
            _payrun.PayrunInvoices.Add(_payrunInvoice);

            _payRunGateway.Setup(g => g.GetPayRunAsync(It.IsAny <Guid>(), It.IsAny <PayRunFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrun);

            _payRunInvoiceGateway.Setup(g => g.GetPayRunInvoiceAsync(It.IsAny <Guid>(), It.IsAny <PayRunInvoiceFields>(), It.IsAny <bool>()))
            .ReturnsAsync(_payrunInvoice);

            _useCase = new HoldInvoiceUseCase(_dbManager.Object, _heldInvoiceGateway.Object,
                                              _payRunInvoiceGateway.Object, _payRunGateway.Object);

            _heldInvoiceCreationDomain = new HeldInvoiceCreationDomain
            {
                PayRunInvoiceId      = _payrunInvoice.Id,
                ActionRequiredFromId = 1,
                ReasonForHolding     = "Incorrect values"
            };
        }