From 8cb3239745cc02e3f3d80df7716732e5e8e7fffe Mon Sep 17 00:00:00 2001 From: Pavel Zhur Date: Tue, 16 Jul 2024 18:05:52 +0300 Subject: [PATCH] billing by category --- .../Services/Commands/DomainAdmin/ViewBilling.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/OneShelf.OneDog/OneShelf.OneDog.Processor/Services/Commands/DomainAdmin/ViewBilling.cs b/OneShelf.OneDog/OneShelf.OneDog.Processor/Services/Commands/DomainAdmin/ViewBilling.cs index ecdd6549..ab1d5bcb 100644 --- a/OneShelf.OneDog/OneShelf.OneDog.Processor/Services/Commands/DomainAdmin/ViewBilling.cs +++ b/OneShelf.OneDog/OneShelf.OneDog.Processor/Services/Commands/DomainAdmin/ViewBilling.cs @@ -31,8 +31,12 @@ protected override async Task ExecuteQuickly() private async Task ExecuteBackground() { var all = await _billingApiClient.All(ScopeAwareness.DomainId); - var total = all.Usages.Where(x => x.Price.HasValue).Sum(x => x.Price); - if (total is 0 or null) + var totals = all.Usages + .Where(x => x.Price > 0) + .GroupBy(x => x.Category ?? "unknown") + .ToDictionary(x => x.Key, x => x.Sum(x => x.Price!.Value)); + + if (!totals.Any()) { Io.WriteLine("Пока ничего нет."); return; @@ -40,6 +44,9 @@ private async Task ExecuteBackground() var domain = await _dogDatabase.Domains.SingleAsync(x => x.Id == ScopeAwareness.DomainId); - Io.WriteLine($"Использовано {total * (domain.BillingRatio ?? 1):C}."); + foreach (var total in totals) + { + Io.WriteLine($"Использовано {total.Key} {total.Value * (domain.BillingRatio ?? 1):C}."); + } } } \ No newline at end of file