Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. create table productos
  2. (
  3. productosCodigo varchar(10),
  4. productosDescripcion varchar(100) not null,
  5. productosPrecio decimal(9,2),
  6. productosStock decimal(9,2),
  7. productosValorDelStock AS (productosPrecio * productosStock),
  8. constraint productosPK Primary key (productosCodigo)
  9. );
  10. commit;
  11.  
  12.  
  13.  
  14. create table facturas
  15. (
  16. facturasNumeroFactura varchar(7),
  17. facturasFecha Date,
  18. facturasMontoSinIGV decimal(9,2),
  19. facturasPorcentajeDeIGV decimal(8,5),
  20. clientesCodigo varchar(15),
  21. facturasMontoIGV AS (facturasMontoSinIGV * facturasPorcentajeDeIGV),
  22. facturasMontoTotal AS (facturasMontoSinIGV + facturasMontoSinIGV *
  23. facturasPorcentajeDeIGV ),
  24. constraint facturasPK primary key (facturasNumeroFactura),
  25. constraint facturasClienteFK foreign key (clientesCodigo) references
  26. clientes (clientesCodigo)
  27. );
  28. commit;
  29.  
  30.  
  31.  
  32. create table detallesFacturas
  33. (
  34. facturasNumeroSerie varchar(7),
  35. facturasNumeroFactura varchar(7),
  36. productosCodigo varchar(10),
  37. detalleCantidadVendida decimal(9,2),
  38. detallePrecioVenta decimal(9,2),
  39. detalleOImporte AS (detalleCantidadVendida * detallePrecioVenta),
  40. constraint detalleFacturaPK Primary key (facturasNumeroSerie),
  41. constraint detalleFacturaFacturasFK foreign key (facturasNumeroFactura)
  42. references facturas (facturasNumeroFactura),
  43. constraint detalleFacturaProductosFK foreign key (productosCodigo)
  44. references productos (productosCodigo)
  45. );
  46. commit;
  47.  
  48. package com.unjfsc.rest.test.model;
  49.  
  50. import java.io.Serializable;
  51. import java.math.BigDecimal;
  52.  
  53. import javax.persistence.Column;
  54. import javax.persistence.Entity;
  55. import javax.persistence.Id;
  56. import javax.persistence.JoinColumn;
  57. import javax.persistence.ManyToOne;
  58. import javax.persistence.Table;
  59.  
  60. import org.hibernate.validator.constraints.NotBlank;
  61.  
  62.  
  63. @Entity
  64. @Table(name="detallesFacturas")
  65. public class detalleFactura implements Serializable{
  66. public static final long serialVersionUID = 1L;
  67.  
  68. @Id
  69. @NotBlank
  70. @Column(name="facturasNumeroSerie")
  71. private String id_detFacturas;
  72.  
  73. @ManyToOne
  74. @JoinColumn(name="productosCodigo")
  75. private producto tblproducto;
  76.  
  77. @ManyToOne
  78. @JoinColumn(name="facturasNumeroFactura")
  79. private factura tblfactura;
  80.  
  81. private BigDecimal detalleCantidadVendida;
  82.  
  83. private BigDecimal detallePrecioVenta;
  84.  
  85. public detalleFactura() {
  86.  
  87. }
  88.  
  89. //CONSTRUCTOR
  90. //GETTERS AND SETTERS
  91.  
  92. }
  93.  
  94. package com.unjfsc.rest.test.repository;
  95.  
  96. import java.util.Optional;
  97.  
  98. import org.springframework.data.jpa.repository.JpaRepository;
  99.  
  100. import com.unjfsc.rest.test.model.detalleFactura;
  101.  
  102. public interface detalleFacturaRepository extends
  103. JpaRepository<detalleFactura, String>{
  104.  
  105. }
  106.  
  107. package com.unjfsc.rest.test.service;
  108.  
  109. import java.util.List;
  110.  
  111. import javax.persistence.EntityManager;
  112. import javax.persistence.PersistenceContext;
  113.  
  114. import org.springframework.beans.factory.annotation.Autowired;
  115. import org.springframework.stereotype.Service;
  116.  
  117. import com.unjfsc.rest.test.model.detalleFactura;
  118. import com.unjfsc.rest.test.repository.detalleFacturaRepository;
  119.  
  120. @Service
  121. public class detalleFacturaService {
  122.  
  123. @PersistenceContext
  124. private EntityManager em;
  125.  
  126. @Autowired
  127. public detalleFacturaRepository detalleFacturaRepository;
  128.  
  129. public List<detalleFactura>obtenerTodos()
  130. {
  131. return detalleFacturaRepository.findAll();
  132. }
  133.  
  134.  
  135. }
  136.  
  137. package com.unjfsc.rest.controller;
  138.  
  139. import java.util.List;
  140.  
  141. import org.springframework.beans.factory.annotation.Autowired;
  142. import org.springframework.http.HttpStatus;
  143. import org.springframework.http.ResponseEntity;
  144. import org.springframework.web.bind.annotation.GetMapping;
  145. import org.springframework.web.bind.annotation.RestController;
  146.  
  147. import com.unjfsc.rest.test.model.detalleFactura;
  148. import com.unjfsc.rest.test.service.detalleFacturaService;
  149.  
  150. @RestController
  151. public class detalleFacturaController {
  152.  
  153. @Autowired
  154. private detalleFacturaService detalleFacturaService;
  155.  
  156. @GetMapping(value="/hello")
  157.  
  158. public ResponseEntity<List<detalleFactura>>obtenerUsuarios()
  159. {
  160.  
  161. return new ResponseEntity<List<detalleFactura>>
  162. (detalleFacturaService.obtenerTodos(), HttpStatus.OK);
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement