< Summary

Information
Class: Services.ApiSupplierSettingsServices.SupplierQuotationPriceMultiplier
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiSupplierSettings/SupplierQuotationPriceMultiplier.cs
Line coverage
78%
Covered lines: 11
Uncovered lines: 3
Coverable lines: 14
Total lines: 40
Line coverage: 78.5%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
Clamp(...)100%11100%
Apply(...)100%22100%
Apply(...)100%22100%
Multiply(...)50%2266.66%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiSupplierSettings/SupplierQuotationPriceMultiplier.cs

#LineLine coverage
 1using System.Globalization;
 2using Services.ApiServices.TradesoftApi.Models.Response;
 3
 4namespace Services.ApiSupplierSettingsServices;
 5
 6/// <summary>Применяет коэффициент из настроек API-поставщика к себестоимости предложения.
 7/// Исходная цена закупки поставщика (<see cref="PreOrderItem.Price"/>) и исходная цена API (<see cref="PreOrderItem.Sou
 8/// намеренно остаются неизменными.</summary>
 9public static class SupplierQuotationPriceMultiplier
 10{
 011    public const decimal MinValue = 0.0001m;
 012    public const decimal MaxValue = 100m;
 13
 914    public static decimal Clamp(decimal value) => Math.Clamp(value, MinValue, MaxValue);
 15
 16    public static void Apply(IEnumerable<PreOrderItem> items, decimal multiplier)
 17    {
 2018        foreach (var item in items) Apply(item, multiplier);
 419    }
 20
 21    public static void Apply(PreOrderItem item, decimal multiplier)
 22    {
 523        var normalized = Clamp(multiplier);
 524        item.PriceMultiplier = normalized;
 825        if (normalized == 1m) return;
 26
 227        item.CostPrice = Multiply(item.CostPrice, normalized);
 28        // Форматированное значение часто дублирует CostPrice; сбрасываем его, чтобы UI показал
 29        // уже пересчитанное число, а не старую строку поставщика.
 230        item.CostPriceFormatted = null;
 231    }
 32
 33    private static string? Multiply(string? value, decimal multiplier)
 34    {
 235        if (!decimal.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out var parsed))
 036            return value;
 37
 238        return (parsed * multiplier).ToString("0.####", CultureInfo.InvariantCulture);
 39    }
 40}