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