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> SetCreateInvoices(BE_Invoices entidad) { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); try { var cadena = "Invoices"; var dataResponseInvoice = await _connectServiceLayer.PostAsync(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 // Lee una factura de venta (GET Invoices(docEntry)): cabecera, campos U_SYP_*, lineas con BaseType/BaseEntry/BaseLine y lotes public async Task> GetInvoice(int docEntry) { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); try { string cadena = $"Invoices({docEntry})"; int maxpagesize = 0; List objectList = await _connectServiceLayer.GetAsync(cadena, maxpagesize,true); return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList); } catch (Exception ex) { return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString()); } } // GET DELIVERY NOTE (para obtener los lotes de la entrega origen de una factura) public async Task> GetDeliveryNote(int docEntry) { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); try { string cadena = $"DeliveryNotes({docEntry})"; List objectList = await _connectServiceLayer.GetAsync(cadena, 0, true); return resultadoTransaccion.GetInformacionResultado(0, 0, "Se Listo correctamento...!!!", objectList); } catch (Exception ex) { return resultadoTransaccion.GetInformacionResultado(-1, -1, ex.Message.ToString()); } } // Reabre una factura cerrada (POST Invoices(n)/Reopen); la NC solo se puede crear sobre una factura abierta public async Task> ReOpen(int docEntry) { _metodoName = regex.Match(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name).Groups[1].Value.ToString(); ResultadoTransaccion resultadoTransaccion = new ResultadoTransaccion(_metodoName, _aplicacionName); try { string cadena = $"Invoices({docEntry})/Reopen"; var dataResponseInvoice = await _connectServiceLayer.PostReOpen(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()); } } } }