vendor/bluue/sales-bundle/src/Entity/InvoiceLine.php line 39

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Quentin CHATELAIN (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\SalesBundle\Entity;
  9. use App\Entity\Traits\EntityManagerServiceEntity;
  10. use App\Services\SoftdeleteFilter;
  11. use DateTime;
  12. use App\Entity\TaxRule;
  13. use Doctrine\ORM\NonUniqueResultException;
  14. use Symfony\Component\Uid\Uuid;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use Doctrine\Common\Collections\Collection;
  18. use Doctrine\Common\Collections\ArrayCollection;
  19. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  20. use Bluue\SalesBundle\Repository\InvoiceLineRepository;
  21. use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
  22. use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
  23. use Bluue\ProductsBundle\Entity\Declination;
  24. use Bluue\ProductsBundle\Entity\Product;
  25. /**
  26.  * @ORM\Entity(repositoryClass=InvoiceLineRepository::class)
  27.  * @ORM\Table(name="sales_bundle__invoice_line", indexes={
  28.  *  @ORM\Index(name="deleted_at", columns={"deleted_at"}),
  29.  *  @ORM\Index(name="created_at", columns={"created_at"}),
  30.  *  @ORM\Index(name="updated_at", columns={"updated_at"})
  31.  * })
  32.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
  33.  */
  34. class InvoiceLine
  35. {
  36.     use UserTimestampableEntity;
  37.     use UserSoftDeleteableEntity;
  38.     use EntityManagerServiceEntity;
  39.     /**
  40.      * @ORM\Id
  41.      * @ORM\Column(type="uuid")
  42.      * @ORM\GeneratedValue(strategy="CUSTOM")
  43.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  44.      */
  45.     private ?Uuid $id null;
  46.     /**
  47.      * @ORM\ManyToOne(targetEntity=Invoice::class, inversedBy="lines")
  48.      * @ORM\JoinColumn(nullable=false)
  49.      */
  50.     private ?Invoice $invoice null;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=LineType::class)
  53.      */
  54.     private ?LineType $line_type null;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity=TaxRule::class)
  57.      */
  58.     private ?TaxRule $tax_rule null;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity="InvoiceLine", inversedBy="childrens")
  61.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  62.      */
  63.     private ?InvoiceLine $parent null;
  64.     /**
  65.      * @ORM\Column(type="boolean")
  66.      */
  67.     private bool $is_group false;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity="InvoiceLine", inversedBy="packChildrens")
  70.      * @ORM\JoinColumn(name="pack_parent_id", referencedColumnName="id")
  71.      */
  72.     private ?InvoiceLine $packParent null;
  73.     /**
  74.      * @ORM\Column(type="boolean")
  75.      */
  76.     private bool $is_pack false;
  77.     /**
  78.      * @ORM\Column(type="string", length=128, nullable="true")
  79.      */
  80.     private ?string $reference null;
  81.     /**
  82.      * @ORM\Column(type="string", length=128, nullable="true")
  83.      */
  84.     private ?string $referenceBrand null;
  85.     /**
  86.      * @ORM\Column(type="string", length=255, nullable="true")
  87.      */
  88.     private ?string $name null;
  89.     /**
  90.      * @ORM\Column(type="text", nullable="true")
  91.      */
  92.     private ?string $description null;
  93.     /**
  94.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  95.      */
  96.     private ?string $unit_price null;
  97.     /**
  98.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  99.      */
  100.     private ?string $unitPriceWithTax null;
  101.     /**
  102.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  103.      */
  104.     private ?string $quantity null;
  105.     /**
  106.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  107.      */
  108.     private ?string $wholesale_price null;
  109.     /**
  110.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  111.      */
  112.     private ?string $margin_ratio null;
  113.     /**
  114.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  115.      */
  116.     private ?string $percentage_discount_untaxed null;
  117.     /**
  118.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  119.      */
  120.     private ?string $total_discount_untaxed null;
  121.     /**
  122.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  123.      */
  124.     private ?string $totalDiscount null;
  125.     /**
  126.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  127.      */
  128.     private ?string $total_amount_no_discount_untaxed null;
  129.     /**
  130.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  131.      */
  132.     private ?string $totalAmountNoDiscount null;
  133.     /**
  134.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  135.      */
  136.     private ?string $total_amount_untaxed null;
  137.     /**
  138.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  139.      */
  140.     private ?string $total_tax_amount null;
  141.     /**
  142.      * @ORM\Column(type="decimal", precision=20, scale=6, nullable="true")
  143.      */
  144.     private ?string $total_amount null;
  145.     /**
  146.      * @ORM\Column(type="integer")
  147.      */
  148.     private ?int $position null;
  149.     /**
  150.      * @ORM\Column(type="json")
  151.      */
  152.     private array $options = [];
  153.     /**
  154.      * @ORM\OneToMany(targetEntity="InvoiceLine", mappedBy="parent", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
  155.      * @ORM\OrderBy({"position" = "ASC"})
  156.      */
  157.     private Collection $childrens;
  158.     /**
  159.      * @ORM\OneToMany(
  160.      *      targetEntity="InvoiceLine",
  161.      *      mappedBy="packParent",
  162.      *      cascade={"persist", "remove"},
  163.      *      fetch="EXTRA_LAZY"
  164.      * )
  165.      * @ORM\OrderBy({"position" = "ASC"})
  166.      */
  167.     private Collection $packChildrens;
  168.     /**
  169.      * @ORM\ManyToOne(targetEntity=Product::class)
  170.      */
  171.     private ?Product $product null;
  172.     /**
  173.      * @ORM\ManyToOne(targetEntity=Declination::class)
  174.      */
  175.     private ?Declination $declination null;
  176.     public function __construct()
  177.     {
  178.         $this->childrens = new ArrayCollection();
  179.         $this->packChildrens = new ArrayCollection();
  180.     }
  181.     /**
  182.      * @return Uuid|null
  183.      */
  184.     public function getId(): ?Uuid
  185.     {
  186.         return $this->id;
  187.     }
  188.     /**
  189.      * @return InvoiceLine
  190.      */
  191.     public function setId(): self
  192.     {
  193.         $this->id null;
  194.         return $this;
  195.     }
  196.     /**
  197.      * @return Invoice|null
  198.      */
  199.     public function getInvoice(): ?Invoice
  200.     {
  201.         return $this->invoice;
  202.     }
  203.     /**
  204.      * @param Invoice $invoice
  205.      * @return InvoiceLine
  206.      */
  207.     public function setInvoice(Invoice $invoice): self
  208.     {
  209.         $this->invoice $invoice;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return LineType|null
  214.      */
  215.     public function getLineType(): ?LineType
  216.     {
  217.         return $this->line_type;
  218.     }
  219.     /**
  220.      * @param LineType|null $line_type
  221.      * @return InvoiceLine
  222.      */
  223.     public function setLineType(?LineType $line_type): self
  224.     {
  225.         $this->line_type $line_type;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return TaxRule|null
  230.      * @throws NonUniqueResultException
  231.      */
  232.     public function getTaxRule(): ?TaxRule
  233.     {
  234.         if ($this->em && $this->tax_rule) {
  235.             SoftdeleteFilter::disable($this->em, [TaxRule::class]);
  236.             $taxRule $this->em->getRepository(TaxRule::class)
  237.                 ->createQueryBuilder('tr')
  238.                 ->where('tr.id = :taxRuleId')
  239.                 ->setParameter('taxRuleId'$this->tax_rule->getId()->toBinary())
  240.                 ->getQuery()
  241.                 ->getOneOrNullResult();
  242.             SoftdeleteFilter::enable($this->em, [TaxRule::class]);
  243.             return $taxRule;
  244.         }
  245.         return $this->tax_rule;
  246.     }
  247.     /**
  248.      * @param TaxRule|null $tax_rule
  249.      * @return InvoiceLine
  250.      */
  251.     public function setTaxRule(?TaxRule $tax_rule): self
  252.     {
  253.         $this->tax_rule $tax_rule;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @return InvoiceLine|null
  258.      */
  259.     public function getParent(): ?InvoiceLine
  260.     {
  261.         return $this->parent;
  262.     }
  263.     /**
  264.      * @param InvoiceLine|null $parent
  265.      * @return InvoiceLine
  266.      */
  267.     public function setParent(?InvoiceLine $parent): self
  268.     {
  269.         $this->parent $parent;
  270.         return $this;
  271.     }
  272.     /**
  273.      * @return bool
  274.      */
  275.     public function getIsGroup(): bool
  276.     {
  277.         return $this->is_group;
  278.     }
  279.     /**
  280.      * @param bool $is_group
  281.      * @return InvoiceLine
  282.      */
  283.     public function setIsGroup(bool $is_group): self
  284.     {
  285.         $this->is_group $is_group;
  286.         return $this;
  287.     }
  288.     /**
  289.      * @return InvoiceLine|null
  290.      */
  291.     public function getPackParent(): ?InvoiceLine
  292.     {
  293.         return $this->packParent;
  294.     }
  295.     /**
  296.      * @param InvoiceLine|null $packParent
  297.      * @return InvoiceLine
  298.      */
  299.     public function setPackParent(?InvoiceLine $packParent): self
  300.     {
  301.         $this->packParent $packParent;
  302.         return $this;
  303.     }
  304.     /**
  305.      * @return bool
  306.      */
  307.     public function getIsPack(): bool
  308.     {
  309.         return $this->is_pack;
  310.     }
  311.     /**
  312.      * @param bool $is_pack
  313.      * @return InvoiceLine
  314.      */
  315.     public function setIsPack(bool $is_pack): self
  316.     {
  317.         $this->is_pack $is_pack;
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return string|null
  322.      */
  323.     public function getReference(): ?string
  324.     {
  325.         return $this->reference;
  326.     }
  327.     /**
  328.      * @param string|null $reference
  329.      * @return InvoiceLine
  330.      */
  331.     public function setReference(?string $reference): self
  332.     {
  333.         $this->reference $reference;
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return string|null
  338.      */
  339.     public function getReferenceBrand(): ?string
  340.     {
  341.         return $this->referenceBrand;
  342.     }
  343.     /**
  344.      * @param string|null $referenceBrand
  345.      * @return InvoiceLine
  346.      */
  347.     public function setReferenceBrand(?string $referenceBrand): self
  348.     {
  349.         $this->referenceBrand $referenceBrand;
  350.         return $this;
  351.     }
  352.     /**
  353.      * @return string|null
  354.      */
  355.     public function getName(): ?string
  356.     {
  357.         return $this->name;
  358.     }
  359.     /**
  360.      * @param string|null $name
  361.      * @return InvoiceLine
  362.      */
  363.     public function setName(?string $name): self
  364.     {
  365.         $this->name $name;
  366.         return $this;
  367.     }
  368.     /**
  369.      * @return string|null
  370.      */
  371.     public function getDescription(): ?string
  372.     {
  373.         return $this->description;
  374.     }
  375.     /**
  376.      * @param string|null $description
  377.      * @return InvoiceLine
  378.      */
  379.     public function setDescription(?string $description): self
  380.     {
  381.         $this->description $description;
  382.         return $this;
  383.     }
  384.     /**
  385.      * @return string|null
  386.      */
  387.     public function getUnitPrice(): ?string
  388.     {
  389.         return $this->unit_price;
  390.     }
  391.     /**
  392.      * @param string|null $unit_price
  393.      * @return InvoiceLine
  394.      */
  395.     public function setUnitPrice(?string $unit_price): self
  396.     {
  397.         $this->unit_price $unit_price;
  398.         return $this;
  399.     }
  400.     /**
  401.      * @return string|null
  402.      */
  403.     public function getUnitPriceWithTax(): ?string
  404.     {
  405.         return $this->unitPriceWithTax;
  406.     }
  407.     /**
  408.      * @param string|null $unitPriceWithTax
  409.      * @return InvoiceLine
  410.      */
  411.     public function setUnitPriceWithTax(?string $unitPriceWithTax): InvoiceLine
  412.     {
  413.         $this->unitPriceWithTax $unitPriceWithTax;
  414.         return $this;
  415.     }
  416.     /**
  417.      * @return string|null
  418.      */
  419.     public function getQuantity(): ?string
  420.     {
  421.         return $this->quantity;
  422.     }
  423.     /**
  424.      * @param string|null $quantity
  425.      * @return InvoiceLine
  426.      */
  427.     public function setQuantity(?string $quantity): self
  428.     {
  429.         $this->quantity $quantity;
  430.         return $this;
  431.     }
  432.     /**
  433.      * @return string|null
  434.      */
  435.     public function getWholesalePrice(): ?string
  436.     {
  437.         return $this->wholesale_price;
  438.     }
  439.     /**
  440.      * @param string|null $wholesale_price
  441.      * @return InvoiceLine
  442.      */
  443.     public function setWholesalePrice(?string $wholesale_price): self
  444.     {
  445.         $this->wholesale_price $wholesale_price;
  446.         return $this;
  447.     }
  448.     /**
  449.      * @return string|null
  450.      */
  451.     public function getMarginRatio(): ?string
  452.     {
  453.         return $this->margin_ratio;
  454.     }
  455.     /**
  456.      * @param string|null $margin_ratio
  457.      * @return InvoiceLine
  458.      */
  459.     public function setMarginRatio(?string $margin_ratio): self
  460.     {
  461.         $this->margin_ratio $margin_ratio;
  462.         return $this;
  463.     }
  464.     /**
  465.      * @param bool $calcWithPackaging
  466.      * @return float|null
  467.      */
  468.     public function getTotalMargin(bool $calcWithPackaging false): ?float
  469.     {
  470.         if ($this->wholesale_price === null) {
  471.             return 0;
  472.         }
  473.         if ($calcWithPackaging && !empty($this->options['unitQuantity'])) {
  474.             $quantity = (float) $this->options['unitQuantity'];
  475.         } else {
  476.             $quantity = (int) $this->quantity;
  477.         }
  478.         $sellPrice = (float) $this->total_amount_untaxed;
  479.         if (!empty($this->options['ecoPart']) && !empty($this->options['ecoPart']['amount'])) {
  480.             $sellPrice -= $this->options['ecoPart']['amount']  * $quantity;
  481.         }
  482.         return $sellPrice - (float) $this->wholesale_price $quantity;
  483.     }
  484.     /**
  485.      * @return string|null
  486.      */
  487.     public function getPercentageDiscountUntaxed(): ?string
  488.     {
  489.         return $this->percentage_discount_untaxed;
  490.     }
  491.     /**
  492.      * @param string|null $percentage_discount_untaxed
  493.      * @return InvoiceLine
  494.      */
  495.     public function setPercentageDiscountUntaxed(?string $percentage_discount_untaxed): self
  496.     {
  497.         $this->percentage_discount_untaxed $percentage_discount_untaxed;
  498.         return $this;
  499.     }
  500.     /**
  501.      * @return string|null
  502.      */
  503.     public function getTotalDiscountUntaxed(): ?string
  504.     {
  505.         return $this->total_discount_untaxed;
  506.     }
  507.     /**
  508.      * @param string|null $total_discount_untaxed
  509.      * @return InvoiceLine
  510.      */
  511.     public function setTotalDiscountUntaxed(?string $total_discount_untaxed): self
  512.     {
  513.         $this->total_discount_untaxed $total_discount_untaxed;
  514.         return $this;
  515.     }
  516.     /**
  517.      * @return string|null
  518.      */
  519.     public function getTotalDiscount(): ?string
  520.     {
  521.         return $this->totalDiscount;
  522.     }
  523.     /**
  524.      * @param string|null $totalDiscount
  525.      * @return InvoiceLine
  526.      */
  527.     public function setTotalDiscount(?string $totalDiscount): InvoiceLine
  528.     {
  529.         $this->totalDiscount $totalDiscount;
  530.         return $this;
  531.     }
  532.     /**
  533.      * @return string|null
  534.      */
  535.     public function getTotalAmountNoDiscountUntaxed(): ?string
  536.     {
  537.         return $this->total_amount_no_discount_untaxed;
  538.     }
  539.     /**
  540.      * @param string|null $total_amount_no_discount_untaxed
  541.      * @return InvoiceLine
  542.      */
  543.     public function setTotalAmountNoDiscountUntaxed(?string $total_amount_no_discount_untaxed): self
  544.     {
  545.         $this->total_amount_no_discount_untaxed $total_amount_no_discount_untaxed;
  546.         return $this;
  547.     }
  548.     /**
  549.      * @return string|null
  550.      */
  551.     public function getTotalAmountNoDiscount(): ?string
  552.     {
  553.         return $this->totalAmountNoDiscount;
  554.     }
  555.     /**
  556.      * @param string|null $totalAmountNoDiscount
  557.      * @return InvoiceLine
  558.      */
  559.     public function setTotalAmountNoDiscount(?string $totalAmountNoDiscount): InvoiceLine
  560.     {
  561.         $this->totalAmountNoDiscount $totalAmountNoDiscount;
  562.         return $this;
  563.     }
  564.     /**
  565.      * @return string|null
  566.      */
  567.     public function getTotalAmountUntaxed(): ?string
  568.     {
  569.         return $this->total_amount_untaxed;
  570.     }
  571.     /**
  572.      * @param string|null $total_amount_untaxed
  573.      * @return InvoiceLine
  574.      */
  575.     public function setTotalAmountUntaxed(?string $total_amount_untaxed): self
  576.     {
  577.         $this->total_amount_untaxed $total_amount_untaxed;
  578.         return $this;
  579.     }
  580.     /**
  581.      * @return string|null
  582.      */
  583.     public function getTotalTaxAmount(): ?string
  584.     {
  585.         return $this->total_tax_amount;
  586.     }
  587.     /**
  588.      * @param string|null $total_tax_amount
  589.      * @return InvoiceLine
  590.      */
  591.     public function setTotalTaxAmount(?string $total_tax_amount): self
  592.     {
  593.         $this->total_tax_amount $total_tax_amount;
  594.         return $this;
  595.     }
  596.     /**
  597.      * @return string|null
  598.      */
  599.     public function getTotalAmount(): ?string
  600.     {
  601.         return $this->total_amount;
  602.     }
  603.     /**
  604.      * @param string|null $total_amount
  605.      * @return InvoiceLine
  606.      */
  607.     public function setTotalAmount(?string $total_amount): self
  608.     {
  609.         $this->total_amount $total_amount;
  610.         return $this;
  611.     }
  612.     /**
  613.      * @return int|null
  614.      */
  615.     public function getPosition(): ?int
  616.     {
  617.         return $this->position;
  618.     }
  619.     /**
  620.      * @param int|null $position
  621.      * @return InvoiceLine
  622.      */
  623.     public function setPosition(?int $position): self
  624.     {
  625.         $this->position $position;
  626.         return $this;
  627.     }
  628.     /**
  629.      * @return array
  630.      */
  631.     public function getOptions(): array
  632.     {
  633.         return $this->options;
  634.     }
  635.     /**
  636.      * @param array $options
  637.      * @return InvoiceLine
  638.      */
  639.     public function setOptions(array $options): self
  640.     {
  641.         $this->options $options;
  642.         return $this;
  643.     }
  644.     /**
  645.      * @param array $options
  646.      * @return InvoiceLine
  647.      */
  648.     public function addOptions(array $options): self
  649.     {
  650.         return $this->setOptions(array_merge($this->options$options));
  651.     }
  652.     /**
  653.      * @return Collection|InvoiceLine[]
  654.      */
  655.     public function getChildrens(): Collection
  656.     {
  657.         return $this->childrens;
  658.     }
  659.     /**
  660.      * @param InvoiceLine $line
  661.      * @return $this
  662.      */
  663.     public function addChildren(InvoiceLine $line): self
  664.     {
  665.         if (!$this->childrens->contains($line)) {
  666.             $this->childrens[] = $line;
  667.             $line->setParent($this);
  668.             if ($line->getInvoice() !== $this->getInvoice()) {
  669.                 $line->setInvoice($this->getInvoice());
  670.             }
  671.         }
  672.         return $this;
  673.     }
  674.     /**
  675.      * @return Collection|InvoiceLine[]
  676.      */
  677.     public function getPackChildrens(): Collection
  678.     {
  679.         return $this->packChildrens;
  680.     }
  681.     /**
  682.      * @param InvoiceLine $line
  683.      * @return $this
  684.      */
  685.     public function addPackChildren(InvoiceLine $line): self
  686.     {
  687.         if (!$this->packChildrens->contains($line)) {
  688.             $this->packChildrens[] = $line;
  689.             $line->setPackParent($this);
  690.             if ($line->getInvoice() !== $this->getInvoice()) {
  691.                 $line->setInvoice($this->getInvoice());
  692.             }
  693.         }
  694.         return $this;
  695.     }
  696.     /**
  697.      * @return Invoice|null
  698.      */
  699.     public function getDocument(): ?Invoice
  700.     {
  701.         return $this->getInvoice();
  702.     }
  703.     /**
  704.      * @param Invoice $invoice
  705.      * @return InvoiceLine
  706.      */
  707.     public function duplicate(Invoice $invoice): InvoiceLine
  708.     {
  709.         if ($this->id) {
  710.             $clone = clone $this;
  711.             $clone->setId();
  712.             $clone->setInvoice($invoice);
  713.             $clone->setCreatedAt(new DateTime());
  714.             $clone->setCreatedBy(null);
  715.             $clone->setUpdatedAt(new DateTime());
  716.             $clone->setUpdatedBy(null);
  717.             $clone->childrens = new ArrayCollection();
  718.             foreach ($this->getChildrens() as $children) {
  719.                 $clone_children $children->duplicate($invoice);
  720.                 $clone->addChildren($clone_children);
  721.                 $children->packChildrens = new ArrayCollection();
  722.                 foreach ($children->getPackChildrens() as $packChildren) {
  723.                     $clone_pack_children $packChildren->duplicate($invoice);
  724.                     $children->addPackChildren($clone_pack_children);
  725.                 }
  726.             }
  727.             $clone->packChildrens = new ArrayCollection();
  728.             foreach ($this->getPackChildrens() as $packChildren) {
  729.                 $clone_pack_children $packChildren->duplicate($invoice);
  730.                 $clone->addPackChildren($clone_pack_children);
  731.             }
  732.             return $clone;
  733.         }
  734.         return $this;
  735.     }
  736.     /**
  737.      * @return string|null
  738.      */
  739.     public function getUnitPriceWithDiscount(): ?string
  740.     {
  741.         if ($this->getDocument()->isEditPricesWithTax()) {
  742.             $unitDiscount = (float) ($this->getOptions()['unitDiscount'] ?? 0);
  743.             return (string) ((float) $this->getUnitPriceWithTax() - $unitDiscount);
  744.         } else {
  745.             $unitDiscountUntaxed = (float) ($this->getOptions()['unitDiscountUntaxed'] ?? 0);
  746.             return (string) ((float) $this->getUnitPrice() - $unitDiscountUntaxed);
  747.         }
  748.     }
  749.     /**
  750.      * @return bool
  751.      */
  752.     public function isProduct(): bool
  753.     {
  754.         $options $this->getOptions();
  755.         return !empty($options['product']) && !empty($options['product']['id']);
  756.     }
  757.     /**
  758.      * @return bool
  759.      */
  760.     public function isDeclination(): bool
  761.     {
  762.         return $this->isProduct() && !empty($this->getOptions()['product']['declination_id']);
  763.     }
  764.     /**
  765.      * @return Product|null
  766.      * @throws NonUniqueResultException
  767.      */
  768.     public function getProduct(): ?Product
  769.     {
  770.         if ($this->em && $this->product) {
  771.             SoftdeleteFilter::disable($this->em, [Product::class]);
  772.             $product $this->em->getRepository(Product::class)
  773.                 ->createQueryBuilder('p')
  774.                 ->where('p.id = :productId')
  775.                 ->setParameter('productId'$this->product->getId()->toBinary())
  776.                 ->getQuery()
  777.                 ->getOneOrNullResult();
  778.             SoftdeleteFilter::enable($this->em, [Product::class]);
  779.             return $product;
  780.         }
  781.         return $this->product;
  782.     }
  783.     /**
  784.      * @param Product|null $Product
  785.      * @return $this
  786.      */
  787.     public function setProduct(?Product $Product): self
  788.     {
  789.         $this->product $Product;
  790.         return $this;
  791.     }
  792.     /**
  793.      * @return Declination|null
  794.      * @throws NonUniqueResultException
  795.      */
  796.     public function getDeclination(): ?Declination
  797.     {
  798.         if ($this->em && $this->declination) {
  799.             SoftdeleteFilter::disable($this->em, [Declination::class]);
  800.             $declination $this->em->getRepository(Declination::class)
  801.                 ->createQueryBuilder('d')
  802.                 ->where('d.id = :declinationId')
  803.                 ->setParameter('declinationId'$this->declination->getId()->toBinary())
  804.                 ->getQuery()
  805.                 ->getOneOrNullResult();
  806.             SoftdeleteFilter::enable($this->em, [Declination::class]);
  807.             return $declination;
  808.         }
  809.         return $this->declination;
  810.     }
  811.     /**
  812.      * @param Declination|null $declination
  813.      * @return $this
  814.      */
  815.     public function setDeclination(?Declination $declination): self
  816.     {
  817.         $this->declination $declination;
  818.         return $this;
  819.     }
  820. }