806 lines
17 KiB
PHP
806 lines
17 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use App\Ramcar\WarrantyClass;
|
|
use App\Ramcar\WarrantyStatus;
|
|
use DateTime;
|
|
use Exception;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(
|
|
* name="warranty",
|
|
* uniqueConstraints={
|
|
* @ORM\UniqueConstraint(columns={"serial"})
|
|
* },
|
|
* indexes={
|
|
* @ORM\Index(name="plate_number_idx", columns={"plate_number"}),
|
|
@ORM\Index(name="serial_idx", columns={"serial"})
|
|
* })
|
|
* )
|
|
*/
|
|
class Warranty
|
|
{
|
|
// unique id
|
|
/**
|
|
* @ORM\Id
|
|
* @ORM\Column(type="integer")
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
protected $id;
|
|
|
|
// serial number
|
|
/**
|
|
* @ORM\Column(type="string", length=50, nullable=true)
|
|
*/
|
|
protected $serial;
|
|
|
|
// warranty class
|
|
/**
|
|
* @ORM\Column(type="string", length=25)
|
|
*/
|
|
protected $warranty_class;
|
|
|
|
// plate
|
|
/**
|
|
* @ORM\Column(type="string", length=20)
|
|
*/
|
|
protected $plate_number;
|
|
|
|
// customer first name
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $first_name;
|
|
|
|
// customer last name
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $last_name;
|
|
|
|
// email
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $email;
|
|
|
|
// customer mobile phone number
|
|
/**
|
|
* @ORM\Column(type="string", length=30, nullable=true)
|
|
*/
|
|
protected $mobile_number;
|
|
|
|
// battery model
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="BatteryModel", inversedBy="warranties")
|
|
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $bty_model;
|
|
|
|
// battery size
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="BatterySize", inversedBy="warranties")
|
|
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $bty_size;
|
|
|
|
// sap battery
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="SAPBattery", inversedBy="warranties")
|
|
* @ORM\JoinColumn(name="sap_bty_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $sap_bty;
|
|
|
|
// status
|
|
/**
|
|
* @ORM\Column(type="string", length=25)
|
|
*/
|
|
protected $status;
|
|
|
|
// date created
|
|
/**
|
|
* @ORM\Column(type="datetime")
|
|
*/
|
|
protected $date_create;
|
|
|
|
// date purchased
|
|
/**
|
|
* @ORM\Column(type="date")
|
|
*/
|
|
protected $date_purchase;
|
|
|
|
// date expires
|
|
/**
|
|
* @ORM\Column(type="date", nullable=true)
|
|
*/
|
|
protected $date_expire;
|
|
|
|
// date claimed
|
|
/**
|
|
* @ORM\Column(type="date", nullable=true)
|
|
*/
|
|
protected $date_claim;
|
|
|
|
// claimed from
|
|
/**
|
|
* @ORM\OneToOne(targetEntity="Warranty")
|
|
* @ORM\JoinColumn(name="claim_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $claim_from;
|
|
|
|
// warranty activated
|
|
/**
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
protected $flag_activated;
|
|
|
|
// privacy policy
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="warranties")
|
|
* @ORM\JoinColumn(name="warranty_privacy_policy", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $privacy_policy;
|
|
|
|
|
|
// NOTE: the following were added later on, so they should all be nullable or have defaults,
|
|
// otherwise we get issues
|
|
|
|
// invoice picture
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $file_invoice;
|
|
|
|
// warranty card picture
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $file_warr_card;
|
|
|
|
// vehicle
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Vehicle")
|
|
* @ORM\JoinColumn(name="vehicle_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $vehicle;
|
|
|
|
// vehicle model year
|
|
/**
|
|
* @ORM\Column(type="string", length=10, nullable=true)
|
|
*/
|
|
protected $v_model_year;
|
|
|
|
// odometer reading
|
|
/**
|
|
* @ORM\Column(type="integer", nullable=true)
|
|
*/
|
|
protected $odometer;
|
|
|
|
// dealer name
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $dealer_name;
|
|
|
|
// dealer address
|
|
/**
|
|
* @ORM\Column(type="string", length=180, nullable=true)
|
|
*/
|
|
protected $dealer_address;
|
|
|
|
// customer contact number
|
|
/**
|
|
* @ORM\Column(type="string", length=30, nullable=true)
|
|
*/
|
|
protected $contact_num;
|
|
|
|
// customer address
|
|
/**
|
|
* @ORM\Column(type="string", length=280, nullable=true)
|
|
*/
|
|
protected $cust_address;
|
|
|
|
// date purchase as specified by customer
|
|
// TODO: currently this does not affect warranty, someone will have to view this and set
|
|
// actual purchase date
|
|
/**
|
|
* @ORM\Column(type="date", nullable=true)
|
|
*/
|
|
protected $date_purchase_cust;
|
|
|
|
// if the warranty has been validated by an agent
|
|
/**
|
|
* @ORM\Column(type="boolean", options={"default": false})
|
|
*/
|
|
protected $flag_validated;
|
|
|
|
// link to customer
|
|
// TODO: check if this is the best way to do it, we'll be creating a new customer for every warranty since there is no reliable way to match customer to existing
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity="Customer")
|
|
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
|
|
*/
|
|
protected $customer;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=11, nullable=true)
|
|
*/
|
|
protected $province_id;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=11, nullable=true)
|
|
*/
|
|
protected $municipality_id;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=80, options={"default": "legacy"})
|
|
*/
|
|
protected $create_source;
|
|
|
|
/**
|
|
* @ORM\Column(type="string", length=80, nullable=true)
|
|
*/
|
|
protected $dealer_branch_code;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=80, options={"default": ""})
|
|
*/
|
|
protected $outlet_name;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=30, options={"default": ""})
|
|
*/
|
|
protected $outlet_contact_num;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=80, options={"default": ""})
|
|
*/
|
|
protected $sender_name;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=30, options={"default": ""})
|
|
*/
|
|
protected $sender_contact_num;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=180, options={"default": ""})
|
|
*/
|
|
protected $outlet_address;
|
|
|
|
// for non-motiv warranties created via admin panel
|
|
/**
|
|
* @ORM\Column(type="string", length=30, options={"default": ""})
|
|
*/
|
|
protected $sales_invoice_num;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->date_create = new DateTime();
|
|
$this->warranty_class = WarrantyClass::WTY_PRIVATE;
|
|
$this->status = WarrantyStatus::ACTIVE;
|
|
$this->date_claim = null;
|
|
$this->flag_activated = false;
|
|
$this->email = '';
|
|
$this->odometer = 0;
|
|
$this->flag_validated = false;
|
|
$this->create_source = 'unknown';
|
|
|
|
$this->outlet_name = '';
|
|
$this->outlet_contact_num = '';
|
|
$this->sender_name = '';
|
|
$this->sender_contact_num = '';
|
|
$this->outlet_address = '';
|
|
$this->sales_invoice_num = '';
|
|
}
|
|
|
|
public function getID()
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setSerial($serial = null)
|
|
{
|
|
$this->serial = $serial;
|
|
return $this;
|
|
}
|
|
|
|
public function getSerial()
|
|
{
|
|
return $this->serial;
|
|
}
|
|
|
|
public function setWarrantyClass($class)
|
|
{
|
|
$this->warranty_class = $class;
|
|
return $this;
|
|
}
|
|
|
|
public function getWarrantyClass()
|
|
{
|
|
return $this->warranty_class;
|
|
}
|
|
|
|
// TODO: use a service to handle plate number filtering
|
|
public static function cleanPlateNumber($plate)
|
|
{
|
|
// trim and make upper case
|
|
$clean_plate = strtoupper(trim($plate));
|
|
|
|
// check if alphanumeric, max length is 11, no spaces
|
|
$res = preg_match("/^[A-Z0-9]{1,11}+$/", $clean_plate);
|
|
if ($res)
|
|
return $clean_plate;
|
|
|
|
return false;
|
|
|
|
// remove invalid characters
|
|
//$clean_plate = preg_replace("/[^A-Z0-9]/", '', $clean_plate);
|
|
|
|
// check for 4 to 5 digit diplomatic plate
|
|
//$res = preg_match("/^[0-9]{4,5}$/", $clean_plate);
|
|
//if ($res)
|
|
// return $clean_plate;
|
|
|
|
// ABC-1234 or ABC-123 or ABC-12 format
|
|
//$res = preg_match("/^[A-Z]{3}[0-9]{2,4}$/", $clean_plate);
|
|
//if ($res)
|
|
// return $clean_plate;
|
|
|
|
// AB-123 or AB-12345 or AB-1234 format (motorcycles)
|
|
//$res = preg_match("/^[A-Z]{2}[0-9]{3,5}$/", $clean_plate);
|
|
//if ($res)
|
|
// return $clean_plate;
|
|
|
|
// 1234-AB format (motorcycles)
|
|
//$res = preg_match("/^[0-9]{4}[A-Z]{2}$/", $clean_plate);
|
|
//if ($res)
|
|
// return $clean_plate;
|
|
|
|
//return false;
|
|
}
|
|
|
|
public function setPlateNumber($plate)
|
|
{
|
|
// TODO: custom exception
|
|
$plate_number = $this->cleanPlateNumber($plate);
|
|
if (!$plate_number)
|
|
throw new Exception('Invalid plate number.');
|
|
|
|
$this->plate_number = $plate_number;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPlateNumber()
|
|
{
|
|
return $this->plate_number;
|
|
}
|
|
|
|
public function setFirstName($fname = null)
|
|
{
|
|
$this->first_name = $fname;
|
|
return $this;
|
|
}
|
|
|
|
public function getFirstName()
|
|
{
|
|
return $this->first_name;
|
|
}
|
|
|
|
public function setLastName($lname = null)
|
|
{
|
|
$this->last_name = $lname;
|
|
return $this;
|
|
}
|
|
|
|
public function getLastName()
|
|
{
|
|
return $this->last_name;
|
|
}
|
|
|
|
public function setEmail($email)
|
|
{
|
|
$this->email = $email;
|
|
return $this;
|
|
}
|
|
|
|
public function getEmail()
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setMobileNumber($mnum = null)
|
|
{
|
|
$this->mobile_number = $mnum;
|
|
return $this;
|
|
}
|
|
|
|
public function getMobileNumber()
|
|
{
|
|
return $this->mobile_number;
|
|
}
|
|
|
|
public function setBatteryModel(BatteryModel $model = null)
|
|
{
|
|
$this->bty_model = $model;
|
|
return $this;
|
|
}
|
|
|
|
public function getBatteryModel()
|
|
{
|
|
return $this->bty_model;
|
|
}
|
|
|
|
public function setBatterySize(BatterySize $size = null)
|
|
{
|
|
$this->bty_size = $size;
|
|
return $this;
|
|
}
|
|
|
|
public function getBatterySize()
|
|
{
|
|
return $this->bty_size;
|
|
}
|
|
|
|
public function setSAPBattery(SAPBattery $sap_bty = null)
|
|
{
|
|
$this->sap_bty = $sap_bty;
|
|
return $this;
|
|
}
|
|
|
|
public function getSAPBattery()
|
|
{
|
|
return $this->sap_bty;
|
|
}
|
|
|
|
public function setStatus($status)
|
|
{
|
|
$this->status = $status;
|
|
return $this;
|
|
}
|
|
|
|
public function getStatus()
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function getDateCreate()
|
|
{
|
|
return $this->date_create;
|
|
}
|
|
|
|
public function setDatePurchase(DateTime $date)
|
|
{
|
|
$this->date_purchase = $date;
|
|
return $this;
|
|
}
|
|
|
|
public function getDatePurchase()
|
|
{
|
|
return $this->date_purchase;
|
|
}
|
|
|
|
public function setDateExpire(DateTime $date)
|
|
{
|
|
$this->date_expire = $date;
|
|
return $this;
|
|
}
|
|
|
|
public function getDateExpire()
|
|
{
|
|
return $this->date_expire;
|
|
}
|
|
|
|
public function setDateClaim(DateTime $date = null)
|
|
{
|
|
$this->date_claim = $date;
|
|
return $this;
|
|
}
|
|
|
|
public function getDateClaim()
|
|
{
|
|
return $this->date_claim;
|
|
}
|
|
|
|
public function canClaim()
|
|
{
|
|
if ($this->status == WarrantyStatus::ACTIVE)
|
|
return true;
|
|
|
|
if ($this->status == WarrantyStatus::CLAIMED)
|
|
return false;
|
|
|
|
return false;
|
|
}
|
|
|
|
public function setClaimedFrom($claim_from)
|
|
{
|
|
$this->claim_form = $claim_from;
|
|
return $this;
|
|
}
|
|
|
|
public function getClaimedFrom()
|
|
{
|
|
return $this->claim_from;
|
|
}
|
|
|
|
public function setActivated($flag_activated = true)
|
|
{
|
|
$this->flag_activated = $flag_activated;
|
|
return $this;
|
|
}
|
|
|
|
public function isActivated()
|
|
{
|
|
return $this->flag_activated;
|
|
}
|
|
|
|
public function hasPrivacyPolicy()
|
|
{
|
|
if ($this->privacy_policy == null)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public function setPrivacyPolicy($privacy_policy)
|
|
{
|
|
$this->privacy_policy = $privacy_policy;
|
|
return $this;
|
|
}
|
|
|
|
public function getPrivacyPolicy()
|
|
{
|
|
return $this->privacy_policy;
|
|
}
|
|
|
|
public function setFileInvoice($file = null)
|
|
{
|
|
$this->file_invoice = $file;
|
|
return $this;
|
|
}
|
|
|
|
public function getFileInvoice()
|
|
{
|
|
return $this->file_invoice;
|
|
}
|
|
|
|
public function setFileWarrantyCard($file = null)
|
|
{
|
|
$this->file_warr_card = $file;
|
|
return $this;
|
|
}
|
|
|
|
public function getFileWarrantyCard()
|
|
{
|
|
return $this->file_warr_card;
|
|
}
|
|
|
|
public function setVehicle(Vehicle $v = null)
|
|
{
|
|
$this->vehicle = $v;
|
|
return $this;
|
|
}
|
|
|
|
public function getVehicle()
|
|
{
|
|
return $this->vehicle;
|
|
}
|
|
|
|
public function setVehicleModelYear($year)
|
|
{
|
|
$this->v_model_year = $year;
|
|
return $this;
|
|
}
|
|
|
|
public function getVehicleModelYear()
|
|
{
|
|
return $this->v_model_year;
|
|
}
|
|
|
|
public function setOdometer($odometer)
|
|
{
|
|
$this->odometer = $odometer;
|
|
return $this;
|
|
}
|
|
|
|
public function getOdometer()
|
|
{
|
|
return $this->odometer;
|
|
}
|
|
|
|
public function setDealerName($name)
|
|
{
|
|
$this->dealer_name = $name;
|
|
return $this;
|
|
}
|
|
|
|
public function getDealerName()
|
|
{
|
|
return $this->dealer_name;
|
|
}
|
|
|
|
public function setDealerAddress($address)
|
|
{
|
|
$this->dealer_address = $address;
|
|
return $this;
|
|
}
|
|
|
|
public function getDealerAddress()
|
|
{
|
|
return $this->dealer_address;
|
|
}
|
|
|
|
public function setContactNumber($contact_num)
|
|
{
|
|
$this->contact_num = $contact_num;
|
|
return $this;
|
|
}
|
|
|
|
public function getContactNumber()
|
|
{
|
|
return $this->contact_num;
|
|
}
|
|
|
|
public function setCustomerAddress($address)
|
|
{
|
|
$this->cust_address = $address;
|
|
return $this;
|
|
}
|
|
|
|
public function getCustomerAddress()
|
|
{
|
|
return $this->cust_address;
|
|
}
|
|
|
|
public function setDatePurchaseCustomer($date)
|
|
{
|
|
$this->date_purchase_cust = $date;
|
|
return $this;
|
|
}
|
|
|
|
public function getDatePurchaseCustomer()
|
|
{
|
|
return $this->date_purchase_cust;
|
|
}
|
|
|
|
public function setValidated($bool = true)
|
|
{
|
|
$this->flag_validated = $bool;
|
|
return $this;
|
|
}
|
|
|
|
public function isValidated()
|
|
{
|
|
return $this->flag_validated;
|
|
}
|
|
|
|
public function setCustomer(Customer $customer = null)
|
|
{
|
|
$this->customer = $customer;
|
|
return $this;
|
|
}
|
|
|
|
public function getCustomer()
|
|
{
|
|
return $this->customer;
|
|
}
|
|
|
|
public function setProvinceID($province_id)
|
|
{
|
|
$this->province_id = $province_id;
|
|
return $this;
|
|
}
|
|
|
|
public function getProvinceID()
|
|
{
|
|
return $this->province_id;
|
|
}
|
|
|
|
public function setMunicipalityID($municipality_id)
|
|
{
|
|
$this->municipality_id = $municipality_id;
|
|
return $this;
|
|
}
|
|
|
|
public function getMunicipalityID()
|
|
{
|
|
return $this->municipality_id;
|
|
}
|
|
|
|
public function setCreateSource($source)
|
|
{
|
|
$this->create_source = $source;
|
|
return $this;
|
|
}
|
|
|
|
public function getCreateSource()
|
|
{
|
|
return $this->create_source;
|
|
}
|
|
|
|
public function setDealerBranchCode($dealer_branch_code)
|
|
{
|
|
$this->dealer_branch_code = $dealer_branch_code;
|
|
return $this;
|
|
}
|
|
|
|
public function getDealerBranchCode()
|
|
{
|
|
return $this->dealer_branch_code;
|
|
}
|
|
|
|
public function setOutletName($outlet_name)
|
|
{
|
|
$this->outlet_name = $outlet_name;
|
|
return $this;
|
|
}
|
|
|
|
public function getOutletName()
|
|
{
|
|
return $this->outlet_name;
|
|
}
|
|
|
|
public function setOutletContactNumber($outlet_contact_num)
|
|
{
|
|
$this->outlet_contact_num = $outlet_contact_num;
|
|
return $this;
|
|
}
|
|
|
|
public function getOutletContactNumber()
|
|
{
|
|
return $this->outlet_contact_num;
|
|
}
|
|
|
|
public function setSenderName($sender_name)
|
|
{
|
|
$this->sender_name = $sender_name;
|
|
return $this;
|
|
}
|
|
|
|
public function getSenderName()
|
|
{
|
|
return $this->sender_name;
|
|
}
|
|
|
|
public function setSenderContactNumber($sender_contact_num)
|
|
{
|
|
$this->sender_contact_num = $sender_contact_num;
|
|
return $this;
|
|
}
|
|
|
|
public function getSenderContactNumber()
|
|
{
|
|
return $this->sender_contact_num;
|
|
}
|
|
|
|
public function setOutletAddress($outlet_address)
|
|
{
|
|
$this->outlet_address = $outlet_address;
|
|
return $this;
|
|
}
|
|
|
|
public function getOutletAddress()
|
|
{
|
|
return $this->outlet_address;
|
|
}
|
|
|
|
public function setSalesInvoiceNumber($sales_invoice_num)
|
|
{
|
|
$this->sales_invoice_num = $sales_invoice_num;
|
|
return $this;
|
|
}
|
|
|
|
public function getSalesInvoiceNumber()
|
|
{
|
|
return $this->sales_invoice_num;
|
|
}
|
|
}
|