Compare commits
22 Commits
prova
...
feat/cad-b
| Author | SHA1 | Date | |
|---|---|---|---|
| cc36c0a18b | |||
| 47e22c5a61 | |||
| c2161ef1fc | |||
|
|
8f6e74cf02 | ||
| 767b65008b | |||
| 1b3f0b16ff | |||
| 179be37a36 | |||
|
|
412f3ae71b | ||
| 0f2f2bc7a9 | |||
| 685cd704e7 | |||
| 09179ce825 | |||
| 27d0399263 | |||
| 0f57034b52 | |||
| db748fb649 | |||
| 6eb0629136 | |||
| 8bd4ea54b2 | |||
| d951212576 | |||
| e23bca0734 | |||
| f5cdaf51cb | |||
| 476dc5b2ce | |||
| 548b23317f | |||
| 9d40e74baf |
@@ -10,11 +10,13 @@ RUN ./gradlew bootJar -x test --no-daemon
|
||||
|
||||
# Stage 2: Runtime Environment
|
||||
FROM eclipse-temurin:21-jre-jammy
|
||||
ARG ORCA_VERSION=2.3.1
|
||||
ARG ORCA_DOWNLOAD_URL
|
||||
|
||||
# Install system dependencies for OrcaSlicer (same as before)
|
||||
RUN apt-get update && apt-get install -y \
|
||||
wget \
|
||||
p7zip-full \
|
||||
assimp-utils \
|
||||
libgl1 \
|
||||
libglib2.0-0 \
|
||||
libgtk-3-0 \
|
||||
@@ -24,14 +26,42 @@ RUN apt-get update && apt-get install -y \
|
||||
|
||||
# Install OrcaSlicer
|
||||
WORKDIR /opt
|
||||
RUN wget -q https://github.com/SoftFever/OrcaSlicer/releases/download/v2.2.0/OrcaSlicer_Linux_V2.2.0.AppImage -O OrcaSlicer.AppImage \
|
||||
&& 7z x OrcaSlicer.AppImage -o/opt/orcaslicer \
|
||||
RUN set -eux; \
|
||||
ORCA_URL="${ORCA_DOWNLOAD_URL:-}"; \
|
||||
if [ -n "${ORCA_URL}" ]; then \
|
||||
wget -q "${ORCA_URL}" -O OrcaSlicer.AppImage; \
|
||||
else \
|
||||
CANDIDATES="\
|
||||
https://github.com/OrcaSlicer/OrcaSlicer/releases/download/v${ORCA_VERSION}/OrcaSlicer_Linux_AppImage_Ubuntu2204_V${ORCA_VERSION}.AppImage \
|
||||
https://github.com/SoftFever/OrcaSlicer/releases/download/v${ORCA_VERSION}/OrcaSlicer_Linux_AppImage_Ubuntu2204_V${ORCA_VERSION}.AppImage \
|
||||
https://github.com/SoftFever/OrcaSlicer/releases/download/v2.2.0/OrcaSlicer_Linux_V2.2.0.AppImage"; \
|
||||
ok=0; \
|
||||
for url in $CANDIDATES; do \
|
||||
if wget -q --spider "$url"; then \
|
||||
echo "Using OrcaSlicer URL: $url"; \
|
||||
wget -q "$url" -O OrcaSlicer.AppImage; \
|
||||
ok=1; \
|
||||
break; \
|
||||
fi; \
|
||||
done; \
|
||||
if [ "$ok" -ne 1 ]; then \
|
||||
echo "Failed to find OrcaSlicer AppImage for version ${ORCA_VERSION}" >&2; \
|
||||
echo "Tried URLs:" >&2; \
|
||||
for url in $CANDIDATES; do echo " - $url" >&2; done; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi \
|
||||
&& chmod +x OrcaSlicer.AppImage \
|
||||
&& rm -rf /opt/orcaslicer /opt/squashfs-root \
|
||||
&& ./OrcaSlicer.AppImage --appimage-extract >/dev/null \
|
||||
&& mv /opt/squashfs-root /opt/orcaslicer \
|
||||
&& chmod -R +x /opt/orcaslicer \
|
||||
&& rm OrcaSlicer.AppImage
|
||||
|
||||
ENV PATH="/opt/orcaslicer/usr/bin:${PATH}"
|
||||
# Set Slicer Path env variable for Java app
|
||||
ENV SLICER_PATH="/opt/orcaslicer/AppRun"
|
||||
ENV ASSIMP_PATH="assimp"
|
||||
|
||||
WORKDIR /app
|
||||
# Copy JAR from build stage
|
||||
|
||||
@@ -42,6 +42,15 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'net.codecrete.qrbill:qrbill-generator:3.4.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-mail'
|
||||
implementation platform('org.lwjgl:lwjgl-bom:3.3.4')
|
||||
implementation 'org.lwjgl:lwjgl'
|
||||
implementation 'org.lwjgl:lwjgl-assimp'
|
||||
runtimeOnly 'org.lwjgl:lwjgl::natives-linux'
|
||||
runtimeOnly 'org.lwjgl:lwjgl::natives-macos'
|
||||
runtimeOnly 'org.lwjgl:lwjgl::natives-macos-arm64'
|
||||
runtimeOnly 'org.lwjgl:lwjgl-assimp::natives-linux'
|
||||
runtimeOnly 'org.lwjgl:lwjgl-assimp::natives-macos'
|
||||
runtimeOnly 'org.lwjgl:lwjgl-assimp::natives-macos-arm64'
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.Year;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -53,6 +55,9 @@ public class CustomQuoteRequestController {
|
||||
@Value("${app.mail.contact-request.admin.address:infog@3d-fab.ch}")
|
||||
private String contactRequestAdminMailAddress;
|
||||
|
||||
@Value("${app.mail.contact-request.customer.enabled:true}")
|
||||
private boolean contactRequestCustomerMailEnabled;
|
||||
|
||||
// TODO: Inject Storage Service
|
||||
private static final Path STORAGE_ROOT = Paths.get("storage_requests").toAbsolutePath().normalize();
|
||||
private static final Pattern SAFE_EXTENSION_PATTERN = Pattern.compile("^[a-z0-9]{1,10}$");
|
||||
@@ -97,6 +102,7 @@ public class CustomQuoteRequestController {
|
||||
"Accettazione Termini e Privacy obbligatoria."
|
||||
);
|
||||
}
|
||||
String language = normalizeLanguage(requestDto.getLanguage());
|
||||
|
||||
// 1. Create Request
|
||||
CustomQuoteRequest request = new CustomQuoteRequest();
|
||||
@@ -173,6 +179,7 @@ public class CustomQuoteRequestController {
|
||||
}
|
||||
|
||||
sendAdminContactRequestNotification(request, attachmentsCount);
|
||||
sendCustomerContactRequestConfirmation(request, attachmentsCount, language);
|
||||
|
||||
return ResponseEntity.ok(request);
|
||||
}
|
||||
@@ -258,6 +265,252 @@ public class CustomQuoteRequestController {
|
||||
);
|
||||
}
|
||||
|
||||
private void sendCustomerContactRequestConfirmation(CustomQuoteRequest request, int attachmentsCount, String language) {
|
||||
if (!contactRequestCustomerMailEnabled) {
|
||||
return;
|
||||
}
|
||||
if (request.getEmail() == null || request.getEmail().isBlank()) {
|
||||
logger.warn("Contact request confirmation skipped: missing customer email for request {}", request.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> templateData = new HashMap<>();
|
||||
templateData.put("requestId", request.getId());
|
||||
templateData.put(
|
||||
"createdAt",
|
||||
request.getCreatedAt().format(
|
||||
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(localeForLanguage(language))
|
||||
)
|
||||
);
|
||||
templateData.put("recipientName", resolveRecipientName(request, language));
|
||||
templateData.put("requestType", localizeRequestType(request.getRequestType(), language));
|
||||
templateData.put("customerType", localizeCustomerType(request.getCustomerType(), language));
|
||||
templateData.put("name", safeValue(request.getName()));
|
||||
templateData.put("companyName", safeValue(request.getCompanyName()));
|
||||
templateData.put("contactPerson", safeValue(request.getContactPerson()));
|
||||
templateData.put("email", safeValue(request.getEmail()));
|
||||
templateData.put("phone", safeValue(request.getPhone()));
|
||||
templateData.put("message", safeValue(request.getMessage()));
|
||||
templateData.put("attachmentsCount", attachmentsCount);
|
||||
templateData.put("currentYear", Year.now().getValue());
|
||||
String subject = applyCustomerContactRequestTexts(templateData, language, request.getId());
|
||||
|
||||
emailNotificationService.sendEmail(
|
||||
request.getEmail(),
|
||||
subject,
|
||||
"contact-request-customer",
|
||||
templateData
|
||||
);
|
||||
}
|
||||
|
||||
private String applyCustomerContactRequestTexts(
|
||||
Map<String, Object> templateData,
|
||||
String language,
|
||||
UUID requestId
|
||||
) {
|
||||
return switch (language) {
|
||||
case "en" -> {
|
||||
templateData.put("emailTitle", "Contact request received");
|
||||
templateData.put("headlineText", "We received your contact request");
|
||||
templateData.put("greetingText", "Hi " + templateData.get("recipientName") + ",");
|
||||
templateData.put("introText", "Thank you for contacting us. Our team will reply as soon as possible.");
|
||||
templateData.put("requestIdHintText", "Please keep this request ID for future order references:");
|
||||
templateData.put("detailsTitleText", "Request details");
|
||||
templateData.put("labelRequestId", "Request ID");
|
||||
templateData.put("labelDate", "Date");
|
||||
templateData.put("labelRequestType", "Request type");
|
||||
templateData.put("labelCustomerType", "Customer type");
|
||||
templateData.put("labelName", "Name");
|
||||
templateData.put("labelCompany", "Company");
|
||||
templateData.put("labelContactPerson", "Contact person");
|
||||
templateData.put("labelEmail", "Email");
|
||||
templateData.put("labelPhone", "Phone");
|
||||
templateData.put("labelMessage", "Message");
|
||||
templateData.put("labelAttachments", "Attachments");
|
||||
templateData.put("supportText", "If you need help, reply to this email.");
|
||||
templateData.put("footerText", "Automated request-receipt confirmation from 3D-Fab.");
|
||||
yield "We received your contact request #" + requestId + " - 3D-Fab";
|
||||
}
|
||||
case "de" -> {
|
||||
templateData.put("emailTitle", "Kontaktanfrage erhalten");
|
||||
templateData.put("headlineText", "Wir haben Ihre Kontaktanfrage erhalten");
|
||||
templateData.put("greetingText", "Hallo " + templateData.get("recipientName") + ",");
|
||||
templateData.put("introText", "Vielen Dank fuer Ihre Anfrage. Unser Team antwortet Ihnen so schnell wie moeglich.");
|
||||
templateData.put("requestIdHintText", "Bitte speichern Sie diese Anfrage-ID fuer zukuenftige Bestellreferenzen:");
|
||||
templateData.put("detailsTitleText", "Anfragedetails");
|
||||
templateData.put("labelRequestId", "Anfrage-ID");
|
||||
templateData.put("labelDate", "Datum");
|
||||
templateData.put("labelRequestType", "Anfragetyp");
|
||||
templateData.put("labelCustomerType", "Kundentyp");
|
||||
templateData.put("labelName", "Name");
|
||||
templateData.put("labelCompany", "Firma");
|
||||
templateData.put("labelContactPerson", "Kontaktperson");
|
||||
templateData.put("labelEmail", "E-Mail");
|
||||
templateData.put("labelPhone", "Telefon");
|
||||
templateData.put("labelMessage", "Nachricht");
|
||||
templateData.put("labelAttachments", "Anhaenge");
|
||||
templateData.put("supportText", "Wenn Sie Hilfe brauchen, antworten Sie auf diese E-Mail.");
|
||||
templateData.put("footerText", "Automatische Bestaetigung des Anfrageeingangs von 3D-Fab.");
|
||||
yield "Wir haben Ihre Kontaktanfrage erhalten #" + requestId + " - 3D-Fab";
|
||||
}
|
||||
case "fr" -> {
|
||||
templateData.put("emailTitle", "Demande de contact recue");
|
||||
templateData.put("headlineText", "Nous avons recu votre demande de contact");
|
||||
templateData.put("greetingText", "Bonjour " + templateData.get("recipientName") + ",");
|
||||
templateData.put("introText", "Merci pour votre message. Notre equipe vous repondra des que possible.");
|
||||
templateData.put("requestIdHintText", "Veuillez conserver cet ID de demande pour vos futures references de commande :");
|
||||
templateData.put("detailsTitleText", "Details de la demande");
|
||||
templateData.put("labelRequestId", "ID de demande");
|
||||
templateData.put("labelDate", "Date");
|
||||
templateData.put("labelRequestType", "Type de demande");
|
||||
templateData.put("labelCustomerType", "Type de client");
|
||||
templateData.put("labelName", "Nom");
|
||||
templateData.put("labelCompany", "Entreprise");
|
||||
templateData.put("labelContactPerson", "Contact");
|
||||
templateData.put("labelEmail", "Email");
|
||||
templateData.put("labelPhone", "Telephone");
|
||||
templateData.put("labelMessage", "Message");
|
||||
templateData.put("labelAttachments", "Pieces jointes");
|
||||
templateData.put("supportText", "Si vous avez besoin d'aide, repondez a cet email.");
|
||||
templateData.put("footerText", "Confirmation automatique de reception de demande par 3D-Fab.");
|
||||
yield "Nous avons recu votre demande de contact #" + requestId + " - 3D-Fab";
|
||||
}
|
||||
default -> {
|
||||
templateData.put("emailTitle", "Richiesta di contatto ricevuta");
|
||||
templateData.put("headlineText", "Abbiamo ricevuto la tua richiesta di contatto");
|
||||
templateData.put("greetingText", "Ciao " + templateData.get("recipientName") + ",");
|
||||
templateData.put("introText", "Grazie per averci contattato. Il nostro team ti rispondera' il prima possibile.");
|
||||
templateData.put("requestIdHintText", "Conserva questo ID richiesta per i futuri riferimenti d'ordine:");
|
||||
templateData.put("detailsTitleText", "Dettagli richiesta");
|
||||
templateData.put("labelRequestId", "ID richiesta");
|
||||
templateData.put("labelDate", "Data");
|
||||
templateData.put("labelRequestType", "Tipo richiesta");
|
||||
templateData.put("labelCustomerType", "Tipo cliente");
|
||||
templateData.put("labelName", "Nome");
|
||||
templateData.put("labelCompany", "Azienda");
|
||||
templateData.put("labelContactPerson", "Contatto");
|
||||
templateData.put("labelEmail", "Email");
|
||||
templateData.put("labelPhone", "Telefono");
|
||||
templateData.put("labelMessage", "Messaggio");
|
||||
templateData.put("labelAttachments", "Allegati");
|
||||
templateData.put("supportText", "Se hai bisogno, rispondi direttamente a questa email.");
|
||||
templateData.put("footerText", "Conferma automatica di ricezione richiesta da 3D-Fab.");
|
||||
yield "Abbiamo ricevuto la tua richiesta di contatto #" + requestId + " - 3D-Fab";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private String localizeRequestType(String requestType, String language) {
|
||||
if (requestType == null || requestType.isBlank()) {
|
||||
return "-";
|
||||
}
|
||||
|
||||
String normalized = requestType.trim().toLowerCase(Locale.ROOT);
|
||||
return switch (language) {
|
||||
case "en" -> switch (normalized) {
|
||||
case "custom", "print_service" -> "Custom part request";
|
||||
case "series" -> "Series production request";
|
||||
case "consult", "design_service" -> "Consultation request";
|
||||
case "question" -> "General question";
|
||||
default -> requestType;
|
||||
};
|
||||
case "de" -> switch (normalized) {
|
||||
case "custom", "print_service" -> "Anfrage fuer Einzelteil";
|
||||
case "series" -> "Anfrage fuer Serienproduktion";
|
||||
case "consult", "design_service" -> "Beratungsanfrage";
|
||||
case "question" -> "Allgemeine Frage";
|
||||
default -> requestType;
|
||||
};
|
||||
case "fr" -> switch (normalized) {
|
||||
case "custom", "print_service" -> "Demande de piece personnalisee";
|
||||
case "series" -> "Demande de production en serie";
|
||||
case "consult", "design_service" -> "Demande de conseil";
|
||||
case "question" -> "Question generale";
|
||||
default -> requestType;
|
||||
};
|
||||
default -> switch (normalized) {
|
||||
case "custom", "print_service" -> "Richiesta pezzo personalizzato";
|
||||
case "series" -> "Richiesta produzione in serie";
|
||||
case "consult", "design_service" -> "Richiesta consulenza";
|
||||
case "question" -> "Domanda generale";
|
||||
default -> requestType;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
private String localizeCustomerType(String customerType, String language) {
|
||||
if (customerType == null || customerType.isBlank()) {
|
||||
return "-";
|
||||
}
|
||||
String normalized = customerType.trim().toLowerCase(Locale.ROOT);
|
||||
return switch (language) {
|
||||
case "en" -> switch (normalized) {
|
||||
case "private" -> "Private";
|
||||
case "business" -> "Business";
|
||||
default -> customerType;
|
||||
};
|
||||
case "de" -> switch (normalized) {
|
||||
case "private" -> "Privat";
|
||||
case "business" -> "Unternehmen";
|
||||
default -> customerType;
|
||||
};
|
||||
case "fr" -> switch (normalized) {
|
||||
case "private" -> "Prive";
|
||||
case "business" -> "Entreprise";
|
||||
default -> customerType;
|
||||
};
|
||||
default -> switch (normalized) {
|
||||
case "private" -> "Privato";
|
||||
case "business" -> "Azienda";
|
||||
default -> customerType;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
private Locale localeForLanguage(String language) {
|
||||
return switch (language) {
|
||||
case "en" -> Locale.ENGLISH;
|
||||
case "de" -> Locale.GERMAN;
|
||||
case "fr" -> Locale.FRENCH;
|
||||
default -> Locale.ITALIAN;
|
||||
};
|
||||
}
|
||||
|
||||
private String normalizeLanguage(String language) {
|
||||
if (language == null || language.isBlank()) {
|
||||
return "it";
|
||||
}
|
||||
String normalized = language.toLowerCase(Locale.ROOT).trim();
|
||||
if (normalized.startsWith("en")) {
|
||||
return "en";
|
||||
}
|
||||
if (normalized.startsWith("de")) {
|
||||
return "de";
|
||||
}
|
||||
if (normalized.startsWith("fr")) {
|
||||
return "fr";
|
||||
}
|
||||
return "it";
|
||||
}
|
||||
|
||||
private String resolveRecipientName(CustomQuoteRequest request, String language) {
|
||||
if (request.getName() != null && !request.getName().isBlank()) {
|
||||
return request.getName().trim();
|
||||
}
|
||||
if (request.getContactPerson() != null && !request.getContactPerson().isBlank()) {
|
||||
return request.getContactPerson().trim();
|
||||
}
|
||||
if (request.getCompanyName() != null && !request.getCompanyName().isBlank()) {
|
||||
return request.getCompanyName().trim();
|
||||
}
|
||||
return switch (language) {
|
||||
case "en" -> "customer";
|
||||
case "de" -> "Kunde";
|
||||
case "fr" -> "client";
|
||||
default -> "cliente";
|
||||
};
|
||||
}
|
||||
|
||||
private String safeValue(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return "-";
|
||||
|
||||
@@ -301,6 +301,11 @@ public class OrderController {
|
||||
dto.setShippingCostChf(order.getShippingCostChf());
|
||||
dto.setDiscountChf(order.getDiscountChf());
|
||||
dto.setSubtotalChf(order.getSubtotalChf());
|
||||
dto.setIsCadOrder(order.getIsCadOrder());
|
||||
dto.setSourceRequestId(order.getSourceRequestId());
|
||||
dto.setCadHours(order.getCadHours());
|
||||
dto.setCadHourlyRateChf(order.getCadHourlyRateChf());
|
||||
dto.setCadTotalChf(order.getCadTotalChf());
|
||||
dto.setTotalChf(order.getTotalChf());
|
||||
dto.setCreatedAt(order.getCreatedAt());
|
||||
dto.setShippingSameAsBilling(order.getShippingSameAsBilling());
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.printcalculator.repository.QuoteLineItemRepository;
|
||||
import com.printcalculator.repository.QuoteSessionRepository;
|
||||
import com.printcalculator.service.OrcaProfileResolver;
|
||||
import com.printcalculator.service.QuoteCalculator;
|
||||
import com.printcalculator.service.QuoteSessionTotalsService;
|
||||
import com.printcalculator.service.SlicerService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -42,6 +43,9 @@ import java.util.Optional;
|
||||
import java.util.Locale;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/quote-sessions")
|
||||
@@ -59,6 +63,7 @@ public class QuoteSessionController {
|
||||
private final OrcaProfileResolver orcaProfileResolver;
|
||||
private final com.printcalculator.repository.PricingPolicyRepository pricingRepo;
|
||||
private final com.printcalculator.service.ClamAVService clamAVService;
|
||||
private final QuoteSessionTotalsService quoteSessionTotalsService;
|
||||
|
||||
public QuoteSessionController(QuoteSessionRepository sessionRepo,
|
||||
QuoteLineItemRepository lineItemRepo,
|
||||
@@ -69,7 +74,8 @@ public class QuoteSessionController {
|
||||
FilamentVariantRepository variantRepo,
|
||||
OrcaProfileResolver orcaProfileResolver,
|
||||
com.printcalculator.repository.PricingPolicyRepository pricingRepo,
|
||||
com.printcalculator.service.ClamAVService clamAVService) {
|
||||
com.printcalculator.service.ClamAVService clamAVService,
|
||||
QuoteSessionTotalsService quoteSessionTotalsService) {
|
||||
this.sessionRepo = sessionRepo;
|
||||
this.lineItemRepo = lineItemRepo;
|
||||
this.slicerService = slicerService;
|
||||
@@ -80,6 +86,7 @@ public class QuoteSessionController {
|
||||
this.orcaProfileResolver = orcaProfileResolver;
|
||||
this.pricingRepo = pricingRepo;
|
||||
this.clamAVService = clamAVService;
|
||||
this.quoteSessionTotalsService = quoteSessionTotalsService;
|
||||
}
|
||||
|
||||
// 1. Start a new empty session
|
||||
@@ -120,7 +127,10 @@ public class QuoteSessionController {
|
||||
|
||||
// Helper to add item
|
||||
private QuoteLineItem addItemToSession(QuoteSession session, MultipartFile file, com.printcalculator.dto.PrintSettingsDto settings) throws IOException {
|
||||
if (file.isEmpty()) throw new IOException("File is empty");
|
||||
if (file.isEmpty()) throw new IllegalArgumentException("File is empty");
|
||||
if ("CONVERTED".equals(session.getStatus())) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Cannot modify a converted session");
|
||||
}
|
||||
|
||||
// Scan for virus
|
||||
clamAVService.scan(file.getInputStream());
|
||||
@@ -146,9 +156,16 @@ public class QuoteSessionController {
|
||||
Files.copy(inputStream, persistentPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
Path convertedPersistentPath = null;
|
||||
try {
|
||||
// Apply Basic/Advanced Logic
|
||||
applyPrintSettings(settings);
|
||||
boolean cadSession = "CAD_ACTIVE".equals(session.getStatus());
|
||||
|
||||
// In CAD sessions, print settings are locked server-side.
|
||||
if (cadSession) {
|
||||
enforceCadPrintSettings(session, settings);
|
||||
} else {
|
||||
applyPrintSettings(settings);
|
||||
}
|
||||
|
||||
BigDecimal nozzleDiameter = BigDecimal.valueOf(settings.getNozzleDiameter() != null ? settings.getNozzleDiameter() : 0.4);
|
||||
|
||||
@@ -158,14 +175,27 @@ public class QuoteSessionController {
|
||||
// Resolve selected filament variant
|
||||
FilamentVariant selectedVariant = resolveFilamentVariant(settings);
|
||||
|
||||
if (cadSession
|
||||
&& session.getMaterialCode() != null
|
||||
&& selectedVariant.getFilamentMaterialType() != null
|
||||
&& selectedVariant.getFilamentMaterialType().getMaterialCode() != null) {
|
||||
String lockedMaterial = normalizeRequestedMaterialCode(session.getMaterialCode());
|
||||
String selectedMaterial = normalizeRequestedMaterialCode(selectedVariant.getFilamentMaterialType().getMaterialCode());
|
||||
if (!lockedMaterial.equals(selectedMaterial)) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Selected filament does not match locked CAD material");
|
||||
}
|
||||
}
|
||||
|
||||
// Update session global settings from the most recent item added
|
||||
session.setMaterialCode(selectedVariant.getFilamentMaterialType().getMaterialCode());
|
||||
session.setNozzleDiameterMm(nozzleDiameter);
|
||||
session.setLayerHeightMm(BigDecimal.valueOf(settings.getLayerHeight() != null ? settings.getLayerHeight() : 0.2));
|
||||
session.setInfillPattern(settings.getInfillPattern());
|
||||
session.setInfillPercent(settings.getInfillDensity() != null ? settings.getInfillDensity().intValue() : 20);
|
||||
session.setSupportsEnabled(settings.getSupportsEnabled() != null ? settings.getSupportsEnabled() : false);
|
||||
sessionRepo.save(session);
|
||||
if (!cadSession) {
|
||||
session.setMaterialCode(selectedVariant.getFilamentMaterialType().getMaterialCode());
|
||||
session.setNozzleDiameterMm(nozzleDiameter);
|
||||
session.setLayerHeightMm(BigDecimal.valueOf(settings.getLayerHeight() != null ? settings.getLayerHeight() : 0.2));
|
||||
session.setInfillPattern(settings.getInfillPattern());
|
||||
session.setInfillPercent(settings.getInfillDensity() != null ? settings.getInfillDensity().intValue() : 20);
|
||||
session.setSupportsEnabled(settings.getSupportsEnabled() != null ? settings.getSupportsEnabled() : false);
|
||||
sessionRepo.save(session);
|
||||
}
|
||||
|
||||
OrcaProfileResolver.ResolvedProfiles profiles = orcaProfileResolver.resolve(machine, nozzleDiameter, selectedVariant);
|
||||
String machineProfile = profiles.machineProfileName();
|
||||
@@ -183,9 +213,20 @@ public class QuoteSessionController {
|
||||
if (settings.getInfillDensity() != null) processOverrides.put("sparse_infill_density", settings.getInfillDensity() + "%");
|
||||
if (settings.getInfillPattern() != null) processOverrides.put("sparse_infill_pattern", settings.getInfillPattern());
|
||||
|
||||
Path slicerInputPath = persistentPath;
|
||||
if ("3mf".equals(ext)) {
|
||||
String convertedFilename = UUID.randomUUID() + "-converted.stl";
|
||||
convertedPersistentPath = sessionStorageDir.resolve(convertedFilename).normalize();
|
||||
if (!convertedPersistentPath.startsWith(sessionStorageDir)) {
|
||||
throw new IOException("Invalid converted STL storage path");
|
||||
}
|
||||
slicerService.convert3mfToPersistentStl(persistentPath.toFile(), convertedPersistentPath);
|
||||
slicerInputPath = convertedPersistentPath;
|
||||
}
|
||||
|
||||
// 3. Slice (Use persistent path)
|
||||
PrintStats stats = slicerService.slice(
|
||||
persistentPath.toFile(),
|
||||
slicerInputPath.toFile(),
|
||||
machineProfile,
|
||||
filamentProfile,
|
||||
processProfile,
|
||||
@@ -193,7 +234,7 @@ public class QuoteSessionController {
|
||||
processOverrides
|
||||
);
|
||||
|
||||
Optional<ModelDimensions> modelDimensions = slicerService.inspectModelDimensions(persistentPath.toFile());
|
||||
Optional<ModelDimensions> modelDimensions = slicerService.inspectModelDimensions(slicerInputPath.toFile());
|
||||
|
||||
// 4. Calculate Quote
|
||||
QuoteResult result = quoteCalculator.calculate(stats, machine.getPrinterDisplayName(), selectedVariant);
|
||||
@@ -216,6 +257,9 @@ public class QuoteSessionController {
|
||||
Map<String, Object> breakdown = new HashMap<>();
|
||||
breakdown.put("machine_cost", result.getTotalPrice()); // Excludes setup fee which is at session level
|
||||
breakdown.put("setup_fee", 0);
|
||||
if (convertedPersistentPath != null) {
|
||||
breakdown.put("convertedStoredPath", QUOTE_STORAGE_ROOT.relativize(convertedPersistentPath).toString());
|
||||
}
|
||||
item.setPricingBreakdown(breakdown);
|
||||
|
||||
// Dimensions for shipping/package checks are computed server-side from the uploaded model.
|
||||
@@ -237,6 +281,9 @@ public class QuoteSessionController {
|
||||
} catch (Exception e) {
|
||||
// Cleanup if failed
|
||||
Files.deleteIfExists(persistentPath);
|
||||
if (convertedPersistentPath != null) {
|
||||
Files.deleteIfExists(convertedPersistentPath);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -272,6 +319,16 @@ public class QuoteSessionController {
|
||||
}
|
||||
}
|
||||
|
||||
private void enforceCadPrintSettings(QuoteSession session, com.printcalculator.dto.PrintSettingsDto settings) {
|
||||
settings.setComplexityMode("ADVANCED");
|
||||
settings.setMaterial(session.getMaterialCode() != null ? session.getMaterialCode() : "PLA");
|
||||
settings.setNozzleDiameter(session.getNozzleDiameterMm() != null ? session.getNozzleDiameterMm().doubleValue() : 0.4);
|
||||
settings.setLayerHeight(session.getLayerHeightMm() != null ? session.getLayerHeightMm().doubleValue() : 0.2);
|
||||
settings.setInfillPattern(session.getInfillPattern() != null ? session.getInfillPattern() : "grid");
|
||||
settings.setInfillDensity(session.getInfillPercent() != null ? session.getInfillPercent().doubleValue() : 20.0);
|
||||
settings.setSupportsEnabled(Boolean.TRUE.equals(session.getSupportsEnabled()));
|
||||
}
|
||||
|
||||
private PrinterMachine resolvePrinterMachine(Long printerMachineId) {
|
||||
if (printerMachineId != null) {
|
||||
PrinterMachine selected = machineRepo.findById(printerMachineId)
|
||||
@@ -326,6 +383,32 @@ public class QuoteSessionController {
|
||||
.replaceAll("\\s+", " ");
|
||||
}
|
||||
|
||||
private int parsePositiveQuantity(Object raw) {
|
||||
if (raw == null) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Quantity is required");
|
||||
}
|
||||
|
||||
int quantity;
|
||||
if (raw instanceof Number number) {
|
||||
double numericValue = number.doubleValue();
|
||||
if (!Double.isFinite(numericValue)) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Quantity must be a finite number");
|
||||
}
|
||||
quantity = (int) Math.floor(numericValue);
|
||||
} else {
|
||||
try {
|
||||
quantity = Integer.parseInt(String.valueOf(raw).trim());
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Quantity must be an integer");
|
||||
}
|
||||
}
|
||||
|
||||
if (quantity < 1) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Quantity must be >= 1");
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
// 3. Update Line Item
|
||||
@PatchMapping("/line-items/{lineItemId}")
|
||||
@Transactional
|
||||
@@ -336,11 +419,19 @@ public class QuoteSessionController {
|
||||
QuoteLineItem item = lineItemRepo.findById(lineItemId)
|
||||
.orElseThrow(() -> new RuntimeException("Item not found"));
|
||||
|
||||
QuoteSession session = item.getQuoteSession();
|
||||
if ("CONVERTED".equals(session.getStatus())) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "Cannot modify a converted session");
|
||||
}
|
||||
|
||||
if (updates.containsKey("quantity")) {
|
||||
item.setQuantity((Integer) updates.get("quantity"));
|
||||
item.setQuantity(parsePositiveQuantity(updates.get("quantity")));
|
||||
}
|
||||
if (updates.containsKey("color_code")) {
|
||||
item.setColorCode((String) updates.get("color_code"));
|
||||
Object colorValue = updates.get("color_code");
|
||||
if (colorValue != null) {
|
||||
item.setColorCode(String.valueOf(colorValue));
|
||||
}
|
||||
}
|
||||
|
||||
// Recalculate price if needed?
|
||||
@@ -376,25 +467,7 @@ public class QuoteSessionController {
|
||||
.orElseThrow(() -> new RuntimeException("Session not found"));
|
||||
|
||||
List<QuoteLineItem> items = lineItemRepo.findByQuoteSessionId(id);
|
||||
|
||||
// Calculate Totals and global session hours
|
||||
BigDecimal itemsTotal = BigDecimal.ZERO;
|
||||
BigDecimal totalSeconds = BigDecimal.ZERO;
|
||||
|
||||
for (QuoteLineItem item : items) {
|
||||
BigDecimal lineTotal = item.getUnitPriceChf().multiply(BigDecimal.valueOf(item.getQuantity()));
|
||||
itemsTotal = itemsTotal.add(lineTotal);
|
||||
|
||||
if (item.getPrintTimeSeconds() != null) {
|
||||
totalSeconds = totalSeconds.add(BigDecimal.valueOf(item.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(item.getQuantity())));
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal totalHours = totalSeconds.divide(BigDecimal.valueOf(3600), 4, RoundingMode.HALF_UP);
|
||||
com.printcalculator.entity.PricingPolicy policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||
BigDecimal globalMachineCost = quoteCalculator.calculateSessionMachineCost(policy, totalHours);
|
||||
|
||||
itemsTotal = itemsTotal.add(globalMachineCost);
|
||||
QuoteSessionTotalsService.QuoteSessionTotals totals = quoteSessionTotalsService.compute(session, items);
|
||||
|
||||
// Map items to DTO to embed distributed machine cost
|
||||
List<Map<String, Object>> itemsDto = new ArrayList<>();
|
||||
@@ -408,58 +481,30 @@ public class QuoteSessionController {
|
||||
dto.put("colorCode", item.getColorCode());
|
||||
dto.put("filamentVariantId", item.getFilamentVariant() != null ? item.getFilamentVariant().getId() : null);
|
||||
dto.put("status", item.getStatus());
|
||||
dto.put("convertedStoredPath", extractConvertedStoredPath(item));
|
||||
|
||||
BigDecimal unitPrice = item.getUnitPriceChf();
|
||||
if (totalSeconds.compareTo(BigDecimal.ZERO) > 0 && item.getPrintTimeSeconds() != null) {
|
||||
BigDecimal itemSeconds = BigDecimal.valueOf(item.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(item.getQuantity()));
|
||||
BigDecimal share = itemSeconds.divide(totalSeconds, 8, RoundingMode.HALF_UP);
|
||||
BigDecimal itemMachineCost = globalMachineCost.multiply(share);
|
||||
BigDecimal unitMachineCost = itemMachineCost.divide(BigDecimal.valueOf(item.getQuantity()), 2, RoundingMode.HALF_UP);
|
||||
BigDecimal unitPrice = item.getUnitPriceChf() != null ? item.getUnitPriceChf() : BigDecimal.ZERO;
|
||||
int quantity = item.getQuantity() != null && item.getQuantity() > 0 ? item.getQuantity() : 1;
|
||||
if (totals.totalPrintSeconds().compareTo(BigDecimal.ZERO) > 0 && item.getPrintTimeSeconds() != null) {
|
||||
BigDecimal itemSeconds = BigDecimal.valueOf(item.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(quantity));
|
||||
BigDecimal share = itemSeconds.divide(totals.totalPrintSeconds(), 8, RoundingMode.HALF_UP);
|
||||
BigDecimal itemMachineCost = totals.globalMachineCostChf().multiply(share);
|
||||
BigDecimal unitMachineCost = itemMachineCost.divide(BigDecimal.valueOf(quantity), 2, RoundingMode.HALF_UP);
|
||||
unitPrice = unitPrice.add(unitMachineCost);
|
||||
}
|
||||
dto.put("unitPriceChf", unitPrice);
|
||||
itemsDto.add(dto);
|
||||
}
|
||||
|
||||
BigDecimal setupFee = session.getSetupCostChf() != null ? session.getSetupCostChf() : BigDecimal.ZERO;
|
||||
|
||||
// Calculate shipping cost based on dimensions
|
||||
boolean exceedsBaseSize = false;
|
||||
for (QuoteLineItem item : items) {
|
||||
BigDecimal x = item.getBoundingBoxXMm() != null ? item.getBoundingBoxXMm() : BigDecimal.ZERO;
|
||||
BigDecimal y = item.getBoundingBoxYMm() != null ? item.getBoundingBoxYMm() : BigDecimal.ZERO;
|
||||
BigDecimal z = item.getBoundingBoxZMm() != null ? item.getBoundingBoxZMm() : BigDecimal.ZERO;
|
||||
|
||||
BigDecimal[] dims = {x, y, z};
|
||||
java.util.Arrays.sort(dims);
|
||||
|
||||
if (dims[2].compareTo(BigDecimal.valueOf(250.0)) > 0 ||
|
||||
dims[1].compareTo(BigDecimal.valueOf(176.0)) > 0 ||
|
||||
dims[0].compareTo(BigDecimal.valueOf(20.0)) > 0) {
|
||||
exceedsBaseSize = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int totalQuantity = items.stream()
|
||||
.mapToInt(i -> i.getQuantity() != null ? i.getQuantity() : 1)
|
||||
.sum();
|
||||
|
||||
BigDecimal shippingCostChf;
|
||||
if (exceedsBaseSize) {
|
||||
shippingCostChf = totalQuantity > 5 ? BigDecimal.valueOf(9.00) : BigDecimal.valueOf(4.00);
|
||||
} else {
|
||||
shippingCostChf = BigDecimal.valueOf(2.00);
|
||||
}
|
||||
|
||||
BigDecimal grandTotal = itemsTotal.add(setupFee).add(shippingCostChf);
|
||||
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("session", session);
|
||||
response.put("items", itemsDto);
|
||||
response.put("itemsTotalChf", itemsTotal); // Includes the base cost of all items + the global tiered machine cost
|
||||
response.put("shippingCostChf", shippingCostChf);
|
||||
response.put("globalMachineCostChf", globalMachineCost); // Provide it so frontend knows how much it was (optional now)
|
||||
response.put("grandTotalChf", grandTotal);
|
||||
response.put("printItemsTotalChf", totals.printItemsTotalChf());
|
||||
response.put("cadTotalChf", totals.cadTotalChf());
|
||||
response.put("itemsTotalChf", totals.itemsTotalChf());
|
||||
response.put("shippingCostChf", totals.shippingCostChf());
|
||||
response.put("globalMachineCostChf", totals.globalMachineCostChf());
|
||||
response.put("grandTotalChf", totals.grandTotalChf());
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
@@ -468,7 +513,8 @@ public class QuoteSessionController {
|
||||
@GetMapping(value = "/{sessionId}/line-items/{lineItemId}/content")
|
||||
public ResponseEntity<org.springframework.core.io.Resource> downloadLineItemContent(
|
||||
@PathVariable UUID sessionId,
|
||||
@PathVariable UUID lineItemId
|
||||
@PathVariable UUID lineItemId,
|
||||
@RequestParam(name = "preview", required = false, defaultValue = "false") boolean preview
|
||||
) throws IOException {
|
||||
QuoteLineItem item = lineItemRepo.findById(lineItemId)
|
||||
.orElseThrow(() -> new RuntimeException("Item not found"));
|
||||
@@ -477,20 +523,32 @@ public class QuoteSessionController {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
if (item.getStoredPath() == null) {
|
||||
String targetStoredPath = item.getStoredPath();
|
||||
if (preview) {
|
||||
String convertedPath = extractConvertedStoredPath(item);
|
||||
if (convertedPath != null && !convertedPath.isBlank()) {
|
||||
targetStoredPath = convertedPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetStoredPath == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Path path = resolveStoredQuotePath(item.getStoredPath(), sessionId);
|
||||
Path path = resolveStoredQuotePath(targetStoredPath, sessionId);
|
||||
if (path == null || !Files.exists(path)) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
org.springframework.core.io.Resource resource = new UrlResource(path.toUri());
|
||||
String downloadName = item.getOriginalFilename();
|
||||
if (preview) {
|
||||
downloadName = path.getFileName().toString();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.header(org.springframework.http.HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + item.getOriginalFilename() + "\"")
|
||||
.header(org.springframework.http.HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + downloadName + "\"")
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
@@ -531,4 +589,17 @@ public class QuoteSessionController {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String extractConvertedStoredPath(QuoteLineItem item) {
|
||||
Map<String, Object> breakdown = item.getPricingBreakdown();
|
||||
if (breakdown == null) {
|
||||
return null;
|
||||
}
|
||||
Object converted = breakdown.get("convertedStoredPath");
|
||||
if (converted == null) {
|
||||
return null;
|
||||
}
|
||||
String path = String.valueOf(converted).trim();
|
||||
return path.isEmpty() ? null : path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.printcalculator.controller.admin;
|
||||
import com.printcalculator.dto.AdminContactRequestDto;
|
||||
import com.printcalculator.dto.AdminContactRequestAttachmentDto;
|
||||
import com.printcalculator.dto.AdminContactRequestDetailDto;
|
||||
import com.printcalculator.dto.AdminCadInvoiceCreateRequest;
|
||||
import com.printcalculator.dto.AdminCadInvoiceDto;
|
||||
import com.printcalculator.dto.AdminFilamentStockDto;
|
||||
import com.printcalculator.dto.AdminQuoteSessionDto;
|
||||
import com.printcalculator.dto.AdminUpdateContactRequestStatusRequest;
|
||||
@@ -10,13 +12,18 @@ import com.printcalculator.entity.CustomQuoteRequest;
|
||||
import com.printcalculator.entity.CustomQuoteRequestAttachment;
|
||||
import com.printcalculator.entity.FilamentVariant;
|
||||
import com.printcalculator.entity.FilamentVariantStockKg;
|
||||
import com.printcalculator.entity.Order;
|
||||
import com.printcalculator.entity.QuoteLineItem;
|
||||
import com.printcalculator.entity.QuoteSession;
|
||||
import com.printcalculator.repository.CustomQuoteRequestAttachmentRepository;
|
||||
import com.printcalculator.repository.CustomQuoteRequestRepository;
|
||||
import com.printcalculator.repository.FilamentVariantRepository;
|
||||
import com.printcalculator.repository.FilamentVariantStockKgRepository;
|
||||
import com.printcalculator.repository.OrderRepository;
|
||||
import com.printcalculator.repository.PricingPolicyRepository;
|
||||
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||
import com.printcalculator.repository.QuoteSessionRepository;
|
||||
import com.printcalculator.service.QuoteSessionTotalsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -31,6 +38,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -39,6 +47,7 @@ import org.springframework.web.server.ResponseStatusException;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.MalformedURLException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -75,7 +84,10 @@ public class AdminOperationsController {
|
||||
private final CustomQuoteRequestRepository customQuoteRequestRepo;
|
||||
private final CustomQuoteRequestAttachmentRepository customQuoteRequestAttachmentRepo;
|
||||
private final QuoteSessionRepository quoteSessionRepo;
|
||||
private final QuoteLineItemRepository quoteLineItemRepo;
|
||||
private final OrderRepository orderRepo;
|
||||
private final PricingPolicyRepository pricingRepo;
|
||||
private final QuoteSessionTotalsService quoteSessionTotalsService;
|
||||
|
||||
public AdminOperationsController(
|
||||
FilamentVariantStockKgRepository filamentStockRepo,
|
||||
@@ -83,14 +95,20 @@ public class AdminOperationsController {
|
||||
CustomQuoteRequestRepository customQuoteRequestRepo,
|
||||
CustomQuoteRequestAttachmentRepository customQuoteRequestAttachmentRepo,
|
||||
QuoteSessionRepository quoteSessionRepo,
|
||||
OrderRepository orderRepo
|
||||
QuoteLineItemRepository quoteLineItemRepo,
|
||||
OrderRepository orderRepo,
|
||||
PricingPolicyRepository pricingRepo,
|
||||
QuoteSessionTotalsService quoteSessionTotalsService
|
||||
) {
|
||||
this.filamentStockRepo = filamentStockRepo;
|
||||
this.filamentVariantRepo = filamentVariantRepo;
|
||||
this.customQuoteRequestRepo = customQuoteRequestRepo;
|
||||
this.customQuoteRequestAttachmentRepo = customQuoteRequestAttachmentRepo;
|
||||
this.quoteSessionRepo = quoteSessionRepo;
|
||||
this.quoteLineItemRepo = quoteLineItemRepo;
|
||||
this.orderRepo = orderRepo;
|
||||
this.pricingRepo = pricingRepo;
|
||||
this.quoteSessionTotalsService = quoteSessionTotalsService;
|
||||
}
|
||||
|
||||
@GetMapping("/filament-stock")
|
||||
@@ -279,6 +297,83 @@ public class AdminOperationsController {
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/cad-invoices")
|
||||
public ResponseEntity<List<AdminCadInvoiceDto>> getCadInvoices() {
|
||||
List<AdminCadInvoiceDto> response = quoteSessionRepo.findByStatusInOrderByCreatedAtDesc(List.of("CAD_ACTIVE", "CONVERTED"))
|
||||
.stream()
|
||||
.filter(this::isCadSessionRecord)
|
||||
.map(this::toCadInvoiceDto)
|
||||
.toList();
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@PostMapping("/cad-invoices")
|
||||
@Transactional
|
||||
public ResponseEntity<AdminCadInvoiceDto> createOrUpdateCadInvoice(
|
||||
@RequestBody AdminCadInvoiceCreateRequest payload
|
||||
) {
|
||||
if (payload == null || payload.getCadHours() == null) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "cadHours is required");
|
||||
}
|
||||
|
||||
BigDecimal cadHours = payload.getCadHours().setScale(2, RoundingMode.HALF_UP);
|
||||
if (cadHours.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new ResponseStatusException(BAD_REQUEST, "cadHours must be > 0");
|
||||
}
|
||||
|
||||
BigDecimal cadRate = payload.getCadHourlyRateChf();
|
||||
if (cadRate == null || cadRate.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
var policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||
cadRate = policy != null && policy.getCadCostChfPerHour() != null
|
||||
? policy.getCadCostChfPerHour()
|
||||
: BigDecimal.ZERO;
|
||||
}
|
||||
cadRate = cadRate.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
QuoteSession session;
|
||||
if (payload.getSessionId() != null) {
|
||||
session = quoteSessionRepo.findById(payload.getSessionId())
|
||||
.orElseThrow(() -> new ResponseStatusException(NOT_FOUND, "Session not found"));
|
||||
} else {
|
||||
session = new QuoteSession();
|
||||
session.setStatus("CAD_ACTIVE");
|
||||
session.setPricingVersion("v1");
|
||||
session.setMaterialCode("PLA");
|
||||
session.setNozzleDiameterMm(BigDecimal.valueOf(0.4));
|
||||
session.setLayerHeightMm(BigDecimal.valueOf(0.2));
|
||||
session.setInfillPattern("grid");
|
||||
session.setInfillPercent(20);
|
||||
session.setSupportsEnabled(false);
|
||||
session.setSetupCostChf(BigDecimal.ZERO);
|
||||
session.setCreatedAt(OffsetDateTime.now());
|
||||
session.setExpiresAt(OffsetDateTime.now().plusDays(30));
|
||||
}
|
||||
|
||||
if ("CONVERTED".equals(session.getStatus())) {
|
||||
throw new ResponseStatusException(CONFLICT, "Session already converted to order");
|
||||
}
|
||||
|
||||
if (payload.getSourceRequestId() != null) {
|
||||
if (!customQuoteRequestRepo.existsById(payload.getSourceRequestId())) {
|
||||
throw new ResponseStatusException(NOT_FOUND, "Source request not found");
|
||||
}
|
||||
session.setSourceRequestId(payload.getSourceRequestId());
|
||||
} else {
|
||||
session.setSourceRequestId(null);
|
||||
}
|
||||
|
||||
session.setStatus("CAD_ACTIVE");
|
||||
session.setCadHours(cadHours);
|
||||
session.setCadHourlyRateChf(cadRate);
|
||||
if (payload.getNotes() != null) {
|
||||
String trimmedNotes = payload.getNotes().trim();
|
||||
session.setNotes(trimmedNotes.isEmpty() ? null : trimmedNotes);
|
||||
}
|
||||
|
||||
QuoteSession saved = quoteSessionRepo.save(session);
|
||||
return ResponseEntity.ok(toCadInvoiceDto(saved));
|
||||
}
|
||||
|
||||
@DeleteMapping("/sessions/{sessionId}")
|
||||
@Transactional
|
||||
public ResponseEntity<Void> deleteQuoteSession(@PathVariable UUID sessionId) {
|
||||
@@ -347,6 +442,48 @@ public class AdminOperationsController {
|
||||
dto.setCreatedAt(session.getCreatedAt());
|
||||
dto.setExpiresAt(session.getExpiresAt());
|
||||
dto.setConvertedOrderId(session.getConvertedOrderId());
|
||||
dto.setSourceRequestId(session.getSourceRequestId());
|
||||
dto.setCadHours(session.getCadHours());
|
||||
dto.setCadHourlyRateChf(session.getCadHourlyRateChf());
|
||||
dto.setCadTotalChf(quoteSessionTotalsService.calculateCadTotal(session));
|
||||
return dto;
|
||||
}
|
||||
|
||||
private boolean isCadSessionRecord(QuoteSession session) {
|
||||
if ("CAD_ACTIVE".equals(session.getStatus())) {
|
||||
return true;
|
||||
}
|
||||
if (!"CONVERTED".equals(session.getStatus())) {
|
||||
return false;
|
||||
}
|
||||
BigDecimal cadHours = session.getCadHours() != null ? session.getCadHours() : BigDecimal.ZERO;
|
||||
return cadHours.compareTo(BigDecimal.ZERO) > 0 || session.getSourceRequestId() != null;
|
||||
}
|
||||
|
||||
private AdminCadInvoiceDto toCadInvoiceDto(QuoteSession session) {
|
||||
List<QuoteLineItem> items = quoteLineItemRepo.findByQuoteSessionId(session.getId());
|
||||
QuoteSessionTotalsService.QuoteSessionTotals totals = quoteSessionTotalsService.compute(session, items);
|
||||
|
||||
AdminCadInvoiceDto dto = new AdminCadInvoiceDto();
|
||||
dto.setSessionId(session.getId());
|
||||
dto.setSessionStatus(session.getStatus());
|
||||
dto.setSourceRequestId(session.getSourceRequestId());
|
||||
dto.setCadHours(session.getCadHours() != null ? session.getCadHours() : BigDecimal.ZERO);
|
||||
dto.setCadHourlyRateChf(session.getCadHourlyRateChf() != null ? session.getCadHourlyRateChf() : BigDecimal.ZERO);
|
||||
dto.setCadTotalChf(totals.cadTotalChf());
|
||||
dto.setPrintItemsTotalChf(totals.printItemsTotalChf());
|
||||
dto.setSetupCostChf(totals.setupCostChf());
|
||||
dto.setShippingCostChf(totals.shippingCostChf());
|
||||
dto.setGrandTotalChf(totals.grandTotalChf());
|
||||
dto.setConvertedOrderId(session.getConvertedOrderId());
|
||||
dto.setCheckoutPath("/checkout/cad?session=" + session.getId());
|
||||
dto.setNotes(session.getNotes());
|
||||
dto.setCreatedAt(session.getCreatedAt());
|
||||
|
||||
if (session.getConvertedOrderId() != null) {
|
||||
Order order = orderRepo.findById(session.getConvertedOrderId()).orElse(null);
|
||||
dto.setConvertedOrderStatus(order != null ? order.getStatus() : null);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
@@ -214,6 +214,11 @@ public class AdminOrderController {
|
||||
dto.setShippingCostChf(order.getShippingCostChf());
|
||||
dto.setDiscountChf(order.getDiscountChf());
|
||||
dto.setSubtotalChf(order.getSubtotalChf());
|
||||
dto.setIsCadOrder(order.getIsCadOrder());
|
||||
dto.setSourceRequestId(order.getSourceRequestId());
|
||||
dto.setCadHours(order.getCadHours());
|
||||
dto.setCadHourlyRateChf(order.getCadHourlyRateChf());
|
||||
dto.setCadTotalChf(order.getCadTotalChf());
|
||||
dto.setTotalChf(order.getTotalChf());
|
||||
dto.setCreatedAt(order.getCreatedAt());
|
||||
dto.setShippingSameAsBilling(order.getShippingSameAsBilling());
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.printcalculator.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminCadInvoiceCreateRequest {
|
||||
private UUID sessionId;
|
||||
private UUID sourceRequestId;
|
||||
private BigDecimal cadHours;
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
private String notes;
|
||||
|
||||
public UUID getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(UUID sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public UUID getSourceRequestId() {
|
||||
return sourceRequestId;
|
||||
}
|
||||
|
||||
public void setSourceRequestId(UUID sourceRequestId) {
|
||||
this.sourceRequestId = sourceRequestId;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHours() {
|
||||
return cadHours;
|
||||
}
|
||||
|
||||
public void setCadHours(BigDecimal cadHours) {
|
||||
this.cadHours = cadHours;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() {
|
||||
return cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) {
|
||||
this.cadHourlyRateChf = cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.printcalculator.dto;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminCadInvoiceDto {
|
||||
private UUID sessionId;
|
||||
private String sessionStatus;
|
||||
private UUID sourceRequestId;
|
||||
private BigDecimal cadHours;
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
private BigDecimal cadTotalChf;
|
||||
private BigDecimal printItemsTotalChf;
|
||||
private BigDecimal setupCostChf;
|
||||
private BigDecimal shippingCostChf;
|
||||
private BigDecimal grandTotalChf;
|
||||
private UUID convertedOrderId;
|
||||
private String convertedOrderStatus;
|
||||
private String checkoutPath;
|
||||
private String notes;
|
||||
private OffsetDateTime createdAt;
|
||||
|
||||
public UUID getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(UUID sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public String getSessionStatus() {
|
||||
return sessionStatus;
|
||||
}
|
||||
|
||||
public void setSessionStatus(String sessionStatus) {
|
||||
this.sessionStatus = sessionStatus;
|
||||
}
|
||||
|
||||
public UUID getSourceRequestId() {
|
||||
return sourceRequestId;
|
||||
}
|
||||
|
||||
public void setSourceRequestId(UUID sourceRequestId) {
|
||||
this.sourceRequestId = sourceRequestId;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHours() {
|
||||
return cadHours;
|
||||
}
|
||||
|
||||
public void setCadHours(BigDecimal cadHours) {
|
||||
this.cadHours = cadHours;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() {
|
||||
return cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) {
|
||||
this.cadHourlyRateChf = cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public BigDecimal getCadTotalChf() {
|
||||
return cadTotalChf;
|
||||
}
|
||||
|
||||
public void setCadTotalChf(BigDecimal cadTotalChf) {
|
||||
this.cadTotalChf = cadTotalChf;
|
||||
}
|
||||
|
||||
public BigDecimal getPrintItemsTotalChf() {
|
||||
return printItemsTotalChf;
|
||||
}
|
||||
|
||||
public void setPrintItemsTotalChf(BigDecimal printItemsTotalChf) {
|
||||
this.printItemsTotalChf = printItemsTotalChf;
|
||||
}
|
||||
|
||||
public BigDecimal getSetupCostChf() {
|
||||
return setupCostChf;
|
||||
}
|
||||
|
||||
public void setSetupCostChf(BigDecimal setupCostChf) {
|
||||
this.setupCostChf = setupCostChf;
|
||||
}
|
||||
|
||||
public BigDecimal getShippingCostChf() {
|
||||
return shippingCostChf;
|
||||
}
|
||||
|
||||
public void setShippingCostChf(BigDecimal shippingCostChf) {
|
||||
this.shippingCostChf = shippingCostChf;
|
||||
}
|
||||
|
||||
public BigDecimal getGrandTotalChf() {
|
||||
return grandTotalChf;
|
||||
}
|
||||
|
||||
public void setGrandTotalChf(BigDecimal grandTotalChf) {
|
||||
this.grandTotalChf = grandTotalChf;
|
||||
}
|
||||
|
||||
public UUID getConvertedOrderId() {
|
||||
return convertedOrderId;
|
||||
}
|
||||
|
||||
public void setConvertedOrderId(UUID convertedOrderId) {
|
||||
this.convertedOrderId = convertedOrderId;
|
||||
}
|
||||
|
||||
public String getConvertedOrderStatus() {
|
||||
return convertedOrderStatus;
|
||||
}
|
||||
|
||||
public void setConvertedOrderStatus(String convertedOrderStatus) {
|
||||
this.convertedOrderStatus = convertedOrderStatus;
|
||||
}
|
||||
|
||||
public String getCheckoutPath() {
|
||||
return checkoutPath;
|
||||
}
|
||||
|
||||
public void setCheckoutPath(String checkoutPath) {
|
||||
this.checkoutPath = checkoutPath;
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public OffsetDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.printcalculator.dto;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminQuoteSessionDto {
|
||||
@@ -10,6 +11,10 @@ public class AdminQuoteSessionDto {
|
||||
private OffsetDateTime createdAt;
|
||||
private OffsetDateTime expiresAt;
|
||||
private UUID convertedOrderId;
|
||||
private UUID sourceRequestId;
|
||||
private BigDecimal cadHours;
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
private BigDecimal cadTotalChf;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
@@ -58,4 +63,36 @@ public class AdminQuoteSessionDto {
|
||||
public void setConvertedOrderId(UUID convertedOrderId) {
|
||||
this.convertedOrderId = convertedOrderId;
|
||||
}
|
||||
|
||||
public UUID getSourceRequestId() {
|
||||
return sourceRequestId;
|
||||
}
|
||||
|
||||
public void setSourceRequestId(UUID sourceRequestId) {
|
||||
this.sourceRequestId = sourceRequestId;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHours() {
|
||||
return cadHours;
|
||||
}
|
||||
|
||||
public void setCadHours(BigDecimal cadHours) {
|
||||
this.cadHours = cadHours;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() {
|
||||
return cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) {
|
||||
this.cadHourlyRateChf = cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public BigDecimal getCadTotalChf() {
|
||||
return cadTotalChf;
|
||||
}
|
||||
|
||||
public void setCadTotalChf(BigDecimal cadTotalChf) {
|
||||
this.cadTotalChf = cadTotalChf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ public class OrderDto {
|
||||
private BigDecimal shippingCostChf;
|
||||
private BigDecimal discountChf;
|
||||
private BigDecimal subtotalChf;
|
||||
private Boolean isCadOrder;
|
||||
private UUID sourceRequestId;
|
||||
private BigDecimal cadHours;
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
private BigDecimal cadTotalChf;
|
||||
private BigDecimal totalChf;
|
||||
private OffsetDateTime createdAt;
|
||||
private String printMaterialCode;
|
||||
@@ -85,6 +90,21 @@ public class OrderDto {
|
||||
public BigDecimal getSubtotalChf() { return subtotalChf; }
|
||||
public void setSubtotalChf(BigDecimal subtotalChf) { this.subtotalChf = subtotalChf; }
|
||||
|
||||
public Boolean getIsCadOrder() { return isCadOrder; }
|
||||
public void setIsCadOrder(Boolean isCadOrder) { this.isCadOrder = isCadOrder; }
|
||||
|
||||
public UUID getSourceRequestId() { return sourceRequestId; }
|
||||
public void setSourceRequestId(UUID sourceRequestId) { this.sourceRequestId = sourceRequestId; }
|
||||
|
||||
public BigDecimal getCadHours() { return cadHours; }
|
||||
public void setCadHours(BigDecimal cadHours) { this.cadHours = cadHours; }
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() { return cadHourlyRateChf; }
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) { this.cadHourlyRateChf = cadHourlyRateChf; }
|
||||
|
||||
public BigDecimal getCadTotalChf() { return cadTotalChf; }
|
||||
public void setCadTotalChf(BigDecimal cadTotalChf) { this.cadTotalChf = cadTotalChf; }
|
||||
|
||||
public BigDecimal getTotalChf() { return totalChf; }
|
||||
public void setTotalChf(BigDecimal totalChf) { this.totalChf = totalChf; }
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import jakarta.validation.constraints.AssertTrue;
|
||||
public class QuoteRequestDto {
|
||||
private String requestType; // "PRINT_SERVICE" or "DESIGN_SERVICE"
|
||||
private String customerType; // "PRIVATE" or "BUSINESS"
|
||||
private String language; // "it" | "en" | "de" | "fr"
|
||||
private String email;
|
||||
private String phone;
|
||||
private String name;
|
||||
|
||||
@@ -119,6 +119,23 @@ public class Order {
|
||||
@Column(name = "subtotal_chf", nullable = false, precision = 12, scale = 2)
|
||||
private BigDecimal subtotalChf;
|
||||
|
||||
@ColumnDefault("false")
|
||||
@Column(name = "is_cad_order", nullable = false)
|
||||
private Boolean isCadOrder;
|
||||
|
||||
@Column(name = "source_request_id")
|
||||
private UUID sourceRequestId;
|
||||
|
||||
@Column(name = "cad_hours", precision = 10, scale = 2)
|
||||
private BigDecimal cadHours;
|
||||
|
||||
@Column(name = "cad_hourly_rate_chf", precision = 10, scale = 2)
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
|
||||
@ColumnDefault("0.00")
|
||||
@Column(name = "cad_total_chf", nullable = false, precision = 12, scale = 2)
|
||||
private BigDecimal cadTotalChf;
|
||||
|
||||
@ColumnDefault("0.00")
|
||||
@Column(name = "total_chf", nullable = false, precision = 12, scale = 2)
|
||||
private BigDecimal totalChf;
|
||||
@@ -400,6 +417,46 @@ public class Order {
|
||||
this.subtotalChf = subtotalChf;
|
||||
}
|
||||
|
||||
public Boolean getIsCadOrder() {
|
||||
return isCadOrder;
|
||||
}
|
||||
|
||||
public void setIsCadOrder(Boolean isCadOrder) {
|
||||
this.isCadOrder = isCadOrder;
|
||||
}
|
||||
|
||||
public UUID getSourceRequestId() {
|
||||
return sourceRequestId;
|
||||
}
|
||||
|
||||
public void setSourceRequestId(UUID sourceRequestId) {
|
||||
this.sourceRequestId = sourceRequestId;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHours() {
|
||||
return cadHours;
|
||||
}
|
||||
|
||||
public void setCadHours(BigDecimal cadHours) {
|
||||
this.cadHours = cadHours;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() {
|
||||
return cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) {
|
||||
this.cadHourlyRateChf = cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public BigDecimal getCadTotalChf() {
|
||||
return cadTotalChf;
|
||||
}
|
||||
|
||||
public void setCadTotalChf(BigDecimal cadTotalChf) {
|
||||
this.cadTotalChf = cadTotalChf;
|
||||
}
|
||||
|
||||
public BigDecimal getTotalChf() {
|
||||
return totalChf;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,15 @@ public class QuoteSession {
|
||||
@Column(name = "converted_order_id")
|
||||
private UUID convertedOrderId;
|
||||
|
||||
@Column(name = "source_request_id")
|
||||
private UUID sourceRequestId;
|
||||
|
||||
@Column(name = "cad_hours", precision = 10, scale = 2)
|
||||
private BigDecimal cadHours;
|
||||
|
||||
@Column(name = "cad_hourly_rate_chf", precision = 10, scale = 2)
|
||||
private BigDecimal cadHourlyRateChf;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -173,4 +182,28 @@ public class QuoteSession {
|
||||
this.convertedOrderId = convertedOrderId;
|
||||
}
|
||||
|
||||
public UUID getSourceRequestId() {
|
||||
return sourceRequestId;
|
||||
}
|
||||
|
||||
public void setSourceRequestId(UUID sourceRequestId) {
|
||||
this.sourceRequestId = sourceRequestId;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHours() {
|
||||
return cadHours;
|
||||
}
|
||||
|
||||
public void setCadHours(BigDecimal cadHours) {
|
||||
this.cadHours = cadHours;
|
||||
}
|
||||
|
||||
public BigDecimal getCadHourlyRateChf() {
|
||||
return cadHourlyRateChf;
|
||||
}
|
||||
|
||||
public void setCadHourlyRateChf(BigDecimal cadHourlyRateChf) {
|
||||
this.cadHourlyRateChf = cadHourlyRateChf;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,20 @@ import java.util.Map;
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(ModelProcessingException.class)
|
||||
public ResponseEntity<Object> handleModelProcessingException(
|
||||
ModelProcessingException ex, WebRequest request) {
|
||||
Map<String, Object> body = new LinkedHashMap<>();
|
||||
body.put("timestamp", LocalDateTime.now());
|
||||
body.put("status", HttpStatus.UNPROCESSABLE_ENTITY.value());
|
||||
body.put("error", "Unprocessable Entity");
|
||||
body.put("code", ex.getCode());
|
||||
body.put("message", ex.getMessage());
|
||||
body.put("path", extractPath(request));
|
||||
|
||||
return new ResponseEntity<>(body, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@ExceptionHandler(VirusDetectedException.class)
|
||||
public ResponseEntity<Object> handleVirusDetectedException(
|
||||
VirusDetectedException ex, WebRequest request) {
|
||||
@@ -58,4 +72,12 @@ public class GlobalExceptionHandler {
|
||||
|
||||
return new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
private String extractPath(WebRequest request) {
|
||||
String raw = request.getDescription(false);
|
||||
if (raw == null) {
|
||||
return "";
|
||||
}
|
||||
return raw.startsWith("uri=") ? raw.substring(4) : raw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.printcalculator.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ModelProcessingException extends IOException {
|
||||
private final String code;
|
||||
|
||||
public ModelProcessingException(String code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public ModelProcessingException(String code, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,6 @@ import java.util.UUID;
|
||||
|
||||
public interface QuoteSessionRepository extends JpaRepository<QuoteSession, UUID> {
|
||||
List<QuoteSession> findByCreatedAtBefore(java.time.OffsetDateTime cutoff);
|
||||
|
||||
List<QuoteSession> findByStatusInOrderByCreatedAtDesc(List<String> statuses);
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import com.printcalculator.entity.Order;
|
||||
import com.printcalculator.entity.OrderItem;
|
||||
@@ -95,6 +97,17 @@ public class InvoicePdfRenderingService {
|
||||
return line;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (order.getCadTotalChf() != null && order.getCadTotalChf().compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal cadHours = order.getCadHours() != null ? order.getCadHours() : BigDecimal.ZERO;
|
||||
BigDecimal cadHourlyRate = order.getCadHourlyRateChf() != null ? order.getCadHourlyRateChf() : BigDecimal.ZERO;
|
||||
Map<String, Object> cadLine = new HashMap<>();
|
||||
cadLine.put("description", "Servizio CAD (" + formatCadHours(cadHours) + "h)");
|
||||
cadLine.put("quantity", 1);
|
||||
cadLine.put("unitPriceFormatted", String.format("CHF %.2f", cadHourlyRate));
|
||||
cadLine.put("lineTotalFormatted", String.format("CHF %.2f", order.getCadTotalChf()));
|
||||
invoiceLineItems.add(cadLine);
|
||||
}
|
||||
|
||||
Map<String, Object> setupLine = new HashMap<>();
|
||||
setupLine.put("description", "Costo Setup");
|
||||
setupLine.put("quantity", 1);
|
||||
@@ -140,4 +153,8 @@ public class InvoicePdfRenderingService {
|
||||
|
||||
return generateInvoicePdfBytesFromTemplate(vars, qrBillSvg);
|
||||
}
|
||||
|
||||
private String formatCadHours(BigDecimal hours) {
|
||||
return hours.setScale(2, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.printcalculator.repository.OrderItemRepository;
|
||||
import com.printcalculator.repository.OrderRepository;
|
||||
import com.printcalculator.repository.QuoteLineItemRepository;
|
||||
import com.printcalculator.repository.QuoteSessionRepository;
|
||||
import com.printcalculator.repository.PricingPolicyRepository;
|
||||
import com.printcalculator.event.OrderCreatedEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -35,8 +34,7 @@ public class OrderService {
|
||||
private final QrBillService qrBillService;
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
private final PaymentService paymentService;
|
||||
private final QuoteCalculator quoteCalculator;
|
||||
private final PricingPolicyRepository pricingRepo;
|
||||
private final QuoteSessionTotalsService quoteSessionTotalsService;
|
||||
|
||||
public OrderService(OrderRepository orderRepo,
|
||||
OrderItemRepository orderItemRepo,
|
||||
@@ -48,8 +46,7 @@ public class OrderService {
|
||||
QrBillService qrBillService,
|
||||
ApplicationEventPublisher eventPublisher,
|
||||
PaymentService paymentService,
|
||||
QuoteCalculator quoteCalculator,
|
||||
PricingPolicyRepository pricingRepo) {
|
||||
QuoteSessionTotalsService quoteSessionTotalsService) {
|
||||
this.orderRepo = orderRepo;
|
||||
this.orderItemRepo = orderItemRepo;
|
||||
this.quoteSessionRepo = quoteSessionRepo;
|
||||
@@ -60,8 +57,7 @@ public class OrderService {
|
||||
this.qrBillService = qrBillService;
|
||||
this.eventPublisher = eventPublisher;
|
||||
this.paymentService = paymentService;
|
||||
this.quoteCalculator = quoteCalculator;
|
||||
this.pricingRepo = pricingRepo;
|
||||
this.quoteSessionTotalsService = quoteSessionTotalsService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -148,60 +144,31 @@ public class OrderService {
|
||||
}
|
||||
|
||||
List<QuoteLineItem> quoteItems = quoteLineItemRepo.findByQuoteSessionId(quoteSessionId);
|
||||
QuoteSessionTotalsService.QuoteSessionTotals totals = quoteSessionTotalsService.compute(session, quoteItems);
|
||||
BigDecimal cadTotal = totals.cadTotalChf();
|
||||
|
||||
BigDecimal subtotal = BigDecimal.ZERO;
|
||||
order.setSubtotalChf(BigDecimal.ZERO);
|
||||
order.setTotalChf(BigDecimal.ZERO);
|
||||
order.setDiscountChf(BigDecimal.ZERO);
|
||||
order.setSetupCostChf(session.getSetupCostChf() != null ? session.getSetupCostChf() : BigDecimal.ZERO);
|
||||
|
||||
// Calculate shipping cost based on dimensions before initial save
|
||||
boolean exceedsBaseSize = false;
|
||||
for (QuoteLineItem item : quoteItems) {
|
||||
BigDecimal x = item.getBoundingBoxXMm() != null ? item.getBoundingBoxXMm() : BigDecimal.ZERO;
|
||||
BigDecimal y = item.getBoundingBoxYMm() != null ? item.getBoundingBoxYMm() : BigDecimal.ZERO;
|
||||
BigDecimal z = item.getBoundingBoxZMm() != null ? item.getBoundingBoxZMm() : BigDecimal.ZERO;
|
||||
|
||||
BigDecimal[] dims = {x, y, z};
|
||||
java.util.Arrays.sort(dims);
|
||||
|
||||
if (dims[2].compareTo(BigDecimal.valueOf(250.0)) > 0 ||
|
||||
dims[1].compareTo(BigDecimal.valueOf(176.0)) > 0 ||
|
||||
dims[0].compareTo(BigDecimal.valueOf(20.0)) > 0) {
|
||||
exceedsBaseSize = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int totalQuantity = quoteItems.stream()
|
||||
.mapToInt(i -> i.getQuantity() != null ? i.getQuantity() : 1)
|
||||
.sum();
|
||||
|
||||
if (exceedsBaseSize) {
|
||||
order.setShippingCostChf(totalQuantity > 5 ? BigDecimal.valueOf(9.00) : BigDecimal.valueOf(4.00));
|
||||
} else {
|
||||
order.setShippingCostChf(BigDecimal.valueOf(2.00));
|
||||
}
|
||||
order.setShippingCostChf(totals.shippingCostChf());
|
||||
order.setIsCadOrder(cadTotal.compareTo(BigDecimal.ZERO) > 0 || "CAD_ACTIVE".equals(session.getStatus()));
|
||||
order.setSourceRequestId(session.getSourceRequestId());
|
||||
order.setCadHours(session.getCadHours() != null ? session.getCadHours() : BigDecimal.ZERO);
|
||||
order.setCadHourlyRateChf(session.getCadHourlyRateChf() != null ? session.getCadHourlyRateChf() : BigDecimal.ZERO);
|
||||
order.setCadTotalChf(cadTotal);
|
||||
|
||||
order = orderRepo.save(order);
|
||||
|
||||
List<OrderItem> savedItems = new ArrayList<>();
|
||||
|
||||
// Calculate global machine cost upfront
|
||||
BigDecimal totalSeconds = BigDecimal.ZERO;
|
||||
for (QuoteLineItem qItem : quoteItems) {
|
||||
if (qItem.getPrintTimeSeconds() != null) {
|
||||
totalSeconds = totalSeconds.add(BigDecimal.valueOf(qItem.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(qItem.getQuantity())));
|
||||
}
|
||||
}
|
||||
BigDecimal totalHours = totalSeconds.divide(BigDecimal.valueOf(3600), 4, RoundingMode.HALF_UP);
|
||||
PricingPolicy policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||
BigDecimal globalMachineCost = quoteCalculator.calculateSessionMachineCost(policy, totalHours);
|
||||
|
||||
for (QuoteLineItem qItem : quoteItems) {
|
||||
OrderItem oItem = new OrderItem();
|
||||
oItem.setOrder(order);
|
||||
oItem.setOriginalFilename(qItem.getOriginalFilename());
|
||||
oItem.setQuantity(qItem.getQuantity());
|
||||
int quantity = qItem.getQuantity() != null && qItem.getQuantity() > 0 ? qItem.getQuantity() : 1;
|
||||
oItem.setQuantity(quantity);
|
||||
oItem.setColorCode(qItem.getColorCode());
|
||||
oItem.setFilamentVariant(qItem.getFilamentVariant());
|
||||
if (qItem.getFilamentVariant() != null
|
||||
@@ -212,17 +179,17 @@ public class OrderService {
|
||||
oItem.setMaterialCode(session.getMaterialCode());
|
||||
}
|
||||
|
||||
BigDecimal distributedUnitPrice = qItem.getUnitPriceChf();
|
||||
if (totalSeconds.compareTo(BigDecimal.ZERO) > 0 && qItem.getPrintTimeSeconds() != null) {
|
||||
BigDecimal itemSeconds = BigDecimal.valueOf(qItem.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(qItem.getQuantity()));
|
||||
BigDecimal share = itemSeconds.divide(totalSeconds, 8, RoundingMode.HALF_UP);
|
||||
BigDecimal itemMachineCost = globalMachineCost.multiply(share);
|
||||
BigDecimal unitMachineCost = itemMachineCost.divide(BigDecimal.valueOf(qItem.getQuantity()), 2, RoundingMode.HALF_UP);
|
||||
BigDecimal distributedUnitPrice = qItem.getUnitPriceChf() != null ? qItem.getUnitPriceChf() : BigDecimal.ZERO;
|
||||
if (totals.totalPrintSeconds().compareTo(BigDecimal.ZERO) > 0 && qItem.getPrintTimeSeconds() != null) {
|
||||
BigDecimal itemSeconds = BigDecimal.valueOf(qItem.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(quantity));
|
||||
BigDecimal share = itemSeconds.divide(totals.totalPrintSeconds(), 8, RoundingMode.HALF_UP);
|
||||
BigDecimal itemMachineCost = totals.globalMachineCostChf().multiply(share);
|
||||
BigDecimal unitMachineCost = itemMachineCost.divide(BigDecimal.valueOf(quantity), 2, RoundingMode.HALF_UP);
|
||||
distributedUnitPrice = distributedUnitPrice.add(unitMachineCost);
|
||||
}
|
||||
|
||||
oItem.setUnitPriceChf(distributedUnitPrice);
|
||||
oItem.setLineTotalChf(distributedUnitPrice.multiply(BigDecimal.valueOf(qItem.getQuantity())));
|
||||
oItem.setLineTotalChf(distributedUnitPrice.multiply(BigDecimal.valueOf(quantity)));
|
||||
oItem.setPrintTimeSeconds(qItem.getPrintTimeSeconds());
|
||||
oItem.setMaterialGrams(qItem.getMaterialGrams());
|
||||
oItem.setBoundingBoxXMm(qItem.getBoundingBoxXMm());
|
||||
@@ -260,9 +227,12 @@ public class OrderService {
|
||||
subtotal = subtotal.add(oItem.getLineTotalChf());
|
||||
}
|
||||
|
||||
order.setSubtotalChf(subtotal);
|
||||
order.setSubtotalChf(subtotal.add(cadTotal));
|
||||
|
||||
BigDecimal total = subtotal.add(order.getSetupCostChf()).add(order.getShippingCostChf()).subtract(order.getDiscountChf() != null ? order.getDiscountChf() : BigDecimal.ZERO);
|
||||
BigDecimal total = order.getSubtotalChf()
|
||||
.add(order.getSetupCostChf())
|
||||
.add(order.getShippingCostChf())
|
||||
.subtract(order.getDiscountChf() != null ? order.getDiscountChf() : BigDecimal.ZERO);
|
||||
order.setTotalChf(total);
|
||||
|
||||
session.setConvertedOrderId(order.getId());
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.printcalculator.service;
|
||||
|
||||
import com.printcalculator.entity.PricingPolicy;
|
||||
import com.printcalculator.entity.QuoteLineItem;
|
||||
import com.printcalculator.entity.QuoteSession;
|
||||
import com.printcalculator.repository.PricingPolicyRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class QuoteSessionTotalsService {
|
||||
private final PricingPolicyRepository pricingRepo;
|
||||
private final QuoteCalculator quoteCalculator;
|
||||
|
||||
public QuoteSessionTotalsService(PricingPolicyRepository pricingRepo, QuoteCalculator quoteCalculator) {
|
||||
this.pricingRepo = pricingRepo;
|
||||
this.quoteCalculator = quoteCalculator;
|
||||
}
|
||||
|
||||
public QuoteSessionTotals compute(QuoteSession session, List<QuoteLineItem> items) {
|
||||
BigDecimal printItemsBaseTotal = BigDecimal.ZERO;
|
||||
BigDecimal totalSeconds = BigDecimal.ZERO;
|
||||
|
||||
for (QuoteLineItem item : items) {
|
||||
int quantity = normalizeQuantity(item.getQuantity());
|
||||
BigDecimal unitPrice = item.getUnitPriceChf() != null ? item.getUnitPriceChf() : BigDecimal.ZERO;
|
||||
printItemsBaseTotal = printItemsBaseTotal.add(unitPrice.multiply(BigDecimal.valueOf(quantity)));
|
||||
|
||||
if (item.getPrintTimeSeconds() != null && item.getPrintTimeSeconds() > 0) {
|
||||
totalSeconds = totalSeconds.add(BigDecimal.valueOf(item.getPrintTimeSeconds()).multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
}
|
||||
|
||||
BigDecimal totalHours = totalSeconds.divide(BigDecimal.valueOf(3600), 4, RoundingMode.HALF_UP);
|
||||
PricingPolicy policy = pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc();
|
||||
BigDecimal globalMachineCost = quoteCalculator.calculateSessionMachineCost(policy, totalHours);
|
||||
BigDecimal printItemsTotal = printItemsBaseTotal.add(globalMachineCost);
|
||||
|
||||
BigDecimal cadTotal = calculateCadTotal(session);
|
||||
BigDecimal itemsTotal = printItemsTotal.add(cadTotal);
|
||||
|
||||
BigDecimal setupFee = session.getSetupCostChf() != null ? session.getSetupCostChf() : BigDecimal.ZERO;
|
||||
BigDecimal shippingCost = calculateShippingCost(items);
|
||||
BigDecimal grandTotal = itemsTotal.add(setupFee).add(shippingCost);
|
||||
|
||||
return new QuoteSessionTotals(
|
||||
printItemsTotal,
|
||||
globalMachineCost,
|
||||
cadTotal,
|
||||
itemsTotal,
|
||||
setupFee,
|
||||
shippingCost,
|
||||
grandTotal,
|
||||
totalSeconds
|
||||
);
|
||||
}
|
||||
|
||||
public BigDecimal calculateCadTotal(QuoteSession session) {
|
||||
if (session == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal cadHours = session.getCadHours() != null ? session.getCadHours() : BigDecimal.ZERO;
|
||||
BigDecimal cadRate = session.getCadHourlyRateChf() != null ? session.getCadHourlyRateChf() : BigDecimal.ZERO;
|
||||
if (cadHours.compareTo(BigDecimal.ZERO) <= 0 || cadRate.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
return cadHours.multiply(cadRate).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
public BigDecimal calculateShippingCost(List<QuoteLineItem> items) {
|
||||
if (items == null || items.isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
boolean exceedsBaseSize = false;
|
||||
for (QuoteLineItem item : items) {
|
||||
BigDecimal x = item.getBoundingBoxXMm() != null ? item.getBoundingBoxXMm() : BigDecimal.ZERO;
|
||||
BigDecimal y = item.getBoundingBoxYMm() != null ? item.getBoundingBoxYMm() : BigDecimal.ZERO;
|
||||
BigDecimal z = item.getBoundingBoxZMm() != null ? item.getBoundingBoxZMm() : BigDecimal.ZERO;
|
||||
|
||||
BigDecimal[] dims = {x, y, z};
|
||||
Arrays.sort(dims);
|
||||
|
||||
if (dims[2].compareTo(BigDecimal.valueOf(250.0)) > 0
|
||||
|| dims[1].compareTo(BigDecimal.valueOf(176.0)) > 0
|
||||
|| dims[0].compareTo(BigDecimal.valueOf(20.0)) > 0) {
|
||||
exceedsBaseSize = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int totalQuantity = items.stream().mapToInt(i -> normalizeQuantity(i.getQuantity())).sum();
|
||||
if (totalQuantity <= 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
if (exceedsBaseSize) {
|
||||
return totalQuantity > 5 ? BigDecimal.valueOf(9.00) : BigDecimal.valueOf(4.00);
|
||||
}
|
||||
return BigDecimal.valueOf(2.00);
|
||||
}
|
||||
|
||||
private int normalizeQuantity(Integer quantity) {
|
||||
if (quantity == null || quantity < 1) {
|
||||
return 1;
|
||||
}
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public record QuoteSessionTotals(
|
||||
BigDecimal printItemsTotalChf,
|
||||
BigDecimal globalMachineCostChf,
|
||||
BigDecimal cadTotalChf,
|
||||
BigDecimal itemsTotalChf,
|
||||
BigDecimal setupCostChf,
|
||||
BigDecimal shippingCostChf,
|
||||
BigDecimal grandTotalChf,
|
||||
BigDecimal totalPrintSeconds
|
||||
) {}
|
||||
}
|
||||
@@ -45,9 +45,8 @@ public class SessionCleanupService {
|
||||
// "rimangono in memoria... cancella quelle vecchie di 7 giorni".
|
||||
// Implementation plan said: status != 'ORDERED'.
|
||||
|
||||
// User specified statuses: ACTIVE, EXPIRED, CONVERTED.
|
||||
// We should NOT delete sessions that have been converted to an order.
|
||||
if ("CONVERTED".equals(session.getStatus())) {
|
||||
// CAD_ACTIVE sessions are managed manually from back-office and must be preserved.
|
||||
if ("CONVERTED".equals(session.getStatus()) || "CAD_ACTIVE".equals(session.getStatus())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,25 +2,54 @@ package com.printcalculator.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.printcalculator.exception.ModelProcessingException;
|
||||
import com.printcalculator.model.ModelDimensions;
|
||||
import com.printcalculator.model.PrintStats;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.assimp.AIFace;
|
||||
import org.lwjgl.assimp.AIMesh;
|
||||
import org.lwjgl.assimp.AIScene;
|
||||
import org.lwjgl.assimp.AIVector3D;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import static org.lwjgl.assimp.Assimp.aiGetErrorString;
|
||||
import static org.lwjgl.assimp.Assimp.aiImportFile;
|
||||
import static org.lwjgl.assimp.Assimp.aiProcess_JoinIdenticalVertices;
|
||||
import static org.lwjgl.assimp.Assimp.aiProcess_PreTransformVertices;
|
||||
import static org.lwjgl.assimp.Assimp.aiProcess_SortByPType;
|
||||
import static org.lwjgl.assimp.Assimp.aiProcess_Triangulate;
|
||||
import static org.lwjgl.assimp.Assimp.aiReleaseImport;
|
||||
|
||||
@Service
|
||||
public class SlicerService {
|
||||
@@ -31,16 +60,19 @@ public class SlicerService {
|
||||
private static final Pattern SIZE_Z_PATTERN = Pattern.compile("(?m)^\\s*size_z\\s*=\\s*([-+]?\\d+(?:\\.\\d+)?)\\s*$");
|
||||
|
||||
private final String trustedSlicerPath;
|
||||
private final String trustedAssimpPath;
|
||||
private final ProfileManager profileManager;
|
||||
private final GCodeParser gCodeParser;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public SlicerService(
|
||||
@Value("${slicer.path}") String slicerPath,
|
||||
@Value("${assimp.path:assimp}") String assimpPath,
|
||||
ProfileManager profileManager,
|
||||
GCodeParser gCodeParser,
|
||||
ObjectMapper mapper) {
|
||||
this.trustedSlicerPath = normalizeExecutablePath(slicerPath);
|
||||
this.trustedAssimpPath = normalizeExecutablePath(assimpPath);
|
||||
this.profileManager = profileManager;
|
||||
this.gCodeParser = gCodeParser;
|
||||
this.mapper = mapper;
|
||||
@@ -87,7 +119,8 @@ public class SlicerService {
|
||||
String processProfilePath = requireSafeArgument(pFile.getAbsolutePath(), "process profile path");
|
||||
String filamentProfilePath = requireSafeArgument(fFile.getAbsolutePath(), "filament profile path");
|
||||
String outputDirPath = requireSafeArgument(tempDir.toAbsolutePath().toString(), "output directory path");
|
||||
String inputStlPath = requireSafeArgument(inputStl.getAbsolutePath(), "input STL path");
|
||||
String inputModelPath = requireSafeArgument(inputStl.getAbsolutePath(), "input model path");
|
||||
List<String> slicerInputPaths = resolveSlicerInputPaths(inputStl, inputModelPath, tempDir);
|
||||
|
||||
// 3. Run slicer. Retry with arrange only for out-of-volume style failures.
|
||||
for (boolean useArrange : new boolean[]{false, true}) {
|
||||
@@ -110,7 +143,7 @@ public class SlicerService {
|
||||
command.add("0");
|
||||
command.add("--outputdir");
|
||||
command.add(outputDirPath);
|
||||
command.add(inputStlPath);
|
||||
command.addAll(slicerInputPaths);
|
||||
|
||||
logger.info("Executing Slicer" + (useArrange ? " (retry with arrange)" : "") + ": " + String.join(" ", command));
|
||||
|
||||
@@ -124,7 +157,10 @@ public class SlicerService {
|
||||
|
||||
if (!finished) {
|
||||
process.destroyForcibly();
|
||||
throw new IOException("Slicer timed out");
|
||||
throw new ModelProcessingException(
|
||||
"SLICER_TIMEOUT",
|
||||
"Model processing timed out. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
}
|
||||
|
||||
if (process.exitValue() != 0) {
|
||||
@@ -136,7 +172,11 @@ public class SlicerService {
|
||||
logger.warning("Slicer reported model out of printable area, retrying with arrange.");
|
||||
continue;
|
||||
}
|
||||
throw new IOException("Slicer failed with exit code " + process.exitValue() + ": " + error);
|
||||
logger.warning("Slicer failed with exit code " + process.exitValue() + ". Log: " + error);
|
||||
throw new ModelProcessingException(
|
||||
"SLICER_EXECUTION_FAILED",
|
||||
"Unable to process this model. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
}
|
||||
|
||||
File gcodeFile = tempDir.resolve(basename + ".gcode").toFile();
|
||||
@@ -145,14 +185,20 @@ public class SlicerService {
|
||||
if (alt.exists()) {
|
||||
gcodeFile = alt;
|
||||
} else {
|
||||
throw new IOException("GCode output not found in " + tempDir);
|
||||
throw new ModelProcessingException(
|
||||
"SLICER_OUTPUT_MISSING",
|
||||
"Unable to generate slicing output for this model. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return gCodeParser.parse(gcodeFile);
|
||||
}
|
||||
|
||||
throw new IOException("Slicer failed after retry");
|
||||
throw new ModelProcessingException(
|
||||
"SLICER_FAILED_AFTER_RETRY",
|
||||
"Unable to process this model. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -274,6 +320,659 @@ public class SlicerService {
|
||||
|| normalized.contains("calc_exclude_triangles");
|
||||
}
|
||||
|
||||
private List<String> resolveSlicerInputPaths(File inputModel, String inputModelPath, Path tempDir)
|
||||
throws IOException, InterruptedException {
|
||||
if (!inputModel.getName().toLowerCase().endsWith(".3mf")) {
|
||||
return List.of(inputModelPath);
|
||||
}
|
||||
|
||||
List<String> convertedStlPaths = convert3mfToStlInputPaths(inputModel, tempDir);
|
||||
logger.info("Converted 3MF to " + convertedStlPaths.size() + " STL file(s) for slicing.");
|
||||
return convertedStlPaths;
|
||||
}
|
||||
|
||||
public Path convert3mfToPersistentStl(File input3mf, Path destinationStl) throws IOException {
|
||||
Path tempDir = Files.createTempDirectory("slicer_convert_");
|
||||
try {
|
||||
List<String> convertedPaths = convert3mfToStlInputPaths(input3mf, tempDir);
|
||||
if (convertedPaths.isEmpty()) {
|
||||
throw new ModelProcessingException(
|
||||
"MODEL_CONVERSION_FAILED",
|
||||
"Unable to process this 3MF file. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
}
|
||||
Path source = Path.of(convertedPaths.get(0));
|
||||
Path parent = destinationStl.toAbsolutePath().normalize().getParent();
|
||||
if (parent != null) {
|
||||
Files.createDirectories(parent);
|
||||
}
|
||||
Files.copy(source, destinationStl, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
return destinationStl;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("Interrupted during 3MF conversion", e);
|
||||
} finally {
|
||||
deleteRecursively(tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> convert3mfToStlInputPaths(File input3mf, Path tempDir) throws IOException, InterruptedException {
|
||||
Path conversionOutputDir = tempDir.resolve("converted-from-3mf");
|
||||
Files.createDirectories(conversionOutputDir);
|
||||
|
||||
String conversionOutputStlPath = requireSafeArgument(
|
||||
conversionOutputDir.resolve("converted.stl").toAbsolutePath().toString(),
|
||||
"3MF conversion output STL path"
|
||||
);
|
||||
String conversionOutputObjPath = requireSafeArgument(
|
||||
conversionOutputDir.resolve("converted.obj").toAbsolutePath().toString(),
|
||||
"3MF conversion output OBJ path"
|
||||
);
|
||||
String input3mfPath = requireSafeArgument(input3mf.getAbsolutePath(), "input 3MF path");
|
||||
|
||||
String stlLog = "";
|
||||
String objLog = "";
|
||||
|
||||
Path lwjglConvertedStl = conversionOutputDir.resolve("converted-lwjgl.stl");
|
||||
try {
|
||||
long lwjglTriangles = convert3mfToStlWithLwjglAssimp(input3mf.toPath(), lwjglConvertedStl);
|
||||
if (lwjglTriangles > 0 && hasRenderableGeometry(lwjglConvertedStl)) {
|
||||
logger.info("Converted 3MF to STL via LWJGL Assimp. Triangles: " + lwjglTriangles);
|
||||
return List.of(lwjglConvertedStl.toString());
|
||||
}
|
||||
logger.warning("LWJGL Assimp conversion produced no renderable geometry.");
|
||||
} catch (Exception | LinkageError e) {
|
||||
logger.warning("LWJGL Assimp conversion failed, falling back to assimp CLI: " + e.getMessage());
|
||||
}
|
||||
|
||||
Path convertedStl = Path.of(conversionOutputStlPath);
|
||||
try {
|
||||
stlLog = runAssimpExport(input3mfPath, conversionOutputStlPath, tempDir.resolve("assimp-convert-stl.log"));
|
||||
if (hasRenderableGeometry(convertedStl)) {
|
||||
return List.of(convertedStl.toString());
|
||||
}
|
||||
logger.warning("Assimp STL conversion produced empty geometry.");
|
||||
} catch (IOException e) {
|
||||
stlLog = e.getMessage() != null ? e.getMessage() : "";
|
||||
logger.warning("Assimp STL conversion failed, trying alternate conversion paths: " + stlLog);
|
||||
}
|
||||
|
||||
logger.warning("Retrying 3MF conversion to OBJ.");
|
||||
|
||||
Path convertedObj = Path.of(conversionOutputObjPath);
|
||||
try {
|
||||
objLog = runAssimpExport(input3mfPath, conversionOutputObjPath, tempDir.resolve("assimp-convert-obj.log"));
|
||||
if (hasRenderableGeometry(convertedObj)) {
|
||||
Path stlFromObj = conversionOutputDir.resolve("converted-from-obj.stl");
|
||||
runAssimpExport(
|
||||
convertedObj.toString(),
|
||||
stlFromObj.toString(),
|
||||
tempDir.resolve("assimp-convert-obj-to-stl.log")
|
||||
);
|
||||
if (hasRenderableGeometry(stlFromObj)) {
|
||||
return List.of(stlFromObj.toString());
|
||||
}
|
||||
logger.warning("Assimp OBJ->STL conversion produced empty geometry.");
|
||||
}
|
||||
logger.warning("Assimp OBJ conversion produced empty geometry.");
|
||||
} catch (IOException e) {
|
||||
objLog = e.getMessage() != null ? e.getMessage() : "";
|
||||
logger.warning("Assimp OBJ conversion failed: " + objLog);
|
||||
}
|
||||
|
||||
Path fallbackStl = conversionOutputDir.resolve("converted-fallback.stl");
|
||||
try {
|
||||
long fallbackTriangles = convert3mfArchiveToAsciiStl(input3mf.toPath(), fallbackStl);
|
||||
if (fallbackTriangles > 0 && hasRenderableGeometry(fallbackStl)) {
|
||||
logger.warning("Assimp conversion produced empty geometry. Fallback 3MF XML extractor generated "
|
||||
+ fallbackTriangles + " triangles.");
|
||||
return List.of(fallbackStl.toString());
|
||||
}
|
||||
logger.warning("3MF XML fallback completed but produced no renderable triangles.");
|
||||
} catch (IOException e) {
|
||||
logger.warning("3MF XML fallback conversion failed: " + e.getMessage());
|
||||
}
|
||||
|
||||
throw new ModelProcessingException(
|
||||
"MODEL_CONVERSION_FAILED",
|
||||
"Unable to process this 3MF file. Try another format or contact us directly via Request Consultation."
|
||||
);
|
||||
}
|
||||
|
||||
private long convert3mfToStlWithLwjglAssimp(Path input3mf, Path outputStl) throws IOException {
|
||||
int flags = aiProcess_Triangulate
|
||||
| aiProcess_JoinIdenticalVertices
|
||||
| aiProcess_PreTransformVertices
|
||||
| aiProcess_SortByPType;
|
||||
AIScene scene = aiImportFile(input3mf.toString(), flags);
|
||||
if (scene == null) {
|
||||
throw new IOException("LWJGL Assimp import failed: " + aiGetErrorString());
|
||||
}
|
||||
|
||||
long triangleCount = 0L;
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(outputStl, StandardCharsets.UTF_8)) {
|
||||
writer.write("solid converted\n");
|
||||
|
||||
int meshCount = scene.mNumMeshes();
|
||||
PointerBuffer meshPointers = scene.mMeshes();
|
||||
if (meshCount <= 0 || meshPointers == null) {
|
||||
throw new IOException("LWJGL Assimp import contains no meshes");
|
||||
}
|
||||
|
||||
for (int meshIndex = 0; meshIndex < meshCount; meshIndex++) {
|
||||
long meshPtr = meshPointers.get(meshIndex);
|
||||
if (meshPtr == 0L) {
|
||||
continue;
|
||||
}
|
||||
AIMesh mesh = AIMesh.create(meshPtr);
|
||||
AIVector3D.Buffer vertices = mesh.mVertices();
|
||||
AIFace.Buffer faces = mesh.mFaces();
|
||||
if (vertices == null || faces == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int vertexCount = mesh.mNumVertices();
|
||||
int faceCount = mesh.mNumFaces();
|
||||
for (int faceIndex = 0; faceIndex < faceCount; faceIndex++) {
|
||||
AIFace face = faces.get(faceIndex);
|
||||
if (face.mNumIndices() != 3) {
|
||||
continue;
|
||||
}
|
||||
IntBuffer indices = face.mIndices();
|
||||
if (indices == null || indices.remaining() < 3) {
|
||||
continue;
|
||||
}
|
||||
int i0 = indices.get(0);
|
||||
int i1 = indices.get(1);
|
||||
int i2 = indices.get(2);
|
||||
if (i0 < 0 || i1 < 0 || i2 < 0
|
||||
|| i0 >= vertexCount
|
||||
|| i1 >= vertexCount
|
||||
|| i2 >= vertexCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vec3 p1 = toVec3(vertices.get(i0));
|
||||
Vec3 p2 = toVec3(vertices.get(i1));
|
||||
Vec3 p3 = toVec3(vertices.get(i2));
|
||||
writeAsciiFacet(writer, p1, p2, p3);
|
||||
triangleCount++;
|
||||
}
|
||||
}
|
||||
|
||||
writer.write("endsolid converted\n");
|
||||
} finally {
|
||||
aiReleaseImport(scene);
|
||||
}
|
||||
|
||||
if (triangleCount <= 0) {
|
||||
throw new IOException("LWJGL Assimp conversion produced no triangles");
|
||||
}
|
||||
return triangleCount;
|
||||
}
|
||||
|
||||
private String runAssimpExport(String input3mfPath, String outputModelPath, Path conversionLogPath)
|
||||
throws IOException, InterruptedException {
|
||||
ProcessBuilder conversionPb = new ProcessBuilder();
|
||||
List<String> conversionCommand = conversionPb.command();
|
||||
conversionCommand.add(trustedAssimpPath);
|
||||
conversionCommand.add("export");
|
||||
conversionCommand.add(input3mfPath);
|
||||
conversionCommand.add(outputModelPath);
|
||||
|
||||
logger.info("Converting 3MF with Assimp: " + String.join(" ", conversionCommand));
|
||||
|
||||
Files.deleteIfExists(conversionLogPath);
|
||||
conversionPb.redirectErrorStream(true);
|
||||
conversionPb.redirectOutput(conversionLogPath.toFile());
|
||||
|
||||
Process conversionProcess = conversionPb.start();
|
||||
boolean conversionFinished = conversionProcess.waitFor(3, TimeUnit.MINUTES);
|
||||
if (!conversionFinished) {
|
||||
conversionProcess.destroyForcibly();
|
||||
throw new IOException("3MF conversion timed out");
|
||||
}
|
||||
|
||||
String conversionLog = Files.exists(conversionLogPath)
|
||||
? Files.readString(conversionLogPath, StandardCharsets.UTF_8)
|
||||
: "";
|
||||
if (conversionProcess.exitValue() != 0) {
|
||||
throw new IOException("3MF conversion failed with exit code "
|
||||
+ conversionProcess.exitValue() + ": " + conversionLog);
|
||||
}
|
||||
return conversionLog;
|
||||
}
|
||||
|
||||
private boolean hasRenderableGeometry(Path modelPath) throws IOException {
|
||||
if (!Files.isRegularFile(modelPath) || Files.size(modelPath) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String fileName = modelPath.getFileName().toString().toLowerCase();
|
||||
if (fileName.endsWith(".obj")) {
|
||||
try (var lines = Files.lines(modelPath)) {
|
||||
return lines.map(String::trim).anyMatch(line -> line.startsWith("f "));
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.endsWith(".stl")) {
|
||||
long size = Files.size(modelPath);
|
||||
if (size <= 84) {
|
||||
return false;
|
||||
}
|
||||
byte[] header = new byte[84];
|
||||
try (InputStream is = Files.newInputStream(modelPath)) {
|
||||
int read = is.read(header);
|
||||
if (read < 84) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
long triangleCount = ((long) (header[80] & 0xff))
|
||||
| (((long) (header[81] & 0xff)) << 8)
|
||||
| (((long) (header[82] & 0xff)) << 16)
|
||||
| (((long) (header[83] & 0xff)) << 24);
|
||||
if (triangleCount > 0) {
|
||||
return true;
|
||||
}
|
||||
try (var lines = Files.lines(modelPath)) {
|
||||
return lines.limit(2000).anyMatch(line -> line.contains("facet normal"));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private long convert3mfArchiveToAsciiStl(Path input3mf, Path outputStl) throws IOException {
|
||||
Map<String, ThreeMfModelDocument> modelCache = new HashMap<>();
|
||||
long[] triangleCount = new long[]{0L};
|
||||
|
||||
try (ZipFile zipFile = new ZipFile(input3mf.toFile());
|
||||
BufferedWriter writer = Files.newBufferedWriter(outputStl, StandardCharsets.UTF_8)) {
|
||||
writer.write("solid converted\n");
|
||||
|
||||
ThreeMfModelDocument rootModel = loadThreeMfModel(zipFile, modelCache, "3D/3dmodel.model");
|
||||
Element build = findFirstChildByLocalName(rootModel.rootElement(), "build");
|
||||
if (build == null) {
|
||||
throw new IOException("3MF build section not found in root model");
|
||||
}
|
||||
|
||||
for (Element item : findChildrenByLocalName(build, "item")) {
|
||||
if ("0".equals(getAttributeByLocalName(item, "printable"))) {
|
||||
continue;
|
||||
}
|
||||
String objectId = getAttributeByLocalName(item, "objectid");
|
||||
if (objectId == null || objectId.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Transform itemTransform = parseTransform(getAttributeByLocalName(item, "transform"));
|
||||
writeObjectTriangles(
|
||||
zipFile,
|
||||
modelCache,
|
||||
rootModel.modelPath(),
|
||||
objectId,
|
||||
itemTransform,
|
||||
writer,
|
||||
triangleCount,
|
||||
new HashSet<>(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
writer.write("endsolid converted\n");
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new IOException("3MF fallback conversion failed: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return triangleCount[0];
|
||||
}
|
||||
|
||||
private void writeObjectTriangles(
|
||||
ZipFile zipFile,
|
||||
Map<String, ThreeMfModelDocument> modelCache,
|
||||
String modelPath,
|
||||
String objectId,
|
||||
Transform transform,
|
||||
BufferedWriter writer,
|
||||
long[] triangleCount,
|
||||
Set<String> recursionGuard,
|
||||
int depth
|
||||
) throws Exception {
|
||||
if (depth > 64) {
|
||||
throw new IOException("3MF component nesting too deep");
|
||||
}
|
||||
|
||||
String guardKey = modelPath + "#" + objectId;
|
||||
if (!recursionGuard.add(guardKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ThreeMfModelDocument modelDocument = loadThreeMfModel(zipFile, modelCache, modelPath);
|
||||
Element objectElement = modelDocument.objectsById().get(objectId);
|
||||
if (objectElement == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Element mesh = findFirstChildByLocalName(objectElement, "mesh");
|
||||
if (mesh != null) {
|
||||
writeMeshTriangles(mesh, transform, writer, triangleCount);
|
||||
}
|
||||
|
||||
Element components = findFirstChildByLocalName(objectElement, "components");
|
||||
if (components != null) {
|
||||
for (Element component : findChildrenByLocalName(components, "component")) {
|
||||
String childObjectId = getAttributeByLocalName(component, "objectid");
|
||||
if (childObjectId == null || childObjectId.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
String componentPath = getAttributeByLocalName(component, "path");
|
||||
String resolvedModelPath = (componentPath == null || componentPath.isBlank())
|
||||
? modelDocument.modelPath()
|
||||
: normalizeZipPath(componentPath);
|
||||
Transform componentTransform = parseTransform(getAttributeByLocalName(component, "transform"));
|
||||
Transform combinedTransform = transform.multiply(componentTransform);
|
||||
|
||||
writeObjectTriangles(
|
||||
zipFile,
|
||||
modelCache,
|
||||
resolvedModelPath,
|
||||
childObjectId,
|
||||
combinedTransform,
|
||||
writer,
|
||||
triangleCount,
|
||||
recursionGuard,
|
||||
depth + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
recursionGuard.remove(guardKey);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeMeshTriangles(
|
||||
Element meshElement,
|
||||
Transform transform,
|
||||
BufferedWriter writer,
|
||||
long[] triangleCount
|
||||
) throws IOException {
|
||||
Element verticesElement = findFirstChildByLocalName(meshElement, "vertices");
|
||||
Element trianglesElement = findFirstChildByLocalName(meshElement, "triangles");
|
||||
if (verticesElement == null || trianglesElement == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Vec3> vertices = new java.util.ArrayList<>();
|
||||
for (Element vertex : findChildrenByLocalName(verticesElement, "vertex")) {
|
||||
Double x = parseDoubleAttribute(vertex, "x");
|
||||
Double y = parseDoubleAttribute(vertex, "y");
|
||||
Double z = parseDoubleAttribute(vertex, "z");
|
||||
if (x == null || y == null || z == null) {
|
||||
continue;
|
||||
}
|
||||
vertices.add(new Vec3(x, y, z));
|
||||
}
|
||||
|
||||
if (vertices.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Element triangle : findChildrenByLocalName(trianglesElement, "triangle")) {
|
||||
Integer v1 = parseIntAttribute(triangle, "v1");
|
||||
Integer v2 = parseIntAttribute(triangle, "v2");
|
||||
Integer v3 = parseIntAttribute(triangle, "v3");
|
||||
if (v1 == null || v2 == null || v3 == null) {
|
||||
continue;
|
||||
}
|
||||
if (v1 < 0 || v2 < 0 || v3 < 0 || v1 >= vertices.size() || v2 >= vertices.size() || v3 >= vertices.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vec3 p1 = transform.apply(vertices.get(v1));
|
||||
Vec3 p2 = transform.apply(vertices.get(v2));
|
||||
Vec3 p3 = transform.apply(vertices.get(v3));
|
||||
writeAsciiFacet(writer, p1, p2, p3);
|
||||
triangleCount[0]++;
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAsciiFacet(BufferedWriter writer, Vec3 p1, Vec3 p2, Vec3 p3) throws IOException {
|
||||
Vec3 normal = computeNormal(p1, p2, p3);
|
||||
writer.write("facet normal " + normal.x() + " " + normal.y() + " " + normal.z() + "\n");
|
||||
writer.write(" outer loop\n");
|
||||
writer.write(" vertex " + p1.x() + " " + p1.y() + " " + p1.z() + "\n");
|
||||
writer.write(" vertex " + p2.x() + " " + p2.y() + " " + p2.z() + "\n");
|
||||
writer.write(" vertex " + p3.x() + " " + p3.y() + " " + p3.z() + "\n");
|
||||
writer.write(" endloop\n");
|
||||
writer.write("endfacet\n");
|
||||
}
|
||||
|
||||
private Vec3 toVec3(AIVector3D v) {
|
||||
return new Vec3(v.x(), v.y(), v.z());
|
||||
}
|
||||
|
||||
private Vec3 computeNormal(Vec3 a, Vec3 b, Vec3 c) {
|
||||
double ux = b.x() - a.x();
|
||||
double uy = b.y() - a.y();
|
||||
double uz = b.z() - a.z();
|
||||
double vx = c.x() - a.x();
|
||||
double vy = c.y() - a.y();
|
||||
double vz = c.z() - a.z();
|
||||
|
||||
double nx = uy * vz - uz * vy;
|
||||
double ny = uz * vx - ux * vz;
|
||||
double nz = ux * vy - uy * vx;
|
||||
double length = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
||||
if (length <= 1e-12) {
|
||||
return new Vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
return new Vec3(nx / length, ny / length, nz / length);
|
||||
}
|
||||
|
||||
private ThreeMfModelDocument loadThreeMfModel(
|
||||
ZipFile zipFile,
|
||||
Map<String, ThreeMfModelDocument> modelCache,
|
||||
String modelPath
|
||||
) throws Exception {
|
||||
String normalizedPath = normalizeZipPath(modelPath);
|
||||
ThreeMfModelDocument cached = modelCache.get(normalizedPath);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
ZipEntry entry = zipFile.getEntry(normalizedPath);
|
||||
if (entry == null) {
|
||||
throw new IOException("3MF model entry not found: " + normalizedPath);
|
||||
}
|
||||
|
||||
Document document = parseXmlDocument(zipFile, entry);
|
||||
Element root = document.getDocumentElement();
|
||||
Map<String, Element> objectsById = new HashMap<>();
|
||||
Element resources = findFirstChildByLocalName(root, "resources");
|
||||
if (resources != null) {
|
||||
for (Element objectElement : findChildrenByLocalName(resources, "object")) {
|
||||
String id = getAttributeByLocalName(objectElement, "id");
|
||||
if (id != null && !id.isBlank()) {
|
||||
objectsById.put(id, objectElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ThreeMfModelDocument loaded = new ThreeMfModelDocument(normalizedPath, root, objectsById);
|
||||
modelCache.put(normalizedPath, loaded);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
private Document parseXmlDocument(ZipFile zipFile, ZipEntry entry) throws Exception {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
dbf.setNamespaceAware(true);
|
||||
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
try {
|
||||
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort hardening.
|
||||
}
|
||||
try {
|
||||
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort hardening.
|
||||
}
|
||||
dbf.setXIncludeAware(false);
|
||||
dbf.setExpandEntityReferences(false);
|
||||
|
||||
try (InputStream is = zipFile.getInputStream(entry)) {
|
||||
return dbf.newDocumentBuilder().parse(is);
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeZipPath(String rawPath) throws IOException {
|
||||
if (rawPath == null || rawPath.isBlank()) {
|
||||
throw new IOException("Invalid empty 3MF model path");
|
||||
}
|
||||
String normalized = rawPath.trim().replace("\\", "/");
|
||||
while (normalized.startsWith("/")) {
|
||||
normalized = normalized.substring(1);
|
||||
}
|
||||
if (normalized.contains("..")) {
|
||||
throw new IOException("Invalid 3MF model path: " + rawPath);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private List<Element> findChildrenByLocalName(Element parent, String localName) {
|
||||
List<Element> result = new java.util.ArrayList<>();
|
||||
NodeList children = parent.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
String nodeLocalName = element.getLocalName() != null ? element.getLocalName() : element.getTagName();
|
||||
if (localName.equals(nodeLocalName)) {
|
||||
result.add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Element findFirstChildByLocalName(Element parent, String localName) {
|
||||
NodeList children = parent.getChildNodes();
|
||||
for (int i = 0; i < children.getLength(); i++) {
|
||||
Node node = children.item(i);
|
||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element element = (Element) node;
|
||||
String nodeLocalName = element.getLocalName() != null ? element.getLocalName() : element.getTagName();
|
||||
if (localName.equals(nodeLocalName)) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getAttributeByLocalName(Element element, String localName) {
|
||||
if (element.hasAttribute(localName)) {
|
||||
return element.getAttribute(localName);
|
||||
}
|
||||
NamedNodeMap attrs = element.getAttributes();
|
||||
for (int i = 0; i < attrs.getLength(); i++) {
|
||||
Node attr = attrs.item(i);
|
||||
String attrLocal = attr.getLocalName() != null ? attr.getLocalName() : attr.getNodeName();
|
||||
if (localName.equals(attrLocal)) {
|
||||
return attr.getNodeValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Double parseDoubleAttribute(Element element, String attributeName) {
|
||||
String value = getAttributeByLocalName(element, attributeName);
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer parseIntAttribute(Element element, String attributeName) {
|
||||
String value = getAttributeByLocalName(element, attributeName);
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Transform parseTransform(String rawTransform) throws IOException {
|
||||
if (rawTransform == null || rawTransform.isBlank()) {
|
||||
return Transform.identity();
|
||||
}
|
||||
String[] tokens = rawTransform.trim().split("\\s+");
|
||||
if (tokens.length != 12) {
|
||||
throw new IOException("Invalid 3MF transform format: " + rawTransform);
|
||||
}
|
||||
double[] v = new double[12];
|
||||
for (int i = 0; i < 12; i++) {
|
||||
try {
|
||||
v[i] = Double.parseDouble(tokens[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IOException("Invalid number in 3MF transform: " + rawTransform, e);
|
||||
}
|
||||
}
|
||||
return new Transform(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11]);
|
||||
}
|
||||
|
||||
private record ThreeMfModelDocument(String modelPath, Element rootElement, Map<String, Element> objectsById) {
|
||||
}
|
||||
|
||||
private record Vec3(double x, double y, double z) {
|
||||
}
|
||||
|
||||
private record Transform(
|
||||
double m00, double m01, double m02,
|
||||
double m10, double m11, double m12,
|
||||
double m20, double m21, double m22,
|
||||
double tx, double ty, double tz
|
||||
) {
|
||||
static Transform identity() {
|
||||
return new Transform(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
Transform multiply(Transform other) {
|
||||
return new Transform(
|
||||
m00 * other.m00 + m01 * other.m10 + m02 * other.m20,
|
||||
m00 * other.m01 + m01 * other.m11 + m02 * other.m21,
|
||||
m00 * other.m02 + m01 * other.m12 + m02 * other.m22,
|
||||
m10 * other.m00 + m11 * other.m10 + m12 * other.m20,
|
||||
m10 * other.m01 + m11 * other.m11 + m12 * other.m21,
|
||||
m10 * other.m02 + m11 * other.m12 + m12 * other.m22,
|
||||
m20 * other.m00 + m21 * other.m10 + m22 * other.m20,
|
||||
m20 * other.m01 + m21 * other.m11 + m22 * other.m21,
|
||||
m20 * other.m02 + m21 * other.m12 + m22 * other.m22,
|
||||
m00 * other.tx + m01 * other.ty + m02 * other.tz + tx,
|
||||
m10 * other.tx + m11 * other.ty + m12 * other.tz + ty,
|
||||
m20 * other.tx + m21 * other.ty + m22 * other.tz + tz
|
||||
);
|
||||
}
|
||||
|
||||
Vec3 apply(Vec3 v) {
|
||||
return new Vec3(
|
||||
m00 * v.x() + m01 * v.y() + m02 * v.z() + tx,
|
||||
m10 * v.x() + m11 * v.y() + m12 * v.z() + ty,
|
||||
m20 * v.x() + m21 * v.y() + m22 * v.z() + tz
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeExecutablePath(String configuredPath) {
|
||||
if (configuredPath == null || configuredPath.isBlank()) {
|
||||
throw new IllegalArgumentException("slicer.path is required");
|
||||
|
||||
@@ -4,7 +4,7 @@ server.port=8000
|
||||
# Database Configuration
|
||||
spring.datasource.url=${DB_URL:jdbc:postgresql://localhost:5432/printcalc}
|
||||
spring.datasource.username=${DB_USERNAME:printcalc}
|
||||
spring.datasource.password=${DB_PASSWORD:}
|
||||
spring.datasource.password=${DB_PASSWORD:printcalc_secret}
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
spring.jpa.open-in-view=false
|
||||
@@ -13,6 +13,7 @@ spring.jpa.open-in-view=false
|
||||
# Slicer Configuration
|
||||
# Map SLICER_PATH env var if present (default to /opt/orcaslicer/AppRun or Mac path)
|
||||
slicer.path=${SLICER_PATH:/Applications/OrcaSlicer.app/Contents/MacOS/OrcaSlicer}
|
||||
assimp.path=${ASSIMP_PATH:assimp}
|
||||
profiles.root=${PROFILES_DIR:profiles}
|
||||
|
||||
|
||||
@@ -43,6 +44,7 @@ app.mail.admin.enabled=${APP_MAIL_ADMIN_ENABLED:true}
|
||||
app.mail.admin.address=${APP_MAIL_ADMIN_ADDRESS:admin@printcalculator.local}
|
||||
app.mail.contact-request.admin.enabled=${APP_MAIL_CONTACT_REQUEST_ADMIN_ENABLED:true}
|
||||
app.mail.contact-request.admin.address=${APP_MAIL_CONTACT_REQUEST_ADMIN_ADDRESS:infog@3d-fab.ch}
|
||||
app.mail.contact-request.customer.enabled=${APP_MAIL_CONTACT_REQUEST_CUSTOMER_ENABLED:true}
|
||||
app.frontend.base-url=${APP_FRONTEND_BASE_URL:http://localhost:4200}
|
||||
|
||||
# Admin back-office authentication
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title th:text="${emailTitle}">Contact request received</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 640px;
|
||||
margin: 20px auto;
|
||||
background-color: #ffffff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
color: #222222;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin-top: 18px;
|
||||
color: #222222;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #444444;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
border-bottom: 1px solid #eeeeee;
|
||||
padding: 10px 6px;
|
||||
color: #333333;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
th {
|
||||
width: 35%;
|
||||
color: #222222;
|
||||
background: #fafafa;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 24px;
|
||||
font-size: 12px;
|
||||
color: #888888;
|
||||
border-top: 1px solid #eeeeee;
|
||||
padding-top: 12px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 th:text="${headlineText}">We received your contact request</h1>
|
||||
<p th:text="${greetingText}">Hi customer,</p>
|
||||
<p th:text="${introText}">Thank you for contacting us. Our team will reply as soon as possible.</p>
|
||||
<p>
|
||||
<strong th:text="${requestIdHintText}">Please keep this request ID for future order references:</strong>
|
||||
<span th:text="${requestId}">00000000-0000-0000-0000-000000000000</span>
|
||||
</p>
|
||||
<h2 th:text="${detailsTitleText}">Request details</h2>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th th:text="${labelRequestId}">Request ID</th>
|
||||
<td th:text="${requestId}">00000000-0000-0000-0000-000000000000</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelDate}">Date</th>
|
||||
<td th:text="${createdAt}">2026-03-03T10:00:00Z</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelRequestType}">Request type</th>
|
||||
<td th:text="${requestType}">custom</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelCustomerType}">Customer type</th>
|
||||
<td th:text="${customerType}">PRIVATE</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelName}">Name</th>
|
||||
<td th:text="${name}">Mario Rossi</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelCompany}">Company</th>
|
||||
<td th:text="${companyName}">3D Fab SA</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelContactPerson}">Contact person</th>
|
||||
<td th:text="${contactPerson}">Mario Rossi</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelEmail}">Email</th>
|
||||
<td th:text="${email}">cliente@example.com</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelPhone}">Phone</th>
|
||||
<td th:text="${phone}">+41 00 000 00 00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelMessage}">Message</th>
|
||||
<td th:text="${message}">Testo richiesta cliente...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th th:text="${labelAttachments}">Attachments</th>
|
||||
<td th:text="${attachmentsCount}">0</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p th:text="${supportText}">If you need help, reply to this email.</p>
|
||||
|
||||
<div class="footer">
|
||||
<p>© <span th:text="${currentYear}">2026</span> <span th:text="${footerText}">Automated request-receipt confirmation from 3D-Fab.</span></p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.printcalculator.service;
|
||||
|
||||
import com.printcalculator.entity.PricingPolicy;
|
||||
import com.printcalculator.entity.QuoteLineItem;
|
||||
import com.printcalculator.entity.QuoteSession;
|
||||
import com.printcalculator.repository.PricingPolicyRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class QuoteSessionTotalsServiceTest {
|
||||
private PricingPolicyRepository pricingRepo;
|
||||
private QuoteCalculator quoteCalculator;
|
||||
private QuoteSessionTotalsService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
pricingRepo = mock(PricingPolicyRepository.class);
|
||||
quoteCalculator = mock(QuoteCalculator.class);
|
||||
service = new QuoteSessionTotalsService(pricingRepo, quoteCalculator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void compute_WithCadOnlySession_ShouldIncludeCadAndNoShipping() {
|
||||
QuoteSession session = new QuoteSession();
|
||||
session.setSetupCostChf(BigDecimal.ZERO);
|
||||
session.setCadHours(BigDecimal.valueOf(2));
|
||||
session.setCadHourlyRateChf(BigDecimal.valueOf(75));
|
||||
|
||||
PricingPolicy policy = new PricingPolicy();
|
||||
when(pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc()).thenReturn(policy);
|
||||
when(quoteCalculator.calculateSessionMachineCost(eq(policy), any(BigDecimal.class))).thenReturn(BigDecimal.ZERO);
|
||||
|
||||
QuoteSessionTotalsService.QuoteSessionTotals totals = service.compute(session, List.of());
|
||||
|
||||
assertAmountEquals("150.00", totals.cadTotalChf());
|
||||
assertAmountEquals("0.00", totals.shippingCostChf());
|
||||
assertAmountEquals("150.00", totals.itemsTotalChf());
|
||||
assertAmountEquals("150.00", totals.grandTotalChf());
|
||||
}
|
||||
|
||||
@Test
|
||||
void compute_WithPrintItemAndCad_ShouldSumEverything() {
|
||||
QuoteSession session = new QuoteSession();
|
||||
session.setSetupCostChf(new BigDecimal("5.00"));
|
||||
session.setCadHours(new BigDecimal("1.50"));
|
||||
session.setCadHourlyRateChf(new BigDecimal("60.00"));
|
||||
|
||||
QuoteLineItem item = new QuoteLineItem();
|
||||
item.setQuantity(2);
|
||||
item.setUnitPriceChf(new BigDecimal("10.00"));
|
||||
item.setPrintTimeSeconds(3600);
|
||||
item.setBoundingBoxXMm(new BigDecimal("10"));
|
||||
item.setBoundingBoxYMm(new BigDecimal("10"));
|
||||
item.setBoundingBoxZMm(new BigDecimal("10"));
|
||||
|
||||
PricingPolicy policy = new PricingPolicy();
|
||||
when(pricingRepo.findFirstByIsActiveTrueOrderByValidFromDesc()).thenReturn(policy);
|
||||
when(quoteCalculator.calculateSessionMachineCost(policy, new BigDecimal("2.0000")))
|
||||
.thenReturn(new BigDecimal("3.00"));
|
||||
|
||||
QuoteSessionTotalsService.QuoteSessionTotals totals = service.compute(session, List.of(item));
|
||||
|
||||
assertAmountEquals("23.00", totals.printItemsTotalChf());
|
||||
assertAmountEquals("90.00", totals.cadTotalChf());
|
||||
assertAmountEquals("113.00", totals.itemsTotalChf());
|
||||
assertAmountEquals("2.00", totals.shippingCostChf());
|
||||
assertAmountEquals("120.00", totals.grandTotalChf());
|
||||
}
|
||||
|
||||
private void assertAmountEquals(String expected, BigDecimal actual) {
|
||||
assertTrue(new BigDecimal(expected).compareTo(actual) == 0,
|
||||
"Expected " + expected + " but got " + actual);
|
||||
}
|
||||
}
|
||||
61
db.sql
61
db.sql
@@ -599,7 +599,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS ux_customers_email
|
||||
CREATE TABLE IF NOT EXISTS quote_sessions
|
||||
(
|
||||
quote_session_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
status text NOT NULL CHECK (status IN ('ACTIVE', 'EXPIRED', 'CONVERTED')),
|
||||
status text NOT NULL CHECK (status IN ('ACTIVE', 'CAD_ACTIVE', 'EXPIRED', 'CONVERTED')),
|
||||
pricing_version text NOT NULL,
|
||||
|
||||
-- Parametri "globali" (dalla tua UI avanzata)
|
||||
@@ -612,6 +612,9 @@ CREATE TABLE IF NOT EXISTS quote_sessions
|
||||
notes text,
|
||||
|
||||
setup_cost_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||
source_request_id uuid,
|
||||
cad_hours numeric(10, 2),
|
||||
cad_hourly_rate_chf numeric(10, 2),
|
||||
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
expires_at timestamptz NOT NULL,
|
||||
@@ -624,6 +627,25 @@ CREATE INDEX IF NOT EXISTS ix_quote_sessions_status
|
||||
CREATE INDEX IF NOT EXISTS ix_quote_sessions_expires_at
|
||||
ON quote_sessions (expires_at);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_quote_sessions_source_request
|
||||
ON quote_sessions (source_request_id);
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
ADD COLUMN IF NOT EXISTS source_request_id uuid;
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
ADD COLUMN IF NOT EXISTS cad_hours numeric(10, 2);
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
ADD COLUMN IF NOT EXISTS cad_hourly_rate_chf numeric(10, 2);
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
DROP CONSTRAINT IF EXISTS quote_sessions_status_check;
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
ADD CONSTRAINT quote_sessions_status_check
|
||||
CHECK (status IN ('ACTIVE', 'CAD_ACTIVE', 'EXPIRED', 'CONVERTED'));
|
||||
|
||||
-- =========================
|
||||
-- QUOTE LINE ITEMS (1 file = 1 riga)
|
||||
-- =========================
|
||||
@@ -676,6 +698,7 @@ CREATE TABLE IF NOT EXISTS orders
|
||||
(
|
||||
order_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
source_quote_session_id uuid REFERENCES quote_sessions (quote_session_id),
|
||||
source_request_id uuid,
|
||||
|
||||
status text NOT NULL CHECK (status IN (
|
||||
'PENDING_PAYMENT', 'PAID', 'IN_PRODUCTION',
|
||||
@@ -717,6 +740,10 @@ CREATE TABLE IF NOT EXISTS orders
|
||||
discount_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||
|
||||
subtotal_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||
is_cad_order boolean NOT NULL DEFAULT false,
|
||||
cad_hours numeric(10, 2),
|
||||
cad_hourly_rate_chf numeric(10, 2),
|
||||
cad_total_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||
total_chf numeric(12, 2) NOT NULL DEFAULT 0.00,
|
||||
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
@@ -730,6 +757,24 @@ CREATE INDEX IF NOT EXISTS ix_orders_status
|
||||
CREATE INDEX IF NOT EXISTS ix_orders_customer_email
|
||||
ON orders (lower(customer_email));
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_orders_source_request
|
||||
ON orders (source_request_id);
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS source_request_id uuid;
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS is_cad_order boolean NOT NULL DEFAULT false;
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS cad_hours numeric(10, 2);
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS cad_hourly_rate_chf numeric(10, 2);
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD COLUMN IF NOT EXISTS cad_total_chf numeric(12, 2) NOT NULL DEFAULT 0.00;
|
||||
|
||||
-- =========================
|
||||
-- ORDER ITEMS (1 file 3D = 1 riga, file salvato su disco)
|
||||
-- =========================
|
||||
@@ -849,3 +894,17 @@ CREATE TABLE IF NOT EXISTS custom_quote_request_attachments
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_custom_quote_attachments_request
|
||||
ON custom_quote_request_attachments (request_id);
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
DROP CONSTRAINT IF EXISTS fk_quote_sessions_source_request;
|
||||
|
||||
ALTER TABLE quote_sessions
|
||||
ADD CONSTRAINT fk_quote_sessions_source_request
|
||||
FOREIGN KEY (source_request_id) REFERENCES custom_quote_requests (request_id);
|
||||
|
||||
ALTER TABLE orders
|
||||
DROP CONSTRAINT IF EXISTS fk_orders_source_request;
|
||||
|
||||
ALTER TABLE orders
|
||||
ADD CONSTRAINT fk_orders_source_request
|
||||
FOREIGN KEY (source_request_id) REFERENCES custom_quote_requests (request_id);
|
||||
|
||||
@@ -28,6 +28,13 @@ const appChildRoutes: Routes = [
|
||||
loadChildren: () =>
|
||||
import('./features/contact/contact.routes').then((m) => m.CONTACT_ROUTES),
|
||||
},
|
||||
{
|
||||
path: 'checkout/cad',
|
||||
loadComponent: () =>
|
||||
import('./features/checkout/checkout.component').then(
|
||||
(m) => m.CheckoutComponent,
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'checkout',
|
||||
loadComponent: () =>
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
}
|
||||
</select>
|
||||
|
||||
<div class="icon-placeholder">
|
||||
<div class="icon-placeholder" routerLink="/admin">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component } from '@angular/core';
|
||||
import { RouterLink, RouterLinkActive } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { LanguageService } from '../services/language.service';
|
||||
import { routes } from '../../app.routes';
|
||||
|
||||
@Component({
|
||||
selector: 'app-navbar',
|
||||
@@ -37,4 +38,6 @@ export class NavbarComponent {
|
||||
closeMenu() {
|
||||
this.isMenuOpen = false;
|
||||
}
|
||||
|
||||
protected readonly routes = routes;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { environment } from '../../../environments/environment';
|
||||
export interface QuoteRequestDto {
|
||||
requestType: string;
|
||||
customerType: string;
|
||||
language?: 'it' | 'en' | 'de' | 'fr';
|
||||
email: string;
|
||||
phone?: string;
|
||||
name?: string;
|
||||
|
||||
@@ -16,6 +16,7 @@ type PassionId =
|
||||
| 'woodworking'
|
||||
| 'van-life'
|
||||
| 'coffee'
|
||||
| 'cooking'
|
||||
| 'software-development';
|
||||
|
||||
interface PassionChip {
|
||||
@@ -50,6 +51,7 @@ export class AboutPageComponent {
|
||||
{ id: 'snowboard', labelKey: 'ABOUT.PASSION_SNOWBOARD' },
|
||||
{ id: 'van-life', labelKey: 'ABOUT.PASSION_VAN_LIFE' },
|
||||
{ id: 'self-hosting', labelKey: 'ABOUT.PASSION_SELF_HOSTING' },
|
||||
{ id: 'cooking', labelKey: 'ABOUT.PASSION_COOKING' },
|
||||
{
|
||||
id: 'snowboard-instructor',
|
||||
labelKey: 'ABOUT.PASSION_SNOWBOARD_INSTRUCTOR',
|
||||
@@ -67,6 +69,7 @@ export class AboutPageComponent {
|
||||
'print-3d',
|
||||
'travel',
|
||||
'coffee',
|
||||
'cooking',
|
||||
'software-development',
|
||||
],
|
||||
matteo: [
|
||||
|
||||
@@ -50,6 +50,13 @@ export const ADMIN_ROUTES: Routes = [
|
||||
(m) => m.AdminSessionsComponent,
|
||||
),
|
||||
},
|
||||
{
|
||||
path: 'cad-invoices',
|
||||
loadComponent: () =>
|
||||
import('./pages/admin-cad-invoices.component').then(
|
||||
(m) => m.AdminCadInvoicesComponent,
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<section class="cad-page">
|
||||
<header class="page-header">
|
||||
<div>
|
||||
<h1>Fatture CAD</h1>
|
||||
<p>
|
||||
Crea un checkout CAD partendo da una sessione esistente (opzionale) e
|
||||
gestisci lo stato fino all'ordine.
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" (click)="loadCadInvoices()" [disabled]="loading">
|
||||
Aggiorna
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<p class="error" *ngIf="errorMessage">{{ errorMessage }}</p>
|
||||
<p class="success" *ngIf="successMessage">{{ successMessage }}</p>
|
||||
|
||||
<section class="create-box">
|
||||
<h2>Crea nuova fattura CAD</h2>
|
||||
<div class="form-grid">
|
||||
<label>
|
||||
<span>ID Sessione (opzionale)</span>
|
||||
<input
|
||||
[(ngModel)]="form.sessionId"
|
||||
placeholder="UUID sessione quote"
|
||||
type="text"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>ID Richiesta Contatto (opzionale)</span>
|
||||
<input
|
||||
[(ngModel)]="form.sourceRequestId"
|
||||
placeholder="UUID richiesta contatto"
|
||||
type="text"
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>Ore CAD</span>
|
||||
<input [(ngModel)]="form.cadHours" min="0.1" step="0.1" type="number" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Tariffa CAD CHF/h (opzionale)</span>
|
||||
<input
|
||||
[(ngModel)]="form.cadHourlyRateChf"
|
||||
placeholder="Se vuoto usa pricing policy attiva"
|
||||
min="0"
|
||||
step="0.05"
|
||||
type="number"
|
||||
/>
|
||||
</label>
|
||||
<label class="notes-field">
|
||||
<span>Nota (opzionale)</span>
|
||||
<textarea
|
||||
[(ngModel)]="form.notes"
|
||||
placeholder="Nota visibile nel checkout CAD (es. dettagli lavorazione)"
|
||||
rows="3"
|
||||
></textarea>
|
||||
</label>
|
||||
</div>
|
||||
<div class="create-actions">
|
||||
<button type="button" (click)="createCadInvoice()" [disabled]="creating">
|
||||
{{ creating ? "Creazione..." : "Crea link checkout CAD" }}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="table-wrap" *ngIf="!loading; else loadingTpl">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sessione</th>
|
||||
<th>Richiesta</th>
|
||||
<th>Ore CAD</th>
|
||||
<th>Tariffa</th>
|
||||
<th>Totale CAD</th>
|
||||
<th>Totale ordine</th>
|
||||
<th>Stato sessione</th>
|
||||
<th>Nota</th>
|
||||
<th>Ordine</th>
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let row of invoices">
|
||||
<td [title]="row.sessionId" [appCopyOnClick]="row.sessionId">
|
||||
{{ row.sessionId | slice: 0 : 8 }}
|
||||
</td>
|
||||
<td
|
||||
[title]="row.sourceRequestId || ''"
|
||||
[appCopyOnClick]="row.sourceRequestId"
|
||||
>
|
||||
{{ row.sourceRequestId || "-" }}
|
||||
</td>
|
||||
<td>{{ row.cadHours }}</td>
|
||||
<td>{{ row.cadHourlyRateChf | currency: "CHF" }}</td>
|
||||
<td>{{ row.cadTotalChf | currency: "CHF" }}</td>
|
||||
<td>{{ row.grandTotalChf | currency: "CHF" }}</td>
|
||||
<td>{{ row.sessionStatus }}</td>
|
||||
<td class="notes-cell" [title]="row.notes || ''">
|
||||
{{ row.notes || "-" }}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
*ngIf="row.convertedOrderId; else noOrder"
|
||||
[title]="row.convertedOrderId || ''"
|
||||
[appCopyOnClick]="row.convertedOrderId"
|
||||
>
|
||||
{{ row.convertedOrderId | slice: 0 : 8 }} ({{
|
||||
row.convertedOrderStatus || "-"
|
||||
}})
|
||||
</span>
|
||||
<ng-template #noOrder>-</ng-template>
|
||||
</td>
|
||||
<td class="actions">
|
||||
<button
|
||||
type="button"
|
||||
class="ghost"
|
||||
(click)="openCheckout(row.checkoutPath)"
|
||||
>
|
||||
Apri checkout
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="ghost"
|
||||
(click)="copyCheckout(row.checkoutPath)"
|
||||
>
|
||||
Copia link
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="ghost"
|
||||
*ngIf="row.convertedOrderId"
|
||||
(click)="downloadInvoice(row.convertedOrderId)"
|
||||
>
|
||||
Scarica fattura
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr *ngIf="invoices.length === 0">
|
||||
<td colspan="10">Nessuna fattura CAD trovata.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<ng-template #loadingTpl>
|
||||
<p>Caricamento fatture CAD...</p>
|
||||
</ng-template>
|
||||
@@ -0,0 +1,140 @@
|
||||
.cad-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-5);
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-4);
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.page-header h1 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.page-header p {
|
||||
margin: var(--space-2) 0 0;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
button {
|
||||
border: 0;
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--space-2) var(--space-4);
|
||||
background: var(--color-brand);
|
||||
color: var(--color-neutral-900);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.65;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.create-box {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--color-bg-card);
|
||||
padding: var(--space-4);
|
||||
}
|
||||
|
||||
.create-box h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.form-grid label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.form-grid span {
|
||||
font-size: 0.9rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.form-grid input {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
|
||||
.notes-field {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.form-grid textarea {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: var(--space-2);
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.create-actions {
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
min-width: 1100px;
|
||||
}
|
||||
|
||||
th,
|
||||
td {
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
padding: var(--space-2);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.notes-cell {
|
||||
max-width: 280px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.ghost {
|
||||
background: transparent;
|
||||
border: 1px solid var(--color-border);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.error {
|
||||
color: var(--color-danger-500);
|
||||
}
|
||||
|
||||
.success {
|
||||
color: var(--color-success-500);
|
||||
}
|
||||
|
||||
@media (max-width: 880px) {
|
||||
.page-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import {
|
||||
AdminCadInvoice,
|
||||
AdminOperationsService,
|
||||
} from '../services/admin-operations.service';
|
||||
import { AdminOrdersService } from '../services/admin-orders.service';
|
||||
import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.directive';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-cad-invoices',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule, CopyOnClickDirective],
|
||||
templateUrl: './admin-cad-invoices.component.html',
|
||||
styleUrl: './admin-cad-invoices.component.scss',
|
||||
})
|
||||
export class AdminCadInvoicesComponent implements OnInit {
|
||||
private readonly adminOperationsService = inject(AdminOperationsService);
|
||||
private readonly adminOrdersService = inject(AdminOrdersService);
|
||||
|
||||
invoices: AdminCadInvoice[] = [];
|
||||
loading = false;
|
||||
creating = false;
|
||||
errorMessage: string | null = null;
|
||||
successMessage: string | null = null;
|
||||
|
||||
form = {
|
||||
sessionId: '',
|
||||
sourceRequestId: '',
|
||||
cadHours: 1,
|
||||
cadHourlyRateChf: '',
|
||||
notes: '',
|
||||
};
|
||||
|
||||
ngOnInit(): void {
|
||||
this.loadCadInvoices();
|
||||
}
|
||||
|
||||
loadCadInvoices(): void {
|
||||
this.loading = true;
|
||||
this.errorMessage = null;
|
||||
this.adminOperationsService.listCadInvoices().subscribe({
|
||||
next: (rows) => {
|
||||
this.invoices = rows;
|
||||
this.loading = false;
|
||||
},
|
||||
error: () => {
|
||||
this.loading = false;
|
||||
this.errorMessage = 'Impossibile caricare le fatture CAD.';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
createCadInvoice(): void {
|
||||
if (this.creating) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cadHours = Number(this.form.cadHours);
|
||||
if (!Number.isFinite(cadHours) || cadHours <= 0) {
|
||||
this.errorMessage = 'Inserisci ore CAD valide (> 0).';
|
||||
return;
|
||||
}
|
||||
|
||||
this.creating = true;
|
||||
this.errorMessage = null;
|
||||
this.successMessage = null;
|
||||
|
||||
let payload: {
|
||||
sessionId?: string;
|
||||
sourceRequestId?: string;
|
||||
cadHours: number;
|
||||
cadHourlyRateChf?: number;
|
||||
notes?: string;
|
||||
};
|
||||
|
||||
try {
|
||||
const sessionIdRaw = String(this.form.sessionId ?? '').trim();
|
||||
const sourceRequestIdRaw = String(this.form.sourceRequestId ?? '').trim();
|
||||
const cadRateRaw = String(this.form.cadHourlyRateChf ?? '').trim();
|
||||
const notesRaw = String(this.form.notes ?? '').trim();
|
||||
|
||||
payload = {
|
||||
sessionId: sessionIdRaw || undefined,
|
||||
sourceRequestId: sourceRequestIdRaw || undefined,
|
||||
cadHours,
|
||||
cadHourlyRateChf:
|
||||
cadRateRaw.length > 0 && Number.isFinite(Number(cadRateRaw))
|
||||
? Number(cadRateRaw)
|
||||
: undefined,
|
||||
notes: notesRaw.length > 0 ? notesRaw : undefined,
|
||||
};
|
||||
} catch {
|
||||
this.creating = false;
|
||||
this.errorMessage = 'Valori form non validi.';
|
||||
return;
|
||||
}
|
||||
|
||||
this.adminOperationsService.createCadInvoice(payload).subscribe({
|
||||
next: (created) => {
|
||||
this.creating = false;
|
||||
this.successMessage = `Fattura CAD pronta. Sessione: ${created.sessionId}`;
|
||||
this.loadCadInvoices();
|
||||
},
|
||||
error: (err) => {
|
||||
this.creating = false;
|
||||
this.errorMessage =
|
||||
err?.error?.message || 'Creazione fattura CAD non riuscita.';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
openCheckout(path: string): void {
|
||||
const url = this.toCheckoutUrl(path);
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
copyCheckout(path: string): void {
|
||||
const url = this.toCheckoutUrl(path);
|
||||
navigator.clipboard?.writeText(url);
|
||||
this.successMessage = 'Link checkout CAD copiato negli appunti.';
|
||||
}
|
||||
|
||||
downloadInvoice(orderId?: string): void {
|
||||
if (!orderId) return;
|
||||
this.adminOrdersService.downloadOrderInvoice(orderId).subscribe({
|
||||
next: (blob) => {
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `fattura-cad-${orderId}.pdf`;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
},
|
||||
error: () => {
|
||||
this.errorMessage = 'Download fattura non riuscito.';
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private toCheckoutUrl(path: string): string {
|
||||
const safePath = path.startsWith('/') ? path : `/${path}`;
|
||||
const lang = this.resolveLang();
|
||||
return `${window.location.origin}/${lang}${safePath}`;
|
||||
}
|
||||
|
||||
private resolveLang(): string {
|
||||
const firstSegment = window.location.pathname
|
||||
.split('/')
|
||||
.filter(Boolean)
|
||||
.shift();
|
||||
if (firstSegment && ['it', 'en', 'de', 'fr'].includes(firstSegment)) {
|
||||
return firstSegment;
|
||||
}
|
||||
return 'it';
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,12 @@
|
||||
<div>
|
||||
<h3>Dettaglio richiesta</h3>
|
||||
<p class="request-id">
|
||||
<span>ID</span><code>{{ selectedRequest.id }}</code>
|
||||
<span>ID</span>
|
||||
<code
|
||||
[title]="selectedRequest.id"
|
||||
[appCopyOnClick]="selectedRequest.id"
|
||||
>{{ selectedRequest.id }}</code
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
<div class="detail-chips">
|
||||
|
||||
@@ -199,18 +199,20 @@ tbody tr.selected {
|
||||
.request-id {
|
||||
margin: var(--space-2) 0 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
font-size: 0.8rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.request-id code {
|
||||
display: inline-block;
|
||||
max-width: 260px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
overflow: visible;
|
||||
text-overflow: clip;
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
color: var(--color-text);
|
||||
background: var(--color-neutral-100);
|
||||
border: 1px solid var(--color-border);
|
||||
|
||||
@@ -7,11 +7,12 @@ import {
|
||||
AdminContactRequestDetail,
|
||||
AdminOperationsService,
|
||||
} from '../services/admin-operations.service';
|
||||
import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.directive';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-contact-requests',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule],
|
||||
imports: [CommonModule, FormsModule, CopyOnClickDirective],
|
||||
templateUrl: './admin-contact-requests.component.html',
|
||||
styleUrl: './admin-contact-requests.component.scss',
|
||||
})
|
||||
|
||||
@@ -97,7 +97,12 @@
|
||||
<div class="detail-header">
|
||||
<h2>Dettaglio ordine {{ selectedOrder.orderNumber }}</h2>
|
||||
<p class="order-uuid">
|
||||
UUID: <code>{{ selectedOrder.id }}</code>
|
||||
UUID:
|
||||
<code
|
||||
[title]="selectedOrder.id"
|
||||
[appCopyOnClick]="selectedOrder.id"
|
||||
>{{ selectedOrder.id }}</code
|
||||
>
|
||||
</p>
|
||||
<p *ngIf="detailLoading">Caricamento dettaglio...</p>
|
||||
</div>
|
||||
|
||||
@@ -5,11 +5,12 @@ import {
|
||||
AdminOrder,
|
||||
AdminOrdersService,
|
||||
} from '../services/admin-orders.service';
|
||||
import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.directive';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-dashboard',
|
||||
standalone: true,
|
||||
imports: [CommonModule, FormsModule],
|
||||
imports: [CommonModule, FormsModule, CopyOnClickDirective],
|
||||
templateUrl: './admin-dashboard.component.html',
|
||||
styleUrl: './admin-dashboard.component.scss',
|
||||
})
|
||||
|
||||
@@ -33,12 +33,23 @@
|
||||
<tbody>
|
||||
<ng-container *ngFor="let session of sessions">
|
||||
<tr>
|
||||
<td [title]="session.id">{{ session.id | slice: 0 : 8 }}</td>
|
||||
<td [title]="session.id" [appCopyOnClick]="session.id">
|
||||
{{ session.id | slice: 0 : 8 }}
|
||||
</td>
|
||||
<td>{{ session.createdAt | date: "short" }}</td>
|
||||
<td>{{ session.expiresAt | date: "short" }}</td>
|
||||
<td>{{ session.materialCode }}</td>
|
||||
<td>{{ session.status }}</td>
|
||||
<td>{{ session.convertedOrderId || "-" }}</td>
|
||||
<td
|
||||
[title]="session.convertedOrderId || ''"
|
||||
[appCopyOnClick]="session.convertedOrderId"
|
||||
>
|
||||
{{
|
||||
session.convertedOrderId
|
||||
? (session.convertedOrderId | slice: 0 : 8)
|
||||
: "-"
|
||||
}}
|
||||
</td>
|
||||
<td class="actions">
|
||||
<button
|
||||
type="button"
|
||||
@@ -78,6 +89,15 @@
|
||||
"
|
||||
class="detail-box"
|
||||
>
|
||||
<div class="detail-session-id">
|
||||
<strong>UUID sessione:</strong>
|
||||
<code
|
||||
[title]="detail.session.id"
|
||||
[appCopyOnClick]="detail.session.id"
|
||||
>{{ detail.session.id }}</code
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="detail-summary">
|
||||
<div>
|
||||
<strong>Elementi:</strong> {{ detail.items.length }}
|
||||
|
||||
@@ -103,6 +103,22 @@ td {
|
||||
padding: var(--space-4);
|
||||
}
|
||||
|
||||
.detail-session-id {
|
||||
margin-bottom: var(--space-3);
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.detail-session-id code {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
padding: var(--space-2);
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-neutral-100);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.detail-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -5,11 +5,12 @@ import {
|
||||
AdminQuoteSession,
|
||||
AdminQuoteSessionDetail,
|
||||
} from '../services/admin-operations.service';
|
||||
import { CopyOnClickDirective } from '../../../shared/directives/copy-on-click.directive';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-sessions',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
imports: [CommonModule, CopyOnClickDirective],
|
||||
templateUrl: './admin-sessions.component.html',
|
||||
styleUrl: './admin-sessions.component.scss',
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
>Richieste contatto</a
|
||||
>
|
||||
<a routerLink="sessions" routerLinkActive="active">Sessioni</a>
|
||||
<a routerLink="cad-invoices" routerLinkActive="active">Fatture CAD</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -115,6 +115,10 @@ export interface AdminQuoteSession {
|
||||
createdAt: string;
|
||||
expiresAt: string;
|
||||
convertedOrderId?: string;
|
||||
sourceRequestId?: string;
|
||||
cadHours?: number;
|
||||
cadHourlyRateChf?: number;
|
||||
cadTotalChf?: number;
|
||||
}
|
||||
|
||||
export interface AdminQuoteSessionDetailItem {
|
||||
@@ -136,14 +140,45 @@ export interface AdminQuoteSessionDetail {
|
||||
setupCostChf?: number;
|
||||
supportsEnabled?: boolean;
|
||||
notes?: string;
|
||||
sourceRequestId?: string;
|
||||
cadHours?: number;
|
||||
cadHourlyRateChf?: number;
|
||||
};
|
||||
items: AdminQuoteSessionDetailItem[];
|
||||
printItemsTotalChf: number;
|
||||
cadTotalChf: number;
|
||||
itemsTotalChf: number;
|
||||
shippingCostChf: number;
|
||||
globalMachineCostChf: number;
|
||||
grandTotalChf: number;
|
||||
}
|
||||
|
||||
export interface AdminCreateCadInvoicePayload {
|
||||
sessionId?: string;
|
||||
sourceRequestId?: string;
|
||||
cadHours: number;
|
||||
cadHourlyRateChf?: number;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface AdminCadInvoice {
|
||||
sessionId: string;
|
||||
sessionStatus: string;
|
||||
sourceRequestId?: string;
|
||||
cadHours: number;
|
||||
cadHourlyRateChf: number;
|
||||
cadTotalChf: number;
|
||||
printItemsTotalChf: number;
|
||||
setupCostChf: number;
|
||||
shippingCostChf: number;
|
||||
grandTotalChf: number;
|
||||
convertedOrderId?: string;
|
||||
convertedOrderStatus?: string;
|
||||
checkoutPath: string;
|
||||
notes?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
@@ -279,4 +314,20 @@ export class AdminOperationsService {
|
||||
{ withCredentials: true },
|
||||
);
|
||||
}
|
||||
|
||||
listCadInvoices(): Observable<AdminCadInvoice[]> {
|
||||
return this.http.get<AdminCadInvoice[]>(`${this.baseUrl}/cad-invoices`, {
|
||||
withCredentials: true,
|
||||
});
|
||||
}
|
||||
|
||||
createCadInvoice(
|
||||
payload: AdminCreateCadInvoicePayload,
|
||||
): Observable<AdminCadInvoice> {
|
||||
return this.http.post<AdminCadInvoice>(
|
||||
`${this.baseUrl}/cad-invoices`,
|
||||
payload,
|
||||
{ withCredentials: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ export interface AdminOrder {
|
||||
customerEmail: string;
|
||||
totalChf: number;
|
||||
createdAt: string;
|
||||
isCadOrder?: boolean;
|
||||
sourceRequestId?: string;
|
||||
cadHours?: number;
|
||||
cadHourlyRateChf?: number;
|
||||
cadTotalChf?: number;
|
||||
printMaterialCode?: string;
|
||||
printNozzleDiameterMm?: number;
|
||||
printLayerHeightMm?: number;
|
||||
|
||||
@@ -23,14 +23,16 @@
|
||||
<div
|
||||
class="mode-option"
|
||||
[class.active]="mode() === 'easy'"
|
||||
(click)="mode.set('easy')"
|
||||
[class.disabled]="cadSessionLocked()"
|
||||
(click)="!cadSessionLocked() && mode.set('easy')"
|
||||
>
|
||||
{{ "CALC.MODE_EASY" | translate }}
|
||||
</div>
|
||||
<div
|
||||
class="mode-option"
|
||||
[class.active]="mode() === 'advanced'"
|
||||
(click)="mode.set('advanced')"
|
||||
[class.disabled]="cadSessionLocked()"
|
||||
(click)="!cadSessionLocked() && mode.set('advanced')"
|
||||
>
|
||||
{{ "CALC.MODE_ADVANCED" | translate }}
|
||||
</div>
|
||||
@@ -39,6 +41,7 @@
|
||||
<app-upload-form
|
||||
#uploadForm
|
||||
[mode]="mode()"
|
||||
[lockedSettings]="cadSessionLocked()"
|
||||
[loading]="loading()"
|
||||
[uploadProgress]="uploadProgress()"
|
||||
(submitRequest)="onCalculate($event)"
|
||||
@@ -65,6 +68,16 @@
|
||||
(proceed)="onProceed()"
|
||||
(itemChange)="onItemChange($event)"
|
||||
></app-quote-result>
|
||||
} @else if (isZeroQuoteError()) {
|
||||
<app-card class="zero-result-card">
|
||||
<h3>{{ "CALC.ZERO_RESULT_TITLE" | translate }}</h3>
|
||||
<p>{{ "CALC.ZERO_RESULT_HELP" | translate }}</p>
|
||||
<div class="zero-result-action">
|
||||
<app-button variant="outline" (click)="onConsult()">
|
||||
{{ "QUOTE.CONSULT" | translate }}
|
||||
</app-button>
|
||||
</div>
|
||||
</app-card>
|
||||
} @else {
|
||||
<app-card>
|
||||
<h3>{{ "CALC.BENEFITS_TITLE" | translate }}</h3>
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.error-action {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: calc(var(--space-4) * -1);
|
||||
}
|
||||
|
||||
.content-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
@@ -74,6 +80,11 @@
|
||||
font-weight: 600;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.benefits {
|
||||
@@ -82,6 +93,15 @@
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
.zero-result-card p {
|
||||
color: var(--color-text-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.zero-result-action {
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
|
||||
.loader-content {
|
||||
text-align: center;
|
||||
max-width: 300px;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
Component,
|
||||
computed,
|
||||
signal,
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
@@ -7,11 +8,12 @@ import {
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { forkJoin } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { forkJoin, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
import { AppCardComponent } from '../../shared/components/app-card/app-card.component';
|
||||
import { AppAlertComponent } from '../../shared/components/app-alert/app-alert.component';
|
||||
import { AppButtonComponent } from '../../shared/components/app-button/app-button.component';
|
||||
import { UploadFormComponent } from './components/upload-form/upload-form.component';
|
||||
import { QuoteResultComponent } from './components/quote-result/quote-result.component';
|
||||
import {
|
||||
@@ -31,6 +33,7 @@ import { LanguageService } from '../../core/services/language.service';
|
||||
TranslateModule,
|
||||
AppCardComponent,
|
||||
AppAlertComponent,
|
||||
AppButtonComponent,
|
||||
UploadFormComponent,
|
||||
QuoteResultComponent,
|
||||
SuccessStateComponent,
|
||||
@@ -45,8 +48,12 @@ export class CalculatorPageComponent implements OnInit {
|
||||
loading = signal(false);
|
||||
uploadProgress = signal(0);
|
||||
result = signal<QuoteResult | null>(null);
|
||||
cadSessionLocked = signal(false);
|
||||
error = signal<boolean>(false);
|
||||
errorKey = signal<string>('CALC.ERROR_GENERIC');
|
||||
isZeroQuoteError = computed(
|
||||
() => this.error() && this.errorKey() === 'CALC.ERROR_ZERO_PRICE',
|
||||
);
|
||||
|
||||
orderSuccess = signal(false);
|
||||
|
||||
@@ -94,6 +101,8 @@ export class CalculatorPageComponent implements OnInit {
|
||||
this.error.set(false);
|
||||
this.errorKey.set('CALC.ERROR_GENERIC');
|
||||
this.result.set(result);
|
||||
const isCadSession = data?.session?.status === 'CAD_ACTIVE';
|
||||
this.cadSessionLocked.set(isCadSession);
|
||||
this.step.set('quote');
|
||||
|
||||
// 2. Determine Mode (Heuristic)
|
||||
@@ -122,15 +131,18 @@ export class CalculatorPageComponent implements OnInit {
|
||||
|
||||
// Download all files
|
||||
const downloads = items.map((item) =>
|
||||
this.estimator.getLineItemContent(session.id, item.id).pipe(
|
||||
map((blob: Blob) => {
|
||||
forkJoin({
|
||||
originalBlob: this.estimator.getLineItemContent(session.id, item.id),
|
||||
previewBlob: this.estimator
|
||||
.getLineItemContent(session.id, item.id, true)
|
||||
.pipe(catchError(() => of(null))),
|
||||
}).pipe(
|
||||
map(({ originalBlob, previewBlob }) => {
|
||||
return {
|
||||
blob,
|
||||
originalBlob,
|
||||
previewBlob,
|
||||
fileName: item.originalFilename,
|
||||
// We need to match the file object to the item so we can set colors ideally.
|
||||
// UploadForm.setFiles takes File[].
|
||||
// We might need to handle matching but UploadForm just pushes them.
|
||||
// If order is preserved, we are good. items from backend are list.
|
||||
hasConvertedPreview: !!item.convertedStoredPath,
|
||||
};
|
||||
}),
|
||||
),
|
||||
@@ -140,13 +152,25 @@ export class CalculatorPageComponent implements OnInit {
|
||||
next: (results: any[]) => {
|
||||
const files = results.map(
|
||||
(res) =>
|
||||
new File([res.blob], res.fileName, {
|
||||
new File([res.originalBlob], res.fileName, {
|
||||
type: 'application/octet-stream',
|
||||
}),
|
||||
);
|
||||
|
||||
if (this.uploadForm) {
|
||||
this.uploadForm.setFiles(files);
|
||||
results.forEach((res, index) => {
|
||||
if (!res.hasConvertedPreview || !res.previewBlob) {
|
||||
return;
|
||||
}
|
||||
const previewName = res.fileName
|
||||
.replace(/\.[^.]+$/, '')
|
||||
.concat('.stl');
|
||||
const previewFile = new File([res.previewBlob], previewName, {
|
||||
type: 'model/stl',
|
||||
});
|
||||
this.uploadForm.setPreviewFileByIndex(index, previewFile);
|
||||
});
|
||||
this.uploadForm.patchSettings(session);
|
||||
|
||||
// Also restore colors?
|
||||
@@ -185,6 +209,7 @@ export class CalculatorPageComponent implements OnInit {
|
||||
this.error.set(false);
|
||||
this.errorKey.set('CALC.ERROR_GENERIC');
|
||||
this.result.set(null);
|
||||
this.cadSessionLocked.set(false);
|
||||
this.orderSuccess.set(false);
|
||||
|
||||
// Auto-scroll on mobile to make analysis visible
|
||||
@@ -225,6 +250,17 @@ export class CalculatorPageComponent implements OnInit {
|
||||
queryParamsHandling: 'merge', // merge with existing params like 'mode' if any
|
||||
replaceUrl: true, // prevent cluttering history, or false if we want back button to work. replaceUrl seems safer for "state update"
|
||||
});
|
||||
this.estimator.getQuoteSession(res.sessionId).subscribe({
|
||||
next: (sessionData) => {
|
||||
this.restoreFilesAndSettings(
|
||||
sessionData.session,
|
||||
sessionData.items || [],
|
||||
);
|
||||
},
|
||||
error: (err) => {
|
||||
console.warn('Failed to refresh files for preview', err);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -238,10 +274,12 @@ export class CalculatorPageComponent implements OnInit {
|
||||
onProceed() {
|
||||
const res = this.result();
|
||||
if (res && res.sessionId) {
|
||||
this.router.navigate(
|
||||
['/', this.languageService.selectedLang(), 'checkout'],
|
||||
{ queryParams: { session: res.sessionId } },
|
||||
);
|
||||
const segments = this.cadSessionLocked()
|
||||
? ['/', this.languageService.selectedLang(), 'checkout', 'cad']
|
||||
: ['/', this.languageService.selectedLang(), 'checkout'];
|
||||
this.router.navigate(segments, {
|
||||
queryParams: { session: res.sessionId },
|
||||
});
|
||||
} else {
|
||||
console.error('No session ID found in quote result');
|
||||
// Fallback or error handling
|
||||
@@ -311,6 +349,7 @@ export class CalculatorPageComponent implements OnInit {
|
||||
onNewQuote() {
|
||||
this.step.set('upload');
|
||||
this.result.set(null);
|
||||
this.cadSessionLocked.set(false);
|
||||
this.orderSuccess.set(false);
|
||||
this.mode.set('easy'); // Reset to default
|
||||
}
|
||||
@@ -318,7 +357,14 @@ export class CalculatorPageComponent implements OnInit {
|
||||
private currentRequest: QuoteRequest | null = null;
|
||||
|
||||
onConsult() {
|
||||
if (!this.currentRequest) return;
|
||||
if (!this.currentRequest) {
|
||||
this.router.navigate([
|
||||
'/',
|
||||
this.languageService.selectedLang(),
|
||||
'contact',
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
const req = this.currentRequest;
|
||||
let details = `Richiesta Preventivo:\n`;
|
||||
@@ -349,7 +395,16 @@ export class CalculatorPageComponent implements OnInit {
|
||||
}
|
||||
|
||||
private isInvalidQuote(result: QuoteResult): boolean {
|
||||
return !Number.isFinite(result.totalPrice) || result.totalPrice <= 0;
|
||||
const invalidPrice =
|
||||
!Number.isFinite(result.totalPrice) || result.totalPrice <= 0;
|
||||
const invalidWeight =
|
||||
!Number.isFinite(result.totalWeight) || result.totalWeight <= 0;
|
||||
const invalidTime =
|
||||
!Number.isFinite(result.totalTimeHours) ||
|
||||
!Number.isFinite(result.totalTimeMinutes) ||
|
||||
(result.totalTimeHours <= 0 && result.totalTimeMinutes <= 0);
|
||||
|
||||
return invalidPrice || invalidWeight || invalidTime;
|
||||
}
|
||||
|
||||
private setQuoteError(key: string): void {
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
: { cost: (result().setupCost | currency: result().currency) }
|
||||
}}</small
|
||||
><br />
|
||||
@if ((result().cadTotal || 0) > 0) {
|
||||
<small class="shipping-note" style="color: #666">
|
||||
Servizio CAD: {{ result().cadTotal | currency: result().currency }}
|
||||
</small>
|
||||
<br />
|
||||
}
|
||||
<small class="shipping-note" style="color: #666">{{
|
||||
"CALC.SHIPPING_NOTE" | translate
|
||||
}}</small>
|
||||
|
||||
@@ -120,8 +120,9 @@ export class QuoteResultComponent implements OnDestroy {
|
||||
totals = computed(() => {
|
||||
const currentItems = this.items();
|
||||
const setup = this.result().setupCost;
|
||||
const cad = this.result().cadTotal || 0;
|
||||
|
||||
let price = setup;
|
||||
let price = setup + cad;
|
||||
let time = 0;
|
||||
let weight = 0;
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
<div class="section">
|
||||
@if (selectedFile()) {
|
||||
<div class="viewer-wrapper">
|
||||
@if (!isStepFile(selectedFile())) {
|
||||
@if (!canPreviewSelectedFile()) {
|
||||
<div class="step-warning">
|
||||
<p>{{ "CALC.STEP_WARNING" | translate }}</p>
|
||||
</div>
|
||||
} @else {
|
||||
<app-stl-viewer
|
||||
[file]="selectedFile()"
|
||||
[file]="getSelectedPreviewFile()"
|
||||
[color]="getSelectedFileColor()"
|
||||
>
|
||||
</app-stl-viewer>
|
||||
@@ -118,6 +118,12 @@
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
@if (lockedSettings()) {
|
||||
<p class="upload-privacy-note">
|
||||
Parametri stampa bloccati per sessione CAD: materiale, nozzle, layer,
|
||||
infill e supporti sono definiti dal back-office.
|
||||
</p>
|
||||
}
|
||||
<app-select
|
||||
formControlName="material"
|
||||
[label]="'CALC.MATERIAL' | translate"
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
signal,
|
||||
OnInit,
|
||||
inject,
|
||||
effect,
|
||||
} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {
|
||||
@@ -32,6 +33,7 @@ import { getColorHex } from '../../../../core/constants/colors.const';
|
||||
|
||||
interface FormItem {
|
||||
file: File;
|
||||
previewFile?: File;
|
||||
quantity: number;
|
||||
color: string;
|
||||
filamentVariantId?: number;
|
||||
@@ -56,6 +58,7 @@ interface FormItem {
|
||||
})
|
||||
export class UploadFormComponent implements OnInit {
|
||||
mode = input<'easy' | 'advanced'>('easy');
|
||||
lockedSettings = input<boolean>(false);
|
||||
loading = input<boolean>(false);
|
||||
uploadProgress = input<number>(0);
|
||||
submitRequest = output<QuoteRequest>();
|
||||
@@ -96,12 +99,24 @@ export class UploadFormComponent implements OnInit {
|
||||
|
||||
acceptedFormats = '.stl,.3mf,.step,.stp';
|
||||
|
||||
isStepFile(file: File | null): boolean {
|
||||
isStlFile(file: File | null): boolean {
|
||||
if (!file) return false;
|
||||
const name = file.name.toLowerCase();
|
||||
return name.endsWith('.stl');
|
||||
}
|
||||
|
||||
canPreviewSelectedFile(): boolean {
|
||||
return this.isStlFile(this.getSelectedPreviewFile());
|
||||
}
|
||||
|
||||
getSelectedPreviewFile(): File | null {
|
||||
const selected = this.selectedFile();
|
||||
if (!selected) return null;
|
||||
const item = this.items().find((i) => i.file === selected);
|
||||
if (!item) return null;
|
||||
return item.previewFile ?? item.file;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.form = this.fb.group({
|
||||
itemsTouched: [false], // Hack to track touched state for custom items list
|
||||
@@ -126,6 +141,10 @@ export class UploadFormComponent implements OnInit {
|
||||
if (this.mode() !== 'easy' || this.isPatchingSettings) return;
|
||||
this.applyAdvancedPresetFromQuality(quality);
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
this.applySettingsLock(this.lockedSettings());
|
||||
});
|
||||
}
|
||||
|
||||
private applyAdvancedPresetFromQuality(quality: string | null | undefined) {
|
||||
@@ -262,6 +281,7 @@ export class UploadFormComponent implements OnInit {
|
||||
const defaultSelection = this.getDefaultVariantSelection();
|
||||
validItems.push({
|
||||
file,
|
||||
previewFile: this.isStlFile(file) ? file : undefined,
|
||||
quantity: 1,
|
||||
color: defaultSelection.colorName,
|
||||
filamentVariantId: defaultSelection.filamentVariantId,
|
||||
@@ -390,6 +410,7 @@ export class UploadFormComponent implements OnInit {
|
||||
for (const file of files) {
|
||||
validItems.push({
|
||||
file,
|
||||
previewFile: this.isStlFile(file) ? file : undefined,
|
||||
quantity: 1,
|
||||
color: defaultSelection.colorName,
|
||||
filamentVariantId: defaultSelection.filamentVariantId,
|
||||
@@ -404,6 +425,16 @@ export class UploadFormComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
setPreviewFileByIndex(index: number, previewFile: File) {
|
||||
if (!Number.isInteger(index) || index < 0) return;
|
||||
this.items.update((current) => {
|
||||
if (index >= current.length) return current;
|
||||
const updated = [...current];
|
||||
updated[index] = { ...updated[index], previewFile };
|
||||
return updated;
|
||||
});
|
||||
}
|
||||
|
||||
private getDefaultVariantSelection(): {
|
||||
colorName: string;
|
||||
filamentVariantId?: number;
|
||||
@@ -495,7 +526,7 @@ export class UploadFormComponent implements OnInit {
|
||||
this.form.value,
|
||||
);
|
||||
this.submitRequest.emit({
|
||||
...this.form.value,
|
||||
...this.form.getRawValue(),
|
||||
items: this.items(), // Pass the items array explicitly AFTER form value to prevent overwrite
|
||||
mode: this.mode(),
|
||||
});
|
||||
@@ -529,4 +560,26 @@ export class UploadFormComponent implements OnInit {
|
||||
private normalizeFileName(fileName: string): string {
|
||||
return (fileName || '').split(/[\\/]/).pop()?.trim().toLowerCase() ?? '';
|
||||
}
|
||||
|
||||
private applySettingsLock(locked: boolean): void {
|
||||
const controlsToLock = [
|
||||
'material',
|
||||
'quality',
|
||||
'nozzleDiameter',
|
||||
'infillPattern',
|
||||
'layerHeight',
|
||||
'infillDensity',
|
||||
'supportEnabled',
|
||||
];
|
||||
|
||||
controlsToLock.forEach((name) => {
|
||||
const control = this.form.get(name);
|
||||
if (!control) return;
|
||||
if (locked) {
|
||||
control.disable({ emitEvent: false });
|
||||
} else {
|
||||
control.enable({ emitEvent: false });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ export interface QuoteResult {
|
||||
items: QuoteItem[];
|
||||
setupCost: number;
|
||||
globalMachineCost: number;
|
||||
cadHours?: number;
|
||||
cadTotal?: number;
|
||||
currency: string;
|
||||
totalPrice: number;
|
||||
totalTimeHours: number;
|
||||
@@ -416,10 +418,15 @@ export class QuoteEstimatorService {
|
||||
}
|
||||
|
||||
// Session File Retrieval
|
||||
getLineItemContent(sessionId: string, lineItemId: string): Observable<Blob> {
|
||||
getLineItemContent(
|
||||
sessionId: string,
|
||||
lineItemId: string,
|
||||
preview = false,
|
||||
): Observable<Blob> {
|
||||
const headers: any = {};
|
||||
const previewQuery = preview ? '?preview=true' : '';
|
||||
return this.http.get(
|
||||
`${environment.apiUrl}/api/quote-sessions/${sessionId}/line-items/${lineItemId}/content`,
|
||||
`${environment.apiUrl}/api/quote-sessions/${sessionId}/line-items/${lineItemId}/content${previewQuery}`,
|
||||
{
|
||||
headers,
|
||||
responseType: 'blob',
|
||||
@@ -458,6 +465,8 @@ export class QuoteEstimatorService {
|
||||
})),
|
||||
setupCost: session.setupCostChf || 0,
|
||||
globalMachineCost: sessionData.globalMachineCostChf || 0,
|
||||
cadHours: session.cadHours || 0,
|
||||
cadTotal: sessionData.cadTotalChf || 0,
|
||||
currency: 'CHF', // Fixed for now
|
||||
totalPrice:
|
||||
(sessionData.itemsTotalChf || 0) +
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<div class="checkout-page">
|
||||
<div class="container hero">
|
||||
<h1 class="section-title">{{ "CHECKOUT.TITLE" | translate }}</h1>
|
||||
<p class="cad-subtitle" *ngIf="isCadSession()">
|
||||
Servizio CAD
|
||||
<ng-container *ngIf="cadRequestId()">
|
||||
riferito alla richiesta contatto #{{ cadRequestId() }}
|
||||
</ng-container>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
@@ -260,6 +266,17 @@
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="summary-item cad-summary-item" *ngIf="cadTotal() > 0">
|
||||
<div class="item-details">
|
||||
<span class="item-name">Servizio CAD</span>
|
||||
<div class="item-specs-sub">{{ cadHours() }}h</div>
|
||||
</div>
|
||||
<div class="item-price">
|
||||
<span class="item-total-price">
|
||||
{{ cadTotal() | currency: "CHF" }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="summary-totals" *ngIf="quoteSession() as session">
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
.cad-subtitle {
|
||||
margin: 0;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.checkout-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 420px;
|
||||
@@ -260,6 +265,13 @@ app-toggle-selector.user-type-selector-compact {
|
||||
}
|
||||
}
|
||||
|
||||
.cad-summary-item {
|
||||
background: var(--color-neutral-100);
|
||||
border-radius: var(--radius-sm);
|
||||
padding-left: var(--space-3);
|
||||
padding-right: var(--space-3);
|
||||
}
|
||||
|
||||
.summary-totals {
|
||||
background: var(--color-neutral-100);
|
||||
padding: var(--space-4);
|
||||
|
||||
@@ -162,6 +162,22 @@ export class CheckoutComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
isCadSession(): boolean {
|
||||
return this.quoteSession()?.session?.status === 'CAD_ACTIVE';
|
||||
}
|
||||
|
||||
cadRequestId(): string | null {
|
||||
return this.quoteSession()?.session?.sourceRequestId ?? null;
|
||||
}
|
||||
|
||||
cadHours(): number {
|
||||
return this.quoteSession()?.session?.cadHours ?? 0;
|
||||
}
|
||||
|
||||
cadTotal(): number {
|
||||
return this.quoteSession()?.cadTotalChf ?? 0;
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
if (this.checkoutForm.invalid) {
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,7 @@ import { AppInputComponent } from '../../../../shared/components/app-input/app-i
|
||||
import { AppButtonComponent } from '../../../../shared/components/app-button/app-button.component';
|
||||
import { QuoteEstimatorService } from '../../../calculator/services/quote-estimator.service';
|
||||
import { QuoteRequestService } from '../../../../core/services/quote-request.service';
|
||||
import { LanguageService } from '../../../../core/services/language.service';
|
||||
|
||||
interface FilePreview {
|
||||
file: File;
|
||||
@@ -53,6 +54,7 @@ export class ContactFormComponent implements OnDestroy {
|
||||
];
|
||||
|
||||
private quoteRequestService = inject(QuoteRequestService);
|
||||
private languageService = inject(LanguageService);
|
||||
|
||||
constructor(
|
||||
private fb: FormBuilder,
|
||||
@@ -257,6 +259,7 @@ export class ContactFormComponent implements OnDestroy {
|
||||
const requestDto: any = {
|
||||
requestType: formVal.requestType,
|
||||
customerType: isCompany ? 'BUSINESS' : 'PRIVATE',
|
||||
language: this.languageService.selectedLang(),
|
||||
email: formVal.email,
|
||||
phone: formVal.phone,
|
||||
message: formVal.message,
|
||||
|
||||
@@ -205,10 +205,10 @@
|
||||
gap: var(--space-3);
|
||||
}
|
||||
|
||||
.capabilities {
|
||||
.section.capabilities {
|
||||
position: relative;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
padding-top: 3rem;
|
||||
padding-top: 4.5rem;
|
||||
}
|
||||
.capabilities-bg {
|
||||
display: none;
|
||||
|
||||
@@ -198,6 +198,10 @@
|
||||
<span>{{ "PAYMENT.SUBTOTAL" | translate }}</span>
|
||||
<span>{{ o.subtotalChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
<div class="total-row" *ngIf="o.cadTotalChf > 0">
|
||||
<span>Servizio CAD ({{ o.cadHours || 0 }}h)</span>
|
||||
<span>{{ o.cadTotalChf | currency: "CHF" }}</span>
|
||||
</div>
|
||||
<div class="total-row">
|
||||
<span>{{ "PAYMENT.SHIPPING" | translate }}</span>
|
||||
<span>{{ o.shippingCostChf | currency: "CHF" }}</span>
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { Directive, HostBinding, HostListener, Input } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[appCopyOnClick]',
|
||||
standalone: true,
|
||||
})
|
||||
export class CopyOnClickDirective {
|
||||
@Input('appCopyOnClick') value: string | null | undefined;
|
||||
|
||||
@HostBinding('style.cursor') readonly cursor = 'pointer';
|
||||
|
||||
@HostListener('click', ['$event'])
|
||||
onClick(event: MouseEvent): void {
|
||||
const text = (this.value ?? '').trim();
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
void this.copy(text);
|
||||
}
|
||||
|
||||
private async copy(text: string): Promise<void> {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return;
|
||||
} catch {
|
||||
// Fallback below for browsers/environments that block clipboard API.
|
||||
}
|
||||
}
|
||||
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.opacity = '0';
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,9 @@
|
||||
"NOTES_PLACEHOLDER": "Spezifische Anweisungen...",
|
||||
"SETUP_NOTE": "* Beinhaltet {{cost}} als Einrichtungskosten",
|
||||
"SHIPPING_NOTE": "** Versandkosten ausgeschlossen, werden im nächsten Schritt berechnet",
|
||||
"ERROR_ZERO_PRICE": "Etwas ist schiefgelaufen. Versuche ein anderes Format oder kontaktiere uns."
|
||||
"ERROR_ZERO_PRICE": "Bei der Berechnung ist etwas schiefgelaufen. Versuche ein anderes Format oder kontaktiere uns direkt über \"Beratung anfragen\".",
|
||||
"ZERO_RESULT_TITLE": "Ungültiges Ergebnis",
|
||||
"ZERO_RESULT_HELP": "Die Berechnung hat ungültige Werte (0) geliefert. Versuche ein anderes Dateiformat oder kontaktiere uns direkt über \"Beratung anfragen\"."
|
||||
},
|
||||
"SHOP": {
|
||||
"TITLE": "Technische Lösungen",
|
||||
@@ -147,6 +149,7 @@
|
||||
"PASSION_WOODWORKING": "Holzbearbeitung",
|
||||
"PASSION_VAN_LIFE": "Van Life",
|
||||
"PASSION_COFFEE": "Kaffee",
|
||||
"PASSION_COOKING": "Kochen",
|
||||
"PASSION_SOFTWARE_DEVELOPMENT": "Softwareentwicklung",
|
||||
"SERVICES_TITLE": "Hauptleistungen",
|
||||
"TARGET_TITLE": "Für wen",
|
||||
@@ -176,9 +179,9 @@
|
||||
"CONSENT": {
|
||||
"UPLOAD_NOTICE_PREFIX": "Durch das Hochladen einer Datei akzeptieren Sie unsere",
|
||||
"UPLOAD_NOTICE_LINK": "Datenschutzerklärung",
|
||||
"LABEL_PREFIX": "Ich habe gelesen und akzeptiere die",
|
||||
"LABEL_PREFIX": "Ich habe die",
|
||||
"TERMS_LINK": "Allgemeinen Geschäftsbedingungen",
|
||||
"AND": "und die",
|
||||
"AND": "gelesen und akzeptiere die",
|
||||
"PRIVACY_LINK": "Datenschutzerklärung",
|
||||
"REQUIRED_ERROR": "Um fortzufahren müssen Sie AGB und Datenschutz akzeptieren."
|
||||
},
|
||||
@@ -469,8 +472,8 @@
|
||||
"FOUNDER_IMAGE_ALT_1": "Gründer - Foto 1",
|
||||
"FOUNDER_IMAGE_ALT_2": "Gründer - Foto 2",
|
||||
"HERO_EYEBROW": "Technischer 3D-Druck für Unternehmen, Freelancer und Maker",
|
||||
"HERO_TITLE": "Preis und Lieferzeit in wenigen Sekunden.<br>Von der 3D-Datei zum fertigen Teil.",
|
||||
"HERO_LEAD": "Der fortschrittlichste Rechner für Ihre 3D-Drucke: maximale Präzision und keine Überraschungen.",
|
||||
"HERO_TITLE": "3D-Druckservice.<br>Von der Datei zum fertigen Teil.",
|
||||
"HERO_LEAD": "Mit dem fortschrittlichsten Rechner für Ihre 3D-Drucke: absolute Präzision und keine Überraschungen.",
|
||||
"HERO_SUBTITLE": "Wir bieten auch CAD-Services für individuelle Teile an!",
|
||||
"BTN_CALCULATE": "Angebot berechnen",
|
||||
"BTN_SHOP": "Zum Shop",
|
||||
@@ -509,7 +512,7 @@
|
||||
"CARD_SHOP_3_TITLE": "Auf Anfrage",
|
||||
"CARD_SHOP_3_TEXT": "Sie finden nicht, was Sie brauchen? Wir entwickeln und produzieren es für Sie.",
|
||||
"SEC_ABOUT_TITLE": "Über uns",
|
||||
"SEC_ABOUT_TEXT": "Wir sind zwei Ingenieurstudenten: 3D-Druck hat uns aus einem einfachen Grund begeistert – ein Problem sehen und die Lösung bauen. Aus dieser Idee entstehen Prototypen und Objekte, die im Alltag funktionieren.",
|
||||
"SEC_ABOUT_TEXT": "Wir sind zwei Ingenieurstudenten: 3D-Druck hat uns aus einem einfachen Grund begeistert ein Problem sehen und die Lösung finden. Aus dieser Idee entstehen Prototypen und Objekte, die im Alltag funktionieren.",
|
||||
"FOUNDERS_PHOTO": "Foto der Gründer"
|
||||
},
|
||||
"ORDER": {
|
||||
|
||||
@@ -91,7 +91,9 @@
|
||||
"NOTES_PLACEHOLDER": "Specific instructions...",
|
||||
"SETUP_NOTE": "* Includes {{cost}} as setup cost",
|
||||
"SHIPPING_NOTE": "** Shipping costs excluded, calculated at the next step",
|
||||
"ERROR_ZERO_PRICE": "Something went wrong. Try another format or contact us."
|
||||
"ERROR_ZERO_PRICE": "Something went wrong during the calculation. Try another format or contact us directly via Request Consultation.",
|
||||
"ZERO_RESULT_TITLE": "Invalid Result",
|
||||
"ZERO_RESULT_HELP": "The calculation returned invalid zero values. Try another file format or contact us directly via Request Consultation."
|
||||
},
|
||||
"SHOP": {
|
||||
"TITLE": "Technical solutions",
|
||||
@@ -147,6 +149,7 @@
|
||||
"PASSION_WOODWORKING": "Woodworking",
|
||||
"PASSION_VAN_LIFE": "Van life",
|
||||
"PASSION_COFFEE": "Coffee",
|
||||
"PASSION_COOKING": "Cooking",
|
||||
"PASSION_SOFTWARE_DEVELOPMENT": "Software development",
|
||||
"SERVICES_TITLE": "Main Services",
|
||||
"TARGET_TITLE": "Who is it for",
|
||||
@@ -469,8 +472,8 @@
|
||||
"FOUNDER_IMAGE_ALT_1": "Founder - photo 1",
|
||||
"FOUNDER_IMAGE_ALT_2": "Founder - photo 2",
|
||||
"HERO_EYEBROW": "Technical 3D printing for businesses, freelancers and makers",
|
||||
"HERO_TITLE": "Price and lead time in a few seconds.<br>From 3D file to finished part.",
|
||||
"HERO_LEAD": "The most advanced calculator for your 3D prints: total precision and zero surprises.",
|
||||
"HERO_TITLE": "3D printing service.<br>From file to finished part.",
|
||||
"HERO_LEAD": "With the most advanced calculator for your 3D prints: absolute precision and zero surprises.",
|
||||
"HERO_SUBTITLE": "We also offer CAD services for custom parts!",
|
||||
"BTN_CALCULATE": "Calculate Quote",
|
||||
"BTN_SHOP": "Go to shop",
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
},
|
||||
"HOME": {
|
||||
"HERO_EYEBROW": "Impression 3D technique pour entreprises, freelances et makers",
|
||||
"HERO_TITLE": "Prix et délais en quelques secondes.<br>Du fichier 3D à la pièce finie.",
|
||||
"HERO_LEAD": "Le calculateur le plus avancé pour vos impressions 3D : précision totale et zéro surprise.",
|
||||
"HERO_TITLE": "Service d'impression 3D.<br>Du fichier à la pièce finie.",
|
||||
"HERO_LEAD": "Avec le calculateur le plus avancé pour vos impressions 3D : précision absolue et zéro surprise.",
|
||||
"HERO_SUBTITLE": "Nous proposons aussi des services CAD pour des pièces personnalisées !",
|
||||
"BTN_CALCULATE": "Calculer un devis",
|
||||
"BTN_SHOP": "Aller à la boutique",
|
||||
@@ -116,7 +116,9 @@
|
||||
"FALLBACK_MATERIAL": "PLA (fallback)",
|
||||
"FALLBACK_QUALITY_STANDARD": "Standard",
|
||||
"ERR_FILE_TOO_LARGE": "Certains fichiers dépassent la limite de 200MB et n'ont pas été ajoutés.",
|
||||
"ERROR_ZERO_PRICE": "Quelque chose s'est mal passé. Essayez un autre format ou contactez-nous."
|
||||
"ERROR_ZERO_PRICE": "Un problème est survenu pendant le calcul. Essayez un autre format ou contactez-nous directement via Demander une consultation.",
|
||||
"ZERO_RESULT_TITLE": "Résultat invalide",
|
||||
"ZERO_RESULT_HELP": "Le calcul a renvoyé des valeurs nulles invalides. Essayez un autre format de fichier ou contactez-nous directement via Demander une consultation."
|
||||
},
|
||||
"QUOTE": {
|
||||
"PROCEED_ORDER": "Procéder à la commande",
|
||||
@@ -204,6 +206,7 @@
|
||||
"PASSION_WOODWORKING": "Travail du bois",
|
||||
"PASSION_VAN_LIFE": "Van life",
|
||||
"PASSION_COFFEE": "Café",
|
||||
"PASSION_COOKING": "Cuisine",
|
||||
"PASSION_SOFTWARE_DEVELOPMENT": "Développement logiciel",
|
||||
"SERVICES_TITLE": "Services principaux",
|
||||
"TARGET_TITLE": "Pour qui",
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
},
|
||||
"HOME": {
|
||||
"HERO_EYEBROW": "Stampa 3D tecnica per aziende, freelance e maker",
|
||||
"HERO_TITLE": "Prezzo e tempi in pochi secondi.<br>Dal file 3D al pezzo finito.",
|
||||
"HERO_LEAD": "Il calcolatore più avanzato per le tue stampe 3D: precisione assoluta e zero sorprese.",
|
||||
"HERO_TITLE": "Servizio di stampa 3D.<br>Dal file al pezzo finito.",
|
||||
"HERO_LEAD": "Con il calcolatore più avanzato per le tue stampe 3D: precisione assoluta e zero sorprese.",
|
||||
"HERO_SUBTITLE": "Offriamo anche servizi di CAD per pezzi personalizzati!",
|
||||
"BTN_CALCULATE": "Calcola Preventivo",
|
||||
"BTN_SHOP": "Vai allo shop",
|
||||
@@ -116,7 +116,9 @@
|
||||
"FALLBACK_MATERIAL": "PLA (fallback)",
|
||||
"FALLBACK_QUALITY_STANDARD": "Standard",
|
||||
"ERR_FILE_TOO_LARGE": "Alcuni file superano il limite di 200MB e non sono stati aggiunti.",
|
||||
"ERROR_ZERO_PRICE": "Qualcosa è andato storto. Prova con un altro formato oppure contattaci."
|
||||
"ERROR_ZERO_PRICE": "Qualcosa è andato storto nel calcolo. Prova un altro formato o contattaci direttamente con Richiedi Consulenza.",
|
||||
"ZERO_RESULT_TITLE": "Risultato non valido",
|
||||
"ZERO_RESULT_HELP": "Il calcolo ha restituito valori non validi (0). Prova con un altro formato file oppure contattaci direttamente con Richiedi Consulenza."
|
||||
},
|
||||
"QUOTE": {
|
||||
"PROCEED_ORDER": "Procedi con l'ordine",
|
||||
@@ -204,6 +206,7 @@
|
||||
"PASSION_WOODWORKING": "Lavorazione del legno",
|
||||
"PASSION_VAN_LIFE": "Van life",
|
||||
"PASSION_COFFEE": "Caffè",
|
||||
"PASSION_COOKING": "Cucina",
|
||||
"PASSION_SOFTWARE_DEVELOPMENT": "Sviluppo software",
|
||||
"SERVICES_TITLE": "Servizi principali",
|
||||
"TARGET_TITLE": "Per chi è",
|
||||
|
||||
Reference in New Issue
Block a user