Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table productos
- (
- productosCodigo varchar(10),
- productosDescripcion varchar(100) not null,
- productosPrecio decimal(9,2),
- productosStock decimal(9,2),
- productosValorDelStock AS (productosPrecio * productosStock),
- constraint productosPK Primary key (productosCodigo)
- );
- commit;
- create table facturas
- (
- facturasNumeroFactura varchar(7),
- facturasFecha Date,
- facturasMontoSinIGV decimal(9,2),
- facturasPorcentajeDeIGV decimal(8,5),
- clientesCodigo varchar(15),
- facturasMontoIGV AS (facturasMontoSinIGV * facturasPorcentajeDeIGV),
- facturasMontoTotal AS (facturasMontoSinIGV + facturasMontoSinIGV *
- facturasPorcentajeDeIGV ),
- constraint facturasPK primary key (facturasNumeroFactura),
- constraint facturasClienteFK foreign key (clientesCodigo) references
- clientes (clientesCodigo)
- );
- commit;
- create table detallesFacturas
- (
- facturasNumeroSerie varchar(7),
- facturasNumeroFactura varchar(7),
- productosCodigo varchar(10),
- detalleCantidadVendida decimal(9,2),
- detallePrecioVenta decimal(9,2),
- detalleOImporte AS (detalleCantidadVendida * detallePrecioVenta),
- constraint detalleFacturaPK Primary key (facturasNumeroSerie),
- constraint detalleFacturaFacturasFK foreign key (facturasNumeroFactura)
- references facturas (facturasNumeroFactura),
- constraint detalleFacturaProductosFK foreign key (productosCodigo)
- references productos (productosCodigo)
- );
- commit;
- package com.unjfsc.rest.test.model;
- import java.io.Serializable;
- import java.math.BigDecimal;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import javax.persistence.JoinColumn;
- import javax.persistence.ManyToOne;
- import javax.persistence.Table;
- import org.hibernate.validator.constraints.NotBlank;
- @Entity
- @Table(name="detallesFacturas")
- public class detalleFactura implements Serializable{
- public static final long serialVersionUID = 1L;
- @Id
- @NotBlank
- @Column(name="facturasNumeroSerie")
- private String id_detFacturas;
- @ManyToOne
- @JoinColumn(name="productosCodigo")
- private producto tblproducto;
- @ManyToOne
- @JoinColumn(name="facturasNumeroFactura")
- private factura tblfactura;
- private BigDecimal detalleCantidadVendida;
- private BigDecimal detallePrecioVenta;
- public detalleFactura() {
- }
- //CONSTRUCTOR
- //GETTERS AND SETTERS
- }
- package com.unjfsc.rest.test.repository;
- import java.util.Optional;
- import org.springframework.data.jpa.repository.JpaRepository;
- import com.unjfsc.rest.test.model.detalleFactura;
- public interface detalleFacturaRepository extends
- JpaRepository<detalleFactura, String>{
- }
- package com.unjfsc.rest.test.service;
- import java.util.List;
- import javax.persistence.EntityManager;
- import javax.persistence.PersistenceContext;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.unjfsc.rest.test.model.detalleFactura;
- import com.unjfsc.rest.test.repository.detalleFacturaRepository;
- @Service
- public class detalleFacturaService {
- @PersistenceContext
- private EntityManager em;
- @Autowired
- public detalleFacturaRepository detalleFacturaRepository;
- public List<detalleFactura>obtenerTodos()
- {
- return detalleFacturaRepository.findAll();
- }
- }
- package com.unjfsc.rest.controller;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.unjfsc.rest.test.model.detalleFactura;
- import com.unjfsc.rest.test.service.detalleFacturaService;
- @RestController
- public class detalleFacturaController {
- @Autowired
- private detalleFacturaService detalleFacturaService;
- @GetMapping(value="/hello")
- public ResponseEntity<List<detalleFactura>>obtenerUsuarios()
- {
- return new ResponseEntity<List<detalleFactura>>
- (detalleFacturaService.obtenerTodos(), HttpStatus.OK);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement