Add Factura and Proveedor entities; establish relationships with Item and update SQL schema
This commit is contained in:
parent
d8d7c089bb
commit
37afb26f59
|
|
@ -18,3 +18,4 @@ public class DataInitializer {
|
|||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package com.ieslamar.GestionInventario.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Table(name = "factura")
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Factura {
|
||||
|
||||
@Id
|
||||
@Column(name = "idfactura")
|
||||
private Integer id;
|
||||
@Column
|
||||
private byte[] foto;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDate fecha;
|
||||
|
||||
@Column(name = "fin_garantia",nullable = false)
|
||||
private LocalDate fechaGarantia;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Double importe;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String numero;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "proveedores_idproveedores")
|
||||
private Proveedor proveedor;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -42,4 +42,9 @@ public class Item {
|
|||
|
||||
@OneToMany(mappedBy = "item")
|
||||
private List<Valor> valores;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "factura_idfactura")
|
||||
private Factura factura;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.ieslamar.GestionInventario.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "proveedores") // Nombre de la tabla en MySQL
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Proveedor {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "idproveedores")
|
||||
private Integer id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String nombre;
|
||||
|
||||
@OneToMany(mappedBy = "proveedor")
|
||||
private List<Factura> facturas;
|
||||
|
||||
}
|
||||
|
|
@ -141,6 +141,41 @@ CREATE TABLE IF NOT EXISTS `inventario`.`producto` (
|
|||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `inventario`.`proveedores`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `inventario`.`proveedores` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `inventario`.`proveedores` (
|
||||
`idproveedores` INT NOT NULL,
|
||||
`nombre` VARCHAR(45) NOT NULL,
|
||||
PRIMARY KEY (`idproveedores`))
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `inventario`.`factura`
|
||||
-- -----------------------------------------------------
|
||||
DROP TABLE IF EXISTS `inventario`.`factura` ;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `inventario`.`factura` (
|
||||
`idfactura` INT NOT NULL,
|
||||
`foto` LONGBLOB NULL,
|
||||
`fecha` DATE NOT NULL,
|
||||
`fin_garantia` DATE NOT NULL,
|
||||
`importe` DOUBLE NOT NULL,
|
||||
`numero` VARCHAR(45) NOT NULL,
|
||||
`proveedores_idproveedores` INT NOT NULL,
|
||||
PRIMARY KEY (`idfactura`),
|
||||
INDEX `fk_factura_proveedores1_idx` (`proveedores_idproveedores` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_factura_proveedores1`
|
||||
FOREIGN KEY (`proveedores_idproveedores`)
|
||||
REFERENCES `inventario`.`proveedores` (`idproveedores`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `inventario`.`item`
|
||||
-- -----------------------------------------------------
|
||||
|
|
@ -153,10 +188,12 @@ CREATE TABLE IF NOT EXISTS `inventario`.`item` (
|
|||
`users_id` BIGINT NOT NULL,
|
||||
`ubicacion_idubicacion` INT NOT NULL,
|
||||
`producto_idproducto` INT NOT NULL,
|
||||
`factura_idfactura` INT NOT NULL,
|
||||
PRIMARY KEY (`iditem`),
|
||||
INDEX `fk_item_users1_idx` (`users_id` ASC) VISIBLE,
|
||||
INDEX `fk_item_ubicacion1_idx` (`ubicacion_idubicacion` ASC) VISIBLE,
|
||||
INDEX `fk_item_producto1_idx` (`producto_idproducto` ASC) VISIBLE,
|
||||
INDEX `fk_item_factura1_idx` (`factura_idfactura` ASC) VISIBLE,
|
||||
CONSTRAINT `fk_item_users1`
|
||||
FOREIGN KEY (`users_id`)
|
||||
REFERENCES `inventario`.`users` (`id`)
|
||||
|
|
@ -171,6 +208,11 @@ CREATE TABLE IF NOT EXISTS `inventario`.`item` (
|
|||
FOREIGN KEY (`producto_idproducto`)
|
||||
REFERENCES `inventario`.`producto` (`idproducto`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_item_factura1`
|
||||
FOREIGN KEY (`factura_idfactura`)
|
||||
REFERENCES `inventario`.`factura` (`idfactura`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue