80 lines
3.0 KiB
PHP
80 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class MotorQuoteModel extends Model
|
|
{
|
|
protected $table = 'motor_quote';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [
|
|
'enquiry_id', 'quote_number', 'application_id', 'policy_holder_type',
|
|
'insurance_product_code', 'sub_insurance_product_code',
|
|
'previous_insurer_code', 'previous_policy_expiry_date', 'external_policy_number',
|
|
'is_ncb_transfer', 'start_date', 'end_date', 'pincode',
|
|
'coverage_details', 'policyholder_details', 'premium', 'idv', 'status',
|
|
'created_at', 'updated_at',
|
|
];
|
|
protected $useTimestamps = true;
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
|
|
public function getListWithVehicle(array $filters = []): array
|
|
{
|
|
$builder = $this->db->table('motor_quote q')
|
|
->select('q.*, v.license_plate_number, v.vehicle_maincode, v.registration_date')
|
|
->join('motor_vehicle v', 'v.quote_id = q.id', 'left')
|
|
->orderBy('q.id', 'DESC');
|
|
|
|
if (!empty($filters['status'])) {
|
|
$builder->where('q.status', $filters['status']);
|
|
}
|
|
if (!empty($filters['enquiry_id'])) {
|
|
$builder->like('q.enquiry_id', $filters['enquiry_id']);
|
|
}
|
|
if (!empty($filters['quote_number'])) {
|
|
$builder->like('q.quote_number', $filters['quote_number']);
|
|
}
|
|
if (!empty($filters['license_plate'])) {
|
|
$builder->like('v.license_plate_number', $filters['license_plate']);
|
|
}
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
|
|
public function getDetail(int $quoteId): ?array
|
|
{
|
|
$quote = $this->find($quoteId);
|
|
if (!$quote) {
|
|
return null;
|
|
}
|
|
|
|
$vehicleModel = new MotorVehicleModel();
|
|
$kycModel = new MotorKycModel();
|
|
$paymentModel = new MotorPaymentModel();
|
|
$policyModel = new MotorPolicyModel();
|
|
|
|
$quote['vehicle'] = $vehicleModel->where('quote_id', $quoteId)->first();
|
|
$quote['kyc'] = $kycModel->where('quote_id', $quoteId)->orderBy('id', 'DESC')->first();
|
|
$quote['payment'] = $paymentModel->where('quote_id', $quoteId)->orderBy('id', 'DESC')->first();
|
|
$quote['policy'] = $policyModel->where('quote_id', $quoteId)->first();
|
|
|
|
if (!empty($quote['coverage_details']) && is_string($quote['coverage_details'])) {
|
|
$quote['coverage_details'] = json_decode($quote['coverage_details'], true);
|
|
}
|
|
if (!empty($quote['policyholder_details']) && is_string($quote['policyholder_details'])) {
|
|
$quote['policyholder_details'] = json_decode($quote['policyholder_details'], true);
|
|
}
|
|
if (!is_array($quote['policyholder_details'] ?? null)) {
|
|
$quote['policyholder_details'] = [];
|
|
}
|
|
|
|
return $quote;
|
|
}
|
|
}
|