Compare commits

..

No commits in common. "c59d9cb1bed88b86224e846fb582d18a91546e95" and "bcc377117dde47ca7487bf2e48bab81988dd4abf" have entirely different histories.

4 changed files with 1095 additions and 243 deletions

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,7 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
backend: backend:
build: build:
context: ../memberflow-api context: ../memberflow-api
@ -36,6 +37,8 @@ services:
JWT_SECRET: c2VjdXJlc2VjdXJlc2VjdXJlc2VjdXJlMTIzNDU2 JWT_SECRET: c2VjdXJlc2VjdXJlc2VjdXJlc2VjdXJlMTIzNDU2
JWT_EXPIRATION: 7200000 JWT_EXPIRATION: 7200000
frontend: frontend:
build: build:
context: .. context: ..
@ -44,14 +47,4 @@ services:
depends_on: depends_on:
- backend - backend
ports: 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"]

View File

@ -1,8 +0,0 @@
#!/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

View File

@ -1,9 +1,6 @@
package com.denniseckerskorn.services.finance_service; package com.denniseckerskorn.services.finance_service;
import com.denniseckerskorn.entities.finance.Invoice; 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.PdfWriter;
import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.layout.Document; import com.itextpdf.layout.Document;
@ -11,7 +8,6 @@ import com.itextpdf.layout.element.Paragraph;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
@Service @Service
public class InvoicePdfGenerator { public class InvoicePdfGenerator {
@ -23,65 +19,24 @@ public class InvoicePdfGenerator {
PdfDocument pdf = new PdfDocument(writer); PdfDocument pdf = new PdfDocument(writer);
Document doc = new Document(pdf); Document doc = new Document(pdf);
// Cabecera doc.add(new Paragraph("Factura #" + invoice.getId()));
doc.add(new Paragraph("FACTURA #" + invoice.getId()).setFontSize(16).setBold());
doc.add(new Paragraph("Fecha: " + invoice.getDate())); 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("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(" "));
doc.add(new Paragraph("Detalle de productos:"));
// Detalle de productos invoice.getInvoiceLines().forEach(line -> {
doc.add(new Paragraph("Detalle de productos:").setBold()); String product = line.getProductService().getName();
doc.add(new Paragraph("Producto | Cant. | Precio | IVA % | Subtotal (sin IVA) | IVA")); int qty = line.getQuantity();
var price = line.getUnitPrice();
BigDecimal totalSubtotal = BigDecimal.ZERO; var total = line.getSubtotal();
BigDecimal totalIVA = BigDecimal.ZERO; doc.add(new Paragraph("- " + product + " x" + qty + " - " + price + " € = " + total + ""));
});
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(" "));
doc.add(new Paragraph("Gracias por su compra.").setItalic()); doc.add(new Paragraph("TOTAL: " + invoice.getTotal() + ""));
doc.close(); doc.close();
return out.toByteArray(); return out.toByteArray();