EKÁER grid: status enum fix, batch create, UI/UX, DB guard

- Fixed EkaerHistory status persistence (int+enum wrapper for linq2db)
- Added batch EKÁER record creation (toolbar date picker, SignalR, UI)
- Enhanced GridEkaerHistory: status, error, XML copy, manual edit
- Improved column display format handling in MgGridInfoPanel
- Updated SignalR binary protocol streaming strategy doc
- Added DB guard PowerShell hook: blocks non-_DEV DB shell access
- New styles for EKÁER toolbar date picker
This commit is contained in:
Loretta 2026-06-11 08:52:10 +02:00
parent 76cb8adbe6
commit ea29ad18bd
10 changed files with 232 additions and 10 deletions

View File

@ -0,0 +1,25 @@
# Claude Code PreToolUse hook: DB-vedelem — csak _DEV nevu adatbazis erheto el shell-parancsbol.
# Bemenet: hook JSON a stdin-en; ha a parancs connection stringet tartalmaz (Initial Catalog= / Database=)
# es a DB-nev NEM tartalmazza a "_DEV"-et, a tool-hivast DENY-jal blokkolja.
$payloadText = [Console]::In.ReadToEnd()
if ([string]::IsNullOrWhiteSpace($payloadText)) { exit 0 }
try { $payload = $payloadText | ConvertFrom-Json } catch { exit 0 }
$command = $payload.tool_input.command
if ([string]::IsNullOrWhiteSpace($command)) { exit 0 }
$pattern = [regex]'(?i)(?:Initial\s+Catalog|Database)\s*=\s*([^;"''\s]+)'
foreach ($match in $pattern.Matches($command)) {
$dbName = $match.Groups[1].Value
if ($dbName -notmatch '(?i)_DEV') {
$reason = "Blokkolt: csak _DEV adatbazis modosithato! (talalt adatbazis: $dbName)"
$result = @{ hookSpecificOutput = @{ hookEventName = 'PreToolUse'; permissionDecision = 'deny'; permissionDecisionReason = $reason } }
Write-Output ($result | ConvertTo-Json -Depth 5 -Compress)
exit 0
}
}
exit 0

17
.claude/settings.json Normal file
View File

@ -0,0 +1,17 @@
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|PowerShell",
"hooks": [
{
"type": "command",
"command": "powershell -NoProfile -ExecutionPolicy Bypass -File \"H:/Applications/Mango/Source/FruitBankHybridApp/.claude/hooks/db-dev-guard.ps1\"",
"timeout": 30,
"statusMessage": "DB guard (_DEV) ellenőrzés..."
}
]
}
]
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,11 @@
using AyCode.Core.Serializers.Attributes; using System.Text.Json.Serialization;
using AyCode.Core.Serializers.Attributes;
using AyCode.Core.Serializers.Toons; using AyCode.Core.Serializers.Toons;
using AyCode.Interfaces.TimeStampInfo; using AyCode.Interfaces.TimeStampInfo;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Mango.Nop.Core.Entities; using Mango.Nop.Core.Entities;
namespace FruitBank.Common.Entities; namespace FruitBank.Common.Entities;
[AcBinarySerializable(false, true, false, true, false, false)] [AcBinarySerializable(false, true, false, true, false, false)]
@ -19,8 +21,18 @@ public sealed class EkaerHistory: MgEntityBase, ITimeStampInfo
[ToonDescription(Purpose = "Direction of the goods movement: false = incoming shipment (Shipping), true = outgoing delivery (Order).")] [ToonDescription(Purpose = "Direction of the goods movement: false = incoming shipment (Shipping), true = outgoing delivery (Order).")]
public bool IsOutgoing { get; set; } public bool IsOutgoing { get; set; }
[ToonDescription(Purpose = "Lifecycle state of the declaration: Pending (auto-created, not yet generated), Generated (tradeCard XML produced and valid), ValidationError (generation produced errors, see ErrorText), Sent (accepted by NAV, EkaerNumber filled), SendError (NAV call failed, see ErrorText).")] [ToonDescription(Purpose = "Lifecycle state of the declaration, stored as int (see EkaerStatus): 0 Pending (auto-created, not yet generated), 1 Generated (tradeCard XML produced and valid), 2 ValidationError (generation produced errors, see ErrorText), 3 Sent (accepted by NAV, EkaerNumber filled), 4 SendError (NAV call failed, see ErrorText).")]
public EkaerStatus Status { get; set; } public int StatusId { get; set; }
/// <summary>A <see cref="StatusId"/> enum-nézete. A tárolt érték az int oszlop (StatusId) — a linq2db réteg
/// az enum-property-t nem perzisztálta (az oszlop kimaradt az insertből, a DB default írt 0-t), ezért a nop-minta:
/// int oszlop + nem-mappelt enum wrapper.</summary>
[NotColumn, System.ComponentModel.DataAnnotations.Schema.NotMapped, Newtonsoft.Json.JsonIgnore, JsonIgnore]
public EkaerStatus Status
{
get => (EkaerStatus)StatusId;
set => StatusId = (int)value;
}
[ToonDescription(Purpose = "The generated NAV EKÁER tradeCard request XML exactly as it was (or will be) submitted — audit copy and source of the read-only detail view. Null until the first Generate.")] [ToonDescription(Purpose = "The generated NAV EKÁER tradeCard request XML exactly as it was (or will be) submitted — audit copy and source of the read-only detail view. Null until the first Generate.")]
public string? XmlDoc { get; set; } public string? XmlDoc { get; set; }

View File

@ -36,6 +36,7 @@ public interface IFruitBankDataControllerCommon
public Task<EkaerHistory?> UpdateEkaerHistory(EkaerHistory ekaerHistory); public Task<EkaerHistory?> UpdateEkaerHistory(EkaerHistory ekaerHistory);
public Task<EkaerHistory?> GenerateEkaerXmlDocument(int shippingDocumentId); public Task<EkaerHistory?> GenerateEkaerXmlDocument(int shippingDocumentId);
public Task<EkaerHistory?> CreateEkaerHistory(int foreignKey, bool isOutgoing); public Task<EkaerHistory?> CreateEkaerHistory(int foreignKey, bool isOutgoing);
public Task<int> CreateMissingEkaerHistories(DateTime fromDate);
#endregion EkaerHistory #endregion EkaerHistory
#region CargoPartner #region CargoPartner

View File

@ -125,6 +125,7 @@ public class SignalRTags : AcSignalRTags
public const int UpdateEkaerHistory = 189; public const int UpdateEkaerHistory = 189;
public const int GenerateEkaerXmlDocument = 190; public const int GenerateEkaerXmlDocument = 190;
public const int CreateEkaerHistory = 191; public const int CreateEkaerHistory = 191;
public const int CreateMissingEkaerHistories = 192;
public const int AuthenticateUser = 195; public const int AuthenticateUser = 195;
public const int RefreshToken = 200; public const int RefreshToken = 200;

View File

@ -3,6 +3,7 @@
@using AyCode.Core.Interfaces @using AyCode.Core.Interfaces
@using AyCode.Core.Loggers @using AyCode.Core.Loggers
@using AyCode.Services.Nav.Ekaer.Models @using AyCode.Services.Nav.Ekaer.Models
@using FruitBank.Common.Entities
@using FruitBankHybrid.Shared.Services.Loggers @using FruitBankHybrid.Shared.Services.Loggers
@using FruitBankHybrid.Shared.Services.SignalRs @using FruitBankHybrid.Shared.Services.SignalRs
@ -27,6 +28,12 @@
</div> </div>
} }
@if (!string.IsNullOrWhiteSpace(ErrorText))
{
@* A generálás/küldés hibái egyben olvashatóan — soronként (a validátor NewLine-nal fűzi). *@
<div class="text-danger" style="padding:0 12px 8px 12px; font-size:0.85rem; white-space:pre-line;">@ErrorText</div>
}
<MgGridWithInfoPanel ShowInfoPanel="false"> <MgGridWithInfoPanel ShowInfoPanel="false">
<GridContent> <GridContent>
<GridEkaerDetailBase @ref="Grid" <GridEkaerDetailBase @ref="Grid"
@ -58,6 +65,8 @@
public bool IsMasterGrid => ParentDataItem == null; public bool IsMasterGrid => ParentDataItem == null;
string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty; string GridCss => !IsMasterGrid ? "hide-toolbar" : string.Empty;
private string? ErrorText => (ParentDataItem as EkaerHistory)?.ErrorText;
private AcObservableCollection<TradeCardItemType> TradeCardItems = []; private AcObservableCollection<TradeCardItemType> TradeCardItems = [];
private LoggerClient<GridEkaerDetail> _logger; private LoggerClient<GridEkaerDetail> _logger;

View File

@ -12,6 +12,7 @@
@inject IEnumerable<IAcLogWriterClientBase> LogWriters @inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject FruitBankSignalRClient FruitBankSignalRClient @inject FruitBankSignalRClient FruitBankSignalRClient
@inject IJSRuntime JS
<MgGridWithInfoPanel ShowInfoPanel="@IsMasterGrid"> <MgGridWithInfoPanel ShowInfoPanel="@IsMasterGrid">
<GridContent> <GridContent>
@ -26,11 +27,44 @@
OnGridFocusedRowChanged="Grid_FocusedRowChanged"> OnGridFocusedRowChanged="Grid_FocusedRowChanged">
<Columns> <Columns>
<DxGridDataColumn FieldName="Id" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" ReadOnly="true" /> <DxGridDataColumn FieldName="Id" SortIndex="0" SortOrder="GridColumnSortOrder.Descending" ReadOnly="true" />
<DxGridDataColumn FieldName="@nameof(EkaerHistory.ForeignKey)" /> <DxGridDataColumn FieldName="@nameof(EkaerHistory.ForeignKey)" ReadOnly="true" />
<DxGridDataColumn FieldName="@nameof(EkaerHistory.IsOutgoing)" /> <DxGridDataColumn FieldName="@nameof(EkaerHistory.IsOutgoing)" ReadOnly="true" />
@* A kézi NAV-beadás fázisában a Status / EKÁER szám / SentDate kézzel szerkeszthető. *@
<DxGridDataColumn FieldName="@nameof(EkaerHistory.Status)" />
<DxGridDataColumn FieldName="@nameof(EkaerHistory.EkaerNumber)" Caption="EKÁER szám" />
<DxGridDataColumn FieldName="@nameof(EkaerHistory.SentDate)" DisplayFormat="yyyy.MM.dd HH:mm" />
<DxGridDataColumn FieldName="@nameof(EkaerHistory.ErrorText)" Caption="Hiba" ReadOnly="true">
<CellDisplayTemplate>
@if (!string.IsNullOrWhiteSpace(context.DisplayText))
{
<span title="@context.DisplayText">
<span aria-hidden="true" style="font-size:1.2em; margin-right:3px;">&#9888;&#65039;</span>@context.DisplayText
</span>
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="Created" ReadOnly="true" DisplayFormat="yyyy.MM.dd hh:mm" /> <DxGridDataColumn FieldName="Created" ReadOnly="true" DisplayFormat="yyyy.MM.dd HH:mm" />
<DxGridDataColumn FieldName="Modified" ReadOnly="true" DisplayFormat="yyyy.MM.dd hh:mm" /> <DxGridDataColumn FieldName="Modified" ReadOnly="true" DisplayFormat="yyyy.MM.dd HH:mm" />
<DxGridDataColumn Caption="Műveletek" Width="200" AllowSort="false" AllowGroup="false">
<CellDisplayTemplate>
@{
var row = (EkaerHistory)context.DataItem;
<DxButton Text="Generate"
SizeMode="SizeMode.Small"
RenderStyle="ButtonRenderStyle.Primary"
Enabled="@(CanGenerate(row))"
Attributes="@(new Dictionary<string, object> { ["title"] = row.ErrorText ?? "EKÁER XML generálása és validálása" })"
Click="async () => await OnGenerateClick(row)" />
<DxButton Text="Copy"
SizeMode="SizeMode.Small"
RenderStyle="ButtonRenderStyle.Secondary"
Enabled="@(CanCopy(row))"
Attributes="@(new Dictionary<string, object> { ["title"] = CanCopy(row) ? "A generált XML vágólapra másolása (kézi NAV-beadáshoz)" : "Hibás bejelentés nem másolható — javítsd az adatokat és generáld újra." })"
Click="async () => await OnCopyClick(row)" />
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridCommandColumn Visible="!IsMasterGrid" Width="120"></DxGridCommandColumn> <DxGridCommandColumn Visible="!IsMasterGrid" Width="120"></DxGridCommandColumn>
</Columns> </Columns>
<DetailRowTemplate> <DetailRowTemplate>
@ -56,8 +90,29 @@
<ToolbarTemplate> <ToolbarTemplate>
@if (IsMasterGrid) @if (IsMasterGrid)
{ {
@* EKÁER-rekordot a rendszer hoz létre (auto-rekord) — kézi new/edit/delete tiltva. *@ @* EKÁER-rekord a toolbar "sorok létrehozása" gombbal készül (new/delete tiltva — nincs automata
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)" EnableNew="false" EnableEdit="false" EnableDelete="false" /> érzékelés, a létrehozás explicit és idempotens). Az Edit a kézi NAV-beadás fázisában
engedélyezett: Status / EKÁER szám / SentDate kézi rögzítéséhez. *@
<MgGridToolbarTemplate Grid="Grid" OnReloadDataClick="() => ReloadDataFromDb(true)" EnableNew="false" EnableEdit="true" EnableDelete="false">
<ToolbarItemsExtended>
@* A dátumválasztó editor csak Template-ben mehet toolbarba; a gomb natív DxToolbarItem,
hogy a toolbar stílusát/igazítását kapja (lásd: "Ai process..." minta a GridShippingDocument-ben). *@
<DxToolbarItem BeginGroup="true" CssClass="ekaer-create-from-date-item">
<Template Context="toolbarItemContext">
<DxDateEdit @bind-Date="CreateFromDate"
Format="yyyy.MM.dd"
MinDate="@DateTime.Today.AddDays(-7)"
MaxDate="@DateTime.Today"
CssClass="ekaer-create-from-date" />
</Template>
</DxToolbarItem>
<DxToolbarItem Text="EKÁER sorok létrehozása"
Enabled="@(!_creatingMissing)"
Tooltip="A választott dátumtól kezdődő, rekord nélküli szállítólevelekre/rendelésekre Pending sort hoz létre (idempotens)."
Click="OnCreateMissingClick">
</DxToolbarItem>
</ToolbarItemsExtended>
</MgGridToolbarTemplate>
} }
</ToolbarTemplate> </ToolbarTemplate>
</GridEkaerHistoryBase> </GridEkaerHistoryBase>
@ -110,4 +165,87 @@
FocusedRowVisibleIndex = args.VisibleIndex; FocusedRowVisibleIndex = args.VisibleIndex;
EditItemsEnabled = true; EditItemsEnabled = true;
} }
private readonly HashSet<int> _generatingIds = [];
// Elküldött bejelentést nem generálunk újra némán (az már a NAV-nál van — módosítás külön művelet lesz);
// kimenő (Order) generálás még nincs implementálva.
private bool CanGenerate(EkaerHistory ekaerHistory)
=> ekaerHistory.Status != EkaerStatus.Sent && !ekaerHistory.IsOutgoing && !_generatingIds.Contains(ekaerHistory.Id);
// Hibás (validációs hibás) bejelentés XML-jét nem adjuk a user kezébe — ne kerülhessen kézzel a NAV-hoz.
private static bool CanCopy(EkaerHistory ekaerHistory)
=> !string.IsNullOrWhiteSpace(ekaerHistory.XmlDoc) && string.IsNullOrWhiteSpace(ekaerHistory.ErrorText);
private async Task OnGenerateClick(EkaerHistory ekaerHistory)
{
if (!_generatingIds.Add(ekaerHistory.Id)) return;
try
{
var updated = await FruitBankSignalRClient.GenerateEkaerXmlDocument(ekaerHistory.ForeignKey);
if (updated == null)
{
_logger.Error($"GenerateEkaerXmlDocument null választ adott; ForeignKey: {ekaerHistory.ForeignKey}");
return;
}
// A sor frissítése helyben — a grid ugyanazt a példányt mutatja.
ekaerHistory.Status = updated.Status;
ekaerHistory.XmlDoc = updated.XmlDoc;
ekaerHistory.ErrorText = updated.ErrorText;
ekaerHistory.EkaerNumber = updated.EkaerNumber;
ekaerHistory.SentDate = updated.SentDate;
ekaerHistory.Modified = updated.Modified;
}
catch (Exception ex)
{
_logger.Error($"GenerateEkaerXmlDocument hiba; ForeignKey: {ekaerHistory.ForeignKey}", ex);
}
finally
{
_generatingIds.Remove(ekaerHistory.Id);
Grid?.Reload();
}
}
DateTime CreateFromDate { get; set; } = DateTime.Today.AddDays(-3);
private bool _creatingMissing;
private async Task OnCreateMissingClick()
{
if (_creatingMissing) return;
_creatingMissing = true;
try
{
var createdCount = await FruitBankSignalRClient.CreateMissingEkaerHistories(CreateFromDate);
_logger.Info($"CreateMissingEkaerHistories; created: {createdCount}; fromDate: {CreateFromDate:yyyy.MM.dd}");
if (createdCount > 0) await ReloadDataFromDb(true);
}
catch (Exception ex)
{
_logger.Error($"CreateMissingEkaerHistories hiba; fromDate: {CreateFromDate:yyyy.MM.dd}", ex);
}
finally
{
_creatingMissing = false;
}
}
private async Task OnCopyClick(EkaerHistory ekaerHistory)
{
if (!CanCopy(ekaerHistory)) return;
try
{
await JS.InvokeVoidAsync("navigator.clipboard.writeText", ekaerHistory.XmlDoc);
}
catch (Exception ex)
{
_logger.Error($"XmlDoc vágólapra másolása sikertelen; EkaerHistory.Id: {ekaerHistory.Id}", ex);
}
}
} }

View File

@ -81,6 +81,7 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
public Task<EkaerHistory?> UpdateEkaerHistory(EkaerHistory ekaerHistory) => PostDataAsync(SignalRTags.UpdateEkaerHistory, ekaerHistory); public Task<EkaerHistory?> UpdateEkaerHistory(EkaerHistory ekaerHistory) => PostDataAsync(SignalRTags.UpdateEkaerHistory, ekaerHistory);
public Task<EkaerHistory?> GenerateEkaerXmlDocument(int shippingDocumentId) => GetByIdAsync<EkaerHistory?>(SignalRTags.GenerateEkaerXmlDocument, shippingDocumentId); public Task<EkaerHistory?> GenerateEkaerXmlDocument(int shippingDocumentId) => GetByIdAsync<EkaerHistory?>(SignalRTags.GenerateEkaerXmlDocument, shippingDocumentId);
public Task<EkaerHistory?> CreateEkaerHistory(int foreignKey, bool isOutgoing) => GetByIdAsync<EkaerHistory?>(SignalRTags.CreateEkaerHistory, [foreignKey, isOutgoing]); public Task<EkaerHistory?> CreateEkaerHistory(int foreignKey, bool isOutgoing) => GetByIdAsync<EkaerHistory?>(SignalRTags.CreateEkaerHistory, [foreignKey, isOutgoing]);
public Task<int> CreateMissingEkaerHistories(DateTime fromDate) => GetByIdAsync<int>(SignalRTags.CreateMissingEkaerHistories, fromDate);
#endregion EkaerHistory #endregion EkaerHistory
#region CargoPartner #region CargoPartner

View File

@ -67,6 +67,20 @@ h1:focus {
--icon-ekaer-mask-image: url("images/ekaer-fluent.svg"); --icon-ekaer-mask-image: url("images/ekaer-fluent.svg");
} }
/* EKÁER toolbar dátumválasztó (GridEkaerHistory) — kompakt szélesség, hogy illeszkedjen a toolbar-elemek közé. */
.ekaer-create-from-date {
width: 9rem;
}
/* A Template-es toolbar-elem konténere alapból teljes magasságra nyúlik, és az editor felülre csúszik
középre igazítjuk, hogy egy vonalban legyen a többi (natív) toolbar-gombbal. */
.ekaer-create-from-date-item .dxbl-toolbar-item-content,
.ekaer-create-from-date-item .dxbl-toolbar-item-template {
display: flex;
align-items: center;
height: 100%;
}
.icon { .icon {
width: var(--icon-width); width: var(--icon-width);
height: var(--icon-height); height: var(--icon-height);