src/Services/Product/ProductConfigTools.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Services\Product;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use App\Entity\Platform\Devis\Devis;
  5. use App\Services\LogTools;
  6. use App\Entity\Product\Config as ProductConfig;
  7. // TODO : See if we need to rename it
  8. // --> Or move it / move function
  9. class ProductConfigTools
  10. {
  11.     public function __construct(ManagerRegistry $doctrineLogTools $logTools)
  12.     {
  13.         $this->em $doctrine->getManager();
  14.         $this->logTools $logTools;
  15.     }
  16.     /**
  17.      * Depending to the zone get the right unitPrice for PDF method complete - Product upper cabinets
  18.      *        - ZoneA = ikea_linear_meter_unit_price_upper_zone_a
  19.      *        - ZoneB or no zone = ikea_linear_meter_unit_price_upper_zone_b
  20.      */
  21.     public function getUnitPriceForMethodCompleteUpperCabinetsLinearMeter(Devis $devis)
  22.     {
  23.         $receiverZone $devis->getIkeaZone();
  24.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  25.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_upper_zone_a);
  26.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_upper_zone_b);
  27.         if ($configProductZoneA === null || $configProductZoneB === null)
  28.         {
  29.             $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_upper_zone_a or ProductConfig::ikea_linear_meter_unit_price_upper_zone_b is null');
  30.             return 0;
  31.         }
  32.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  33.         {
  34.             return floatval($configProductZoneA->getValue());
  35.         }
  36.         // Default zone b
  37.         return floatval($configProductZoneB->getValue());
  38.     }
  39.     /**
  40.      * Depending to the zone get the right unitPrice for PDF method complete - Product lower cabinets
  41.      *        - ZoneA = ikea_linear_meter_unit_price_lower_zone_a
  42.      *        - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b
  43.      */
  44.     public function getUnitPriceForMethodCompleteLowerCabinetsLinearMeter(Devis $devis)
  45.     {
  46.         $receiverZone $devis->getIkeaZone();
  47.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  48.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_lower_zone_a);
  49.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_linear_meter_unit_price_lower_zone_b);
  50.         if ($configProductZoneA === null || $configProductZoneB === null)
  51.         {
  52.             $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_lower_zone_a or ProductConfig::ikea_linear_meter_unit_price_lower_zone_b is null');
  53.             return 0;
  54.         }
  55.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  56.         {
  57.             return floatval($configProductZoneA->getValue());
  58.         }
  59.         // Default zone b
  60.         return floatval($configProductZoneB->getValue());
  61.     }
  62.     /**
  63.      * Depending to the zone get the right unitPrice for PDF method complete - Product upper cabinets
  64.      *        - ZoneA = ikea_linear_meter_unit_price_upper_zone_a
  65.      *        - ZoneB or no zone = ikea_linear_meter_unit_price_upper_zone_b
  66.      */
  67.     public function getMLPriceForMethodCompleteUpperCabinetsLinearMeter(Devis $devis)
  68.     {
  69.         $receiverZone $devis->getIkeaZone();
  70.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  71.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_upper_cabinets_zone_1);
  72.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_upper_cabinets_zone_2);
  73.         if ($configProductZoneA === null || $configProductZoneB === null)
  74.         {
  75.             $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_upper_zone_a or ProductConfig::ikea_linear_meter_unit_price_upper_zone_b is null');
  76.             return 0;
  77.         }
  78.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  79.         {
  80.             return floatval($configProductZoneA->getValue());
  81.         }
  82.         // Default zone b
  83.         return floatval($configProductZoneB->getValue());
  84.     }
  85.     /**
  86.      * Depending to the zone get the right unitPrice for PDF method complete - Product lower cabinets
  87.      *        - ZoneA = ikea_linear_meter_unit_price_lower_zone_a
  88.      *        - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b
  89.      */
  90.     public function getMLPriceForMethodCompleteLowerCabinetsLinearMeter(Devis $devis)
  91.     {
  92.         $receiverZone $devis->getIkeaZone();
  93.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  94.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_lower_cabinets_zone_1);
  95.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_lower_cabinets_zone_2);
  96.         if ($configProductZoneA === null || $configProductZoneB === null)
  97.         {
  98.             $this->logTools->errorLog('ProductConfig::ikea_linear_meter_unit_price_lower_zone_a or ProductConfig::ikea_linear_meter_unit_price_lower_zone_b is null');
  99.             return 0;
  100.         }
  101.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  102.         {
  103.             return floatval($configProductZoneA->getValue());
  104.         }
  105.         // Default zone b
  106.         return floatval($configProductZoneB->getValue());
  107.     }
  108.     /**
  109.      * Depending to the zone get the right unitPrice for PDF method complete - Product lislandwer cabinets
  110.      *        - ZoneA = ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_1
  111.      *        - ZoneB or no zone = ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_2
  112.      */
  113.     public function getMLPriceForMethodCompleteIslandCabinetsLinearMeter(Devis $devis)
  114.     {
  115.         $receiverZone $devis->getIkeaZone();
  116.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  117.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_1);
  118.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_island_cabinets_zone_2);
  119.         if ($configProductZoneA === null || $configProductZoneB === null)
  120.         {
  121.             $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');
  122.             return 0;
  123.         }
  124.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  125.         {
  126.             return floatval($configProductZoneA->getValue());
  127.         }
  128.         // Default zone b
  129.         return floatval($configProductZoneB->getValue());
  130.     }
  131.         /**
  132.      * Depending to the zone get the right unitPrice for PDF method complete - Product column cabinets
  133.      *        - ZoneA = ikea_linear_meter_unit_price_lower_zone_a
  134.      *        - ZoneB or no zone = ikea_linear_meter_unit_price_lower_zone_b
  135.      */
  136.     public function getMLPriceForMethodCompleteColumnCabinetsLinearMeter(Devis $devis)
  137.     {
  138.         $receiverZone $devis->getIkeaZone();
  139.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  140.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_1);
  141.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_price_per_linear_meter_column_cabinets_zone_2);
  142.         if ($configProductZoneA === null || $configProductZoneB === null)
  143.         {
  144.             $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');
  145.             return 0;
  146.         }
  147.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  148.         {
  149.             return floatval($configProductZoneA->getValue());
  150.         }
  151.         // Default zone b
  152.         return floatval($configProductZoneB->getValue());
  153.     }
  154.     /**
  155.      * Depending to the zone get the right unitPrice for PDF knoxhult - Intervention cost
  156.      *        - ZoneA = ikea_intervention_cost_knoxhult_zone_a
  157.      *        - ZoneB or no zone = ikea_intervention_cost_knoxhult_zone_b
  158.      */
  159.     public function getUnitPriceForInterventionCostKnoxhult(Devis $devis)
  160.     {
  161.         $receiverZone $devis->getIkeaZone();
  162.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  163.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_knoxhult_zone_a);
  164.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_knoxhult_zone_b);
  165.         if ($configProductZoneA === null || $configProductZoneB === null)
  166.         {
  167.             $this->logTools->errorLog('ProductConfig::ikea_intervention_cost_knoxhult_zone_a or ProductConfig::ikea_intervention_cost_knoxhult_zone_b is null');
  168.             return 0;
  169.         }
  170.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  171.         {
  172.             return floatval($configProductZoneA->getValue());
  173.         }
  174.         // Default zone b
  175.         return floatval($configProductZoneB->getValue());
  176.     }
  177.     /**
  178.      * Depending to the zone get the right unitPrice for PDF method custom - Intervention cost
  179.      *        - ZoneA = ikea_intervention_cost_method_custom_zone_a
  180.      *        - ZoneB or no zone = ikea_intervention_cost_method_custom_zone_b
  181.      */
  182.     public function getUnitPriceForInterventionCostMethodCustom(Devis $devis)
  183.     {
  184.         $receiverZone $devis->getIkeaZone();
  185.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  186.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_method_custom_zone_a);
  187.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_intervention_cost_method_custom_zone_b);
  188.         if ($configProductZoneA === null || $configProductZoneB === null)
  189.         {
  190.             $this->logTools->errorLog('ProductConfig::ikea_intervention_cost_method_custom_zone_a or ProductConfig::ikea_intervention_cost_method_custom_zone_b is null');
  191.             return 0;
  192.         }
  193.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  194.         {
  195.             return floatval($configProductZoneA->getValue());
  196.         }
  197.         // Default zone b
  198.         return floatval($configProductZoneB->getValue());
  199.     }
  200.     // Plan.io Task #4647
  201.     public function getUnitPriceForPrevisitMethodComplete2026(Devis $devis)
  202.     {
  203.         $receiverZone $devis->getIkeaZone();
  204.         $configProductRepository $this->em->getRepository(ProductConfig::class);
  205.         $configProductZoneA $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_previsit_price_zone_a);
  206.         $configProductZoneB $configProductRepository->findOneByName(ProductConfig::ikea_method_complete_2026_previsit_price_zone_b);
  207.         if ($configProductZoneA === null || $configProductZoneB === null)
  208.         {
  209.             $this->logTools->errorLog('ProductConfig::ikea_method_complete_2026_previsit_price_zone_a or ProductConfig::ikea_method_complete_2026_previsit_price_zone_b is null');
  210.             return 0;
  211.         }
  212.         if ($receiverZone !== null && $receiverZone->getIkeaZoneA())
  213.         {
  214.             return floatval($configProductZoneA->getValue());
  215.         }
  216.         
  217.         return floatval($configProductZoneB->getValue());
  218.     }
  219.     /**
  220.      * Verify that all active configs exist in the database.
  221.      *
  222.      * @return bool True if all active configs exist, false otherwise
  223.      */
  224.     public function productConfigsAreValid(): bool
  225.     {
  226.         $productConfigRepository $this->em->getRepository(ProductConfig::class);
  227.         $activeConfigs ProductConfig::activeConfigs;
  228.         $missingConfigs $productConfigRepository->findMissingConfigs($activeConfigs);
  229.         if (!empty($missingConfigs))
  230.         {
  231.             $missingConfigsString implode(', '$missingConfigs);
  232.             $this->logTools->errorLog("Missing product configs: ".$missingConfigsString);
  233.             return false;
  234.         }
  235.         // $this->logTools->ploopLog("All product configs are accounted for.");
  236.         return true;
  237.     }
  238. }