Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/sic/controller/ProductoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.data.domain.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sic.aspect.AccesoRolesPermitidos;
import sic.modelo.*;
Expand Down Expand Up @@ -139,6 +143,18 @@ public void getListaDePrecios(
}
}

@GetMapping("/productos/reporte")
public ResponseEntity<byte[]> getListaProductosSeleccionados(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The response should be sent by email

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case doesn't require the response to be send by email, the requirement is obtain a report of the chosen products the same way that others like Factura and Pedidos do, the email one it's beacause usualy whitout a product selection the list is to big and the request take to long

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user selects X (a very big number) products and sends the request? It's gonna crush. We need to cover all possible scenarios

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happens that the access to the business email account it's only to very few people, and the new feature it's to vendedor use as "Presupuesto". Now I notice a problem, to use this as a vendedor we have to let it access to the product administration list, then the real solution it's to have a real "Presupuesto" report, this do not solve the original problem and carry a new one.

@RequestParam long[] idProducto) {
HttpHeaders headers = new HttpHeaders();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use "var" instead

headers.setContentType(MediaType.APPLICATION_PDF);
headers.add("content-disposition", "inline; filename=ProductList.pdf");
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
byte[] reportePDF =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use "var" instead, and all in one line

productoService.getListaDePreciosEnPdf(idProducto);
return new ResponseEntity<>(reportePDF, headers, HttpStatus.OK);
}

@DeleteMapping("/productos")
@AccesoRolesPermitidos({Rol.ADMINISTRADOR})
public void eliminarMultiplesProductos(@RequestParam long[] idProducto) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/sic/service/IProductoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ BigDecimal calcularGananciaPorcentaje(

void getListaDePreciosEnPdf(BusquedaProductoCriteria criteria, long idSucursal);

byte[] getListaDePreciosEnPdf(long[] idProductos);

void enviarListaDeProductosPorEmail(String mailTo, byte[] listaDeProductos, String formato);

Producto guardar(NuevoProductoDTO producto, long idMedida, long idRubro, long idProveedor);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/sic/service/impl/ProductoServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,15 @@ public void getListaDePreciosEnPdf(BusquedaProductoCriteria criteria, long idSuc
this.getListaDePrecios(productos, FORMATO_PDF), FORMATO_PDF);
}

@Override
public byte[] getListaDePreciosEnPdf(long[] idProductos) {
var productos = new ArrayList<Producto>();
for (long idProducto : idProductos) {
productos.add(this.getProductoNoEliminadoPorId(idProducto));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very inefficient. The query should be something like SELECT xxxx FROM xxxx WHERE IN .....

}
return this.getListaDePrecios(productos, FORMATO_PDF);
}

@Override
public void enviarListaDeProductosPorEmail(String mailTo, byte[] listaDeProductos, String formato) {
emailService.enviarEmail(
Expand Down