private bool Agregar9500() { // Se valida la parte de "Partes" if (!this.ctlPartes.Validar()) { return(false); } // Se pide el efectivo, si aplica if (!this.ctlCobro.CompletarCobro()) { return(false); } // Se valida que exista una Medida genérica, para las nuevas partes if (Datos.GetEntity <Medida>(q => q.MedidaID == Cat.Medidas.Pieza && q.Estatus) == null) { UtilLocal.MensajeAdvertencia("No existe una Medida genérica para asignarle a las partes nuevas. No se puede continuar."); return(false); } // Se solicitan la autorizaciones, si se requiere int iAutorizoID = 0; if (this.ctlPartes.AutorizacionRequeridaPrecio || this.ctlPartes.AutorizacionRequeridaAnticipo) { string sPermiso = (this.ctlPartes.AutorizacionRequeridaPrecio ? "Autorizaciones.Ventas.9500.PrecioFueraDeRango" : "Autorizaciones.Ventas.9500.NoAnticipo"); var Res = UtilLocal.ValidarObtenerUsuario(sPermiso, "Autorización"); iAutorizoID = (Res.Respuesta == null ? 0 : Res.Respuesta.UsuarioID); } // Se procede a guardar los datos DateTime dAhora = DateTime.Now; // Se genera la Cotización 9500 var o9500 = this.ctlPartes.Generar9500(); o9500.Fecha = dAhora; o9500.RealizoUsuarioID = this.ctlCobro.VendodorID; if (this.ctlCobro.ComisionistaID > 0) { o9500.ComisionistaClienteID = this.ctlCobro.ComisionistaID; } // Se genera el detalle del 9500 var oParteGanancia = this.ctlPartes.ObtenerParteGanancia(null); var o9500Detalle = new List <Cotizacion9500Detalle>(); foreach (var Parte9500 in this.ctlPartes.Detalle) { // Si la parte no existe, se agrega if (Parte9500.Value.ParteID <= 0) { int iFila = UtilLocal.findRowIndex(this.ctlPartes.dgvPartes, "Llave", Parte9500.Key); string sNumeroDeParte = Util.Cadena(this.ctlPartes.dgvPartes["NumeroDeParte", iFila].Value); string sDescripcion = Util.Cadena(this.ctlPartes.dgvPartes["Descripcion", iFila].Value); var oLinea = Datos.GetEntity <Linea>(q => q.LineaID == Parte9500.Value.LineaID && q.Estatus); Parte oParte = new Parte() { NumeroParte = sNumeroDeParte, LineaID = Parte9500.Value.LineaID, MarcaParteID = Parte9500.Value.MarcaParteID, ProveedorID = Parte9500.Value.ProveedorID, NombreParte = sDescripcion, Es9500 = true, SubsistemaID = oLinea.SubsistemaID.Valor() }; // Se agregan los precios PartePrecio oPartePrecio = null; if (oParteGanancia != null) { oPartePrecio = new PartePrecio() { Costo = Parte9500.Value.Costo, PorcentajeUtilidadUno = oParteGanancia.PorcentajeDeGanancia1, PorcentajeUtilidadDos = oParteGanancia.PorcentajeDeGanancia2, PorcentajeUtilidadTres = oParteGanancia.PorcentajeDeGanancia3, PorcentajeUtilidadCuatro = oParteGanancia.PorcentajeDeGanancia4, PorcentajeUtilidadCinco = oParteGanancia.PorcentajeDeGanancia5, PrecioUno = UtilTheos.AplicarRedondeo(Parte9500.Value.Costo * oParteGanancia.PorcentajeDeGanancia1), PrecioDos = UtilTheos.AplicarRedondeo(Parte9500.Value.Costo * oParteGanancia.PorcentajeDeGanancia2), PrecioTres = UtilTheos.AplicarRedondeo(Parte9500.Value.Costo * oParteGanancia.PorcentajeDeGanancia3), PrecioCuatro = UtilTheos.AplicarRedondeo(Parte9500.Value.Costo * oParteGanancia.PorcentajeDeGanancia4), PrecioCinco = UtilTheos.AplicarRedondeo(Parte9500.Value.Costo * oParteGanancia.PorcentajeDeGanancia5) }; } // Se guarda Guardar.Parte(oParte, oPartePrecio); Parte9500.Value.ParteID = oParte.ParteID; } // Se agrega la parte al detalle del 9500 o9500Detalle.Add(Parte9500.Value); } // Se guardan los datos de 9500 Guardar.c9500(o9500, o9500Detalle); // Se genera la venta con el anticipo var oVenta = new Venta() { ClienteID = o9500.ClienteID, RealizoUsuarioID = o9500.RealizoUsuarioID }; var oPrecioAnticipo = Datos.GetEntity <PartePrecio>(c => c.ParteID == Cat.Partes.AnticipoClientes && c.Estatus); var oVentaDetalle = new VentaDetalle() { ParteID = Cat.Partes.AnticipoClientes, Cantidad = 1, PrecioUnitario = o9500.Anticipo, Costo = oPrecioAnticipo.Costo.Valor(), CostoConDescuento = (oPrecioAnticipo.CostoConDescuento ?? oPrecioAnticipo.Costo.Valor()) }; Guardar.Venta(oVenta, new List <VentaDetalle>() { oVentaDetalle }); // Se guarda el dato de la venta con el anticipo en el registro de 9500 o9500.AnticipoVentaID = oVenta.VentaID; Datos.Guardar <Cotizacion9500>(o9500); // Se guardan las autorizaciones, si hubiera if (this.ctlPartes.AutorizacionRequeridaPrecio) { VentasProc.GenerarAutorizacion(Cat.AutorizacionesProcesos.c9500PrecioFueraDeRango, Cat.Tablas.Tabla9500, o9500.Cotizacion9500ID, iAutorizoID); } if (this.ctlPartes.AutorizacionRequeridaAnticipo) { VentasProc.GenerarAutorizacion(Cat.AutorizacionesProcesos.c9500SinAnticipo, Cat.Tablas.Tabla9500, o9500.Cotizacion9500ID, iAutorizoID); } // Se muestra una notifiación con el resultado UtilLocal.MostrarNotificacion("Cotización 9500 guardada correctamente."); return(true); }