GWM : policy report

This commit is contained in:
Gowtham M 2025-09-27 08:26:48 +05:30
parent 8e0a21a2a1
commit d3237f4a4a
4 changed files with 25 additions and 135 deletions

View File

@ -263,6 +263,12 @@ class AgentController extends ResourceController
try{
$data = $this->request->getPost();
//duplicate check
$duplicateData = $this->AgentIncentiveFileModel->where('agent_id',$data['agent_id'])->where('incentive_month',$data['incentive_month'])->first();
if(!empty($duplicateData)){
return $this->respond(['status' => 'failed', 'code' => 200, 'data' => 'Duplicate Entry.'], 200);
}
// handle file uploads
$incentiveFile = $this->request->getFile('incentive_file_name');

View File

@ -36,15 +36,16 @@ class EnquiryController extends ResourceController
$staff_id = $this->request->getGet('staff_id');
$enquiry_id = $this->request->getGet('enquiry_id');
$manager_id = $this->request->getGet('manager_id');
$only_policy_data = $this->request->getGet('only_policy_data') ?? false;
if (!empty($agent_id)) {
$data = $this->enquiryModel->getEnquiry('AGENT', $agent_id);
$data = $this->enquiryModel->getEnquiry('AGENT', $agent_id, $only_policy_data);
} elseif (!empty($staff_id)) {
$data = $this->enquiryModel->getEnquiry('STAFF', $staff_id);
$data = $this->enquiryModel->getEnquiry('STAFF', $staff_id, $only_policy_data);
} elseif (!empty($enquiry_id)) {
$data = $this->enquiryModel->getEnquiry('ENQUIRY',$enquiry_id);
$data = $this->enquiryModel->getEnquiry('ENQUIRY',$enquiry_id, $only_policy_data);
} elseif (!empty($manager_id)) {
$data = $this->enquiryModel->getEnquiry('MANAGER',$manager_id);
$data = $this->enquiryModel->getEnquiry('MANAGER',$manager_id, $only_policy_data);
} else {
$data = $this->enquiryModel->getEnquiry('ALL');
}
@ -104,6 +105,13 @@ class EnquiryController extends ResourceController
->where('partner_policy.quotation_id', $quotationId)
->where('partner_policy.is_active', 1)
->first();
if (!empty($policies)) {
$policies['issued_date'] = format_date_for_client($policies['issued_date'] ?? null);
$policies['start_date'] = format_date_for_client($policies['start_date'] ?? null);
$policies['end_date'] = format_date_for_client($policies['end_date'] ?? null);
}
}
// Final response
@ -120,7 +128,6 @@ class EnquiryController extends ResourceController
}
}
// CREATE enquiry
public function createEnquiry()
{
@ -300,7 +307,6 @@ class EnquiryController extends ResourceController
}
}
// Download enquiry file
public function downloadEnquiryFile()
{

View File

@ -10,8 +10,6 @@ use App\Models\PtCoShareDetailsModel;
use App\Models\VehicleModel;
if (!function_exists('createBDS')) {
function createBDS(array $policyData, int $policyId)
{
$enquiryModel = new EnquiryModel();
@ -157,130 +155,11 @@ if (!function_exists('createBDS')) {
return $log; // return logs for debugging
}
// function createClientAndVehicle(array $policyData, int $policyId)
// {
// $enquiryModel = new EnquiryModel();
// $quotationModel = new QuotationModel();
// $policyModel = new PolicyModel();
// $clientModel = new ClientModel();
// $clientPolicyModel = new ClientPolicyModel();
// $policyTransactionModel = new PolicyTransactionModel();
// $ptCoShareDetailsModel = new PtCoShareDetailsModel();
// $vehicleModel = new VehicleModel();
// // 1. Create client
// $clientData = [
// 'client_type' => 2,
// 'client_name' => $policyData['client_name'],
// 'short_name' => $policyData['client_name'],
// 'phone' => $policyData['client_mobile'],
// 'email' => $policyData['client_email'],
// 'created_by' => $policyData['created_by']
// ];
// $clientId = $clientModel->insert($clientData, true); // returns insert ID
// // 2. Create client policy
// $clientPolicyData = [
// 'client_id' => $clientId,
// 'policy_id' => $policyData['id'],
// 'policy_type_id' => 8,
// 'insurer_id' => $policyData['insurer_id'],
// 'insurer_branch_id'=> $policyData['insurer_branch_id'],
// 'policy_start_date'=> $policyData['start_date'],
// 'policy_end_date' => $policyData['end_date'],
// 'policy_no' => $policyData['policy_number']
// ];
// $clientPolicyId = $clientPolicyModel->insert($clientPolicyData, true); // returns insert ID
// // 3. Create vehicle
// $vehicleData = [
// 'vehicle_no' => $policyData['reg_no'],
// 'type' => $policyData['vehicle_type_id'],
// 'description' => 'Motor Vehicle',
// 'owner' => $clientId,
// 'rc' => $policyData['reg_no'],
// 'created_by' => $policyData['created_by']
// ];
// $vehicleId = $vehicleModel->insert($vehicleData, true);
// // 4. Create policy transaction
// $policyTransactionData = [
// 'issuer' => 2,
// 'issue_type' => 1,
// 'client_id' => $clientId ?? null,
// 'policy_type_id' => 8 ,
// 'client_policy_id' => $clientPolicyId ?? null,
// 'insurer_id' => $policyData['insurer_id'] ?? null,
// 'insurer_branch_id' => $policyData['insurer_branch_id'],
// 'vehicle_id' => $vehicleId ?? null,
// 'policy_no' => $policyData['policy_number'] ?? null,
// 'policy_issue_date' => $policyData['issued_date'],
// 'month' => $policyData['issued_date'], // policy_issue_month
// 'policy_start_date' => $policyData['start_date'],
// 'policy_end_date' => $policyData['end_date'],
// 'endorsement_no' => null,
// 'action_type' => 'inception',
// 'revenue_type' => "NA" ?? null,
// 'status' => 'completed',
// 'policy_holder_name' => $policyData['insured_name'], // insured name
// 'ct_type' => 1,
// 'sales_generated_by' => null, // ask this doubt
// 'serviced_by' => null, // ask this doubt
// 'policy_with_corr' => 0,
// 'is_active' => 1,
// 'ref' => null,
// 'co_share' => 0,
// 'endorse_eff_date' => null,
// 'pre_payable_by' => 1,
// 'bro_payable_by' => 1,
// ];
// $policyTransactionId = $policyTransactionModel->insert($policyTransactionData, true);
// // 5. Create pt co share details
// $pt_co_share_details = [
// 'pt_id' => $policyTransactionId,
// 'insurer_id' => $policyData['insurer_id'],
// 'insurer_branch_id' => $policyData['insurer_branch_id'],
// 'co_share_type' => 1,
// 'co_share_per' => 100,
// 'bp_amt' => $policyData['premium_amount'], // premium amt
// 'cop_amt' => $policyData['premium_amount'], // premium amt
// ];
// $ptCoShareId = $ptCoShareDetailsModel->insert($vehicleData, true);
// // Finally Update policy with client_id & vehicle_id
// $policyModel->update($policyId, [
// 'client_id' => $clientId,
// 'client_policy_id' => $clientPolicyId,
// 'vehicle_id' => $vehicleId,
// 'policy_transaction_id' => $policyTransactionId,
// 'pt_oc_share_details_id'=> $ptCoShareId,
// 'updated_by' => $policyData['created_by'],
// 'updated_on' => date('Y-m-d H:i:s')
// ]);
// }
}
if (!function_exists('format_date_for_database')) {
/**
* Converts a date from 'd-m-Y' to 'Y-m-d'.
*
* @param string $date
* @return string|null
*/
function format_date_for_database(string $date): ?string
{
$dt = DateTime::createFromFormat('d-m-Y', $date);
@ -293,12 +172,7 @@ if (!function_exists('format_date_for_database')) {
}
if (!function_exists('format_date_for_client')) {
/**
* Converts a date from 'Y-m-d' to 'd-m-Y'.
*
* @param string $date
* @return string|null
*/
function format_date_for_client(string $date): ?string
{
$dt = DateTime::createFromFormat('Y-m-d', $date);

View File

@ -35,7 +35,7 @@ class EnquiryModel extends Model
protected $updatedField = 'updated_on';
public function getEnquiry($getBy = null , $Id = null )
public function getEnquiry($getBy = null , $Id = null , $only_policy_data = false)
{
$data = $this->select('partner_enquiry.*,
VT.vehicle_type as vehicle_type,
@ -57,6 +57,10 @@ class EnquiryModel extends Model
->where('partner_enquiry.is_active', 1)
->orderBy('partner_enquiry.created_on', 'ASC');
if($only_policy_data){
$data->where('P.id IS NOT NULL');
}
if($getBy == 'ALL')
{