Apply client markup_percent from price API and fix truncated download logs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Magomed 2026-07-20 11:36:20 +03:00
parent 999cfe4121
commit 5c439fe780
12 changed files with 272 additions and 25 deletions

View File

@ -103,6 +103,7 @@ GET /api/supplier-prices/summary?supplier_id={uuid}
```json ```json
{ {
"markup_percent": 15.5,
"summary": [ "summary": [
{ {
"supplier_price_id": "uuid", "supplier_price_id": "uuid",
@ -114,6 +115,7 @@ GET /api/supplier-prices/summary?supplier_id={uuid}
"cure_form": "таб.", "cure_form": "таб.",
"barcode": "...", "barcode": "...",
"price": 123.45, "price": 123.45,
"markup_percent": 15.5,
"quantity": 10, "quantity": 10,
"region_id": "...", "region_id": "...",
"region_name": "...", "region_name": "...",

View File

@ -27,6 +27,9 @@
<setting name="IntDefaultPercentMarkup" serializeAs="String"> <setting name="IntDefaultPercentMarkup" serializeAs="String">
<value>0</value> <value>0</value>
</setting> </setting>
<setting name="ClientMarkupPercent" serializeAs="String">
<value>0</value>
</setting>
<setting name="stringLogin" serializeAs="String"> <setting name="stringLogin" serializeAs="String">
<value /> <value />
</setting> </setting>

View File

@ -0,0 +1,65 @@
using System;
namespace Электроннаяармация.Classes
{
public static class MarkupHelper
{
public const decimal FallbackMarkupPercent = 30m;
public static decimal ResolveMarkupPercent(decimal? itemMarkup, decimal? clientMarkup, decimal fallbackMarkup)
{
if (itemMarkup.HasValue && itemMarkup.Value >= 0)
{
return itemMarkup.Value;
}
if (clientMarkup.HasValue && clientMarkup.Value >= 0)
{
return clientMarkup.Value;
}
return fallbackMarkup > 0 ? fallbackMarkup : FallbackMarkupPercent;
}
public static decimal ApplyMarkup(decimal basePrice, decimal markupPercent)
{
return basePrice + (basePrice * markupPercent / 100m);
}
public static bool TryParseMarkup(object value, out decimal markupPercent)
{
markupPercent = 0m;
if (value == null || value == DBNull.Value)
{
return false;
}
if (value is decimal decimalValue)
{
markupPercent = decimalValue;
return true;
}
if (value is double doubleValue)
{
markupPercent = (decimal)doubleValue;
return true;
}
if (value is float floatValue)
{
markupPercent = (decimal)floatValue;
return true;
}
if (value is int intValue)
{
markupPercent = intValue;
return true;
}
var text = value.ToString()?.Trim().Replace(',', '.');
return !string.IsNullOrWhiteSpace(text) && decimal.TryParse(text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out markupPercent);
}
}
}

View File

@ -56,11 +56,17 @@ namespace Электронная_Фармация.Classes
public string Barcode { get; set; } public string Barcode { get; set; }
/// <summary> /// <summary>
/// Финальная цена с учетом наценки (рассчитана на сервере) /// Базовая цена поставщика (без розничной наценки клиента).
/// </summary> /// </summary>
[JsonPropertyName("price")] [JsonPropertyName("price")]
public decimal? Price { get; set; } public decimal? Price { get; set; }
/// <summary>
/// Процент наценки для позиции. Если не задан — используется markup_percent из ответа прайса.
/// </summary>
[JsonPropertyName("markup_percent")]
public decimal? MarkupPercent { get; set; }
/// <summary> /// <summary>
/// Количество товара на складе /// Количество товара на складе
/// </summary> /// </summary>

View File

@ -9,6 +9,12 @@ namespace Электронная_Фармация.Classes
{ {
public class PriceSummaryResponse public class PriceSummaryResponse
{ {
/// <summary>
/// Процент наценки для текущего клиента (покупателя), приходит вместе с прайсом.
/// </summary>
[JsonPropertyName("markup_percent")]
public decimal? MarkupPercent { get; set; }
[JsonPropertyName("summary")] [JsonPropertyName("summary")]
public List<PriceSummaryItem> Summary { get; set; } public List<PriceSummaryItem> Summary { get; set; }
} }

View File

@ -111,6 +111,7 @@
<Compile Include="Classes\InvoiceSyncService.cs" /> <Compile Include="Classes\InvoiceSyncService.cs" />
<Compile Include="Classes\LoginRequest.cs" /> <Compile Include="Classes\LoginRequest.cs" />
<Compile Include="Classes\LoginResponse.cs" /> <Compile Include="Classes\LoginResponse.cs" />
<Compile Include="Classes\MarkupHelper.cs" />
<Compile Include="Classes\AppServices.cs" /> <Compile Include="Classes\AppServices.cs" />
<Compile Include="Classes\UiDialogs.cs" /> <Compile Include="Classes\UiDialogs.cs" />
<Compile Include="Classes\UiThemeHelper.cs" /> <Compile Include="Classes\UiThemeHelper.cs" />

View File

@ -402,6 +402,7 @@ create table if not exists [OrderItems] (
TryAddColumn(conForCheckTables, "Invoice", "IsRequestedInvoice", "int(1)"); TryAddColumn(conForCheckTables, "Invoice", "IsRequestedInvoice", "int(1)");
TryAddColumn(conForCheckTables, "PriceList", "TradeName", "nvarchar(256)"); TryAddColumn(conForCheckTables, "PriceList", "TradeName", "nvarchar(256)");
TryAddColumn(conForCheckTables, "PriceList", "Dosage", "nvarchar(128)"); TryAddColumn(conForCheckTables, "PriceList", "Dosage", "nvarchar(128)");
TryAddColumn(conForCheckTables, "PriceList", "MarkupPercent", "real");
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -51,6 +51,8 @@
// //
// progressDownload // progressDownload
// //
this.progressDownload.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressDownload.Location = new System.Drawing.Point(25, 52); this.progressDownload.Location = new System.Drawing.Point(25, 52);
this.progressDownload.Name = "progressDownload"; this.progressDownload.Name = "progressDownload";
this.progressDownload.Size = new System.Drawing.Size(630, 22); this.progressDownload.Size = new System.Drawing.Size(630, 22);
@ -60,23 +62,34 @@
// //
// lblProgress // lblProgress
// //
this.lblProgress.AutoEllipsis = true; this.lblProgress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.lblProgress.Font = new System.Drawing.Font("Segoe UI", 10F); | System.Windows.Forms.AnchorStyles.Right)));
this.lblProgress.Font = new System.Drawing.Font("Segoe UI", 9.75F);
this.lblProgress.Location = new System.Drawing.Point(25, 82); this.lblProgress.Location = new System.Drawing.Point(25, 82);
this.lblProgress.Name = "lblProgress"; this.lblProgress.Name = "lblProgress";
this.lblProgress.Size = new System.Drawing.Size(630, 24); this.lblProgress.Size = new System.Drawing.Size(630, 40);
this.lblProgress.TabIndex = 7; this.lblProgress.TabIndex = 7;
this.lblProgress.Text = "Подготовка..."; this.lblProgress.Text = "Подготовка...";
this.lblProgress.UseMnemonic = false;
// //
// rtxtDebug // rtxtDebug
// //
this.rtxtDebug.BackColor = System.Drawing.SystemColors.Control; this.rtxtDebug.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.rtxtDebug.BorderStyle = System.Windows.Forms.BorderStyle.None; | System.Windows.Forms.AnchorStyles.Left)
this.rtxtDebug.Location = new System.Drawing.Point(25, 116); | System.Windows.Forms.AnchorStyles.Right)));
this.rtxtDebug.BackColor = System.Drawing.SystemColors.Window;
this.rtxtDebug.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.rtxtDebug.DetectUrls = false;
this.rtxtDebug.Font = new System.Drawing.Font("Consolas", 9F);
this.rtxtDebug.HideSelection = false;
this.rtxtDebug.Location = new System.Drawing.Point(25, 128);
this.rtxtDebug.Name = "rtxtDebug"; this.rtxtDebug.Name = "rtxtDebug";
this.rtxtDebug.Size = new System.Drawing.Size(630, 215); this.rtxtDebug.ReadOnly = true;
this.rtxtDebug.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.rtxtDebug.Size = new System.Drawing.Size(630, 243);
this.rtxtDebug.TabIndex = 0; this.rtxtDebug.TabIndex = 0;
this.rtxtDebug.Text = ""; this.rtxtDebug.Text = "";
this.rtxtDebug.WordWrap = true;
// //
// dataGridView1 // dataGridView1
// //
@ -95,8 +108,9 @@
// //
// btnCloseThis // btnCloseThis
// //
this.btnCloseThis.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCloseThis.Font = new System.Drawing.Font("Segoe UI", 11.25F); this.btnCloseThis.Font = new System.Drawing.Font("Segoe UI", 11.25F);
this.btnCloseThis.Location = new System.Drawing.Point(555, 337); this.btnCloseThis.Location = new System.Drawing.Point(555, 381);
this.btnCloseThis.Margin = new System.Windows.Forms.Padding(4); this.btnCloseThis.Margin = new System.Windows.Forms.Padding(4);
this.btnCloseThis.Name = "btnCloseThis"; this.btnCloseThis.Name = "btnCloseThis";
this.btnCloseThis.Size = new System.Drawing.Size(100, 41); this.btnCloseThis.Size = new System.Drawing.Size(100, 41);
@ -110,15 +124,16 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Control; this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(684, 396); this.ClientSize = new System.Drawing.Size(684, 440);
this.Controls.Add(this.lblProgress); this.Controls.Add(this.lblProgress);
this.Controls.Add(this.progressDownload); this.Controls.Add(this.progressDownload);
this.Controls.Add(this.lblTitle); this.Controls.Add(this.lblTitle);
this.Controls.Add(this.btnCloseThis); this.Controls.Add(this.btnCloseThis);
this.Controls.Add(this.dataGridView1); this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.rtxtDebug); this.Controls.Add(this.rtxtDebug);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.MaximizeBox = false; this.MaximizeBox = true;
this.MinimumSize = new System.Drawing.Size(640, 420);
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "HF_DownloadDataFromServer"; this.Name = "HF_DownloadDataFromServer";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;

View File

@ -2,7 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.SQLite; using System.Data.SQLite;
using System.Drawing;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Электроннаяармация.Classes; using Электроннаяармация.Classes;
@ -30,6 +32,7 @@ namespace Электронная_Фармация.HelpForms
private async void HF_DownloadDataFromServer_Load(object sender, EventArgs e) private async void HF_DownloadDataFromServer_Load(object sender, EventArgs e)
{ {
UiThemeHelper.ApplyToControlTree(this); UiThemeHelper.ApplyToControlTree(this);
ConfigureLogView();
btnCloseThis.Enabled = false; btnCloseThis.Enabled = false;
dataGridView1.Visible = false; dataGridView1.Visible = false;
rtxtDebug.Visible = true; rtxtDebug.Visible = true;
@ -51,6 +54,12 @@ namespace Электронная_Фармация.HelpForms
AppendStatus("Загружаю сводный прайс..."); AppendStatus("Загружаю сводный прайс...");
var allSuppliersSummary = await GetFullPriceSummaryPagedAsync(client); var allSuppliersSummary = await GetFullPriceSummaryPagedAsync(client);
int totalItems = allSuppliersSummary.Summary?.Count ?? 0; int totalItems = allSuppliersSummary.Summary?.Count ?? 0;
ApplyClientMarkupSettings(allSuppliersSummary);
if (allSuppliersSummary.MarkupPercent.HasValue)
{
AppendStatus($"Наценка клиента: {allSuppliersSummary.MarkupPercent.Value:0.##}%");
}
AppendStatus($"Получено {totalItems} позиций"); AppendStatus($"Получено {totalItems} позиций");
SetOverallProgress(DownloadPhaseEnd, $"Получено {totalItems} / {totalItems} позиций (100%)"); SetOverallProgress(DownloadPhaseEnd, $"Получено {totalItems} / {totalItems} позиций (100%)");
@ -182,6 +191,11 @@ namespace Электронная_Фармация.HelpForms
} }
int got = chunk?.Summary?.Count ?? 0; int got = chunk?.Summary?.Count ?? 0;
if (page == 0 && chunk?.MarkupPercent.HasValue == true)
{
combined.MarkupPercent = chunk.MarkupPercent;
}
if (got > 0) if (got > 0)
{ {
combined.Summary.AddRange(chunk.Summary); combined.Summary.AddRange(chunk.Summary);
@ -197,6 +211,19 @@ namespace Электронная_Фармация.HelpForms
return combined; return combined;
} }
private static void ApplyClientMarkupSettings(PriceSummaryResponse response)
{
if (response?.MarkupPercent == null)
{
return;
}
var markup = response.MarkupPercent.Value;
Settings.Default.ClientMarkupPercent = markup;
Settings.Default.IntDefaultPercentMarkup = (int)Math.Round(markup, MidpointRounding.AwayFromZero);
Settings.Default.Save();
}
private void ReportTransferProgress(HttpTransferProgress transfer) private void ReportTransferProgress(HttpTransferProgress transfer)
{ {
if (transfer.TotalBytes.HasValue && transfer.TotalBytes.Value > 0) if (transfer.TotalBytes.HasValue && transfer.TotalBytes.Value > 0)
@ -253,12 +280,19 @@ namespace Электронная_Фармация.HelpForms
DataType = typeof(string), DataType = typeof(string),
AllowDBNull = true AllowDBNull = true
}); });
tablePrice.Columns.Add(new DataColumn
{
ColumnName = "MarkupPercent",
DataType = typeof(decimal),
AllowDBNull = true
});
if (allSuppliersSummary?.Summary == null) if (allSuppliersSummary?.Summary == null)
{ {
return tablePrice; return tablePrice;
} }
var clientMarkup = allSuppliersSummary.MarkupPercent;
int total = allSuppliersSummary.Summary.Count; int total = allSuppliersSummary.Summary.Count;
int current = 0; int current = 0;
foreach (var item in allSuppliersSummary.Summary) foreach (var item in allSuppliersSummary.Summary)
@ -278,6 +312,8 @@ namespace Электронная_Фармация.HelpForms
row["SummaZakaza"] = string.Empty; row["SummaZakaza"] = string.Empty;
row["TradeName"] = string.IsNullOrWhiteSpace(item.TradeName) ? (object)DBNull.Value : item.TradeName.Trim(); 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["Dosage"] = string.IsNullOrWhiteSpace(item.Dosage) ? (object)DBNull.Value : item.Dosage.Trim();
var markupPercent = MarkupHelper.ResolveMarkupPercent(item.MarkupPercent, clientMarkup, Settings.Default.ClientMarkupPercent);
row["MarkupPercent"] = markupPercent;
tablePrice.Rows.Add(row); tablePrice.Rows.Add(row);
current++; current++;
@ -308,7 +344,8 @@ namespace Электронная_Фармация.HelpForms
[SummaZakaza], [SummaZakaza],
[supplier_price_id], [supplier_price_id],
[TradeName], [TradeName],
[Dosage] [Dosage],
[MarkupPercent]
) )
VALUES VALUES
( (
@ -325,7 +362,8 @@ VALUES
@SummaZakaza, @SummaZakaza,
@supplier_price_id, @supplier_price_id,
@TradeName, @TradeName,
@Dosage @Dosage,
@MarkupPercent
)"; )";
int total = tablePrice.Rows.Count; int total = tablePrice.Rows.Count;
@ -361,6 +399,7 @@ VALUES
cmd.Parameters.AddWithValue("@supplier_price_id", row["supplier_price_id"]); cmd.Parameters.AddWithValue("@supplier_price_id", row["supplier_price_id"]);
cmd.Parameters.AddWithValue("@TradeName", row.Table.Columns.Contains("TradeName") ? row["TradeName"] : DBNull.Value); cmd.Parameters.AddWithValue("@TradeName", row.Table.Columns.Contains("TradeName") ? row["TradeName"] : DBNull.Value);
cmd.Parameters.AddWithValue("@Dosage", row.Table.Columns.Contains("Dosage") ? row["Dosage"] : DBNull.Value); cmd.Parameters.AddWithValue("@Dosage", row.Table.Columns.Contains("Dosage") ? row["Dosage"] : DBNull.Value);
cmd.Parameters.AddWithValue("@MarkupPercent", row.Table.Columns.Contains("MarkupPercent") ? row["MarkupPercent"] : DBNull.Value);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@ -433,11 +472,74 @@ VALUES
progressDownload.Minimum = 0; progressDownload.Minimum = 0;
progressDownload.Maximum = 100; progressDownload.Maximum = 100;
progressDownload.Value = Math.Max(0, Math.Min(100, percent)); progressDownload.Value = Math.Max(0, Math.Min(100, percent));
lblProgress.Text = $"{Math.Max(0, Math.Min(100, percent))}% — {text}"; lblProgress.Text = FormatProgressText(percent, text);
lblProgress.Refresh(); lblProgress.Refresh();
progressDownload.Refresh(); progressDownload.Refresh();
} }
private void ConfigureLogView()
{
rtxtDebug.ReadOnly = true;
rtxtDebug.WordWrap = true;
rtxtDebug.ScrollBars = RichTextBoxScrollBars.Vertical;
rtxtDebug.HideSelection = false;
rtxtDebug.DetectUrls = false;
rtxtDebug.BorderStyle = BorderStyle.FixedSingle;
if (rtxtDebug.Font.Name != "Consolas")
{
rtxtDebug.Font = new Font("Consolas", 9f);
}
lblProgress.AutoEllipsis = false;
lblProgress.UseMnemonic = false;
}
private static string FormatProgressText(int percent, string text)
{
return WrapLongText($"{Math.Max(0, Math.Min(100, percent))}% — {text}", 78, 2);
}
private static string WrapLongText(string text, int maxLineLength, int maxLines)
{
if (string.IsNullOrEmpty(text) || text.Length <= maxLineLength)
{
return text ?? string.Empty;
}
var lines = new List<string>();
var remaining = text.Trim();
while (!string.IsNullOrEmpty(remaining) && lines.Count < maxLines)
{
if (remaining.Length <= maxLineLength)
{
lines.Add(remaining);
break;
}
var breakIndex = remaining.LastIndexOf(' ', Math.Min(maxLineLength, remaining.Length - 1));
if (breakIndex <= 0)
{
breakIndex = maxLineLength;
}
lines.Add(remaining.Substring(0, breakIndex).TrimEnd());
remaining = remaining.Substring(breakIndex).TrimStart();
}
if (!string.IsNullOrEmpty(remaining) && lines.Count >= maxLines)
{
var lastLine = lines[lines.Count - 1];
if (lastLine.Length > maxLineLength - 3)
{
lastLine = lastLine.Substring(0, Math.Max(0, maxLineLength - 3)).TrimEnd();
}
lines[lines.Count - 1] = lastLine + "...";
}
return string.Join(Environment.NewLine, lines);
}
private void AppendStatus(string message) private void AppendStatus(string message)
{ {
if (InvokeRequired) if (InvokeRequired)
@ -446,8 +548,10 @@ VALUES
return; return;
} }
rtxtDebug.AppendText(message + Environment.NewLine); var wrapped = WrapLongText(message ?? string.Empty, 96, int.MaxValue);
rtxtDebug.AppendText(wrapped + Environment.NewLine);
rtxtDebug.SelectionStart = rtxtDebug.TextLength; rtxtDebug.SelectionStart = rtxtDebug.TextLength;
rtxtDebug.SelectionLength = 0;
rtxtDebug.ScrollToCaret(); rtxtDebug.ScrollToCaret();
rtxtDebug.Refresh(); rtxtDebug.Refresh();
AppDebugLog.Info("Download", message); AppDebugLog.Info("Download", message);

View File

@ -35,6 +35,18 @@ namespace Электронная_Фармация.Properties {
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public decimal ClientMarkupPercent {
get {
return ((decimal)(this["ClientMarkupPercent"]));
}
set {
this["ClientMarkupPercent"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("")]

View File

@ -5,6 +5,9 @@
<Setting Name="IntDefaultPercentMarkup" Type="System.Int32" Scope="User"> <Setting Name="IntDefaultPercentMarkup" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value> <Value Profile="(Default)">0</Value>
</Setting> </Setting>
<Setting Name="ClientMarkupPercent" Type="System.Decimal" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="stringLogin" Type="System.String" Scope="User"> <Setting Name="stringLogin" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>

View File

@ -399,6 +399,11 @@ namespace Электронная_Фармация.UserControls
tablePrice.Columns["Dosage"].ColumnName = "Дозировка"; tablePrice.Columns["Dosage"].ColumnName = "Дозировка";
} }
if (tablePrice.Columns.Contains("MarkupPercent"))
{
tablePrice.Columns["MarkupPercent"].ColumnName = "Наценка %";
}
EnsureDerivedBrowseColumns(tablePrice); EnsureDerivedBrowseColumns(tablePrice);
_fullPriceTable = tablePrice; _fullPriceTable = tablePrice;
_selectedBaseName = string.Empty; _selectedBaseName = string.Empty;
@ -797,6 +802,7 @@ namespace Электронная_Фармация.UserControls
HideOptionalColumn("Торговое название"); HideOptionalColumn("Торговое название");
HideOptionalColumn("Дозировка"); HideOptionalColumn("Дозировка");
HideOptionalColumn("Наценка %");
HideOptionalColumn("Базовое наименование"); HideOptionalColumn("Базовое наименование");
HideOptionalColumn("МГ"); HideOptionalColumn("МГ");
@ -927,16 +933,37 @@ namespace Электронная_Фармация.UserControls
void loadInfoAboutDefaultMarkup() void loadInfoAboutDefaultMarkup()
{ {
var percentageMarkupDefault = Properties.Settings.Default.IntDefaultPercentMarkup; decimal percentageMarkupDefault = Properties.Settings.Default.ClientMarkupPercent;
if (percentageMarkupDefault <= 0) if (percentageMarkupDefault <= 0)
{ {
percentageMarkupDefault = 30; percentageMarkupDefault = Properties.Settings.Default.IntDefaultPercentMarkup;
}
if (percentageMarkupDefault <= 0)
{
percentageMarkupDefault = MarkupHelper.FallbackMarkupPercent;
} }
_percentageAsDefault = percentageMarkupDefault; _percentageAsDefault = percentageMarkupDefault;
numericPercent.DecimalPlaces = 2;
numericPercent.Increment = 0.1m;
numericPercent.Value = Math.Max(numericPercent.Minimum, Math.Min(numericPercent.Maximum, percentageMarkupDefault)); numericPercent.Value = Math.Max(numericPercent.Minimum, Math.Min(numericPercent.Maximum, percentageMarkupDefault));
} }
private decimal GetMarkupPercentForRow(DataGridViewRow row)
{
if (row?.DataGridView?.Columns.Contains("Наценка %") == true)
{
var cellValue = row.Cells["Наценка %"]?.Value;
if (MarkupHelper.TryParseMarkup(cellValue, out var itemMarkup) && itemMarkup >= 0)
{
return itemMarkup;
}
}
return _percentageAsDefault;
}
public void loadSupplierTabs(string SupplierName) public void loadSupplierTabs(string SupplierName)
{ {
string tabName; string tabName;
@ -1911,9 +1938,10 @@ and SumOrderedItems = '{SumOrder}'";
return; return;
} }
var markupPercentage = (double)numericPercent.Value; var markupPercentage = GetMarkupPercentForRow(currentRow);
var priceWithPercentage = priceForGood + (priceForGood / 100 * markupPercentage); numericPercent.Value = Math.Max(numericPercent.Minimum, Math.Min(numericPercent.Maximum, markupPercentage));
lblPriceForGood.Text = $"= {priceWithPercentage} руб"; var priceWithPercentage = MarkupHelper.ApplyMarkup((decimal)priceForGood, markupPercentage);
lblPriceForGood.Text = $"= {priceWithPercentage:0.##} руб";
} }
catch catch
{ {
@ -2313,12 +2341,13 @@ and SumOrderedItems = '{SumOrder}'";
private void checkUsePercentageAsDefault_CheckedChanged(object sender, EventArgs e) private void checkUsePercentageAsDefault_CheckedChanged(object sender, EventArgs e)
{ {
int newDefaultPercent;
if (_percentageAsDefault != numericPercent.Value && checkUsePercentageAsDefault.Checked == true) if (_percentageAsDefault != numericPercent.Value && checkUsePercentageAsDefault.Checked == true)
{ {
newDefaultPercent = Convert.ToInt32(numericPercent.Value); var newDefaultPercent = numericPercent.Value;
Properties.Settings.Default.IntDefaultPercentMarkup = Convert.ToInt32(newDefaultPercent); Properties.Settings.Default.ClientMarkupPercent = newDefaultPercent;
Properties.Settings.Default.IntDefaultPercentMarkup = Convert.ToInt32(Math.Round(newDefaultPercent, MidpointRounding.AwayFromZero));
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
_percentageAsDefault = newDefaultPercent;
} }
} }