< Summary

Information
Class: OzonOrdersWeb.Areas.Settlements.Models.ArmtekInvoicePageViewModel
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Settlements/Models/ArmtekSettlementsViewModels.cs
Line coverage
95%
Covered lines: 46
Uncovered lines: 2
Coverable lines: 48
Total lines: 94
Line coverage: 95.8%
Branch coverage
84%
Covered branches: 42
Total branches: 50
Branch coverage: 84%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Kunnr()100%11100%
get_Vbeln()100%11100%
get_InvoiceId()100%11100%
get_LoadedAtUtc()100%11100%
get_HasInvoicePage()100%11100%
get_Header()100%11100%
get_TotalAmount()100%11100%
get_TotalQuantity()100%11100%
get_ReturnedQuantity()100%11100%
get_Currency()100%11100%
Build(...)83.33%484894.59%
Add()100%22100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Settlements/Models/ArmtekSettlementsViewModels.cs

#LineLine coverage
 1using System.Text.Json;
 2using OzonDomains.Models.ArmtekEtp;
 3
 4namespace OzonOrdersWeb.Areas.Settlements.Models;
 5
 6public sealed class ArmtekSettlementsPageViewModel
 7{
 8    public string Tab { get; init; } = "settlements";
 9    public int SettlementsCount { get; init; }
 10    public int InvoicesCount { get; init; }
 11    public int ItemsCount { get; init; }
 12    public DateTime? LastUpdatedAtUtc { get; init; }
 13    public string? LastError { get; init; }
 14    public DateTime? LastErrorAtUtc { get; init; }
 15    public string Schedule { get; init; } = string.Empty;
 16    public decimal? Balance { get; init; }
 17    public string? BalanceCurrency { get; init; }
 18    public DateTime? BalanceDate { get; init; }
 19    public bool CanSync { get; init; }
 20}
 21
 22/// <summary>Строка шапки фактуры для страницы: название, код партнёра и значение (как в кабинете Armtek).</summary>
 23public sealed record ArmtekInvoiceHeaderRow(string Label, string? Code, string Value);
 24
 25public sealed class ArmtekInvoicePageViewModel
 26{
 427    public string Kunnr { get; init; } = string.Empty;
 428    public string Vbeln { get; init; } = string.Empty;
 429    public long? InvoiceId { get; init; }
 230    public DateTime? LoadedAtUtc { get; init; }
 431    public bool HasInvoicePage { get; init; }
 732    public IReadOnlyList<ArmtekInvoiceHeaderRow> Header { get; init; } = [];
 233    public decimal TotalAmount { get; init; }
 234    public decimal TotalQuantity { get; init; }
 235    public decimal ReturnedQuantity { get; init; }
 236    public string? Currency { get; init; }
 37
 38    /// <summary>
 39    /// Шапка берётся из сохранённых строк кабинета (HeaderJson) — там все строки, в том числе те, что не разобраны в ко
 40    /// Без фактуры (платёж, ещё не загружена) показываются поля строки взаиморасчётов.
 41    /// </summary>
 42    public static ArmtekInvoicePageViewModel Build(string kunnr, string vbeln, ArmtekInvoice? invoice, ArmtekSettlement?
 43    {
 244        var header = new List<ArmtekInvoiceHeaderRow>();
 245        if (invoice != null)
 46        {
 47            try
 48            {
 149                using var doc = JsonDocument.Parse(invoice.HeaderJson);
 650                foreach (var f in doc.RootElement.EnumerateArray())
 51                {
 252                    var label = f.TryGetProperty("Label", out var l) ? l.GetString() : null;
 253                    var code = f.TryGetProperty("Code", out var c) && c.ValueKind == JsonValueKind.String ? c.GetString(
 254                    var text = f.TryGetProperty("Text", out var tx) ? tx.GetString() ?? string.Empty : string.Empty;
 255                    if (string.IsNullOrWhiteSpace(label)) continue;
 256                    if (code != null && text.StartsWith(code, StringComparison.Ordinal))
 157                        text = text[code.Length..].Trim();
 258                    header.Add(new ArmtekInvoiceHeaderRow(label, code, text));
 59                }
 160            }
 061            catch (JsonException)
 62            {
 63                // Битый снимок шапки — страница всё равно покажет позиции.
 064            }
 65        }
 166        else if (settlement != null)
 67        {
 2368            void Add(string label, string? value) { if (!string.IsNullOrWhiteSpace(value)) header.Add(new ArmtekInvoiceH
 169            Add("Дата документа", settlement.DocDate?.ToString("dd.MM.yyyy"));
 170            Add("Тип документа", settlement.DocTypeName ?? settlement.DocType);
 171            Add("Номер документа", settlement.PrintNumber ?? settlement.DocNumber);
 172            Add("Клиент", settlement.ClientName);
 173            Add("Сумма", settlement.Amount.ToString("N2"));
 174            Add("Сумма возврата", settlement.ReturnAmount.ToString("N2"));
 175            Add("Сумма платежа", settlement.PaymentAmount.ToString("N2"));
 176            Add("Сальдо", settlement.Balance?.ToString("N2"));
 177            Add("Договор", settlement.Contract);
 78        }
 79
 280        return new ArmtekInvoicePageViewModel
 281        {
 282            Kunnr = kunnr,
 283            Vbeln = vbeln,
 284            InvoiceId = invoice?.Id,
 285            LoadedAtUtc = invoice?.LoadedAtUtc,
 286            HasInvoicePage = invoice != null || settlement?.DocType is { } t && Services.ArmtekEtpServices.ArmtekEtpSync
 287            Header = header,
 288            TotalAmount = invoice?.TotalAmount ?? 0,
 289            TotalQuantity = invoice?.TotalQuantity ?? 0,
 290            ReturnedQuantity = invoice?.ReturnedQuantity ?? 0,
 291            Currency = settlement?.Currency
 292        };
 93    }
 94}