src/Entity/Articles/PrixPromo.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Articles;
  3. use App\Entity\Clients\Client;
  4. use App\Entity\Utilisateur\Utilisateur;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use App\Entity\Clients\Categorie;
  10. /**
  11.  * PrixPromo
  12.  *
  13.  * @ORM\Table("article__prix_promo")
  14.  * @ORM\Entity(repositoryClass="App\Repository\Articles\PrixPromoRepository")
  15.  * @Gedmo\SoftDeleteable(fieldName="dateSuppression",timeAware=false) 
  16.  */
  17. class PrixPromo
  18. {
  19.     /**
  20.      * @ORM\Column(name="id", type="integer")
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue(strategy="AUTO")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\ManyToOne(targetEntity="App\Entity\Articles\Article", inversedBy="prixPromo")
  27.      * @ORM\JoinColumn(nullable=true)
  28.      */
  29.     private $article;
  30.     
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\Clients\Categorie", inversedBy="prixPromo")
  33.      * @ORM\JoinColumn(nullable=true)
  34.      */
  35.     private $categorieClient;
  36.     
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\Clients\Client", inversedBy="prixPromo")
  39.      * @ORM\JoinColumn(nullable=true)
  40.      */
  41.     private $client;
  42.     
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur\Utilisateur", inversedBy="prixPromo")
  45.      * @ORM\JoinColumn(nullable=true)
  46.      */
  47.     private $utilisateur;
  48.     /**
  49.      * @ORM\Column(name="date", type="datetime", nullable=true)
  50.      */
  51.     private $date;
  52.     /**
  53.      * @ORM\Column(name="dateMaj", type="datetime", nullable=true)
  54.      * @Gedmo\Timestampable(on="update")     
  55.      */
  56.     private $dateMaj;
  57.     /**
  58.      * @ORM\Column(name="dateSuppression", type="datetime", nullable=true)
  59.      */
  60.     private $dateSuppression;
  61.     /**
  62.      * @ORM\Column(name="dateDebut", type="datetime", nullable=true)
  63.      */
  64.     private $dateDebut;
  65.     /**
  66.      * @ORM\Column(name="dateFin", type="datetime", nullable=true)
  67.      * @Assert\NotNull(message="Merci de définir une date de fin")
  68.      */
  69.     private $dateFin;
  70.     /**
  71.      * @ORM\Column(name="prix", type="float", nullable=true)
  72.      */
  73.     private $prix;
  74.     /**
  75.      * @ORM\Column(name="reduction", type="float", nullable=true)
  76.      */
  77.     private $reduction;
  78.     /**
  79.      * @ORM\Column(name="typeReduction", type="string", length=255)
  80.      */
  81.     private $typeReduction;
  82.     
  83.     /**
  84.      * @ORM\Column(name="statut", type="boolean", nullable=true)
  85.      */
  86.     private $statut;
  87.     /**
  88.      * @Assert\True(message="Merci de saisir un nouveau prix HT ou une remise")
  89.     */
  90.     public function isPromoSaisiValid(): bool
  91.     {
  92.         if($this->reduction or $this->prix 0) return true;
  93.         else return false;
  94.     }
  95.     
  96.     
  97.     /**
  98.      * @Assert\True(message="Cette promo est supérieur à la remise max de l'article")
  99.     */
  100.     public function isPromoValid(): bool
  101.     {
  102.         $article $this->article;
  103.         $prixArticle $article->getPrixBase();
  104.         $remiseMaxArticle $article->getRemiseMax();
  105.         $typeRemiseMaxArticle $article->getTypeRemiseMax();
  106.         
  107.         $nouveauPrix $this->getPrix();
  108.         $remiseMax $this->getReduction();
  109.         $typeRemiseMax $this->getTypeReduction();
  110.         
  111.         if($remiseMaxArticle && ($typeRemiseMaxArticle == 'pourcentage' or $typeRemiseMaxArticle == 'montant')) {
  112.             //Nouveau prix HT pour la promo
  113.             if($nouveauPrix != "") {
  114.                 if($typeRemiseMaxArticle == "montant") {
  115.                     if(($prixArticle $nouveauPrix) > $remiseMaxArticle) return false;
  116.                 }
  117.                 else if($typeRemiseMaxArticle == "pourcentage") {
  118.                     $calculPrixRemiseMax $prixArticle - (($remiseMaxArticle*$prixArticle)/100);
  119.                     
  120.                     if($nouveauPrix $calculPrixRemiseMax) return false;
  121.                 }
  122.             }
  123.             //Reduction pour la promo
  124.             else {
  125.                 if($typeRemiseMaxArticle == "pourcentage" && $typeRemiseMax == "pourcentage") {
  126.                     if($remiseMax $remiseMaxArticle) return false;
  127.                 }
  128.                 else if($typeRemiseMaxArticle == "montant" && $typeRemiseMax == "montant") {
  129.                     if($remiseMax $remiseMaxArticle) return false;
  130.                 }
  131.                 else if($typeRemiseMaxArticle == "montant" && $typeRemiseMax == "pourcentage") {
  132.                     $calculPrixRemiseMax $prixArticle $remiseMaxArticle;
  133.                     $calculPrixPromo $prixArticle - (($remiseMax*$prixArticle)/100);
  134.                     if($calculPrixPromo $calculPrixRemiseMax) return false;
  135.                 }
  136.                 else if($typeRemiseMaxArticle == "pourcentage" && $typeRemiseMax == "montant") {
  137.                     
  138.                     $calculPrixRemiseMax $prixArticle - (($remiseMaxArticle*$prixArticle)/100);
  139.                     $calculPrixPromo $prixArticle $remiseMax;
  140.                     if($calculPrixPromo $calculPrixRemiseMax) return false;
  141.                 }
  142.             }
  143.         }    
  144.         return true;
  145.     }
  146.     public function __construct()
  147.     {
  148.         $this->date      = new Datetime();
  149.         $this->dateDebut = new Datetime();
  150.         $this->statut    true;
  151.     }
  152.     public function getId(): int
  153.     {
  154.         return $this->id;
  155.     }
  156.     public function setDate(?DateTime $date): PrixPromo
  157.     {
  158.         $this->date $date;
  159.         return $this;
  160.     }
  161.     public function getDate(): ?DateTime
  162.     {
  163.         return $this->date;
  164.     }
  165.     public function setDateMaj(?DateTime $dateMaj): PrixPromo
  166.     {
  167.         $this->dateMaj $dateMaj;
  168.         return $this;
  169.     }
  170.     public function getDateMaj(): ?DateTime
  171.     {
  172.         return $this->dateMaj;
  173.     }
  174.     public function setDateSuppression(?DateTime $dateSuppression): PrixPromo
  175.     {
  176.         $this->dateSuppression $dateSuppression;
  177.         return $this;
  178.     }
  179.     public function getDateSuppression(): ?DateTime
  180.     {
  181.         return $this->dateSuppression;
  182.     }
  183.     public function setDateDebut(?DateTime $dateDebut): PrixPromo
  184.     {
  185.         $this->dateDebut $dateDebut;
  186.         return $this;
  187.     }
  188.     public function getDateDebut(): ?DateTime
  189.     {
  190.         return $this->dateDebut;
  191.     }
  192.     public function setDateFin(?DateTime $dateFin): PrixPromo
  193.     {
  194.         $this->dateFin $dateFin;
  195.         return $this;
  196.     }
  197.     public function getDateFin(): ?DateTime
  198.     {
  199.         return $this->dateFin;
  200.     }
  201.     public function setPrix(?float $prix): PrixPromo
  202.     {
  203.         $this->prix $prix;
  204.         return $this;
  205.     }
  206.     public function getPrix(): ?float
  207.     {
  208.         return $this->prix;
  209.     }
  210.     public function setReduction(?float $reduction): PrixPromo
  211.     {
  212.         $this->reduction $reduction;
  213.         return $this;
  214.     }
  215.     public function getReduction(): ?float
  216.     {
  217.         return $this->reduction;
  218.     }
  219.     public function setUtilisateur(?Utilisateur $utilisateur): PrixPromo
  220.     {
  221.         $this->utilisateur $utilisateur;
  222.         return $this;
  223.     }
  224.     public function getUtilisateur(): ?Utilisateur
  225.     {
  226.         return $this->utilisateur;
  227.     }
  228.     public function setArticle(?Article $article): PrixPromo
  229.     {
  230.         $this->article $article;
  231.         return $this;
  232.     }
  233.     public function getArticle(): ?Article
  234.     {
  235.         return $this->article;
  236.     }
  237.     public function setTypeReduction(string $typeReduction): PrixPromo
  238.     {
  239.         $this->typeReduction $typeReduction;
  240.         return $this;
  241.     }
  242.     public function getTypeReduction(): string
  243.     {
  244.         return $this->typeReduction;
  245.     }
  246.     public function setStatut(?bool $statut): PrixPromo
  247.     {
  248.         $this->statut $statut;
  249.         return $this;
  250.     }
  251.     public function getStatut(): ?bool
  252.     {
  253.         return $this->statut;
  254.     }
  255.     public function setCategorieClient(?Categorie $categorieClient): PrixPromo
  256.     {
  257.         $this->categorieClient $categorieClient;
  258.         return $this;
  259.     }
  260.     public function getCategorieClient(): ?Categorie
  261.     {
  262.         return $this->categorieClient;
  263.     }
  264.     public function setClient(?Client $client): PrixPromo
  265.     {
  266.         $this->client $client;
  267.         return $this;
  268.     }
  269.     public function getClient(): ?Client
  270.     {
  271.         return $this->client;
  272.     }
  273. }