Set EkaerHistory summary fields and update dev DB config

Updated the connection string to use the FruitBank_DEV database.
Ensured EkaerHistory summary fields (ShippingDate, Partner/Customer)
are consistently set via fruitBankEkaerService.SetSummary when
creating or updating records, improving data consistency for both
inbound and outbound cases.
This commit is contained in:
Loretta 2026-06-17 13:54:52 +02:00
parent c71bf2fcd8
commit fdde2b3c6b
1 changed files with 19 additions and 7 deletions

View File

@ -344,6 +344,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
var documents = await ctx.ShippingDocuments.GetAll(true).Where(sd => foreignKeys.Contains(sd.Id)).ToListAsync(); var documents = await ctx.ShippingDocuments.GetAll(true).Where(sd => foreignKeys.Contains(sd.Id)).ToListAsync();
if (documents.Count == 0) throw new InvalidOperationException($"EkaerHistory #{ekaerHistoryId}: no ShippingDocuments found for the mapped ids."); if (documents.Count == 0) throw new InvalidOperationException($"EkaerHistory #{ekaerHistoryId}: no ShippingDocuments found for the mapped ids.");
ekaerHistory = fruitBankEkaerService.GenerateEkaerXmlDocument(documents, ekaerHistory); ekaerHistory = fruitBankEkaerService.GenerateEkaerXmlDocument(documents, ekaerHistory);
// Összegző (ShippingDate + Partner) frissítése — a csoporton belül invariáns, így bármelyik dok jó.
fruitBankEkaerService.SetSummary(ekaerHistory, documents[0].ShippingDate, documents[0].Partner?.Name);
} }
else else
{ {
@ -351,6 +354,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
var order = await ctx.OrderDtos.GetByIdAsync(foreignKeys[0], true) var order = await ctx.OrderDtos.GetByIdAsync(foreignKeys[0], true)
?? throw new ArgumentException($"Order not found; id: {foreignKeys[0]}"); ?? throw new ArgumentException($"Order not found; id: {foreignKeys[0]}");
ekaerHistory = fruitBankEkaerService.GenerateEkaerXmlDocument(order, ekaerHistory); ekaerHistory = fruitBankEkaerService.GenerateEkaerXmlDocument(order, ekaerHistory);
fruitBankEkaerService.SetSummary(ekaerHistory, order.DateOfReceipt, order.Customer?.Company);
} }
await ctx.EkaerHistories.UpdateAsync(ekaerHistory); await ctx.EkaerHistories.UpdateAsync(ekaerHistory);
@ -376,18 +381,21 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
if (existing != null) return existing; if (existing != null) return existing;
// A forrás-entitás léte irányfüggő: bejövő → ShippingDocument, kimenő → Order. // A forrás-entitás létét ellenőrizzük és betöltjük (relations) az összegző mezőkhöz (ShippingDate + Partner).
var ekaerHistory = new EkaerHistory { IsOutgoing = isOutgoing, Status = EkaerStatus.Pending };
if (!isOutgoing) if (!isOutgoing)
{ {
_ = await ctx.ShippingDocuments.GetByIdAsync(foreignKey, false) ?? throw new ArgumentException($"ShippingDocument not found; id: {foreignKey}", nameof(foreignKey)); var doc = await ctx.ShippingDocuments.GetByIdAsync(foreignKey, true) ?? throw new ArgumentException($"ShippingDocument not found; id: {foreignKey}", nameof(foreignKey));
fruitBankEkaerService.SetSummary(ekaerHistory, doc.ShippingDate, doc.Partner?.Name);
} }
else else
{ {
_ = await ctx.OrderDtos.GetByIdAsync(foreignKey, false) ?? throw new ArgumentException($"Order not found; id: {foreignKey}", nameof(foreignKey)); var order = await ctx.OrderDtos.GetByIdAsync(foreignKey, true) ?? throw new ArgumentException($"Order not found; id: {foreignKey}", nameof(foreignKey));
fruitBankEkaerService.SetSummary(ekaerHistory, order.DateOfReceipt, order.Customer?.Company);
} }
// EGY EkaerHistory + EGY mapping sor (egyelemű csoport), atomikusan. // EGY EkaerHistory + EGY mapping sor (egyelemű csoport), atomikusan.
var ekaerHistory = await ctx.AddEkaerHistoryWithMappingsAsync(new EkaerHistory { IsOutgoing = isOutgoing, Status = EkaerStatus.Pending }, [foreignKey]); ekaerHistory = await ctx.AddEkaerHistoryWithMappingsAsync(ekaerHistory, [foreignKey]);
// A friss sort adjuk vissza, a betöltött Mappings-szel; a sor biztosan létezik (épp beszúrtuk). // A friss sort adjuk vissza, a betöltött Mappings-szel; a sor biztosan létezik (épp beszúrtuk).
return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id, true); return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id, true);
@ -426,8 +434,10 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
if (result.Obligation == EkaerObligation.DataError) { messages.UnionWith(result.Errors); continue; } if (result.Obligation == EkaerObligation.DataError) { messages.UnionWith(result.Errors); continue; }
if (result.Obligation == EkaerObligation.NotRequired) continue; if (result.Obligation == EkaerObligation.NotRequired) continue;
// Kötelező → EGY EkaerHistory a csoportra + a csoport dokumentumai mapping-foreignKey-ként. // Kötelező → EGY EkaerHistory a csoportra (összegző: ShippingDate + Partner — invariáns) + a dokumentumok mapping-foreignKey-ként.
toCreate.Add((new EkaerHistory { IsOutgoing = false, StatusId = (int)EkaerStatus.Pending }, docs.Select(d => d.Id).ToList())); var history = new EkaerHistory { IsOutgoing = false, StatusId = (int)EkaerStatus.Pending };
fruitBankEkaerService.SetSummary(history, docs[0].ShippingDate, docs[0].Partner?.Name);
toCreate.Add((history, docs.Select(d => d.Id).ToList()));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -454,7 +464,9 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
if (result.Obligation == EkaerObligation.DataError) { messages.UnionWith(result.Errors); continue; } if (result.Obligation == EkaerObligation.DataError) { messages.UnionWith(result.Errors); continue; }
if (result.Obligation == EkaerObligation.NotRequired) continue; if (result.Obligation == EkaerObligation.NotRequired) continue;
toCreate.Add((new EkaerHistory { IsOutgoing = true, StatusId = (int)EkaerStatus.Pending }, [order.Id])); var history = new EkaerHistory { IsOutgoing = true, StatusId = (int)EkaerStatus.Pending };
fruitBankEkaerService.SetSummary(history, order.DateOfReceipt, order.Customer?.Company);
toCreate.Add((history, [order.Id]));
} }
catch (Exception ex) catch (Exception ex)
{ {