internal MuertesEnTransitoInfo ObtenerPorFolioEntrada(MuertesEnTransitoInfo filtro) { try { Logger.Info(); Dictionary <string, object> parameters = AuxMuertesEnTransitoDAL.ObtenerParametrosPorFolioEntrada(filtro); DataSet ds = Retrieve("MuertesEnTransito_EntradaGanado_ObtenerPorFolioEntrada", parameters); MuertesEnTransitoInfo result = null; if (ValidateDataSet(ds)) { result = MapMuertesEnTransitoDAL.ObtenerPorFolioEntrada(ds); } return(result); } catch (SqlException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (DataException ex) { Logger.Error(ex); throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
internal static Dictionary <string, object> ObtenerParametrosPorFolioEntrada(MuertesEnTransitoInfo filtro) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@FolioEntrada", filtro.FolioEntrada }, { "@OrganizacionID", filtro.OrganizacionID } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene los aretes de los animales que correspondan al Folio de Entrada y la Organizacion /// </summary> /// <param name="filtro"></param> /// <returns></returns> public List <AnimalInfo> ObtenerAretesPorFolioEntrada(MuertesEnTransitoInfo filtro) { try { Logger.Info(); var muelrtesEnTransitoBl = new MuertesEnTransitoBL(); List <AnimalInfo> result = muelrtesEnTransitoBl.ObtenerAnimalesPorFolioEntrada(filtro); return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
public MemoryStream Guardar(MuertesEnTransitoInfo muerteEnTransito, List <AnimalInfo> animales) { try { Logger.Info(); var muerteEnTransitoBl = new MuertesEnTransitoBL(); MemoryStream result = muerteEnTransitoBl.Guardar(muerteEnTransito, animales); return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene la informacion de la entrada de gandado por Folio de entrada y Organizacion /// </summary> /// <param name="filtro"></param> /// <returns></returns> internal MuertesEnTransitoInfo ObtenerPorFolioEntrada(MuertesEnTransitoInfo filtro) { try { Logger.Info(); var muertesDAL = new MuertesEnTransitoDAL(); MuertesEnTransitoInfo result = muertesDAL.ObtenerPorFolioEntrada(filtro); return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Inicializa los valores de inicio y limpia el formulario. /// </summary> private void InicializarFormulario() { muertesEnTransitoInfoSeleccionado = null; Animales.Clear(); txtFecha.Text = DateTime.Now.ToShortDateString(); txtOrigen.Text = string.Empty; txtTipoOrigen.Text = string.Empty; skAyudaCliente.LimpiarCampos(); txtCorral.Text = string.Empty; txtLote.Text = string.Empty; txtCabezas.Text = string.Empty; txtMuertesEnTransito.Text = string.Empty; txtArete.Text = string.Empty; txtArete.IsEnabled = true; chkSinArete.IsChecked = false; skAyudaFolioEntrada.LimpiarCampos(); skAyudaCliente.IsEnabled = false; dgAretes.Items.Refresh(); InicializarAyudaFolioEntrada(); }
/// <summary> /// Obtiene la informacion de la entrada de gandado por Folio de entrada y Organizacion /// </summary> /// <param name="filtro"></param> /// <returns></returns> public MuertesEnTransitoInfo ObtenerPorFolioEntrada(MuertesEnTransitoInfo filtro) { MuertesEnTransitoInfo muerteEnTransitoInfo; try { Logger.Info(); var muelrtesEnTransitoBl = new MuertesEnTransitoBL(); muerteEnTransitoInfo = muelrtesEnTransitoBl.ObtenerPorFolioEntrada(filtro); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } return(muerteEnTransitoInfo); }
private void deshabilitaControles() { muertesEnTransitoInfoSeleccionado = null; Animales.Clear(); txtFecha.IsEnabled = false; txtOrigen.IsEnabled = false; txtTipoOrigen.IsEnabled = false; skAyudaCliente.IsEnabled = false; txtCorral.IsEnabled = false; txtLote.IsEnabled = false; txtCabezas.IsEnabled = false; txtMuertesEnTransito.IsEnabled = false; txtArete.IsEnabled = false; chkSinArete.IsEnabled = false; //skAyudaFolioEntrada.IsEnabled = false; skAyudaCliente.IsEnabled = false; btnGuardar.IsEnabled = false; btnCancelar.IsEnabled = false; btnAgregarActualizar.IsEnabled = false; btnLimpiar.IsEnabled = false; }
internal static MuertesEnTransitoInfo ObtenerPorFolioEntrada(DataSet ds) { try { Logger.Info(); DataTable dt = ds.Tables[ConstantesDAL.DtDatos]; MuertesEnTransitoInfo entidad = (from info in dt.AsEnumerable() select new MuertesEnTransitoInfo { EntradaGanadoID = info.Field <int>("EntradaGanadoID"), FolioEntrada = info.Field <int>("FolioEntrada"), Origen = info.Field <string>("Origen"), TipoOrigenID = info.Field <int>("TipoOrganizacionID"), TipoOrigen = info.Field <string>("TipoOrigen"), CodigoProveedor = info.Field <string>("CodigoSAP"), Proveedor = info.Field <string>("Proveedor"), CorralID = info.Field <int>("CorralID"), Corral = info.Field <string>("Corral"), LoteID = info.Field <int>("LoteID"), Lote = info.Field <string>("Lote"), Cabezas = info.Field <int>("CabezasRecibidas"), MuertesTransito = info.Field <int>("MuertesEnTransito"), MuertesRegistradas = info.Field <int>("MuertesRegistradas"), CabezasLote = info.Field <int>("Cabezas"), EmbarqueID = info.Field <int>("EmbarqueID") }).First(); return(entidad); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
internal static Dictionary <string, object> ObtenerParametrosPorPagina(PaginacionInfo pagina, MuertesEnTransitoInfo filtro) { try { Logger.Info(); var parametros = new Dictionary <string, object> { { "@FolioEntrada", filtro.Origen }, //Se utiliza para mostrar el campo en el grid y filtrar con el. { "@OrganizacionID", filtro.OrganizacionID }, { "@Inicio", pagina.Inicio }, { "@Limite", pagina.Limite } }; return(parametros); } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene las entradas de ganado con muertes pendientes a registrar en la ayuda Folio de Entrada. /// </summary> /// <param name="pagina"></param> /// <param name="filtro"></param> /// <returns></returns> public ResultadoInfo <MuertesEnTransitoInfo> ObtenerPorPagina(PaginacionInfo pagina, MuertesEnTransitoInfo filtro) { try { Logger.Info(); var muelrtesEnTransitoBl = new MuertesEnTransitoBL(); ResultadoInfo <MuertesEnTransitoInfo> result = muelrtesEnTransitoBl.ObtenerPorPagina(pagina, filtro); return(result); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
internal MemoryStream Guardar(MuertesEnTransitoInfo muerteEnTransito, List <AnimalInfo> animales) { MemoryStream retorno = null; try { Logger.Info(); PolizaAbstract poliza; IList <PolizaInfo> polizaMuerteEnTransito; var entradaGanadoMuerteLista = new List <EntradaGanadoMuerteInfo>(); using (var transaction = new TransactionScope()) { var fecha = DateTime.Now; int organizacionID = muerteEnTransito.OrganizacionID; int usuarioCreacionID = muerteEnTransito.UsuarioCreacionID; int pesoAnimal = 0; int corralID = 0; int loteID = 0; var datosInterface = false; List <InterfaceSalidaAnimalInfo> interfaceSalidaAnimal = null; var entradaGanadoBL = new EntradaGanadoBL(); EntradaGanadoInfo entradaGanado = entradaGanadoBL.ObtenerPorID(muerteEnTransito.EntradaGanadoID); if (entradaGanado != null) { loteID = entradaGanado.LoteID; corralID = entradaGanado.CorralID; if (entradaGanado.FolioOrigen > 0) { var interfaceSalidaBL = new InterfaceSalidaAnimalBL(); interfaceSalidaAnimal = interfaceSalidaBL.ObtenerInterfazSalidaAnimal(entradaGanado.FolioOrigen, entradaGanado.OrganizacionOrigenID); if (interfaceSalidaAnimal == null || interfaceSalidaAnimal.Count <= 0) { fecha = entradaGanado.FechaEntrada; pesoAnimal = Convert.ToInt32((entradaGanado.PesoBruto - entradaGanado.PesoTara) / entradaGanado.CabezasRecibidas); } else { datosInterface = true; } } else { pesoAnimal = Convert.ToInt32((entradaGanado.PesoBruto - entradaGanado.PesoTara) / entradaGanado.CabezasRecibidas); } } // Generamos el Folio FolioBL folioBL = new FolioBL(); var folioMuerte = folioBL.ObtenerFolio(organizacionID, TipoFolio.MuertesEnTransito); foreach (var animal in animales) { if (datosInterface) { pesoAnimal = interfaceSalidaAnimal.Where( are => are.Arete.Equals(animal.Arete)).Select( peso => Convert.ToInt32(peso.PesoCompra)).FirstOrDefault(); } if (datosInterface) { fecha = interfaceSalidaAnimal.Where(arete => arete.Arete.Equals(animal.Arete)).Select( fechaItz => fechaItz.FechaCompra).FirstOrDefault(); } if (fecha == new DateTime(1, 1, 1)) { fecha = DateTime.Now; } animal.OrganizacionIDEntrada = organizacionID; animal.FolioEntrada = muerteEnTransito.FolioEntrada; animal.UsuarioCreacionID = usuarioCreacionID; animal.ClasificacionGanadoID = 1; animal.CalidadGanadoID = 1; animal.TipoGanadoID = 1; animal.FechaCompra = fecha; animal.PesoCompra = pesoAnimal; animal.Activo = false; } //Guardamos los Animales var animalBL = new AnimalBL(); animalBL.GuardarAnimal(animales); //Obtenemos los animales almacenados con su animales = animalBL.ObtenerPorArete(animales); foreach (AnimalInfo animal in animales) { animal.UsuarioCreacionID = usuarioCreacionID; } //Genera los costos por animal animales = animalBL.ProcesoGenerarCostos(animales); foreach (AnimalInfo animal in animales) { var entradaGanadoMuerte = new EntradaGanadoMuerteInfo { EntradaGanado = new EntradaGanadoInfo { EntradaGanadoID = muerteEnTransito.EntradaGanadoID, }, Animal = new AnimalInfo { Arete = animal.Arete }, FolioMuerte = folioMuerte, Activo = EstatusEnum.Activo, UsuarioCreacionID = usuarioCreacionID, Peso = animal.PesoCompra, EntradaGanadMuerteDetalle = new List <EntradaGanadoMuerteDetalleInfo>(), ProveedorFletes = new ProveedorInfo() { CodigoSAP = muerteEnTransito.CodigoProveedor }, Cliente = new ClienteInfo() { CodigoSAP = muerteEnTransito.Cliente.CodigoSAP, Descripcion = muerteEnTransito.Cliente.Descripcion }, OrganizacionDestinoID = entradaGanado.OrganizacionID }; if (animal.ListaCostosAnimal != null) { entradaGanadoMuerte.EntradaGanadMuerteDetalle = animal.ListaCostosAnimal.Select(im => new EntradaGanadoMuerteDetalleInfo { Costo = new CostoInfo { CostoID = im.CostoID }, Importe = im.Importe, EntradaGanadoMuerte = entradaGanadoMuerte }).ToList(); } entradaGanadoMuerteLista.Add(entradaGanadoMuerte); } if (interfaceSalidaAnimal != null && interfaceSalidaAnimal.Count > 0 && animales != null && animales.Count > 0) { var interfaceSalidaBL = new InterfaceSalidaAnimalBL(); foreach (AnimalInfo animal in animales) { InterfaceSalidaAnimalInfo interfaceSalidaAnimalIndividual = interfaceSalidaAnimal.FirstOrDefault(animalInfo => animalInfo.Arete.Equals(animal.Arete)); interfaceSalidaBL.GuardarAnimalID(interfaceSalidaAnimalIndividual, animal.AnimalID); } } //Asignamos el AnimalID en la lista de muertes ante sde guardar. foreach (EntradaGanadoMuerteInfo muerte in entradaGanadoMuerteLista) { muerte.Animal.AnimalID = animales.Where(animal => animal.Arete.Equals(muerte.Animal.Arete)) .Select(animal => animal.AnimalID).FirstOrDefault(); muerte.Peso = animales.Where(animal => animal.Arete.Equals(muerte.Animal.Arete)) .Select(animal => animal.PesoCompra).FirstOrDefault(); } //Guardamos las muertes en transito var muertesEnTransitoDal = new MuertesEnTransitoDAL(); muertesEnTransitoDal.Guardar(entradaGanadoMuerteLista, muerteEnTransito.Cliente); //Creamos los movimientos para el animal if (animales != null && animales.Any()) { fecha = DateTime.Now; var animalMovimientoBL = new AnimalMovimientoBL(); List <AnimalMovimientoInfo> movimientosAnimal = animales.Select(ani => new AnimalMovimientoInfo { AnimalID = ani.AnimalID, Activo = EstatusEnum.Activo, CorralID = corralID, LoteID = loteID, FechaMovimiento = fecha, OrganizacionID = organizacionID, TipoMovimientoID = TipoMovimiento.MuerteTransito.GetHashCode(), OperadorID = 1, TrampaID = 1, Peso = ani.PesoCompra, UsuarioCreacionID = usuarioCreacionID, }).ToList(); animalMovimientoBL.GuardarAnimalMovimientoXML(movimientosAnimal); } //Afectamos el lote correspondiente. var loteBl = new LoteBL(); var loteInfo = loteBl.ObtenerPorID(muerteEnTransito.LoteID); loteInfo.UsuarioModificacionID = muerteEnTransito.UsuarioCreacionID; loteInfo.Cabezas -= muerteEnTransito.MuertesTransito; var filtro = new FiltroActualizarCabezasLote { CabezasProcesadas = muerteEnTransito.MuertesTransito, LoteIDDestino = 0, LoteIDOrigen = loteInfo.LoteID, UsuarioModificacionID = usuarioCreacionID }; var cabezasActualizadas = loteBl.ActualizarCabezasProcesadas(filtro); //Executamos el SP CorteGanado_CierrePartidaPesoOrigenLLegada(Antes-->CorteGanado_PesoCompraDirecta), si se inactiva el lote. if (cabezasActualizadas.CabezasOrigen <= 0) { //muertesEnTransitoDal.CorteGanado_PesoCompraDirecta(muerteEnTransito.OrganizacionID, muerteEnTransito.CorralID, muerteEnTransito.LoteID); var corteGanadoBl = new CorteGanadoBL(); corteGanadoBl.ObtenerPesosOrigenLlegada(muerteEnTransito.OrganizacionID, muerteEnTransito.CorralID, muerteEnTransito.LoteID); } #region Poliza //VentaGanadoBL ventaGanadoBL = new VentaGanadoBL(); //List<EntradaGanadoMuerteInfo> ventasGanado = ventaGanadoBL.ObtenerVentaGanadoPorTicketPoliza(folio, organizacionID); //if (ventasGanado != null && ventasGanado.Any()) if (entradaGanadoMuerteLista != null && entradaGanadoMuerteLista.Any()) { poliza = FabricaPoliza.ObtenerInstancia().ObtenerTipoPoliza(TipoPoliza.PolizaMuerteTransito); polizaMuerteEnTransito = poliza.GeneraPoliza(entradaGanadoMuerteLista); if (polizaMuerteEnTransito != null && polizaMuerteEnTransito.Any()) { polizaMuerteEnTransito.ToList().ForEach( org => { org.OrganizacionID = organizacionID; org.UsuarioCreacionID = usuarioCreacionID; org.ArchivoEnviadoServidor = 1; }); entradaGanadoMuerteLista.ToList().ForEach(org => { org.EntradaGanado.Lote = entradaGanado.Lote; org.EntradaGanado.CodigoCorral = entradaGanado.CodigoCorral; }); retorno = poliza.ImprimePoliza(entradaGanadoMuerteLista, polizaMuerteEnTransito); var polizaBL = new PolizaBL(); polizaBL.GuardarServicioPI(polizaMuerteEnTransito, TipoPoliza.PolizaMuerteTransito); } } // Genera el xml y lo guarda en la ruta especificada en la configuración var facturaBl = new FacturaBL(); facturaBl.GenerarDatosFacturaMuertesEnTransito(folioMuerte, organizacionID); #endregion Poliza animalBL.EnviarAHistorico(animales); transaction.Complete(); } return(retorno); } catch (ExcepcionGenerica) { throw; } catch (Exception ex) { Logger.Error(ex); throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex); } }
/// <summary> /// Obtiene los datos del elemento seleccionado en la ayuda Folio de Entrada. /// </summary> /// <param name="filtro"></param> private void ObtenerDatosAyudaFolioEntrada(string filtro) { List <string> aretes = new List <string>(); muertesEnTransitoInfoSeleccionado = skAyudaFolioEntrada.Info; InicializarAyudaFolioEntrada(); skAyudaCliente.LimpiarCampos(); MuertesEnTransitoPL muertePl = new MuertesEnTransitoPL(); ValidacionesFolioVentaMuerte validaciones = new ValidacionesFolioVentaMuerte(); if (muertesEnTransitoInfoSeleccionado != null && muertesEnTransitoInfoSeleccionado.EntradaGanadoID != 0) { foreach (AnimalInfo arete in dgAretes.Items) { aretes.Add(arete.Arete); } validaciones = muertePl.ValidarFolio(muertesEnTransitoInfoSeleccionado.FolioEntrada, organizacionID, aretes); if (!validaciones.RegistroCondicionMuerte) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_FolioSinCondicionMuerte, MessageBoxButton.OK, MessageImage.Warning); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else if (validaciones.FolioConMuertesRegistradas) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_FolioConRegistroMuertes, MessageBoxButton.OK, MessageImage.Warning); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else if (muertesEnTransitoInfoSeleccionado.MuertesTransito == 0) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_msgNoTieneMuertes, MessageBoxButton.OK, MessageImage.Warning); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else if (muertesEnTransitoInfoSeleccionado.MuertesRegistradas != 0) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_msgMuertesRegistradas, MessageBoxButton.OK, MessageImage.Warning); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else if (!validaciones.EstatusLote) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_LoteInactivo, MessageBoxButton.OK, MessageImage.Stop); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else if (validaciones.Cabezas == 0) { SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_LoteSinCabezas, MessageBoxButton.OK, MessageImage.Stop); InicializarFormulario(); skAyudaFolioEntrada.AsignarFoco(); } else { muertesEnTransitoInfoSeleccionado.OrganizacionID = organizacionID; txtArete.IsEnabled = true; chkSinArete.IsChecked = false; if (muertesEnTransitoInfoSeleccionado.TipoOrigenID == (int)TipoOrganizacion.CompraDirecta) { txtArete.IsEnabled = false; chkSinArete.IsChecked = true; } else { AnimalesDelCorral = new List <AnimalInfo>(); var muertesEnTransitoPl = new MuertesEnTransitoPL(); AnimalesDelCorral = muertesEnTransitoPl.ObtenerAretesPorFolioEntrada(muertesEnTransitoInfoSeleccionado); } if (ProveedoresAsignadosAlEmbarque(muertesEnTransitoInfoSeleccionado.EmbarqueID) <= 1) { var pl = new ProveedorPL(); var cl = new ClientePL(); var clienteInfo = new ClienteInfo(); var info = new ProveedorInfo() { CodigoSAP = muertesEnTransitoInfoSeleccionado.CodigoProveedor }; clienteInfo = cl.ObtenerPorDescripcion(muertesEnTransitoInfoSeleccionado.Proveedor); Contexto.Proveedor = pl.ObtenerPorCodigoSAP(info); if (clienteInfo != null) { skAyudaCliente.IsEnabled = false; muertesEnTransitoInfoSeleccionado.Cliente = clienteInfo; skAyudaCliente.Clave = muertesEnTransitoInfoSeleccionado.Cliente.CodigoSAP; skAyudaCliente.Descripcion = muertesEnTransitoInfoSeleccionado.Cliente.Descripcion; Contexto.Cliente = clienteInfo; } else { skAyudaCliente.IsEnabled = true; skAyudaCliente.Clave = string.Empty; skAyudaCliente.Descripcion = string.Empty; SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.MuertesEnTransito_ProveedorNoEsCliente, MessageBoxButton.OK, MessageImage.Warning); skAyudaCliente.Focus(); } } else { skAyudaCliente.IsEnabled = true; } Contexto.Proveedor.EmbarqueID = muertesEnTransitoInfoSeleccionado.EmbarqueID; countAreteGenerico = muertesEnTransitoInfoSeleccionado.MuertesRegistradas + 1; txtOrigen.Text = muertesEnTransitoInfoSeleccionado.Origen; txtTipoOrigen.Text = muertesEnTransitoInfoSeleccionado.TipoOrigen; txtCorral.Text = muertesEnTransitoInfoSeleccionado.Corral; txtLote.Text = muertesEnTransitoInfoSeleccionado.Lote; txtCabezas.Text = muertesEnTransitoInfoSeleccionado.Cabezas.ToString(); txtMuertesEnTransito.Text = muertesEnTransitoInfoSeleccionado.MuertesTransito.ToString(); Animales.Clear(); dgAretes.Items.Refresh(); txtArete.Clear(); txtArete.Focus(); } } }