src/Entity/Supplier.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\Currency;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(
  10.  *     repositoryClass="App\Repository\SupplierRepository"
  11.  * )
  12.  * @ORM\Table(
  13.  *     name="supplier",
  14.  *     options={"collate"="utf8_swedish_ci"},
  15.  *     uniqueConstraints={
  16.  *         @ORM\UniqueConstraint(
  17.  *             name="supplier_label",
  18.  *             columns={"label"}
  19.  *         )
  20.  *     }
  21.  * )
  22.  * @ORM\HasLifecycleCallbacks
  23.  */
  24. class Supplier implements EntityInterfaceAddressInterface
  25. {
  26.     use AddressTrait;
  27.     use TermsOfDeliveryTrait;
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\Column(
  31.      *     type="integer"
  32.      * )
  33.      * @ORM\GeneratedValue(
  34.      *     strategy="AUTO"
  35.      * )
  36.      *
  37.      * @var int|null
  38.      */
  39.     protected ?int $id null;
  40.     /**
  41.      * @ORM\Column(
  42.      *     type="boolean"
  43.      * )
  44.      *
  45.      * @var bool
  46.      */
  47.     protected bool $active true;
  48.     /**
  49.      * @ORM\Column(
  50.      *     type="string",
  51.      *     length=3
  52.      * )
  53.      * @Assert\NotNull
  54.      * @Assert\Choice(
  55.      *     callback={"\App\Model\Currency", "getCodeChoices"}
  56.      * )
  57.      *
  58.      * @var string
  59.      */
  60.     protected string $currency Currency::DEFAULT_CURRENCY;
  61.     /**
  62.      * @ORM\Column(
  63.      *     type="boolean"
  64.      * )
  65.      *
  66.      * @var bool
  67.      */
  68.     protected bool $grossMarginPurchasesZero false;
  69.     /**
  70.      * @ORM\Column(
  71.      *     type="boolean"
  72.      * )
  73.      *
  74.      * @var bool
  75.      */
  76.     protected bool $inventoryAddress false;
  77.     /**
  78.      * @ORM\Column(
  79.      *     type="boolean"
  80.      * )
  81.      *
  82.      * @var bool
  83.      */
  84.     protected bool $inventoryTransactions false;
  85.     /**
  86.      * @ORM\Column(
  87.      *     type="string",
  88.      *     length=20,
  89.      *     nullable=true
  90.      * )
  91.      *
  92.      * @var string|null
  93.      */
  94.     protected ?string $label null;
  95.     /**
  96.      * @ORM\Column(
  97.      *     type="string",
  98.      *     length=500
  99.      * )
  100.      *
  101.      * @var string
  102.      */
  103.     protected string $name;
  104.     /**
  105.      * @ORM\OneToMany(
  106.      *     targetEntity="Product",
  107.      *     mappedBy="supplier",
  108.      *     cascade={"persist"}
  109.      * )
  110.      * @orm\OrderBy({"code" = "ASC"})
  111.      *
  112.      * @var Collection<Product>
  113.      */
  114.     protected Collection $products;
  115.     /**
  116.      * @ORM\OneToMany(
  117.      *     targetEntity="PurchaseOrder",
  118.      *     mappedBy="supplier",
  119.      *     cascade={"persist"}
  120.      * )
  121.      *
  122.      * @var Collection<PurchaseOrder>
  123.      */
  124.     protected Collection $purchaseOrders;
  125.     /**
  126.      * @ORM\OneToMany(
  127.      *     targetEntity="SalesItem",
  128.      *     mappedBy="supplier",
  129.      *     cascade={"persist","remove"}
  130.      * )
  131.      *
  132.      * @var Collection<SalesItem>
  133.      */
  134.     protected Collection $salesItems;
  135.     /**
  136.      * @ORM\ManyToMany(
  137.      *     targetEntity="TermsOfPaymentRow",
  138.      *     cascade={"persist","remove"},
  139.      *     orphanRemoval=true
  140.      * )
  141.      * @ORM\JoinTable(
  142.      *     name="supplier_terms_of_payment_row",
  143.      *     joinColumns={
  144.      *         @ORM\JoinColumn(
  145.      *             name="supplier_id",
  146.      *             referencedColumnName="id",
  147.      *             onDelete="cascade"
  148.      *         )
  149.      *     },
  150.      *     inverseJoinColumns={
  151.      *         @ORM\JoinColumn(
  152.      *             name="terms_of_payment_row_id",
  153.      *             referencedColumnName="id",
  154.      *             unique=true,
  155.      *             onDelete="cascade"
  156.      *         )
  157.      *     }
  158.      * )
  159.      *
  160.      * @Assert\Valid
  161.      *
  162.      * @var Collection<TermsOfPaymentRow>
  163.      */
  164.     protected Collection $termsOfPaymentRows;
  165.     /**
  166.      * @param string $name
  167.      */
  168.     public function __construct(string $name)
  169.     {
  170.         $this->name $name;
  171.         $this->products = new ArrayCollection();
  172.         $this->purchaseOrders = new ArrayCollection();
  173.         $this->salesItems = new ArrayCollection();
  174.         $this->termsOfPaymentRows = new ArrayCollection();
  175.     }
  176.     /**
  177.      * @return string
  178.      */
  179.     public function __toString(): string
  180.     {
  181.         return $this->getName();
  182.     }
  183.     /**
  184.      * @param TermsOfPaymentRow $row
  185.      */
  186.     public function addTermsOfPaymentRow(TermsOfPaymentRow $row): void
  187.     {
  188.         $this->termsOfPaymentRows->add($row);
  189.     }
  190.     /**
  191.      * @return string
  192.      */
  193.     public function getCurrency(): string
  194.     {
  195.         return $this->currency;
  196.     }
  197.     /**
  198.      * @return int|null
  199.      */
  200.     public function getId(): ?int
  201.     {
  202.         return $this->id;
  203.     }
  204.     /**
  205.      * @return null|string
  206.      */
  207.     public function getLabel(): ?string
  208.     {
  209.         return $this->label;
  210.     }
  211.     /**
  212.      * @return Collection<PurchaseOrder>
  213.      */
  214.     public function getPurchaseOrders(): Collection
  215.     {
  216.         return $this->purchaseOrders;
  217.     }
  218.     /**
  219.      * @return Collection<SalesItem>
  220.      */
  221.     public function getSalesItems(): Collection
  222.     {
  223.         return $this->salesItems;
  224.     }
  225.     /**
  226.      * @return Collection<TermsOfPaymentRow>
  227.      */
  228.     public function getTermsOfPaymentRows(): Collection
  229.     {
  230.         return $this->termsOfPaymentRows;
  231.     }
  232.     /**
  233.      * @return bool
  234.      */
  235.     public function isActive(): bool
  236.     {
  237.         return $this->active;
  238.     }
  239.     /**
  240.      * @return bool
  241.      */
  242.     public function isGrossMarginPurchasesZero(): bool
  243.     {
  244.         return $this->grossMarginPurchasesZero;
  245.     }
  246.     /**
  247.      * @return bool
  248.      */
  249.     public function isInventoryAddress(): bool
  250.     {
  251.         return $this->inventoryAddress;
  252.     }
  253.     /**
  254.      * @return bool
  255.      */
  256.     public function isInventoryTransactions(): bool
  257.     {
  258.         return $this->inventoryTransactions;
  259.     }
  260.     /**
  261.      * @param TermsOfPaymentRow $row
  262.      */
  263.     public function removeTermsOfPaymentRow(TermsOfPaymentRow $row): void
  264.     {
  265.         $this->termsOfPaymentRows?->removeElement($row);
  266.     }
  267.     /**
  268.      * @param bool $active
  269.      */
  270.     public function setActive(bool $active): void
  271.     {
  272.         $this->active $active;
  273.     }
  274.     /**
  275.      * @param string $currency
  276.      */
  277.     public function setCurrency(string $currency): void
  278.     {
  279.         $this->currency $currency;
  280.     }
  281.     /**
  282.      * @param bool $grossMarginPurchasesZero
  283.      */
  284.     public function setGrossMarginPurchasesZero(bool $grossMarginPurchasesZero): void
  285.     {
  286.         $this->grossMarginPurchasesZero $grossMarginPurchasesZero;
  287.     }
  288.     /**
  289.      * @param bool $inventoryAddress
  290.      */
  291.     public function setInventoryAddress(bool $inventoryAddress): void
  292.     {
  293.         $this->inventoryAddress $inventoryAddress;
  294.     }
  295.     /**
  296.      * @param bool $inventoryTransactions
  297.      */
  298.     public function setInventoryTransactions(bool $inventoryTransactions): void
  299.     {
  300.         $this->inventoryTransactions $inventoryTransactions;
  301.     }
  302.     /**
  303.      * @param string|null $label
  304.      */
  305.     public function setLabel(?string $label): void
  306.     {
  307.         $this->label $label;
  308.     }
  309. }