Add method to create missing EKÁER history records
Introduced CreateMissingEkaerHistories in FruitBankDataController to generate Pending EKÁER records for inbound shipping documents and completed outbound orders lacking such records from a specified date. The method is user-invoked, idempotent, logs actions and errors, and supports SignalR notifications.
This commit is contained in:
parent
c8ecbc94a2
commit
75ce276f64
|
|
@ -21,6 +21,7 @@ using Mango.Nop.Core.Loggers;
|
|||
using Mango.Nop.Core.Models;
|
||||
using Nop.Core;
|
||||
using Nop.Core.Domain.Customers;
|
||||
using Nop.Core.Domain.Orders;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Factories;
|
||||
using Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||
|
|
@ -358,6 +359,49 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id) ?? ekaerHistory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A megadott dátumtól kezdődő, EKÁER-rekord nélküli szállítólevelekre Pending rekordot hoz létre.
|
||||
/// User-vezérelt (toolbar gomb) — szándékosan NINCS automata rekord-érzékelés: a létrehozás explicit,
|
||||
/// idempotens, és bármikor újrafuttatható (maga a gomb a "reconciliation").
|
||||
/// </summary>
|
||||
[SignalR(SignalRTags.CreateMissingEkaerHistories)]
|
||||
public async Task<int> CreateMissingEkaerHistories(DateTime fromDate)
|
||||
{
|
||||
_logger.Detail($"CreateMissingEkaerHistories invoked; fromDate: {fromDate:yyyy-MM-dd}");
|
||||
|
||||
// Bejövő: rekord nélküli szállítólevelek a dátumtól.
|
||||
var missingInbound = await ctx.ShippingDocuments.GetAll(false)
|
||||
.Where(sd => sd.ShippingDate >= fromDate)
|
||||
.Where(sd => !ctx.EkaerHistories.Table.Any(eh => eh.ForeignKey == sd.Id && !eh.IsOutgoing))
|
||||
.Select(sd => new EkaerHistory { ForeignKey = sd.Id, IsOutgoing = false, StatusId = (int)EkaerStatus.Pending })
|
||||
.ToListAsync();
|
||||
|
||||
// Kimenő: rekord nélküli, lezárt (Complete) rendelések, DateOfReceipt a dátumtól (jövőbeli is — előre-bejelentés).
|
||||
var missingOutgoing = await ctx.OrderDtos.GetAllByOrderStatus(OrderStatus.Complete, false)
|
||||
.Where(o => o.GenericAttributes.Any(ga => ga.Key == nameof(OrderDto.DateOfReceipt) && DateTime.Parse(ga.Value) >= fromDate.Date))
|
||||
.Where(o => !ctx.EkaerHistories.Table.Any(eh => eh.ForeignKey == o.Id && eh.IsOutgoing))
|
||||
.Select(o => new EkaerHistory { ForeignKey = o.Id, IsOutgoing = true, StatusId = (int)EkaerStatus.Pending })
|
||||
.ToListAsync();
|
||||
|
||||
var createdCount = 0;
|
||||
|
||||
foreach (var ekaerHistory in missingInbound.Concat(missingOutgoing))
|
||||
{
|
||||
try
|
||||
{
|
||||
await ctx.EkaerHistories.InsertAsync(ekaerHistory);
|
||||
createdCount++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"CreateMissingEkaerHistories; insert failed; ForeignKey: {ekaerHistory.ForeignKey}; IsOutgoing: {ekaerHistory.IsOutgoing}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info($"CreateMissingEkaerHistories; created: {createdCount} (inbound: {missingInbound.Count}, outgoing: {missingOutgoing.Count}); fromDate: {fromDate:yyyy-MM-dd}");
|
||||
return createdCount;
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippings)]
|
||||
public async Task<List<Shipping>> GetShippings()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue