������� �� Avalonia 2.0 (�����-���������, ����������, �������� ��������) #1

Merged
Exest merged 18 commits from feature/avalonia-ui into master 2026-08-11 09:41:09 +03:00
5 changed files with 44 additions and 22 deletions
Showing only changes of commit cd2fb57bca - Show all commits

View File

@ -134,6 +134,7 @@ public partial class OrdersViewModel : ViewModelBase
Busy = true;
var req = new BuyerOrderCreateRequest
{
GlobalSign = d.Number.StartsWith("EX-", StringComparison.OrdinalIgnoreCase) ? d.Number : null,
LocationId = d.LocationId,
Comment = d.Comment,
Items = d.Items.Select(i => new BuyerOrderItemReq

View File

@ -88,28 +88,37 @@ public partial class PriceListViewModel : ViewModelBase
private void RemoveFromCart(CartItem? item) => _cart.Remove(item!);
[RelayCommand]
private void SaveDraft()
private async Task SaveDraftAsync()
{
if (_cart.Count == 0) { Status = "Заказ пуст — добавьте позиции."; return; }
var draft = new DraftOrder
try
{
LocationId = SelectedLocation?.BuyerLocationId,
LocationAddress = SelectedLocation?.Address,
Comment = string.IsNullOrWhiteSpace(Comment) ? null : Comment.Trim(),
Items = _cart.Items.Select(c => new DraftItem
Busy = true;
// Резервируем настоящий номер заказа EX-####### (как в WinForms)
var sign = await _api.NextGlobalSignAsync();
var draft = new DraftOrder
{
SupplierPriceId = c.Source.SupplierPriceId ?? "",
Name = c.Name,
Supplier = c.Supplier,
Barcode = c.Source.Barcode,
Price = c.Price,
Qty = c.Qty
}).ToList()
};
var saved = DraftStore.Add(draft);
_cart.Clear();
Comment = "";
Status = $"Заказ сохранён как черновик {saved.Number} → раздел «Заказы» (не отправлен).";
Number = string.IsNullOrWhiteSpace(sign) ? $"ЧРН-{DateTime.Now:HHmmss}" : sign!,
LocationId = SelectedLocation?.BuyerLocationId,
LocationAddress = SelectedLocation?.Address,
Comment = string.IsNullOrWhiteSpace(Comment) ? null : Comment.Trim(),
Items = _cart.Items.Select(c => new DraftItem
{
SupplierPriceId = c.Source.SupplierPriceId ?? "",
Name = c.Name,
Supplier = c.Supplier,
Barcode = c.Source.Barcode,
Price = c.Price,
Qty = c.Qty
}).ToList()
};
DraftStore.Add(draft);
_cart.Clear();
Comment = "";
Status = $"Заказ сохранён: {draft.Number} → раздел «Заказы» (не отправлен).";
}
catch (Exception ex) { Status = "Ошибка сохранения: " + ex.Message; }
finally { Busy = false; }
}
}

View File

@ -129,6 +129,19 @@ public sealed class ApiClient
return JsonSerializer.Deserialize<BuyerOrderResponse>(text, Json) ?? new BuyerOrderResponse();
}
/// <summary>Резервирует следующий номер заказа EX-####### (как в WinForms до создания заказа).</summary>
public async Task<string?> NextGlobalSignAsync()
{
EnsureAuth();
var text = await AuthorizedGetAsync("/api/buyer/global-sign/next", "резервирование номера").ConfigureAwait(false);
try
{
using var doc = JsonDocument.Parse(text);
return doc.RootElement.TryGetProperty("global_sign", out var v) ? v.GetString() : null;
}
catch { return null; }
}
/// <summary>Адреса-грузополучатели покупателя.</summary>
public async Task<List<BuyerLocationDto>> GetBuyerLocationsAsync()
{

View File

@ -29,7 +29,7 @@ public sealed class DraftOrder
/// <summary>Локальные черновики заказов (%APPDATA%\ElfisaAvalonia\drafts.json).</summary>
public static class DraftStore
{
private sealed class Box { public int Seq { get; set; } public List<DraftOrder> Drafts { get; set; } = new(); }
private sealed class Box { public List<DraftOrder> Drafts { get; set; } = new(); }
private static readonly string Dir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ElfisaAvalonia");
@ -62,8 +62,6 @@ public static class DraftStore
public static DraftOrder Add(DraftOrder draft)
{
_box.Seq++;
draft.Number = $"ЧРН-{_box.Seq:0000}";
_box.Drafts.Insert(0, draft);
Save();
return draft;

View File

@ -94,6 +94,7 @@ public sealed class BuyerOrderCreateRequest
{
[JsonPropertyName("location_id")] public string? LocationId { get; set; }
[JsonPropertyName("comment")] public string? Comment { get; set; }
[JsonPropertyName("global_sign")] public string? GlobalSign { get; set; }
[JsonPropertyName("items")] public List<BuyerOrderItemReq> Items { get; set; } = new();
}