Compare commits
2 Commits
bcc377117d
...
c59d9cb1be
| Author | SHA1 | Date |
|---|---|---|
|
|
c59d9cb1be | |
|
|
b52519979c |
1244
docker/backup.sql
1244
docker/backup.sql
File diff suppressed because it is too large
Load Diff
|
|
@ -19,7 +19,6 @@ services:
|
|||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ../memberflow-api
|
||||
|
|
@ -37,8 +36,6 @@ services:
|
|||
JWT_SECRET: c2VjdXJlc2VjdXJlc2VjdXJlc2VjdXJlMTIzNDU2
|
||||
JWT_EXPIRATION: 7200000
|
||||
|
||||
|
||||
|
||||
frontend:
|
||||
build:
|
||||
context: ..
|
||||
|
|
@ -47,4 +44,14 @@ services:
|
|||
depends_on:
|
||||
- backend
|
||||
ports:
|
||||
- "3000:80"
|
||||
- "3000:80"
|
||||
|
||||
db-restore:
|
||||
image: mysql:8.0
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- ./backup.sql:/backup.sql
|
||||
- ./docker/initdb.sh:/docker-entrypoint-initdb.d/initdb.sh
|
||||
entrypoint: ["/bin/bash", "/docker-entrypoint-initdb.d/initdb.sh"]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
echo "Esperando a que MySQL esté disponible..."
|
||||
until mysql -h mysql -u root -p1234 -e "SELECT 1" > /dev/null 2>&1; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Restaurando base de datos desde backup.sql..."
|
||||
mysql -h mysql -u root -p1234 mf_db < /backup.sql
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.denniseckerskorn.services.finance_service;
|
||||
|
||||
import com.denniseckerskorn.entities.finance.Invoice;
|
||||
import com.denniseckerskorn.entities.finance.InvoiceLine;
|
||||
import com.denniseckerskorn.entities.finance.ProductService;
|
||||
import com.denniseckerskorn.entities.user_managment.users.Student;
|
||||
import com.itextpdf.kernel.pdf.PdfWriter;
|
||||
import com.itextpdf.kernel.pdf.PdfDocument;
|
||||
import com.itextpdf.layout.Document;
|
||||
|
|
@ -8,6 +11,7 @@ import com.itextpdf.layout.element.Paragraph;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Service
|
||||
public class InvoicePdfGenerator {
|
||||
|
|
@ -19,24 +23,65 @@ public class InvoicePdfGenerator {
|
|||
PdfDocument pdf = new PdfDocument(writer);
|
||||
Document doc = new Document(pdf);
|
||||
|
||||
doc.add(new Paragraph("Factura #" + invoice.getId()));
|
||||
// Cabecera
|
||||
doc.add(new Paragraph("FACTURA #" + invoice.getId()).setFontSize(16).setBold());
|
||||
doc.add(new Paragraph("Fecha: " + invoice.getDate()));
|
||||
doc.add(new Paragraph("Cliente: " + invoice.getUser().getName() + " " + invoice.getUser().getSurname()));
|
||||
doc.add(new Paragraph("Estado: " + invoice.getStatus()));
|
||||
doc.add(new Paragraph(" "));
|
||||
|
||||
// Información del cliente
|
||||
var user = invoice.getUser();
|
||||
doc.add(new Paragraph("Cliente: " + user.getName() + " " + user.getSurname()));
|
||||
doc.add(new Paragraph("Email: " + user.getEmail()));
|
||||
doc.add(new Paragraph("Teléfono: " + user.getPhoneNumber()));
|
||||
doc.add(new Paragraph("Dirección: " + user.getAddress()));
|
||||
|
||||
// Si es estudiante, mostrar info básica (sin tutor ni cinturón)
|
||||
Student student = user.getStudent();
|
||||
if (student != null) {
|
||||
doc.add(new Paragraph("DNI: " + student.getDni()));
|
||||
doc.add(new Paragraph("Fecha de nacimiento: " + student.getBirthdate()));
|
||||
}
|
||||
|
||||
doc.add(new Paragraph(" "));
|
||||
doc.add(new Paragraph("Detalle de productos:"));
|
||||
|
||||
invoice.getInvoiceLines().forEach(line -> {
|
||||
String product = line.getProductService().getName();
|
||||
int qty = line.getQuantity();
|
||||
var price = line.getUnitPrice();
|
||||
var total = line.getSubtotal();
|
||||
doc.add(new Paragraph("- " + product + " x" + qty + " - " + price + " € = " + total + " €"));
|
||||
});
|
||||
// Detalle de productos
|
||||
doc.add(new Paragraph("Detalle de productos:").setBold());
|
||||
doc.add(new Paragraph("Producto | Cant. | Precio | IVA % | Subtotal (sin IVA) | IVA"));
|
||||
|
||||
BigDecimal totalSubtotal = BigDecimal.ZERO;
|
||||
BigDecimal totalIVA = BigDecimal.ZERO;
|
||||
|
||||
for (InvoiceLine line : invoice.getInvoiceLines()) {
|
||||
ProductService product = line.getProductService();
|
||||
String nombre = product.getName();
|
||||
int cantidad = line.getQuantity();
|
||||
BigDecimal unitPrice = line.getUnitPrice(); // sin IVA
|
||||
BigDecimal subtotalSinIVA = unitPrice.multiply(BigDecimal.valueOf(cantidad));
|
||||
BigDecimal porcentajeIVA = product.getIvaType().getPercentage();
|
||||
BigDecimal iva = subtotalSinIVA.multiply(porcentajeIVA).divide(BigDecimal.valueOf(100));
|
||||
|
||||
totalSubtotal = totalSubtotal.add(subtotalSinIVA);
|
||||
totalIVA = totalIVA.add(iva);
|
||||
|
||||
doc.add(new Paragraph(
|
||||
nombre + " | " +
|
||||
cantidad + " | " +
|
||||
unitPrice + " € | " +
|
||||
porcentajeIVA + "% | " +
|
||||
subtotalSinIVA + " € | " +
|
||||
iva + " €"
|
||||
));
|
||||
}
|
||||
|
||||
// Totales
|
||||
doc.add(new Paragraph(" "));
|
||||
doc.add(new Paragraph("Subtotal (sin IVA): " + totalSubtotal + " €").setBold());
|
||||
doc.add(new Paragraph("IVA total: " + totalIVA + " €").setBold());
|
||||
doc.add(new Paragraph("TOTAL: " + totalSubtotal.add(totalIVA) + " €").setFontSize(14).setBold());
|
||||
|
||||
doc.add(new Paragraph(" "));
|
||||
doc.add(new Paragraph("TOTAL: " + invoice.getTotal() + " €"));
|
||||
doc.add(new Paragraph("Gracias por su compra.").setItalic());
|
||||
|
||||
doc.close();
|
||||
return out.toByteArray();
|
||||
|
|
|
|||
Loading…
Reference in New Issue