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->calculateExtraCost());
  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.             $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.     /**
  124.      * @ORM\Column(name="id", type="bigint")
  125.      * @ORM\Id
  126.      * @ORM\GeneratedValue(strategy="AUTO")
  127.      */
  128.     protected $id;
  129.     
  130.     /**
  131.      * @ORM\Column(name="datetime", type="datetime")
  132.      */
  133.     protected $datetime;
  134.     /**
  135.      * @ORM\Column(name="datetime_billing", type="datetime", nullable=true)
  136.      */
  137.     protected $datetimeBilling;
  138.     
  139.     /**
  140.      * @ORM\Column(name="referent", type="string", length=191, nullable=true)
  141.      */
  142.     protected $referent;
  143.     
  144.     /**
  145.      * @ORM\Column(name="motivation", type="text", nullable=true)
  146.      */
  147.     protected $motivation;
  148.     
  149.     /**
  150.      * @ORM\Column(name="phone", type="string", length=191, nullable=true)
  151.      */
  152.     protected $phone;
  153.     
  154.     /**
  155.      * @ORM\Column(name="photo_path", type="string", length=191, nullable=true)
  156.      */
  157.     protected $photoPath;
  158.     /**
  159.      * @ORM\Column(name="amount", type="decimal", scale=2, nullable=true)
  160.      */
  161.     protected $amount;
  162.     
  163.     /**
  164.      * @ORM\Column(name="amount_technician", type="decimal", scale=2, nullable=true)
  165.      */
  166.     protected $amountTechnician;
  167.     
  168.     /**
  169.      * @ORM\Column(name="sla_outbound_percentage", type="integer", nullable=true)
  170.      */
  171.     protected $slaOutboundPercentage;
  172.     /**
  173.      * @ORM\Column(name="billable", type="boolean")
  174.      */
  175.     protected $billable true;
  176.     // OneToOne
  177.         /**
  178.         * @ORM\OneToOne(targetEntity="App\Entity\Slave\TicketSuspension", mappedBy="intervention")
  179.         */
  180.         private $suspension;
  181.     //
  182.     
  183.     // OneToMany
  184.         /**
  185.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionActivity", mappedBy="intervention")
  186.          */
  187.         private $activities;
  188.         
  189.         /**
  190.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionExtra", mappedBy="intervention")
  191.          */
  192.         private $extras;
  193.         
  194.         /**
  195.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductLog", mappedBy="intervention")
  196.          */
  197.         private $productLogs;
  198.     //
  199.     
  200.     // ManyToOne
  201.         /**
  202.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Ticket", inversedBy="interventions")
  203.          * @ORM\JoinColumn(name="ticket_id", referencedColumnName="id")
  204.          */
  205.         private $ticket;
  206.         /**
  207.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="interventions")
  208.          * @ORM\JoinColumn(name="technician_id", referencedColumnName="id")
  209.          */
  210.         private $technician;
  211.         
  212.         /**
  213.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="operatorInterventions")
  214.          * @ORM\JoinColumn(name="operator_id", referencedColumnName="id")
  215.          */
  216.         private $operator;
  217.         /**
  218.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcome", inversedBy="interventions")
  219.          * @ORM\JoinColumn(name="outcome_id", referencedColumnName="id")
  220.          */
  221.         private $outcome;
  222.         /**
  223.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcomeType", inversedBy="interventions")
  224.          * @ORM\JoinColumn(name="outcome_type_id", referencedColumnName="id")
  225.          */
  226.         private $outcomeType;
  227.         /**
  228.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="interventions")
  229.          * @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id")
  230.          */
  231.         private $warehouse;
  232.         public function __construct()
  233.         {
  234.             $this->activities = new ArrayCollection();
  235.             $this->extras = new ArrayCollection();
  236.             $this->productLogs = new ArrayCollection();
  237.         }
  238.         public function getId(): ?string
  239.         {
  240.             return $this->id;
  241.         }
  242.         public function getDatetime(): ?\DateTimeInterface
  243.         {
  244.             return $this->datetime;
  245.         }
  246.         public function setDatetime(\DateTimeInterface $datetime): static
  247.         {
  248.             $this->datetime $datetime;
  249.             return $this;
  250.         }
  251.         public function getDatetimeBilling(): ?\DateTimeInterface
  252.         {
  253.             return $this->datetimeBilling;
  254.         }
  255.         public function setDatetimeBilling(?\DateTimeInterface $datetimeBilling): static
  256.         {
  257.             $this->datetimeBilling $datetimeBilling;
  258.             return $this;
  259.         }
  260.         public function getReferent(): ?string
  261.         {
  262.             return $this->referent;
  263.         }
  264.         public function setReferent(?string $referent): static
  265.         {
  266.             $this->referent $referent;
  267.             return $this;
  268.         }
  269.         public function getMotivation(): ?string
  270.         {
  271.             return $this->motivation;
  272.         }
  273.         public function setMotivation(?string $motivation): static
  274.         {
  275.             $this->motivation $motivation;
  276.             return $this;
  277.         }
  278.         public function getPhone(): ?string
  279.         {
  280.             return $this->phone;
  281.         }
  282.         public function setPhone(?string $phone): static
  283.         {
  284.             $this->phone $phone;
  285.             return $this;
  286.         }
  287.         public function getPhotoPath(): ?string
  288.         {
  289.             return $this->photoPath;
  290.         }
  291.         public function setPhotoPath(?string $photoPath): static
  292.         {
  293.             $this->photoPath $photoPath;
  294.             return $this;
  295.         }
  296.         public function getAmount(): ?string
  297.         {
  298.             return $this->amount;
  299.         }
  300.         public function setAmount(?string $amount): static
  301.         {
  302.             $this->amount $amount;
  303.             return $this;
  304.         }
  305.         public function getAmountTechnician(): ?string
  306.         {
  307.             return $this->amountTechnician;
  308.         }
  309.         public function setAmountTechnician(?string $amountTechnician): static
  310.         {
  311.             $this->amountTechnician $amountTechnician;
  312.             return $this;
  313.         }
  314.         public function getSlaOutboundPercentage(): ?int
  315.         {
  316.             return $this->slaOutboundPercentage;
  317.         }
  318.         public function setSlaOutboundPercentage(?int $slaOutboundPercentage): static
  319.         {
  320.             $this->slaOutboundPercentage $slaOutboundPercentage;
  321.             return $this;
  322.         }
  323.         public function isBillable(): ?bool
  324.         {
  325.             return $this->billable;
  326.         }
  327.         public function setBillable(bool $billable): static
  328.         {
  329.             $this->billable $billable;
  330.             return $this;
  331.         }
  332.         public function getSuspension(): ?TicketSuspension
  333.         {
  334.             return $this->suspension;
  335.         }
  336.         public function setSuspension(?TicketSuspension $suspension): static
  337.         {
  338.             // unset the owning side of the relation if necessary
  339.             if ($suspension === null && $this->suspension !== null) {
  340.                 $this->suspension->setIntervention(null);
  341.             }
  342.             // set the owning side of the relation if necessary
  343.             if ($suspension !== null && $suspension->getIntervention() !== $this) {
  344.                 $suspension->setIntervention($this);
  345.             }
  346.             $this->suspension $suspension;
  347.             return $this;
  348.         }
  349.         /**
  350.          * @return Collection<int, InterventionActivity>
  351.          */
  352.         public function getActivities(): Collection
  353.         {
  354.             return $this->activities;
  355.         }
  356.         public function addActivity(InterventionActivity $activity): static
  357.         {
  358.             if (!$this->activities->contains($activity)) {
  359.                 $this->activities->add($activity);
  360.                 $activity->setIntervention($this);
  361.             }
  362.             return $this;
  363.         }
  364.         public function removeActivity(InterventionActivity $activity): static
  365.         {
  366.             if ($this->activities->removeElement($activity)) {
  367.                 // set the owning side to null (unless already changed)
  368.                 if ($activity->getIntervention() === $this) {
  369.                     $activity->setIntervention(null);
  370.                 }
  371.             }
  372.             return $this;
  373.         }
  374.         /**
  375.          * @return Collection<int, InterventionExtra>
  376.          */
  377.         public function getExtras(): Collection
  378.         {
  379.             return $this->extras;
  380.         }
  381.         public function addExtra(InterventionExtra $extra): static
  382.         {
  383.             if (!$this->extras->contains($extra)) {
  384.                 $this->extras->add($extra);
  385.                 $extra->setIntervention($this);
  386.             }
  387.             return $this;
  388.         }
  389.         public function removeExtra(InterventionExtra $extra): static
  390.         {
  391.             if ($this->extras->removeElement($extra)) {
  392.                 // set the owning side to null (unless already changed)
  393.                 if ($extra->getIntervention() === $this) {
  394.                     $extra->setIntervention(null);
  395.                 }
  396.             }
  397.             return $this;
  398.         }
  399.         /**
  400.          * @return Collection<int, ProductLog>
  401.          */
  402.         public function getProductLogs(): Collection
  403.         {
  404.             return $this->productLogs;
  405.         }
  406.         public function addProductLog(ProductLog $productLog): static
  407.         {
  408.             if (!$this->productLogs->contains($productLog)) {
  409.                 $this->productLogs->add($productLog);
  410.                 $productLog->setIntervention($this);
  411.             }
  412.             return $this;
  413.         }
  414.         public function removeProductLog(ProductLog $productLog): static
  415.         {
  416.             if ($this->productLogs->removeElement($productLog)) {
  417.                 // set the owning side to null (unless already changed)
  418.                 if ($productLog->getIntervention() === $this) {
  419.                     $productLog->setIntervention(null);
  420.                 }
  421.             }
  422.             return $this;
  423.         }
  424.         public function getTicket(): ?Ticket
  425.         {
  426.             return $this->ticket;
  427.         }
  428.         public function setTicket(?Ticket $ticket): static
  429.         {
  430.             $this->ticket $ticket;
  431.             return $this;
  432.         }
  433.         public function getTechnician(): ?User
  434.         {
  435.             return $this->technician;
  436.         }
  437.         public function setTechnician(?User $technician): static
  438.         {
  439.             $this->technician $technician;
  440.             return $this;
  441.         }
  442.         public function getOperator(): ?User
  443.         {
  444.             return $this->operator;
  445.         }
  446.         public function setOperator(?User $operator): static
  447.         {
  448.             $this->operator $operator;
  449.             return $this;
  450.         }
  451.         public function getOutcome(): ?InterventionOutcome
  452.         {
  453.             return $this->outcome;
  454.         }
  455.         public function setOutcome(?InterventionOutcome $outcome): static
  456.         {
  457.             $this->outcome $outcome;
  458.             return $this;
  459.         }
  460.         public function getOutcomeType(): ?InterventionOutcomeType
  461.         {
  462.             return $this->outcomeType;
  463.         }
  464.         public function setOutcomeType(?InterventionOutcomeType $outcomeType): static
  465.         {
  466.             $this->outcomeType $outcomeType;
  467.             return $this;
  468.         }
  469.         public function getWarehouse(): ?Warehouse
  470.         {
  471.             return $this->warehouse;
  472.         }
  473.         public function setWarehouse(?Warehouse $warehouse): static
  474.         {
  475.             $this->warehouse $warehouse;
  476.             return $this;
  477.         }
  478. }