public IHttpActionResult PostDETALLE_FACTURA(DETALLE_FACTURA dETALLE_FACTURA) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.DETALLE_FACTURA.Add(dETALLE_FACTURA); try { db.SaveChanges(); } catch (DbUpdateException) { if (DETALLE_FACTURAExists(dETALLE_FACTURA.DETALLE_FACTURA_ID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = dETALLE_FACTURA.DETALLE_FACTURA_ID }, dETALLE_FACTURA)); }
public IHttpActionResult PutDETALLE_FACTURA(decimal id, DETALLE_FACTURA dETALLE_FACTURA) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dETALLE_FACTURA.DETALLE_FACTURA_ID) { return(BadRequest()); } db.Entry(dETALLE_FACTURA).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DETALLE_FACTURAExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int AgregarDetalleFactura() { Detalle_factura df = new Detalle_factura(); DETALLE_FACTURA dff = new DETALLE_FACTURA(); dff.ID_OT = df.Id_ot; dff.ID_FACTURA = df.Id_factura; ModeloEntidades.AddToDETALLE_FACTURA(dff); return(ModeloEntidades.SaveChanges()); }
public IHttpActionResult GetDETALLE_FACTURA(decimal id) { DETALLE_FACTURA dETALLE_FACTURA = db.DETALLE_FACTURA.Find(id); if (dETALLE_FACTURA == null) { return(NotFound()); } return(Ok(dETALLE_FACTURA)); }
public IHttpActionResult Post(DETALLE_FACTURA d) { try { DetFacturaBLL.Create(d); return(Content(HttpStatusCode.OK, "Message: \n\tCompra Exitosa" + "\nGracias por preferirnos")); } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, "Solicitud no procesada")); } }
public IHttpActionResult DeleteDETALLE_FACTURA(decimal id) { DETALLE_FACTURA dETALLE_FACTURA = db.DETALLE_FACTURA.Find(id); if (dETALLE_FACTURA == null) { return(NotFound()); } db.DETALLE_FACTURA.Remove(dETALLE_FACTURA); db.SaveChanges(); return(Ok(dETALLE_FACTURA)); }
public async Task <ActionResult> GUARDARVENTA([Bind(Include = "id_producto,cantidad")] DETALLE_FACTURA detallefactura) { if (ModelState.IsValid) { comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = " SELECT TOP 1 * FROM ENCABEZADO_FACTURA ORDER BY id_encabezado_factura DESC"; informacion = conexion.EjecutarComandosInformacion(comando); PRODUCTO producto = await db.PRODUCTOes.FindAsync(detallefactura.id_producto); detallefactura.total = detallefactura.cantidad * producto.precio_venta; if (informacion.Rows.Count > 1) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { foreach (DataRow row in informacion.Rows) { detallefactura.id_encabezado_factura = Convert.ToInt32(row["id_encabezado_factura"]); } } comando = new SqlCommand(); comando.CommandType = CommandType.Text; comando.CommandText = " SELECT TOP 1 * FROM DETALLE_FACTURA ORDER BY id_detalle_factura DESC"; informacion = conexion.EjecutarComandosInformacion(comando); if (informacion.Rows.Count > 1) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { foreach (DataRow row in informacion.Rows) { detallefactura.id_detalle_factura = Convert.ToInt32(row["id_detalle_factura"]) + 1; } } db.DETALLE_FACTURA.Add(detallefactura); await db.SaveChangesAsync(); return(RedirectToAction("DETALLESVENTA")); } ViewBag.id_producto = new SelectList(db.PRODUCTOes, "id_producto", "nombre"); return(View(detallefactura)); }
// GET: VENTAS/DETALLESVENTA/5 public async Task <ActionResult> ELIMINARDETALLE(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DETALLE_FACTURA dETALLE_FACTURA = await db.DETALLE_FACTURA.FindAsync(id); if (dETALLE_FACTURA == null) { return(HttpNotFound()); } db.DETALLE_FACTURA.Remove(dETALLE_FACTURA); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public static void Create(DETALLE_FACTURA df) { using (DeliveryEntidades1 db = new DeliveryEntidades1()) { using (var transaction = db.Database.BeginTransaction()) { try { db.DETALLE_FACTURA.Add(df); db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine("No se ha podido crear el detalle de factura" + ex.Message); transaction.Rollback(); throw ex; } } } }
public static void Delete(int?id) { using (DeliveryEntidades1 db = new DeliveryEntidades1()) { using (var transaction = db.Database.BeginTransaction()) { try { DETALLE_FACTURA df = db.DETALLE_FACTURA.Find(id); db.Entry(df).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine("No se ha podido eliminar el detalle de factura " + ex.Message); transaction.Rollback(); throw ex; } } } }
public static void Update(DETALLE_FACTURA df) { using (DeliveryEntidades1 db = new DeliveryEntidades1()) { using (var transaction = db.Database.BeginTransaction()) { try { db.DETALLE_FACTURA.Attach(df); db.Entry(df).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine("No se ha podido actualizar la factura " + ex.Message); transaction.Rollback(); throw ex; } } } }
public int ModificarDetalleFacturaByID(int ID_DETALLE_FAC, int ID_OT, int ID_FACTURA) { int resultado = 0; DETALLE_FACTURA detalle_fac = new DETALLE_FACTURA(); Detalle_factura df = new Detalle_factura(); df.Id_detalle_fac = ID_DETALLE_FAC; df.Id_ot = ID_OT; df.Id_factura = ID_FACTURA; detalle_fac.ID_DETALLE_FAC = df.Id_detalle_fac; detalle_fac.ID_OT = df.Id_ot; detalle_fac.ID_FACTURA = df.Id_factura; EntityKey key = ModeloEntidades.CreateEntityKey("SIAFEntities.DETALLE_FACTURA", detalle_fac); Object ActualizaDetalleFactura; // se crea esta variable segun actualizacion, ahora es usuario, luego puede ser ActualizaProducto if (ModeloEntidades.TryGetObjectByKey(key, out ActualizaDetalleFactura)) { ModeloEntidades.ApplyCurrentValues(key.EntitySetName, detalle_fac); resultado = ModeloEntidades.SaveChanges(); } return(resultado); }
public void generarFactura() { EntitiesNoMasAccidentes bd = new EntitiesNoMasAccidentes(); DateTime fechaActual = DateTime.Now; DateTime primerDiaMes = new DateTime(fechaActual.Year, fechaActual.Month - 1, 1); DateTime ultimoDiaMes = primerDiaMes.AddMonths(1).AddDays(-1); //Contratos Activos y con fecha de vencimiento menor a la fecha actual List <Models.CONTRATO> contratos = bd.CONTRATO.ToList().FindAll(x => x.ACTIVO.Equals("S") & x.FECHA_FIN_CONTRATO >= fechaActual); //Obtener actividades que se generaron entre el primer y ultimo dia del mes(Mes anterior ya que la factura se genera el primero de cada mes) List <Models.ACTIVIDAD> actividades = bd.ACTIVIDAD.ToList().FindAll(x => x.FECHA_ACTIVIDAD >= primerDiaMes && x.FECHA_ACTIVIDAD <= ultimoDiaMes); //Creacion de factura NoMasAccidentes.Models.FACTURA factura = new FACTURA(); foreach (var contrato in contratos) { //Buscar actividades del cliente del contrato var actividad = actividades.FindAll(x => x.CLIENTE_ID_CLIENTE == contrato.CLIENTE_ID_CLIENTE); var totalActividades = actividad.Sum(x => x.TIPO_ACTIVIDAD.VALOR_ACTIVIDAD); //Calcular Fecha de vencimiento DateTime fechaVencimiento = ultimoDiaMes.AddMonths(1); //Calcular Sub Total var subTtotal = contrato.PLAN.VALOR + totalActividades; //Calcular IVA var iva = Math.Round((subTtotal / 100) * 19); //Calcular Total var total = iva + subTtotal; //Agregar Factura factura.CONTRATO_ID_CONTRATO = contrato.ID_CONTRATO; factura.FECHA = fechaActual; factura.PAGADO = "N"; factura.SUBTOTAL = subTtotal; factura.TOTAL = total; factura.IVA = iva; factura.FECHA_VENCIMIENTO = fechaVencimiento; factura.NOMBRE_PLAN = contrato.PLAN.NOMBRE; factura.VALOR_PLAN = contrato.PLAN.VALOR; factura.NOMBRE_CLIENTE = contrato.CLIENTE.NOMBRE_CLIENTE + " " + contrato.CLIENTE.APELLIDO_CLIENTE; factura.DIRECCION_CLIENTE = contrato.CLIENTE.DIREC_CLIENTE; factura.RUT_CLIENTE = contrato.CLIENTE.RUT_CLIENTE; factura.CORREO_ELECTRONICO_CLIENTE = contrato.CLIENTE.CORREO_CLIENTE; bd.FACTURA.Add(factura); bd.SaveChanges(); //Detalle Factura foreach (var acti in actividad) { //Creacion de detalleFactura NoMasAccidentes.Models.DETALLE_FACTURA detalleFactura = new DETALLE_FACTURA(); detalleFactura.NOMBRE_ACTIVIDAD_EXTRA = acti.TIPO_ACTIVIDAD.TIPO_ACTIVIDAD1; detalleFactura.VALOR_ACTIVIDAD_EXTRA = acti.TIPO_ACTIVIDAD.VALOR_ACTIVIDAD; detalleFactura.DETALLE_ACTIVIDAD = "Actividad Realizada el " + acti.FECHA_ACTIVIDAD.ToString("D") + " Por el Profesional a Cargo: " + acti.PERSONAL.NOMBRE_PERSO + " " + acti.PERSONAL.APELLIDOP_PERSO; detalleFactura.FACTURA_ID_FACTURA = bd.FACTURA.Max(x => x.ID_FACTURA); bd.DETALLE_FACTURA.Add(detalleFactura); bd.SaveChanges(); } } }