<?phpnamespace App\Services\Product;use Doctrine\Persistence\ManagerRegistry;use App\Entity\Platform\Devis\Devis;use App\Services\LogTools;use App\Entity\Product\Config as ProductConfig;// TODO : See if we need to rename it// --> Or move it / move functionclass ProductConfigTools{ public function __construct(ManagerRegistry $doctrine, LogTools $logTools) { $this->em = $doctrine->getManager(); $this->logTools = $logTools; } /** * Depending to the zone get the right unitPrice for PDF method complete - Product upper cabinets * - ZoneA = ikea_linear_meter_unit_price_upper_zone_a * - ZoneB or no zone = ikea_linear_meter_unit_price_upper_zone_b */ public function getUnitPriceForMethodCompleteUpperCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_upper_zone_a); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_upper_zone_b); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_upper_zone_a or ProductConfig::ikea_linear_meter_unit_price_upper_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method complete - Product lower cabinets * - ZoneA = ikea_linear_meter_unit_price_lower_zone_a * - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b */ public function getUnitPriceForMethodCompleteLowerCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_lower_zone_a); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_lower_zone_b); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_lower_zone_a or ProductConfig::ikea_linear_meter_unit_price_lower_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method complete - Product upper cabinets * - ZoneA = ikea_linear_meter_unit_price_upper_zone_a * - ZoneB or no zone = ikea_linear_meter_unit_price_upper_zone_b */ public function getMLPriceForMethodCompleteUpperCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_upper_cabinets_zone_1); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_upper_cabinets_zone_2); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_upper_zone_a or ProductConfig::ikea_linear_meter_unit_price_upper_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method complete - Product lower cabinets * - ZoneA = ikea_linear_meter_unit_price_lower_zone_a * - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b */ public function getMLPriceForMethodCompleteLowerCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_lower_cabinets_zone_1); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_lower_cabinets_zone_2); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_lower_zone_a or ProductConfig::ikea_linear_meter_unit_price_lower_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method complete - Product lislandwer cabinets * - ZoneA = ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_1 * - ZoneB or no zone = ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_2 */ public function getMLPriceForMethodCompleteIslandCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_1); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_2); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_1 or ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_2 is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method complete - Product column cabinets * - ZoneA = ikea_linear_meter_unit_price_lower_zone_a * - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b */ public function getMLPriceForMethodCompleteColumnCabinetsLinearMeter(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_1); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_2); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_1 or ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_2 is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF knoxhult - Intervention cost * - ZoneA = ikea_intervention_cost_knoxhult_zone_a * - ZoneB or no zone = ikea_intervention_cost_knoxhult_zone_b */ public function getUnitPriceForInterventionCostKnoxhult(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_knoxhult_zone_a); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_knoxhult_zone_b); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_intervention_cost_knoxhult_zone_a or ProductConfig::ikea_intervention_cost_knoxhult_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } /** * Depending to the zone get the right unitPrice for PDF method custom - Intervention cost * - ZoneA = ikea_intervention_cost_method_custom_zone_a * - ZoneB or no zone = ikea_intervention_cost_method_custom_zone_b */ public function getUnitPriceForInterventionCostMethodCustom(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_method_custom_zone_a); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_method_custom_zone_b); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_intervention_cost_method_custom_zone_a or ProductConfig::ikea_intervention_cost_method_custom_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } // Default zone b return floatval($configProductZoneB->getValue()); } // Plan.io Task #4647 public function getUnitPriceForPrevisitMethodComplete2026(Devis $devis) { $receiverZone = $devis->getIkeaZone(); $configProductRepository = $this->em->getRepository(ProductConfig::class); $configProductZoneA = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_previsit_price_zone_a); $configProductZoneB = $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_previsit_price_zone_b); if ($configProductZoneA === null || $configProductZoneB === null) { $this->logTools->errorLog('ProductConfig::ikea_method_complete_2026_previsit_price_zone_a or ProductConfig::ikea_method_complete_2026_previsit_price_zone_b is null'); return 0; } if ($receiverZone !== null && $receiverZone->getIkeaZoneA()) { return floatval($configProductZoneA->getValue()); } return floatval($configProductZoneB->getValue()); } /** * Verify that all active configs exist in the database. * * @return bool True if all active configs exist, false otherwise */ public function productConfigsAreValid(): bool { $productConfigRepository = $this->em->getRepository(ProductConfig::class); $activeConfigs = ProductConfig::activeConfigs; $missingConfigs = $productConfigRepository->findMissingConfigs($activeConfigs); if (!empty($missingConfigs)) { $missingConfigsString = implode(', ', $missingConfigs); $this->logTools->errorLog("Missing product configs: ".$missingConfigsString); return false; } // $this->logTools->ploopLog("All product configs are accounted for."); return true; }}