public async Task <IActionResult> Crear([FromBody] List <CrearViewModel> model) { List <VentaDetalle> ventasDetalles = new List <VentaDetalle>(); model.ForEach(ventaDetalle => { VentaDetalle v = new VentaDetalle { VedId = ventaDetalle.VedId, VtaId = ventaDetalle.VtaId, ProId = ventaDetalle.ProId, VedPrecio = ventaDetalle.VedPrecio, VedDescuento = ventaDetalle.VedDescuento, VedCantidad = ventaDetalle.VedCantidad }; ventasDetalles.Add(v); }); await _context.VentaDetalles.AddRangeAsync(ventasDetalles); try { await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest(ex)); } return(Ok()); }
// DELETE api/VentaDetalleService/5 public void delete(long id) { VentaDetalle v = this.db.VentaDetalle.Find(id); this.db.VentaDetalle.Remove(v); this.save(); }
public async Task <VentasCancelaciones> GetAsync(object id) { try { VentaDetalle ventaDetalle; List <VentaDetalle> Lista = new List <VentaDetalle>(); VentasCancelaciones item; using (IDbConnection conexion = new SqlConnection(WebConnectionString)) { conexion.Open(); var dynamicParameters = new DynamicParameters(); dynamicParameters.Add("@IdVenta", id); var dr = await conexion.ExecuteReaderAsync("[Venta].[SPCID_Get_ObtenerDetalleVenta]", param : dynamicParameters, commandType : CommandType.StoredProcedure); while (dr.Read()) { ventaDetalle = new VentaDetalle(); ventaDetalle.IdTipo = dr.GetInt32(dr.GetOrdinal("Tipo")); ventaDetalle.TipoVenta = dr.GetString(dr.GetOrdinal("TipoVenta")); ventaDetalle.Cantidad = dr.GetInt32(dr.GetOrdinal("Cantidad")); ventaDetalle.Nombre = dr.GetString(dr.GetOrdinal("Nombre")); ventaDetalle.Total = dr.GetDecimal(dr.GetOrdinal("Total")); Lista.Add(ventaDetalle); } item = new VentasCancelaciones(); item.ListaVentaDetalle = Lista; return(item); } } catch (Exception ex) { throw ex; } }
/// <summary> Consultar los registros del detalle de una venta. </summary> /// <param name="tintCodigo"> Codigo de la venta a la que se le va a conocer el detalle. </param> /// <returns> La lista con los detalles de venta seleccionados. </returns> public List <VentaDetalle> gmtdConsultarDetalle(int tintCodigo) { List <VentaDetalle> lstVentaDetalle = new List <VentaDetalle>(); try { List <SqlParameter> lstParameters = new List <SqlParameter>(); lstParameters.Add(new SqlParameter("intCodVenta", tintCodigo)); DataTable dt = new Utilidad().ejecutarSp(lstParameters, Sp.uspVentaDetalleConsultar); if (dt.Rows.Count > 0) { for (int indexRow = 0; indexRow < dt.Rows.Count; indexRow++) { VentaDetalle objVentaDetalle = new VentaDetalle(); objVentaDetalle.decValCompra = Convert.ToDecimal(dt.Rows[indexRow]["decValCompra"]); objVentaDetalle.decValVenta = Convert.ToDecimal(dt.Rows[indexRow]["decValVenta"]); objVentaDetalle.intCantidad = Convert.ToInt32(dt.Rows[indexRow]["intCantidad"]); objVentaDetalle.intCodVenta = Convert.ToInt32(dt.Rows[indexRow]["intCodVenta"]); objVentaDetalle.decTotal = Convert.ToInt32(dt.Rows[indexRow]["intTotal"]); objVentaDetalle.strCodProducto = dt.Rows[indexRow]["strCodProducto"].ToString(); objVentaDetalle.strDesProducto = dt.Rows[indexRow]["strDesProducto"].ToString(); lstVentaDetalle.Add(objVentaDetalle); } } } catch (Exception ex) { new dao().gmtdInsertarError(ex); } return(lstVentaDetalle); }
public async Task <int> InsertarDetalleAsync(VentaDetalle detalle) { const string sql = @"INSERT INTO ventaDetalle (id_venta ,id_banco ,id_tipo_tarjeta ,dia_vencimiento ,num_cuenta_corriente ,num_tarjeta_credito ,venc_tarjeta_credito ,cvv_tarjeta_credito) VALUES (@IdVenta, @IdBanco, @IdTipoTarjeta, @DiaVencimiento, @NumeroCuentaCorriente, @NumeroTarjetaCredito, @VencimientoTarjetaCredito, @CvvTarjetaCredito)"; return(await _repository.InsertAsync(sql, new Dictionary <string, object> { { "@IdVenta", detalle.IdVenta }, { "@IdBanco", detalle.IdBanco }, { "@IdTipoTarjeta", detalle.IdTipoTarjeta }, { "@DiaVencimiento", detalle.DiaVencimiento }, { "@NumeroCuentaCorriente", detalle.NumeroCuentaCorriente }, { "@NumeroTarjetaCredito", detalle.NumeroTarjetaCredito }, { "@VencimientoTarjetaCredito", detalle.VencimientoTarjetaCredito }, { "@CvvTarjetaCredito", detalle.CvvTarjetaCredito } })); }
/// <summary> Consultar los registros del detalle de una venta. </summary> /// <param name="tintCodigo"> Codigo de la venta a la que se le va a conocer el detalle. </param> /// <returns> La lista con los detalles de venta seleccionados. </returns> public List <VentaDetalle> gmtdConsultarDetalleTbl(int tintCodigo) { using (dbExequial2010DataContext ventas = new dbExequial2010DataContext()) { var query = from deu in ventas.tblVentasDetalles join ven in ventas.tblProductos on deu.strCodProducto equals ven.strCodProducto where deu.intCodVenta == tintCodigo select new { deu.intCantidad, deu.intCodVenta, deu.intTotal, deu.decValCompra, deu.decValVenta, deu.strCodProducto, ven.strDesProducto }; List <VentaDetalle> lstVentaDetalle = new List <VentaDetalle>(); foreach (var dato in query.ToList()) { VentaDetalle ven = new VentaDetalle(); ven.intCantidad = dato.intCantidad; ven.decTotal = dato.intTotal; ven.decValCompra = dato.decValCompra; ven.decValVenta = dato.decValVenta; ven.strCodProducto = dato.strCodProducto; //ven.strNomProducto = dato.strDesProducto; lstVentaDetalle.Add(ven); } return(lstVentaDetalle); } }
public ActionResult Create([Bind(Include = "Id,MedicamentoId,Cantidad,Precio,VentaId")] VentaDetalle ventaDetalle) { var medicamento = db.Medicamentos.Where(m => m.Id == ventaDetalle.MedicamentoId).Single(); if (medicamento.Existencia <= 0 || medicamento.Existencia < ventaDetalle.Cantidad) { TempData["error"] = $"La existencia ({medicamento.Existencia}), es menor a la cantidad solicitada({ventaDetalle.Cantidad})"; ViewBag.MedicamentoId = new SelectList(db.Medicamentos, "Id", "Nombre", ventaDetalle.MedicamentoId); ViewBag.VentaId = new SelectList(db.Ventas, "Id", "Codigo", ventaDetalle.VentaId); return(RedirectToAction("Details", "Ventas", new { @id = ventaDetalle.VentaId })); } if (ModelState.IsValid) { db.VentaDetalles.Add(ventaDetalle); db.SaveChanges(); ReducirExitencia(medicamento, ventaDetalle); return(RedirectToAction("Details", "Ventas", new { @id = ventaDetalle.VentaId })); } ViewBag.MedicamentoId = new SelectList(db.Medicamentos, "Id", "Nombre", ventaDetalle.MedicamentoId); ViewBag.VentaId = new SelectList(db.Ventas, "Id", "Codigo", ventaDetalle.VentaId); return(View(ventaDetalle)); }
private void dgvServicios_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { VentaDetalle Datos = this.ObtenerDatosVentaServicios(e.RowIndex); if (!string.IsNullOrEmpty(Datos.IDVentaServicio)) { if (!Datos.Concluido) { frmTicketDetalleProductosXServicio Detalle = new frmTicketDetalleProductosXServicio(Datos, this.BandVales); this.Visible = false; Detalle.ShowDialog(); Detalle.Dispose(); this.Visible = true; if (Detalle.BandCambios) { this.CargarGridServicios(); } } else { MessageBox.Show("El servicio ya está concluido. Ya no se pueden realizar modificaciones.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } catch (Exception ex) { this.Visible = true; LogError.AddExcFileTxt(ex, "frmDatosServicio ~ dgvServicios_CellContentDoubleClick"); } }
private VentaDetalle ObtenerDatosVentaServicios(int Row) { try { VentaDetalle DatosAux = new VentaDetalle(); bool Concluido = false; int IDEstatusServicio = 0; string IDVentaServ = string.Empty; DataGridViewRow Fila = this.dgvServicios.Rows[Row]; bool.TryParse(Fila.Cells["Concluido"].Value.ToString(), out Concluido); int.TryParse(Fila.Cells["IDEstatusServicio"].Value.ToString(), out IDEstatusServicio); IDVentaServ = Fila.Cells["IDVentaServicio"].Value.ToString(); string IDServicio = Fila.Cells["IDServicio"].Value.ToString(); string IDEmpleado = Fila.Cells["IDEmpleado"].Value.ToString(); DatosAux.IDVenta = this.DatosVenta.IDVenta; DatosAux.Concluido = Concluido; DatosAux.IDVentaServicio = IDVentaServ; DatosAux.IDEstatusServicio = IDEstatusServicio; DatosAux.IDEmpleado = IDEmpleado; DatosAux.IDServicio = IDServicio; DatosAux.Conexion = Comun.Conexion; DatosAux.IDUsuario = Comun.IDUsuario; DatosAux.IDSucursal = Comun.IDSucursalCaja; DatosAux.IDVenta = this.DatosVenta.IDVenta; return(DatosAux); } catch (Exception ex) { throw ex; } }
private void AgregarProducto(VentaDetalle DatosAux) { try { bool BandExiste = false; foreach (VentaDetalle Item in DetalleVenta) { if (Item.IDVentaDetalle == DatosAux.IDVentaDetalle) { Item.PrecioNormal = DatosAux.PrecioNormal; Item.CantidadVenta = DatosAux.CantidadVenta; Item.Subtotal = DatosAux.Subtotal; Item.Descuento = DatosAux.Descuento; Item.Total = DatosAux.Total; BandExiste = true; break; } } if (!BandExiste) { DetalleVenta.Add(DatosAux); } this.CargarGridVentaDetalle(); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(int id, [Bind("Id,IdVenta,IdProducto,Cantidad")] VentaDetalle ventaDetalle) { if (id != ventaDetalle.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ventaDetalle); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VentaDetalleExists(ventaDetalle.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(ventaDetalle)); }
private void QuitarItemLista(VentaDetalle Datos) { try { VentaDetalle AuxDel = null; foreach (VentaDetalle Item in DetalleVenta) { if (Item.IDVentaDetalle == Datos.IDVentaDetalle) { AuxDel = Item; break; } } if (AuxDel != null) { DetalleVenta.Remove(AuxDel); this.CargarGridVentaDetalle(); this.CalcularTotales(); } } catch (Exception ex) { throw ex; } }
private void btnAplicarVale_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(this.txtVale.Text.Trim())) { this.txtErrorVale.Visible = false; Vales Datos = new Vales { IDVenta = this.IDVenta, IDCliente = (DatosCliente != null ? DatosCliente.IDCliente : string.Empty), Folio = this.txtVale.Text.Trim(), IDUsuario = Comun.IDUsuario, Conexion = Comun.Conexion }; Venta_Negocio VN = new Venta_Negocio(); Cobro DatosAux = VN.AplicarVale(Datos); if (DatosAux.Completado) { this.txtVale.Text = string.Empty; this.IDVale = DatosAux.IDVale; this.CodigoVale = DatosAux.FolioVale; List <VentaDetalle> Lista = new List <VentaDetalle>(); VentaDetalle Item; DataTableReader Dr = DatosAux.TablaDatos.CreateDataReader(); while (Dr.Read()) { Item = new VentaDetalle(); Item.IDVentaDetalle = Dr.GetString(Dr.GetOrdinal("IDVentaDetalle")); Item.IDProducto = Dr.GetString(Dr.GetOrdinal("IDProducto")); Item.Clave = Dr.GetString(Dr.GetOrdinal("Clave")); Item.NombreProducto = Dr.GetString(Dr.GetOrdinal("NombreProducto")); Item.PrecioNormal = Dr.GetDecimal(Dr.GetOrdinal("Precio")); Item.CantidadVenta = Dr.GetDecimal(Dr.GetOrdinal("Cantidad")); Item.Subtotal = Dr.GetDecimal(Dr.GetOrdinal("Subtotal")); Item.Descuento = Dr.GetDecimal(Dr.GetOrdinal("Descuento")); Item.Total = Dr.GetDecimal(Dr.GetOrdinal("Total")); Lista.Add(Item); } this.DetalleVenta = Lista; this.CargarGridVentaDetalle(); this.ActiveControl = this.btnCobrar; this.btnCobrar.Focus(); } else { this.MensajeErrorVale(DatosAux.Resultado); this.ActiveControl = this.txtVale; this.txtVale.Focus(); } } } catch (Exception ex) { LogError.AddExcFileTxt(ex, "frmVentaDirecta ~ btnAplicarVale_Click"); MessageBox.Show(Comun.MensajeError, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGuardar_Click(object sender, EventArgs e) { try { this.txtMensajeError.Visible = false; List <Error> Errores = this.ValidarDatos(); if (Errores.Count == 0) { VentaDetalle Datos = this.ObtenerDatos(); Venta_Negocio VN = new Venta_Negocio(); bool Resultado = VN.IniciarServicio(Datos, Comun.Conexion, Comun.IDUsuario); if (Resultado) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Ocurrió un error. Intente nuevamente. Si el problema persiste, contacte a Soporte Técnico.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { this.MostrarMensajeError(Errores); } } catch (Exception ex) { LogError.AddExcFileTxt(ex, "frmNuevoServicioTicket ~ btnGuardar_Click"); MessageBox.Show(Comun.MensajeError, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public async Task <IActionResult> Create([Bind("Id,Date,IdUsuario")] VentaCabecera ventaCabecera) { if (ModelState.IsValid && ListProducts.Count > 0) { if (User.Identity.IsAuthenticated) { //var user = userManager.Id; //NO SIRVE var user = User.FindFirstValue(ClaimTypes.NameIdentifier); //SI Funciona! ventaCabecera.IdUsuario = user; var ListDetalle = new List <VentaDetalle>(); foreach (var item in ListProducts) { var ventaDetail = new VentaDetalle(); ventaDetail.ProductId = item.IdProduct; ventaDetail.Quantity = item.Quantity; ventaDetail.Price = _context.Product.Where(p => p.Id == item.IdProduct).FirstOrDefault().Price; ListDetalle.Add(ventaDetail); } ventaCabecera.Details = ListDetalle; _context.Add(ventaCabecera); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(ventaCabecera)); }
public void Eliminar(ApplicationDbContext Context) { if (!IsNew) { VentaDetalle model = this.ToModel(); Context.Entry(model).State = EntityState.Deleted; } }
private void btnEliminarItem_Click(object sender, EventArgs e) { if (lstvVenta.SelectedItems.Count > 0) { VentaDetalle.RemoveAt(lstvVenta.SelectedItems[0].Index); lstvVenta.Items.Remove(lstvVenta.SelectedItems[0]); } }
public ActionResult DeleteConfirmed(int id) { VentaDetalle ventaDetalle = db.VentaDetalles.Find(id); db.VentaDetalles.Remove(ventaDetalle); db.SaveChanges(); return(RedirectToAction("Index")); }
public VentaDetalle Build() { ValidarQueElProductoSeaParaVender(); ValidarValorNoMenorAlPermitido(); ValidarQueElProductoTengaExistencias(); VentaDetalle detalle = new VentaDetalle(this); return(detalle); }
public static int insertar(VentaDetalle ventaDetalle) { using (var db = new VentaEntities()) { db.VentaDetalle.Add(ventaDetalle); db.SaveChanges(); return(ventaDetalle.id); } }
private void btnCancelarServicio_Click(object sender, EventArgs e) { try { if (this.dgvServicios.SelectedRows.Count == 1) { int Row = this.dgvServicios.Rows.GetFirstRow(DataGridViewElementStates.Selected); VentaDetalle Datos = this.ObtenerDatosVentaServicios(Row); if (!string.IsNullOrEmpty(Datos.IDVentaServicio)) { if (!Datos.Concluido) { Venta_Negocio VN = new Venta_Negocio(); VN.QuitarServicio(Datos); if (Datos.Completado) { this.CargarGridServicios(); BandCambios = true; } else { if (Datos.Resultado == -1) { MessageBox.Show("No se puede completar la acción. El servicio ya está concluido.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Datos.Resultado == -2) { MessageBox.Show("No se puede completar la acción. El servicio tiene productos extra, debe quitarlos para continuar.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Datos.Resultado == -3) { MessageBox.Show("No se puede completar la acción. El servicio pertenece a un paquete.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("Ocurrió un error al guardar los datos. Código del error : " + Datos.Resultado, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("No se puede completar la acción. El servicio ya está concluido.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else { MessageBox.Show("Seleccione un registro.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { LogError.AddExcFileTxt(ex, "frmDatosServicio ~ btnCancelarServicio_Click"); MessageBox.Show(Comun.MensajeError, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ActualizarCantidadProducto(VentaDetalle Datos) { try { } catch (Exception ex) { throw ex; } }
private void btnRemoverVale_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(this.IDVale)) { Vales Datos = new Vales { IDVenta = this.IDVenta, IDCliente = DatosCliente.IDCliente, IDVale = this.IDVale, IDUsuario = Comun.IDUsuario, Conexion = Comun.Conexion }; Venta_Negocio VN = new Venta_Negocio(); Cobro DatosAux = VN.RemoverVale(Datos); if (DatosAux.Completado) { this.IDVale = string.Empty; this.CodigoVale = string.Empty; List <VentaDetalle> Lista = new List <VentaDetalle>(); VentaDetalle Item; DataTableReader Dr = DatosAux.TablaDatos.CreateDataReader(); while (Dr.Read()) { Item = new VentaDetalle(); Item.IDVentaDetalle = Dr.GetString(Dr.GetOrdinal("IDVentaDetalle")); Item.IDProducto = Dr.GetString(Dr.GetOrdinal("IDProducto")); Item.Clave = Dr.GetString(Dr.GetOrdinal("Clave")); Item.NombreProducto = Dr.GetString(Dr.GetOrdinal("NombreProducto")); Item.PrecioNormal = Dr.GetDecimal(Dr.GetOrdinal("Precio")); Item.CantidadVenta = Dr.GetDecimal(Dr.GetOrdinal("Cantidad")); Item.Subtotal = Dr.GetDecimal(Dr.GetOrdinal("Subtotal")); Item.Descuento = Dr.GetDecimal(Dr.GetOrdinal("Descuento")); Item.Total = Dr.GetDecimal(Dr.GetOrdinal("Total")); Lista.Add(Item); } this.DetalleVenta = Lista; this.CargarGridVentaDetalle(); this.ActiveControl = this.btnCobrar; this.btnCobrar.Focus(); } else { MessageBox.Show("Ocurrió un error. Código del error: " + DatosAux.Resultado, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { throw ex; } }
public JsonResult addProducto(int IdProducto, int cantidad) { var newProducto = new VentaDetalle(); newProducto.IdProducto = IdProducto; newProducto.Cantidad = cantidad; ventaDetalles.Add(newProducto); return(Json(ventaDetalles)); }
public async Task <IActionResult> Create([Bind("Id,IdVenta,IdProducto,Cantidad")] VentaDetalle ventaDetalle) { if (ModelState.IsValid) { _context.Add(ventaDetalle); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(ventaDetalle)); }
public static int actualizar(VentaDetalle ventaDetalle) { using (var db = new VentaEntities()) { var actual = db.VentaDetalle.Find(ventaDetalle.id); actual.idVenta = ventaDetalle.idVenta; actual.idProducto = ventaDetalle.idProducto; actual.cantidad = ventaDetalle.cantidad; actual.total = ventaDetalle.total; return(db.SaveChanges()); } }
public void ObtenerUsosXIDVentaServicio(VentaDetalle Datos) { try { Venta_Datos VD = new Venta_Datos(); VD.ObtenerUsosXIDVentaServicio(Datos); } catch (Exception ex) { throw ex; } }
public List <PedidoDetalle> LlenarComboClavesProduccion(VentaDetalle Datos) { try { Venta_Datos VD = new Venta_Datos(); return(VD.LlenarComboClavesProduccion(Datos)); } catch (Exception ex) { throw ex; } }
public void AgregarClaveAServicio(VentaDetalle Datos) { try { Venta_Datos VD = new Venta_Datos(); VD.AgregarClaveAServicio(Datos); } catch (Exception ex) { throw ex; } }
public ActionResult Edit([Bind(Include = "Id,MedicamentoId,Cantidad,Precio,VentaId")] VentaDetalle ventaDetalle) { if (ModelState.IsValid) { db.Entry(ventaDetalle).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MedicamentoId = new SelectList(db.Medicamentos, "Id", "Nombre", ventaDetalle.MedicamentoId); ViewBag.VentaId = new SelectList(db.Ventas, "Id", "Codigo", ventaDetalle.VentaId); return(View(ventaDetalle)); }
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; }