diff --git a/src/ElectronicPharmacy/HelpForms/HF_DownloadDataFromServer.cs b/src/ElectronicPharmacy/HelpForms/HF_DownloadDataFromServer.cs index 9c5babd..969822d 100644 --- a/src/ElectronicPharmacy/HelpForms/HF_DownloadDataFromServer.cs +++ b/src/ElectronicPharmacy/HelpForms/HF_DownloadDataFromServer.cs @@ -59,23 +59,9 @@ namespace Электронная_Фармация.HelpForms var allSuppliersSummary = await GetFullPriceSummaryPagedAsync(client); int totalItems = allSuppliersSummary.Summary?.Count ?? 0; - AppendStatus("Загружаю скидки покупателя / прайса / региона..."); - var discountLookup = await DiscountResolver.LoadAsync(client, _login); - if (!string.IsNullOrWhiteSpace(discountLookup.BuyerId)) - { - AppendStatus($"buyer_id: {discountLookup.BuyerId}"); - } - else - { - AppendStatus("buyer_id не найден — клиентская скидка будет 0, если не пришла иначе"); - } - - AppendStatus($"Прайс-листов со скидками: {discountLookup.ByPriceListId.Count}"); - ApplyClientMarkupSettings(allSuppliersSummary); - if (allSuppliersSummary.MarkupPercent.HasValue) - { - AppendStatus($"Скидка из summary: {allSuppliersSummary.MarkupPercent.Value:0.##}%"); - } + // Наценки прайса/региона/покупателя считает сервер. + // Десктоп сохраняет цену из API как есть, без локального пересчёта. + AppendStatus("Цена берётся с сервера без локального пересчёта наценок"); AppendStatus($"Получено {totalItems} позиций"); SetOverallProgress(DownloadPhaseEnd, $"Получено {totalItems} / {totalItems} позиций (100%)"); @@ -88,7 +74,7 @@ namespace Электронная_Фармация.HelpForms phasePercent, $"Обработка: {p.Current} / {p.Total} ({PercentOf(p.Current, p.Total)}%)"); }); - var tablePrice = await Task.Run(() => BuildPriceTable(allSuppliersSummary, discountLookup, buildProgress)); + var tablePrice = await Task.Run(() => BuildPriceTable(allSuppliersSummary, buildProgress)); SetOverallProgress(BuildPhaseEnd, "Сохранение в локальную базу..."); var saveProgress = new Progress(p => @@ -366,18 +352,6 @@ namespace Электронная_Фармация.HelpForms } } - private static void ApplyClientMarkupSettings(PriceSummaryResponse response) - { - // Серверный % используем только как стартовое значение для аптек, - // у которых клиент ещё ничего не сохранил. Уже введённые проценты не трогаем. - if (response?.MarkupPercent == null) - { - return; - } - - ConsigneeHelper.SeedClientMarkupPercentIfEmpty(response.MarkupPercent); - } - private void ReportTransferProgress(HttpTransferProgress transfer) { if (transfer.TotalBytes.HasValue && transfer.TotalBytes.Value > 0) @@ -397,7 +371,6 @@ namespace Электронная_Фармация.HelpForms private static DataTable BuildPriceTable( PriceSummaryResponse allSuppliersSummary, - DiscountLookup discountLookup, IProgress progress = null) { var tablePrice = new DataTable(); @@ -447,7 +420,6 @@ namespace Электронная_Фармация.HelpForms return tablePrice; } - var summaryClientDiscount = allSuppliersSummary.MarkupPercent; int total = allSuppliersSummary.Summary.Count; int current = 0; foreach (var item in allSuppliersSummary.Summary) @@ -460,19 +432,9 @@ namespace Электронная_Фармация.HelpForms row["DrugName"] = item.DrugName ?? string.Empty; row["SupplierName"] = item.SupplierName ?? string.Empty; - var parts = DiscountResolver.ResolveForItem(discountLookup, item); - // Вешаем только то, что пришло. Нет значения = 0. - // summary.markup_percent / item.markup_percent — доп. источник, если API ещё отдаёт. - var totalDiscount = MarkupHelper.SumDiscountPercents( - parts.PriceListDiscountPct, - parts.RegionDiscountPct, - parts.ClientDiscountPct > 0m ? parts.ClientDiscountPct : (decimal?)null, - parts.ClientDiscountPct <= 0m ? summaryClientDiscount : null, - item.MarkupPercent); - - var basePrice = item.Price ?? 0m; - var finalPrice = MarkupHelper.ApplyDiscount(basePrice, totalDiscount); - row["Price"] = finalPrice.ToString(System.Globalization.CultureInfo.InvariantCulture); + // Цена уже итоговая с сервера — локально не пересчитываем. + var serverPrice = item.Price ?? 0m; + row["Price"] = serverPrice.ToString(System.Globalization.CultureInfo.InvariantCulture); row["Quantity"] = item.Quantity?.ToString() ?? string.Empty; row["ExpiryPeriod"] = item.ExpiryPeriod == null ? (object)DBNull.Value : item.ExpiryPeriod; row["Description"] = item.Description == null ? (object)DBNull.Value : item.Description; @@ -480,7 +442,9 @@ namespace Электронная_Фармация.HelpForms row["SummaZakaza"] = string.Empty; row["TradeName"] = string.IsNullOrWhiteSpace(item.TradeName) ? (object)DBNull.Value : item.TradeName.Trim(); row["Dosage"] = string.IsNullOrWhiteSpace(item.Dosage) ? (object)DBNull.Value : item.Dosage.Trim(); - row["MarkupPercent"] = totalDiscount; + row["MarkupPercent"] = item.MarkupPercent.HasValue && item.MarkupPercent.Value > 0m + ? item.MarkupPercent.Value + : 0m; tablePrice.Rows.Add(row); current++;