<?php
namespace App\Entity;
use App\Manager\CustomerManager;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* Network
* @ORM\Table(name="network", indexes={
*
* @ORM\Index(name="idx_608487bc7e3c61f9", columns={"owner_id"}),
* @ORM\Index(name="idx_608487bc9f2c3fab", columns={"zone_id"}),
* @ORM\Index(name="idx_608487bc5373c966", columns={"country"}),
* @ORM\Index(name="networkidx1", columns={"localization_long", "localization_lat"})
*
* },
*
* uniqueConstraints={
* @ORM\UniqueConstraint(name="network_number_key", columns={"network_number", "deleted_at"}),
* @ORM\UniqueConstraint(name="project_number_key", columns={"project_number"}),
* @ORM\UniqueConstraint(name="network_name_key", columns={"name", "deleted_at"})
* }
*
* )
* @ORM\Entity(repositoryClass="App\Repository\NetworkRepository")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
*/
class Network
{
use SoftDeleteableEntity;
const REMOVE_ACTION = 'remove';
const STATUS_PROJECT = 'project';
const STATUS_NETWORK = 'network';
const STATUSES = [
self::STATUS_PROJECT,
self::STATUS_NETWORK,
];
const STATE_DEFINITION = 'definition';
const STATE_SIZING = 'sizing';
const STATE_NETWORK_DEVICES = 'network_devices';
const STATE_CUSTOMER_DEVICES = 'customer_devices';
const STATE_CONTRACT = 'contract';
const STATE_CONSTRUCTION = 'construction';
const STATE_FINAL_DECISION = 'final_decision';
const STATE_VALIDATED = 'validated';
const STATE_REJECTED = 'rejected';
const STATE_GENERATION_CODE = "generation_code";
const STATES = [
self::STATE_DEFINITION,
self::STATE_SIZING,
self::STATE_NETWORK_DEVICES,
self::STATE_CUSTOMER_DEVICES,
self::STATE_CONTRACT,
self::STATE_CONSTRUCTION,
self::STATE_FINAL_DECISION,
self::STATE_VALIDATED,
self::STATE_REJECTED,
];
const FINAL_STATES = [
self::STATE_VALIDATED,
self::STATE_REJECTED,
];
const ADMIN_STATES = [
self::STATE_NETWORK_DEVICES,
self::STATE_CUSTOMER_DEVICES,
self::STATE_CONTRACT,
self::STATE_CONSTRUCTION,
self::STATE_FINAL_DECISION,
];
const TRASITIONS_HISTORIC = [
self::TRANSITION_VALIDATE_CONTRACT,
self::TRANSITION_VALIDATE_FINAL_DECISION
];
const TRANSITION_VALIDATE_DEFINITION = 'validate_definition';
const TRANSITION_REJECT_DEFINITION = 'reject_definition';
const TRANSITION_VALIDATE_SIZING = 'validate_sizing';
const TRANSITION_REJECT_SIZING = 'reject_sizing';
const TRANSITION_VALIDATE_NETWORK_DEVICES = 'validate_network_devices';
const TRANSITION_REJECT_NETWORK_DEVICES = 'reject_network_devices';
const TRANSITION_VALIDATE_CUSTOMER_DEVICES = 'validate_customer_devices';
const TRANSITION_REJECT_CUSTOMER_DEVICES = 'reject_customer_devices';
const TRANSITION_VALIDATE_CONTRACT = 'validate_contract';
const TRANSITION_REJECT_CONTRACT = 'reject_contract';
const TRANSITION_REJECT_CONSTRUCTION = 'reject_construction';
const TRANSITION_VALIDATE_FINAL_DECISION = 'validate_final_decision';
const TRANSITION_REJECT_FINAL_DECISION = 'reject_final_decision';
const TRANSITION_GENERATION_CODE = 'generation_code';
const TRANSITIONS = [
self::TRANSITION_VALIDATE_DEFINITION,
self::TRANSITION_REJECT_DEFINITION,
self::TRANSITION_VALIDATE_SIZING,
self::TRANSITION_REJECT_SIZING,
self::TRANSITION_VALIDATE_NETWORK_DEVICES,
self::TRANSITION_REJECT_NETWORK_DEVICES,
self::TRANSITION_VALIDATE_CUSTOMER_DEVICES,
self::TRANSITION_REJECT_CUSTOMER_DEVICES,
self::TRANSITION_VALIDATE_CONTRACT,
self::TRANSITION_REJECT_CONTRACT,
self::TRANSITION_REJECT_CONSTRUCTION,
self::TRANSITION_VALIDATE_FINAL_DECISION,
self::TRANSITION_REJECT_FINAL_DECISION,
self::TRANSITION_GENERATION_CODE,
];
const FINAL_TRANSITIONS = [
self::TRANSITION_REJECT_FINAL_DECISION,
self::TRANSITION_VALIDATE_FINAL_DECISION,
];
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="network_id_seq", allocationSize=1, initialValue=1)
*/
private $id;
/**
* @var string|null
*
* @ORM\Column(name="name", type="text", nullable=true)
*/
private $name;
/**
* @var string|null
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* @var string|null
*
* @ORM\Column(name="status", type="text", nullable=true)
*/
private $status;
/**
* @var float|null
*
* @ORM\Column(name="localization_long", type="float", precision=10, scale=0, nullable=true)
*/
private $localizationLong;
/**
* @var float|null
*
* @ORM\Column(name="localization_lat", type="float", precision=10, scale=0, nullable=true)
*/
private $localizationLat;
/**
* @var string|null
*
* @ORM\Column(name="address", type="text", nullable=true)
*/
private $address;
/**
* @var string|null
*
* @ORM\Column(name="quarter", type="text", nullable=true)
*/
private $quarter;
/**
* @var string|null
*
* @ORM\Column(name="zip", type="text", nullable=true)
*/
private $zip;
/**
* @var string|null
*
* @ORM\Column(name="city", type="text", nullable=true)
*/
private $city;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_start_construction", type="datetimetz", nullable=true)
*/
private $dateStartConstruction;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_start_service", type="datetimetz", nullable=true)
*/
private $dateStartService;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_end_service", type="datetimetz", nullable=true)
*/
private $dateEndService;
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_creation", type="datetimetz", nullable=true)
*/
private $dateCreation;
/**
* @var \DateTime
*
* @ORM\Column(name="date_update", type="datetimetz", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
*/
private $dateUpdate;
/**
* @var bool|null
*
* @ORM\Column(name="active", type="boolean", nullable=true)
*/
private $active = false;
/**
* @var bool|null
*
* @ORM\Column(name="check_updated", type="boolean", nullable=true)
*/
private $checkUpdated = false;
/**
* @var string|null
*
* @ORM\Column(name="ash_key", type="text", nullable=true)
*/
private $ashKey;
/**
* @var string|null
*
* @ORM\Column(name="permutation_key", type="text", nullable=true)
*/
private $permutationKey;
/**
* @var \App\Entity\NetworkDevice
*
* @ORM\OneToMany(targetEntity="App\Entity\NetworkDevice", mappedBy="network", cascade={"persist"})
*/
private $devices;
/**
* @var #ArrayCollection
*/
// private $deviceDeleted;
/**
* @var string|null
*
* @ORM\Column(name="workflow_state", type="string", length=255, nullable=true)
*/
private $workflowState;
/**
* @var \App\Entity\Zone
*
* @ORM\ManyToOne(targetEntity="App\Entity\Zone")
* @ORM\JoinColumns({
* @ORM\JoinColumn(onDelete="SET NULL", name="zone_id", referencedColumnName="id")
* })
*/
private $zone;
/**
* @var \App\Entity\Users
*
* @ORM\ManyToOne(targetEntity="App\Entity\Users")
* @ORM\JoinColumns({
* @ORM\JoinColumn(onDelete="SET NULL", name="owner_id", referencedColumnName="id")
* })
*/
private $owner;
/**
* @var int|null
*
* @ORM\Column(name="project_number", type="integer", nullable=true)
*/
private $projectNumber;
/**
* @var int|null
*
* @ORM\Column(name="prospect_number", type="integer", nullable=true)
*/
private $prospectNumber;
/**
* @var int|null
*
* @ORM\Column(name="network_number", type="integer", nullable=true)
*/
private $networkNumber;
/**
* @var float|null
*
* @ORM\Column(name="stake_localization_long", type="float", precision=10, scale=0, nullable=true)
*/
private $stakeLocalizationLong;
/**
* @var float|null
*
* @ORM\Column(name="stake_localization_lat", type="float", precision=10, scale=0, nullable=true)
*/
private $stakeLocalizationLat;
/**
* @var \App\Entity\Customer
*
* @ORM\OneToMany(targetEntity="App\Entity\Customer", mappedBy="network")
*/
private $customers;
/**
* @var NetworkDevice
*/
private $networkDevices;
/**
* @var int|null
*
* @ORM\Column(name="total_power", type="integer", nullable=true)
*/
private $totalPower;
/**
* @var int|null
*
* @ORM\Column(name="total_storage_capacity", type="integer", nullable=true)
*/
private $totalStorageCapacity;
/**
* @var int|null
*
* @ORM\Column(name="total_voltage", type="integer", nullable=true)
*/
private $totalVoltage;
/**
* @var int|null
*
* @ORM\Column(name="total_cost", type="integer", nullable=true)
*/
private $totalCost;
/**
* @var int|null
*
* @ORM\Column(name="total_wire_length", type="integer", nullable=true)
*/
private $totalWireLength;
/**
* @var int|null
*
* @ORM\Column(name="total_max_power_consumption", type="integer", nullable=true)
*/
private $totalMaxPowerConsumption;
/**
* @var int|null
*
* @ORM\Column(name="total_consumption_day", type="integer", nullable=true)
*/
private $totalConsumptionDay;
/**
* @var \App\Entity\CustomerOperations
*
* @ORM\OneToMany(targetEntity="App\Entity\CustomerOperations", mappedBy="network")
*/
private $customerOperations;
/**
* @var float|null
*
* @ORM\Column(name="commission_percentage", type="float", precision=10, scale=0, nullable=true)
*/
private $commissionPercentage;
/**
* @var \App\Entity\TensionRecord
*
* @ORM\OneToMany(targetEntity="App\Entity\TensionRecord", mappedBy="network")
*/
private $tensionRecords;
/**
* @var \App\Entity\ReloadRecord
*
* @ORM\OneToMany(targetEntity="App\Entity\ReloadRecord", mappedBy="network")
*/
private $reloadRecords;
/**
* @var \App\Entity\AggTensionRecord
*
* @ORM\OneToMany(targetEntity="App\Entity\AggTensionRecord", mappedBy="network")
*/
private $aggTensionRecords;
/**
* @var \App\Entity\AggTransactionRecord
*
* @ORM\OneToMany(targetEntity="App\Entity\AggTransactionRecord", mappedBy="network")
*/
private $aggTransactionRecords;
/**
* @var \App\Entity\Intervention
*
* @ORM\OneToMany(targetEntity="App\Entity\Intervention", mappedBy="network")
*/
private $interventions;
/**
* @var array|null
*
* @ORM\Column(name="commissions", type="array", nullable=true, options={"default"="a:0:{}"})
*/
private $commissions = 'a:0:{}';
/**
* @var \App\Entity\Commission
*
* @ORM\OneToMany(targetEntity="App\Entity\Commission", mappedBy="network", cascade={"persist"}, orphanRemoval=true)
*/
private $commissionEntrepreneurs;
/**
* @var array|null
*
* @ORM\Column(name="nano_entrepreneur", type="array", nullable=true, options={"default"="a:0:{}"})
*/
private $nanoEntrepreneur = 'a:0:{}';
/**
* @ORM\OneToMany(targetEntity="App\Entity\NanoEntrepreneur", mappedBy="network", cascade={"persist"}, orphanRemoval=true)
*/
private $nanoEntrepreneurs;
// /**
// * @var \DateTime|null
// *
// * @ORM\Column(name="deleted_at", type="datetime", nullable=true)
// */
// private $deletedAt;
/**
* @var \App\Entity\NetworkCustomerHistoric
*
* @ORM\OneToMany(targetEntity="App\Entity\NetworkCustomerHistoric", mappedBy="network")
*/
private $networkCustomerHistoric;
/**
* @var string|null
*
* @ORM\Column(name="comment", type="string", length=255, nullable=true)
*/
private $comment;
/**
* @var string|null
*
* @ORM\Column(name="cryptage", type="string", length=10, nullable=true)
*/
private $cryptage;
/**
* @var int
*/
private $puissance;
/**
* @var \App\Entity\CommonCountry
*
* @ORM\ManyToOne(targetEntity="App\Entity\CommonCountry")
* @ORM\JoinColumns({
* @ORM\JoinColumn(onDelete="SET NULL", name="country", referencedColumnName="id")
* })
*/
private $country;
/**
* @var int
*/
private $capaciteStockage;
/**
* @var \App\Entity\GeneratedCode
*
* @ORM\OneToMany(targetEntity="App\Entity\GeneratedCode", mappedBy="network")
*/
private $generatedCodes;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $generatedCode;
/**
* @ORM\OneToMany(targetEntity=Stock::class, mappedBy="nanoReseau")
*/
private $stocks;
/**
* Network constructor.
*/
public function __construct()
{
$this->dateUpdate = $this->dateUpdate ?? new \DateTime();
$this->status = self::STATUS_PROJECT;
$this->devices = new ArrayCollection();
$this->workflowState = self::STATE_DEFINITION;
$this->customers = new ArrayCollection();
$this->active = false;
$this->customerOperations = new ArrayCollection();
$this->tensionRecords = new ArrayCollection();
$this->reloadRecords = new ArrayCollection();
$this->aggTensionRecords = new ArrayCollection();
$this->aggTransactionRecords = new ArrayCollection();
$this->interventions = new ArrayCollection();
$this->commissions = serialize([]);
$this->nanoEntrepreneurs = serialize([]);
$this->nanoEntrepreneurs = new ArrayCollection();
$this->commissionEntrepreneurs = new ArrayCollection();
$this->stocks = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
public function getMarking()
{
}
public function setMarking()
{
}
// public function getDeletedAt()
// {
// return $this->deletedAt;
// }
// public function setDeletedAt(\DateTime $deletedAt)
// {
// $this->deletedAt = $deletedAt;
// }
/**
* Set name
*
* @param string $name
*
* @return Network
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param string $description
*
* @return Network
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set status
*
* @param string $status
*
* @return Network
*/
public function setStatus($status)
{
$this->status = $status;
return $this;
}
/**
* Get status
*
* @return string
*/
public function getStatus()
{
return $this->status;
}
/**
* Set localizationLong
*
* @param float $localizationLong
*
* @return Network
*/
public function setLocalizationLong($localizationLong)
{
$this->localizationLong = $localizationLong;
return $this;
}
/**
* Get localizationLong
*
* @return float
*/
public function getLocalizationLong()
{
return $this->localizationLong;
}
/**
* Set localizationLat
*
* @param float $localizationLat
*
* @return Network
*/
public function setLocalizationLat($localizationLat)
{
$this->localizationLat = $localizationLat;
return $this;
}
/**
* Get localizationLat
*
* @return float
*/
public function getLocalizationLat()
{
return $this->localizationLat;
}
/**
* @return string
*/
public function getCoordinates()
{
return $this->localizationLat && $this->localizationLong
? $this->localizationLat . ', ' . $this->localizationLong
: 'N/A';
}
/**
* @return float
*/
public function getStakeLocalizationLong()
{
return $this->stakeLocalizationLong;
}
/**
* @param float $stakeLocalizationLong
* @return Network
*/
public function setStakeLocalizationLong($stakeLocalizationLong)
{
$this->stakeLocalizationLong = $stakeLocalizationLong;
return $this;
}
/**
* @return float
*/
public function getStakeLocalizationLat()
{
return $this->stakeLocalizationLat;
}
/**
* @param float $stakeLocalizationLat
* @return Network
*/
public function setStakeLocalizationLat($stakeLocalizationLat)
{
$this->stakeLocalizationLat = $stakeLocalizationLat;
return $this;
}
/**
* @return string
*/
public function getstakeCoordinates()
{
return $this->stakeLocalizationLat && $this->stakeLocalizationLong
? $this->stakeLocalizationLat . ', ' . $this->stakeLocalizationLong
: 'N/A';
}
/**
* Set address
*
* @param string $address
*
* @return Network
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set quarter
*
* @param string $quarter
*
* @return Network
*/
public function setQuarter($quarter)
{
$this->quarter = $quarter;
return $this;
}
/**
* Get quarter
*
* @return string
*/
public function getQuarter()
{
return $this->quarter;
}
/**
* Set zip
*
* @param string $zip
*
* @return Network
*/
public function setZip($zip)
{
$this->zip = $zip;
return $this;
}
/**
* Get zip
*
* @return string
*/
public function getZip()
{
return $this->zip;
}
/**
* Set city
*
* @param string $city
*
* @return Network
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set dateStartConstruction
*
* @param \DateTime $dateStartConstruction
*
* @return Network
*/
public function setDateStartConstruction(\DateTime $dateStartConstruction)
{
$this->dateStartConstruction = $dateStartConstruction;
return $this;
}
/**
* Get dateStartConstruction
*
* @return \DateTime
*/
public function getDateStartConstruction()
{
return $this->dateStartConstruction;
}
/**
* Set dateStartService
*
* @param \DateTime $dateStartService
*
* @return Network
*/
public function setDateStartService(\DateTime $dateStartService)
{
$this->dateStartService = $dateStartService;
return $this;
}
/**
* Get dateStartService
*
* @return \DateTime
*/
public function getDateStartService()
{
return $this->dateStartService;
}
/**
* Set dateEndService
*
* @param \DateTime $dateEndService
*
* @return Network
*/
public function setDateEndService(\DateTime $dateEndService)
{
$this->dateEndService = $dateEndService;
return $this;
}
/**
* Get dateEndService
*
* @return \DateTime
*/
public function getDateEndService()
{
return $this->dateEndService;
}
/**
* Set dateCreation
*
* @param \DateTime $dateCreation
*
* @return Network
*/
public function setDateCreation(\DateTime $dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* @return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set dateUpdate
*
* @param \DateTime $dateUpdate
*
* @return Network
*/
public function setDateUpdate(\DateTime $dateUpdate)
{
$this->dateUpdate = $dateUpdate;
return $this;
}
/**
* Get dateUpdate
*
* @return \DateTime
*/
public function getDateUpdate()
{
return $this->dateUpdate;
}
/**
* Set active
*
* @param boolean $active
*
* @return Network
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
public function setCheckUpdated($checkUpdated)
{
$this->checkUpdated = $checkUpdated;
return $this;
}
public function getCheckUpdated()
{
return $this->checkUpdated;
}
/**
* Set country
*
* @param CommonCountry $country
*
* @return Network
*/
public function setCountry(CommonCountry $country = null)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return CommonCountry
*/
public function getCountry()
{
return $this->country;
}
/**
* @return string
*/
public function getAshKey()
{
return $this->ashKey;
}
/**
* @param string $ashKey
* @return Network
*/
public function setAshKey($ashKey)
{
$this->ashKey = $ashKey;
return $this;
}
/**
* @return string
*/
public function getPermutationKey()
{
return $this->permutationKey;
}
/**
* @param string $permutationKey
* @return Network
*/
public function setPermutationKey($permutationKey)
{
$this->permutationKey = $permutationKey;
return $this;
}
/**
* @return bool
*/
public function isProject()
{
return $this->status === self::STATUS_PROJECT;
}
/**
* @return bool
*/
public function isNetwork()
{
return $this->status === self::STATUS_NETWORK;
}
/**
* @param NetworkDevice $networkDevice
* @return Network
*/
public function addDevices(NetworkDevice $networkDevice)
{
if (!$this->devices->contains($networkDevice)) {
$this->devices->add($networkDevice);
$networkDevice->setNetwork($this);
}
return $this;
}
/**
* @param NetworkDevice $networkDevice
* @return Network
*/
public function removeDevices(NetworkDevice $networkDevice)
{
if ($this->devices->contains($networkDevice)) {
$this->devices->removeElement($networkDevice);
$networkDevice->setNetwork(null);
}
return $this;
}
/**
* @param NetworkDevice $networkDevice
* @return Network
*/
public function setDevice(NetworkDevice $networkDevice)
{
return $this->addDevices($networkDevice);
}
/**
* @return ArrayCollection
*/
public function getDevices()
{
//return $this->devices;
$data = $this->devices->filter(
function ($entry) {
return is_null($entry->getDateDeletion());
}
)->getValues();
return new ArrayCollection($data);
}
public function getDeviceDeleted()
{
return $this->devices->filter(
function ($entry) {
return !is_null($entry->getDateDeletion()) || !is_null($entry->getUserUpdated());
}
);
}
/**
* @return string
*/
public function getWorkflowState()
{
return $this->workflowState;
}
/**
* @param string $workflowState
* @return Network
*/
public function setWorkflowState($workflowState)
{
$this->workflowState = $workflowState;
return $this;
}
/**
* @return Zone
*/
public function getZone()
{
return $this->zone;
}
/**
* @param Zone $zone
* @return Network
*/
public function setZone(Zone $zone = null)
{
$this->zone = $zone;
return $this;
}
/**
* @return Users
*/
public function getOwner()
{
return $this->owner;
}
/**
* @param Users $owner
* @return Network
*/
public function setOwner(Users $owner = null)
{
$this->owner = $owner;
return $this;
}
/**
* @return int
*/
public function getProjectNumber()
{
return $this->projectNumber;
}
/**
* @param int $projectNumber
* @return Network
*/
public function setProjectNumber($projectNumber)
{
$this->projectNumber = $projectNumber;
return $this;
}
/**
* @return int
*/
public function getNetworkNumber()
{
return $this->networkNumber;
}
/**
* @param int $networkNumber
* @return Network
*/
public function setNetworkNumber($networkNumber)
{
$this->networkNumber = $networkNumber;
return $this;
}
/**
* @return ArrayCollection
*/
public function getCustomers()
{
return $this->customers;
}
/**
* @param Customer $customer
* @return Network
*/
public function setCustomers(Customer $customer)
{
return $this->addCustomers($customer);
}
/**
* @param Customer $customer
* @return Network
*/
public function addCustomers(Customer $customer)
{
/*if (!$this->customers->contains($customer)) {
$this->customers->add($customer);
$customer
->setNetwork($this)
->setSlotNumber($this->customers->count() + 1)
;
}*/
$slots = [1, 2, 3, 4, 5, 6];
//dump($this->customers->contains($customer));
if (!$this->customers->contains($customer)) {
foreach ($this->customers as $cust) {
unset($slots[$cust->getSlotNumber() - 1]);
}
$this->customers->add($customer);
$customer
->setNetwork($this)
//->setSlotNumber(reset($slots))
;
}
return $this;
}
/**
* @param Customer $customer
* @return Network
*/
public function removeCustomers(Customer $customer)
{
if ($this->customers->contains($customer)) {
$this->customers->removeElement($customer);
$customer
->setNetwork(null)
->setStatus(Customer::STATUS_PROSPECT)
->setDateJoinNetwork(null)
//->setSlotNumber(null)
->setCustomNumber(null);
}
return $this;
}
/**
* @return Network
*/
public function removeAllCustomers()
{
/** @var Customer $customer */
foreach ($this->customers as $customer) {
if (is_object($customer)) {
$this->removeCustomers($customer);
}
}
return $this;
}
/**
* @return int
*/
public function getTotalPower()
{
return $this->totalPower;
}
/**
* @param int $totalPower
* @return Network
*/
public function setTotalPower($totalPower)
{
$this->totalPower = $totalPower;
return $this;
}
/**
* @return int
*/
public function getTotalStorageCapacity()
{
return $this->totalStorageCapacity;
}
/**
* @param int $totalStorageCapacity
* @return Network
*/
public function setTotalStorageCapacity($totalStorageCapacity)
{
$this->totalStorageCapacity = $totalStorageCapacity;
return $this;
}
/**
* @return int
*/
public function getTotalVoltage()
{
return $this->totalVoltage;
}
/**
* @param int $totalVoltage
* @return Network
*/
public function setTotalVoltage($totalVoltage)
{
$this->totalVoltage = $totalVoltage;
return $this;
}
/**
* @return int
*/
public function getTotalCost()
{
return $this->totalCost;
}
/**
* @param int $totalCost
* @return Network
*/
public function setTotalCost($totalCost)
{
$this->totalCost = $totalCost;
return $this;
}
/**
* @return int
*/
public function getTotalWireLength()
{
return $this->totalWireLength;
}
/**
* @param int $totalWireLength
* @return Network
*/
public function setTotalWireLength($totalWireLength)
{
$this->totalWireLength = $totalWireLength;
return $this;
}
/**
* @return int
*/
public function getTotalMaxPowerConsumption()
{
return $this->totalMaxPowerConsumption;
}
/**
* @param int $totalMaxPowerConsumption
* @return Network
*/
public function setTotalMaxPowerConsumption($totalMaxPowerConsumption)
{
$this->totalMaxPowerConsumption = $totalMaxPowerConsumption;
return $this;
}
/**
* @return int
*/
public function getTotalConsumptionDay()
{
return $this->totalConsumptionDay;
}
/**
* @param int $totalConsumptionDay
* @return Network
*/
public function setTotalConsumptionDay($totalConsumptionDay)
{
$this->totalConsumptionDay = $totalConsumptionDay;
return $this;
}
/**
* @return ArrayCollection
*/
public function getCustomerOperations()
{
return $this->customerOperations;
}
/**
* @param ArrayCollection $customerOperations
* @return Network
*/
public function setCustomerOperations($customerOperations)
{
$this->customerOperations = $customerOperations;
return $this;
}
/**
* @param CustomerOperations $customerOperations
* @return Network
*/
public function addCustomerOperations(CustomerOperations $customerOperations)
{
if (!$this->customerOperations->contains($customerOperations)) {
$this->customerOperations->add($customerOperations);
$customerOperations->setNetwork($this);
}
return $this;
}
/**
* @param CustomerOperations $customerOperations
* @return Network
*/
public function removeCustomerOperations(CustomerOperations $customerOperations)
{
if ($this->customerOperations->contains($customerOperations)) {
$this->customerOperations->removeElement($customerOperations);
$customerOperations->setNetwork(null);
}
return $this;
}
/**
* @return float
*/
public function getCommissionPercentage()
{
return $this->commissionPercentage;
}
/**
* @param float $commissionPercentage
* @return Network
*/
public function setCommissionPercentage($commissionPercentage)
{
$this->commissionPercentage = $commissionPercentage;
return $this;
}
/**
* @return TensionRecord
*/
public function getTensionRecords()
{
return $this->tensionRecords;
}
/**
* @param TensionRecord $tensionRecord
* @return $this
*/
public function addTensionRecords(TensionRecord $tensionRecord)
{
if (!$this->tensionRecords->contains($tensionRecord)) {
$this->tensionRecords->add($tensionRecord);
$tensionRecord->setNetwork($this);
}
return $this;
}
/**
* @param TensionRecord $tensionRecords
* @return Network
*/
public function setTensionRecords(TensionRecord $tensionRecords)
{
return $this->addTensionRecords($tensionRecords);
}
/**
* @return ReloadRecord
*/
public function getReloadRecords()
{
return $this->reloadRecords;
}
/**
* @param ReloadRecord $reloadRecords
* @return Network
*/
public function addReloadRecords(ReloadRecord $reloadRecords)
{
if (!$this->reloadRecords->contains($reloadRecords)) {
$this->reloadRecords->add($reloadRecords);
$reloadRecords->setNetwork($this);
}
return $this;
}
/**
* @param ReloadRecord $reloadRecords
* @return Network
*/
public function setReloadRecords(ReloadRecord $reloadRecords)
{
return $this->addReloadRecords($reloadRecords);
}
/**
* @return Collection
*/
public function getAggTensionRecords(): Collection
{
return $this->aggTensionRecords;
}
/**
* @return Collection
*/
public function getAggTransactionRecords(): Collection
{
return $this->aggTransactionRecords;
}
/**
* @return Collection
*/
public function getInterventions(): Collection
{
return $this->interventions;
}
/**
* @param Intervention $intervention
* @return $this
*/
public function addInterventions(Intervention $intervention)
{
if (!$this->interventions->contains($intervention)) {
$this->interventions->add($intervention);
$intervention->setNetwork($this);
}
return $this;
}
/**
* @return string
*/
public function getNetworkNumberAndOwnerName()
{
return $this->getNetworkNumber() . ' - ' . $this->getOwner();
}
/**
* @return string
*/
public function __toString()
{
return (string) $this->name;
}
/**
* @param LifecycleEventArgs $args
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function turnProjectToNetwork(LifecycleEventArgs $args)
{
/** @var Network $network */
$network = $args->getObject();
$em = $args->getEntityManager();
if (
$network->getDateStartService() !== null
&& $network->getDateStartService() <= new \DateTime()
&& $network->getWorkflowState() === self::STATE_VALIDATED
) {
$this->setStatus(self::STATUS_NETWORK);
/** @var Customer $customer */
foreach ($network->getCustomers() as $customer) {
if ($customer->isAllowedToBecomeAClient()) {
$customer->setStatus(Customer::STATUS_CLIENT);
$em->persist($customer);
$em->flush();
}
}
}
}
/**
* @param LifecycleEventArgs $args
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
*/
public function turnClientToProspect(LifecycleEventArgs $args)
{
/** @var Network $network */
$network = $args->getObject();
$em = $args->getEntityManager();
foreach ($network->getCustomers() as $customer) {
$customer->setDateJoinNetwork(null);
$customer->setNetwork(null);
$customer->setCustomNumber(null);
$customer->setStatus(Customer::STATUS_PROSPECT);
$customer->setCreator($network->getOwner());
$customer->setWorkflowState(Customer::STATE_VALIDATED);
if (!$customer->isBalancePositive()) {
$customer->setBalance(0);
}
$em->persist($customer);
}
$em->flush();
}
/**
* @return array
*/
public function getCommissions()
{
if (is_string($this->commissions)) {
return unserialize($this->commissions);
}
return ($this->commissions);
}
/**
* @param array $commissions
* @return $commissions
*/
public function setCommissions($commissions)
{
$this->commissions = serialize($commissions);
return $this;
}
/**
* @return \NetworkCustomerHistoric
*/
public function getNetworkCustomerHistoric()
{
return $this->networkCustomerHistoric;
}
/**
* @param NetworkCustomerHistoric $networkCustomerHistoric
*/
public function setNetworkCustomerHistoric(NetworkCustomerHistoric $networkCustomerHistoric): void
{
$this->networkCustomerHistoric = $networkCustomerHistoric;
}
/**
* @return array
*/
public function getNanoEntrepreneur()
{
if (is_string($this->nanoEntrepreneurs)) {
return unserialize($this->nanoEntrepreneurs);
}
return ($this->nanoEntrepreneurs);
}
/**
* @param array $nanoEntrepreneur
*/
/* public function setNanoEntrepreneur(array $nanoEntrepreneur)
{
$this->nanoEntrepreneur = serialize($nanoEntrepreneur);
return $this;
}*/
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string $comment
*/
public function setComment(string $comment = null): void
{
$this->comment = $comment;
}
/**
* @return string
*/
public function getCryptage()
{
return $this->cryptage;
}
/**
* @param string $comment
*/
public function setCryptage(string $cryptage = null)
{
$this->cryptage = $cryptage;
return $this;
}
/**
* Add customer.
*
* @param \App\Entity\Customer $customer
*
* @return Network
*/
public function addCustomer(\App\Entity\Customer $customer)
{
/*Quick fix for not able to persist collection through cascade persist*/
$customer->setNetwork($this);
$customer->setSlotNumber(count($this->customers) + 1);
$this->customers->add($customer);
return $this;
}
/**
* Remove customer.
*
* @param \App\Entity\Customer $customer
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeCustomer(\App\Entity\Customer $customer)
{
/*Quick fix for not able to persist collection through cascade persist*/
$customer->setNetwork(null);
$customer->setSlotNumber(null);
return $this->customers->removeElement($customer);
}
/**
* Add device.
*
* @param \App\Entity\NetworkDevice $device
*
* @return Network
*/
public function addDevice(\App\Entity\NetworkDevice $device)
{
$this->devices[] = $device;
return $this;
}
/**
* Remove device.
*
* @param \App\Entity\NetworkDevice $device
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeDevice(\App\Entity\NetworkDevice $device)
{
$device->setNetwork(null);
return $this->devices->removeElement($device);
}
/**
* Add customerOperation.
*
* @param \App\Entity\CustomerOperations $customerOperation
*
* @return Network
*/
public function addCustomerOperation(\App\Entity\CustomerOperations $customerOperation)
{
$this->customerOperations[] = $customerOperation;
return $this;
}
/**
* Remove customerOperation.
*
* @param \App\Entity\CustomerOperations $customerOperation
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeCustomerOperation(\App\Entity\CustomerOperations $customerOperation)
{
return $this->customerOperations->removeElement($customerOperation);
}
/**
* Add tensionRecord.
*
* @param \App\Entity\TensionRecord $tensionRecord
*
* @return Network
*/
public function addTensionRecord(\App\Entity\TensionRecord $tensionRecord)
{
$this->tensionRecords[] = $tensionRecord;
return $this;
}
/**
* Remove tensionRecord.
*
* @param \App\Entity\TensionRecord $tensionRecord
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeTensionRecord(\App\Entity\TensionRecord $tensionRecord)
{
return $this->tensionRecords->removeElement($tensionRecord);
}
/**
* Add reloadRecord.
*
* @param \App\Entity\ReloadRecord $reloadRecord
*
* @return Network
*/
public function addReloadRecord(\App\Entity\ReloadRecord $reloadRecord)
{
$this->reloadRecords[] = $reloadRecord;
return $this;
}
/**
* Remove reloadRecord.
*
* @param \App\Entity\ReloadRecord $reloadRecord
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeReloadRecord(\App\Entity\ReloadRecord $reloadRecord)
{
return $this->reloadRecords->removeElement($reloadRecord);
}
/**
* Add aggTensionRecord.
*
* @param \App\Entity\AggTensionRecord $aggTensionRecord
*
* @return Network
*/
public function addAggTensionRecord(\App\Entity\AggTensionRecord $aggTensionRecord)
{
$this->aggTensionRecords[] = $aggTensionRecord;
return $this;
}
/**
* Remove aggTensionRecord.
*
* @param \App\Entity\AggTensionRecord $aggTensionRecord
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeAggTensionRecord(\App\Entity\AggTensionRecord $aggTensionRecord)
{
return $this->aggTensionRecords->removeElement($aggTensionRecord);
}
/**
* Add aggTransactionRecord.
*
* @param \App\Entity\AggTransactionRecord $aggTransactionRecord
*
* @return Network
*/
public function addAggTransactionRecord(\App\Entity\AggTransactionRecord $aggTransactionRecord)
{
$this->aggTransactionRecords[] = $aggTransactionRecord;
return $this;
}
/**
* Remove aggTransactionRecord.
*
* @param \App\Entity\AggTransactionRecord $aggTransactionRecord
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeAggTransactionRecord(\App\Entity\AggTransactionRecord $aggTransactionRecord)
{
return $this->aggTransactionRecords->removeElement($aggTransactionRecord);
}
/**
* Add intervention.
*
* @param \App\Entity\Intervention $intervention
*
* @return Network
*/
public function addIntervention(\App\Entity\Intervention $intervention)
{
$this->interventions[] = $intervention;
return $this;
}
/**
* Remove intervention.
*
* @param \App\Entity\Intervention $intervention
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeIntervention(\App\Entity\Intervention $intervention)
{
return $this->interventions->removeElement($intervention);
}
/**
* Add networkCustomerHistoric.
*
* @param \App\Entity\NetworkCustomerHistoric $networkCustomerHistoric
*
* @return Network
*/
public function addNetworkCustomerHistoric(\App\Entity\NetworkCustomerHistoric $networkCustomerHistoric)
{
$this->networkCustomerHistoric[] = $networkCustomerHistoric;
return $this;
}
/**
* Remove networkCustomerHistoric.
*
* @param \App\Entity\NetworkCustomerHistoric $networkCustomerHistoric
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeNetworkCustomerHistoric(\App\Entity\NetworkCustomerHistoric $networkCustomerHistoric)
{
return $this->networkCustomerHistoric->removeElement($networkCustomerHistoric);
}
/**
* Add generatedCode.
*
* @param \App\Entity\GeneratedCode $generatedCode
*
* @return Network
*/
public function addGeneratedCode(\App\Entity\GeneratedCode $generatedCode)
{
$this->generatedCodes[] = $generatedCode;
return $this;
}
/**
* Remove generatedCode.
*
* @param \App\Entity\GeneratedCode $generatedCode
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeGeneratedCode(\App\Entity\GeneratedCode $generatedCode)
{
return $this->generatedCodes->removeElement($generatedCode);
}
/**
* Get generatedCodes.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGeneratedCodes()
{
return $this->generatedCodes;
}
/**
* Get generatedCode.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGeneratedCode()
{
return $this->generatedCode;
}
/**
* Add commissionEntrepreneur.
*
* @param \App\Entity\Commission $commissionEntrepreneur
*
* @return Network
*/
public function addCommissionEntrepreneur(\App\Entity\Commission $commissionEntrepreneur)
{
$this->commissionEntrepreneurs[] = $commissionEntrepreneur;
return $this;
}
/**
* Remove commissionEntrepreneur.
*
* @param \App\Entity\Commission $commissionEntrepreneur
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeCommissionEntrepreneur(\App\Entity\Commission $commissionEntrepreneur)
{
return $this->commissionEntrepreneurs->removeElement($commissionEntrepreneur);
}
/**
* Get commissionEntrepreneurs.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getCommissionEntrepreneurs()
{
$datas = $this->commissionEntrepreneurs->toArray();
usort($datas, function($a, $b) {
return $a->getStartDate() <=> $b->getStartDate();
});
return new ArrayCollection($datas);
}
/**
* Add nanoEntrepreneur.
*
* @param \App\Entity\NanoEntrepreneur $nanoEntrepreneur
*
* @return Network
*/
public function addNanoEntrepreneur(\App\Entity\NanoEntrepreneur $nanoEntrepreneur)
{
$this->nanoEntrepreneurs[] = $nanoEntrepreneur;
if (!$this->nanoEntrepreneurs->contains($nanoEntrepreneur)) {
$this->nanoEntrepreneurs[] = $nanoEntrepreneur;
$nanoEntrepreneur->setNetwork($this);
}
return $this;
}
public function removeNanoEntrepreneur(\App\Entity\NanoEntrepreneur $nanoEntrepreneur): self
{
if ($this->nanoEntrepreneurs->removeElement($nanoEntrepreneur)) {
// set the owning side to null (unless already changed)
if ($nanoEntrepreneur->getNetwork() === $this) {
$nanoEntrepreneur->setNetwork(null);
}
}
return $this;
}
/**
* Get nanoEntrepreneurs.
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getNanoEntrepreneurs()
{
$datas = $this->nanoEntrepreneurs->toArray();
usort($datas, function($a, $b) {
return $a->getStartDate() <=> $b->getStartDate();
});
return new ArrayCollection($datas);
}
/**
* @param NanoEntrepreneur $nanoEntrepreneur
* @return Network
*/
public function addNanoEntrepreneurs(NanoEntrepreneur $nanoEntrepreneur)
{
if (!$this->nanoEntrepreneurs->contains($nanoEntrepreneur)) {
$this->nanoEntrepreneurs->add($nanoEntrepreneur);
$nanoEntrepreneur->setNetwork($this);
}
return $this;
}
/**
* @param NanoEntrepreneur $nanoEntrepreneur
* @return Network
*/
public function setNanoEntrepreneur(NanoEntrepreneur $nanoEntrepreneur)
{
return $this->addNanoEntrepreneurs($nanoEntrepreneur);
}
/**
* @param Commission $commission
* @return Network
*/
public function addCommissionEntrepreneurs(Commission $commission)
{
if (!$this->commissionEntrepreneurs->contains($commission)) {
$this->commissionEntrepreneurs->add($commission);
$commission->setNetwork($this);
}
return $this;
}
/**
* @param Commission $commission
* @return Network
*/
public function removeCommissionEntrepreneurs(Commission $commission)
{
if ($this->commissionEntrepreneurs->contains($commission)) {
$this->commissionEntrepreneurs->removeElement($commission);
$commission->setNetwork(null);
}
return $this;
}
/**
* @param Commission $commission
* @return Network
*/
public function setCommissionEntrepreneur(Commission $commission)
{
return $this->addCommissionEntrepreneurs($commission);
}
/**
* @return int
*/
public function getPuissance($networkDevices): int
{
$this->puissance = 0;
$ideviceDimension = 0;
foreach ($networkDevices as $networkDevice) {
if (empty($networkDevice->getDateDeletion())) {
$aDeviceDimensions = $networkDevice->getDevice()->getDeviceDimension()->toArray();
foreach ($aDeviceDimensions as $deviceDimension) {
if ($deviceDimension->getUnit() === 'Wc' && $networkDevice->getDevice()->getType()->getId() == 1) {
$ideviceDimension = (int) $deviceDimension->getValue();
$this->puissance += $ideviceDimension * (int) $networkDevice->getDeviceCount();
}
}
}
}
return $this->puissance;
}
/**
* @return int
*/
public function getCapaciteStockage($networkDevices): int
{
$this->capaciteStockage = 0;
$ideviceDimension = 0;
foreach ($networkDevices as $networkDevice) {
if (empty($networkDevice->getDateDeletion())) {
$aDeviceDimensions = $networkDevice->getDevice()->getDeviceDimension()->toArray();
foreach ($aDeviceDimensions as $deviceDimension) {
if ($deviceDimension->getUnit() === 'Ah' && $networkDevice->getDevice()->getType()->getId() == 3) {
$ideviceDimension = (int) $deviceDimension->getValue();
$this->capaciteStockage += $ideviceDimension * (int) $networkDevice->getDeviceCount();
}
}
}
}
return $this->capaciteStockage;
}
/**
* @return Collection<int, Stock>
*/
public function getStocks(): Collection
{
return $this->stocks;
}
public function addStock(Stock $stock): self
{
if (!$this->stocks->contains($stock)) {
$this->stocks[] = $stock;
$stock->setNanoReseau($this);
}
return $this;
}
public function removeStock(Stock $stock): self
{
if ($this->stocks->removeElement($stock)) {
// set the owning side to null (unless already changed)
if ($stock->getNanoReseau() === $this) {
$stock->setNanoReseau(null);
}
}
return $this;
}
}