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