diff --git a/backend/src/main/java/com/printcalculator/controller/QuoteSessionController.java b/backend/src/main/java/com/printcalculator/controller/QuoteSessionController.java index 50a6329..58ccb50 100644 --- a/backend/src/main/java/com/printcalculator/controller/QuoteSessionController.java +++ b/backend/src/main/java/com/printcalculator/controller/QuoteSessionController.java @@ -296,9 +296,7 @@ public class QuoteSessionController { return variant; } - String requestedMaterialCode = settings.getMaterial() != null - ? settings.getMaterial().trim().toUpperCase() - : "PLA"; + String requestedMaterialCode = normalizeRequestedMaterialCode(settings.getMaterial()); FilamentMaterialType materialType = materialRepo.findByMaterialCode(requestedMaterialCode) .orElseGet(() -> materialRepo.findByMaterialCode("PLA") @@ -316,6 +314,18 @@ public class QuoteSessionController { .orElseThrow(() -> new RuntimeException("No active variant for material: " + requestedMaterialCode)); } + private String normalizeRequestedMaterialCode(String value) { + if (value == null || value.isBlank()) { + return "PLA"; + } + + return value.trim() + .toUpperCase(Locale.ROOT) + .replace('_', ' ') + .replace('-', ' ') + .replaceAll("\\s+", " "); + } + // 3. Update Line Item @PatchMapping("/line-items/{lineItemId}") @Transactional diff --git a/backend/src/main/java/com/printcalculator/dto/PrintSettingsDto.java b/backend/src/main/java/com/printcalculator/dto/PrintSettingsDto.java index 5c56ced..e01cfc6 100644 --- a/backend/src/main/java/com/printcalculator/dto/PrintSettingsDto.java +++ b/backend/src/main/java/com/printcalculator/dto/PrintSettingsDto.java @@ -8,7 +8,7 @@ public class PrintSettingsDto { private String complexityMode; // Common - private String material; // e.g. "PLA", "PETG" + private String material; // e.g. "PLA", "PLA TOUGH", "PETG" private String color; // e.g. "White", "#FFFFFF" private Long filamentVariantId; private Long printerMachineId; diff --git a/backend/src/main/java/com/printcalculator/service/OrcaProfileResolver.java b/backend/src/main/java/com/printcalculator/service/OrcaProfileResolver.java index 26f0d88..b1f35dd 100644 --- a/backend/src/main/java/com/printcalculator/service/OrcaProfileResolver.java +++ b/backend/src/main/java/com/printcalculator/service/OrcaProfileResolver.java @@ -116,6 +116,7 @@ public class OrcaProfileResolver { : "PLA"; return switch (materialCode) { + case "PLA TOUGH" -> "Bambu PLA Tough @BBL A1"; case "PETG" -> "Generic PETG"; case "TPU" -> "Generic TPU"; case "PC" -> "Generic PC"; diff --git a/backend/src/main/java/com/printcalculator/service/ProfileManager.java b/backend/src/main/java/com/printcalculator/service/ProfileManager.java index 3737d43..67eee52 100644 --- a/backend/src/main/java/com/printcalculator/service/ProfileManager.java +++ b/backend/src/main/java/com/printcalculator/service/ProfileManager.java @@ -46,6 +46,7 @@ public class ProfileManager { // Material Aliases profileAliases.put("pla_basic", "Bambu PLA Basic @BBL A1"); + profileAliases.put("pla_tough", "Bambu PLA Tough @BBL A1"); profileAliases.put("petg_basic", "Bambu PETG Basic @BBL A1"); profileAliases.put("tpu_95a", "Bambu TPU 95A @BBL A1"); diff --git a/backend/src/main/java/com/printcalculator/service/QuoteCalculator.java b/backend/src/main/java/com/printcalculator/service/QuoteCalculator.java index 4dc4f82..5b8dbdf 100644 --- a/backend/src/main/java/com/printcalculator/service/QuoteCalculator.java +++ b/backend/src/main/java/com/printcalculator/service/QuoteCalculator.java @@ -175,6 +175,7 @@ public class QuoteCalculator { private String detectMaterialCode(String profileName) { String lower = profileName.toLowerCase(); + if (lower.contains("pla tough") || lower.contains("pla_tough")) return "PLA TOUGH"; if (lower.contains("petg")) return "PETG"; if (lower.contains("tpu")) return "TPU"; if (lower.contains("abs")) return "ABS"; diff --git a/db.sql b/db.sql index ee9422d..8b1fe79 100644 --- a/db.sql +++ b/db.sql @@ -285,6 +285,7 @@ insert into filament_material_type (material_code, is_technical, technical_type_label) values ('PLA', false, false, null), + ('PLA TOUGH', false, false, null), ('PETG', false, false, null), ('TPU', true, false, null), ('PC', false, true, 'engineering'), @@ -355,6 +356,37 @@ on conflict (filament_material_type_id, variant_display_name) do update is_active = excluded.is_active; -- Varianti base per materiali principali del calcolatore +with mat as (select filament_material_type_id + from filament_material_type + where material_code = 'PLA TOUGH') +insert +into filament_variant (filament_material_type_id, variant_display_name, color_name, color_hex, finish_type, brand, + is_matte, is_special, cost_chf_per_kg, stock_spools, spool_net_kg, is_active) +select mat.filament_material_type_id, + 'PLA Tough Nero', + 'Nero', + '#1A1A1A', + 'GLOSSY', + 'Bambu', + false, + false, + 18.00, + 1.000, + 1.000, + true +from mat +on conflict (filament_material_type_id, variant_display_name) do update + set color_name = excluded.color_name, + color_hex = excluded.color_hex, + finish_type = excluded.finish_type, + brand = excluded.brand, + is_matte = excluded.is_matte, + is_special = excluded.is_special, + cost_chf_per_kg = excluded.cost_chf_per_kg, + stock_spools = excluded.stock_spools, + spool_net_kg = excluded.spool_net_kg, + is_active = excluded.is_active; + with mat as (select filament_material_type_id from filament_material_type where material_code = 'PETG') @@ -491,13 +523,14 @@ with p as (select printer_machine_profile_id and pmp.nozzle_diameter_mm = 0.40::numeric), m as (select filament_material_type_id, material_code from filament_material_type - where material_code in ('PLA', 'PETG', 'TPU', 'PC')) + where material_code in ('PLA', 'PLA TOUGH', 'PETG', 'TPU', 'PC')) insert into material_orca_profile_map (printer_machine_profile_id, filament_material_type_id, orca_filament_profile_name, is_active) select p.printer_machine_profile_id, m.filament_material_type_id, case m.material_code when 'PLA' then 'Bambu PLA Basic @BBL A1' + when 'PLA TOUGH' then 'Bambu PLA Tough @BBL A1' when 'PETG' then 'Bambu PETG Basic @BBL A1' when 'TPU' then 'Bambu TPU 95A @BBL A1' when 'PC' then 'Generic PC @BBL A1' diff --git a/frontend/src/app/features/admin/pages/admin-filament-stock.component.html b/frontend/src/app/features/admin/pages/admin-filament-stock.component.html index 051e71d..d4dfd8d 100644 --- a/frontend/src/app/features/admin/pages/admin-filament-stock.component.html +++ b/frontend/src/app/features/admin/pages/admin-filament-stock.component.html @@ -316,7 +316,7 @@
Vuoi eliminare la variante {{ variantToDelete?.variantDisplayName }}?
+Vuoi eliminare la variante {{ variantToDelete.variantDisplayName }}?
L'operazione non รจ reversibile.