src/Services/Product/ProductTools.php line 32

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Services/Product/ProductTools.php
  4. //----------------------------------------------------------------------
  5. namespace App\Services\Product;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use App\Entity\Access;
  9. use App\Entity\SocietyGroup;
  10. use App\Entity\Config\Config;
  11. use App\Entity\Product\Unit;
  12. use App\Entity\Product\Product;
  13. use App\Entity\Product\Tva;
  14. use App\Services\LogTools;
  15. use App\Services\Common\TextTools;
  16. class ProductTools
  17. {
  18.     // Import product : Correspond to the number of element in each line of the CSV
  19.     const IMPORT_SIZE_ROW_PRODUCT 6;
  20.     const IMPORT_MAX_ERROR 20;
  21.     const IMPORT_MAX_SIZE_FILE 10000;
  22.     const IMPORT_MAX_PACKAGE_SQL 1000;
  23.     public function __construct(ManagerRegistry $doctrineLogtools $logToolsTextTools $textTools)
  24.     {
  25.         $this->em $doctrine->getManager();
  26.         $this->logTools $logTools;
  27.         $this->textTools $textTools;
  28.     }
  29.     public function productToArray($product)
  30.     {
  31.         if ($product === null) return array();
  32.         $url $this->em->getRepository(Config::class)
  33.             ->findOneByName(Config::URL);
  34.         if ($url !== null)
  35.         {
  36.             $url $url->getValue();
  37.         }
  38.         $unitData = array();
  39.         $questionData = array();
  40.         $templates = array();
  41.         $productUrl null;
  42.         $tva null;
  43.         $unit $product->getUnit();
  44.         $question $product->getQuestion();
  45.         $tva $product->getTva();
  46.         if ($unit !== null)
  47.         {
  48.             $unitData = array(
  49.                 "unit_id"                =>    $unit->getId(),
  50.                 "unit_value"            =>    $unit->getValue(),
  51.                 "unit_abbrv"            =>    $unit->getAbbrv(),
  52.             );
  53.         }
  54.         if ($question !== null)
  55.         {
  56.             $questionData = array(
  57.                 "question_id"            =>    $question->getId(),
  58.                 "question_content"        =>    $question->getContent(),
  59.             );
  60.         }
  61.         if ($tva !== null)
  62.         {
  63.             $tva $tva->getValue();
  64.         }
  65.         if ($product->getLogo() !== null && $url !== null)
  66.         {
  67.             $productUrl $url "/" .$product->getLogo()->getUrlForDisplay();
  68.         }
  69.         foreach ($product->getTemplates() as $template)
  70.         {
  71.             $templates[] = array(
  72.                 "template_id"                =>    $template->getId(),
  73.                 "template_ref"                =>    $template->getRef(),
  74.                 "template_title"            =>    $template->getTitle(),
  75.                 "template_description"        =>    $template->getDescription(),
  76.             );
  77.         }
  78.         $productData = array(
  79.             "id"                        =>    $product->getId(),
  80.             "ref"                        =>    $product->getRef(),
  81.             "title"                        =>    $product->getTitle(),
  82.             "description"                =>    $product->getDescription(),
  83.             "tva"                        =>    $this->textTools->encodeForJson($tva),
  84.             "public_price"                =>    $product->getPublicPrice(),
  85.             "internal_price"            =>    $product->getInternalPrice(),
  86.             "free"                        =>    $this->textTools->encodeForJson($product->getFree()),
  87.             "discount"                    =>    $this->textTools->encodeForJson($product->getDiscount()),
  88.             "readonly"                    =>    $this->textTools->encodeForJson($product->getReadonly()),
  89.             "samePrice"                    =>    $this->textTools->encodeForJson($product->getSamePrice()),
  90.             "optionNoPrice"                =>    $this->textTools->encodeForJson($product->getOptionNoPrice()),
  91.             "logo"                        =>    $productUrl,
  92.             "unit"                        =>    $unitData,
  93.             "question"                    =>    $questionData,
  94.             "logo_url"                    =>    $productUrl,
  95.             "templates"                    =>    $templates,
  96.         );
  97.         return $productData;
  98.     }
  99.     public function productDevisToArray($product)
  100.     {
  101.         if ($product === null) return array();
  102.         $unitData = array();
  103.         $questionData = array();
  104.         $unit $product->getUnit();
  105.         $question $product->getQuestion();
  106.         $tva $product->getTva();
  107.         if ($unit !== null)
  108.         {
  109.             $unitData = array(
  110.                 "unit_id"                =>    $unit->getId(),
  111.                 "unit_value"            =>    $unit->getValue(),
  112.                 "unit_abbrv"            =>    $unit->getAbbrv(),
  113.             );
  114.         }
  115.         if ($question !== null)
  116.         {
  117.             $questionData = array(
  118.                 "question_id"            =>    $question->getId(),
  119.                 "question_content"        =>    $question->getContent(),
  120.             );
  121.         }
  122.         if ($tva !== null)
  123.         {
  124.             $tva $tva->getValue();
  125.         }
  126.         $productData = array(
  127.             "id"                        =>    $product->getId(),
  128.             "ref"                        =>    $product->getRef(),
  129.             "title"                        =>    $product->getTitle(),
  130.             "description"                =>    $product->getDescription(),
  131.             "tva"                        =>    $this->textTools->encodeForJson($tva),
  132.             "public_price"                =>    $product->getPublicPrice(),
  133.             "internal_price"            =>    $product->getInternalPrice(),
  134.             "quantity"                    =>    $this->textTools->encodeForJson($product->getQuantity()),
  135.             "percentage"                =>    $this->textTools->encodeForJson($product->getPercentage()),
  136.             "invoiced"                    =>    $this->textTools->encodeForJson($product->getInvoiced()),
  137.             "invoiced_percentage"        =>    $this->textTools->encodeForJson($product->getInvoicedPercentage()),
  138.             "discount"                    =>    $this->textTools->encodeForJson($product->getDiscount()),
  139.             "readonly"                    =>    $this->textTools->encodeForJson($product->getReadonly()),
  140.             "same_price"                =>    $this->textTools->encodeForJson($product->getSamePrice()),
  141.             "optionNoPrice"                =>    $this->textTools->encodeForJson($product->getOptionNoPrice()),
  142.             "unit"                        =>    $unitData,
  143.             "question"                    =>    $questionData,
  144.             "total_public_ht"            =>    $product->getTotalPublicHT(),
  145.             "total_internal_ht"            =>    $product->getTotalInternalHT(),
  146.             "total_public_ttc"            =>    $product->getTotalPublicTTC(),
  147.             "total_internal_ttc"        =>    $product->getTotalInternalTTC(),
  148.         );
  149.         return $productData;
  150.     }
  151. }