<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_intervention")
* @ORM\Entity(repositoryClass="App\Repository\Slave\InterventionRepository")
*/
class Intervention
{
public function __toString(){
if($this->getOutcome() != null)
return $this->getOutcome()->getValue().' il '.$this->getDatetime()->format('d-m-Y H:i');
else
return 'Intervento incompleto';
}
public function calculateTotalTechnicianAmount()
{
return floatval($this->calculateTechnicianAmount()) + floatval($this->calculateExtraAmount());
}
public function calculateTechnicianAmount()
{
$total = 0;
if($this->getAmountTechnician() != '0.00')
$total = floatval($this->getAmountTechnician());
else{
foreach($this->getExtras() as $extra){
if($extra->isTariffOut() && $extra->isApproved())
return $extra->getCost();
}
}
if($this->getSlaOutboundPercentage() != null){
$sla = ($total / 100 * $this->getSlaOutboundPercentage());
$total = $total - $sla;
}
return $total;
}
public function calculateExtraAmount()
{
$totalExtra = 0;
foreach($this->getExtras() as $extra){
if($extra->isApproved() && !$extra->isTariffOut())
$totalExtra += floatval($extra->getCost());
}
return floatval($totalExtra);
}
public function takeAllExtraAmount()
{
$totalExtra = 0;
foreach($this->getExtras() as $extra){
$totalExtra += floatval($extra->getCost());
}
return floatval($totalExtra);
}
public function takeAllExtraNotBillableAmount()
{
$totalExtra = 0;
foreach($this->getExtras() as $extra){
if(!$extra->isApproved())
$totalExtra += floatval($extra->getCost());
}
return floatval($totalExtra);
}
public function getLastProductLog($type)
{
$log = null;
$oldDatetime = date_create_from_format('Ymd', '20000101');
foreach($this->getProductLogs() as $pl){
if($pl->getType() == $type && $pl->getDatetime()->format('YmdHi') > $oldDatetime->format('YmdHi')){
$oldDatetime = $pl->getDatetime();
$log = $pl;
}
}
return $log;
}
public function hasExtras(){
if(sizeof($this->getExtras()) > 0)
return true;
return false;
}
public function displayExtras(){
$string = "";
if(sizeof($this->getExtras()) > 0){
foreach($this->extras as $extra){
$string.= $extra->displayResume()."</br>";
}
}
return $string;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="datetime", type="datetime")
*/
protected $datetime;
/**
* @ORM\Column(name="datetime_billing", type="datetime", nullable=true)
*/
protected $datetimeBilling;
/**
* @ORM\Column(name="referent", type="string", length=191, nullable=true)
*/
protected $referent;
/**
* @ORM\Column(name="motivation", type="text", nullable=true)
*/
protected $motivation;
/**
* @ORM\Column(name="phone", type="string", length=191, nullable=true)
*/
protected $phone;
/**
* @ORM\Column(name="photo_path", type="string", length=191, nullable=true)
*/
protected $photoPath;
/**
* @ORM\Column(name="amount", type="decimal", scale=2, nullable=true)
*/
protected $amount;
/**
* @ORM\Column(name="amount_technician", type="decimal", scale=2, nullable=true)
*/
protected $amountTechnician;
/**
* @ORM\Column(name="sla_outbound_percentage", type="integer", nullable=true)
*/
protected $slaOutboundPercentage;
/**
* @ORM\Column(name="billable", type="boolean")
*/
protected $billable = true;
// OneToOne
/**
* @ORM\OneToOne(targetEntity="App\Entity\Slave\TicketSuspension", mappedBy="intervention")
*/
private $suspension;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionActivity", mappedBy="intervention")
*/
private $activities;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\InterventionExtra", mappedBy="intervention")
*/
private $extras;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductLog", mappedBy="intervention")
*/
private $productLogs;
//
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Ticket", inversedBy="interventions")
* @ORM\JoinColumn(name="ticket_id", referencedColumnName="id")
*/
private $ticket;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="interventions")
* @ORM\JoinColumn(name="technician_id", referencedColumnName="id")
*/
private $technician;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="operatorInterventions")
* @ORM\JoinColumn(name="operator_id", referencedColumnName="id")
*/
private $operator;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcome", inversedBy="interventions")
* @ORM\JoinColumn(name="outcome_id", referencedColumnName="id")
*/
private $outcome;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\InterventionOutcomeType", inversedBy="interventions")
* @ORM\JoinColumn(name="outcome_type_id", referencedColumnName="id")
*/
private $outcomeType;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="interventions")
* @ORM\JoinColumn(name="warehouse_id", referencedColumnName="id")
*/
private $warehouse;
public function __construct()
{
$this->activities = new ArrayCollection();
$this->extras = new ArrayCollection();
$this->productLogs = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getDatetime(): ?\DateTimeInterface
{
return $this->datetime;
}
public function setDatetime(\DateTimeInterface $datetime): static
{
$this->datetime = $datetime;
return $this;
}
public function getDatetimeBilling(): ?\DateTimeInterface
{
return $this->datetimeBilling;
}
public function setDatetimeBilling(\DateTimeInterface $datetimeBilling): static
{
$this->datetimeBilling = $datetimeBilling;
return $this;
}
public function getReferent(): ?string
{
return $this->referent;
}
public function setReferent(?string $referent): static
{
$this->referent = $referent;
return $this;
}
public function getMotivation(): ?string
{
return $this->motivation;
}
public function setMotivation(?string $motivation): static
{
$this->motivation = $motivation;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getPhotoPath(): ?string
{
return $this->photoPath;
}
public function setPhotoPath(?string $photoPath): static
{
$this->photoPath = $photoPath;
return $this;
}
public function getAmount(): ?string
{
return $this->amount;
}
public function setAmount(?string $amount): static
{
$this->amount = $amount;
return $this;
}
public function getAmountTechnician(): ?string
{
return $this->amountTechnician;
}
public function setAmountTechnician(?string $amountTechnician): static
{
$this->amountTechnician = $amountTechnician;
return $this;
}
public function getSlaOutboundPercentage(): ?int
{
return $this->slaOutboundPercentage;
}
public function setSlaOutboundPercentage(?int $slaOutboundPercentage): static
{
$this->slaOutboundPercentage = $slaOutboundPercentage;
return $this;
}
public function isBillable(): ?bool
{
return $this->billable;
}
public function setBillable(bool $billable): static
{
$this->billable = $billable;
return $this;
}
public function getSuspension(): ?TicketSuspension
{
return $this->suspension;
}
public function setSuspension(?TicketSuspension $suspension): static
{
// unset the owning side of the relation if necessary
if ($suspension === null && $this->suspension !== null) {
$this->suspension->setIntervention(null);
}
// set the owning side of the relation if necessary
if ($suspension !== null && $suspension->getIntervention() !== $this) {
$suspension->setIntervention($this);
}
$this->suspension = $suspension;
return $this;
}
/**
* @return Collection<int, InterventionActivity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(InterventionActivity $activity): static
{
if (!$this->activities->contains($activity)) {
$this->activities->add($activity);
$activity->setIntervention($this);
}
return $this;
}
public function removeActivity(InterventionActivity $activity): static
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getIntervention() === $this) {
$activity->setIntervention(null);
}
}
return $this;
}
/**
* @return Collection<int, InterventionExtra>
*/
public function getExtras(): Collection
{
return $this->extras;
}
public function addExtra(InterventionExtra $extra): static
{
if (!$this->extras->contains($extra)) {
$this->extras->add($extra);
$extra->setIntervention($this);
}
return $this;
}
public function removeExtra(InterventionExtra $extra): static
{
if ($this->extras->removeElement($extra)) {
// set the owning side to null (unless already changed)
if ($extra->getIntervention() === $this) {
$extra->setIntervention(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductLog>
*/
public function getProductLogs(): Collection
{
return $this->productLogs;
}
public function addProductLog(ProductLog $productLog): static
{
if (!$this->productLogs->contains($productLog)) {
$this->productLogs->add($productLog);
$productLog->setIntervention($this);
}
return $this;
}
public function removeProductLog(ProductLog $productLog): static
{
if ($this->productLogs->removeElement($productLog)) {
// set the owning side to null (unless already changed)
if ($productLog->getIntervention() === $this) {
$productLog->setIntervention(null);
}
}
return $this;
}
public function getTicket(): ?Ticket
{
return $this->ticket;
}
public function setTicket(?Ticket $ticket): static
{
$this->ticket = $ticket;
return $this;
}
public function getTechnician(): ?User
{
return $this->technician;
}
public function setTechnician(?User $technician): static
{
$this->technician = $technician;
return $this;
}
public function getOperator(): ?User
{
return $this->operator;
}
public function setOperator(?User $operator): static
{
$this->operator = $operator;
return $this;
}
public function getOutcome(): ?InterventionOutcome
{
return $this->outcome;
}
public function setOutcome(?InterventionOutcome $outcome): static
{
$this->outcome = $outcome;
return $this;
}
public function getOutcomeType(): ?InterventionOutcomeType
{
return $this->outcomeType;
}
public function setOutcomeType(?InterventionOutcomeType $outcomeType): static
{
$this->outcomeType = $outcomeType;
return $this;
}
public function getWarehouse(): ?Warehouse
{
return $this->warehouse;
}
public function setWarehouse(?Warehouse $warehouse): static
{
$this->warehouse = $warehouse;
return $this;
}
}