Avalonia: черновики получают реальный номер EX-####### (как в WinForms)
- при «Сохранить заказ» резервируется настоящий номер через GET /api/buyer/global-sign/next (fallback ЧРН-… если офлайн) - при отправке черновика этот EX-номер передаётся в заказ (global_sign), заказ сохраняет тот же номер - ApiClient.NextGlobalSignAsync, BuyerOrderCreateRequest.GlobalSign - DraftStore: номер задаёт вызывающий Проверено: черновик = EX-0000018, статус «Не отправлен». Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
2420a71ace
commit
cd2fb57bca
@ -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
|
||||
|
||||
@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user