From 8d2ac35c091f9ce352b72a72c4bf92e902c43da3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 10 Jan 2023 09:27:44 +0000 Subject: [PATCH] Add function to form the data for the insurance application. #727 --- src/Insurance/ClientData.php | 299 ++++++++++++++++++++++++++++- src/Service/InsuranceConnector.php | 60 +++++- 2 files changed, 348 insertions(+), 11 deletions(-) diff --git a/src/Insurance/ClientData.php b/src/Insurance/ClientData.php index d9d392e8..68113f32 100644 --- a/src/Insurance/ClientData.php +++ b/src/Insurance/ClientData.php @@ -34,12 +34,12 @@ class ClientData protected $year_model; // year model of vehicle. Mandatory. Integer. protected $mv_type_id; // LTO mv type. Mandatory. Integer. protected $body_type; // vehicle body type. Mandatory. String. - protected $is_public; // public vehicle or not? Mandatory. Boolean. + protected $flag_public; // public vehicle or not? Mandatory. Boolean. protected $line; // defines where vehicle should be part of. Mandatory. String. Valid values are: PCOC - Private Car, MCOC - Mototcycle/Motorcycle with Sidecar/Tricycle(is_public is false), CCOC - Commercial Vehicle, LCOC - Motorcycle with sidecar/Tricycle(is_public is true) public function __construct() { - $this->client_type = 'I'; + $this->client_type = ''; $this->first_name = ''; $this->middle_name = ''; $this->surname = ''; @@ -66,11 +66,304 @@ class ClientData $this->year_model = 0; $this->mv_type_id = 0; $this->body_type = ''; - $this->is_public = false; + $this->flag_public = false; $this->line = ''; } public function setClientType($client_type) { + $this->client_type = $client_type; + return $this; + } + + public function getClientType() + { + return $this->client_type; + } + + public function setFirstName($first_name) + { + $this->first_name = $first_name; + return $this; + } + + public function getFirstName() + { + return $this->first_name; + } + + public function setMiddleName($middle_name) + { + $this->middle_name = $middle_name; + return $this; + } + + public function getMiddleName() + { + return $this->middle_name; + } + + public function setSurname($surname) + { + $this->surname = $surname; + return $this; + } + + public function getSurname() + { + return $this->surname; + } + + public function setCorporateName($corporate_name) + { + $this->corporate_name = $corporate_name; + return $this; + } + + public function getCorporateName() + { + return $this->corporate_name; + } + + public function setAddressNumber($address_number) + { + $this->address_number = $address_number; + return $this; + } + + public function getAddressNumber() + { + return $this->address_number; + } + + public function setAddressStreet($address_street) + { + $this->address_street = $address_street; + return $this; + } + + public function getAddressStreet() + { + return $this->address_street; + } + + public function setAdddressBuilding($address_building) + { + $this->address_building = $address_building; + return $this; + } + + public function getAdddressBuilding() + { + return $this->address_building; + } + + public function setAddressBarangay($address_barangay) + { + $this->address_barangay = $address_barangay; + return $this; + } + + public function getAddressBarangay() + { + return $this->address_barangay; + } + + public function setAddressCity($address_city) + { + $this->address_city = $address_city; + return $this; + } + + public function getAddressCity() + { + return $this->address_city; + } + + public function setAddressProvince($address_province) + { + $this->address_province = $address_province; + return $this; + } + + public function getAddressProvince() + { + return $this->address_province; + } + + public function setZipcode($zipcode) + { + $this->zipcode = $zipcode; + return $this; + } + + public function getZipcode() + { + return $this->zipcode; + } + + public function setMobileNumber($mobile_number) + { + $this->mobile_number = $mobile_number; + return $this; + } + + public function getMobileNumber() + { + return $this->mobile_number; + } + + public function setEmailAddress($email_address) + { + $this->email_address = $email_address; + return $this; + } + + public function getEmailAddress() + { + return $this->email_address; + } + + public function setMake($make) + { + $this->make = $make; + return $this; + } + + public function getMake() + { + return $this->make; + } + + public function setModel($model) + { + $this->model = $model; + return $this; + } + + public function getModel() + { + return $this->model; + } + + public function setSeries($series) + { + $this->series = $series; + return $this; + } + + public function getSeries() + { + return $this->series; + } + + public function setColor($color) + { + $this->color = $color; + return $this; + } + + public function getColor() + { + return $this->color; + } + + public function setPlateNumber($plate_number) + { + $this->plate_number = $plate_number; + return $this; + } + + public function getPlateNumber() + { + return $this->plate_number; + } + + public function setMvFileNumber($mv_file_number) + { + $this->mv_file_number = $mv_file_number; + return $this; + } + + public function getMvFileNumber() + { + return $this->mv_file_number; + } + + public function setMotorNumber($motor_number) + { + $this->motor_number = $motor_number; + return $this; + } + + public function getMotorNumber() + { + return $this->motor_number; + } + + public function setSerialChassis($serial_chassis) + { + $this->serial_chassis = $serial_chassis; + return $this; + } + + public function getSerialChassis() + { + return $this->serial_chassis; + } + + public function setYearModel($year_model) + { + $this->year_model = $year_model; + return $this; + } + + public function getYearModel() + { + return $this->year_model; + } + + public function setMvTypeID($mv_type_id) + { + $this->mv_type_id = $mv_type_id; + return $this; + } + + public function getMvTypeID() + { + return $this->mv_type_id; + } + + public function setBodyType($body_type) + { + $this->body_type = $body_type; + return $this; + } + + public function getBodyType() + { + return $this->body_type; + } + + public function setLine($line) + { + $this->line = $line; + return $this; + } + + public function getLine() + { + return $this->line; + } + + public function setPublic($flag_public = true) + { + $this->flag_public = $flag_public; + return $this; + } + + public function isPublic() + { + return $this->flag_public; } } diff --git a/src/Service/InsuranceConnector.php b/src/Service/InsuranceConnector.php index f72a0b10..fbf306f6 100644 --- a/src/Service/InsuranceConnector.php +++ b/src/Service/InsuranceConnector.php @@ -2,6 +2,12 @@ namespace App\Service; +use App\Entity\MotorVehicleType; + +use App\Insurance\ClientData; +use App\Insurance\LineType; +use App\Insurance\ClientType; + class InsuranceConnector { protected $base_url; @@ -18,20 +24,58 @@ class InsuranceConnector $this->token = $token; } - // TODO: create a function that builds the client data to be sent - // might need to rethink ClientData. It might be easier to break ClientData apart into three - // separate structures - - // TODO: error handling - - public function createApplication($client_info = [], $client_contact_info = [], $car_info = []) + public function createClientData(ClientData $client_data) { - $body = [ + // transform ClientData into the format needed for insurance application + $client_info = [ + 'client_type' => $client_data->getClientType(), + 'first_name' => $client_data->getFirstName(), + 'middle_name' => $client_data->getMiddleName(), + 'surname' => $client_data->getSurname(), + 'corporate_name' => $client_data->getCorporateName(), + ]; + + $client_contact_info = [ + 'address_number' => $client_data->getAddressNumber(), + 'address_street' => $client_data->getAddressStreet(), + 'address_building' => $client_data->getAddressBuilding(), + 'address_barangay' => $client_data->getAddressBarangay(), + 'address_city' => $client_data->getAddressCity(), + 'address_province' => $client_data->getAddressProvince(), + 'zipcode' => $client_data->getZipcode(), + 'mobile_number' => $cilent_data->getMobileNumber(), + 'email_address' => $client_data->getEmailAddress(), + ]; + + $car_info = [ + 'make' => $client_data->getMake(), + 'model' => $client_data->getModel(),, + 'series' => $client_data->getSeries(), + 'color' => $client_data->getColor(), + 'plate_number' => $client_data->getPlateNumber(), + 'mv_file_number' => $client_data->getMvFileNumber(), + 'motor_number' => $client_data->getMotorNumber(), + 'serial_chasis' => $client_data->getSerialChassis(), + 'year_model' => $client_data->getYearModel(), + 'mv_type_id' => $client_data->getMvTypeID(), + 'body_type' => $client_data->getBodyType(), + 'is_public' => $client_data->isPublic(), + 'line' => $client_data->getLine(), + ]; + + $app_data = [ 'client_info' => $client_info, 'client_contact_info' => $client_contact_info, 'car_info' => $car_info, ]; + $result = $this->createApplication($app_data); + + // TODO: error handling + } + + protected function createApplication($body) + { $body_text = json_encode($body); // generate token for basic authorization