Exemplo n.º 1
0
        public Decimal AdicionarAlmOrdenCompra(DateTime FECHA,
            Decimal ID_EMPRESA,
            String ARTICULO,
            String MOTIVO,
            String PROCESO_AREA,
            Decimal ID_PROVEEDOR,
            int PERIODOENTREGA,
            int GARANTIA,
            String FORMA_PAGO,
            Decimal ID_ENTIDAD_BANCARIA,
            String CUENTA_BANCARIA,
            String CONDICIONES_ENTREGA,
            Decimal SUBTOTAL,
            Decimal DESCUENTO_APLICADO,
            Decimal IVA_APLICADO,
            Decimal VALOR_TOTAL,
            String ESPECIFICACIONES_TECNICAS,
            String ESTADO,
            String OBSERVACIONES,
            List<ordenCompra> listaDetalles,
            Byte[] ARCHIVO_COTIZACION,
            Int32 ARCHIVO_COTIZACION_TAMANO,
            String ARCHIVO_COTIZACION_EXTENSION,
            String ARCHIVO_COTIZACION_TYPE,
            String NOMBRE_SOLICITO,
            String CARGO_SOLICITO,
            String TIPO_COMPRA,
            String FACTURAR_A)
        {
            Decimal ID_ORDEN = 0;
            Decimal ID_ARCHIVO = 0;
            Decimal ID_DETALLE = 0;
            Decimal ID_REF_PRODUCTO_PROVEEDOR = 0;
            Boolean verificador = true;

            Conexion conexion = new Conexion(Empresa);
            conexion.IniciarTransaccion();

            try
            {
                ID_ORDEN = AdicionarOrdenComra(FECHA, ID_EMPRESA, ARTICULO, MOTIVO, PROCESO_AREA, ID_PROVEEDOR, PERIODOENTREGA, GARANTIA, FORMA_PAGO, ID_ENTIDAD_BANCARIA, CUENTA_BANCARIA, CONDICIONES_ENTREGA, SUBTOTAL, DESCUENTO_APLICADO, IVA_APLICADO, VALOR_TOTAL, ESPECIFICACIONES_TECNICAS, ESTADO, OBSERVACIONES, NOMBRE_SOLICITO, CARGO_SOLICITO, TIPO_COMPRA, FACTURAR_A, conexion);

                if (ID_ORDEN <= 0)
                {
                    conexion.DeshacerTransaccion();
                    MensajeError = MensajeError;
                    verificador = false;
                }
                else
                {
                    foreach (ordenCompra detalle in listaDetalles)
                    {
                        ID_DETALLE = AdicionarDetalleOrdenCompra(ID_ORDEN, detalle.ID_PRODUCTO, detalle.REFERENCIA, detalle.TALLA, detalle.DESCRIPCION, detalle.CANTIDAD, detalle.VALOR_UNIDAD, detalle.VALOR_TOTAL, detalle.DESCUENTO, detalle.IVA_APLICADO, conexion);

                        if (ID_DETALLE <= 0)
                        {
                            conexion.DeshacerTransaccion();
                            MensajeError = MensajeError;
                            verificador = false;
                            break;
                        }
                        else
                        {
                            ID_REF_PRODUCTO_PROVEEDOR = verificarReferenciaProductoProveedor(ID_PROVEEDOR, detalle.ID_PRODUCTO, detalle.REFERENCIA, conexion);

                            if (ID_REF_PRODUCTO_PROVEEDOR <= 0)
                            {
                                conexion.DeshacerTransaccion();
                                MensajeError = MensajeError;
                                verificador = false;
                                break;
                            }
                        }
                    }

                    if (verificador == true)
                    {
                        if (ARCHIVO_COTIZACION != null)
                        {
                            ID_ARCHIVO = Convert.ToDecimal(conexion.ExecuteEscalarParaAdicionaArchivoCotizacionOrdenCompra(ID_ORDEN, FECHA, ARCHIVO_COTIZACION, ARCHIVO_COTIZACION_EXTENSION, ARCHIVO_COTIZACION_TAMANO, ARCHIVO_COTIZACION_TYPE, Usuario));

                            if (ID_ARCHIVO <= 0)
                            {
                                conexion.DeshacerTransaccion();
                                MensajeError = MensajeError;
                                verificador = false;
                            }
                        }
                    }

                    if (verificador == true)
                    {
                        conexion.AceptarTransaccion();
                    }
                }
            }
            catch (Exception ex)
            {
                conexion.DeshacerTransaccion();
                MensajeError = ex.Message;
                verificador = false;
            }
            finally
            {
                conexion.Desconectar();
            }

            if (verificador == true)
            {
                return ID_ORDEN;
            }
            else
            {
                return 0;
            }
        }