public override IEnumerable <InvoiceItem> CreateRefundItems(CarePackage package, IList <InvoiceDomain> packageInvoices)
        {
            var oneOffs = package.Details.Where(d => d.CostPeriod == PaymentPeriod.OneOff);

            foreach (var detail in oneOffs)
            {
                var refunds = RefundCalculator.Calculate(
                    detail, packageInvoices,
                    (paymentRange, quantity) => CalculateCostForPeriod(detail, paymentRange));

                foreach (var refund in refunds)
                {
                    yield return(new InvoiceItem
                    {
                        Name = $"{GetDetailItemName(detail)} (adjustment)",
                        Quantity = 1,
                        WeeklyCost = 0.0m,
                        TotalCost = refund.Amount,
                        FromDate = refund.StartDate,
                        ToDate = (detail.EndDate is null)
                            ? refund.StartDate // ongoing one-offs are infinite, so voluntarily limit end date to same day as start
                            : refund.EndDate,
                        CarePackageDetailId = detail.Id,
                        SourceVersion = detail.Version,
                        PriceEffect = refund.Amount > 0
                            ? PriceEffect.Add
                            : PriceEffect.Subtract
                    });
        public override IEnumerable <InvoiceItem> CreateRefundItems(CarePackage package, IList <InvoiceDomain> packageInvoices)
        {
            var weeklyDetails = package.Details.Where(d => d.CostPeriod == PaymentPeriod.Weekly);

            foreach (var detail in weeklyDetails)
            {
                var refunds = RefundCalculator.Calculate(
                    detail, packageInvoices,
                    (paymentRange, quantity) => detail.Cost * quantity);

                foreach (var refund in refunds)
                {
                    yield return(new InvoiceItem
                    {
                        Name = $"{GetDetailItemName(detail)} (adjustment)",
                        Quantity = refund.Quantity,
                        WeeklyCost = detail.Cost,
                        TotalCost = refund.Amount,
                        FromDate = refund.StartDate,
                        ToDate = refund.EndDate,
                        CarePackageDetailId = detail.Id,
                        SourceVersion = detail.Version,
                        PriceEffect = refund.Amount > 0
                            ? PriceEffect.Add
                            : PriceEffect.Subtract
                    });
                }
            }
        }
        public override IEnumerable <InvoiceItem> CreateRefundItems(CarePackage package, IList <InvoiceDomain> packageInvoices)
        {
            var fundedNursingCare = package.Reclaims
                                    .Where(r => r.Type is ReclaimType.Fnc)
                                    .ToList();

            foreach (var reclaim in fundedNursingCare)
            {
                var refunds = RefundCalculator.Calculate(
                    reclaim, packageInvoices,
                    (paymentRange, quantity) => CalculateFncPriceForPeriod(paymentRange, reclaim));

                foreach (var refund in refunds)
                {
                    yield return(new InvoiceItem
                    {
                        Name = $"Funded Nursing Care (adjustment) {FormatDescription(reclaim.Description)}",
                        Quantity = refund.Quantity,
                        WeeklyCost = GetPriceForDate(refund.StartDate),
                        TotalCost = refund.Amount,
                        FromDate = refund.StartDate,
                        ToDate = refund.EndDate,
                        CarePackageReclaimId = reclaim.Id,
                        SourceVersion = reclaim.Version,
                        PriceEffect = refund.Amount > 0
                            ? PriceEffect.Add
                            : PriceEffect.Subtract
                    });
                }
            }
        }