Transferencia desde ALM99: elegir la entrada de la factura de reserva por articulos/cantidades y que no tenga transferencia. Version 2.1.9.0
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31b0929342
commit
baaf85554a
7 files changed
+198
-26
No files matched your search
@@ -4,6 +4,7 @@ using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseDeliveryNotes;
|
||||
using Net.Business.Entities.ServicesLayer.StockTransfer;
|
||||
using Net.Business.Entities.WMS.Transferencia;
|
||||
using Net.Connection;
|
||||
@@ -110,36 +111,80 @@ namespace Net.Data.WMS.Transferencia
|
||||
#endregion
|
||||
});
|
||||
|
||||
//=== SI EL ALMACEN ES ALM99, FUERZA EL AMARRE CON LA ENTRADA DE MERCANCIA
|
||||
//=== SI EL ALMACEN ES ALM99 (almacen de costeo de importaciones), AMARRA CON LA ENTRADA DE MERCANCIA
|
||||
if (entidad.CodigoSubAlmacenOrigen == "ALM99")
|
||||
{
|
||||
StockTransfer.U_SYP_MDMT = "21";
|
||||
int DocEntry_Entada = entidad.DocEntryEM; //HelperInvoice.Get(entidad.NumOrden);
|
||||
if(DocEntry_Entada > 0)
|
||||
PurchaseDeliveryNotesRepository _purchaseDeliveryNotesRepository = new PurchaseDeliveryNotesRepository(_clientFactory, _configuration);
|
||||
|
||||
if (entidad.DocEntryEM > 0)
|
||||
{
|
||||
PurchaseDeliveryNotesRepository _purchaseDeliveryNotesRepository = new PurchaseDeliveryNotesRepository(_clientFactory, _configuration);
|
||||
var _purchaseDeliveryNotesRepository_Response = _purchaseDeliveryNotesRepository.GetPurchaseDeliveryNotes(DocEntry_Entada).Result.ListData.FirstOrDefault();
|
||||
|
||||
//=== RESETEA STOCK POR LOTES
|
||||
StockTransfer.StockTransferLines.ForEach(line =>
|
||||
// WMS indica la entrada: se toman sus lotes y se amarra linea por linea (BaseLine del JSON == BaseLine de la entrada)
|
||||
var pdn = _purchaseDeliveryNotesRepository.GetPurchaseDeliveryNotes(entidad.DocEntryEM).Result.ListData?.FirstOrDefault();
|
||||
if (pdn == null)
|
||||
{
|
||||
var Lines = _purchaseDeliveryNotesRepository_Response.DocumentLines.FirstOrDefault(line_purchaseDeliveryNotesRepository_Response => line_purchaseDeliveryNotesRepository_Response.BaseLine == line.LineNum);
|
||||
line.BatchNumbers = new List<BE_StockTransferLineBatchNumber>();
|
||||
return resultadoTransaccion.GetInformacionResultado($"SAP: La entrada de mercaderia {entidad.DocEntryEM} no se encuentra", entidad);
|
||||
}
|
||||
|
||||
//=== AGREGA LOTES
|
||||
Lines.BatchNumbers.ForEach(lotes =>
|
||||
foreach (var line in StockTransfer.StockTransferLines)
|
||||
{
|
||||
var Lines = pdn.DocumentLines.FirstOrDefault(l => l.BaseLine == line.LineNum);
|
||||
if (Lines == null)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = lotes.BatchNumber,
|
||||
Quantity = lotes.Quantity,
|
||||
});
|
||||
});
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado($"SAP: La linea {line.LineNum} no existe en la entrada de mercaderia {entidad.DocEntryEM}", entidad);
|
||||
}
|
||||
line.BatchNumbers = (Lines.BatchNumbers ?? new List<BE_PurchaseDeliveryNotesBatchNumbers>())
|
||||
.Select(lotes => new BE_StockTransferLineBatchNumber() { BatchNumber = lotes.BatchNumber, Quantity = lotes.Quantity }).ToList();
|
||||
line.BaseLine = Lines.LineNum;
|
||||
line.BaseType = "PurchaseDeliveryNotes";
|
||||
line.BaseEntry = DocEntry_Entada;
|
||||
});
|
||||
line.BaseEntry = entidad.DocEntryEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// WMS envia en NumOrden el DocNum de la Factura de Reserva y en el detalle los articulos/cantidades de UNA de sus
|
||||
// entradas: se busca la entrada con ese mismo juego que aun no tenga transferencia y se transfiere esa.
|
||||
var filas = HelperInvoice.GetEntradasPorFactura(entidad.NumOrden);
|
||||
if (filas.Count > 0)
|
||||
{
|
||||
int docEntryEntrada = EntradaImportacion.Elegir(entidad.NumOrden, filas, entidad.TransferenciaDetalles, out string errorEntrada);
|
||||
if (docEntryEntrada == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(errorEntrada, entidad);
|
||||
}
|
||||
|
||||
var pdn = _purchaseDeliveryNotesRepository.GetPurchaseDeliveryNotes(docEntryEntrada).Result.ListData?.FirstOrDefault();
|
||||
if (pdn == null)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado($"SAP: La entrada de mercaderia {docEntryEntrada} no se puede leer", entidad);
|
||||
}
|
||||
|
||||
// Las lineas de la transferencia salen de la entrada (articulo, cantidad y lotes reales de cada linea)
|
||||
StockTransfer.StockTransferLines = new List<BE_StockTransferLine>();
|
||||
foreach (var l in pdn.DocumentLines)
|
||||
{
|
||||
var lotes = (l.BatchNumbers ?? new List<BE_PurchaseDeliveryNotesBatchNumbers>())
|
||||
.Select(b => new BE_StockTransferLineBatchNumber() { BatchNumber = b.BatchNumber, Quantity = b.Quantity }).ToList();
|
||||
if (lotes.Count > 0 && Math.Abs(lotes.Sum(b => b.Quantity) - l.Quantity) > 0.0001)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado($"SAP: Los lotes de la linea {l.LineNum} ({l.ItemCode}) de la entrada {docEntryEntrada} no cubren la cantidad {l.Quantity}", entidad);
|
||||
}
|
||||
StockTransfer.StockTransferLines.Add(new BE_StockTransferLine
|
||||
{
|
||||
FromWarehouseCode = entidad.CodigoSubAlmacenOrigen,
|
||||
WarehouseCode = entidad.CodigoSubAlmacenDestino,
|
||||
ItemCode = l.ItemCode,
|
||||
Quantity = l.Quantity,
|
||||
LineNum = l.LineNum,
|
||||
BaseType = "PurchaseDeliveryNotes",
|
||||
BaseEntry = docEntryEntrada,
|
||||
BaseLine = l.LineNum,
|
||||
BatchNumbers = lotes
|
||||
});
|
||||
}
|
||||
}
|
||||
// Si la factura no tiene entradas (o NumOrden no es una factura de reserva) se mantiene lo de antes:
|
||||
// transferencia con los lotes del stock de HANA, sin amarre.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user