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.         public function getId(): ?string
  212.         {
  213.             return $this->id;
  214.         }
  215.         public function getDatetime(): ?\DateTimeInterface
  216.         {
  217.             return $this->datetime;
  218.         }
  219.         public function setDatetime(\DateTimeInterface $datetime): static
  220.         {
  221.             $this->datetime $datetime;
  222.             return $this;
  223.         }
  224.         public function getDatetimeBilling(): ?\DateTimeInterface
  225.         {
  226.             return $this->datetimeBilling;
  227.         }
  228.         public function setDatetimeBilling(?\DateTimeInterface $datetimeBilling): static
  229.         {
  230.             $this->datetimeBilling $datetimeBilling;
  231.             return $this;
  232.         }
  233.         public function getReferent(): ?string
  234.         {
  235.             return $this->referent;
  236.         }
  237.         public function setReferent(?string $referent): static
  238.         {
  239.             $this->referent $referent;
  240.             return $this;
  241.         }
  242.         public function getMotivation(): ?string
  243.         {
  244.             return $this->motivation;
  245.         }
  246.         public function setMotivation(?string $motivation): static
  247.         {
  248.             $this->motivation $motivation;
  249.             return $this;
  250.         }
  251.         public function getPhone(): ?string
  252.         {
  253.             return $this->phone;
  254.         }
  255.         public function setPhone(?string $phone): static
  256.         {
  257.             $this->phone $phone;
  258.             return $this;
  259.         }
  260.         public function getPhotoPath(): ?string
  261.         {
  262.             return $this->photoPath;
  263.         }
  264.         public function setPhotoPath(?string $photoPath): static
  265.         {
  266.             $this->photoPath $photoPath;
  267.             return $this;
  268.         }
  269.         public function getAmount(): ?string
  270.         {
  271.             return $this->amount;
  272.         }
  273.         public function setAmount(?string $amount): static
  274.         {
  275.             $this->amount $amount;
  276.             return $this;
  277.         }
  278.         public function getAmountTechnician(): ?string
  279.         {
  280.             return $this->amountTechnician;
  281.         }
  282.         public function setAmountTechnician(?string $amountTechnician): static
  283.         {
  284.             $this->amountTechnician $amountTechnician;
  285.             return $this;
  286.         }
  287.         public function getSlaOutboundPercentage(): ?int
  288.         {
  289.             return $this->slaOutboundPercentage;
  290.         }
  291.         public function setSlaOutboundPercentage(?int $slaOutboundPercentage): static
  292.         {
  293.             $this->slaOutboundPercentage $slaOutboundPercentage;
  294.             return $this;
  295.         }
  296.         public function isBillable(): ?bool
  297.         {
  298.             return $this->billable;
  299.         }
  300.         public function setBillable(bool $billable): static
  301.         {
  302.             $this->billable $billable;
  303.             return $this;
  304.         }
  305.         public function getSuspension(): ?TicketSuspension
  306.         {
  307.             return $this->suspension;
  308.         }
  309.         public function setSuspension(?TicketSuspension $suspension): static
  310.         {
  311.             // unset the owning side of the relation if necessary
  312.             if ($suspension === null && $this->suspension !== null) {
  313.                 $this->suspension->setIntervention(null);
  314.             }
  315.             // set the owning side of the relation if necessary
  316.             if ($suspension !== null && $suspension->getIntervention() !== $this) {
  317.                 $suspension->setIntervention($this);
  318.             }
  319.             $this->suspension $suspension;
  320.             return $this;
  321.         }
  322.         /**
  323.          * @return Collection<int, InterventionActivity>
  324.          */
  325.         public function getActivities(): Collection
  326.         {
  327.             return $this->activities;
  328.         }
  329.         public function addActivity(InterventionActivity $activity): static
  330.         {
  331.             if (!$this->activities->contains($activity)) {
  332.                 $this->activities->add($activity);
  333.                 $activity->setIntervention($this);
  334.             }
  335.             return $this;
  336.         }
  337.         public function removeActivity(InterventionActivity $activity): static
  338.         {
  339.             if ($this->activities->removeElement($activity)) {
  340.                 // set the owning side to null (unless already changed)
  341.                 if ($activity->getIntervention() === $this) {
  342.                     $activity->setIntervention(null);
  343.                 }
  344.             }
  345.             return $this;
  346.         }
  347.         /**
  348.          * @return Collection<int, InterventionExtra>
  349.          */
  350.         public function getExtras(): Collection
  351.         {
  352.             return $this->extras;
  353.         }
  354.         public function addExtra(InterventionExtra $extra): static
  355.         {
  356.             if (!$this->extras->contains($extra)) {
  357.                 $this->extras->add($extra);
  358.                 $extra->setIntervention($this);
  359.             }
  360.             return $this;
  361.         }
  362.         public function removeExtra(InterventionExtra $extra): static
  363.         {
  364.             if ($this->extras->removeElement($extra)) {
  365.                 // set the owning side to null (unless already changed)
  366.                 if ($extra->getIntervention() === $this) {
  367.                     $extra->setIntervention(null);
  368.                 }
  369.             }
  370.             return $this;
  371.         }
  372.         /**
  373.          * @return Collection<int, ProductLog>
  374.          */
  375.         public function getProductLogs(): Collection
  376.         {
  377.             return $this->productLogs;
  378.         }
  379.         public function addProductLog(ProductLog $productLog): static
  380.         {
  381.             if (!$this->productLogs->contains($productLog)) {
  382.                 $this->productLogs->add($productLog);
  383.                 $productLog->setIntervention($this);
  384.             }
  385.             return $this;
  386.         }
  387.         public function removeProductLog(ProductLog $productLog): static
  388.         {
  389.             if ($this->productLogs->removeElement($productLog)) {
  390.                 // set the owning side to null (unless already changed)
  391.                 if ($productLog->getIntervention() === $this) {
  392.                     $productLog->setIntervention(null);
  393.                 }
  394.             }
  395.             return $this;
  396.         }
  397.         public function getTicket(): ?Ticket
  398.         {
  399.             return $this->ticket;
  400.         }
  401.         public function setTicket(?Ticket $ticket): static
  402.         {
  403.             $this->ticket $ticket;
  404.             return $this;
  405.         }
  406.         public function getTechnician(): ?User
  407.         {
  408.             return $this->technician;
  409.         }
  410.         public function setTechnician(?User $technician): static
  411.         {
  412.             $this->technician $technician;
  413.             return $this;
  414.         }
  415.         public function getOperator(): ?User
  416.         {
  417.             return $this->operator;
  418.         }
  419.         public function setOperator(?User $operator): static
  420.         {
  421.             $this->operator $operator;
  422.             return $this;
  423.         }
  424.         public function getOutcome(): ?InterventionOutcome
  425.         {
  426.             return $this->outcome;
  427.         }
  428.         public function setOutcome(?InterventionOutcome $outcome): static
  429.         {
  430.             $this->outcome $outcome;
  431.             return $this;
  432.         }
  433.         public function getOutcomeType(): ?InterventionOutcomeType
  434.         {
  435.             return $this->outcomeType;
  436.         }
  437.         public function setOutcomeType(?InterventionOutcomeType $outcomeType): static
  438.         {
  439.             $this->outcomeType $outcomeType;
  440.             return $this;
  441.         }
  442.         public function getWarehouse(): ?Warehouse
  443.         {
  444.             return $this->warehouse;
  445.         }
  446.         public function setWarehouse(?Warehouse $warehouse): static
  447.         {
  448.             $this->warehouse $warehouse;
  449.             return $this;
  450.         }
  451. }