Add customer, customer vehicle, distributor and retailer entities. #370
This commit is contained in:
parent
efba8f1f48
commit
e14947e486
4 changed files with 442 additions and 0 deletions
222
src/Service/Prowar/Entity/Customer.php
Normal file
222
src/Service/Prowar/Entity/Customer.php
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\Prowar\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="customer")
|
||||
*/
|
||||
class Customer
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// first name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $first_name;
|
||||
|
||||
// last name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $last_name;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", length=65535)
|
||||
*/
|
||||
protected $customer_notes;
|
||||
|
||||
// mobile phone
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $phone_mobile;
|
||||
|
||||
// landline
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $phone_landline;
|
||||
|
||||
// office phone
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $phone_office;
|
||||
|
||||
// fax
|
||||
/**
|
||||
* @ORM\Column(type="string", length=30)
|
||||
*/
|
||||
protected $phone_fax;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
*/
|
||||
protected $email;
|
||||
|
||||
// vehicles linked to customer
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer", cascade={"persist"})
|
||||
*/
|
||||
protected $vehicles;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->vehicles = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
public function setFirstName($first_name)
|
||||
{
|
||||
$this->first_name = $first_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->first_name;
|
||||
}
|
||||
|
||||
public function setLastName($last_name)
|
||||
{
|
||||
$this->last_name = $last_name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->last_name;
|
||||
}
|
||||
|
||||
public function getNameDisplay()
|
||||
{
|
||||
return $this->first_name . ' ' . $this->last_name;
|
||||
}
|
||||
|
||||
public function setCustomerNotes($customer_notes)
|
||||
{
|
||||
$this->customer_notes = $customer_notes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomerNotes()
|
||||
{
|
||||
return $this->customer_notes;
|
||||
}
|
||||
|
||||
public function getMobileNumberList()
|
||||
{
|
||||
$phones = [];
|
||||
|
||||
if (!empty($this->phone_mobile))
|
||||
$phones[] = $this->phone_mobile;
|
||||
|
||||
if (!empty($this->phone_landline))
|
||||
$phones[] = $this->phone_landline;
|
||||
|
||||
if (!empty($this->phone_office))
|
||||
$phones[] = $this->phone_office;
|
||||
|
||||
if (!empty($this->phone_fax))
|
||||
$phones[] = $this->phone_fax;
|
||||
|
||||
return $phones;
|
||||
}
|
||||
|
||||
public function setPhoneMobile($phone)
|
||||
{
|
||||
$this->phone_mobile = $phone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhoneMobile()
|
||||
{
|
||||
return $this->phone_mobile;
|
||||
}
|
||||
|
||||
public function setPhoneLandline($phone)
|
||||
{
|
||||
$this->phone_landline = $phone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhoneLandline()
|
||||
{
|
||||
return $this->phone_landline;
|
||||
}
|
||||
|
||||
public function setPhoneOffice($phone)
|
||||
{
|
||||
$this->phone_office = $phone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhoneOffice()
|
||||
{
|
||||
return $this->phone_office;
|
||||
}
|
||||
|
||||
public function setPhoneFax($phone)
|
||||
{
|
||||
$this->phone_fax = $phone;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhoneFax()
|
||||
{
|
||||
return $this->phone_fax;
|
||||
}
|
||||
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function addVehicle(CustomerVehicle $vehicle)
|
||||
{
|
||||
$this->vehicles->add($vehicle);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearVehicles()
|
||||
{
|
||||
$this->vehicles->clear();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeVehicle($vehicle)
|
||||
{
|
||||
$this->vehicles->removeElement($vehicle);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVehicles()
|
||||
{
|
||||
return $this->vehicles;
|
||||
}
|
||||
}
|
||||
77
src/Service/Prowar/Entity/CustomerVehicle.php
Normal file
77
src/Service/Prowar/Entity/CustomerVehicle.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="customer_vehicle", indexes={@ORM\Index(columns={"plate_number"}, flags={"fulltext"}),
|
||||
@ORM\Index(name="plate_number_idx", columns={"plate_number"})})
|
||||
*/
|
||||
class CustomerVehicle
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// link to customer
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="vehicles")
|
||||
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
// plate number
|
||||
/**
|
||||
* @ORM\Column(type="string", length=100)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $plate_number;
|
||||
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setCustomer(Customer $customer)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
public function setPlateNumber($plate_number)
|
||||
{
|
||||
// make it upper case
|
||||
$plate_number = trim(strtoupper($plate_number));
|
||||
|
||||
// remove spaces
|
||||
$plate_number = str_replace(' ', '', $plate_number);
|
||||
|
||||
// upper case
|
||||
$plate_number = strtoupper($plate_number);
|
||||
|
||||
$this->plate_number = $plate_number;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPlateNumber()
|
||||
{
|
||||
return strtoupper($this->plate_number);
|
||||
}
|
||||
}
|
||||
82
src/Service/Prowar/Entity/Distributor.php
Normal file
82
src/Service/Prowar/Entity/Distributor.php
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\Prowar\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="distributor")
|
||||
*/
|
||||
class Distributor
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// retailers
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Retailer", inversedBy="distributors", indexBy="id")
|
||||
* @ORM\JoinTable(name="distributor_retailer")
|
||||
*/
|
||||
protected $retailers;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->retailers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function addRetailer(Retailer $retailer)
|
||||
{
|
||||
if (!isset($this->retailers[$retailer->getID()]))
|
||||
$this->retailers[$retailer->getID()] = $retailer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRetailer(Retailer $retailer)
|
||||
{
|
||||
if (isset($this->retailers[$retailer->getID()]))
|
||||
unset($this->retailers[$retailer->getID()]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function clearRetailers()
|
||||
{
|
||||
$this->retailers->clear();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRetailers()
|
||||
{
|
||||
return $this->retailers;
|
||||
}
|
||||
}
|
||||
61
src/Service/Prowar/Entity/Retailer.php
Normal file
61
src/Service/Prowar/Entity/Retailer.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\Prowar\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="retailer")
|
||||
*/
|
||||
class Retailer
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
// name
|
||||
/**
|
||||
* @ORM\Column(type="string", length=80)
|
||||
* @Assert\NotBlank()
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
// distributors
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Distributor", mappedBy="retailers", indexBy="id", fetch="EXTRA_LAZY")
|
||||
*/
|
||||
protected $distributors;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->distributors = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getDistributors()
|
||||
{
|
||||
return $this->distributors;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue