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,94 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.Authenticate;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.Authenticate
|
||||
{
|
||||
public class AuthenticateRepository : RepositoryBase<object>, IAuthenticateRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
#endregion
|
||||
|
||||
|
||||
public AuthenticateRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_AuthenticateResponse>> GetToken(BE_AuthenticateRequest value)
|
||||
{
|
||||
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_AuthenticateResponse> resultadoTransaccion = new ResultadoTransaccion<BE_AuthenticateResponse>(_metodoName, _aplicacionName);
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
BE_AuthenticateResponse response = new BE_AuthenticateResponse();
|
||||
response.Type = "Bearer";
|
||||
|
||||
//=== OBTENEMOS LISTADO DE CLIENTES
|
||||
var ls_entity_client = get_client();
|
||||
|
||||
//=== BUSCAMOS EXISTENCIA DEL CLIENTE
|
||||
var result_client = ls_entity_client.FirstOrDefault(x => x.client_id == value.client_id);
|
||||
if (result_client != null)
|
||||
{
|
||||
string semilla = "c071$@p*$b@.m0dul3";
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim("Usuario", result_client.client_secret)
|
||||
};
|
||||
|
||||
//firma - header
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(semilla));
|
||||
var signCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
|
||||
//generador de JWT
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: "ARDICORD",
|
||||
audience: "CUBICO",
|
||||
claims: claims,
|
||||
expires: DateTime.Now.AddHours(10),
|
||||
signingCredentials: signCredentials
|
||||
);
|
||||
|
||||
string tokenGenerado = new JwtSecurityTokenHandler().WriteToken(token);
|
||||
response.Token = tokenGenerado;
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "", response);
|
||||
}
|
||||
else
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, "El usuario no tiene permiso");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public List<ModelCredential> get_client()
|
||||
{
|
||||
return new List<ModelCredential>()
|
||||
{
|
||||
new ModelCredential(){ client_secret = "YzBkZjU0ODY0NjY0NDAxN2FkOTdlMzhjMTIwNGRjMjk", client_id ="0HXoLsLmCIz05OjUwbqISz" },
|
||||
new ModelCredential(){ client_secret = "YzBkZjU0ODY0NjY0NDAxN2FkOTdlMzhjMTIwNGRjMjk", client_id ="0HXoLsLmCIz05OjUwbqISx" },
|
||||
new ModelCredential(){ client_secret = "XmTjrMQPeAOFwA3SoUUTKolohA9HfDVSijY66pOtSsJ", client_id ="rpDDCZBSsJRbQnejvULvn5" },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.Authenticate;
|
||||
using Net.Connection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.Authenticate
|
||||
{
|
||||
public interface IAuthenticateRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_AuthenticateResponse>> GetToken(BE_AuthenticateRequest value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using Net.Data.ServicesLayer;
|
||||
using Net.Data.ServicesLayer.CreditNotes;
|
||||
using Net.Data.Authenticate;
|
||||
using Net.Data.ServicesLayer.ReturnRequest;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using Net.Data.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Data.WMS.Items;
|
||||
using Net.Data.WMS.Recibo;
|
||||
using Net.Data.WMS.Picking;
|
||||
using Net.Data.WMS.SolicitudTransferencia;
|
||||
using Net.Data.WMS.Transferencia;
|
||||
using Net.Data.WMS.Inventario;
|
||||
using Net.Data.ServicesLayer.InventoryGenExits;
|
||||
using Net.Data.ServicesLayer.HR;
|
||||
using Net.Data.ServicesLayer.GlobalData;
|
||||
|
||||
namespace Net.Data
|
||||
{
|
||||
public interface IRepositoryWrapper
|
||||
{
|
||||
#region WMS
|
||||
IReciboRepository Recibo { get; }
|
||||
IInventarioRepository Inventario { get; }
|
||||
ITransferenciaRepository Transferencia { get; }
|
||||
IPickingRepository Picking { get; }
|
||||
ISolicitudTransferenciaRepository SolicitudTransferencia { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAP (SERVICES LAYER)
|
||||
IBusinessPartnersRepository BusinessPartners { get; }
|
||||
ICreditNotesRepository CreditNotes { get; }
|
||||
IPurchaseInvoicesRepository PurchaseInvoices { get; }
|
||||
IInvoiceRepository InvoiceRepository { get; }
|
||||
IPurchaseDeliveryNotesRepository PurchaseDeliveryNotes { get; }
|
||||
IPurchaseOrdersRepository PurchaseOrders { get; }
|
||||
IAuthenticateRepository Authenticate { get; }
|
||||
IItemsRepository Items { get; }
|
||||
IReturnRequestRepository ReturnRequest { get; }
|
||||
IStockTransferRepository StockTransfer { get; }
|
||||
IInventoryGenEntriesRepository InventoryGenEntries { get; }
|
||||
IInventoryGenExitsRepository InventoryGenExits { get; }
|
||||
IHRRepository HR { get; }
|
||||
IGlobalDataRepository GlobalData { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.Authenticate;
|
||||
using Net.Data.ServicesLayer;
|
||||
using Net.Data.ServicesLayer.CreditNotes;
|
||||
using Net.Data.ServicesLayer.GlobalData;
|
||||
using Net.Data.ServicesLayer.HR;
|
||||
using Net.Data.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Data.ServicesLayer.InventoryGenExits;
|
||||
using Net.Data.ServicesLayer.ReturnRequest;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using Net.Data.WMS.Inventario;
|
||||
using Net.Data.WMS.Items;
|
||||
using Net.Data.WMS.Picking;
|
||||
using Net.Data.WMS.Recibo;
|
||||
using Net.Data.WMS.SolicitudTransferencia;
|
||||
using Net.Data.WMS.Transferencia;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Net.Data
|
||||
{
|
||||
public class RepositoryWrapper : IRepositoryWrapper
|
||||
{
|
||||
#region Variables de conexion
|
||||
private string _conSQL;
|
||||
//private string _conSAPSQL;
|
||||
|
||||
private readonly string _entorno;
|
||||
private readonly string _Source;
|
||||
private readonly string _Catalog;
|
||||
private readonly string _User;
|
||||
private readonly string _Password;
|
||||
#endregion
|
||||
|
||||
private IConnectionSQL _repoContext;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
|
||||
#region WMS
|
||||
|
||||
private IReciboRepository _Recibo;
|
||||
private ITransferenciaRepository _Transferencia;
|
||||
private IStockTransferRepository _StockTransfer;
|
||||
private IPickingRepository _Picking;
|
||||
private IInventarioRepository _Inventario;
|
||||
private ISolicitudTransferenciaRepository _SolicitudTransferencia;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SAP (SERVICES LAYER)
|
||||
|
||||
private IBusinessPartnersRepository _BusinessPartners;
|
||||
private IPurchaseInvoicesRepository _PurchaseInvoices;
|
||||
private IInvoiceRepository _Invoice;
|
||||
private ICreditNotesRepository _CreditNotes;
|
||||
private IAuthenticateRepository _AuthenticateRepository;
|
||||
private IPurchaseDeliveryNotesRepository _PurchaseDeliveryNotes;
|
||||
private IPurchaseOrdersRepository _PurchaseOrders;
|
||||
private IItemsRepository _Items;
|
||||
private IReturnRequestRepository _ReturnRequest;
|
||||
private IInventoryGenEntriesRepository _InventoryGenEntries;
|
||||
private IInventoryGenExitsRepository _InventoryGenExits;
|
||||
private IHRRepository _HR;
|
||||
private IGlobalDataRepository _GlobalData;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public RepositoryWrapper(IConnectionSQL repoContext, IConfiguration configuration, IHttpClientFactory clientFactory, IServiceProvider serviceProvider)
|
||||
{
|
||||
_repoContext = repoContext;
|
||||
_configuration = configuration;
|
||||
_clientFactory = clientFactory;
|
||||
|
||||
#region Conexion CORS
|
||||
_conSQL = configuration.GetConnectionString("cnnSql");
|
||||
|
||||
/*Obtenemos que ambiente realizaremos la conexión*/
|
||||
_entorno = configuration["EntornoConection:Entorno"];
|
||||
_Source = EncriptaHelper.DecryptStringAES(configuration[string.Format("{0}:Source", _entorno)]);
|
||||
_Catalog = EncriptaHelper.DecryptStringAES(configuration[string.Format("{0}:Catalog", _entorno)]);
|
||||
_User = EncriptaHelper.DecryptStringAES(configuration[string.Format("{0}:User", _entorno)]);
|
||||
_Password = EncriptaHelper.DecryptStringAES(configuration[string.Format("{0}:Password", _entorno)]);
|
||||
_conSQL = _conSQL.Replace("{Source}", _Source).Replace("{Catalog}", _Catalog).Replace("{User}", _User).Replace("{Password}", _Password);
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region WMS
|
||||
public IReciboRepository Recibo
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Recibo == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Recibo = new ReciboRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _Recibo;
|
||||
}
|
||||
}
|
||||
public ITransferenciaRepository Transferencia
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Transferencia == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Transferencia = new TransferenciaRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _Transferencia;
|
||||
}
|
||||
}
|
||||
public IItemsRepository Items
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Items == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Items = new ItemsRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _Items;
|
||||
}
|
||||
}
|
||||
public IPickingRepository Picking
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Picking == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Picking = new PickingRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _Picking;
|
||||
}
|
||||
}
|
||||
public IInventarioRepository Inventario
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Inventario == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Inventario = new InventarioRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _Inventario;
|
||||
}
|
||||
}
|
||||
public ISolicitudTransferenciaRepository SolicitudTransferencia
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_SolicitudTransferencia == null)
|
||||
{
|
||||
_SolicitudTransferencia = new SolicitudTransferenciaRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _SolicitudTransferencia;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SAP (SERVICES LAYER)
|
||||
public IBusinessPartnersRepository BusinessPartners
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_BusinessPartners == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_BusinessPartners = new BusinessPartnersRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _BusinessPartners;
|
||||
}
|
||||
}
|
||||
public ICreditNotesRepository CreditNotes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_CreditNotes == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_CreditNotes = new CreditNotesRepository(_clientFactory, _configuration, _repoContext);
|
||||
|
||||
}
|
||||
return _CreditNotes;
|
||||
}
|
||||
}
|
||||
public IInvoiceRepository InvoiceRepository
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Invoice == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_Invoice = new InvoiceRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _Invoice;
|
||||
}
|
||||
}
|
||||
public IPurchaseInvoicesRepository PurchaseInvoices
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PurchaseInvoices == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_PurchaseInvoices = new PurchaseInvoicesRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _PurchaseInvoices;
|
||||
}
|
||||
}
|
||||
public IPurchaseDeliveryNotesRepository PurchaseDeliveryNotes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PurchaseDeliveryNotes == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_PurchaseDeliveryNotes = new PurchaseDeliveryNotesRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _PurchaseDeliveryNotes;
|
||||
}
|
||||
}
|
||||
public IPurchaseOrdersRepository PurchaseOrders
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PurchaseOrders == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_PurchaseOrders = new PurchaseOrdersRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _PurchaseOrders;
|
||||
}
|
||||
}
|
||||
public IAuthenticateRepository Authenticate
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_AuthenticateRepository == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_AuthenticateRepository = new AuthenticateRepository(_repoContext, _clientFactory, _configuration);
|
||||
}
|
||||
return _AuthenticateRepository;
|
||||
}
|
||||
}
|
||||
public IReturnRequestRepository ReturnRequest
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_ReturnRequest == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_ReturnRequest = new ReturnRequestRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _ReturnRequest;
|
||||
}
|
||||
}
|
||||
public IStockTransferRepository StockTransfer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_StockTransfer == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_StockTransfer = new StockTransferRepository(_clientFactory, _configuration);
|
||||
}
|
||||
return _StockTransfer;
|
||||
}
|
||||
}
|
||||
public IInventoryGenEntriesRepository InventoryGenEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_InventoryGenEntries == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_InventoryGenEntries = new InventoryGenEntriesRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _InventoryGenEntries;
|
||||
}
|
||||
}
|
||||
public IInventoryGenExitsRepository InventoryGenExits
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_InventoryGenExits == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_InventoryGenExits = new InventoryGenExitsRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _InventoryGenExits;
|
||||
}
|
||||
}
|
||||
|
||||
public IHRRepository HR
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_HR == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_HR = new HRRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _HR;
|
||||
}
|
||||
}
|
||||
|
||||
public IGlobalDataRepository GlobalData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_GlobalData == null)
|
||||
{
|
||||
_repoContext._cnx = _conSQL;
|
||||
_GlobalData = new GlobalDataRepository(_clientFactory, _configuration, _repoContext);
|
||||
}
|
||||
return _GlobalData;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.Correlativo
|
||||
{
|
||||
public class HelperCorrelativo
|
||||
{
|
||||
public static string Get(string Serie)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
string Cuenta = "";
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"SELECT \"U_SYP_NDCD\" FROM \"{LocalData.Schema}\".\"@SYP_NUMDOC\" WHERE \"Code\" = '07' AND \"U_SYP_NDSD\" = ?", con);
|
||||
cmd.Parameters.Add("Serie", HanaDbType.VarChar).Value = Serie ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
Cuenta = (dt.Rows[x]["U_SYP_NDCD"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_SYP_NDCD"]) : string.Empty;
|
||||
}
|
||||
|
||||
return Cuenta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using Sap.Data.Hana;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData
|
||||
{
|
||||
public class HelperDB
|
||||
{
|
||||
public static void SET(string query)
|
||||
{
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand
|
||||
{
|
||||
CommandText = query,
|
||||
Connection = con,
|
||||
CommandType = CommandType.Text
|
||||
};
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
con.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using Net.Business.Entities.ServicesLayer.HR;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.HojaRuta
|
||||
{
|
||||
public class HelperHojaRuta
|
||||
{
|
||||
public static List<HojaRutaDetailsEntities> Get(int DocEntry)
|
||||
{
|
||||
List<HojaRutaDetailsEntities> ListaStock = new List<HojaRutaDetailsEntities>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITC_GetDataDetalleHR\"(?)", con);
|
||||
cmd.Parameters.Add("DocEntry", HanaDbType.VarChar).Value = DocEntry.ToString();
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
ListaStock.Add(new HojaRutaDetailsEntities()
|
||||
{
|
||||
U_ARD_PHR_DIRDESP = (dt.Rows[x]["U_ARD_PHR_DIRDESP"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_DIRDESP"]) : string.Empty,
|
||||
U_ARD_PHR_FEENPED = (dt.Rows[x]["U_ARD_PHR_FEENPED"] != DBNull.Value) ? Convert.ToDateTime(dt.Rows[x]["U_ARD_PHR_FEENPED"]) : DateTime.Now,
|
||||
U_ARD_PHR_FORPAG = (dt.Rows[x]["U_ARD_PHR_FORPAG"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_FORPAG"]) : string.Empty,
|
||||
U_ARD_PHR_MONED = (dt.Rows[x]["U_ARD_PHR_MONED"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_MONED"]) : string.Empty,
|
||||
U_ARD_PHR_NOMCLI = (dt.Rows[x]["U_ARD_PHR_NOMCLI"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_NOMCLI"]) : string.Empty,
|
||||
U_ARD_PHR_NROFACT = (dt.Rows[x]["U_ARD_PHR_NROFACT"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_NROFACT"]) : string.Empty,
|
||||
U_ARD_PHR_NROGRE = (dt.Rows[x]["U_ARD_PHR_NROGRE"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_NROGRE"]) : string.Empty,
|
||||
U_ARD_PHR_NROPED = (dt.Rows[x]["U_ARD_PHR_NROPED"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_NROPED"]) : string.Empty,
|
||||
U_ARD_PHR_RUCCLI = (dt.Rows[x]["U_ARD_PHR_RUCCLI"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_RUCCLI"]) : string.Empty,
|
||||
U_ARD_PHR_TERRIT = (dt.Rows[x]["U_ARD_PHR_TERRIT"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_TERRIT"]) : string.Empty,
|
||||
U_ARD_PHR_TOTALPD = (dt.Rows[x]["U_ARD_PHR_TOTALPD"] != DBNull.Value) ? Convert.ToDecimal(dt.Rows[x]["U_ARD_PHR_TOTALPD"]) : 0,
|
||||
U_ARD_PHR_ZONA = (dt.Rows[x]["U_ARD_PHR_ZONA"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ARD_PHR_ZONA"]) : string.Empty,
|
||||
U_ARD_TOTALFC = (dt.Rows[x]["U_ARD_TOTALFC"] != DBNull.Value) ? Convert.ToDecimal(dt.Rows[x]["U_ARD_TOTALFC"]) : 0,
|
||||
U_ITC_PHR_NOMVEN = (dt.Rows[x]["U_ITC_PHR_NOMVEN"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITC_PHR_NOMVEN"]) : string.Empty,
|
||||
U_MSV_PKH_CGUI = (dt.Rows[x]["U_MSV_PKH_CGUI"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_MSV_PKH_CGUI"]) : string.Empty,
|
||||
U_MSV_PKH_DCPE = (dt.Rows[x]["U_MSV_PKH_DCPE"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_MSV_PKH_DCPE"]) : string.Empty,
|
||||
U_MSV_PKH_DGRE = (dt.Rows[x]["U_MSV_PKH_DGRE"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_MSV_PKH_DGRE"]) : string.Empty,
|
||||
U_MSV_PKH_DORV = (dt.Rows[x]["U_MSV_PKH_DORV"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_MSV_PKH_DORV"]) : string.Empty,
|
||||
U_MSV_PKH_PEOV = (dt.Rows[x]["U_MSV_PKH_PEOV"] != DBNull.Value) ? Convert.ToInt32(dt.Rows[x]["U_MSV_PKH_PEOV"]) : 0,
|
||||
U_MSV_PKH_APLG = (dt.Rows[x]["U_MSV_PKH_APLG"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_MSV_PKH_APLG"]) : string.Empty,
|
||||
});
|
||||
}
|
||||
|
||||
return ListaStock;
|
||||
}
|
||||
|
||||
|
||||
public static List<BE_ItemStock> GetConsolidado(string ItemCode, string FromWarehouseCode)
|
||||
{
|
||||
List<BE_ItemStock> ListaStock = new List<BE_ItemStock>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetStockConsolidado\"(?, ?)", con);
|
||||
cmd.Parameters.Add("ItemCode", HanaDbType.VarChar).Value = ItemCode ?? "";
|
||||
cmd.Parameters.Add("FromWarehouseCode", HanaDbType.VarChar).Value = FromWarehouseCode ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
ListaStock.Add(new BE_ItemStock()
|
||||
{
|
||||
BinCode = (dt.Rows[x]["BinCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["BinCode"]) : string.Empty,
|
||||
DistNumber = (dt.Rows[x]["DistNumber"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["DistNumber"]) : string.Empty,
|
||||
ExpDate = (dt.Rows[x]["ExpDate"] != DBNull.Value) ? Convert.ToDateTime(dt.Rows[x]["ExpDate"]) : DateTime.Now,
|
||||
ItemCode = (dt.Rows[x]["ItemCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemCode"]) : string.Empty,
|
||||
ItemName = (dt.Rows[x]["ItemName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemName"]) : string.Empty,
|
||||
OnHandQty = (dt.Rows[x]["OnHandQty"] != DBNull.Value) ? Convert.ToDouble(dt.Rows[x]["OnHandQty"]) : 0,
|
||||
WhsCode = (dt.Rows[x]["WhsCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsCode"]) : string.Empty,
|
||||
WhsName = (dt.Rows[x]["WhsName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsName"]) : string.Empty,
|
||||
AvgPrice = (dt.Rows[x]["AvgPrice"] != DBNull.Value) ? Convert.ToDouble(dt.Rows[x]["AvgPrice"]) : 0,
|
||||
});
|
||||
}
|
||||
|
||||
return ListaStock;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.Inventario
|
||||
{
|
||||
public class HelperInventario
|
||||
{
|
||||
public static string Get(string TipoMovimiento)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
string Cuenta = "";
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_GetAccountCode_TipoEntradaSalida\"(?)", con);
|
||||
cmd.Parameters.Add("TipoMovimiento", HanaDbType.VarChar).Value = TipoMovimiento ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
Cuenta = (dt.Rows[x]["U_Cuenta"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_Cuenta"]) : string.Empty;
|
||||
}
|
||||
|
||||
return Cuenta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.Invoices
|
||||
{
|
||||
public class HelperInvoice
|
||||
{
|
||||
public static int Get(string DocNum)
|
||||
{
|
||||
DataTable dt = new DataTable();
|
||||
int DocEntry = 0;
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetEntradaPorImportacion\"(?)", con);
|
||||
cmd.Parameters.Add("DocNum", HanaDbType.VarChar).Value = DocNum ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
DocEntry = (dt.Rows[x]["DocEntry"] != DBNull.Value) ? Convert.ToInt32(dt.Rows[x]["DocEntry"]) : 0;
|
||||
}
|
||||
|
||||
return DocEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Net.Business.Entities.WMS.ProcesoPicking;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.HelperProcesoPermitido
|
||||
{
|
||||
public class HelperProcesoPermitido
|
||||
{
|
||||
public static int Get(string Proceso, int IdEstado, string Endpoint, out List<BE_ProcesoPicking> ListaProceso)
|
||||
{
|
||||
List<BE_ProcesoPicking> list = new List<BE_ProcesoPicking>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"SELECT * FROM \"{LocalData.Schema}\".\"@ITCA_PROWMS\" WHERE \"U_ITCA_PROCESO\" = ? AND \"U_ITCA_ESTADO\" = ? AND \"U_ITCA_ENDPOINT\" = ?", con);
|
||||
cmd.Parameters.Add("Proceso", HanaDbType.VarChar).Value = (Proceso ?? "").ToUpper();
|
||||
cmd.Parameters.Add("IdEstado", HanaDbType.VarChar).Value = IdEstado.ToString();
|
||||
cmd.Parameters.Add("Endpoint", HanaDbType.VarChar).Value = Endpoint ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
list.Add(new BE_ProcesoPicking()
|
||||
{
|
||||
Code = (dt.Rows[x]["Code"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["Code"]) : string.Empty,
|
||||
U_ITCA_ESTADO = (dt.Rows[x]["U_ITCA_ESTADO"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITCA_ESTADO"]) : string.Empty,
|
||||
U_ITCA_GNRPROC = (dt.Rows[x]["U_ITCA_GNRPROC"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITCA_GNRPROC"]) : string.Empty,
|
||||
U_ITCA_PROCESO = (dt.Rows[x]["U_ITCA_PROCESO"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITCA_PROCESO"]) : string.Empty,
|
||||
});
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
ListaProceso = list;
|
||||
return dt.Rows.Count;
|
||||
}
|
||||
|
||||
public static string GetMotivoAlmacen(string CodEstado, out bool Reproceso, out string MotivoNotaCredito, out string DescripcionMotivo)
|
||||
{
|
||||
string Almacen = "";
|
||||
Reproceso = false;
|
||||
MotivoNotaCredito = "";
|
||||
DescripcionMotivo = "";
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"SELECT * FROM \"{LocalData.Schema}\".\"@SYP_MOTIVOS\" WHERE \"Code\" = ?", con);
|
||||
cmd.Parameters.Add("Code", HanaDbType.VarChar).Value = (CodEstado ?? "").ToUpper();
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
Reproceso = (dt.Rows[x]["U_ITC_WMS_RPG"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITC_WMS_RPG"]) == "Y" : false;
|
||||
Almacen = (dt.Rows[x]["U_ITC_WMS_WHS"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_ITC_WMS_WHS"]) : string.Empty;
|
||||
MotivoNotaCredito = (dt.Rows[x]["U_SYP_CODMO"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["U_SYP_CODMO"]) : string.Empty;
|
||||
DescripcionMotivo = (dt.Rows[x]["Name"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["Name"]) : string.Empty;
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
return Almacen;
|
||||
}
|
||||
|
||||
public static int? ConvertTimeToSeconds(string timeString)
|
||||
{
|
||||
string[] parts = timeString.Split(':');
|
||||
if (parts.Length != 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int hours = int.Parse(parts[0]);
|
||||
int minutes = int.Parse(parts[1]);
|
||||
int seconds = int.Parse(parts[2]);
|
||||
|
||||
return (hours * 3600) + (minutes * 60) + seconds;
|
||||
}
|
||||
|
||||
public static int? ConvertTimeToInteger(string timeString)
|
||||
{
|
||||
// Split the time string into hours and minutes
|
||||
string[] parts = timeString.Split(':');
|
||||
if (parts.Length == 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int hours = int.Parse(parts[0]);
|
||||
int minutes = int.Parse(parts[1]);
|
||||
|
||||
// Combine hours and minutes into a single integer (e.g., 10:30 becomes 1030)
|
||||
int result = (hours * 100) + minutes;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Sap.Data.Hana;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.HelperProcesoPermitido
|
||||
{
|
||||
public class HelperProcesoPiciking
|
||||
{
|
||||
public static void Set(string Proceso, int IdEstado, int DocEntry, string CodMotivo, string Code)
|
||||
{
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand();
|
||||
// Parametrizado (antes interpolaba el string directo - SQL injection
|
||||
// real, ver docs/PORTE_FUNCIONALIDAD_NUEVA.md hallazgo #6): Proceso y
|
||||
// CodMotivo vienen del body del request HTTP sin validar.
|
||||
cmd.CommandText = $"CALL \"{LocalData.Schema}\".\"ITCA_WMS_SAP_SetProcesoPicking\"(?, ?, ?, ?, ?, ?, ?)";
|
||||
cmd.Parameters.Add("Proceso", HanaDbType.VarChar).Value = Proceso;
|
||||
cmd.Parameters.Add("IdEstado", HanaDbType.Integer).Value = IdEstado;
|
||||
cmd.Parameters.Add("DocEntry", HanaDbType.Integer).Value = DocEntry;
|
||||
cmd.Parameters.Add("HoraInicio", HanaDbType.VarChar).Value = "";
|
||||
cmd.Parameters.Add("HoraFin", HanaDbType.VarChar).Value = "";
|
||||
cmd.Parameters.Add("CodMotivo", HanaDbType.VarChar).Value = CodMotivo;
|
||||
cmd.Parameters.Add("Code", HanaDbType.VarChar).Value = Code;
|
||||
cmd.CommandType = System.Data.CommandType.Text;
|
||||
cmd.Connection = con;
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Set(string Proceso, int IdEstado, int DocEntry, int? HoraInicio, int? HoraFin, string CodMotivo, string Code)
|
||||
{
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand();
|
||||
// Ver nota de parametrizacion en la sobrecarga de arriba.
|
||||
cmd.CommandText = $"CALL \"{LocalData.Schema}\".\"ITCA_WMS_SAP_SetProcesoPicking\"(?, ?, ?, ?, ?, ?, ?)";
|
||||
cmd.Parameters.Add("Proceso", HanaDbType.VarChar).Value = Proceso;
|
||||
cmd.Parameters.Add("IdEstado", HanaDbType.Integer).Value = IdEstado;
|
||||
cmd.Parameters.Add("DocEntry", HanaDbType.Integer).Value = DocEntry;
|
||||
cmd.Parameters.Add("HoraInicio", HanaDbType.VarChar).Value = HoraInicio?.ToString() ?? "";
|
||||
cmd.Parameters.Add("HoraFin", HanaDbType.VarChar).Value = HoraFin?.ToString() ?? "";
|
||||
cmd.Parameters.Add("CodMotivo", HanaDbType.VarChar).Value = CodMotivo;
|
||||
cmd.Parameters.Add("Code", HanaDbType.VarChar).Value = Code;
|
||||
cmd.CommandType = System.Data.CommandType.Text;
|
||||
cmd.Connection = con;
|
||||
cmd.ExecuteNonQuery();
|
||||
con.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace Net.Data.HelperData.Stock
|
||||
{
|
||||
public class HelperStock
|
||||
{
|
||||
public static List<BE_ItemStock> Get(string ItemCode, string FromWarehouseCode)
|
||||
{
|
||||
List<BE_ItemStock> ListaStock = new List<BE_ItemStock>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetStock\"(?, ?)", con);
|
||||
cmd.Parameters.Add("ItemCode", HanaDbType.VarChar).Value = ItemCode ?? "";
|
||||
cmd.Parameters.Add("FromWarehouseCode", HanaDbType.VarChar).Value = FromWarehouseCode ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
ListaStock.Add(new BE_ItemStock()
|
||||
{
|
||||
BinCode = (dt.Rows[x]["BinCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["BinCode"]) : string.Empty,
|
||||
DistNumber = (dt.Rows[x]["DistNumber"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["DistNumber"]) : string.Empty,
|
||||
ExpDate = (dt.Rows[x]["ExpDate"] != DBNull.Value) ? Convert.ToDateTime(dt.Rows[x]["ExpDate"]) : DateTime.Now,
|
||||
ItemCode = (dt.Rows[x]["ItemCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemCode"]) : string.Empty,
|
||||
ItemName = (dt.Rows[x]["ItemName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemName"]) : string.Empty,
|
||||
OnHandQty = (dt.Rows[x]["OnHandQty"] != DBNull.Value) ? Convert.ToDouble(dt.Rows[x]["OnHandQty"]) : 0,
|
||||
WhsCode = (dt.Rows[x]["WhsCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsCode"]) : string.Empty,
|
||||
WhsName = (dt.Rows[x]["WhsName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsName"]) : string.Empty,
|
||||
});
|
||||
}
|
||||
|
||||
return ListaStock;
|
||||
}
|
||||
|
||||
|
||||
public static List<BE_ItemStock> GetConsolidado(string ItemCode, string FromWarehouseCode)
|
||||
{
|
||||
List<BE_ItemStock> ListaStock = new List<BE_ItemStock>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetStockConsolidado\"(?, ?)", con);
|
||||
cmd.Parameters.Add("ItemCode", HanaDbType.VarChar).Value = ItemCode ?? "";
|
||||
cmd.Parameters.Add("FromWarehouseCode", HanaDbType.VarChar).Value = FromWarehouseCode ?? "";
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
con.Close();
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
ListaStock.Add(new BE_ItemStock()
|
||||
{
|
||||
BinCode = (dt.Rows[x]["BinCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["BinCode"]) : string.Empty,
|
||||
DistNumber = (dt.Rows[x]["DistNumber"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["DistNumber"]) : string.Empty,
|
||||
ExpDate = (dt.Rows[x]["ExpDate"] != DBNull.Value) ? Convert.ToDateTime(dt.Rows[x]["ExpDate"]) : DateTime.Now,
|
||||
ItemCode = (dt.Rows[x]["ItemCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemCode"]) : string.Empty,
|
||||
ItemName = (dt.Rows[x]["ItemName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["ItemName"]) : string.Empty,
|
||||
OnHandQty = (dt.Rows[x]["OnHandQty"] != DBNull.Value) ? Convert.ToDouble(dt.Rows[x]["OnHandQty"]) : 0,
|
||||
WhsCode = (dt.Rows[x]["WhsCode"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsCode"]) : string.Empty,
|
||||
WhsName = (dt.Rows[x]["WhsName"] != DBNull.Value) ? Convert.ToString(dt.Rows[x]["WhsName"]) : string.Empty,
|
||||
AvgPrice = (dt.Rows[x]["AvgPrice"] != DBNull.Value) ? Convert.ToDouble(dt.Rows[x]["AvgPrice"]) : 0,
|
||||
});
|
||||
}
|
||||
|
||||
return ListaStock;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
|
||||
namespace Net.Data
|
||||
{
|
||||
public class LocalData
|
||||
{
|
||||
public static string ConnectionString { get; private set; }
|
||||
|
||||
// Esquema HANA: por defecto la compañia del Service Layer (SapServiceLayer:company)
|
||||
public static string Schema { get; private set; }
|
||||
|
||||
// Unico punto de lectura de las credenciales HANA (seccion "Hana" de appsettings.json)
|
||||
public static void Configure(IConfiguration configuration)
|
||||
{
|
||||
var server = configuration["Hana:server"];
|
||||
var user = configuration["Hana:user"];
|
||||
var password = configuration["Hana:password"];
|
||||
|
||||
if (string.IsNullOrWhiteSpace(server) || string.IsNullOrWhiteSpace(user) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new InvalidOperationException("Falta la seccion \"Hana\" (server, user, password) en appsettings.json");
|
||||
}
|
||||
|
||||
ConnectionString = $"Server={server};UserName={user};Password={password}";
|
||||
|
||||
var schema = configuration["Hana:schema"];
|
||||
if (string.IsNullOrWhiteSpace(schema)) schema = configuration["SapServiceLayer:company"];
|
||||
if (string.IsNullOrWhiteSpace(schema))
|
||||
{
|
||||
throw new InvalidOperationException("Falta el esquema HANA: configure Hana:schema o SapServiceLayer:company en appsettings.json");
|
||||
}
|
||||
|
||||
Schema = schema;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Net.Business.Entities\Net.Business.Entities.csproj" />
|
||||
<ProjectReference Include="..\Net.Connection.ServiceLayer\Net.Connection.ServiceLayer.csproj" />
|
||||
<ProjectReference Include="..\Net.Connection\Net.Connection.csproj" />
|
||||
<ProjectReference Include="..\Net.Constantes\Net.Constantes.csproj" />
|
||||
<ProjectReference Include="..\Net.CrossCotting\Net.CrossCotting.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Sap.Data.Hana.Core.v2.1">
|
||||
<HintPath>..\..\..\..\..\..\..\..\Program Files\sap\hdbclient\dotnetcore\v2.1\Sap.Data.Hana.Core.v2.1.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.Constantes;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public class BusinessPartnersRepository : IBusinessPartnersRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
#endregion
|
||||
|
||||
public BusinessPartnersRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BusinessPartners>> GetBusinessPartnersByFilter(FE_BusinessPartners entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BusinessPartners> resultadoTransaccion = new ResultadoTransaccion<BE_BusinessPartners>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
string select = "select= CardCode, CardName,CardType, FederalTaxID,Address,EmailAddress,Phone1";
|
||||
|
||||
entidad.CardCode = string.IsNullOrEmpty(entidad.CardCode) ? string.Empty : entidad.CardCode;
|
||||
entidad.CardName = string.IsNullOrEmpty(entidad.CardName) ? string.Empty : entidad.CardName;
|
||||
entidad.FederalTaxID = string.IsNullOrEmpty(entidad.FederalTaxID) ? string.Empty : entidad.FederalTaxID;
|
||||
|
||||
string cadena = string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(entidad.CardCode))
|
||||
{
|
||||
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and CardCode eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.CardCode, select);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(entidad.CardName))
|
||||
{
|
||||
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and CardName eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.CardName, select);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(entidad.FederalTaxID))
|
||||
{
|
||||
cadena = string.Format("{0}?$filter = Valid eq 'tYES' and FederalTaxID eq '{1}' &${2}", StoreProcedure.SP_SERVICES_LAYER_BUSINESSPARTNERS, entidad.FederalTaxID, select);
|
||||
}
|
||||
|
||||
int maxpagesize = 0;
|
||||
List<BE_BusinessPartners> objectList = await _connectServiceLayer.GetAsync<BE_BusinessPartners>(cadena, maxpagesize);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public interface IBusinessPartnersRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BusinessPartners>> GetBusinessPartnersByFilter(FE_BusinessPartners entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.CreditNotes
|
||||
{
|
||||
public class CreditNotesRepository : ICreditNotesRepository
|
||||
{
|
||||
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
#endregion
|
||||
|
||||
public CreditNotesRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateCreditNotes(BE_CreditNotesNotes entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
//var cadena = "Drafts";
|
||||
var cadena = "CreditNotes";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> UpdateCreateCreditNotes(dynamic entidad, int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
//var cadena = "Drafts";
|
||||
var cadena = $"CreditNotes({DocEntry})";
|
||||
var data = await _connectServiceLayer.PatchAsyncSBA<BE_BaseResponseSap>(cadena, entidad);
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.CreditNotes
|
||||
{
|
||||
public interface ICreditNotesRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateCreditNotes(BE_CreditNotesNotes entidad);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.HR;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData.HojaRuta;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.GlobalData
|
||||
{
|
||||
public class GlobalDataRepository : IGlobalDataRepository
|
||||
{
|
||||
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
#endregion
|
||||
|
||||
public GlobalDataRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<ITC_SOLSALMER>> GetSolicitudSalida(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<ITC_SOLSALMER> resultadoTransaccion = new ResultadoTransaccion<ITC_SOLSALMER>(_metodoName, _aplicacionName);
|
||||
try
|
||||
{
|
||||
|
||||
string cadena = $"ITC_SOLSALMER({DocEntry})";
|
||||
int maxpagesize = 0;
|
||||
List<ITC_SOLSALMER> objectList = await _connectServiceLayer.GetAsync<ITC_SOLSALMER>(cadena, maxpagesize, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<ITC_SOLINGMER>> GetSolicitudIngreso(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<ITC_SOLINGMER> resultadoTransaccion = new ResultadoTransaccion<ITC_SOLINGMER>(_metodoName, _aplicacionName);
|
||||
try
|
||||
{
|
||||
|
||||
string cadena = $"ITC_SOLINGMER({DocEntry})";
|
||||
int maxpagesize = 0;
|
||||
List<ITC_SOLINGMER> objectList = await _connectServiceLayer.GetAsync<ITC_SOLINGMER>(cadena, maxpagesize, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.HR;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.GlobalData
|
||||
{
|
||||
public interface IGlobalDataRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<ITC_SOLSALMER>> GetSolicitudSalida(int DocEntry);
|
||||
Task<BE_ResultadoTransaccion<ITC_SOLINGMER>> GetSolicitudIngreso(int DocEntry);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.HR;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData.HojaRuta;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.HR
|
||||
{
|
||||
public class HRRepository : IHRRepository
|
||||
{
|
||||
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
#endregion
|
||||
|
||||
public HRRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> SetCreateHojaRuta(BE_HojaRutaCreate entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
int Indice = 1;
|
||||
List<HojaRutaDetailsEntities> detalle = new List<HojaRutaDetailsEntities>();
|
||||
entidad.Detalle.ForEach(item =>
|
||||
{
|
||||
var data = HelperHojaRuta.Get(Convert.ToInt32(item.CodigoInterno));
|
||||
var linea = data.FirstOrDefault();
|
||||
linea.LineId = Indice;
|
||||
detalle.Add(linea);
|
||||
|
||||
Indice++;
|
||||
});
|
||||
|
||||
HojaRutaSAP HojaRuta = new HojaRutaSAP()
|
||||
{
|
||||
ARD_PCK_HJRT_DETCollection = new List<HojaRutaDetailsEntities>(),
|
||||
U_ARD_PHR_PLACA = entidad.PlacaVehiculo,
|
||||
U_ARD_PHR_TERRI = entidad.Territorio,
|
||||
U_ARD_PHR_ZONDIS = entidad.Zona,
|
||||
U_ARD_PHR_FECCRE = entidad.FechaDespacho,
|
||||
U_ARD_PHR_MODTRANSP = entidad.ModalidadTransporte,
|
||||
U_ARD_PHR_NOMDESP = entidad.Despachador,
|
||||
U_ARD_PHR_ESTDESP = "Embarcado",
|
||||
U_ARD_PHR_RUCAGENTRANS = entidad.AgenciaTransporte,
|
||||
U_ARD_PHR_LICCON = entidad.LicenciaConductor,
|
||||
U_MSV_PKH_ORIG = "Y",
|
||||
U_ARD_PHR_CNTDOC = entidad.Detalle.Count()
|
||||
};
|
||||
|
||||
//if(entidad.ModalidadTransporte == "Privado")
|
||||
//{
|
||||
// HojaRuta = new HojaRutaSAP()
|
||||
// {
|
||||
// ARD_PCK_HJRT_DETCollection = new List<HojaRutaDetailsEntities>(),
|
||||
// U_ARD_PHR_PLACA = entidad.PlacaVehiculo,
|
||||
// U_ARD_PHR_TERRI = entidad.Territorio,
|
||||
// U_ARD_PHR_ZONDIS = entidad.Zona,
|
||||
// U_ARD_PHR_FECCRE = entidad.FechaDespacho,
|
||||
// U_ARD_PHR_MODTRANSP = entidad.ModalidadTransporte,
|
||||
// U_ARD_PHR_NOMDESP = entidad.Despachador,
|
||||
// U_ARD_PHR_NOMAGENTRANS = "ARDICORP S.A.C.",
|
||||
// U_ARD_PHR_CODAGENTRANS = "P20136836545",
|
||||
// U_ARD_PHR_RUCAGENTRANS = "20136836545",
|
||||
// U_ARD_PHR_ESTDESP = "Embarcado"
|
||||
// };
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
HojaRuta.ARD_PCK_HJRT_DETCollection = detalle;
|
||||
|
||||
var cadena = "ARD_PHR";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, HojaRuta);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(data.Mensaje.ToString(), entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)data.DocEntry, data.DocNum.ToString(), "Se Listo correctamento...!!!", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message, entidad);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> UpdateCreateCreditNotes(dynamic entidad, int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
//var cadena = "Drafts";
|
||||
var cadena = $"CreditNotes({DocEntry})";
|
||||
var data = await _connectServiceLayer.PatchAsyncSBA<BE_BaseResponseSap>(cadena, entidad);
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.HR;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.HR
|
||||
{
|
||||
public interface IHRRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> SetCreateHojaRuta(BE_HojaRutaCreate entidad);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Net.Data.ServicesLayer.InventoryGenEntries
|
||||
{
|
||||
public interface IInventoryGenEntriesRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInventoryGenEntries(BE_InventoryGenEntries entidad, bool Drafts = true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.InventoryGenEntries
|
||||
{
|
||||
public class InventoryGenEntriesRepository : IInventoryGenEntriesRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
|
||||
public InventoryGenEntriesRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
//Inicializamos los servicios de services layer
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
|
||||
}
|
||||
|
||||
// VENTAS PARA SAP
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInventoryGenEntries(BE_InventoryGenEntries entidad, bool Draft = true)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = Draft ? "Drafts" : "InventoryGenEntries";
|
||||
var dataResponseInvoice = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!dataResponseInvoice.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, dataResponseInvoice.Mensaje);
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se registró correctamento...!!!", dataResponseInvoice);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenExits;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Net.Data.ServicesLayer.InventoryGenExits
|
||||
{
|
||||
public interface IInventoryGenExitsRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInventoryGenExits(BE_InventoryGenExits entidad, bool Drafts = true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenExits;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.InventoryGenExits
|
||||
{
|
||||
public class InventoryGenExitsRepository : IInventoryGenExitsRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
|
||||
public InventoryGenExitsRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
//Inicializamos los servicios de services layer
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
|
||||
}
|
||||
|
||||
// VENTAS PARA SAP
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInventoryGenExits(BE_InventoryGenExits entidad, bool Drafts = true)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = Drafts ? "Drafts": "InventoryGenExits";
|
||||
var dataResponseInvoice = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!dataResponseInvoice.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, dataResponseInvoice.Mensaje);
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se registró correctamento...!!!", dataResponseInvoice);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Connection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public interface IInvoiceRepository
|
||||
{
|
||||
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInvoices(BE_Invoices entidad);
|
||||
Task<BE_ResultadoTransaccion<BE_InvoicesConsulta>> GetInvoice(int docEntry);
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> ReOpen(int docEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.Constantes;
|
||||
using Net.CrossCotting;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public class InvoiceRepository : IInvoiceRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
private readonly IConnectionSQL _context;
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
|
||||
public InvoiceRepository(IHttpClientFactory clientFactory, IConfiguration configuration, IConnectionSQL context)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
//Inicializamos los servicios de services layer
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
_context = context;
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
|
||||
}
|
||||
|
||||
// VENTAS PARA SAP
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateInvoices(BE_Invoices entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "Invoices";
|
||||
var dataResponseInvoice = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!dataResponseInvoice.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, dataResponseInvoice.Mensaje);
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se registró correctamento...!!!", dataResponseInvoice);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// GET INVOICES
|
||||
public async Task<BE_ResultadoTransaccion<BE_InvoicesConsulta>> GetInvoice(int docEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_InvoicesConsulta> resultadoTransaccion = new ResultadoTransaccion<BE_InvoicesConsulta>(_metodoName, _aplicacionName);
|
||||
try
|
||||
{
|
||||
|
||||
string cadena = $"Invoices({docEntry})";
|
||||
int maxpagesize = 0;
|
||||
List<BE_InvoicesConsulta> objectList = await _connectServiceLayer.GetAsync<BE_InvoicesConsulta>(cadena, maxpagesize,true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> ReOpen(int docEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
try
|
||||
{
|
||||
|
||||
string cadena = $"Invoices({docEntry})/Reopen";
|
||||
var dataResponseInvoice = await _connectServiceLayer.PostReOpen<BE_BaseResponseSap>(cadena);
|
||||
|
||||
if (!dataResponseInvoice.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, dataResponseInvoice.Mensaje);
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se registró correctamento...!!!", dataResponseInvoice);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseDeliveryNotes;
|
||||
using Net.Connection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public interface IPurchaseDeliveryNotesRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseDeliveryNotes(BE_PurchaseDeliveryNotes entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseDeliveryNotes;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public class PurchaseDeliveryNotesRepository : IPurchaseDeliveryNotesRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
#endregion
|
||||
|
||||
public PurchaseDeliveryNotesRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseDeliveryNotes(BE_PurchaseDeliveryNotes entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "PurchaseDeliveryNotes";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// GET INVOICES
|
||||
public async Task<BE_ResultadoTransaccion<BE_PurchaseDeliveryNotes>> GetPurchaseDeliveryNotes(int docEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_PurchaseDeliveryNotes> resultadoTransaccion = new ResultadoTransaccion<BE_PurchaseDeliveryNotes>(_metodoName, _aplicacionName);
|
||||
try
|
||||
{
|
||||
|
||||
string cadena = $"PurchaseDeliveryNotes({docEntry})";
|
||||
int maxpagesize = 0;
|
||||
List<BE_PurchaseDeliveryNotes> objectList = await _connectServiceLayer.GetAsync<BE_PurchaseDeliveryNotes>(cadena, maxpagesize, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public interface IPurchaseInvoicesRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseInvoices(BE_PurchaseInvoices entidad);
|
||||
Task<BE_ResultadoTransaccion<BE_PurchaseInvoices>> GetPurchaseInvoices(int DocEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public class PurchaseInvoicesRepository: IPurchaseInvoicesRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
|
||||
#endregion
|
||||
|
||||
public PurchaseInvoicesRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseInvoices(BE_PurchaseInvoices entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "PurchaseInvoices";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_PurchaseInvoices>> GetPurchaseInvoices(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_PurchaseInvoices> resultadoTransaccion = new ResultadoTransaccion<BE_PurchaseInvoices>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = $"PurchaseInvoices({DocEntry})";
|
||||
var data = await _connectServiceLayer.GetAsync<BE_PurchaseInvoices>(cadena, 0, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseOrders;
|
||||
using Net.Connection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public interface IPurchaseOrdersRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseInvoices(BE_PurchaseInvoices entidad);
|
||||
Task<BE_ResultadoTransaccion<BE_PurchaseOrders>> GetPurchaseInvoices(int DocEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseOrders;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer
|
||||
{
|
||||
public class PurchaseOrdersRepository : IPurchaseOrdersRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
#endregion
|
||||
|
||||
public PurchaseOrdersRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreatePurchaseInvoices(BE_PurchaseInvoices entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "PurchaseInvoices";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_PurchaseOrders>> GetPurchaseInvoices(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_PurchaseOrders> resultadoTransaccion = new ResultadoTransaccion<BE_PurchaseOrders>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = $"PurchaseOrders({DocEntry})";
|
||||
var data = await _connectServiceLayer.GetAsync<BE_PurchaseOrders>(cadena, 0, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.ReturnRequest;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.ReturnRequest
|
||||
{
|
||||
public interface IReturnRequestRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateReturnRequest(BE_ReturnRequest entidad);
|
||||
Task<BE_ResultadoTransaccion<BE_ReturnRequest>> GetRequestReturn(int DocEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.ReturnRequest;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.ReturnRequest
|
||||
{
|
||||
public class ReturnRequestRepository: IReturnRequestRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
|
||||
#endregion
|
||||
|
||||
public ReturnRequestRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> SetCreateReturnRequest(BE_ReturnRequest entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "ReturnRequest";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_ReturnRequest>> GetRequestReturn(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_ReturnRequest> resultadoTransaccion = new ResultadoTransaccion<BE_ReturnRequest>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = $"ReturnRequest({DocEntry})";
|
||||
var data = await _connectServiceLayer.GetAsync<BE_ReturnRequest>(cadena, 0, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.StockTransfer
|
||||
{
|
||||
public interface IStockTransferRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> StockTransfer(dynamic entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.ServicesLayer.StockTransfer
|
||||
{
|
||||
public class StockTransferRepository: IStockTransferRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
//Services Layer
|
||||
private readonly ConnectionServiceLayer _connectServiceLayer;
|
||||
|
||||
#endregion
|
||||
|
||||
public StockTransferRepository(IHttpClientFactory clientFactory, IConfiguration configuration)
|
||||
{
|
||||
_aplicacionName = this.GetType().Name;
|
||||
_connectServiceLayer = new ConnectionServiceLayer(configuration, clientFactory);
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> StockTransfer(dynamic entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = "StockTransfers";
|
||||
var data = await _connectServiceLayer.PostAsync<BE_BaseResponseSap>(cadena, entidad);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> CloseInventoryTransferRequest(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = $"InventoryTransferRequests({DocEntry})/Close";
|
||||
var data = await _connectServiceLayer.PostClose<BE_BaseResponseSap>(cadena);
|
||||
|
||||
if (!data.Exito)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, data.Mensaje);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_BaseResponseSap>> GetInventoryTransferRequest(int DocEntry)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_BaseResponseSap> resultadoTransaccion = new ResultadoTransaccion<BE_BaseResponseSap>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
var cadena = $"InventoryTransferRequests({DocEntry})";
|
||||
var data = await _connectServiceLayer.GetAsync<BE_BaseResponseSap>(cadena, 0, true);
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
try
|
||||
{
|
||||
HelperDB.SET($"UPDATE \"{LocalData.DB_NAME}\".\"ODRF\" SET \"U_ITC_WMS_NUMINV\" = '{entidad.NroInventario}' WHERE \"DocEntry\" = {inventoryGenEntries_result.Data.DocEntry} ");
|
||||
}
|
||||
catch (Exception) { }
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Net.Data.WMS.Enums
|
||||
{
|
||||
public class EnumRecibo
|
||||
{
|
||||
public const int IMPORTACION = 1;
|
||||
public const int IMPORTACION_ORDEN = 1;
|
||||
public const int IMPORTACION_ORDEN_COMPRA = 2;
|
||||
public const int IMPORTACION_SOL_ENTRADA = 10;
|
||||
public const int NACIONAL = 2;
|
||||
public const int DEVOLUCION = 3;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.WMS.Inventario;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Inventario
|
||||
{
|
||||
public interface IInventarioRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> Create(BE_Inventario entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,601 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenExits;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Net.Business.Entities.ServicesLayer.StockTransfer;
|
||||
using Net.Business.Entities.WMS.Inventario;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData;
|
||||
using Net.Data.HelperData.Inventario;
|
||||
using Net.Data.HelperData.Stock;
|
||||
using Net.Data.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Data.ServicesLayer.InventoryGenExits;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Inventario
|
||||
{
|
||||
public class InventarioRepository : RepositoryBase<object>, IInventarioRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
public InventarioRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
_aplicacionName = GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> Create(BE_Inventario entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
if (string.IsNullOrEmpty(entidad.TipoMovimiento))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El campo Tipo Movimiento no puede ser vacio", entidad);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entidad.TipoMovimientoSAP))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El campo Tipo Movimiento SAP no puede ser vacio", entidad);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(entidad.TipoInventario))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El campo Tipo Inventario no puede ser vacio", entidad);
|
||||
}
|
||||
|
||||
//=== ASIGNA PRECIO PROMEDIO (solo aplica a entradas de mercancia)
|
||||
if (entidad.TipoMovimiento == "01")
|
||||
{
|
||||
foreach (var x in entidad.Detalle)
|
||||
{
|
||||
var Stock = HelperStock.GetConsolidado(x.CodigoArticulo, entidad.SubAlmacen);
|
||||
|
||||
// Un ingreso puede crear el primer stock del articulo: sin datos se conserva el precio del request
|
||||
if (Stock.Count > 0)
|
||||
{
|
||||
x.PrecioPromedio = Stock.FirstOrDefault().AvgPrice;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var ListaxLista = new List<BE_Inventario>();
|
||||
var lista = entidad.Detalle;
|
||||
for (int i = 0; i < lista.Count; i += 100)
|
||||
{
|
||||
var bloque = lista.Skip(i).Take(100).ToList();
|
||||
// Copia por bloque: antes se reutilizaba "entidad" y todos los bloques
|
||||
// terminaban apuntando al ultimo detalle (documentos repetidos y lineas perdidas)
|
||||
var Inventario = new BE_Inventario()
|
||||
{
|
||||
Fecha = entidad.Fecha,
|
||||
FechaVencimiento = entidad.FechaVencimiento,
|
||||
TipoMovimientoSAP = entidad.TipoMovimientoSAP,
|
||||
TipoMovimiento = entidad.TipoMovimiento,
|
||||
TipoInventario = entidad.TipoInventario,
|
||||
Almacen = entidad.Almacen,
|
||||
SubAlmacen = entidad.SubAlmacen,
|
||||
NroInventario = entidad.NroInventario,
|
||||
Detalle = bloque
|
||||
};
|
||||
ListaxLista.Add(Inventario);
|
||||
}
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
string CuentaContable = HelperInventario.Get(entidad.TipoMovimientoSAP);
|
||||
|
||||
if (string.IsNullOrEmpty(CuentaContable))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("No existe cuenta contable configurado para el tipo movimiento SAP", entidad);
|
||||
}
|
||||
|
||||
//=== OBTIENE PRECIO PROMEDIO (solo aplica a entradas de mercancia)
|
||||
if (entidad.TipoMovimiento == "01")
|
||||
{
|
||||
entidad.Detalle.ForEach(detalle =>
|
||||
{
|
||||
var ListaStockConsolidado = HelperStock.GetConsolidado(detalle.CodigoArticulo, entidad.Almacen);
|
||||
|
||||
// Un ingreso puede crear el primer stock del articulo: sin datos se conserva el precio del request
|
||||
if (ListaStockConsolidado.Count > 0)
|
||||
{
|
||||
detalle.PrecioPromedio = ListaStockConsolidado.FirstOrDefault().AvgPrice;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//=== TIPO DE INVENTARIO GENERAL
|
||||
if (entidad.TipoInventario == "01")
|
||||
{
|
||||
//=== INGRESO DE MERCANCIA
|
||||
if (entidad.TipoMovimiento == "01")
|
||||
{
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_InventoryGenEntries _InventoryGenEntries = new BE_InventoryGenEntries()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenEntry",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenEntriesLine>(),
|
||||
U_SYP_TPOENTME = entidad_inventario.TipoMovimientoSAP,
|
||||
U_ITC_WMS_NUMINV = entidad_inventario.NroInventario
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenEntries.DocumentLines.Add(new BE_InventoryGenEntriesLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = detalle.DescripcionArticulo,
|
||||
Quantity = (double)detalle.Cantidad,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.Cantidad,
|
||||
WarehouseCode = entidad.SubAlmacen,
|
||||
AccountCode = CuentaContable,
|
||||
CostingCode = detalle.CentroCosto ?? "",
|
||||
BatchNumbers = new List<BE_InventoryGenEntriesBatchNumbers>()
|
||||
{
|
||||
new BE_InventoryGenEntriesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (double)detalle.Cantidad
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
InventoryGenEntriesRepository inventoryGenEntries = new InventoryGenEntriesRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenEntries_result = inventoryGenEntries.SetCreateInventoryGenEntries(_InventoryGenEntries, false).Result;
|
||||
if (inventoryGenEntries_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenEntries_result.Message.ToString(), entidad);
|
||||
}
|
||||
|
||||
DocEntry = (int)inventoryGenEntries_result.Data.DocEntry;
|
||||
DocNum = (int)inventoryGenEntries_result.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
|
||||
//=== SALIDA DE MERCANCIA
|
||||
if (entidad.TipoMovimiento == "02")
|
||||
{
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_InventoryGenExits _InventoryGenExits = new BE_InventoryGenExits()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenExit",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenExitsLine>(),
|
||||
U_SYP_TPOSALME = entidad_inventario.TipoMovimientoSAP,
|
||||
U_ITC_WMS_NUMINV = entidad_inventario.NroInventario
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenExits.DocumentLines.Add(new BE_InventoryGenExitsLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = detalle.DescripcionArticulo,
|
||||
Quantity = (double)detalle.Cantidad,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.Cantidad,
|
||||
WarehouseCode = entidad.SubAlmacen,
|
||||
AccountCode = CuentaContable,
|
||||
BatchNumbers = new List<BE_InventoryGenExitsBatchNumbers>(),
|
||||
CostingCode = detalle.CentroCosto ?? "",
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
_InventoryGenExits.DocumentLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.SubAlmacen);
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
var cantidadStock = ListaStock.Sum(x => x.OnHandQty);
|
||||
if (cantidadStock < line.Quantity)
|
||||
{
|
||||
throw new Exception($"El producto {line.ItemCode} no cuenta con stock suficiente");
|
||||
}
|
||||
else
|
||||
{
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = Lote.OnHandQty });
|
||||
CantidadPendiente -= Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
|
||||
InventoryGenExitsRepository inventoryGenExits = new InventoryGenExitsRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenExits_result = inventoryGenExits.SetCreateInventoryGenExits(_InventoryGenExits, false).Result;
|
||||
if (inventoryGenExits_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenExits_result.Message.ToString(), entidad);
|
||||
}
|
||||
DocEntry = (int)inventoryGenExits_result.Data.DocEntry;
|
||||
DocNum = (int)inventoryGenExits_result.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
//=== TIPO DE INVENTARIO CICLICO
|
||||
if (entidad.TipoInventario == "02")
|
||||
{
|
||||
//=== INGRESO DE MERCANCIA
|
||||
if (entidad.TipoMovimiento == "01")
|
||||
{
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_InventoryGenEntries _InventoryGenEntries = new BE_InventoryGenEntries()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenEntry",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenEntriesLine>(),
|
||||
U_SYP_TPOENTME = entidad_inventario.TipoMovimientoSAP,
|
||||
U_ITC_WMS_NUMINV = entidad_inventario.NroInventario
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenEntries.DocumentLines.Add(new BE_InventoryGenEntriesLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = detalle.DescripcionArticulo,
|
||||
Quantity = (double)detalle.Cantidad,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.Cantidad,
|
||||
WarehouseCode = entidad.SubAlmacen,
|
||||
AccountCode = CuentaContable,
|
||||
CostingCode = detalle.CentroCosto ?? "",
|
||||
BatchNumbers = new List<BE_InventoryGenEntriesBatchNumbers>()
|
||||
{
|
||||
new BE_InventoryGenEntriesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (double)detalle.Cantidad
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
InventoryGenEntriesRepository inventoryGenEntries = new InventoryGenEntriesRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenEntries_result = inventoryGenEntries.SetCreateInventoryGenEntries(_InventoryGenEntries).Result;
|
||||
if (inventoryGenEntries_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenEntries_result.Message.ToString(), entidad);
|
||||
}
|
||||
DocEntry = (int)inventoryGenEntries_result.Data.DocEntry;
|
||||
DocNum = (int)inventoryGenEntries_result.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
|
||||
//=== SALIDA DE MERCANCIA [GENERA TRANSFERENCIA]
|
||||
if (entidad.TipoMovimiento == "02")
|
||||
{
|
||||
string AlmacenDestino = "ALM12";
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(_clientFactory, _configuration);
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_StockTransfer StockTransfer = new BE_StockTransfer
|
||||
{
|
||||
DocDate = DateTime.Now,
|
||||
DueDate = DateTime.Now,
|
||||
TaxDate = DateTime.Now,
|
||||
FromWarehouse = entidad.SubAlmacen,
|
||||
ToWarehouse = AlmacenDestino,
|
||||
Comments = "Transferencia Generado desde Cubico - SAP",
|
||||
StockTransferLines = new List<BE_StockTransferLine>(),
|
||||
U_ITC_WMS_NUMINV = entidad.NroInventario,
|
||||
U_SYP_TPOENTME = entidad.TipoMovimientoSAP
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(x =>
|
||||
{
|
||||
var Detalle = new BE_StockTransferLine
|
||||
{
|
||||
FromWarehouseCode = entidad.SubAlmacen,
|
||||
WarehouseCode = AlmacenDestino,
|
||||
ItemCode = x.CodigoArticulo,
|
||||
Quantity = (double)x.Cantidad,
|
||||
BaseLine = null,
|
||||
BaseEntry = null,
|
||||
BaseType = null,
|
||||
LineNum = LineNum,
|
||||
BatchNumbers = new List<BE_StockTransferLineBatchNumber>()
|
||||
};
|
||||
StockTransfer.StockTransferLines.Add(Detalle);
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
// == REALIZA DISTRIBUCION DE STOCK POR LOTE / ALMACEN
|
||||
StockTransfer.StockTransferLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.SubAlmacen);
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
var cantidadStock = ListaStock.Sum(x => x.OnHandQty);
|
||||
if (cantidadStock < line.Quantity)
|
||||
{
|
||||
throw new Exception($"El producto {line.ItemCode} no cuenta con stock suficiente");
|
||||
}
|
||||
else
|
||||
{
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber() { BatchNumber = Lote.DistNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber() { BatchNumber = Lote.DistNumber, Quantity = Lote.OnHandQty });
|
||||
CantidadPendiente -= Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
var jsonForma = Newtonsoft.Json.JsonConvert.SerializeObject(StockTransfer);
|
||||
var ResultTransaction = stockTransferRepository.StockTransfer(StockTransfer).Result;
|
||||
if (ResultTransaction.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ResultTransaction.Message.ToString(), entidad);
|
||||
}
|
||||
DocEntry = (int)ResultTransaction.Data.DocEntry;
|
||||
DocNum = (int)ResultTransaction.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
//=== TIPO DE INVENTARIO POR CONSUMO
|
||||
if (entidad.TipoInventario == "03")
|
||||
{
|
||||
//=== INGRESO DE MERCANCIA
|
||||
if (entidad.TipoMovimiento == "01")
|
||||
{
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_InventoryGenEntries _InventoryGenEntries = new BE_InventoryGenEntries()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenEntry",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenEntriesLine>(),
|
||||
U_SYP_TPOENTME = entidad.TipoMovimientoSAP,
|
||||
U_ITC_WMS_NUMINV = entidad.NroInventario
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenEntries.DocumentLines.Add(new BE_InventoryGenEntriesLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = detalle.DescripcionArticulo,
|
||||
Quantity = (double)detalle.Cantidad,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.Cantidad,
|
||||
WarehouseCode = entidad.SubAlmacen,
|
||||
AccountCode = CuentaContable,
|
||||
CostingCode = detalle.CentroCosto ?? "",
|
||||
BatchNumbers = new List<BE_InventoryGenEntriesBatchNumbers>()
|
||||
{
|
||||
new BE_InventoryGenEntriesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (double)detalle.Cantidad
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
InventoryGenEntriesRepository inventoryGenEntries = new InventoryGenEntriesRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenEntries_result = inventoryGenEntries.SetCreateInventoryGenEntries(_InventoryGenEntries, false).Result;
|
||||
if (inventoryGenEntries_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenEntries_result.Message.ToString(), entidad);
|
||||
}
|
||||
DocEntry = (int)inventoryGenEntries_result.Data.DocEntry;
|
||||
DocNum = (int)inventoryGenEntries_result.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
// return resultadoTransaccion.GetInformacionResultado((int)inventoryGenEntries_result.Data.DocEntry, inventoryGenEntries_result.Data.DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
|
||||
//=== SALIDA DE MERCANCIA
|
||||
if (entidad.TipoMovimiento == "02")
|
||||
{
|
||||
int DocEntry = 0;
|
||||
int DocNum = 0;
|
||||
foreach (var entidad_inventario in ListaxLista)
|
||||
{
|
||||
BE_InventoryGenExits _InventoryGenExits = new BE_InventoryGenExits()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenExit",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenExitsLine>(),
|
||||
U_SYP_TPOSALME = entidad.TipoMovimientoSAP,
|
||||
U_ITC_WMS_NUMINV = entidad.NroInventario
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad_inventario.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenExits.DocumentLines.Add(new BE_InventoryGenExitsLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = detalle.DescripcionArticulo,
|
||||
Quantity = (double)detalle.Cantidad,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.Cantidad,
|
||||
WarehouseCode = entidad.SubAlmacen,
|
||||
AccountCode = CuentaContable,
|
||||
BatchNumbers = new List<BE_InventoryGenExitsBatchNumbers>(),
|
||||
CostingCode = detalle.CentroCosto ?? "",
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
_InventoryGenExits.DocumentLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.SubAlmacen);
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
var cantidadStock = ListaStock.Sum(x => x.OnHandQty);
|
||||
if (cantidadStock < line.Quantity)
|
||||
{
|
||||
throw new Exception($"El producto {line.ItemCode} no cuenta con stock suficiente");
|
||||
}
|
||||
else
|
||||
{
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = Lote.OnHandQty });
|
||||
CantidadPendiente -= Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
InventoryGenExitsRepository inventoryGenExits = new InventoryGenExitsRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenExits_result = inventoryGenExits.SetCreateInventoryGenExits(_InventoryGenExits, false).Result;
|
||||
if (inventoryGenExits_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenExits_result.Message.ToString(), entidad);
|
||||
}
|
||||
DocEntry = (int)inventoryGenExits_result.Data.DocEntry;
|
||||
DocNum = (int)inventoryGenExits_result.Data.DocNum;
|
||||
};
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(DocEntry, DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
//return resultadoTransaccion.GetInformacionResultado((int)inventoryGenExits_result.Data.DocEntry, inventoryGenExits_result.Data.DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Registrado Correctamente", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), entidad);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Items
|
||||
{
|
||||
public interface IItemsRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<BE_ItemStock>> GetStockItem();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Items
|
||||
{
|
||||
public class ItemsRepository : RepositoryBase<object>, IItemsRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
#endregion
|
||||
|
||||
public ItemsRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_aplicacionName = GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<BE_ItemStock>> GetStockItem()
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<BE_ItemStock> resultadoTransaccion = new ResultadoTransaccion<BE_ItemStock>(_metodoName, _aplicacionName);
|
||||
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
List<BE_ItemStock> ListaStock = new List<BE_ItemStock>();
|
||||
DataTable dt = new DataTable();
|
||||
using (HanaConnection con = new HanaConnection(LocalData.ConnectionString))
|
||||
{
|
||||
con.Open();
|
||||
HanaCommand cmd = new HanaCommand($"CALL\"{LocalData.Schema}\".\"ITCA_WMS_SAP_GetStockConsolidado\"", con);
|
||||
HanaDataAdapter da = new HanaDataAdapter(cmd);
|
||||
if (da != null)
|
||||
{
|
||||
da.Fill(dt);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < dt.Rows.Count; x++)
|
||||
{
|
||||
ListaStock.Add(new BE_ItemStock()
|
||||
{
|
||||
BinCode = dt.Rows[x]["BinCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["BinCode"]) : string.Empty,
|
||||
DistNumber = dt.Rows[x]["DistNumber"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["DistNumber"]) : string.Empty,
|
||||
ExpDate = dt.Rows[x]["ExpDate"] != DBNull.Value ? Convert.ToDateTime(dt.Rows[x]["ExpDate"]) : DateTime.Now,
|
||||
ItemCode = dt.Rows[x]["ItemCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["ItemCode"]) : string.Empty,
|
||||
ItemName = dt.Rows[x]["ItemName"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["ItemName"]) : string.Empty,
|
||||
OnHandQty = dt.Rows[x]["OnHandQty"] != DBNull.Value ? Convert.ToDouble(dt.Rows[x]["OnHandQty"]) : 0,
|
||||
WhsCode = dt.Rows[x]["WhsCode"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["WhsCode"]) : string.Empty,
|
||||
WhsName = dt.Rows[x]["WhsName"] != DBNull.Value ? Convert.ToString(dt.Rows[x]["WhsName"]) : string.Empty,
|
||||
AvgPrice = dt.Rows[x]["AvgPrice"] != DBNull.Value ? Convert.ToDouble(dt.Rows[x]["AvgPrice"]) : 0,
|
||||
});
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado(0, 0, "Datos obtenidos Correctamente", ListaStock);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.WMS.HojaRuta;
|
||||
using Net.Business.Entities.WMS.Picking;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Picking
|
||||
{
|
||||
public interface IPickingRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> Create(BE_PickingRequest entidad);
|
||||
Task<BE_ResultadoTransaccion<object>> CreateHojaRuta(BE_HojaRutaEntities entidad);
|
||||
Task<BE_ResultadoTransaccion<object>> CerrarHojaRuta(int docEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,794 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenExits;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Business.Entities.ServicesLayer.Items;
|
||||
using Net.Business.Entities.ServicesLayer.ReturnRequest;
|
||||
using Net.Business.Entities.ServicesLayer.StockTransfer;
|
||||
using Net.Business.Entities.WMS.HojaRuta;
|
||||
using Net.Business.Entities.WMS.Picking;
|
||||
using Net.Business.Entities.WMS.ProcesoPicking;
|
||||
using Net.Connection;
|
||||
using Net.Connection.ServiceLayer;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData.Correlativo;
|
||||
using Net.Data.HelperData.HelperProcesoPermitido;
|
||||
using Net.Data.HelperData.Stock;
|
||||
using Net.Data.ServicesLayer;
|
||||
using Net.Data.ServicesLayer.CreditNotes;
|
||||
using Net.Data.ServicesLayer.GlobalData;
|
||||
using Net.Data.ServicesLayer.InventoryGenExits;
|
||||
using Net.Data.ServicesLayer.ReturnRequest;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Picking
|
||||
{
|
||||
public class PickingRepository : RepositoryBase<object>, IPickingRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
public PickingRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
_aplicacionName = GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> Create(BE_PickingRequest entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
if (entidad.DocEntry == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El campo docEntry no puede ser cero o vacio", entidad);
|
||||
}
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var Almacen = HelperProcesoPermitido.GetMotivoAlmacen(entidad.CodMotivo, out bool Reproceso, out string MotivoNotaCredito, out string DescripcionMotivo);
|
||||
|
||||
if (string.IsNullOrEmpty(entidad.Proceso))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Se necesita definir el proceso para continuar con el proceso.", entidad);
|
||||
}
|
||||
|
||||
if (entidad.IdEstadoCubico == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Se necesita indicar el IdEstado Cubico para continuar con el proceso.", entidad);
|
||||
}
|
||||
|
||||
int Existe = HelperProcesoPermitido.Get(entidad.Proceso, entidad.IdEstadoCubico, "PICKING", out List<BE_ProcesoPicking> ListaProceso);
|
||||
var Proceso = ListaProceso.FirstOrDefault();
|
||||
if (Existe == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El Proceso y estado no se encuentra configurado para este EndPoint", entidad);
|
||||
}
|
||||
|
||||
var TotalDetalle = 0;
|
||||
var TotalDetalle_Anulado = 0;
|
||||
var TotalDetalle_Parcial = 0;
|
||||
var TotalDetalle_Completo = 0;
|
||||
if (Existe > 1)
|
||||
{
|
||||
TotalDetalle = entidad.Detalle.Count();
|
||||
TotalDetalle_Anulado = entidad.Detalle.Where(x=> x.Estado == "A").Count();
|
||||
TotalDetalle_Parcial = entidad.Detalle.Where(x => x.Estado == "P").Count();
|
||||
TotalDetalle_Completo = entidad.Detalle.Where(x => x.Estado == "C").Count();
|
||||
if(TotalDetalle == TotalDetalle_Anulado)
|
||||
{
|
||||
Proceso = ListaProceso.FirstOrDefault(x => x.Code == "013");
|
||||
if (Reproceso)
|
||||
{
|
||||
Proceso = ListaProceso.FirstOrDefault(x => x.Code == "017");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Proceso = ListaProceso.FirstOrDefault(x => x.Code == "012");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalDetalle = entidad.Detalle.Count();
|
||||
TotalDetalle_Anulado = entidad.Detalle.Where(x => x.Estado == "A").Count();
|
||||
TotalDetalle_Parcial = entidad.Detalle.Where(x => x.Estado == "P").Count();
|
||||
TotalDetalle_Completo = entidad.Detalle.Where(x => x.Estado == "C").Count();
|
||||
}
|
||||
|
||||
//=== REALIZA PROCESO COMPLETO DE ACTUALIZACION
|
||||
HelperProcesoPiciking.Set(entidad.Proceso, entidad.IdEstadoCubico, entidad.DocEntry, entidad.CodMotivo, Proceso.Code);
|
||||
|
||||
// === NUEVO (Picking diurno/nocturno): "notificacion" distinta de "cierre"
|
||||
// (o ausente) es la notificacion preliminar en tiempo real - solo actualiza
|
||||
// estado en HANA (ya hecho arriba), NUNCA debe crear documentos en SAP.
|
||||
// Default seguro: cualquier valor que no sea "cierre" exacto cae aca.
|
||||
if (!string.Equals(entidad.Notificacion, "cierre", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(entidad.DocEntry, entidad.NumOrden, "Estado actualizado correctamente", entidad);
|
||||
}
|
||||
if(TotalDetalle == TotalDetalle_Completo && entidad.IdTipoDoc != 9)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(entidad.DocEntry, entidad.NumOrden, "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
#region PROCESO DE NOTA DE CREDITO
|
||||
|
||||
if (entidad.Proceso.ToUpper() == "DESPACHO" && (entidad.IdEstadoCubico == 6 || entidad.IdEstadoCubico == 5))
|
||||
{
|
||||
if (entidad.IdTipoDoc != 9)
|
||||
{
|
||||
CreditNotesRepository _creditNotesRepository = new CreditNotesRepository(_clientFactory, _configuration, context);
|
||||
BE_CreditNotesNotes creditNotesNotes = new BE_CreditNotesNotes
|
||||
{
|
||||
DocObjectCode = "oCreditNotes",
|
||||
DocumentLines = new List<BE_CreditNotesLine>()
|
||||
};
|
||||
|
||||
InvoiceRepository invoicestRepository = new InvoiceRepository(_clientFactory, _configuration, context);
|
||||
BE_ResultadoTransaccion<BE_InvoicesConsulta> response_invoicesRepository = invoicestRepository.GetInvoice(entidad.DocEntry).Result;
|
||||
|
||||
if (response_invoicesRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Factura no se encuentra", entidad);
|
||||
}
|
||||
|
||||
|
||||
BE_InvoicesConsulta _invoices = response_invoicesRepository.ListData.FirstOrDefault();
|
||||
|
||||
if (_invoices.DocumentStatus != "bost_Open")
|
||||
{
|
||||
var Response_Reopen = invoicestRepository.ReOpen(_invoices.DocEntry).Result;
|
||||
if (Response_Reopen.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Factura no se puede reabrir", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
string Serie = _invoices.U_SYP_MDTD == "03" ? "BC10" : "FC10";
|
||||
string Correlativo = HelperCorrelativo.Get(Serie);
|
||||
creditNotesNotes.DocCurrency = _invoices.DocCurrency;
|
||||
creditNotesNotes.CardCode = _invoices.CardCode;
|
||||
creditNotesNotes.CardName = _invoices.CardName;
|
||||
creditNotesNotes.PaymentGroupCode = _invoices.PaymentGroupCode;
|
||||
creditNotesNotes.DocDate = DateTime.Now;
|
||||
creditNotesNotes.DocDueDate = DateTime.Now;
|
||||
creditNotesNotes.U_SYP_MDTO = _invoices.U_SYP_MDTD;
|
||||
creditNotesNotes.U_SYP_MDCO = _invoices.U_SYP_MDCD;
|
||||
creditNotesNotes.U_SYP_MDSO = _invoices.U_SYP_MDSD;
|
||||
creditNotesNotes.U_SYP_MOTNC = DescripcionMotivo;
|
||||
creditNotesNotes.U_SYP_TPONC = MotivoNotaCredito;
|
||||
creditNotesNotes.U_SYP_MDCD = Correlativo;
|
||||
creditNotesNotes.U_SYP_MDSD = Serie;
|
||||
creditNotesNotes.U_SYP_MDTD = "07";
|
||||
creditNotesNotes.U_SYP_FECHAREF = _invoices.DocDate.ToString("yyyy-MM-dd");
|
||||
creditNotesNotes.NumAtCard = ("07-" + Serie + "-" + Correlativo);
|
||||
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
var Item = _invoices.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
if (Item.Quantity - x.CantidadPedida > 0)
|
||||
{
|
||||
creditNotesNotes.DocumentLines.Add(new BE_CreditNotesLine()
|
||||
{
|
||||
Currency = _invoices.DocCurrency,
|
||||
BatchNumbers = new List<BE_CreditNotesBatchNumbers>(),
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = Item.Quantity - x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 13,
|
||||
LineNum = x.Item,
|
||||
U_ITC_ALMDES = ((Almacen == "ALMPRO") ? Item.WarehouseCode : Almacen),
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// == REALIZA DISTRIBUCION DE STOCK POR LOTE / ALMACEN
|
||||
creditNotesNotes.DocumentLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
//List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.CodigoAlmacen);
|
||||
var ReferenciaFactura = _invoices.DocumentLines.FirstOrDefault(t => t.LineNum == line.LineNum);
|
||||
var ListaStock = _invoices.DocumentLines.FirstOrDefault(InvoiceLine => InvoiceLine.LineNum == ReferenciaFactura.BaseLine).BatchNumbers;
|
||||
|
||||
double CantidadPendiente = (double)line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock;
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.Quantity >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.BatchNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.Quantity < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.BatchNumber, Quantity = Lote.Quantity });
|
||||
CantidadPendiente -= Lote.Quantity;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#endregion
|
||||
});
|
||||
|
||||
if (creditNotesNotes.DocumentLines.Count > 0)
|
||||
{
|
||||
var result_creditNotesRepository = _creditNotesRepository.SetCreateCreditNotes(creditNotesNotes).Result;
|
||||
|
||||
if (result_creditNotesRepository.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_creditNotesRepository.Message.ToString(), entidad);
|
||||
}
|
||||
else
|
||||
{
|
||||
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>();
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>();
|
||||
ListaUnicaArticulo.ForEach(x =>
|
||||
{
|
||||
var ListLote = new List<BE_StockTransferLineBatchNumber>();
|
||||
ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).FirstOrDefault().BatchNumbers.ForEach(r =>
|
||||
{
|
||||
ListLote.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = r.BatchNumber,
|
||||
Quantity = 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
|
||||
});
|
||||
|
||||
|
||||
//=== AGREGA DOCUMENTO REFERENCIA
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>
|
||||
{
|
||||
new BE_StockTransferDocumentReferences()
|
||||
{
|
||||
RefDocEntr = (int)result_creditNotesRepository.Data.DocEntry,
|
||||
RefObjType = "rot_SalesCreditNote",
|
||||
IssueDate = DateTime.Now,
|
||||
Remark = "Nota de Credito",
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(_clientFactory, _configuration);
|
||||
var ResultTransfer = stockTransferRepository.StockTransfer(Transfer).Result;
|
||||
if (ResultTransfer.StatusCode == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ListDocEntry.Add((int)ResultTransfer.Data.DocEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
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, (int)result_creditNotesRepository.Data.DocEntry).Result;
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_creditNotesRepository.Data.DocEntry, result_creditNotesRepository.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado((int)entidad.DocEntry, entidad.NumOrden.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//=== ASIGNA PRECIO PROMEDIO
|
||||
foreach (var x in entidad.Detalle)
|
||||
{
|
||||
var Stock = HelperStock.GetConsolidado(x.CodigoArticulo, entidad.CodigoAlmacen);
|
||||
if (Stock.Count == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("No existe stock disponible para el articulo " + x.CodigoArticulo, entidad);
|
||||
}
|
||||
x.PrecioPromedio = Stock.FirstOrDefault().AvgPrice;
|
||||
};
|
||||
|
||||
GlobalDataRepository globalDataRepository = new GlobalDataRepository(_clientFactory, _configuration, context);
|
||||
|
||||
var Data_SolicitudSalida = globalDataRepository.GetSolicitudSalida(entidad.DocEntry).Result.ListData.FirstOrDefault();
|
||||
|
||||
InventoryGenExitsRepository inventoryGenExitsRepository = new InventoryGenExitsRepository(_clientFactory, _configuration, context);
|
||||
BE_InventoryGenExits _InventoryGenExits = new BE_InventoryGenExits()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenExit",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenExitsLine>(),
|
||||
U_SYP_TPOSALME = Data_SolicitudSalida.U_ITC_MDTS,
|
||||
U_ITC_WMS_NUMINV = "",
|
||||
U_ARD_PERSOLIC = Data_SolicitudSalida.U_ITC_USRSOL,
|
||||
Comments = Data_SolicitudSalida.U_ITC_MDCM
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad.Detalle.ForEach(detalle =>
|
||||
{
|
||||
_InventoryGenExits.DocumentLines.Add(new BE_InventoryGenExitsLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = Data_SolicitudSalida.ITCA_SOLSALMERDETCollection.FirstOrDefault(item_s => item_s.LineId == detalle.Item).U_ITC_ItemName,
|
||||
Quantity = (double)detalle.CantidadPedida,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = detalle.PrecioPromedio,
|
||||
LineTotal = detalle.PrecioPromedio * (double)detalle.CantidadPedida,
|
||||
WarehouseCode = entidad.CodigoAlmacen,
|
||||
AccountCode = Data_SolicitudSalida.ITCA_SOLSALMERDETCollection.FirstOrDefault(item_s => item_s.LineId == detalle.Item).U_ITC_AccCode,
|
||||
BatchNumbers = new List<BE_InventoryGenExitsBatchNumbers>(),
|
||||
CostingCode = Data_SolicitudSalida.ITCA_SOLSALMERDETCollection.FirstOrDefault(item_s => item_s.LineId == detalle.Item).U_ITC_CCOST,
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
|
||||
_InventoryGenExits.DocumentLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, entidad.CodigoAlmacen);
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
var cantidadStock = ListaStock.Sum(x => x.OnHandQty);
|
||||
if (cantidadStock < line.Quantity)
|
||||
{
|
||||
throw new Exception($"El producto {line.ItemCode} no cuenta con stock suficiente");
|
||||
}
|
||||
else
|
||||
{
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_InventoryGenExitsBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = Lote.OnHandQty });
|
||||
CantidadPendiente -= Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
|
||||
var Result = inventoryGenExitsRepository.SetCreateInventoryGenExits(_InventoryGenExits, false).Result;
|
||||
if (Result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(Result.Message.ToString(), entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)entidad.DocEntry, entidad.NumOrden.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
if (entidad.Proceso.ToUpper() == "PICKING" && entidad.IdEstadoCubico == 13)
|
||||
{
|
||||
CreditNotesRepository _creditNotesRepository = new CreditNotesRepository(_clientFactory, _configuration, context);
|
||||
BE_CreditNotesNotes creditNotesNotes = new BE_CreditNotesNotes
|
||||
{
|
||||
DocObjectCode = "oCreditNotes",
|
||||
DocumentLines = new List<BE_CreditNotesLine>()
|
||||
};
|
||||
|
||||
InvoiceRepository invoicestRepository = new InvoiceRepository(_clientFactory, _configuration, context);
|
||||
BE_ResultadoTransaccion<BE_InvoicesConsulta> response_invoicesRepository = invoicestRepository.GetInvoice(entidad.DocEntry).Result;
|
||||
|
||||
if (response_invoicesRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Factura no se encuentra", entidad);
|
||||
}
|
||||
BE_InvoicesConsulta _invoices = response_invoicesRepository.ListData.FirstOrDefault();
|
||||
|
||||
if (_invoices.DocumentStatus != "bost_Open")
|
||||
{
|
||||
var Response_Reopen = invoicestRepository.ReOpen(_invoices.DocEntry).Result;
|
||||
if (Response_Reopen.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Factura no se puede reabrir", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
string Serie = _invoices.U_SYP_MDTD == "03" ? "BC10" : "FC10";
|
||||
string Correlativo = HelperCorrelativo.Get(Serie);
|
||||
|
||||
creditNotesNotes.DocCurrency = _invoices.DocCurrency;
|
||||
creditNotesNotes.CardCode = _invoices.CardCode;
|
||||
creditNotesNotes.CardName = _invoices.CardName;
|
||||
creditNotesNotes.PaymentGroupCode = _invoices.PaymentGroupCode;
|
||||
creditNotesNotes.DocDate = DateTime.Now;
|
||||
creditNotesNotes.DocDueDate = DateTime.Now;
|
||||
creditNotesNotes.U_SYP_MDTO = _invoices.U_SYP_MDTD;
|
||||
creditNotesNotes.U_SYP_MDCO = _invoices.U_SYP_MDCD;
|
||||
creditNotesNotes.U_SYP_MDSO = _invoices.U_SYP_MDSD;
|
||||
creditNotesNotes.U_SYP_MOTNC = DescripcionMotivo;
|
||||
creditNotesNotes.U_SYP_TPONC = MotivoNotaCredito;
|
||||
creditNotesNotes.U_SYP_MDCD = Correlativo;
|
||||
creditNotesNotes.U_SYP_MDSD = Serie;
|
||||
creditNotesNotes.U_SYP_MDTD = "07";
|
||||
creditNotesNotes.U_SYP_FECHAREF = _invoices.DocDate.ToString("yyyy-MM-dd");
|
||||
creditNotesNotes.NumAtCard = ("07-" + Serie+ "-" + Correlativo);
|
||||
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
var Item = _invoices.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
creditNotesNotes.DocumentLines.Add(new BE_CreditNotesLine()
|
||||
{
|
||||
Currency = _invoices.DocCurrency,
|
||||
BatchNumbers = new List<BE_CreditNotesBatchNumbers>(),
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = Item.Quantity - x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 13,
|
||||
LineNum = x.Item,
|
||||
U_ITC_ALMDES = ((Almacen == "ALMPRO") ? Item.WarehouseCode : Almacen),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var _Invoice = response_invoicesRepository.ListData.FirstOrDefault();
|
||||
creditNotesNotes.DocumentLines.ForEach(line =>
|
||||
{
|
||||
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"), Quantity = (double)line.Quantity });
|
||||
});
|
||||
|
||||
if (creditNotesNotes.DocumentLines.Count > 0)
|
||||
{
|
||||
var result_creditNotesRepository = _creditNotesRepository.SetCreateCreditNotes(creditNotesNotes).Result;
|
||||
if (result_creditNotesRepository.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_creditNotesRepository.Message.ToString(), entidad);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
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.DueDate = creditNotesNotes.DocDueDate;
|
||||
Transfer.U_SYP_MDTS = "TSI";
|
||||
Transfer.U_SYP_MDMT = "24";
|
||||
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>();
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>();
|
||||
|
||||
ListaUnicaArticulo.ForEach(x =>
|
||||
{
|
||||
var ListLote = new List<BE_StockTransferLineBatchNumber>();
|
||||
ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).FirstOrDefault().BatchNumbers.ForEach(r =>
|
||||
{
|
||||
ListLote.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = r.BatchNumber,
|
||||
Quantity = 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
|
||||
});
|
||||
|
||||
//=== AGREGA DOCUMENTO REFERENCIA
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>
|
||||
{
|
||||
new BE_StockTransferDocumentReferences()
|
||||
{
|
||||
RefDocEntr = (int)result_creditNotesRepository.Data.DocEntry,
|
||||
RefObjType = "rot_SalesCreditNote",
|
||||
IssueDate = DateTime.Now,
|
||||
Remark = "Nota de Credito",
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(_clientFactory, _configuration);
|
||||
var ResultTransfer = stockTransferRepository.StockTransfer(Transfer).Result;
|
||||
if (ResultTransfer.StatusCode == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ListDocEntry.Add((int)ResultTransfer.Data.DocEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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, (int)result_creditNotesRepository.Data.DocEntry).Result;
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_creditNotesRepository.Data.DocEntry, result_creditNotesRepository.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado((int)entidad.DocEntry, entidad.NumOrden.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
if(entidad.Proceso.ToUpper() == "ULTIMA MILLA" && entidad.IdEstadoCubico == 23)
|
||||
{
|
||||
if(Proceso.U_ITCA_GNRPROC == "SOLICITUD DEV" && !Reproceso)
|
||||
{
|
||||
|
||||
if (string.IsNullOrEmpty(Almacen))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El motivo no tiene asignado un almacen de destino", entidad);
|
||||
}
|
||||
|
||||
ReturnRequestRepository returnRequestRepository = new ReturnRequestRepository(_clientFactory, _configuration);
|
||||
|
||||
InvoiceRepository invoicestRepository = new InvoiceRepository(_clientFactory, _configuration, context);
|
||||
BE_ResultadoTransaccion<BE_InvoicesConsulta> response_invoicesRepository = invoicestRepository.GetInvoice(entidad.DocEntry).Result;
|
||||
|
||||
if (response_invoicesRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Factura no se encuentra", entidad);
|
||||
}
|
||||
BE_InvoicesConsulta invoices = response_invoicesRepository.ListData.FirstOrDefault();
|
||||
BE_ReturnRequest _ReturnRequest = new BE_ReturnRequest()
|
||||
{
|
||||
CardCode = invoices.CardCode,
|
||||
CardName = invoices.CardName,
|
||||
DocCurrency = invoices.DocCurrency,
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
DocObjectCode = "oReturnRequest",
|
||||
PaymentGroupCode = invoices.PaymentGroupCode,
|
||||
U_SYP_MOTNC = DescripcionMotivo,
|
||||
U_SYP_TPONC = MotivoNotaCredito,
|
||||
U_SYP_MDTO = invoices.U_SYP_MDTD,
|
||||
U_SYP_MDCO = invoices.U_SYP_MDCD,
|
||||
U_SYP_MDSO = invoices.U_SYP_MDSD,
|
||||
U_SYP_FECHAREF = invoices.DocDate,
|
||||
DocumentLines = new List<BE_ReturnRequestLine>()
|
||||
};
|
||||
|
||||
var ListaDetalle = entidad.Detalle.Where(x => x.Estado != "C").ToList();
|
||||
ListaDetalle.ForEach(detalle =>
|
||||
{
|
||||
var Detalle_Factura = invoices.DocumentLines.FirstOrDefault(x => x.LineNum == detalle.Item);
|
||||
_ReturnRequest.DocumentLines.Add(new BE_ReturnRequestLine()
|
||||
{
|
||||
LineNum = detalle.Item,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = Detalle_Factura.LineNum,
|
||||
BatchNumbers = new List<BE_ReturnRequestBatchNumbers>(),
|
||||
Currency = invoices.DocCurrency,
|
||||
ItemCode = Detalle_Factura.ItemCode,
|
||||
ItemDescription = Detalle_Factura.ItemDescription,
|
||||
PriceAfterVAT = Detalle_Factura.PriceAfterVAT,
|
||||
Quantity = (Detalle_Factura.Quantity - detalle.CantidadPedida),
|
||||
WarehouseCode = Detalle_Factura.WarehouseCode,
|
||||
BaseType = 13,
|
||||
U_ITC_ALMDES = ((Almacen == "ALMPRO") ? Detalle_Factura.WarehouseCode: Almacen),
|
||||
});
|
||||
});
|
||||
|
||||
var _returnRequestRepository_Result = returnRequestRepository.SetCreateReturnRequest(_ReturnRequest).Result;
|
||||
if (_returnRequestRepository_Result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(_returnRequestRepository_Result.Message.ToString(), entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)_returnRequestRepository_Result.Data.DocEntry, _returnRequestRepository_Result.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
return resultadoTransaccion.GetInformacionResultado(entidad.DocEntry, entidad.NumOrden, "Registrado Correctamente", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), entidad);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> CreateHojaRuta(BE_HojaRutaEntities entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
if (entidad.DocEntry == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El campo docEntry no puede ser cero o vacio", entidad);
|
||||
}
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(entidad.Proceso))
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Se necesita definir el proceso para continuar con el proceso.", entidad);
|
||||
}
|
||||
|
||||
if (entidad.IdEstadoCubico == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Se necesita indicar el IdEstado Cubico para continuar con el proceso.", entidad);
|
||||
}
|
||||
|
||||
int Existe = HelperProcesoPermitido.Get(entidad.Proceso, entidad.IdEstadoCubico, "HOJARUTA", out List<BE_ProcesoPicking> ListaProceso);
|
||||
if (Existe == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("El Proceso y estado no se encuentra configurado para este EndPoint", entidad);
|
||||
}
|
||||
|
||||
HelperProcesoPiciking.Set(entidad.Proceso, entidad.IdEstadoCubico, entidad.DocEntry, HelperProcesoPermitido.ConvertTimeToInteger(entidad.HoraInicio), HelperProcesoPermitido.ConvertTimeToInteger(entidad.FinRuta), entidad.CodMotivo, ListaProceso.FirstOrDefault().Code);
|
||||
if (entidad.Proceso == "Picking")
|
||||
{
|
||||
//=== IDENTIFICA DESCRIPCION DE ESTADO
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(entidad.DocEntry, entidad.DocEntry.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), entidad);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> CerrarHojaRuta(int docEntry)
|
||||
{
|
||||
_metodoName = "CerrarHojaRuta";
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
try
|
||||
{
|
||||
// Hoja de Ruta es un UDO en SAP (ARD_PHR) - mismo patron que
|
||||
// SolicitudTransferencia/{docEntry}/cerrar (POST {recurso}({docEntry})/Close).
|
||||
var connectServiceLayer = new ConnectionServiceLayer(_configuration, _clientFactory);
|
||||
await connectServiceLayer.PostActionAsync($"ARD_PHR({docEntry})/Close");
|
||||
return resultadoTransaccion.GetInformacionResultado(docEntry, docEntry.ToString(), "Cerrado Correctamente", (object)null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), (object)null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.WMS.Recibo;
|
||||
using Net.Connection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Recibo
|
||||
{
|
||||
public interface IReciboRepository : IRepositoryBase<object>
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> Create(BE_ReciboRequest entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.ServicesLayer;
|
||||
using Net.Business.Entities.ServicesLayer.CreditNotes;
|
||||
using Net.Business.Entities.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Business.Entities.ServicesLayer.Invoices;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseDeliveryNotes;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseInvoices;
|
||||
using Net.Business.Entities.ServicesLayer.PurchaseOrders;
|
||||
using Net.Business.Entities.ServicesLayer.ReturnRequest;
|
||||
using Net.Business.Entities.ServicesLayer.StockTransfer;
|
||||
using Net.Business.Entities.WMS.Recibo;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData.Correlativo;
|
||||
using Net.Data.HelperData.Stock;
|
||||
using Net.Data.ServicesLayer;
|
||||
using Net.Data.ServicesLayer.CreditNotes;
|
||||
using Net.Data.ServicesLayer.GlobalData;
|
||||
using Net.Data.ServicesLayer.InventoryGenEntries;
|
||||
using Net.Data.ServicesLayer.ReturnRequest;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using Net.Data.WMS.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Recibo
|
||||
{
|
||||
public class ReciboRepository : RepositoryBase<object>, IReciboRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
public ReciboRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
_aplicacionName = GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> Create(BE_ReciboRequest entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
return await Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
//=== INICIALIZA OBJETO DE SAP
|
||||
PurchaseDeliveryNotesRepository _purchaseDeliveryNotes = new PurchaseDeliveryNotesRepository(_clientFactory, _configuration);
|
||||
CreditNotesRepository _creditNotesRepository = new CreditNotesRepository(_clientFactory, _configuration, context);
|
||||
|
||||
BusinessPartnersRepository businessPartnersRepository = new BusinessPartnersRepository(_clientFactory, _configuration, context);
|
||||
var response_businessPartnersRepository = await businessPartnersRepository.GetBusinessPartnersByFilter(new FE_BusinessPartners()
|
||||
{
|
||||
CardCode = entidad.CodigoERPProveedor
|
||||
});
|
||||
|
||||
if (response_businessPartnersRepository.ListData.Count() == 0)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: El Proveedor no se encuentra registrado en SAP", entidad);
|
||||
}
|
||||
|
||||
#region PROCESO POR COMPRA DE IMPORTACION
|
||||
|
||||
if (entidad.IdTipo == EnumRecibo.IMPORTACION)
|
||||
{
|
||||
//=== INICIALIZA OBJETO DE SAP
|
||||
BE_PurchaseDeliveryNotes purchaseDeliveryNotes = new BE_PurchaseDeliveryNotes
|
||||
{
|
||||
DocObjectCode = "oPurchaseDeliveryNotes",
|
||||
DocumentLines = new List<BE_PurchaseDeliveryNotesLine>()
|
||||
};
|
||||
|
||||
if (entidad.IdTipoDoc == EnumRecibo.IMPORTACION_ORDEN)
|
||||
{
|
||||
PurchaseInvoicesRepository purchaseInvoicesRepository = new PurchaseInvoicesRepository(_clientFactory, _configuration);
|
||||
BE_ResultadoTransaccion<BE_PurchaseInvoices> response_purchaseInvoicesRepository = purchaseInvoicesRepository.GetPurchaseInvoices(entidad.DocEntry).Result;
|
||||
if (response_purchaseInvoicesRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Factura de reserva por importaciones no se encuentra", entidad);
|
||||
}
|
||||
|
||||
BE_PurchaseInvoices purchaseOrders = response_purchaseInvoicesRepository.ListData.FirstOrDefault();
|
||||
purchaseDeliveryNotes.DocCurrency = purchaseOrders.DocCurrency;
|
||||
purchaseDeliveryNotes.CardCode = purchaseOrders.CardCode;
|
||||
purchaseDeliveryNotes.CardName = purchaseOrders.CardName;
|
||||
purchaseDeliveryNotes.PaymentGroupCode = purchaseOrders.PaymentGroupCode;
|
||||
purchaseDeliveryNotes.DocDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.DocDueDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.NumAtCard = entidad.DocImportacion;
|
||||
purchaseDeliveryNotes.U_SYP_MDCD = entidad.U_SYP_MDCD;
|
||||
purchaseDeliveryNotes.U_SYP_MDSD = entidad.U_SYP_MDSD;
|
||||
purchaseDeliveryNotes.U_SYP_MDTD = entidad.U_SYP_MDTD;
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
if (x.CantidadPedida > 0)
|
||||
{
|
||||
var Item = purchaseOrders.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
purchaseDeliveryNotes.DocumentLines.Add(new BE_PurchaseDeliveryNotesLine()
|
||||
{
|
||||
Currency = purchaseOrders.DocCurrency,
|
||||
BatchNumbers = new List<BE_PurchaseDeliveryNotesBatchNumbers>
|
||||
{
|
||||
new BE_PurchaseDeliveryNotesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (int)x.CantidadPedida
|
||||
},
|
||||
},
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = (double)x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 18,
|
||||
LineNum = x.Item,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var result_purchaseDeliveryNotes = _purchaseDeliveryNotes.SetCreatePurchaseDeliveryNotes(purchaseDeliveryNotes).Result;
|
||||
if (result_purchaseDeliveryNotes.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_purchaseDeliveryNotes.Message, entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_purchaseDeliveryNotes.Data.DocEntry, result_purchaseDeliveryNotes.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
if (entidad.IdTipoDoc == EnumRecibo.IMPORTACION_ORDEN_COMPRA)
|
||||
{
|
||||
PurchaseOrdersRepository purchaseOrdersRepository = new PurchaseOrdersRepository(_clientFactory, _configuration);
|
||||
BE_ResultadoTransaccion<BE_PurchaseOrders> response_purchaseOrdersRepository = purchaseOrdersRepository.GetPurchaseInvoices(entidad.DocEntry).Result;
|
||||
|
||||
if (response_purchaseOrdersRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Orden de Compra no se encuentra", entidad);
|
||||
}
|
||||
|
||||
BE_PurchaseOrders purchaseOrders = response_purchaseOrdersRepository.ListData.FirstOrDefault();
|
||||
purchaseDeliveryNotes.DocCurrency = purchaseOrders.DocCurrency;
|
||||
purchaseDeliveryNotes.CardCode = purchaseOrders.CardCode;
|
||||
purchaseDeliveryNotes.CardName = purchaseOrders.CardName;
|
||||
purchaseDeliveryNotes.PaymentGroupCode = purchaseOrders.PaymentGroupCode;
|
||||
purchaseDeliveryNotes.DocDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.DocDueDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.NumAtCard = entidad.DocImportacion;
|
||||
purchaseDeliveryNotes.U_SYP_MDCD = entidad.U_SYP_MDCD;
|
||||
purchaseDeliveryNotes.U_SYP_MDSD = entidad.U_SYP_MDSD;
|
||||
purchaseDeliveryNotes.U_SYP_MDTD = entidad.U_SYP_MDTD;
|
||||
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
var Item = purchaseOrders.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
purchaseDeliveryNotes.DocumentLines.Add(new BE_PurchaseDeliveryNotesLine()
|
||||
{
|
||||
Currency = purchaseOrders.DocCurrency,
|
||||
BatchNumbers = new List<BE_PurchaseDeliveryNotesBatchNumbers>
|
||||
{
|
||||
new BE_PurchaseDeliveryNotesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (int)x.CantidadPedida
|
||||
},
|
||||
},
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = (double)x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 22,
|
||||
LineNum = x.Item
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var result_purchaseDeliveryNotes = _purchaseDeliveryNotes.SetCreatePurchaseDeliveryNotes(purchaseDeliveryNotes).Result;
|
||||
if (result_purchaseDeliveryNotes.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_purchaseDeliveryNotes.Message, entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_purchaseDeliveryNotes.Data.DocEntry, result_purchaseDeliveryNotes.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
if (entidad.IdTipoDoc == EnumRecibo.IMPORTACION_SOL_ENTRADA)
|
||||
{
|
||||
GlobalDataRepository globalDataRepository = new GlobalDataRepository(_clientFactory, _configuration, context);
|
||||
var Result_globalDataRepository = globalDataRepository.GetSolicitudIngreso(entidad.DocEntry).Result.ListData.FirstOrDefault();
|
||||
|
||||
BE_InventoryGenEntries _InventoryGenEntries = new BE_InventoryGenEntries()
|
||||
{
|
||||
DocObjectCode = "oInventoryGenEntry",
|
||||
DocDate = DateTime.Now,
|
||||
DocDueDate = DateTime.Now,
|
||||
PaymentGroupCode = "-2",
|
||||
DocCurrency = "S/",
|
||||
DocRate = 1,
|
||||
DocumentLines = new List<BE_InventoryGenEntriesLine>(),
|
||||
U_SYP_TPOENTME = Result_globalDataRepository.U_ITC_MDTI,
|
||||
U_ITC_WMS_NUMINV = "",
|
||||
U_ARD_PERSOLIC = Result_globalDataRepository.U_ITC_USRSOL,
|
||||
Comments = Result_globalDataRepository.U_ITC_MDCM
|
||||
};
|
||||
|
||||
int LineNum = 0;
|
||||
entidad.Detalle.ForEach(detalle =>
|
||||
{
|
||||
var LineaDetalle = Result_globalDataRepository.ITC_SOLINGMERDETCollection.FirstOrDefault(x => x.LineId == detalle.Item);
|
||||
|
||||
var Precio = HelperStock.GetConsolidado(detalle.CodigoArticulo, Result_globalDataRepository.U_ITC_MDWC).FirstOrDefault().AvgPrice;
|
||||
|
||||
_InventoryGenEntries.DocumentLines.Add(new BE_InventoryGenEntriesLine()
|
||||
{
|
||||
Currency = "S/",
|
||||
ItemCode = detalle.CodigoArticulo,
|
||||
ItemDescription = LineaDetalle.U_ITC_ITEMNAME,
|
||||
Quantity = (double)detalle.CantidadPedida,
|
||||
LineNum = LineNum,
|
||||
PriceAfterVAT = Precio,
|
||||
LineTotal = Precio * (double)detalle.CantidadPedida,
|
||||
WarehouseCode = Result_globalDataRepository.U_ITC_MDWC,
|
||||
AccountCode = LineaDetalle.U_ITC_ACCCODE,
|
||||
CostingCode = LineaDetalle.U_ITC_CCOSTO ?? "",
|
||||
BatchNumbers = new List<BE_InventoryGenEntriesBatchNumbers>()
|
||||
{
|
||||
new BE_InventoryGenEntriesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (double)detalle.CantidadPedida
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LineNum++;
|
||||
});
|
||||
|
||||
InventoryGenEntriesRepository inventoryGenEntries = new InventoryGenEntriesRepository(_clientFactory, _configuration, context);
|
||||
var inventoryGenEntries_result = inventoryGenEntries.SetCreateInventoryGenEntries(_InventoryGenEntries, false).Result;
|
||||
if (inventoryGenEntries_result.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(inventoryGenEntries_result.Message.ToString(), entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)inventoryGenEntries_result.Data.DocEntry, inventoryGenEntries_result.Data.DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PROCESO POR COMPRA NACIONAL
|
||||
|
||||
if (entidad.IdTipo == EnumRecibo.NACIONAL)
|
||||
{
|
||||
//=== INICIALIZA OBJETO DE SAP
|
||||
BE_PurchaseDeliveryNotes purchaseDeliveryNotes = new BE_PurchaseDeliveryNotes
|
||||
{
|
||||
DocObjectCode = "oPurchaseDeliveryNotes",
|
||||
DocumentLines = new List<BE_PurchaseDeliveryNotesLine>()
|
||||
};
|
||||
|
||||
PurchaseOrdersRepository purchaseOrdersRepository = new PurchaseOrdersRepository(_clientFactory, _configuration);
|
||||
BE_ResultadoTransaccion<BE_PurchaseOrders> response_purchaseOrdersRepository = purchaseOrdersRepository.GetPurchaseInvoices(entidad.DocEntry).Result;
|
||||
|
||||
if (response_purchaseOrdersRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Orden de Compra no se encuentra", entidad);
|
||||
}
|
||||
|
||||
BE_PurchaseOrders purchaseOrders = response_purchaseOrdersRepository.ListData.FirstOrDefault();
|
||||
purchaseDeliveryNotes.DocCurrency = purchaseOrders.DocCurrency;
|
||||
purchaseDeliveryNotes.CardCode = purchaseOrders.CardCode;
|
||||
purchaseDeliveryNotes.CardName = purchaseOrders.CardName;
|
||||
purchaseDeliveryNotes.PaymentGroupCode = purchaseOrders.PaymentGroupCode;
|
||||
purchaseDeliveryNotes.DocDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.DocDueDate = DateTime.Now;
|
||||
purchaseDeliveryNotes.NumAtCard = entidad.DocImportacion;
|
||||
purchaseDeliveryNotes.U_SYP_MDCD = entidad.U_SYP_MDCD;
|
||||
purchaseDeliveryNotes.U_SYP_MDSD = entidad.U_SYP_MDSD;
|
||||
purchaseDeliveryNotes.U_SYP_MDTD = entidad.U_SYP_MDTD;
|
||||
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
var Item = purchaseOrders.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
purchaseDeliveryNotes.DocumentLines.Add(new BE_PurchaseDeliveryNotesLine()
|
||||
{
|
||||
Currency = purchaseOrders.DocCurrency,
|
||||
BatchNumbers = new List<BE_PurchaseDeliveryNotesBatchNumbers>
|
||||
{
|
||||
new BE_PurchaseDeliveryNotesBatchNumbers()
|
||||
{
|
||||
BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"),
|
||||
Quantity = (int)x.CantidadPedida
|
||||
},
|
||||
},
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = (double)x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 22,
|
||||
LineNum = x.Item
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var result_purchaseDeliveryNotes = _purchaseDeliveryNotes.SetCreatePurchaseDeliveryNotes(purchaseDeliveryNotes).Result;
|
||||
if (result_purchaseDeliveryNotes.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_purchaseDeliveryNotes.Message, entidad);
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_purchaseDeliveryNotes.Data.DocEntry, result_purchaseDeliveryNotes.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PROCESO DE NOTA DE CREDITO
|
||||
|
||||
if (entidad.IdTipo == EnumRecibo.DEVOLUCION)
|
||||
{
|
||||
BE_CreditNotesNotes creditNotesNotes = new BE_CreditNotesNotes
|
||||
{
|
||||
DocObjectCode = "oCreditNotes",
|
||||
DocumentLines = new List<BE_CreditNotesLine>()
|
||||
};
|
||||
|
||||
ReturnRequestRepository returnRequestRepository = new ReturnRequestRepository(_clientFactory, _configuration);
|
||||
BE_ResultadoTransaccion<BE_ReturnRequest> response_purchaseOrdersRepository = returnRequestRepository.GetRequestReturn(entidad.DocEntry).Result;
|
||||
|
||||
if (response_purchaseOrdersRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: Solicitud de Devolucion no se encuentra", entidad);
|
||||
}
|
||||
|
||||
BE_ReturnRequest returnRequest = response_purchaseOrdersRepository.ListData.FirstOrDefault();
|
||||
|
||||
#region OBTIENE FACTURAS RELACIONADA A LA SOLICITUD DE DEVOLUCION
|
||||
|
||||
List<int> ListaDocEntryFactura = returnRequest.DocumentLines.Select(x => !x.BaseEntry.HasValue? 0: x.BaseEntry.Value).Distinct().Where(x => x > 0).ToList();
|
||||
BE_InvoicesConsulta _Invoice = null;
|
||||
ListaDocEntryFactura.ForEach(DocEntry =>
|
||||
{
|
||||
var _InvoiceRepository = new InvoiceRepository(_clientFactory, _configuration, context);
|
||||
|
||||
var _Invoice_Result = _InvoiceRepository.GetInvoice(DocEntry).Result;
|
||||
if (_Invoice_Result.ListData.Count() > 0)
|
||||
{
|
||||
_Invoice = _Invoice_Result.ListData.FirstOrDefault();
|
||||
}
|
||||
});
|
||||
string SerieOrigen = "";
|
||||
string U_SYP_MDTO = "";
|
||||
string U_SYP_MDCO = "";
|
||||
string U_SYP_MDSO = "";
|
||||
DateTime DocDate;
|
||||
|
||||
if (_Invoice == null)
|
||||
{
|
||||
SerieOrigen = returnRequest.U_SYP_MDSO;
|
||||
U_SYP_MDTO = returnRequest.U_SYP_MDTO;
|
||||
U_SYP_MDCO = returnRequest.U_SYP_MDCO;
|
||||
U_SYP_MDSO = returnRequest.U_SYP_MDSO;
|
||||
DocDate = returnRequest.U_SYP_FECHAREF;
|
||||
}
|
||||
else
|
||||
{
|
||||
SerieOrigen = _Invoice.U_SYP_MDSD;
|
||||
U_SYP_MDTO = _Invoice.U_SYP_MDTD;
|
||||
U_SYP_MDCO = _Invoice.U_SYP_MDCD;
|
||||
U_SYP_MDSO = _Invoice.U_SYP_MDSD;
|
||||
DocDate = _Invoice.DocDate;
|
||||
}
|
||||
|
||||
#endregion
|
||||
string Serie = SerieOrigen == "03" ? "BC10" : "FC10";
|
||||
string Correlativo = HelperCorrelativo.Get(Serie);
|
||||
creditNotesNotes.DocCurrency = returnRequest.DocCurrency;
|
||||
creditNotesNotes.CardCode = returnRequest.CardCode;
|
||||
creditNotesNotes.CardName = returnRequest.CardName;
|
||||
creditNotesNotes.PaymentGroupCode = returnRequest.PaymentGroupCode;
|
||||
creditNotesNotes.DocDate = DateTime.Now;
|
||||
creditNotesNotes.DocDueDate = DateTime.Now;
|
||||
//creditNotesNotes.NumAtCard = entidad.DocImportacion;
|
||||
creditNotesNotes.NumAtCard = ("07-" + Serie +"-" + Correlativo);
|
||||
creditNotesNotes.U_SYP_MDTO = U_SYP_MDTO;
|
||||
creditNotesNotes.U_SYP_MDCO = U_SYP_MDCO;
|
||||
creditNotesNotes.U_SYP_MDSO = U_SYP_MDSO;
|
||||
creditNotesNotes.U_SYP_MOTNC = returnRequest.U_SYP_MOTNC;
|
||||
creditNotesNotes.U_SYP_TPONC = returnRequest.U_SYP_TPONC;
|
||||
creditNotesNotes.U_SYP_MDCD = Correlativo;
|
||||
creditNotesNotes.U_SYP_MDSD = Serie;
|
||||
creditNotesNotes.U_SYP_MDTD = "07";
|
||||
creditNotesNotes.U_SYP_FECHAREF = DocDate.ToString("yyyy-MM-dd");
|
||||
entidad.Detalle.ForEach(x =>
|
||||
{
|
||||
var Item = returnRequest.DocumentLines.ToList().FirstOrDefault(t => t.LineNum == x.Item);
|
||||
if (Item != null)
|
||||
{
|
||||
creditNotesNotes.DocumentLines.Add(new BE_CreditNotesLine()
|
||||
{
|
||||
Currency = returnRequest.DocCurrency,
|
||||
BatchNumbers = new List<BE_CreditNotesBatchNumbers>
|
||||
{
|
||||
new BE_CreditNotesBatchNumbers()
|
||||
{
|
||||
BatchNumber = x.LoteProducto,
|
||||
Quantity = (int)x.CantidadPedida
|
||||
},
|
||||
},
|
||||
ItemCode = Item.ItemCode,
|
||||
ItemDescription = Item.ItemDescription,
|
||||
PriceAfterVAT = Item.PriceAfterVAT,
|
||||
Quantity = x.CantidadPedida,
|
||||
WarehouseCode = Item.WarehouseCode,
|
||||
BaseEntry = entidad.DocEntry,
|
||||
BaseLine = x.Item,
|
||||
BaseType = 234000031,
|
||||
LineNum = x.Item
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (_Invoice == null)
|
||||
{
|
||||
//=== REALIZA DISTRIBUCION DE STOCK POR LOTE
|
||||
creditNotesNotes.DocumentLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
var ListaStock = HelperStock.Get(line.ItemCode, line.WarehouseCode);
|
||||
if (ListaStock.Count > 0)
|
||||
{
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= (double)CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = (double)CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < (double)CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.DistNumber, Quantity = (double)Lote.OnHandQty });
|
||||
CantidadPendiente -= (decimal)Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"), Quantity = (double)line.Quantity });
|
||||
}
|
||||
|
||||
#endregion
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
creditNotesNotes.DocumentLines.ForEach(line =>
|
||||
{
|
||||
var ReferenciaFactura = returnRequest.DocumentLines.FirstOrDefault(t => t.LineNum == line.LineNum);
|
||||
var ListaStock = _Invoice.DocumentLines.FirstOrDefault(InvoiceLine => InvoiceLine.LineNum == ReferenciaFactura.BaseLine).BatchNumbers;
|
||||
if (ListaStock.Count > 0)
|
||||
{
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock;
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.Quantity >= (double)CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.BatchNumber, Quantity = (double)CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.Quantity < (double)CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = Lote.BatchNumber, Quantity = (double)Lote.Quantity });
|
||||
CantidadPendiente -= (decimal)Lote.Quantity;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_CreditNotesBatchNumbers() { BatchNumber = DateTime.Now.ToString("yyyyMMddhhmmss"), Quantity = (double)line.Quantity });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var result_creditNotesRepository = _creditNotesRepository.SetCreateCreditNotes(creditNotesNotes).Result;
|
||||
if (result_creditNotesRepository.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(result_creditNotesRepository.Message, entidad);
|
||||
}
|
||||
else
|
||||
{
|
||||
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.DueDate = creditNotesNotes.DocDueDate;
|
||||
Transfer.U_SYP_MDTS = "TSI";
|
||||
Transfer.U_SYP_MDMT = "24";
|
||||
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>();
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>();
|
||||
|
||||
ListaUnicaArticulo.ForEach(x =>
|
||||
{
|
||||
var ListLote = new List<BE_StockTransferLineBatchNumber>();
|
||||
ListaDetalle_PorAlmacen.Where(t => t.ItemCode == x).FirstOrDefault().BatchNumbers.ForEach(r =>
|
||||
{
|
||||
ListLote.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = r.BatchNumber,
|
||||
Quantity = 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
|
||||
});
|
||||
|
||||
//=== AGREGA DOCUMENTO REFERENCIA
|
||||
Transfer.DocumentReferences = new List<BE_StockTransferDocumentReferences>
|
||||
{
|
||||
new BE_StockTransferDocumentReferences()
|
||||
{
|
||||
RefDocEntr = (int)result_creditNotesRepository.Data.DocEntry,
|
||||
RefObjType = "rot_SalesCreditNote",
|
||||
IssueDate = DateTime.Now,
|
||||
Remark = "Nota de Credito",
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(_clientFactory, _configuration);
|
||||
var ResultTransfer = stockTransferRepository.StockTransfer(Transfer).Result;
|
||||
if (ResultTransfer.StatusCode == -1)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
ListDocEntry.Add((int)ResultTransfer.Data.DocEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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, (int)result_creditNotesRepository.Data.DocEntry).Result;
|
||||
}
|
||||
return resultadoTransaccion.GetInformacionResultado((int)result_creditNotesRepository.Data.DocEntry, result_creditNotesRepository.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
//return resultadoTransaccion.GetInformacionResultado((int)result_creditNotesRepository.Data.DocEntry, result_creditNotesRepository.Data.DocNum.ToString(), "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado(0, "", "Se registro correctamente...!!!", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), entidad);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.WMS.SolicitudTransferencia;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.SolicitudTransferencia
|
||||
{
|
||||
public interface ISolicitudTransferenciaRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> Update(int docEntry, BE_SolicitudTransferenciaPatchRequest entidad);
|
||||
Task<BE_ResultadoTransaccion<object>> Cerrar(int docEntry);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Net.Business.Entities;
|
||||
using Net.Business.Entities.WMS.Transferencia;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Transferencia
|
||||
{
|
||||
public interface ITransferenciaRepository
|
||||
{
|
||||
Task<BE_ResultadoTransaccion<object>> Create(BE_TransferenciaRequest entidad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
using iTextSharp.text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
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.StockTransfer;
|
||||
using Net.Business.Entities.WMS.Transferencia;
|
||||
using Net.Connection;
|
||||
using Net.CrossCotting;
|
||||
using Net.Data.HelperData.Invoices;
|
||||
using Net.Data.HelperData.Stock;
|
||||
using Net.Data.ServicesLayer;
|
||||
using Net.Data.ServicesLayer.StockTransfer;
|
||||
using Sap.Data.Hana;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Net.Data.WMS.Transferencia
|
||||
{
|
||||
public class TransferenciaRepository : RepositoryBase<object>, ITransferenciaRepository
|
||||
{
|
||||
#region Variables Globales
|
||||
private string _aplicacionName;
|
||||
private string _metodoName;
|
||||
private readonly Regex regex = new Regex(@"<(\w+)>.*");
|
||||
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
private readonly IConfiguration _configuration;
|
||||
#endregion
|
||||
|
||||
public TransferenciaRepository(IConnectionSQL context, IHttpClientFactory clientFactory, IConfiguration configuration) : base(context)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
_configuration = configuration;
|
||||
_aplicacionName = GetType().Name;
|
||||
}
|
||||
|
||||
public async Task<BE_ResultadoTransaccion<object>> Create(BE_TransferenciaRequest entidad)
|
||||
{
|
||||
_metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString();
|
||||
|
||||
ResultadoTransaccion<object> resultadoTransaccion = new ResultadoTransaccion<object>(_metodoName, _aplicacionName);
|
||||
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
//=== CREA INSTANCIA PARA CONECTAR A SAP
|
||||
StockTransferRepository stockTransferRepository = new StockTransferRepository(_clientFactory, _configuration);
|
||||
|
||||
BE_StockTransfer StockTransfer = new BE_StockTransfer
|
||||
{
|
||||
DocDate = entidad.FechaOrden,
|
||||
DueDate = entidad.FechaOrden,
|
||||
TaxDate = entidad.FechaOrden,
|
||||
FromWarehouse = entidad.CodigoSubAlmacenOrigen,
|
||||
ToWarehouse = entidad.CodigoSubAlmacenDestino,
|
||||
Comments = "Transferencia Generado desde Cubico - SAP",
|
||||
StockTransferLines = new List<BE_StockTransferLine>()
|
||||
};
|
||||
|
||||
entidad.TransferenciaDetalles.ForEach(x =>
|
||||
{
|
||||
var Detalle = new BE_StockTransferLine
|
||||
{
|
||||
FromWarehouseCode = entidad.CodigoSubAlmacenOrigen,
|
||||
WarehouseCode = entidad.CodigoSubAlmacenDestino,
|
||||
ItemCode = x.CodigoArticulo,
|
||||
Quantity = (double)x.CantidadPedida,
|
||||
BaseLine = entidad.DocEntry == 0 ? null : (int?)x.Item,
|
||||
BaseEntry = entidad.DocEntry == 0 ? null : (int?)entidad.DocEntry,
|
||||
BaseType = entidad.DocEntry == 0 ? null : "InventoryTransferRequest",
|
||||
LineNum = x.Item,
|
||||
BatchNumbers = new List<BE_StockTransferLineBatchNumber>()
|
||||
};
|
||||
StockTransfer.StockTransferLines.Add(Detalle);
|
||||
});
|
||||
|
||||
// == REALIZA DISTRIBUCION DE STOCK POR LOTE / ALMACEN
|
||||
StockTransfer.StockTransferLines.ForEach(line =>
|
||||
{
|
||||
#region CONSULTA A HANA
|
||||
|
||||
List<BE_ItemStock> ListaStock = HelperStock.Get(line.ItemCode, line.FromWarehouseCode);
|
||||
var CantidadPendiente = line.Quantity;
|
||||
var ListOrdenadaFecha = ListaStock.OrderBy(x => x.ExpDate).ToList();
|
||||
ListOrdenadaFecha.ForEach(Lote =>
|
||||
{
|
||||
if (CantidadPendiente > 0)
|
||||
{
|
||||
if (Lote.OnHandQty >= CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber() { BatchNumber = Lote.DistNumber, Quantity = CantidadPendiente });
|
||||
CantidadPendiente = 0;
|
||||
}
|
||||
else if (Lote.OnHandQty < CantidadPendiente)
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber() { BatchNumber = Lote.DistNumber, Quantity = Lote.OnHandQty });
|
||||
CantidadPendiente -= Lote.OnHandQty;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
#endregion
|
||||
});
|
||||
|
||||
//=== SI EL ALMACEN ES ALM99, FUERZA EL AMARRE 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);
|
||||
var _purchaseDeliveryNotesRepository_Response = _purchaseDeliveryNotesRepository.GetPurchaseDeliveryNotes(DocEntry_Entada).Result.ListData.FirstOrDefault();
|
||||
|
||||
//=== RESETEA STOCK POR LOTES
|
||||
StockTransfer.StockTransferLines.ForEach(line =>
|
||||
{
|
||||
var Lines = _purchaseDeliveryNotesRepository_Response.DocumentLines.FirstOrDefault(line_purchaseDeliveryNotesRepository_Response => line_purchaseDeliveryNotesRepository_Response.BaseLine == line.LineNum);
|
||||
line.BatchNumbers = new List<BE_StockTransferLineBatchNumber>();
|
||||
|
||||
//=== AGREGA LOTES
|
||||
Lines.BatchNumbers.ForEach(lotes =>
|
||||
{
|
||||
line.BatchNumbers.Add(new BE_StockTransferLineBatchNumber()
|
||||
{
|
||||
BatchNumber = lotes.BatchNumber,
|
||||
Quantity = lotes.Quantity,
|
||||
});
|
||||
});
|
||||
|
||||
line.BaseLine = Lines.LineNum;
|
||||
line.BaseType = "PurchaseDeliveryNotes";
|
||||
line.BaseEntry = DocEntry_Entada;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var ResultTransaction = stockTransferRepository.StockTransfer(StockTransfer).Result;
|
||||
if (ResultTransaction.StatusCode == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ResultTransaction.Message.ToString(), entidad);
|
||||
}
|
||||
|
||||
// === SOLO SE EJECUTA CUANDO TIENE UN DOCUMENTO BASE [SOLICITUD DE TRASLADO]
|
||||
if (entidad.DocEntry != 0)
|
||||
{
|
||||
var Result_SolicitudTraslado = stockTransferRepository.GetInventoryTransferRequest(entidad.DocEntry).Result;
|
||||
if (Result_SolicitudTraslado.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La solicitud no se encuentra", entidad);
|
||||
}
|
||||
var _SolicitudTraslado = Result_SolicitudTraslado.ListData.FirstOrDefault();
|
||||
|
||||
// === SOLO CIERRA CUANDO EL DOCUMENTO ESTA ABIERTO
|
||||
if (_SolicitudTraslado.DocumentStatus == "bost_Open")
|
||||
{
|
||||
var Response_Close = stockTransferRepository.CloseInventoryTransferRequest(entidad.DocEntry).Result;
|
||||
if (Response_Close.DocEntry == -1)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado("SAP: La Solicitud no se puede cerrar en automatico", entidad);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultadoTransaccion.GetInformacionResultado((int)ResultTransaction.Data.DocEntry, ResultTransaction.Data.DocNum.ToString(), "Registrado Correctamente", entidad);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return resultadoTransaccion.GetInformacionResultado(ex.Message.ToString(), entidad);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user