예제 #1
0
 public DtoLib.ResultadoAuto DocumentoAdm_Agregar_Pedido(DtoLibPos.DocumentoAdm.Agregar.Pedido.Ficha ficha)
 {
     return(ServiceProv.DocumentoAdm_Agregar_Pedido(ficha));
 }
        public OOB.Resultado.FichaAuto Documento_Agregar_Pedido(OOB.Documento.Agregar.Pedido.Ficha ficha)
        {
            var result = new OOB.Resultado.FichaAuto();

            var fichaDTO   = new DtoLibPos.DocumentoAdm.Agregar.Pedido.Ficha();
            var fichaEnc   = ficha.Encabezado;
            var Encabezado = new DtoLibPos.DocumentoAdm.Agregar.Pedido.FichaEncabezado()
            {
                RazonSocial              = fichaEnc.RazonSocial,
                DirFiscal                = fichaEnc.DirFiscal,
                CiRif                    = fichaEnc.CiRif,
                Tipo                     = fichaEnc.CodigoTipoDoc,
                Exento                   = fichaEnc.Exento,
                Base1                    = fichaEnc.Base1,
                Base2                    = fichaEnc.Base2,
                Base3                    = fichaEnc.Base3,
                Impuesto1                = fichaEnc.Impuesto1,
                Impuesto2                = fichaEnc.Impuesto2,
                Impuesto3                = fichaEnc.Impuesto3,
                MBase                    = fichaEnc.MBase,
                Impuesto                 = fichaEnc.Impuesto,
                Total                    = fichaEnc.Total,
                Tasa1                    = fichaEnc.Tasa1,
                Tasa2                    = fichaEnc.Tasa2,
                Tasa3                    = fichaEnc.Tasa3,
                Nota                     = fichaEnc.Nota,
                TasaRetencionIva         = fichaEnc.TasaRetencionIva,
                TasaRetencionIslr        = fichaEnc.TasaRetencionIslr,
                RetencionIva             = fichaEnc.TasaRetencionIva,
                RetencionIslr            = fichaEnc.RetencionIslr,
                AutoCliente              = fichaEnc.AutoCliente,
                CodigoCliente            = fichaEnc.CodigoCliente,
                Control                  = fichaEnc.Control,
                OrdenCompra              = fichaEnc.OrdenCompra,
                Dias                     = fichaEnc.Dias,
                Descuento1               = fichaEnc.Descuento1,
                Descuento2               = fichaEnc.Descuento2,
                Cargos                   = fichaEnc.Cargos,
                Descuento1p              = fichaEnc.Descuento1p,
                Descuento2p              = fichaEnc.Descuento2p,
                Cargosp                  = fichaEnc.Cargosp,
                Columna                  = fichaEnc.Columna,
                EstatusAnulado           = fichaEnc.EstatusAnulado,
                Aplica                   = fichaEnc.Aplica,
                ComprobanteRetencion     = fichaEnc.ComprobanteRetencion,
                SubTotalNeto             = fichaEnc.SubTotalNeto,
                Telefono                 = fichaEnc.Telefono,
                FactorCambio             = fichaEnc.FactorCambio,
                CodigoVendedor           = fichaEnc.CodigoVendedor,
                Vendedor                 = fichaEnc.Vendedor,
                AutoVendedor             = fichaEnc.AutoVendedor,
                Pedido                   = fichaEnc.Pedido,
                CondicionPago            = fichaEnc.CondicionPago,
                Usuario                  = fichaEnc.Usuario,
                CodigoUsuario            = fichaEnc.CodigoUsuario,
                CodigoSucursal           = fichaEnc.CodigoSucursal,
                Transporte               = fichaEnc.Transporte,
                CodigoTransporte         = fichaEnc.CodigoTransporte,
                MontoDivisa              = fichaEnc.MontoDivisa,
                Despachado               = fichaEnc.Despachado,
                DirDespacho              = fichaEnc.DirDespacho,
                Estacion                 = fichaEnc.Estacion,
                Renglones                = fichaEnc.Renglones,
                SaldoPendiente           = fichaEnc.SaldoPendiente,
                ComprobanteRetencionIslr = fichaEnc.ComprobanteRetencionIslr,
                DiasValidez              = fichaEnc.DiasValidez,
                AutoUsuario              = fichaEnc.AutoUsuario,
                AutoTransporte           = fichaEnc.AutoTransporte,
                Situacion                = fichaEnc.Situacion,
                Signo                    = fichaEnc.SignoTipoDoc,
                Serie                    = fichaEnc.SiglasTipoDoc,
                Tarifa                   = fichaEnc.Tarifa,
                TipoRemision             = fichaEnc.TipoRemision,
                DocumentoRemision        = fichaEnc.DocumentoRemision,
                AutoRemision             = fichaEnc.AutoRemision,
                DocumentoNombre          = fichaEnc.NombreTipoDoc,
                SubTotalImpuesto         = fichaEnc.SubTotalImpuesto,
                SubTotal                 = fichaEnc.SubTotal,
                TipoCliente              = fichaEnc.TipoCliente,
                Planilla                 = fichaEnc.Planilla,
                Expendiente              = fichaEnc.Expendiente,
                AnticipoIva              = fichaEnc.AnticipoIva,
                TercerosIva              = fichaEnc.TercerosIva,
                Neto                     = fichaEnc.Neto,
                Costo                    = fichaEnc.Costo,
                Utilidad                 = fichaEnc.Utilidad,
                Utilidadp                = fichaEnc.Utilidadp,
                DocumentoTipo            = fichaEnc.TipoTipoDoc,
                CiTitular                = fichaEnc.CiTitular,
                NombreTitular            = fichaEnc.NombreTitular,
                CiBeneficiario           = fichaEnc.CiBeneficiario,
                NombreBeneficiario       = fichaEnc.NombreBeneficiario,
                Clave                    = fichaEnc.Clave,
                DenominacionFiscal       = fichaEnc.DenominacionFiscal,
                Cambio                   = fichaEnc.Cambio,
                Cierre                   = fichaEnc.Cierre,
                CierreFtp                = fichaEnc.CierreFtp,
                EstatusCierreContable    = fichaEnc.EstatusCierreContable,
                EstatusValidado          = fichaEnc.EstatusValidado,
                FechaPedido              = fichaEnc.FechaPedido,
                Prefijo                  = fichaEnc.Prefijo,
            };

            fichaDTO.Encabezado = Encabezado;
            var detalles = ficha.Detalles.Select(s =>
            {
                var nr = new DtoLibPos.DocumentoAdm.Agregar.Pedido.FichaDetalle()
                {
                    AutoProducto     = s.AutoProducto,
                    Codigo           = s.Codigo,
                    Nombre           = s.Nombre,
                    AutoDepartamento = s.AutoDepartamento,
                    AutoGrupo        = s.AutoGrupo,
                    AutoSubGrupo     = s.AutoSubGrupo,
                    AutoDeposito     = s.AutoDeposito,
                    Cantidad         = s.Cantidad,
                    Empaque          = s.Empaque,
                    PrecioNeto       = s.PrecioNeto,
                    Descuento1p      = s.Descuento1p,
                    Descuento2p      = s.Descuento2p,
                    Descuento3p      = s.Descuento3p,
                    Descuento1       = s.Descuento1,
                    Descuento2       = s.Descuento2,
                    Descuento3       = s.Descuento3,
                    CostoVenta       = s.CostoVenta,
                    TotalNeto        = s.TotalNeto,
                    Tasa             = s.Tasa,
                    Impuesto         = s.Impuesto,
                    Total            = s.Total,
                    EstatusAnulado   = s.EstatusAnulado,
                    Tipo             = s.Tipo,
                    Deposito         = s.Deposito,
                    Signo            = s.Signo,
                    PrecioFinal      = s.PrecioFinal,
                    AutoCliente      = s.AutoCliente,
                    Decimales        = s.Decimales,
                    ContenidoEmpaque = s.ContenidoEmpaque,
                    CantidadUnd      = s.CantidadUnd,
                    PrecioUnd        = s.PrecioUnd,
                    CostoUnd         = s.CostoUnd,
                    Utilidad         = s.Utilidad,
                    Utilidadp        = s.Utilidadp,
                    PrecioItem       = s.PrecioItem,
                    EstatusGarantia  = s.EstatusGarantia,
                    EstatusSerial    = s.EstatusSerial,
                    CodigoDeposito   = s.CodigoDeposito,
                    DiasGarantia     = s.DiasGarantia,
                    Detalle          = s.Detalle,
                    PrecioSugerido   = s.PrecioSugerido,
                    AutoTasa         = s.AutoTasa,
                    EstatusCorte     = s.EstatusCorte,
                    X                 = s.X,
                    Y                 = s.Y,
                    Z                 = s.Z,
                    Corte             = s.Corte,
                    Categoria         = s.Categoria,
                    Cobranzap         = s.Cobranzap,
                    Ventasp           = s.Ventasp,
                    CobranzapVendedor = s.CobranzapVendedor,
                    VentaspVendedor   = s.VentaspVendedor,
                    Cobranza          = s.Cobranza,
                    Ventas            = s.Ventas,
                    CobranzaVendedor  = s.CobranzaVendedor,
                    VentasVendedor    = s.VentasVendedor,
                    CostoPromedioUnd  = s.CostoPromedioUnd,
                    CostoCompra       = s.CostoCompra,
                    EstatusChecked    = s.EstatusChecked,
                    Tarifa            = s.Tarifa,
                    TotalDescuento    = s.TotalDescuento,
                    CodigoVendedor    = s.CodigoVendedor,
                    AutoVendedor      = s.AutoVendedor,
                };
                return(nr);
            }).ToList();

            fichaDTO.Detalles = detalles;
            var itemsBLoquear = ficha.ItemDepositoBloquear.Select(s =>
            {
                var nr = new DtoLibPos.DocumentoAdm.Agregar.Pedido.FichaItemDepositoBloquear()
                {
                    autoDeposito   = s.autoDeposito,
                    autoProducto   = s.autoProducto,
                    cntUnd         = s.cntUnd,
                    depDescripcion = s.depDescripcion,
                    prdDescripcion = s.prdDescripcion,
                };
                return(nr);
            }).ToList();

            fichaDTO.ItemDepositoBloquear = itemsBLoquear;
            fichaDTO.VentaTemporal        = new DtoLibPos.DocumentoAdm.Agregar.Pedido.FichaTemporalVenta()
            {
                id = ficha.VentaTemporal.id,
            };
            fichaDTO.ValidarRupturaPorExistencia = ficha.ValidarRupturaPorExistencia;

            var r01 = MyData.DocumentoAdm_Agregar_Pedido(fichaDTO);

            if (r01.Result == DtoLib.Enumerados.EnumResult.isError)
            {
                result.Mensaje = r01.Mensaje;
                result.Result  = OOB.Resultado.Enumerados.EnumResult.isError;
                return(result);
            }
            result.Auto = r01.Auto;

            return(result);
        }
예제 #3
0
        public DtoLib.ResultadoAuto DocumentoAdm_Agregar_Pedido(DtoLibPos.DocumentoAdm.Agregar.Pedido.Ficha ficha)
        {
            var result = new DtoLib.ResultadoAuto();

            try
            {
                using (var cn = new PosEntities(_cnPos.ConnectionString))
                {
                    using (var ts = new TransactionScope())
                    {
                        var fechaSistema = cn.Database.SqlQuery <DateTime>("select now()").FirstOrDefault();
                        var mesRelacion  = fechaSistema.Month.ToString().Trim().PadLeft(2, '0');
                        var anoRelacion  = fechaSistema.Year.ToString().Trim().PadLeft(4, '0');
                        var fechaNula    = new DateTime(2000, 1, 1);

                        var sql = "update sistema_contadores set a_ventas=a_ventas+1, a_ventas_pedido=a_ventas_pedido+1";
                        var r1  = cn.Database.ExecuteSqlCommand(sql);
                        if (r1 == 0)
                        {
                            result.Mensaje = "PROBLEMA AL ACTUALIZAR TABLA CONTADORES";
                            result.Result  = DtoLib.Enumerados.EnumResult.isError;
                            return(result);
                        }

                        var fichaEnc   = ficha.Encabezado;
                        var aVenta     = cn.Database.SqlQuery <int>("select a_ventas from sistema_contadores").FirstOrDefault();
                        var aDocumento = cn.Database.SqlQuery <int>("select a_ventas_pedido from sistema_contadores").FirstOrDefault();
                        var largo      = 0;
                        largo = 10 - fichaEnc.Prefijo.Length;
                        var fechaVenc    = fechaSistema.AddDays(fichaEnc.Dias);
                        var autoVenta    = fichaEnc.Prefijo + aVenta.ToString().Trim().PadLeft(largo, '0');
                        var autoCxC      = "";
                        var autoRecibo   = "";
                        var reciboNUmero = "";
                        var documentoNro = aDocumento.ToString().Trim().PadLeft(10, '0');


                        //DOCUMENTO VENTA
                        var entVenta = new ventas()
                        {
                            auto                       = autoVenta,
                            documento                  = documentoNro,
                            fecha                      = fechaSistema.Date,
                            fecha_vencimiento          = fechaVenc.Date,
                            razon_social               = fichaEnc.RazonSocial,
                            dir_fiscal                 = fichaEnc.DirFiscal,
                            ci_rif                     = fichaEnc.CiRif,
                            tipo                       = fichaEnc.Tipo,
                            exento                     = fichaEnc.Exento,
                            base1                      = fichaEnc.Base1,
                            base2                      = fichaEnc.Base2,
                            base3                      = fichaEnc.Base3,
                            impuesto1                  = fichaEnc.Impuesto1,
                            impuesto2                  = fichaEnc.Impuesto2,
                            impuesto3                  = fichaEnc.Impuesto3,
                            @base                      = fichaEnc.MBase,
                            impuesto                   = fichaEnc.Impuesto,
                            total                      = fichaEnc.Total,
                            tasa1                      = fichaEnc.Tasa1,
                            tasa2                      = fichaEnc.Tasa2,
                            tasa3                      = fichaEnc.Tasa3,
                            nota                       = fichaEnc.Nota,
                            tasa_retencion_iva         = fichaEnc.TasaRetencionIva,
                            tasa_retencion_islr        = fichaEnc.TasaRetencionIslr,
                            retencion_iva              = fichaEnc.RetencionIva,
                            retencion_islr             = fichaEnc.TasaRetencionIslr,
                            auto_cliente               = fichaEnc.AutoCliente,
                            codigo_cliente             = fichaEnc.CodigoCliente,
                            mes_relacion               = mesRelacion,
                            control                    = fichaEnc.Control,
                            fecha_registro             = fechaSistema.Date,
                            orden_compra               = fichaEnc.OrdenCompra,
                            dias                       = fichaEnc.Dias,
                            descuento1                 = fichaEnc.Descuento1,
                            descuento2                 = fichaEnc.Descuento2,
                            cargos                     = fichaEnc.Cargos,
                            descuento1p                = fichaEnc.Descuento1p,
                            descuento2p                = fichaEnc.Descuento2p,
                            cargosp                    = fichaEnc.Cargosp,
                            columna                    = fichaEnc.Columna,
                            estatus_anulado            = fichaEnc.EstatusAnulado,
                            aplica                     = fichaEnc.Aplica,
                            comprobante_retencion      = fichaEnc.ComprobanteRetencion,
                            subtotal_neto              = fichaEnc.SubTotalNeto,
                            telefono                   = fichaEnc.Telefono,
                            factor_cambio              = fichaEnc.FactorCambio,
                            codigo_vendedor            = fichaEnc.CodigoVendedor,
                            vendedor                   = fichaEnc.Vendedor,
                            auto_vendedor              = fichaEnc.AutoVendedor,
                            fecha_pedido               = fichaEnc.FechaPedido,
                            pedido                     = fichaEnc.Pedido,
                            condicion_pago             = fichaEnc.CondicionPago,
                            usuario                    = fichaEnc.Usuario,
                            codigo_usuario             = fichaEnc.CodigoUsuario,
                            codigo_sucursal            = fichaEnc.CodigoSucursal,
                            hora                       = fechaSistema.ToShortTimeString(),
                            transporte                 = fichaEnc.Transporte,
                            codigo_transporte          = fichaEnc.CodigoTransporte,
                            monto_divisa               = fichaEnc.MontoDivisa,
                            despachado                 = fichaEnc.Despachado,
                            dir_despacho               = fichaEnc.DirDespacho,
                            estacion                   = fichaEnc.Estacion,
                            auto_recibo                = autoRecibo,
                            recibo                     = reciboNUmero,
                            renglones                  = fichaEnc.Renglones,
                            saldo_pendiente            = fichaEnc.SaldoPendiente,
                            ano_relacion               = anoRelacion,
                            comprobante_retencion_islr = fichaEnc.ComprobanteRetencionIslr,
                            dias_validez               = fichaEnc.DiasValidez,
                            auto_usuario               = fichaEnc.AutoUsuario,
                            auto_transporte            = fichaEnc.AutoTransporte,
                            situacion                  = fichaEnc.Situacion,
                            signo                      = fichaEnc.Signo,
                            serie                      = fichaEnc.Serie,
                            tarifa                     = fichaEnc.Tarifa,
                            tipo_remision              = fichaEnc.TipoRemision,
                            documento_remision         = fichaEnc.DocumentoRemision,
                            auto_remision              = fichaEnc.AutoRemision,
                            documento_nombre           = fichaEnc.DocumentoNombre,
                            subtotal_impuesto          = fichaEnc.SubTotalImpuesto,
                            subtotal                   = fichaEnc.SubTotal,
                            auto_cxc                   = autoCxC,
                            tipo_cliente               = fichaEnc.TipoCliente,
                            planilla                   = fichaEnc.Planilla,
                            expediente                 = fichaEnc.Expendiente,
                            anticipo_iva               = fichaEnc.AnticipoIva,
                            terceros_iva               = fichaEnc.TercerosIva,
                            neto                       = fichaEnc.Neto,
                            costo                      = fichaEnc.Costo,
                            utilidad                   = fichaEnc.Utilidad,
                            utilidadp                  = fichaEnc.Utilidadp,
                            documento_tipo             = fichaEnc.DocumentoTipo,
                            ci_titular                 = fichaEnc.CiTitular,
                            nombre_titular             = fichaEnc.NombreTitular,
                            ci_beneficiario            = fichaEnc.CiBeneficiario,
                            nombre_beneficiario        = fichaEnc.NombreBeneficiario,
                            clave                      = fichaEnc.Clave,
                            denominacion_fiscal        = fichaEnc.DenominacionFiscal,
                            cambio                     = fichaEnc.Cambio,
                            estatus_validado           = fichaEnc.EstatusValidado,
                            cierre                     = fichaEnc.Cierre,
                            fecha_retencion            = fechaNula,
                            estatus_cierre_contable    = fichaEnc.EstatusCierreContable,
                            cierre_ftp                 = fichaEnc.CierreFtp,
                        };
                        cn.ventas.Add(entVenta);
                        cn.SaveChanges();


                        //DETALLES
                        var sql1 = @"INSERT INTO ventas_detalle (auto_documento, auto_producto, codigo, nombre, auto_departamento,
                                    auto_grupo, auto_subgrupo, auto_deposito, cantidad, empaque, precio_neto, descuento1p, descuento2p,
                                    descuento3p, descuento1, descuento2, descuento3, costo_venta, total_neto, tasa, impuesto, total,
                                    auto, estatus_anulado, fecha, tipo, deposito, signo, precio_final, auto_cliente, decimales, 
                                    contenido_empaque, cantidad_und, precio_und, costo_und, utilidad, utilidadp, precio_item, 
                                    estatus_garantia, estatus_serial, codigo_deposito, dias_garantia, detalle, precio_sugerido,
                                    auto_tasa, estatus_corte, x, y, z, corte, categoria, cobranzap, ventasp, cobranzap_vendedor,
                                    ventasp_vendedor, cobranza, ventas, cobranza_vendedor, ventas_vendedor, costo_promedio_und, 
                                    costo_compra, estatus_checked, tarifa, total_descuento, codigo_vendedor, auto_vendedor, hora, cierre_ftp) 
                                    Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15},
                                    {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31},
                                    {32}, {33}, {34}, {35}, {36}, {37}, {38}, {39}, {40}, {41}, {42}, {43}, {44}, {45}, {46}, {47},
                                    {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}, {56}, {57}, {58}, {59}, {60}, {61}, {62}, {63},
                                    {64}, {65}, {66}, {67})";
                        //CUERPO DEL DOCUMENTO => ITEMS
                        var item = 0;
                        foreach (var dt in ficha.Detalles)
                        {
                            item += 1;
                            var autoItem = item.ToString().Trim().PadLeft(10, '0');

                            var vd = cn.Database.ExecuteSqlCommand(sql1, autoVenta, dt.AutoProducto, dt.Codigo, dt.Nombre, dt.AutoDepartamento,
                                                                   dt.AutoGrupo, dt.AutoSubGrupo, dt.AutoDeposito, dt.Cantidad, dt.Empaque, dt.PrecioNeto, dt.Descuento1p,
                                                                   dt.Descuento2p, dt.Descuento3p, dt.Descuento1, dt.Descuento2, dt.Descuento3,
                                                                   dt.CostoVenta, dt.TotalNeto, dt.Tasa, dt.Impuesto, dt.Total, autoItem, dt.EstatusAnulado, fechaSistema.Date,
                                                                   dt.Tipo, dt.Deposito, dt.Signo, dt.PrecioFinal, dt.AutoCliente, dt.Decimales, dt.ContenidoEmpaque,
                                                                   dt.CantidadUnd, dt.PrecioUnd, dt.CostoUnd, dt.Utilidad, dt.Utilidadp, dt.PrecioItem, dt.EstatusGarantia,
                                                                   dt.EstatusSerial, dt.CodigoDeposito, dt.DiasGarantia, dt.Detalle, dt.PrecioSugerido, dt.AutoTasa, dt.EstatusCorte,
                                                                   dt.X, dt.Y, dt.Z, dt.Corte, dt.Categoria, dt.Cobranzap, dt.Ventasp, dt.CobranzapVendedor,
                                                                   dt.VentaspVendedor, dt.Cobranza, dt.Ventas, dt.CobranzaVendedor, dt.VentasVendedor,
                                                                   dt.CostoPromedioUnd, dt.CostoCompra, dt.EstatusChecked, dt.Tarifa, dt.TotalDescuento,
                                                                   dt.CodigoVendedor, dt.AutoVendedor, fechaSistema.ToShortTimeString(), dt.CierreFtp);
                            if (vd == 0)
                            {
                                result.Mensaje = "PROBLEMA AL REGISTRAR ITEM [ " + Environment.NewLine + dt.Nombre + " ]";
                                result.Result  = DtoLib.Enumerados.EnumResult.isError;
                                return(result);
                            }
                        }

                        //BLOQUEAR MERCANCA
                        foreach (var dt in ficha.ItemDepositoBloquear)
                        {
                            var xp1 = new MySql.Data.MySqlClient.MySqlParameter();
                            xp1.ParameterName = "@p1";
                            xp1.Value         = dt.autoDeposito;
                            var xp2 = new MySql.Data.MySqlClient.MySqlParameter();
                            xp2.ParameterName = "@p2";
                            xp2.Value         = dt.autoProducto;
                            var xp3 = new MySql.Data.MySqlClient.MySqlParameter();
                            xp3.ParameterName = "@p3";
                            xp3.Value         = dt.cntUnd;
                            var xsql1 = @"update productos_deposito set 
                                            reservada=reservada+@p3, 
                                            disponible=disponible-@p3
                                        where auto_deposito=@p1 and auto_producto=@p2";
                            var vk1   = cn.Database.ExecuteSqlCommand(xsql1, xp1, xp2, xp3);
                            if (vk1 == 0)
                            {
                                var xmsg = "PROBLEMA AL ENCONTRAR PRODUCTO-DEPOSITO " + Environment.NewLine + "Deposito: " + dt.depDescripcion + Environment.NewLine + "Producto: " + dt.prdDescripcion;
                                result.Mensaje = xmsg;
                                result.Result  = DtoLib.Enumerados.EnumResult.isError;
                                return(result);
                            }

                            if (ficha.ValidarRupturaPorExistencia)
                            {
                                var yp1 = new MySql.Data.MySqlClient.MySqlParameter();
                                yp1.ParameterName = "@p1";
                                yp1.Value         = dt.autoDeposito;
                                var yp2 = new MySql.Data.MySqlClient.MySqlParameter();
                                yp2.ParameterName = "@p2";
                                yp2.Value         = dt.autoProducto;
                                var xsql2 = @"select disponible from  productos_deposito
                                            where auto_deposito=@p1 and auto_producto=@p2";
                                var cnt   = cn.Database.SqlQuery <decimal>(xsql2, yp1, yp2).FirstOrDefault();
                                if (cnt < 0m)
                                {
                                    var xmsg = "PROBLEMA AL BLOQUEAR MERCANCIA PRODUCTO-DEPOSITO" + Environment.NewLine + "Deposito: " + dt.depDescripcion + Environment.NewLine + "Producto: " + dt.prdDescripcion + Environment.NewLine + "NO HAY DISPONIBILIDAD";
                                    result.Mensaje = xmsg;
                                    result.Result  = DtoLib.Enumerados.EnumResult.isError;
                                    return(result);
                                }
                            }
                        }


                        //TEMPORAL VENTA-DETALLE
                        var sql2 = @"DELETE from p_ventaadm_det where id_ventaAdm=@p1";
                        var p1   = new MySql.Data.MySqlClient.MySqlParameter();
                        p1.ParameterName = "@p1";
                        p1.Value         = ficha.VentaTemporal.id;
                        var vk2 = cn.Database.ExecuteSqlCommand(sql2, p1);
                        if (vk2 == 0)
                        {
                            result.Mensaje = "PROBLEMA AL ELIMINAR REGISTRO TEMPORAL-VENTA-DETALLES";
                            result.Result  = DtoLib.Enumerados.EnumResult.isError;
                            return(result);
                        }


                        //TEMPORAL VENTA
                        var sql3 = @"DELETE from p_ventaadm where id=@p2";
                        var p2   = new MySql.Data.MySqlClient.MySqlParameter();
                        p2.ParameterName = "@p2";
                        p2.Value         = ficha.VentaTemporal.id;
                        vk2 = cn.Database.ExecuteSqlCommand(sql3, p2);
                        if (vk2 == 0)
                        {
                            result.Mensaje = "PROBLEMA AL ELIMINAR REGISTRO TEMPORAL-VENTA";
                            result.Result  = DtoLib.Enumerados.EnumResult.isError;
                            return(result);
                        }

                        cn.SaveChanges();
                        ts.Complete();
                        result.Auto = autoVenta;
                    }
                };
            }
            catch (DbEntityValidationException e)
            {
                var msg = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        msg += ve.ErrorMessage;
                    }
                }
                result.Mensaje = msg;
                result.Result  = DtoLib.Enumerados.EnumResult.isError;
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException e)
            {
                var msg = "";
                foreach (var eve in e.Entries)
                {
                    //msg += eve.m;
                    foreach (var ve in eve.CurrentValues.PropertyNames)
                    {
                        msg += ve.ToString();
                    }
                }
                result.Mensaje = msg;
                result.Result  = DtoLib.Enumerados.EnumResult.isError;
            }
            catch (Exception e)
            {
                result.Mensaje = e.Message;
                result.Result  = DtoLib.Enumerados.EnumResult.isError;
            }

            return(result);
        }