Unificar la transferencia automatica de la NC en TransferenciaAutomaticaNC.Crear
El mismo bloque (~100 lineas) estaba copiado en Picking DESPACHO, Picking PICKING y Recibo. Ahora los tres llaman al mismo metodo. Sin cambios de comportamiento (la referencia de la NC en la transferencia se asigna una vez antes de las lineas en vez de dentro del ciclo de articulos). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3bce3ed117
commit
3ea0aca535
4 files changed
+126
-299
No files matched your search
@@ -0,0 +1,114 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.StockTransfer;
|
||||
using Net.Data.ServicesLayer.CreditNotes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Net.Data.ServicesLayer.StockTransfer
|
||||
{
|
||||
// Transferencias de stock automaticas de una nota de credito (Picking DESPACHO/PICKING y Recibo Devolucion).
|
||||
// Antes este bloque estaba copiado 3 veces.
|
||||
public static class TransferenciaAutomaticaNC
|
||||
{
|
||||
// Por cada almacen de origen (WarehouseCode) y almacen destino (U_ITC_ALMDES) distintos de las lineas de la NC
|
||||
// crea una transferencia de stock en SAP, con las cantidades y lotes de esas lineas y la NC como referencia.
|
||||
// Luego agrega a la NC una referencia por cada transferencia creada.
|
||||
// OJO: si SAP rechaza una transferencia se ignora (la NC ya esta creada) y no se informa al consumidor.
|
||||
public static void Crear(BE_CreditNotesNotes creditNotesNotes, int docEntryNC, IHttpClientFactory clientFactory, IConfiguration configuration, CreditNotesRepository creditNotesRepository)
|
||||
{
|
||||
List<string> ListaUnicaAlmacen = creditNotesNotes.DocumentLines.Select(x => x.WarehouseCode).Distinct().ToList();
|
||||
List<int> ListDocEntry = new List<int>();
|
||||
ListaUnicaAlmacen.ForEach(Almacen =>
|
||||
{
|
||||
List<string> ListaUnicaAlmDestino = creditNotesNotes.DocumentLines.Where(Linea => Linea.WarehouseCode == Almacen).ToList().Select(x => x.U_ITC_ALMDES).Distinct().ToList().Where(x => !string.IsNullOrEmpty(x)).ToList();
|
||||
ListaUnicaAlmDestino.ForEach(Destino =>
|
||||
{
|
||||
if (Almacen != Destino)
|
||||
{
|
||||
BE_StockTransferAutomatico Transfer = new BE_StockTransferAutomatico();
|
||||
Transfer.FromWarehouse = Almacen;
|
||||
Transfer.ToWarehouse = Destino;
|
||||
Transfer.DocDate = creditNotesNotes.DocDate;
|
||||
Transfer.TaxDate = creditNotesNotes.DocDate;
|
||||
Transfer.U_SYP_MDTS = "TSI";
|
||||
Transfer.U_SYP_MDMT = "24";
|
||||
Transfer.DueDate = creditNotesNotes.DocDueDate;
|
||||
Transfer.PriceList = -2;
|
||||
var ListaDetalle_PorAlmacen = creditNotesNotes.DocumentLines.Where(x => x.WarehouseCode == Almacen && x.U_ITC_ALMDES == Destino).ToList();
|
||||
var ListaUnicaArticulo = ListaDetalle_PorAlmacen.Select(x => x.ItemCode).Distinct().ToList();
|
||||
Transfer.StockTransferLines = new List<BE_StockTransferLine>();
|
||||
|
||||
//=== AGREGA DOCUMENTO REFERENCIA
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>
|
||||
{
|
||||
new BE_StockTransferDocumentReferences()
|
||||
{
|
||||
RefDocEntr = docEntryNC,
|
||||
RefObjType = "rot_SalesCreditNote",
|
||||
IssueDate = DateTime.Now,
|
||||
Remark = "Nota de Credito",
|
||||
}
|
||||
};
|
||||
|
||||
ListaUnicaArticulo.ForEach(x =>
|
||||
{
|
||||
var ListLote = new List<BE_StockTransferLineBatchNumber>();
|
||||
// Lotes de todas las lineas del articulo (si el mismo lote esta en varias lineas se suma)
|
||||
ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).SelectMany(t => t.BatchNumbers).GroupBy(r => r.BatchNumber).ToList().ForEach(g =>
|
||||
{
|
||||
ListLote.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = g.Key,
|
||||
Quantity = g.Sum(r => r.Quantity)
|
||||
});
|
||||
});
|
||||
Transfer.StockTransferLines.Add(new BE_StockTransferLine()
|
||||
{
|
||||
ItemCode = x,
|
||||
ItemDescription = ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).FirstOrDefault().ItemDescription,
|
||||
Quantity = Convert.ToDouble(ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).Sum(t => t.Quantity)),
|
||||
WarehouseCode = Destino,
|
||||
FromWarehouseCode = Almacen,
|
||||
BatchNumbers = ListLote
|
||||
});
|
||||
});
|
||||
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(clientFactory, configuration);
|
||||
var ResultTransfer = stockTransferRepository.StockTransfer(Transfer).Result;
|
||||
if (ResultTransfer.StatusCode != -1)
|
||||
{
|
||||
ListDocEntry.Add((int)ResultTransfer.Data.DocEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Referencia las transferencias creadas en la NC
|
||||
if (ListDocEntry.Count > 0)
|
||||
{
|
||||
var listaReferencia = new List<BE_CreditNotesDocumentReferences>();
|
||||
ListDocEntry.ForEach(x =>
|
||||
{
|
||||
listaReferencia.Add(new BE_CreditNotesDocumentReferences()
|
||||
{
|
||||
RefDocEntr = x,
|
||||
IssueDate = DateTime.Now,
|
||||
RefObjType = "rot_InventoryTransfer",
|
||||
Remark = "Transferencias Automatica"
|
||||
});
|
||||
});
|
||||
|
||||
var credit = new
|
||||
{
|
||||
DocumentReferences = listaReferencia
|
||||
};
|
||||
|
||||
var Actualizacion = creditNotesRepository.UpdateCreateCreditNotes(credit, docEntryNC).Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user