using GB5Shared.DTO.Framework.Login;
using System.Data.Common;
namespace MMBLL.StockLedgerCost;
public interface IStockLedgerCostBLL
{
///
/// Called synchronously within the transaction that posts the stock ledger rows.
/// Applies AverageCost to TSTOCKLEDGER and updates TSTOCKPOSITION.AverageValue/AverageCost.
/// If the transaction date is before today and the item uses perpetual valuation,
/// publishes a Dapr event to trigger background recosting.
///
Task UpdateCostAsync(
int objectTypeId, int objectId,
bool isTransfer, int fromStoreId, int toStoreId,
bool isStorewise,
DateOnly transactionDate,
LoginDTO login, DbTransaction tx, CancellationToken ct);
///
/// Convenience overload called from document-save BLL (MMHeadBLL).
/// Reads the OU-level storewise flag from MOULEVELSETTING automatically.
/// Runs in its own implicit transaction (no open TX required from caller).
/// Best-effort: exceptions are swallowed and logged; they do not fail the document save.
///
Task UpdateCostForDocumentAsync(
int objectTypeId, int objectId,
bool isTransfer, int fromStoreId, int toStoreId,
DateOnly transactionDate,
LoginDTO login, CancellationToken ct);
///
/// Reprocesses TSTOCKLEDGER PostedCost/PostedValue for a period range.
/// Called by the Dapr subscriber for backdated entries and by the batch valuation job.
/// Uses temp table batch — all steps run on one connection.
///
Task RunPerpetualRerunAsync(
int ouid, DateOnly fromDate, DateOnly toDate, int documentId,
bool isStorewise,
LoginDTO login, CancellationToken ct);
}