src/Entity/MaterialRequest.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MaterialRequestRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * MaterialRequest — in-house (execution_scope=internal) production task'inda, task'i
  10.  * ustlenen responsible person'in (TaskExecution.branch_contact_person) actigi malzeme
  11.  * siparis talebi. Talebe birden fazla PDF (MaterialRequestDocument) eklenir; bir
  12.  * TaskExecution icin birden fazla talep acilabilir (bu yuzden ManyToOne, OneToOne DEGIL).
  13.  *
  14.  * Sistem PDF'i PARSE ETMEZ. Durum PDF'lerden TURER (recomputeStatusFromDocuments,
  15.  * upsertV2 deseni: BE hesaplar, PERSIST eder — bkz. TaskExecutionService::recomputeDerivedFieldsFromJobs).
  16.  *
  17.  * @ORM\Entity(repositoryClass=MaterialRequestRepository::class)
  18.  * @ORM\HasLifecycleCallbacks
  19.  */
  20. class MaterialRequest
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      * @Groups({
  27.      *     "material_request@ref",
  28.      *     "material_request@base",
  29.      *     "material_request@core"
  30.      * })
  31.      */
  32.     private $id;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity=ProjectOrderTaskFulfillment::class)
  35.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  36.      * @Groups({
  37.      *     "material_request@task_execution"
  38.      * })
  39.      */
  40.     private $task_execution;
  41.     /**
  42.      * Talebi acan kisi — in-house execution'in responsible person'i
  43.      * (TaskExecution.branch_contact_person ile ayni WorkerActivities).
  44.      * @ORM\ManyToOne(targetEntity=WorkerActivities::class)
  45.      * @ORM\JoinColumn(nullable=false)
  46.      * @Groups({
  47.      *     "material_request@requester"
  48.      * })
  49.      */
  50.     private $requester;
  51.     /**
  52.      * Default'un TEK kaynagi burasi (property default) — Doctrine Type sadece gecerli
  53.      * degerleri dogrular, varsayilan atamaz.
  54.      * @ORM\Column(type="material_request_status", nullable=false, options={"default": "draft"})
  55.      * @Groups({
  56.      *     "material_request@base",
  57.      *     "material_request@core"
  58.      * })
  59.      */
  60.     private $status = 'draft';
  61.     /**
  62.      * Kararı veren Expenses sorumlusu — ilk/son karar aninda set edilir.
  63.      * @ORM\ManyToOne(targetEntity=WorkerActivities::class)
  64.      * @ORM\JoinColumn(nullable=true)
  65.      * @Groups({
  66.      *     "material_request@reviewer"
  67.      * })
  68.      */
  69.     private $reviewer;
  70.     /**
  71.      * @ORM\Column(type="datetime_immutable", nullable=true)
  72.      * @Groups({
  73.      *     "material_request@core"
  74.      * })
  75.      */
  76.     private $submitted_at;
  77.     /**
  78.      * @ORM\Column(type="datetime_immutable", nullable=true)
  79.      * @Groups({
  80.      *     "material_request@core"
  81.      * })
  82.      */
  83.     private $reviewed_at;
  84.     /**
  85.      * Talep sahibine EN SON ne zaman karar bildirimi e-postasi gonderildi.
  86.      *
  87.      * Neden tutuluyor: karar maili KAYIT BASINA tek ozet gidiyor (kullanici karari
  88.      * 2026-08-20). Ayni talebe sonradan tekrar karar verilirse ERP "bu talep icin
  89.      * daha once mail gitmisti, tekrar gondermek ister misin?" diye SORAR. O soruyu
  90.      * sorabilmek icin "gonderildi mi" bilgisinin kalici olmasi gerekiyor — aksi
  91.      * halde her kayitta sessizce mail giderdi ve kullanicinin dedigi gibi
  92.      * "sinir bozucu" olurdu.
  93.      *
  94.      * NULL = bu talep icin hic karar bildirimi gonderilmedi.
  95.      *
  96.      * 🪤 `reviewed_at` ILE KARISTIRMA: o KARARIN ne zaman verildigini soyler,
  97.      *    bu ise BILDIRIMIN ne zaman gonderildigini. Ikisi ayri olaydir; karar
  98.      *    verilip mail gonderilmemis olabilir (kullanici "gonderme" der).
  99.      *
  100.      * @ORM\Column(type="datetime_immutable", nullable=true)
  101.      * @Groups({
  102.      *     "material_request@core"
  103.      * })
  104.      */
  105.     private $last_decision_mail_at;
  106.     /**
  107.      * @ORM\Column(type="datetime_immutable", nullable=false)
  108.      * @Groups({
  109.      *     "material_request@core"
  110.      * })
  111.      */
  112.     private $created_at;
  113.     /**
  114.      * @ORM\OneToMany(targetEntity=MaterialRequestDocument::class, mappedBy="material_request", cascade={"persist"}, orphanRemoval=true)
  115.      * @Groups({
  116.      *     "material_request@documents"
  117.      * })
  118.      */
  119.     private $documents;
  120.     public function __construct()
  121.     {
  122.         $this->documents = new ArrayCollection();
  123.     }
  124.     /**
  125.      * @ORM\PrePersist
  126.      */
  127.     public function onPrePersist(): void
  128.     {
  129.         if ($this->created_at === null) {
  130.             $this->created_at = new \DateTimeImmutable();
  131.         }
  132.     }
  133.     public function getId(): ?int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function getTaskExecution(): ?ProjectOrderTaskFulfillment
  138.     {
  139.         return $this->task_execution;
  140.     }
  141.     public function setTaskExecution(?ProjectOrderTaskFulfillment $task_execution): self
  142.     {
  143.         $this->task_execution = $task_execution;
  144.         return $this;
  145.     }
  146.     public function getRequester(): ?WorkerActivities
  147.     {
  148.         return $this->requester;
  149.     }
  150.     public function setRequester(?WorkerActivities $requester): self
  151.     {
  152.         $this->requester = $requester;
  153.         return $this;
  154.     }
  155.     public function getStatus(): ?string
  156.     {
  157.         return $this->status;
  158.     }
  159.     public function setStatus(string $status): self
  160.     {
  161.         $this->status = $status;
  162.         return $this;
  163.     }
  164.     public function getReviewer(): ?WorkerActivities
  165.     {
  166.         return $this->reviewer;
  167.     }
  168.     public function setReviewer(?WorkerActivities $reviewer): self
  169.     {
  170.         $this->reviewer = $reviewer;
  171.         return $this;
  172.     }
  173.     public function getSubmittedAt(): ?\DateTimeImmutable
  174.     {
  175.         return $this->submitted_at;
  176.     }
  177.     public function getLastDecisionMailAt(): ?\DateTimeImmutable
  178.     {
  179.         return $this->last_decision_mail_at;
  180.     }
  181.     public function setLastDecisionMailAt(?\DateTimeImmutable $last_decision_mail_at): self
  182.     {
  183.         $this->last_decision_mail_at = $last_decision_mail_at;
  184.         return $this;
  185.     }
  186.     public function setSubmittedAt(?\DateTimeImmutable $submitted_at): self
  187.     {
  188.         $this->submitted_at = $submitted_at;
  189.         return $this;
  190.     }
  191.     public function getReviewedAt(): ?\DateTimeImmutable
  192.     {
  193.         return $this->reviewed_at;
  194.     }
  195.     public function setReviewedAt(?\DateTimeImmutable $reviewed_at): self
  196.     {
  197.         $this->reviewed_at = $reviewed_at;
  198.         return $this;
  199.     }
  200.     public function getCreatedAt(): ?\DateTimeImmutable
  201.     {
  202.         return $this->created_at;
  203.     }
  204.     public function setCreatedAt(?\DateTimeImmutable $created_at): self
  205.     {
  206.         $this->created_at = $created_at;
  207.         return $this;
  208.     }
  209.     /**
  210.      * @return Collection<int, MaterialRequestDocument>
  211.      */
  212.     public function getDocuments(): Collection
  213.     {
  214.         return $this->documents;
  215.     }
  216.     public function addDocument(MaterialRequestDocument $document): self
  217.     {
  218.         if (!$this->documents->contains($document)) {
  219.             $this->documents[] = $document;
  220.             $document->setMaterialRequest($this);
  221.         }
  222.         return $this;
  223.     }
  224.     public function removeDocument(MaterialRequestDocument $document): self
  225.     {
  226.         if ($this->documents->removeElement($document)) {
  227.             if ($document->getMaterialRequest() === $this) {
  228.                 $document->setMaterialRequest(null);
  229.             }
  230.         }
  231.         return $this;
  232.     }
  233. }