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'; } 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; } }