src/Entity/Slave/Intervention.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Slave;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="eposm_s_intervention")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Slave\InterventionRepository")
  10.  */
  11. class Intervention
  12. {    
  13.     public function __toString(){
  14.         if($this->getOutcome() != null)
  15.             return $this->getOutcome()->getValue().' il '.$this->getDatetime()->format('d-m-Y H:i');
  16.         else
  17.             return 'Intervento incompleto';
  18.     }
  19.     public function calculateTotalTechnicianAmount()
  20.     {
  21.         return floatval($this->calculateTechnicianAmount()) + floatval($this->calculateExtraAmount());
  22.     }
  23.     
  24.     public function calculateTechnicianAmount()
  25.     {
  26.         $total 0;
  27.         if($this->getAmountTechnician() != '0.00')
  28.             $total floatval($this->getAmountTechnician());
  29.         else{
  30.             foreach($this->getExtras() as $extra){
  31.                 if($extra->isTariffOut() && $extra->isApproved())
  32.                     return $extra->getCost();
  33.             }
  34.         }
  35.         if($this->getSlaOutboundPercentage() != null){
  36.             $sla = ($total 100 $this->getSlaOutboundPercentage());
  37.             $total $total $sla;
  38.         }
  39.         return $total;
  40.     }
  41.     
  42.     public function calculateExtraAmount()
  43.     {
  44.         $totalExtra 0;
  45.         foreach($this->getExtras() as $extra){
  46.             if($extra->isApproved() && !$extra->isTariffOut())
  47.                 $totalExtra += floatval($extra->getCost());
  48.         }        
  49.         return floatval($totalExtra);
  50.     }
  51.     
  52.     public function takeAllExtraAmount()
  53.     {
  54.         $totalExtra 0;
  55.         foreach($this->getExtras() as $extra){
  56.             $totalExtra += floatval($extra->getCost());
  57.         }
  58.         return floatval($totalExtra);
  59.     }
  60.     
  61.     public function takeAllExtraNotBillableAmount()
  62.     {
  63.         $totalExtra 0;
  64.         foreach($this->getExtras() as $extra){
  65.             if(!$extra->isApproved())
  66.                 $totalExtra += floatval($extra->getCost());
  67.         }
  68.         return floatval($totalExtra);
  69.     }
  70.     public function getLastProductLog($type)
  71.     {
  72.         $log null;
  73.         $oldDatetime date_create_from_format('Ymd''20000101');
  74.         foreach($this->getProductLogs() as $pl){
  75.             if($pl->getType() == $type && $pl->getDatetime()->format('YmdHi') > $oldDatetime->format('YmdHi')){
  76.                 $oldDatetime $pl->getDatetime();
  77.                 $log $pl;
  78.             }
  79.         }
  80.         return $log;
  81.     }
  82.     public function hasExtras(){
  83.         if(sizeof($this->getExtras()) > 0)
  84.             return true;
  85.         return false;
  86.     }
  87.     public function displayExtras(){
  88.         $string "";
  89.         if(sizeof($this->getExtras()) > 0){
  90.             foreach($this->extras as $extra){
  91.                 $string.= $extra->displayResume()."</br>";
  92.             }
  93.         }
  94.         return $string;
  95.     }
  96.     /**
  97.      * @ORM\Column(name="id", type="bigint")
  98.      * @ORM\Id
  99.      * @ORM\GeneratedValue(strategy="AUTO")
  100.      */
  101.     protected $id;
  102.     
  103.     /**
  104.      * @ORM\Column(name="datetime", type="datetime")
  105.      */
  106.     protected $datetime;
  107.     /**
  108.      * @ORM\Column(name="datetime_billing", type="datetime", nullable=true)
  109.      */
  110.     protected $datetimeBilling;
  111.     
  112.     /**
  113.      * @ORM\Column(name="referent", type="string", length=191, nullable=true)
  114.      */
  115.     protected $referent;
  116.     
  117.     /**
  118.      * @ORM\Column(name="motivation", type="text", nullable=true)
  119.      */
  120.     protected $motivation;
  121.     
  122.     /**
  123.      * @ORM\Column(name="phone", type="string", length=191, nullable=true)
  124.      */
  125.     protected $phone;
  126.     
  127.     /**
  128.      * @ORM\Column(name="photo_path", type="string", length=191, nullable=true)
  129.      */
  130.     protected $photoPath;
  131.     /**
  132.      * @ORM\Column(name="amount", type="decimal", scale=2, nullable=true)
  133.      */
  134.     protected $amount;
  135.     
  136.     /**
  137.      * @ORM\Column(name="amount_technician", type="decimal", scale=2, nullable=true)
  138.      */
  139.     protected $amountTechnician;
  140.     
  141.     /**
  142.      * @ORM\Column(name="sla_outbound_percentage", type="integer", nullable=true)
  143.      */
  144.     protected $slaOutboundPercentage;
  145.     /**
  146.      * @ORM\Column(name="billable", type="boolean")
  147.      */
  148.     protected $billable true;
  149.     // OneToOne
  150.         /**
  151.         * @ORM\OneToOne(targetEntity="App\Entity\Slave\TicketSuspension", mappedBy="intervention")
  152.         */
  153.         private $suspension;
  154.     //
  155.     
  156.     // OneToMany
  157.         /**
  158.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionActivity", mappedBy="intervention")
  159.          */
  160.         private $activities;
  161.         
  162.         /**
  163.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionExtra", mappedBy="intervention")
  164.          */
  165.         private $extras;
  166.         
  167.         /**
  168.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductLog", mappedBy="intervention")
  169.          */
  170.         private $productLogs;
  171.     //
  172.     
  173.     // ManyToOne
  174.         /**
  175.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Ticket", inversedBy="interventions")
  176.          * @ORM\JoinColumn(name="ticket_id", referencedColumnName="id")
  177.          */
  178.         private $ticket;
  179.         /**
  180.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="interventions")
  181.          * @ORM\JoinColumn(name="technician_id", referencedColumnName="id")
  182.          */
  183.         private $technician;
  184.         
  185.         /**
  186.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="operatorInterventions")
  187.          * @ORM\JoinColumn(name="operator_id", referencedColumnName="id")
  188.          */
  189.         private $operator;
  190.         /**
  191.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcome", inversedBy="interventions")
  192.          * @ORM\JoinColumn(name="outcome_id", referencedColumnName="id")
  193.          */
  194.         private $outcome;
  195.         /**
  196.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcomeType", inversedBy="interventions")
  197.          * @ORM\JoinColumn(name="outcome_type_id", referencedColumnName="id")
  198.          */
  199.         private $outcomeType;
  200.         /**
  201.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="interventions")
  202.          * @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id")
  203.          */
  204.         private $warehouse;
  205.         public function __construct()
  206.         {
  207.             $this->activities = new ArrayCollection();
  208.             $this->extras = new ArrayCollection();
  209.             $this->productLogs = new ArrayCollection();
  210.         }
  211.     //
  212.     public function getId(): ?string
  213.     {
  214.         return $this->id;
  215.     }
  216.     public function getDatetime(): ?\DateTimeInterface
  217.     {
  218.         return $this->datetime;
  219.     }
  220.     public function setDatetime(\DateTimeInterface $datetime): static
  221.     {
  222.         $this->datetime $datetime;
  223.         return $this;
  224.     }
  225.     public function getDatetimeBilling(): ?\DateTimeInterface
  226.     {
  227.         return $this->datetimeBilling;
  228.     }
  229.     public function setDatetimeBilling(\DateTimeInterface $datetimeBilling): static
  230.     {
  231.         $this->datetimeBilling $datetimeBilling;
  232.         return $this;
  233.     }
  234.     public function getReferent(): ?string
  235.     {
  236.         return $this->referent;
  237.     }
  238.     public function setReferent(?string $referent): static
  239.     {
  240.         $this->referent $referent;
  241.         return $this;
  242.     }
  243.     public function getMotivation(): ?string
  244.     {
  245.         return $this->motivation;
  246.     }
  247.     public function setMotivation(?string $motivation): static
  248.     {
  249.         $this->motivation $motivation;
  250.         return $this;
  251.     }
  252.     public function getPhone(): ?string
  253.     {
  254.         return $this->phone;
  255.     }
  256.     public function setPhone(?string $phone): static
  257.     {
  258.         $this->phone $phone;
  259.         return $this;
  260.     }
  261.     public function getPhotoPath(): ?string
  262.     {
  263.         return $this->photoPath;
  264.     }
  265.     public function setPhotoPath(?string $photoPath): static
  266.     {
  267.         $this->photoPath $photoPath;
  268.         return $this;
  269.     }
  270.     public function getAmount(): ?string
  271.     {
  272.         return $this->amount;
  273.     }
  274.     public function setAmount(?string $amount): static
  275.     {
  276.         $this->amount $amount;
  277.         return $this;
  278.     }
  279.     public function getAmountTechnician(): ?string
  280.     {
  281.         return $this->amountTechnician;
  282.     }
  283.     public function setAmountTechnician(?string $amountTechnician): static
  284.     {
  285.         $this->amountTechnician $amountTechnician;
  286.         return $this;
  287.     }
  288.     public function getSlaOutboundPercentage(): ?int
  289.     {
  290.         return $this->slaOutboundPercentage;
  291.     }
  292.     public function setSlaOutboundPercentage(?int $slaOutboundPercentage): static
  293.     {
  294.         $this->slaOutboundPercentage $slaOutboundPercentage;
  295.         return $this;
  296.     }
  297.     public function isBillable(): ?bool
  298.     {
  299.         return $this->billable;
  300.     }
  301.     public function setBillable(bool $billable): static
  302.     {
  303.         $this->billable $billable;
  304.         return $this;
  305.     }
  306.     public function getSuspension(): ?TicketSuspension
  307.     {
  308.         return $this->suspension;
  309.     }
  310.     public function setSuspension(?TicketSuspension $suspension): static
  311.     {
  312.         // unset the owning side of the relation if necessary
  313.         if ($suspension === null && $this->suspension !== null) {
  314.             $this->suspension->setIntervention(null);
  315.         }
  316.         // set the owning side of the relation if necessary
  317.         if ($suspension !== null && $suspension->getIntervention() !== $this) {
  318.             $suspension->setIntervention($this);
  319.         }
  320.         $this->suspension $suspension;
  321.         return $this;
  322.     }
  323.     /**
  324.      * @return Collection<int, InterventionActivity>
  325.      */
  326.     public function getActivities(): Collection
  327.     {
  328.         return $this->activities;
  329.     }
  330.     public function addActivity(InterventionActivity $activity): static
  331.     {
  332.         if (!$this->activities->contains($activity)) {
  333.             $this->activities->add($activity);
  334.             $activity->setIntervention($this);
  335.         }
  336.         return $this;
  337.     }
  338.     public function removeActivity(InterventionActivity $activity): static
  339.     {
  340.         if ($this->activities->removeElement($activity)) {
  341.             // set the owning side to null (unless already changed)
  342.             if ($activity->getIntervention() === $this) {
  343.                 $activity->setIntervention(null);
  344.             }
  345.         }
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return Collection<int, InterventionExtra>
  350.      */
  351.     public function getExtras(): Collection
  352.     {
  353.         return $this->extras;
  354.     }
  355.     public function addExtra(InterventionExtra $extra): static
  356.     {
  357.         if (!$this->extras->contains($extra)) {
  358.             $this->extras->add($extra);
  359.             $extra->setIntervention($this);
  360.         }
  361.         return $this;
  362.     }
  363.     public function removeExtra(InterventionExtra $extra): static
  364.     {
  365.         if ($this->extras->removeElement($extra)) {
  366.             // set the owning side to null (unless already changed)
  367.             if ($extra->getIntervention() === $this) {
  368.                 $extra->setIntervention(null);
  369.             }
  370.         }
  371.         return $this;
  372.     }
  373.     /**
  374.      * @return Collection<int, ProductLog>
  375.      */
  376.     public function getProductLogs(): Collection
  377.     {
  378.         return $this->productLogs;
  379.     }
  380.     public function addProductLog(ProductLog $productLog): static
  381.     {
  382.         if (!$this->productLogs->contains($productLog)) {
  383.             $this->productLogs->add($productLog);
  384.             $productLog->setIntervention($this);
  385.         }
  386.         return $this;
  387.     }
  388.     public function removeProductLog(ProductLog $productLog): static
  389.     {
  390.         if ($this->productLogs->removeElement($productLog)) {
  391.             // set the owning side to null (unless already changed)
  392.             if ($productLog->getIntervention() === $this) {
  393.                 $productLog->setIntervention(null);
  394.             }
  395.         }
  396.         return $this;
  397.     }
  398.     public function getTicket(): ?Ticket
  399.     {
  400.         return $this->ticket;
  401.     }
  402.     public function setTicket(?Ticket $ticket): static
  403.     {
  404.         $this->ticket $ticket;
  405.         return $this;
  406.     }
  407.     public function getTechnician(): ?User
  408.     {
  409.         return $this->technician;
  410.     }
  411.     public function setTechnician(?User $technician): static
  412.     {
  413.         $this->technician $technician;
  414.         return $this;
  415.     }
  416.     public function getOperator(): ?User
  417.     {
  418.         return $this->operator;
  419.     }
  420.     public function setOperator(?User $operator): static
  421.     {
  422.         $this->operator $operator;
  423.         return $this;
  424.     }
  425.     public function getOutcome(): ?InterventionOutcome
  426.     {
  427.         return $this->outcome;
  428.     }
  429.     public function setOutcome(?InterventionOutcome $outcome): static
  430.     {
  431.         $this->outcome $outcome;
  432.         return $this;
  433.     }
  434.     public function getOutcomeType(): ?InterventionOutcomeType
  435.     {
  436.         return $this->outcomeType;
  437.     }
  438.     public function setOutcomeType(?InterventionOutcomeType $outcomeType): static
  439.     {
  440.         $this->outcomeType $outcomeType;
  441.         return $this;
  442.     }
  443.     public function getWarehouse(): ?Warehouse
  444.     {
  445.         return $this->warehouse;
  446.     }
  447.     public function setWarehouse(?Warehouse $warehouse): static
  448.     {
  449.         $this->warehouse $warehouse;
  450.         return $this;
  451.     }
  452. }