Commit inicial: ITCA_API_SAP_WMS (.NET Core 3.1)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
2b82744eb8
168 files changed
+11066
No files matched your search
@@ -0,0 +1,109 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryTransferRequest;
|
||||
using Net.Business.Entities.WMS.SolicitudTransferencia;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.SolicitudTransferencia
|
||||
{
|
||||
// Modulo 100% nuevo (sin equivalente en el .NET original) - porte 1:1 de
|
||||
// itca_api_sap_wms_python/app/services/solicitud_transferencia_service.py.
|
||||
// Actualiza y cierra documentos InventoryTransferRequests (Solicitud de
|
||||
// Traslado) en SAP Business One via Service Layer. Ver
|
||||
// docs/SOLICITUD_TRANSFERENCIA.md para el detalle completo del contrato.
|
||||
public class SolicitudTransferenciaRepository : ISolicitudTransferenciaRepository
|
||||
{
|
||||
private readonly string _aplicacionName;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
|
||||
public SolicitudTransferenciaRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = GetType().Name;
|
||||
_configuration = configuration;
|
||||
_clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
// Devuelve null en exito (el caller arma un BE_ResultadoTransaccion 200 con
|
||||
// body - ver el controller; no responde 204 porque muchos clientes HTTP,
|
||||
// incluido HttpClient de .NET, no leen el body de un 204 - ver
|
||||
// docs/SOLICITUD_TRANSFERENCIA.md).
|
||||
//
|
||||
// El PATCH SOLO actualiza cantidades de linea existentes en SAP - no toca
|
||||
// fechas, almacenes ni ningun otro campo del documento - y ELIMINA una
|
||||
// linea cuando Cantidad = 0. Confirmado contra el Service Layer real de QA:
|
||||
// alcanza con mandar LineNum + Quantity por linea junto con el header
|
||||
// B1S-ReplaceCollectionsOnPatch: true, que le indica a Service Layer que
|
||||
// trate StockTransferLines como reemplazo COMPLETO del array, no un merge
|
||||
// parcial. SAP ademas RECHAZA una linea mandada explicita con Quantity: 0,
|
||||
// por eso se omite del array en vez de mandarla en cero.
|
||||
//
|
||||
// Al ser un reemplazo completo, SAP TAMBIEN exige el Rate real de cada
|
||||
// linea (hallazgo de QA, no cubierto en la primera tanda de pruebas) - por
|
||||
// eso se hace un GET previo para leerlo y reenviarlo, en vez de mandar
|
||||
// Rate: 0 fijo (pisaria la valorizacion real de la linea).
|
||||
public async Task<BE_ResultadoTransaccion<object>> Update(int docEntry, BE_SolicitudTransferenciaPatchRequest entidad)
|
||||
{
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>("Update", _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var connectServiceLayer = new ConnectionServiceLayer(_configuration, _clientFactory);
|
||||
|
||||
var doc = (await connectServiceLayer.GetAsync<BE_InventoryTransferRequest>($"InventoryTransferRequests({docEntry})", 0, true)).FirstOrDefault();
|
||||
var ratesByLine = (doc?.StockTransferLines ?? new List<BE_InventoryTransferRequestLine>())
|
||||
.ToDictionary(l => l.LineNum, l => l.Rate);
|
||||
|
||||
var lines = new List<object>();
|
||||
foreach (var detalle in entidad.Detalle ?? new List<BE_SolicitudTransferenciaPatchDetalle>())
|
||||
{
|
||||
if (detalle.Cantidad == 0) continue;
|
||||
|
||||
if (!ratesByLine.TryGetValue(detalle.Linea, out var rate))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado($"La linea {detalle.Linea} no existe en la Solicitud de Traslado {docEntry}", (object)entidad);
|
||||
}
|
||||
|
||||
lines.Add(new { LineNum = detalle.Linea, Quantity = detalle.Cantidad, Rate = rate });
|
||||
}
|
||||
|
||||
await connectServiceLayer.PatchNoContentAsync(
|
||||
$"InventoryTransferRequests({docEntry})",
|
||||
new { StockTransferLines = lines },
|
||||
new Dictionary<string, string> { ["B1S-ReplaceCollectionsOnPatch"] = "true" });
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), (object)entidad);
|
||||
}
|
||||
}
|
||||
|
||||
// Cierra el documento completo. Funcionalidad nueva (no existe en el .NET
|
||||
// original) - SAP Service Layer cierra documentos via POST a la sub-ruta
|
||||
// /Close, mismo patron que Picking/HojaRuta/Cerrar. Devuelve null en exito
|
||||
// (el caller arma el BE_ResultadoTransaccion 200 con body).
|
||||
public async Task<BE_ResultadoTransaccion<object>> Cerrar(int docEntry)
|
||||
{
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>("Cerrar", _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var connectServiceLayer = new ConnectionServiceLayer(_configuration, _clientFactory);
|
||||
await connectServiceLayer.PostActionAsync($"InventoryTransferRequests({docEntry})/Close");
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), (object)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user