コード例 #1
0
 internal int Guardar(GastoMateriaPrimaInfo gasto)
 {
     try
     {
         Logger.Info();
         var parameters = AuxGastoMateriaPrimaDAL.ObtenerParametrosGuardar(gasto);
         int result     = Create("GastoMateriaPrima_Crear", parameters);
         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);
     }
 }
コード例 #2
0
 /// <summary>
 /// Obtiene un registro de GastoMateriaPrima
 /// </summary>
 /// <param name="gastoMateriaPrimaID">Identificador de la GastoMateriaPrima</param>
 /// <returns></returns>
 public GastoMateriaPrimaInfo ObtenerPorID(int gastoMateriaPrimaID)
 {
     try
     {
         Logger.Info();
         Dictionary <string, object> parameters = AuxGastoMateriaPrimaDAL.ObtenerParametrosPorID(gastoMateriaPrimaID);
         DataSet ds = Retrieve("GastoMateriaPrima_ObtenerPorID", parameters);
         GastoMateriaPrimaInfo result = null;
         if (ValidateDataSet(ds))
         {
             result = MapGastoMateriaPrimaDAL.ObtenerPorID(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);
     }
 }
コード例 #3
0
 /// <summary>
 /// Obtiene los parametros para crear una solicitud
 /// </summary>
 /// <param name="gasto"></param>
 /// <returns></returns>
 internal static Dictionary <string, object> ObtenerParametrosGuardar(GastoMateriaPrimaInfo gasto)
 {
     try
     {
         Logger.Info();
         var parametros =
             new Dictionary <string, object>
         {
             { "@AlmacenMovimientoID", gasto.AlmacenMovimientoID },
             { "@OrganizacionID", gasto.Organizacion.OrganizacionID },
             { "@TipoMovimientoID", gasto.TipoMovimiento.TipoMovimientoID },
             { "@ProductoID", gasto.Producto.ProductoId },
             { "@TieneCuenta", gasto.TieneCuenta },
             { "@CuentaSAPID", gasto.CuentaSAP.CuentaSAPID },
             { "@ProveedorID", gasto.Proveedor.ProveedorID },
             { "@AlmacenInventarioLoteID", gasto.AlmacenInventarioLote.AlmacenInventarioLoteId },
             { "@Importe", gasto.Importe },
             { "@IVA", gasto.Iva },
             { "@Observaciones", gasto.Observaciones },
             { "@Activo", gasto.Activo },
             { "@Cantidad", gasto.UnidadMedida ? gasto.Kilogramos : 0 },
             { "@TipoFolio", gasto.TipoFolio.GetHashCode() },
             { "@UsuarioCreacionID", gasto.UsuarioCreacionID }
         };
         return(parametros);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
コード例 #4
0
        internal static Dictionary <string, object> ObtenerParametrosGuardarAretes(GastoMateriaPrimaInfo gasto)
        {
            try
            {
                Logger.Info();
                var xml = new XElement("ROOT",
                                       from arete in gasto.AretesCapturados
                                       select new XElement("DATOS",
                                                           new XElement("Arete", arete.Arete)
                                                           ));

                var parametros = new Dictionary <string, object> {
                    { "@XML", xml.ToString() },
                    { "@OrganizacionId", gasto.Organizacion.OrganizacionID },
                    { "@ProductoId", gasto.Producto.ProductoId },
                    { "@EsAreteSukarne", gasto.EsAreteSukarne.GetHashCode() },
                    { "@EsEntradaAlmacen", gasto.TipoMovimiento.EsEntrada.GetHashCode() },
                    { "@Cantidad", gasto.AretesCapturados.Count },
                    { "@Importe", gasto.Importe },
                    { "@UsuarioId", gasto.UsuarioCreacionID }
                };
                return(parametros);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }
コード例 #5
0
 /// <summary>
 ///  Método que obtiene un registro
 /// </summary>
 /// <param name="ds"></param>
 /// <returns></returns>
 public static GastoMateriaPrimaInfo ObtenerPorID(DataSet ds)
 {
     try
     {
         Logger.Info();
         DataTable             dt      = ds.Tables[ConstantesDAL.DtDatos];
         GastoMateriaPrimaInfo entidad =
             (from info in dt.AsEnumerable()
              select
              new GastoMateriaPrimaInfo
         {
             GastoMateriaPrimaID = info.Field <int>("GastoMateriaPrimaID"),
             Organizacion = new OrganizacionInfo {
                 OrganizacionID = info.Field <int>("OrganizacionID"), Descripcion = info.Field <string>("Organizacion")
             },
             FolioGasto = info.Field <long>("FolioGasto"),
             TipoMovimiento = new TipoMovimientoInfo {
                 TipoMovimientoID = info.Field <int>("TipoMovimientoID"), Descripcion = info.Field <string>("TipoMovimiento")
             },
             Fecha = info.Field <DateTime>("Fecha"),
             Producto = new ProductoInfo {
                 ProductoId = info.Field <int>("ProductoID"), Descripcion = info.Field <string>("Producto")
             },
             TieneCuenta = info.Field <bool>("TieneCuenta"),
             CuentaSAP = new CuentaSAPInfo
             {
                 CuentaSAPID = info.Field <int?>("CuentaSAPID") != null ? info.Field <int>("CuentaSAPID") : 0,
                 Descripcion = info.Field <string>("CuentaSAP")
             },
             Proveedor = new ProveedorInfo
             {
                 ProveedorID = info.Field <int?>("ProveedorID") != null ? info.Field <int>("ProveedorID") : 0,
                 Descripcion = info.Field <string>("Proveedor")
             },
             AlmacenMovimientoID = info.Field <long>("AlmacenMovimientoID"),
             AlmacenInventarioLote = new AlmacenInventarioLoteInfo
             {
                 AlmacenInventarioLoteId = info.Field <int?>("AlmacenInventarioLoteID") != null ? info.Field <int>("AlmacenInventarioLoteID") : 0
             },
             Importe = info.Field <decimal>("Importe"),
             Iva = info.Field <bool>("IVA"),
             Observaciones = info.Field <string>("Observaciones"),
             Activo = info.Field <bool>("Activo").BoolAEnum(),
         }).First();
         return(entidad);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
コード例 #6
0
 /// <summary>
 /// Obtiene una entidad GastoMateriaPrima por su Id
 /// </summary>
 /// <param name="gastoMateriaPrimaID">Obtiene una entidad GastoMateriaPrima por su Id</param>
 /// <returns></returns>
 internal GastoMateriaPrimaInfo ObtenerPorID(int gastoMateriaPrimaID)
 {
     try
     {
         Logger.Info();
         var gastoMateriaPrimaDAL     = new GastoMateriaPrimaDAL();
         GastoMateriaPrimaInfo result = gastoMateriaPrimaDAL.ObtenerPorID(gastoMateriaPrimaID);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
コード例 #7
0
 /// <summary>
 /// Guarda los datos para una solicitud de premezclas
 /// </summary>
 /// <param name="gasto"></param>
 /// <returns></returns>
 public long Guardar(GastoMateriaPrimaInfo gasto)
 {
     try
     {
         Logger.Info();
         var gastoMateriaPrimaBl = new GastoMateriaPrimaBL();
         return(gastoMateriaPrimaBl.Guardar(gasto));
     }
     catch (ExcepcionServicio)
     {
         throw;
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
コード例 #8
0
 internal void GuardarAretes(GastoMateriaPrimaInfo gasto)
 {
     try
     {
         Logger.Info();
         var parameters = AuxGastoMateriaPrimaDAL.ObtenerParametrosGuardarAretes(gasto);
         var ds         = Create("GastosMateriasPrimas_GuardarAretes", parameters);
     }
     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);
     }
 }
コード例 #9
0
        /// <summary>
        /// Guarda los datos para un gasto materia prima
        /// </summary>
        /// <param name="gasto"></param>
        /// <returns></returns>
        internal long Guardar(GastoMateriaPrimaInfo gasto)
        {
            long folioGasto = 0;

            try
            {
                Logger.Info();
                IList <PolizaInfo> polizas;
                PolizaAbstract     poliza;
                using (var transaction = new TransactionScope())
                {
                    var tipoOrg = gasto.Organizacion.TipoOrganizacion.TipoOrganizacionID;
                    var gastoMateriaPrimaDal = new GastoMateriaPrimaDAL();

                    if (gasto.GuardaAretes)
                    {
                        gastoMateriaPrimaDal.GuardarAretes(gasto);
                    }

                    if (tipoOrg == TipoOrganizacion.Centro.GetHashCode() || tipoOrg == TipoOrganizacion.Cadis.GetHashCode() || tipoOrg == TipoOrganizacion.Descanso.GetHashCode())
                    {
                        #region CENTROS

                        gasto.TipoFolio           = TipoFolio.GastoMateriaPrima;
                        gasto.AlmacenMovimientoID = null;
                        folioGasto = gastoMateriaPrimaDal.Guardar(gasto);

                        #endregion CENTROS
                    }
                    else
                    {
                        #region SIAP

                        #region MOVIMIENTOS

                        var listaAlmacenDetalle = new List <AlmacenMovimientoDetalle>();

                        var almacenMovimiento = new AlmacenMovimientoInfo
                        {
                            AlmacenID         = gasto.AlmacenID,
                            TipoMovimientoID  = gasto.TipoMovimiento.TipoMovimientoID,
                            ProveedorId       = gasto.Proveedor.ProveedorID,
                            Observaciones     = gasto.Observaciones,
                            Status            = (int)EstatusInventario.Aplicado,
                            UsuarioCreacionID = gasto.UsuarioCreacionID
                        };
                        var almacenMovimientoBl = new AlmacenMovimientoBL();
                        var almacenMovimientoID = almacenMovimientoBl.Crear(almacenMovimiento);
                        gasto.AlmacenMovimientoID = almacenMovimientoID;

                        var almacenMovimientoDetalle = new AlmacenMovimientoDetalle
                        {
                            AlmacenMovimientoID = almacenMovimientoID,
                            ProductoID          = gasto.Producto.ProductoId,
                            UsuarioCreacionID   = gasto.UsuarioCreacionID,
                            Importe             = gasto.Importe,
                            Cantidad            = 0,
                            Precio = 0
                        };
                        if (gasto.UnidadMedida)
                        {
                            almacenMovimientoDetalle.Cantidad = gasto.Kilogramos;
                            if (gasto.Kilogramos > 0)
                            {
                                almacenMovimientoDetalle.Precio = gasto.Importe / gasto.Kilogramos;
                            }
                            else
                            {
                                almacenMovimientoDetalle.Precio = 0;
                            }
                        }
                        gasto.TipoFolio = TipoFolio.GastoMateriaPrima;
                        int gastoMateriaPrimaID = gastoMateriaPrimaDal.Guardar(gasto);
                        //Actualizamos en AlmacenInventarioLote
                        if (gasto.AlmacenInventarioLote.AlmacenInventarioLoteId != 0)
                        {
                            almacenMovimientoDetalle.AlmacenInventarioLoteId =
                                gasto.AlmacenInventarioLote.AlmacenInventarioLoteId;

                            var almacenInventarioLote     = new AlmacenInventarioLoteDAL();
                            var almacenInventarioLoteInfo = new AlmacenInventarioLoteInfo();
                            almacenInventarioLoteInfo =
                                almacenInventarioLote.ObtenerAlmacenInventarioLotePorId(
                                    gasto.AlmacenInventarioLote.AlmacenInventarioLoteId);
                            almacenInventarioLoteInfo.UsuarioModificacionId = gasto.UsuarioCreacionID;
                            if (gasto.TipoMovimiento.TipoMovimientoID == (int)TipoMovimiento.EntradaPorAjuste)
                            {
                                almacenInventarioLoteInfo.Importe  += gasto.Importe;
                                almacenInventarioLoteInfo.Cantidad += gasto.Kilogramos;
                            }
                            else // Salida por Ajuste
                            {
                                almacenInventarioLoteInfo.Importe  -= gasto.Importe;
                                almacenInventarioLoteInfo.Cantidad -= gasto.Kilogramos;
                            }
                            if (almacenInventarioLoteInfo.Cantidad == 0)
                            {
                                almacenInventarioLoteInfo.PrecioPromedio = 0;
                            }
                            else
                            {
                                almacenInventarioLoteInfo.PrecioPromedio = almacenInventarioLoteInfo.Importe /
                                                                           almacenInventarioLoteInfo.Cantidad;
                            }
                            almacenInventarioLote.Actualizar(almacenInventarioLoteInfo);
                        }
                        // Actualizamos en AlmacenInventario
                        var almacenInventario     = new AlmacenInventarioDAL();
                        var almacenInventarioInfo = new AlmacenInventarioInfo
                        {
                            AlmacenID  = gasto.AlmacenID,
                            ProductoID = gasto.Producto.ProductoId
                        };
                        almacenInventarioInfo = almacenInventario.ObtenerPorAlmacenIdProductoId(almacenInventarioInfo);
                        if (gasto.TipoMovimiento.TipoMovimientoID == (int)TipoMovimiento.EntradaPorAjuste)
                        {
                            almacenInventarioInfo.Importe  += gasto.Importe;
                            almacenInventarioInfo.Cantidad += gasto.Kilogramos;
                            gasto.EsEntrada = true;
                        }
                        else // Salida por Ajuste
                        {
                            almacenInventarioInfo.Importe  -= gasto.Importe;
                            almacenInventarioInfo.Cantidad -= gasto.Kilogramos;
                        }
                        almacenInventarioInfo.UsuarioModificacionID = gasto.UsuarioCreacionID;
                        if (almacenInventarioInfo.Cantidad == 0)
                        {
                            almacenInventarioInfo.PrecioPromedio = 0;
                        }
                        else
                        {
                            almacenInventarioInfo.PrecioPromedio = almacenInventarioInfo.Importe / almacenInventarioInfo.Cantidad;
                        }
                        almacenInventario.Actualizar(almacenInventarioInfo);

                        listaAlmacenDetalle.Add(almacenMovimientoDetalle);
                        var almacenMovimientoDetalleBL = new AlmacenMovimientoDetalleBL();
                        almacenMovimientoDetalleBL.GuardarAlmacenMovimientoDetalle(listaAlmacenDetalle, almacenMovimientoID);

                        #endregion MOVIMIENTOS

                        #region POLIZA

                        GastoMateriaPrimaInfo gastoMateriaGuardado = gastoMateriaPrimaDal.ObtenerPorID(gastoMateriaPrimaID);

                        gasto.Fecha      = gastoMateriaGuardado.Fecha;
                        gasto.FolioGasto = gastoMateriaGuardado.FolioGasto;
                        folioGasto       = gastoMateriaGuardado.FolioGasto;
                        poliza           = FabricaPoliza.ObtenerInstancia().ObtenerTipoPoliza(TipoPoliza.GastosMateriaPrima);
                        polizas          = poliza.GeneraPoliza(gasto);
                        if (polizas != null && polizas.Any())
                        {
                            polizas.ToList().ForEach(datos =>
                            {
                                datos.OrganizacionID         = gasto.Organizacion.OrganizacionID;
                                datos.UsuarioCreacionID      = gasto.UsuarioCreacionID;
                                datos.ArchivoEnviadoServidor = 1;
                            });
                            var polizaBL = new PolizaBL();
                            if (gasto.EsEntrada)
                            {
                                polizaBL.GuardarServicioPI(polizas, TipoPoliza.EntradaAjuste);
                            }
                            else
                            {
                                polizaBL.GuardarServicioPI(polizas, TipoPoliza.SalidaAjuste);
                            }
                        }

                        #endregion POLIZA

                        #endregion SIAP
                    }

                    transaction.Complete();
                }
                return(folioGasto);
            }
            catch (ExcepcionServicio ex)
            {
                Logger.Error(ex);
                throw;
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }