Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
847719fd92
@ -421,6 +421,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
|
||||
$routes->match(['get', 'post', 'delete'], 'nhanceBranchMaster', 'MasterController::nhanceBranchMaster');
|
||||
$routes->match(['get', 'post', 'delete'], 'vehicleTypeMaster', 'MasterController::vehicleTypeMaster');
|
||||
$routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster');
|
||||
$routes->match(['get', 'post', 'delete'], 'partnerPOS', 'MasterController::partnerPOS');
|
||||
$routes->get('checkDuplicateCdAccount', 'MasterController::checkDuplicateCdAccount');
|
||||
$routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation');
|
||||
$routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable');
|
||||
@ -647,6 +648,11 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct
|
||||
$routes->get("ticketHistoryList", "ThzController::ticketHistoryList");
|
||||
$routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType');
|
||||
|
||||
//this route for nhance website contact form (sales/service)
|
||||
$routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) {
|
||||
$routes->post("ticketSave", "ThzController::ticketSave");
|
||||
});
|
||||
|
||||
|
||||
|
||||
//claims
|
||||
@ -776,7 +782,7 @@ $routes->get('testTracelog','TestBusinessController::a');
|
||||
$routes->get("claimView", "EmployeeRestController::claimView");
|
||||
|
||||
// General Tickets
|
||||
$routes->post("ticketSave", "ThzController::ticketSave");
|
||||
$routes->post("ticketSave", "ThzController::ticketSave"); //
|
||||
$routes->get("ticketList", "ThzController::ticketList");
|
||||
$routes->post("ticketConversationSave", "ThzController::ticketConversationSave");
|
||||
$routes->get("ticketConversationList", "ThzController::ticketConversationList");
|
||||
@ -852,3 +858,89 @@ $routes->group('logs', function($routes) {
|
||||
$routes->get('delete/(:segment)', 'LogController::delete/$1');
|
||||
$routes->get('clearAll', 'LogController::clearAll');
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
$routes->group('sales', function($routes) {
|
||||
|
||||
// ==================== LEAD ROUTES ====================
|
||||
|
||||
// Get all leads with filters
|
||||
$routes->get('leads', 'SalesController::getLeads');
|
||||
|
||||
// Get lead statistics
|
||||
$routes->get('leads/stats', 'SalesController::getLeadStats');
|
||||
|
||||
// Get single lead with complete details
|
||||
$routes->get('leads/(:num)', 'SalesController::getLead/$1');
|
||||
|
||||
// Create new lead
|
||||
$routes->post('leads', 'SalesController::createLead');
|
||||
|
||||
// Update lead
|
||||
$routes->put('leads/(:num)', 'SalesController::updateLead/$1');
|
||||
|
||||
// Delete lead
|
||||
$routes->delete('leads/(:num)', 'SalesController::deleteLead/$1');
|
||||
|
||||
// Get contacts for a lead
|
||||
$routes->get('leads/(:num)/contacts', 'SalesController::getContacts/$1');
|
||||
|
||||
// Get activities for a lead
|
||||
$routes->get('leads/(:num)/activities', 'SalesController::getLeadActivities/$1');
|
||||
|
||||
// Get activity timeline for a lead
|
||||
$routes->get('leads/(:num)/timeline', 'SalesController::getActivityTimeline/$1');
|
||||
|
||||
// Get notes for a lead
|
||||
$routes->get('leads/(:num)/notes', 'SalesController::getLeadNotes/$1');
|
||||
|
||||
// ==================== CONTACT PERSON ROUTES ====================
|
||||
|
||||
// Create contact person
|
||||
$routes->post('contacts', 'SalesController::createContact');
|
||||
|
||||
// Update contact person
|
||||
$routes->put('contacts/(:num)', 'SalesController::updateContact/$1');
|
||||
|
||||
// Delete contact person
|
||||
$routes->delete('contacts/(:num)', 'SalesController::deleteContact/$1');
|
||||
|
||||
// Set primary contact
|
||||
$routes->put('contacts/(:num)/set-primary', 'SalesController::setPrimaryContact/$1');
|
||||
|
||||
// ==================== ACTIVITY ROUTES ====================
|
||||
|
||||
// Get all activities with filters
|
||||
$routes->get('activities', 'SalesController::getActivities');
|
||||
|
||||
// Get upcoming activities
|
||||
$routes->get('activities/upcoming', 'SalesController::getUpcomingActivities');
|
||||
|
||||
// Get pending activities count
|
||||
$routes->get('activities/pending-count', 'SalesController::getPendingCount');
|
||||
|
||||
// Create activity
|
||||
$routes->post('activities', 'SalesController::createActivity');
|
||||
|
||||
// Update activity
|
||||
$routes->put('activities/(:num)', 'SalesController::updateActivity/$1');
|
||||
|
||||
// Complete activity
|
||||
$routes->post('activities/(:num)/complete', 'SalesController::completeActivity/$1');
|
||||
|
||||
// Delete activity
|
||||
$routes->delete('activities/(:num)', 'SalesController::deleteActivity/$1');
|
||||
|
||||
// ==================== NOTE ROUTES ====================
|
||||
|
||||
// Create note
|
||||
$routes->post('notes', 'SalesController::createNote');
|
||||
|
||||
// Update note
|
||||
$routes->put('notes/(:num)', 'SalesController::updateNote/$1');
|
||||
|
||||
// Delete note
|
||||
$routes->delete('notes/(:num)', 'SalesController::deleteNote/$1');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -726,7 +726,7 @@ class ClientController extends AdminController
|
||||
if ($requestFrom == 'rest') {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// print_rr($data);die();
|
||||
// Load the view for the new list page;
|
||||
echo view('layout/header', $headerData);
|
||||
echo view('view_deposit', $data);
|
||||
@ -741,12 +741,14 @@ class ClientController extends AdminController
|
||||
$client_id = $this->request->getPost('client_id');
|
||||
$insurer_id = $this->request->getPost('insurer_id');
|
||||
$record_date = $this->request->getPost('record_date');
|
||||
$cd_ac_pk = $this->request->getPost('cd_ac_pk');
|
||||
$cd_ac_no = $this->request->getPost('cd_ac_no');
|
||||
|
||||
$CD_Account_Number = $this->CDMasterModel
|
||||
->where('client_id', $client_id)
|
||||
->where('insurer_id', $insurer_id)
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
// $CD_Account_Number = $this->CDMasterModel
|
||||
// ->where('client_id', $client_id)
|
||||
// ->where('insurer_id', $insurer_id)
|
||||
// ->where('is_active', 1)
|
||||
// ->first();
|
||||
|
||||
|
||||
if (!empty($record_date)) {
|
||||
@ -762,8 +764,8 @@ class ClientController extends AdminController
|
||||
'sub_type_id' => $this->request->getPost('sub_type_id'),
|
||||
'client_id' => $this->request->getPost('client_id'),
|
||||
'client_policy_id' => null,
|
||||
'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null,
|
||||
'cd_ac_pk' => $CD_Account_Number['id'] ?? null,
|
||||
'cd_ac_no' => $cd_ac_no ?? null,
|
||||
'cd_ac_pk' => $cd_ac_pk ?? null,
|
||||
'endorsement_no' => null,
|
||||
'insurer_id' => $this->request->getPost('insurer_id'),
|
||||
'description' => $this->request->getPost('description'),
|
||||
@ -1099,6 +1101,8 @@ class ClientController extends AdminController
|
||||
|
||||
$kyc_id = $this->request->getPost('id');
|
||||
$client_id = $this->request->getPost('client_id');
|
||||
// echo "KID".$kyc_id;
|
||||
// echo "CID".$client_id;
|
||||
|
||||
if (empty($kyc_id)) {
|
||||
return $this->respond(['status' => false, 'code' => 400, 'message' => 'Missing document ID.'], 200);
|
||||
@ -1107,7 +1111,7 @@ class ClientController extends AdminController
|
||||
$updateData['is_active'] = $this->request->getPost('is_active');
|
||||
|
||||
$delete = $this->clientKYCDocsModel->update($kyc_id, $updateData);
|
||||
|
||||
// $delete = 1;
|
||||
if ($delete) {
|
||||
$html = $this->generateKycSingleTable($client_id);
|
||||
$dropdown = $this->fetch_dropdown($client_id);
|
||||
|
||||
@ -4413,7 +4413,8 @@ class EmployeeRestController extends AdminController
|
||||
{
|
||||
$client = \Config\Services::curlrequest();
|
||||
$url = env('PRE_ENROLLMENT_BASEURL') . $endPoint;
|
||||
$response = $client->post($url, ['json' => $postData, 'http_errors' => false]);
|
||||
$headers = [ 'App-Signature' => getenv('APP_SIGNATURE') ];
|
||||
$response = $client->post($url, ['json' => $postData,'headers' => $headers,'http_errors' => false]);
|
||||
// return json_decode($response->getBody(), true);
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ use App\Models\SettingsModel;
|
||||
use App\Models\VehicleModel;
|
||||
use App\Models\VehicleTypeModel;
|
||||
use App\Models\RTOModel;
|
||||
use App\Models\PartnerPosModel;
|
||||
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
@ -2320,4 +2321,141 @@ class MasterController extends AdminController
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public function partnerPOS()
|
||||
{
|
||||
$posModel = new PartnerPosModel();
|
||||
$method = $this->request->getMethod();
|
||||
|
||||
if ($this->request->getMethod() === 'post') {
|
||||
|
||||
$id = $this->request->getPost('pk');
|
||||
$data = $this->request->getPost();
|
||||
|
||||
unset($data['pk']);
|
||||
|
||||
try {
|
||||
// Certificate
|
||||
$certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files');
|
||||
if ($certificate !== null) { $data['certificate_file_name'] = $certificate; } else { unset($data['certificate_file_name']); }
|
||||
|
||||
// PAN file
|
||||
$panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files');
|
||||
if ($panFile !== null) { $data['pan_file_name'] = $panFile; } else { unset($data['pan_file_name']);}
|
||||
|
||||
// Aadhaar file
|
||||
$aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files');
|
||||
if ($aadharFile !== null) { $data['aadhar_file_name'] = $aadharFile; } else { unset($data['aadhar_file_name']);}
|
||||
|
||||
} catch (\RuntimeException $e) {
|
||||
return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $data ], 400);
|
||||
}
|
||||
|
||||
// INSERT / UPDATE
|
||||
if (empty($id)) {
|
||||
$status = $posModel->insert($data);
|
||||
} else {
|
||||
$status = $posModel->update($id, $data);
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
return $this->respond([ 'status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $data ], 200);
|
||||
}
|
||||
|
||||
return $this->respond([ 'status' => false, 'code' => 400, 'message' => 'Failed to update', 'data' => $data ], 400);
|
||||
}
|
||||
elseif ($method === 'get') {
|
||||
|
||||
$id = $this->request->getGet('pk') ?? null;
|
||||
|
||||
$db = db_connect();
|
||||
|
||||
$builder = $db->table('partner_staff');
|
||||
|
||||
$data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name')
|
||||
->where('partner_staff.is_active', 1)
|
||||
->where('partner_staff.role_id', 1)
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
|
||||
if (!empty($id)) {
|
||||
|
||||
$data['pos_list'] = $posModel
|
||||
->select('partner_pos.*, partner_staff.name AS manager_name')
|
||||
->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left')
|
||||
->where('partner_pos.id', $id)
|
||||
->orderBy('partner_pos.id', 'DESC')
|
||||
->findAll();
|
||||
|
||||
if (!empty($data)) {
|
||||
return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
$data['pos_list'] = $posModel
|
||||
->select('partner_pos.*, ps.name AS manager_name')
|
||||
->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left')
|
||||
->orderBy('partner_pos.id', 'DESC')
|
||||
->findAll();
|
||||
|
||||
|
||||
return $this->loadLayout('pos_list', ['data' => $data,'tab_name' => 'POS details','page_name' => 'POS details']);
|
||||
|
||||
} elseif ($method === 'delete') {
|
||||
|
||||
// $input = $this->request->getRawInput();
|
||||
$id = $this->request->getGet('pk'); // ✅ THIS
|
||||
$id = $id ?? null;
|
||||
|
||||
if (empty($id)) {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 404,
|
||||
'message' => 'No ID provided for deletion'
|
||||
], 200);
|
||||
}
|
||||
|
||||
$update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update();
|
||||
|
||||
if ($update_status) {
|
||||
return $this->respond([
|
||||
'status' => true,
|
||||
'code' => 200,
|
||||
'message' => 'Data removed successfully',
|
||||
'pk' => $id
|
||||
], 200);
|
||||
} else {
|
||||
return $this->respond([
|
||||
'status' => false,
|
||||
'code' => 400,
|
||||
'message' => 'Failed to remove data',
|
||||
'pk' => $id
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function uploadPOSFile(string $fieldName, string $uploadDir)
|
||||
{
|
||||
$file = $this->request->getFile($fieldName);
|
||||
|
||||
if (!$file || !$file->isValid()) { return null; }
|
||||
|
||||
$allowedMime = [ 'image/jpg', 'image/jpeg', 'image/png', 'image/webp', 'application/pdf'];
|
||||
|
||||
if (!in_array($file->getMimeType(), $allowedMime)) { throw new \RuntimeException('Invalid file format'); }
|
||||
|
||||
$path = ROOTPATH . 'public/uploads/' . $uploadDir . '/';
|
||||
|
||||
if (!is_dir($path)) { mkdir($path, 0755, true); }
|
||||
|
||||
$newName = $file->getRandomName();
|
||||
$file->move($path, $newName);
|
||||
|
||||
return $newName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -439,7 +439,7 @@ class PayoutController extends BaseController
|
||||
$agentCode = $agent["agent_code"];
|
||||
|
||||
$today = date("Ymd");
|
||||
$likePattern = "INV/$agentCode/$today/%";
|
||||
$likePattern = "NIIB/$agentCode/$today/%";
|
||||
|
||||
$count = $this->invoiceModel
|
||||
->like("invoice_no", $likePattern)
|
||||
@ -447,7 +447,7 @@ class PayoutController extends BaseController
|
||||
|
||||
$nextNumber = $count + 1;
|
||||
|
||||
return "INV/$agentCode/$today/$nextNumber";
|
||||
return "NIIB/$agentCode/$today/$nextNumber";
|
||||
}
|
||||
|
||||
// private function generateInvoiceNumber()
|
||||
|
||||
@ -1917,6 +1917,7 @@
|
||||
$data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']);
|
||||
$data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']);
|
||||
$data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']);
|
||||
$data['client_kyc_dd_data'] = $clientController->fetch_dropdown($data['client_id']);
|
||||
|
||||
$data['vehicle_docs'] = $this->clientKYCDocsModel
|
||||
->where('client_id', $data['client_id'])
|
||||
|
||||
695
app/Controllers/SalesController.php
Normal file
695
app/Controllers/SalesController.php
Normal file
@ -0,0 +1,695 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Api;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use App\Models\SalesActualLeadModel;
|
||||
use App\Models\SalesContactPersonModel;
|
||||
use App\Models\SalesActivityModel;
|
||||
use App\Models\SalesLeadNoteModel;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
class SalesController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
protected $leadModel;
|
||||
protected $contactModel;
|
||||
protected $activityModel;
|
||||
protected $noteModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->leadModel = new SalesActualLeadModel();
|
||||
$this->contactModel = new SalesContactPersonModel();
|
||||
$this->activityModel = new SalesActivityModel();
|
||||
$this->noteModel = new SalesLeadNoteModel();
|
||||
}
|
||||
|
||||
// ==================== LEAD APIs ====================
|
||||
|
||||
/**
|
||||
* Get all leads with pagination and filters
|
||||
* GET /api/sales/leads
|
||||
*/
|
||||
public function getLeads()
|
||||
{
|
||||
try {
|
||||
$limit = $this->request->getGet('limit') ?? 10;
|
||||
$offset = $this->request->getGet('offset') ?? 0;
|
||||
|
||||
$filters = [
|
||||
'status' => $this->request->getGet('status'),
|
||||
'assigned_to' => $this->request->getGet('assigned_to'),
|
||||
'search' => $this->request->getGet('search'),
|
||||
];
|
||||
|
||||
$result = $this->leadModel->getLeadsWithFilters($filters, $limit, $offset);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $result['data'],
|
||||
'total' => $result['total'],
|
||||
'limit' => $limit,
|
||||
'offset' => $offset
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single lead with complete details
|
||||
* GET /api/sales/leads/{id}
|
||||
*/
|
||||
public function getLead($id)
|
||||
{
|
||||
try {
|
||||
$lead = $this->leadModel->getLeadComplete($id);
|
||||
|
||||
if (!$lead) {
|
||||
return $this->failNotFound('Lead not found');
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $lead
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new lead
|
||||
* POST /api/sales/leads
|
||||
*/
|
||||
public function createLead()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
|
||||
// Set created_by and updated_by from authenticated user
|
||||
$data['created_by'] = $this->getUserId();
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->leadModel->insert($data)) {
|
||||
return $this->fail($this->leadModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$leadId = $this->leadModel->getInsertID();
|
||||
|
||||
// Insert contact persons if provided
|
||||
if (!empty($data['contact_persons'])) {
|
||||
foreach ($data['contact_persons'] as $contact) {
|
||||
$contact['lead_id'] = $leadId;
|
||||
$contact['created_by'] = $this->getUserId();
|
||||
$this->contactModel->insert($contact);
|
||||
}
|
||||
}
|
||||
|
||||
$lead = $this->leadModel->getLeadComplete($leadId);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Lead created successfully',
|
||||
'data' => $lead
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update lead
|
||||
* PUT /api/sales/leads/{id}
|
||||
*/
|
||||
public function updateLead($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->leadModel->find($id)) {
|
||||
return $this->failNotFound('Lead not found');
|
||||
}
|
||||
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->leadModel->update($id, $data)) {
|
||||
return $this->fail($this->leadModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$lead = $this->leadModel->getLeadComplete($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Lead updated successfully',
|
||||
'data' => $lead
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete lead
|
||||
* DELETE /api/sales/leads/{id}
|
||||
*/
|
||||
public function deleteLead($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->leadModel->find($id)) {
|
||||
return $this->failNotFound('Lead not found');
|
||||
}
|
||||
|
||||
$this->leadModel->delete($id);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Lead deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lead statistics
|
||||
* GET /api/sales/leads/stats
|
||||
*/
|
||||
public function getLeadStats()
|
||||
{
|
||||
try {
|
||||
$userId = $this->request->getGet('user_id');
|
||||
$stats = $this->leadModel->getLeadStats($userId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $stats
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== CONTACT PERSON APIs ====================
|
||||
|
||||
/**
|
||||
* Get contacts for a lead
|
||||
* GET /api/sales/leads/{leadId}/contacts
|
||||
*/
|
||||
public function getContacts($leadId)
|
||||
{
|
||||
try {
|
||||
$contacts = $this->contactModel->getContactsByLead($leadId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $contacts
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contact person
|
||||
* POST /api/sales/contacts
|
||||
*/
|
||||
public function createContact()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['created_by'] = $this->getUserId();
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->contactModel->insert($data)) {
|
||||
return $this->fail($this->contactModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$contactId = $this->contactModel->getInsertID();
|
||||
$contact = $this->contactModel->find($contactId);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Contact created successfully',
|
||||
'data' => $contact
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update contact person
|
||||
* PUT /api/sales/contacts/{id}
|
||||
*/
|
||||
public function updateContact($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->contactModel->find($id)) {
|
||||
return $this->failNotFound('Contact not found');
|
||||
}
|
||||
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->contactModel->update($id, $data)) {
|
||||
return $this->fail($this->contactModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$contact = $this->contactModel->find($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Contact updated successfully',
|
||||
'data' => $contact
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete contact person
|
||||
* DELETE /api/sales/contacts/{id}
|
||||
*/
|
||||
public function deleteContact($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->contactModel->find($id)) {
|
||||
return $this->failNotFound('Contact not found');
|
||||
}
|
||||
|
||||
$this->contactModel->delete($id);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Contact deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set primary contact
|
||||
* PUT /api/sales/contacts/{id}/set-primary
|
||||
*/
|
||||
public function setPrimaryContact($id)
|
||||
{
|
||||
try {
|
||||
$contact = $this->contactModel->find($id);
|
||||
|
||||
if (!$contact) {
|
||||
return $this->failNotFound('Contact not found');
|
||||
}
|
||||
|
||||
$this->contactModel->setPrimaryContact($id, $contact['lead_id']);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Primary contact updated successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== ACTIVITY APIs ====================
|
||||
|
||||
/**
|
||||
* Get all activities with filters
|
||||
* GET /api/sales/activities
|
||||
*/
|
||||
public function getActivities()
|
||||
{
|
||||
try {
|
||||
$limit = $this->request->getGet('limit') ?? 10;
|
||||
$offset = $this->request->getGet('offset') ?? 0;
|
||||
|
||||
$filters = [
|
||||
'status' => $this->request->getGet('status'),
|
||||
'activity_type' => $this->request->getGet('activity_type'),
|
||||
'assigned_to' => $this->request->getGet('assigned_to'),
|
||||
'date_from' => $this->request->getGet('date_from'),
|
||||
'date_to' => $this->request->getGet('date_to'),
|
||||
];
|
||||
|
||||
$result = $this->activityModel->getActivitiesWithFilters($filters, $limit, $offset);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $result['data'],
|
||||
'total' => $result['total'],
|
||||
'limit' => $limit,
|
||||
'offset' => $offset
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get activities for a specific lead
|
||||
* GET /api/sales/leads/{leadId}/activities
|
||||
*/
|
||||
public function getLeadActivities($leadId)
|
||||
{
|
||||
try {
|
||||
$status = $this->request->getGet('status');
|
||||
$activities = $this->activityModel->getActivitiesByLead($leadId, $status);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $activities
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get activity timeline for a lead
|
||||
* GET /api/sales/leads/{leadId}/timeline
|
||||
*/
|
||||
public function getActivityTimeline($leadId)
|
||||
{
|
||||
try {
|
||||
$timeline = $this->activityModel->getActivityTimeline($leadId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $timeline
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upcoming activities for user
|
||||
* GET /api/sales/activities/upcoming
|
||||
*/
|
||||
public function getUpcomingActivities()
|
||||
{
|
||||
try {
|
||||
$userId = $this->getUserId();
|
||||
$days = $this->request->getGet('days') ?? 7;
|
||||
$limit = $this->request->getGet('limit') ?? 10;
|
||||
|
||||
$activities = $this->activityModel->getUpcomingActivities($userId, $days, $limit);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $activities
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create activity
|
||||
* POST /api/sales/activities
|
||||
*/
|
||||
public function createActivity()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['created_by'] = $this->getUserId();
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->activityModel->insert($data)) {
|
||||
return $this->fail($this->activityModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$activityId = $this->activityModel->getInsertID();
|
||||
$activity = $this->activityModel->find($activityId);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Activity created successfully',
|
||||
'data' => $activity
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update activity
|
||||
* PUT /api/sales/activities/{id}
|
||||
*/
|
||||
public function updateActivity($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->activityModel->find($id)) {
|
||||
return $this->failNotFound('Activity not found');
|
||||
}
|
||||
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->activityModel->update($id, $data)) {
|
||||
return $this->fail($this->activityModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$activity = $this->activityModel->find($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Activity updated successfully',
|
||||
'data' => $activity
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete activity
|
||||
* POST /api/sales/activities/{id}/complete
|
||||
*/
|
||||
public function completeActivity($id)
|
||||
{
|
||||
try {
|
||||
$activity = $this->activityModel->find($id);
|
||||
|
||||
if (!$activity) {
|
||||
return $this->failNotFound('Activity not found');
|
||||
}
|
||||
|
||||
if ($activity['status'] === 'completed') {
|
||||
return $this->fail('Activity is already completed', ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
$this->activityModel->completeActivity($id, $data);
|
||||
|
||||
// Create follow-up activity if requested
|
||||
if (!empty($data['create_followup']) && $data['create_followup'] === true) {
|
||||
$followupData = [
|
||||
'lead_id' => $activity['lead_id'],
|
||||
'activity_type' => $data['followup_type'] ?? 'Call',
|
||||
'notes' => $data['followup_notes'] ?? '',
|
||||
'scheduled_date' => $data['followup_date'] ?? null,
|
||||
'assigned_to' => $activity['assigned_to'],
|
||||
'parent_activity_id' => $id,
|
||||
'created_by' => $this->getUserId(),
|
||||
'updated_by' => $this->getUserId(),
|
||||
];
|
||||
|
||||
$this->activityModel->insert($followupData);
|
||||
}
|
||||
|
||||
$updatedActivity = $this->activityModel->find($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Activity completed successfully',
|
||||
'data' => $updatedActivity
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete activity
|
||||
* DELETE /api/sales/activities/{id}
|
||||
*/
|
||||
public function deleteActivity($id)
|
||||
{
|
||||
try {
|
||||
if (!$this->activityModel->find($id)) {
|
||||
return $this->failNotFound('Activity not found');
|
||||
}
|
||||
|
||||
$this->activityModel->delete($id);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Activity deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pending activities count
|
||||
* GET /api/sales/activities/pending-count
|
||||
*/
|
||||
public function getPendingCount()
|
||||
{
|
||||
try {
|
||||
$userId = $this->getUserId();
|
||||
$count = $this->activityModel->getPendingActivitiesCount($userId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => ['count' => $count]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== LEAD NOTES APIs ====================
|
||||
|
||||
/**
|
||||
* Get notes for a lead
|
||||
* GET /api/sales/leads/{leadId}/notes
|
||||
*/
|
||||
public function getLeadNotes($leadId)
|
||||
{
|
||||
try {
|
||||
$notes = $this->noteModel->getNotesByLead($leadId);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'data' => $notes
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create note
|
||||
* POST /api/sales/notes
|
||||
*/
|
||||
public function createNote()
|
||||
{
|
||||
try {
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['user_id'] = $this->getUserId();
|
||||
$data['created_by'] = $this->getUserId();
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->noteModel->insert($data)) {
|
||||
return $this->fail($this->noteModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$noteId = $this->noteModel->getInsertID();
|
||||
$note = $this->noteModel->find($noteId);
|
||||
|
||||
return $this->respondCreated([
|
||||
'status' => 'success',
|
||||
'message' => 'Note created successfully',
|
||||
'data' => $note
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update note
|
||||
* PUT /api/sales/notes/{id}
|
||||
*/
|
||||
public function updateNote($id)
|
||||
{
|
||||
try {
|
||||
$note = $this->noteModel->find($id);
|
||||
|
||||
if (!$note) {
|
||||
return $this->failNotFound('Note not found');
|
||||
}
|
||||
|
||||
// Check if user owns the note
|
||||
if ($note['user_id'] != $this->getUserId()) {
|
||||
return $this->failUnauthorized('You are not authorized to update this note');
|
||||
}
|
||||
|
||||
$data = $this->request->getJSON(true);
|
||||
$data['updated_by'] = $this->getUserId();
|
||||
|
||||
if (!$this->noteModel->update($id, $data)) {
|
||||
return $this->fail($this->noteModel->errors(), ResponseInterface::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$updatedNote = $this->noteModel->find($id);
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'message' => 'Note updated successfully',
|
||||
'data' => $updatedNote
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete note
|
||||
* DELETE /api/sales/notes/{id}
|
||||
*/
|
||||
public function deleteNote($id)
|
||||
{
|
||||
try {
|
||||
$note = $this->noteModel->find($id);
|
||||
|
||||
if (!$note) {
|
||||
return $this->failNotFound('Note not found');
|
||||
}
|
||||
|
||||
// Check if user owns the note
|
||||
if ($note['user_id'] != $this->getUserId()) {
|
||||
return $this->failUnauthorized('You are not authorized to delete this note');
|
||||
}
|
||||
|
||||
$this->noteModel->delete($id);
|
||||
|
||||
return $this->respondDeleted([
|
||||
'status' => 'success',
|
||||
'message' => 'Note deleted successfully'
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== HELPER METHODS ====================
|
||||
|
||||
/**
|
||||
* Get current user ID from session or JWT token
|
||||
* You'll need to implement this based on your authentication system
|
||||
*/
|
||||
private function getUserId()
|
||||
{
|
||||
// If using session
|
||||
if (session()->has('user_id')) {
|
||||
return session()->get('user_id');
|
||||
}
|
||||
|
||||
// If using JWT, decode token and get user_id
|
||||
// Example: return $this->decodeJWT()['user_id'];
|
||||
|
||||
// For development/testing, you can return a default value
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -23,6 +23,7 @@ class InvoiceModel extends Model
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'payout_status',
|
||||
'broker_id'
|
||||
];
|
||||
|
||||
// Timestamps
|
||||
@ -219,7 +220,8 @@ class InvoiceModel extends Model
|
||||
|
||||
if ($flag == 1) { // Add mode
|
||||
// EXCLUDE all policies that exist in partner_invoice_items
|
||||
$builder->where("pt.id NOT IN (SELECT policy_id FROM partner_invoice_items)", null, false);
|
||||
$builder->where("pp.id NOT IN (SELECT policy_id FROM partner_invoice_items)", null, false);
|
||||
$builder->where("pt.policy_no NOT IN (SELECT policy_no FROM partner_invoice_items)", null, false);
|
||||
}
|
||||
|
||||
if ($flag == 2) { // Edit mode
|
||||
|
||||
132
app/Models/PartnerPosModel.php
Normal file
132
app/Models/PartnerPosModel.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class PartnerPosModel extends Model
|
||||
{
|
||||
// 1. Core Configuration
|
||||
|
||||
/**
|
||||
* @var string The database table that this model primarily works with.
|
||||
*/
|
||||
protected $table = 'partner_pos';
|
||||
|
||||
/**
|
||||
* @var string The name of the primary key field.
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* @var string The type of value the primary key is.
|
||||
*/
|
||||
protected $returnType = 'array'; // Can be 'array' or 'object' (e.g., \App\Entities\PartnerPos)
|
||||
|
||||
/**
|
||||
* @var bool Whether to use timestamps. We will handle them manually with $useTimestamps.
|
||||
*/
|
||||
protected $useAutoIncrement = true;
|
||||
|
||||
// 2. Timestamps and Dates
|
||||
|
||||
/**
|
||||
* @var bool Whether to use the automatic timestamps. Set to true if you use CI4's
|
||||
* default `created_at` and `updated_at` column names. Since you use custom names,
|
||||
* we set this to false and handle the fields manually in $allowedFields.
|
||||
*/
|
||||
protected $useTimestamps = true;
|
||||
|
||||
/**
|
||||
* @var string The field name for the creation timestamp.
|
||||
* We use `created_on` to match your table.
|
||||
*/
|
||||
protected $createdField = 'created_on';
|
||||
|
||||
/**
|
||||
* @var string The field name for the update timestamp.
|
||||
* We use `updated_on` to match your table.
|
||||
*/
|
||||
protected $updatedField = 'updated_on';
|
||||
|
||||
// Note: The `created_by` and `updated_by` fields need to be handled
|
||||
// in the controller/service layer before calling insert/update.
|
||||
|
||||
// 3. Allowed Fields
|
||||
|
||||
/**
|
||||
* @var array The fields that can be set during an insert or update operation.
|
||||
*/
|
||||
protected $allowedFields = [
|
||||
'name',
|
||||
'email',
|
||||
'mobile',
|
||||
'pos_code',
|
||||
'certificate_file_name',
|
||||
'pan',
|
||||
'pan_file_name',
|
||||
'aadhar',
|
||||
'aadhar_file_name',
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'manager_id',
|
||||
'bank_name',
|
||||
'account_holder_name',
|
||||
'account_number',
|
||||
'ifsc_code',
|
||||
|
||||
// 'created_on' and 'updated_on' are handled by the Model,
|
||||
// but need to be in $allowedFields if $useTimestamps is false.
|
||||
// Since $useTimestamps is true and we customized the field names, CI4 handles them.
|
||||
];
|
||||
|
||||
// 4. Validation (Optional, but highly recommended in CI4)
|
||||
|
||||
// protected $validationRules = [
|
||||
// 'name' => 'required|min_length[3]',
|
||||
// 'email' => 'permit_empty|valid_email|is_unique[partner_pos.email,id,{id}]',
|
||||
// 'mobile' => 'permit_empty|numeric|max_length[20]|is_unique[partner_pos.mobile,id,{id}]',
|
||||
// 'manager_id' => 'required|integer',
|
||||
// ];
|
||||
|
||||
// protected $validationMessages = [
|
||||
// 'email' => [
|
||||
// 'is_unique' => 'Sorry, that email address is already registered.',
|
||||
// ],
|
||||
// ];
|
||||
|
||||
/**
|
||||
* @var bool Whether to skip validation during inserts and updates.
|
||||
*/
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* @var bool Whether to clean data for SQL Injection.
|
||||
*/
|
||||
protected $cleanValidationRules = true;
|
||||
|
||||
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||
|
||||
protected function checkAndADDCreatedByValue(array $data)
|
||||
{
|
||||
// Check if 'updated_by' value is null or empty
|
||||
if (empty($data['data']['created_by'])) {
|
||||
// Set 'updated_by' value to the current session user ID
|
||||
$data['data']['created_by'] = get_session_userid();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||
{
|
||||
// Check if 'updated_by' value is null or empty
|
||||
if (empty($data['data']['updated_by'])) {
|
||||
// Set 'updated_by' value to the current session user ID
|
||||
$data['data']['updated_by'] = get_session_userid();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
166
app/Models/SalesActivityModel.php
Normal file
166
app/Models/SalesActivityModel.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
/**
|
||||
* Activity Model
|
||||
*/
|
||||
class SalesActivityModel extends Model
|
||||
{
|
||||
protected $table = 'sales_activities';
|
||||
protected $primaryKey = 'activity_id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'lead_id',
|
||||
'activity_type',
|
||||
'notes',
|
||||
'scheduled_date',
|
||||
'assigned_to',
|
||||
'status',
|
||||
'completion_notes',
|
||||
'completed_date',
|
||||
'parent_activity_id',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'lead_id' => 'required|integer',
|
||||
'activity_type' => 'required|in_list[Call,Email,Meeting,Demo,Share,Todo]',
|
||||
'notes' => 'required',
|
||||
'scheduled_date' => 'required|valid_date',
|
||||
'assigned_to' => 'required|integer',
|
||||
'status' => 'in_list[pending,completed]',
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'lead_id' => [
|
||||
'required' => 'Lead ID is required',
|
||||
],
|
||||
'activity_type' => [
|
||||
'required' => 'Activity type is required',
|
||||
],
|
||||
'notes' => [
|
||||
'required' => 'Activity notes are required',
|
||||
],
|
||||
];
|
||||
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* Get activities by lead with user details
|
||||
*/
|
||||
public function getActivitiesByLead($leadId, $status = null)
|
||||
{
|
||||
$builder = $this->select('activities.*, user_profiles.username as assigned_to_name')
|
||||
->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left')
|
||||
->where('activities.lead_id', $leadId);
|
||||
|
||||
if ($status) {
|
||||
$builder->where('activities.status', $status);
|
||||
}
|
||||
|
||||
return $builder->orderBy('activities.scheduled_date', 'DESC')->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all activities with filters
|
||||
*/
|
||||
public function getActivitiesWithFilters($filters = [], $limit = 10, $offset = 0)
|
||||
{
|
||||
$builder = $this->select('activities.*, actual_leads.company_name, user_profiles.username as assigned_to_name')
|
||||
->join('actual_leads', 'actual_leads.lead_id = activities.lead_id', 'left')
|
||||
->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left');
|
||||
|
||||
if (!empty($filters['status'])) {
|
||||
$builder->where('activities.status', $filters['status']);
|
||||
}
|
||||
|
||||
if (!empty($filters['activity_type'])) {
|
||||
$builder->where('activities.activity_type', $filters['activity_type']);
|
||||
}
|
||||
|
||||
if (!empty($filters['assigned_to'])) {
|
||||
$builder->where('activities.assigned_to', $filters['assigned_to']);
|
||||
}
|
||||
|
||||
if (!empty($filters['date_from'])) {
|
||||
$builder->where('activities.scheduled_date >=', $filters['date_from']);
|
||||
}
|
||||
|
||||
if (!empty($filters['date_to'])) {
|
||||
$builder->where('activities.scheduled_date <=', $filters['date_to']);
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => $builder->orderBy('activities.scheduled_date', 'DESC')
|
||||
->limit($limit, $offset)->findAll(),
|
||||
'total' => $builder->countAllResults(false)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete an activity
|
||||
*/
|
||||
public function completeActivity($activityId, $completionData)
|
||||
{
|
||||
return $this->update($activityId, [
|
||||
'status' => 'completed',
|
||||
'completion_notes' => $completionData['completion_notes'],
|
||||
'completed_date' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => $completionData['updated_by'] ?? null
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pending activities count by user
|
||||
*/
|
||||
public function getPendingActivitiesCount($userId)
|
||||
{
|
||||
return $this->where('assigned_to', $userId)
|
||||
->where('status', 'pending')
|
||||
->where('scheduled_date <=', date('Y-m-d H:i:s'))
|
||||
->countAllResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upcoming activities for a user
|
||||
*/
|
||||
public function getUpcomingActivities($userId, $days = 7, $limit = 10)
|
||||
{
|
||||
$endDate = date('Y-m-d H:i:s', strtotime("+{$days} days"));
|
||||
|
||||
return $this->select('activities.*, actual_leads.company_name')
|
||||
->join('actual_leads', 'actual_leads.lead_id = activities.lead_id', 'left')
|
||||
->where('activities.assigned_to', $userId)
|
||||
->where('activities.status', 'pending')
|
||||
->where('activities.scheduled_date <=', $endDate)
|
||||
->orderBy('activities.scheduled_date', 'ASC')
|
||||
->limit($limit)
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get activity timeline for a lead
|
||||
*/
|
||||
public function getActivityTimeline($leadId)
|
||||
{
|
||||
return $this->select('activities.*, user_profiles.username as assigned_to_name')
|
||||
->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left')
|
||||
->where('activities.lead_id', $leadId)
|
||||
->orderBy('activities.scheduled_date', 'DESC')
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
145
app/Models/SalesActualLeadModel.php
Normal file
145
app/Models/SalesActualLeadModel.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
/**
|
||||
* Lead Model
|
||||
* Handles all operations related to actual_leads table
|
||||
*/
|
||||
class SalesActualLeadModel extends Model
|
||||
{
|
||||
protected $table = 'sales_actual_leads';
|
||||
protected $primaryKey = 'lead_id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'company_name',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'website',
|
||||
'gst_number',
|
||||
'status',
|
||||
'assigned_to',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'company_name' => 'required|min_length[2]|max_length[255]',
|
||||
'email' => 'required|valid_email|max_length[255]',
|
||||
'phone' => 'required|min_length[10]|max_length[20]',
|
||||
'status' => 'in_list[New,Potential,Prospects,Non prospects]',
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'company_name' => [
|
||||
'required' => 'Company name is required',
|
||||
],
|
||||
'email' => [
|
||||
'required' => 'Email is required',
|
||||
'valid_email' => 'Please provide a valid email address',
|
||||
],
|
||||
'phone' => [
|
||||
'required' => 'Phone number is required',
|
||||
],
|
||||
];
|
||||
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* Get lead with assigned user details
|
||||
*/
|
||||
public function getLeadWithUser($leadId)
|
||||
{
|
||||
return $this->select('actual_leads.*, user_profiles.username as assigned_to_name, user_profiles.email as assigned_to_email')
|
||||
->join('user_profiles', 'user_profiles.id = actual_leads.assigned_to', 'left')
|
||||
->where('actual_leads.lead_id', $leadId)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all leads with pagination and filters
|
||||
*/
|
||||
public function getLeadsWithFilters($filters = [], $limit = 10, $offset = 0)
|
||||
{
|
||||
$builder = $this->select('actual_leads.*, user_profiles.username as assigned_to_name')
|
||||
->join('user_profiles', 'user_profiles.id = actual_leads.assigned_to', 'left');
|
||||
|
||||
if (!empty($filters['status'])) {
|
||||
$builder->where('actual_leads.status', $filters['status']);
|
||||
}
|
||||
|
||||
if (!empty($filters['assigned_to'])) {
|
||||
$builder->where('actual_leads.assigned_to', $filters['assigned_to']);
|
||||
}
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$builder->groupStart()
|
||||
->like('actual_leads.company_name', $filters['search'])
|
||||
->orLike('actual_leads.email', $filters['search'])
|
||||
->orLike('actual_leads.phone', $filters['search'])
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
return [
|
||||
'data' => $builder->limit($limit, $offset)->findAll(),
|
||||
'total' => $builder->countAllResults(false)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lead with all related data (contacts, activities, notes)
|
||||
*/
|
||||
public function getLeadComplete($leadId)
|
||||
{
|
||||
$lead = $this->getLeadWithUser($leadId);
|
||||
|
||||
if (!$lead) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$contactModel = new SalesContactPersonModel();
|
||||
$activityModel = new SalesActivityModel();
|
||||
$noteModel = new SalesLeadNoteModel();
|
||||
|
||||
$lead['contact_persons'] = $contactModel->where('lead_id', $leadId)->findAll();
|
||||
$lead['activities'] = $activityModel->getActivitiesByLead($leadId);
|
||||
$lead['notes'] = $noteModel->getNotesByLead($leadId);
|
||||
|
||||
return $lead;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get leads statistics
|
||||
*/
|
||||
public function getLeadStats($userId = null)
|
||||
{
|
||||
$builder = $this->builder();
|
||||
|
||||
if ($userId) {
|
||||
$builder->where('assigned_to', $userId);
|
||||
}
|
||||
|
||||
$stats = [
|
||||
'total' => $builder->countAllResults(false),
|
||||
'new' => $builder->where('status', 'New')->countAllResults(false),
|
||||
'potential' => $builder->where('status', 'Potential')->countAllResults(false),
|
||||
'prospects' => $builder->where('status', 'Prospects')->countAllResults(false),
|
||||
'non_prospects' => $builder->where('status', 'Non prospects')->countAllResults(false),
|
||||
];
|
||||
|
||||
return $stats;
|
||||
}
|
||||
}
|
||||
95
app/Models/SalesContactPersonModel.php
Normal file
95
app/Models/SalesContactPersonModel.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
/**
|
||||
* Contact Person Model
|
||||
*/
|
||||
class SalesContactPersonModel extends Model
|
||||
{
|
||||
protected $table = 'sales_contact_persons';
|
||||
protected $primaryKey = 'contact_id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'lead_id',
|
||||
'name',
|
||||
'mobile',
|
||||
'designation',
|
||||
'email',
|
||||
'is_primary',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'lead_id' => 'required|integer',
|
||||
'name' => 'required|min_length[2]|max_length[100]',
|
||||
'mobile' => 'required|min_length[10]|max_length[20]',
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'lead_id' => [
|
||||
'required' => 'Lead ID is required',
|
||||
],
|
||||
'name' => [
|
||||
'required' => 'Contact person name is required',
|
||||
],
|
||||
'mobile' => [
|
||||
'required' => 'Mobile number is required',
|
||||
],
|
||||
];
|
||||
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* Get all contacts for a lead
|
||||
*/
|
||||
public function getContactsByLead($leadId)
|
||||
{
|
||||
return $this->where('lead_id', $leadId)
|
||||
->orderBy('is_primary', 'DESC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get primary contact for a lead
|
||||
*/
|
||||
public function getPrimaryContact($leadId)
|
||||
{
|
||||
return $this->where('lead_id', $leadId)
|
||||
->where('is_primary', 1)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a contact as primary (unset others)
|
||||
*/
|
||||
public function setPrimaryContact($contactId, $leadId)
|
||||
{
|
||||
$this->db->transStart();
|
||||
|
||||
// Unset all primary contacts for this lead
|
||||
$this->where('lead_id', $leadId)
|
||||
->set(['is_primary' => 0])
|
||||
->update();
|
||||
|
||||
// Set the specified contact as primary
|
||||
$this->update($contactId, ['is_primary' => 1]);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
||||
return $this->db->transStatus();
|
||||
}
|
||||
}
|
||||
75
app/Models/SalesLeadNoteModel.php
Normal file
75
app/Models/SalesLeadNoteModel.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Lead Note Model
|
||||
*/
|
||||
class SalesLeadNoteModel extends Model
|
||||
{
|
||||
protected $table = 'sales_lead_notes';
|
||||
protected $primaryKey = 'note_id';
|
||||
protected $useAutoIncrement = true;
|
||||
protected $returnType = 'array';
|
||||
protected $useSoftDeletes = false;
|
||||
protected $protectFields = true;
|
||||
protected $allowedFields = [
|
||||
'lead_id',
|
||||
'user_id',
|
||||
'note_text',
|
||||
'created_by',
|
||||
'updated_by'
|
||||
];
|
||||
|
||||
// Dates
|
||||
protected $useTimestamps = true;
|
||||
protected $dateFormat = 'datetime';
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
// Validation
|
||||
protected $validationRules = [
|
||||
'lead_id' => 'required|integer',
|
||||
'user_id' => 'required|integer',
|
||||
'note_text' => 'required|min_length[3]',
|
||||
];
|
||||
|
||||
protected $validationMessages = [
|
||||
'lead_id' => [
|
||||
'required' => 'Lead ID is required',
|
||||
],
|
||||
'note_text' => [
|
||||
'required' => 'Note text is required',
|
||||
],
|
||||
];
|
||||
|
||||
protected $skipValidation = false;
|
||||
|
||||
/**
|
||||
* Get notes by lead with user details
|
||||
*/
|
||||
public function getNotesByLead($leadId)
|
||||
{
|
||||
return $this->select('lead_notes.*, user_profiles.username')
|
||||
->join('user_profiles', 'user_profiles.id = lead_notes.user_id', 'left')
|
||||
->where('lead_notes.lead_id', $leadId)
|
||||
->orderBy('lead_notes.created_at', 'DESC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notes by user
|
||||
*/
|
||||
public function getNotesByUser($userId, $limit = 20, $offset = 0)
|
||||
{
|
||||
return $this->select('lead_notes.*, actual_leads.company_name')
|
||||
->join('actual_leads', 'actual_leads.lead_id = lead_notes.lead_id', 'left')
|
||||
->where('lead_notes.user_id', $userId)
|
||||
->orderBy('lead_notes.created_at', 'DESC')
|
||||
->limit($limit, $offset)
|
||||
->findAll();
|
||||
}
|
||||
}
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
<div class="form-group col-md-3 file-input-group">
|
||||
<label for="file_input">Browser File<span class="text-danger">*</span></label>
|
||||
<input type="file" class="form-control file-input" id="kyc_docs_file" name="file_name" required accept=".pdf, .jpeg, .jpg, .png"
|
||||
<input type="file" class="form-control file-input" id="kyc_docs_file" name="file_name" required
|
||||
style="box-shadow: none !important; outline: none !important; border: none; height: unset !important;padding: 0px !important;background: transparent !important;">
|
||||
</div>
|
||||
|
||||
@ -318,5 +318,29 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Centralized Validation Function
|
||||
function validateFile(fileInput) {
|
||||
var file = fileInput.files[0];
|
||||
if (!file) {
|
||||
return true; // No file selected, considered valid or neutral
|
||||
}
|
||||
|
||||
var type = file.type;
|
||||
|
||||
// Check if the type is PDF or starts with 'image/'
|
||||
if (type === 'application/pdf' || type.startsWith('image/')) {
|
||||
return true; // Valid
|
||||
}
|
||||
|
||||
// Invalid format
|
||||
toastr.warning('Invalid file format. Only PDF or Image files are allowed.', 'WARNING!');
|
||||
$(fileInput).val(''); // clear file
|
||||
return false; // Invalid
|
||||
}
|
||||
|
||||
// Attach the centralized handler to BOTH classes
|
||||
$(document).on('change', '.file-input, .edit_file-input', function () {
|
||||
validateFile(this);
|
||||
});
|
||||
|
||||
</script>
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
<a class="mdi mdi-delete mr-1 btn-delete-kyc"
|
||||
data-id="<?= $value['id'] ?>"
|
||||
data-client_id="<?= $value['client_id'] ?>"
|
||||
style="font-size:18px;"></a>
|
||||
</td>
|
||||
</tr>
|
||||
@ -45,7 +46,7 @@
|
||||
<input type="file"
|
||||
name="file_name"
|
||||
id="kyc_docs_file_<?= $value['id'] ?>"
|
||||
class="form-control"
|
||||
class="form-control edit-file-input"
|
||||
style="box-shadow:none!important; outline:none!important; border:none; height:unset!important;padding: 0px !important;background: transparent !important;">
|
||||
</div>
|
||||
|
||||
|
||||
@ -1808,6 +1808,9 @@
|
||||
<li>
|
||||
<a href="<?= base_url('/util/rtoMaster') ?>"> RTO </a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="<?= base_url('/util/partnerPOS') ?>"> POS </a>
|
||||
</li>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
title: 'Policy-Tranction-Inception-List',
|
||||
title: 'NHance-Branch-List',
|
||||
className: 'app-btn-primary ',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
|
||||
@ -1702,7 +1702,7 @@
|
||||
$('#follower_policy_no_' + uniqueid).prop('readonly', false);
|
||||
$('#calc_policy_issue_date_1').val(policy_issue_date).addClass('readonly-select');
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
$(document).on('change', 'select[name="relationship[]"]', function() {
|
||||
@ -2612,141 +2612,203 @@
|
||||
console.log('variance', variance);
|
||||
}
|
||||
|
||||
function co_share_percentage_calculation(input, extra = null){
|
||||
// function co_share_percentage_calculation(input, extra = null){
|
||||
|
||||
console.log('input', input)
|
||||
var inputs = $('input[name="co_share_per[]"]'); // Specifically select input elements
|
||||
console.log('Number of inputs:', inputs.length);
|
||||
// console.log('input', input)
|
||||
// var inputs = $('input[name="co_share_per[]"]'); // Specifically select input elements
|
||||
// console.log('Number of inputs:', inputs.length);
|
||||
|
||||
let insurer_count = insurer_count_array.length;
|
||||
console.log('insurer_count', insurer_count);
|
||||
console.log('insurer_count_array', insurer_count_array);
|
||||
// let insurer_count = insurer_count_array.length;
|
||||
// console.log('insurer_count', insurer_count);
|
||||
// console.log('insurer_count_array', insurer_count_array);
|
||||
|
||||
if(input){
|
||||
if(insurer_count == 2){
|
||||
// if ($('#cop_yes').is(':checked')) {
|
||||
// console.log('cop_yes checked', $('#cop_yes').is(':checked'));
|
||||
// if(input){
|
||||
// if(insurer_count == 2){
|
||||
|
||||
// Find the index of the value
|
||||
let index = insurer_count_array.indexOf(Number(input));
|
||||
let second_value_index = "";
|
||||
// // Find the index of the value
|
||||
// let index = insurer_count_array.indexOf(Number(input));
|
||||
// let second_value_index = "";
|
||||
|
||||
if (index !== -1) {
|
||||
// if (index !== -1) {
|
||||
|
||||
console.log(`Value ${input} exists at index ${index}.`);
|
||||
// console.log(`Value ${input} exists at index ${index}.`);
|
||||
|
||||
let beforeValue = index > 0 ? insurer_count_array[index - 1] : null;
|
||||
let afterValue = index < insurer_count_array.length - 1 ? insurer_count_array[index + 1] : null;
|
||||
// let beforeValue = index > 0 ? insurer_count_array[index - 1] : null;
|
||||
// let afterValue = index < insurer_count_array.length - 1 ? insurer_count_array[index + 1] : null;
|
||||
|
||||
if (beforeValue != null) {
|
||||
second_value_index = beforeValue;
|
||||
} else if (afterValue != null) {
|
||||
second_value_index = afterValue;
|
||||
}
|
||||
// if (beforeValue != null) {
|
||||
// second_value_index = beforeValue;
|
||||
// } else if (afterValue != null) {
|
||||
// second_value_index = afterValue;
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
let value1 = $('#co_share_per_' + input).val();
|
||||
let value2 = $('#co_share_per_' + second_value_index).val();
|
||||
// let value1 = $('#co_share_per_' + input).val();
|
||||
// let value2 = $('#co_share_per_' + second_value_index).val();
|
||||
|
||||
value1 = Number(value1);
|
||||
value2 = Number(value2);
|
||||
// value1 = Number(value1);
|
||||
// value2 = Number(value2);
|
||||
|
||||
console.log('value1', value1);
|
||||
console.log('value2', value2);
|
||||
// console.log('value1', value1);
|
||||
// console.log('value2', value2);
|
||||
|
||||
if(extra == "add"){
|
||||
// if(extra == "add"){
|
||||
|
||||
if(value2 == 0){
|
||||
value1 = 50;
|
||||
value2 = 50;
|
||||
}else{
|
||||
if(value2 == 100){
|
||||
value1 = 50;
|
||||
value2 = 50;
|
||||
}else{
|
||||
value1 = 100 - value2;
|
||||
}
|
||||
}
|
||||
// if(value2 == 0){
|
||||
// value1 = 50;
|
||||
// value2 = 50;
|
||||
// }else{
|
||||
// if(value2 == 100){
|
||||
// value1 = 50;
|
||||
// value2 = 50;
|
||||
// }else{
|
||||
// value1 = 100 - value2;
|
||||
// }
|
||||
// }
|
||||
|
||||
}else{
|
||||
// }else{
|
||||
|
||||
if(value1 == 100){
|
||||
value2 = 0;
|
||||
}else{
|
||||
value2 = 100 - value1;
|
||||
}
|
||||
}
|
||||
// if(value1 == 100){
|
||||
// value2 = 0;
|
||||
// }else{
|
||||
// value2 = 100 - value1;
|
||||
// }
|
||||
// }
|
||||
|
||||
console.log('value1', value1);
|
||||
console.log('value2', value2);
|
||||
// console.log('value1', value1);
|
||||
// console.log('value2', value2);
|
||||
|
||||
$('#co_share_per_' + input).val(value1);
|
||||
$('#co_share_per_' + second_value_index).val(value2);
|
||||
// $('#co_share_per_' + input).val(value1);
|
||||
// $('#co_share_per_' + second_value_index).val(value2);
|
||||
|
||||
}else if(insurer_count > 2){
|
||||
// }else if(insurer_count > 2){
|
||||
|
||||
let total_val = 0;
|
||||
// let total_val = 0;
|
||||
|
||||
// Calculate the total sum of input values
|
||||
inputs.each(function () {
|
||||
let val = Number($(this).val()) || 0;
|
||||
if(val == 0){
|
||||
$(this).val(0)
|
||||
}
|
||||
total_val += val;
|
||||
});
|
||||
// // Calculate the total sum of input values
|
||||
// inputs.each(function () {
|
||||
// let val = Number($(this).val()) || 0;
|
||||
// if(val == 0){
|
||||
// $(this).val(0)
|
||||
// }
|
||||
// total_val += val;
|
||||
// });
|
||||
|
||||
// if (total_val < 100) {
|
||||
// let remaining_val = 100 - total_val; // Calculate the remaining value
|
||||
// // if (total_val < 100) {
|
||||
// // let remaining_val = 100 - total_val; // Calculate the remaining value
|
||||
|
||||
// // Assign the remaining value to the first empty input
|
||||
// let assigned = false;
|
||||
// inputs.each(function () {
|
||||
// let current_val = Number($(this).val()) || 0;
|
||||
// if (current_val === 0 && !assigned) { // Assign only once
|
||||
// $(this).val(remaining_val);
|
||||
// assigned = true;
|
||||
// } else if (current_val === 0) {
|
||||
// $(this).val(0); // Set other empty inputs to 0
|
||||
// }
|
||||
// });
|
||||
// } else if (total_val > 100) {
|
||||
// toastr.warning('Sum of the co-share is greater than 100');
|
||||
// }
|
||||
// // // Assign the remaining value to the first empty input
|
||||
// // let assigned = false;
|
||||
// // inputs.each(function () {
|
||||
// // let current_val = Number($(this).val()) || 0;
|
||||
// // if (current_val === 0 && !assigned) { // Assign only once
|
||||
// // $(this).val(remaining_val);
|
||||
// // assigned = true;
|
||||
// // } else if (current_val === 0) {
|
||||
// // $(this).val(0); // Set other empty inputs to 0
|
||||
// // }
|
||||
// // });
|
||||
// // } else if (total_val > 100) {
|
||||
// // toastr.warning('Sum of the co-share is greater than 100');
|
||||
// // }
|
||||
|
||||
}
|
||||
}else{
|
||||
inputs.each(function (index) {
|
||||
if (inputs.length === 1) {
|
||||
$(this).val(100);
|
||||
} else if(inputs.length === 2) {
|
||||
let first = $('#co_share_per_1').val();
|
||||
first = Number(first)
|
||||
let second_val = 100 - first;
|
||||
// }
|
||||
// }else{
|
||||
// inputs.each(function (index) {
|
||||
// if (inputs.length === 1) {
|
||||
// $(this).val(100);
|
||||
// } else if(inputs.length === 2) {
|
||||
// let first = $('#co_share_per_1').val();
|
||||
// first = Number(first)
|
||||
// let second_val = 100 - first;
|
||||
|
||||
if (index === 1) {
|
||||
$(this).val(second_val);
|
||||
}
|
||||
}
|
||||
});
|
||||
// if (index === 1) {
|
||||
// $(this).val(second_val);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
let val_sum = 0;
|
||||
// let val_sum = 0;
|
||||
|
||||
inputs.each(function () {
|
||||
let val = Number($(this).val()) || 0;
|
||||
val_sum += val;
|
||||
});
|
||||
// inputs.each(function () {
|
||||
// let val = Number($(this).val()) || 0;
|
||||
// val_sum += val;
|
||||
// });
|
||||
|
||||
if (val_sum > 100) {
|
||||
toastr.warning('Sum of the co-share is greater than 100', 'WARNING');
|
||||
}
|
||||
// if ($('#cop_yes').is(':checked')) {
|
||||
// if (val_sum > 100) {
|
||||
// toastr.warning('Sum of the co-share is greater than 100', 'WARNING');
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
function co_share_percentage_calculation(changedEl = null) {
|
||||
|
||||
let inputs = $('input[name="co_share_per[]"]');
|
||||
let count = inputs.length;
|
||||
let copChecked = $('#cop_yes').is(':checked');
|
||||
|
||||
/* =========================
|
||||
COP UNCHECKED
|
||||
========================= */
|
||||
if (!copChecked) {
|
||||
inputs.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
AUTO MODE (default / fetch / add / remove)
|
||||
========================= */
|
||||
if (changedEl === null) {
|
||||
|
||||
// Single card → empty (means 100)
|
||||
if (count === 1) {
|
||||
inputs.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
// Multiple cards → auto split
|
||||
let split = (100 / count).toFixed(2);
|
||||
inputs.val(split);
|
||||
return;
|
||||
}
|
||||
|
||||
/* =========================
|
||||
USER MODE (manual edit)
|
||||
========================= */
|
||||
let sum = 0;
|
||||
let userTouched = false;
|
||||
|
||||
inputs.each(function () {
|
||||
let v = $(this).val();
|
||||
|
||||
if (v !== '') {
|
||||
userTouched = true;
|
||||
sum += Number(v) || 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Show warning ONLY if user changed something
|
||||
if (userTouched && sum > 100) {
|
||||
toastr.warning(
|
||||
'Sum of the co-share is greater than 100',
|
||||
'WARNING'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$(document).on('change', '[name="base_premium"], [name="co_share_per[]"]', function() {
|
||||
|
||||
console.log('Triggered change event.');
|
||||
console.log('Triggered change event. base_premium');
|
||||
|
||||
// Get the first non-empty base premium value
|
||||
// let basePremium = $('input[name="base_premium[]"]').toArray()
|
||||
@ -3276,7 +3338,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function addCDAccountNumber(input)
|
||||
function addCDAccountNumber_old(input)
|
||||
{
|
||||
var val = $(input).val();
|
||||
var uniqueid = $(input).data('count');
|
||||
@ -3328,6 +3390,93 @@
|
||||
}
|
||||
}
|
||||
|
||||
function addCDAccountNumber(input)
|
||||
{
|
||||
|
||||
var $input = $(input);
|
||||
var val = $input.val();
|
||||
var uniqueid = $input.data('count');
|
||||
|
||||
var client_id = $('#client_id').val();
|
||||
var insurer_id = $('#follow_insurer_id_' + uniqueid).val();
|
||||
|
||||
var isCurrentLeader = $('#co_share_type_' + uniqueid).is(':checked');
|
||||
var isAnyLeaderSelected = $('input[name="co_share_type[]"]:checked').length > 0;
|
||||
var cop_yes = $('#cop_yes').is(':checked');
|
||||
|
||||
|
||||
|
||||
// Missing base data
|
||||
if (!client_id || !insurer_id) {
|
||||
toastr.warning('Client or Insurer does not exist.', 'WARNING!');
|
||||
return;
|
||||
}
|
||||
|
||||
// COP enabled but no leader selected
|
||||
if (cop_yes && !isAnyLeaderSelected) {
|
||||
toastr.warning('Please select a Leader.', 'WARNING!');
|
||||
$input.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
// CD allowed only for leader
|
||||
if (cop_yes && !isCurrentLeader) {
|
||||
|
||||
toastr.warning(
|
||||
'CD account number allowed only for Leader.',
|
||||
'WARNING!'
|
||||
);
|
||||
|
||||
// Clear current select
|
||||
$input.val('');
|
||||
|
||||
// Disable CD for NON-leaders, enable only leader, clear balance div
|
||||
$('select.follow_insurer_cd').each(function () {
|
||||
|
||||
var count = $(this).data('count');
|
||||
var isLeaderRow = $('#co_share_type_' + count).is(':checked');
|
||||
|
||||
// Get the corresponding balance div
|
||||
var balanceDiv = document.getElementById('cd_current_balance_info_' + count);
|
||||
|
||||
if (!isLeaderRow) {
|
||||
$(this)
|
||||
.prop('disabled', true)
|
||||
.removeAttr('required')
|
||||
.val('');
|
||||
|
||||
// Clear balance div if it exists
|
||||
if (balanceDiv) {
|
||||
balanceDiv.innerHTML = "";
|
||||
}
|
||||
|
||||
} else {
|
||||
$(this)
|
||||
.prop('disabled', false)
|
||||
.attr('required', true);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// ➕ Add CD
|
||||
if (val === 'add_cd') {
|
||||
$('#premium_details_unique_id').val(uniqueid);
|
||||
new bootstrap.Modal(
|
||||
document.getElementById('cd_form_modal')
|
||||
).show();
|
||||
$input.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
// ✅ Valid selection (leader only)
|
||||
$('#cd_ac_pk_for_leader').val(val);
|
||||
getCdAmount(val, uniqueid);
|
||||
}
|
||||
|
||||
|
||||
function restrictCDACNO(currentSelect){
|
||||
|
||||
const selectedValue = $(currentSelect).val();
|
||||
@ -3780,85 +3929,160 @@
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
|
||||
$('#cop_yes').change(function() {
|
||||
// $('#cop_yes').change(function() {
|
||||
|
||||
if ($(this).is(':checked')) {
|
||||
$('.add-insurer-button').removeClass('d-none');
|
||||
$('.payby').removeClass('d-none');
|
||||
$('.card_group_2').show()
|
||||
$('.card_group_3').show()
|
||||
$('.card_group_7').show()
|
||||
$('.card_group_35').removeClass('d-none');
|
||||
// if ($(this).is(':checked')) {
|
||||
// $('.add-insurer-button').removeClass('d-none');
|
||||
// $('.payby').removeClass('d-none');
|
||||
// $('.card_group_2').show()
|
||||
// $('.card_group_3').show()
|
||||
// $('.card_group_7').show()
|
||||
// $('.card_group_35').removeClass('d-none');
|
||||
|
||||
var selectedOption = $('#policy_type_id').find('option:selected');
|
||||
var bap = selectedOption.data('bap');
|
||||
var allocg = selectedOption.data('allocg');
|
||||
// console.log('allocg:', allocg);
|
||||
// var selectedOption = $('#policy_type_id').find('option:selected');
|
||||
// var bap = selectedOption.data('bap');
|
||||
// var allocg = selectedOption.data('allocg');
|
||||
// // console.log('allocg:', allocg);
|
||||
|
||||
|
||||
// do not remove this commented items
|
||||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||||
// $('.hidecoter').show()
|
||||
// $('.hidecotp').hide()
|
||||
// }else{
|
||||
// // do not remove this commented items
|
||||
// // if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||||
// // $('.hidecoter').show()
|
||||
// // $('.hidecotp').hide()
|
||||
// // }else{
|
||||
|
||||
// if(bap == 'Motor'){
|
||||
// $('.hidecotp').show()
|
||||
// $('.hidecoter').hide()
|
||||
// }else{
|
||||
// $('.hidecoter').hide()
|
||||
// $('.hidecotp').hide()
|
||||
// }
|
||||
// }
|
||||
// // if(bap == 'Motor'){
|
||||
// // $('.hidecotp').show()
|
||||
// // $('.hidecoter').hide()
|
||||
// // }else{
|
||||
// // $('.hidecoter').hide()
|
||||
// // $('.hidecotp').hide()
|
||||
// // }
|
||||
// // }
|
||||
|
||||
if(allocg == "EB"){
|
||||
$('.hideter').hide();
|
||||
$('.hidetp').hide();
|
||||
$('.hidecoter').hide()
|
||||
$('.hidecotp').hide()
|
||||
}else{
|
||||
// if(allocg == "EB"){
|
||||
// $('.hideter').hide();
|
||||
// $('.hidetp').hide();
|
||||
// $('.hidecoter').hide()
|
||||
// $('.hidecotp').hide()
|
||||
// }else{
|
||||
|
||||
$('.hidetp').show();
|
||||
if($(this).is(':checked')){
|
||||
$('.hidecotp').show();
|
||||
}else{
|
||||
$('.hidecotp').hide();
|
||||
}
|
||||
// $('.hidetp').show();
|
||||
// if($(this).is(':checked')){
|
||||
// $('.hidecotp').show();
|
||||
// }else{
|
||||
// $('.hidecotp').hide();
|
||||
// }
|
||||
|
||||
if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||||
$('.hideter').show();
|
||||
if($(this).is(':checked')){
|
||||
$('.hidecoter').show();
|
||||
}else{
|
||||
$('.hidecoter').hide();
|
||||
}
|
||||
}else{
|
||||
$('.hideter').hide();
|
||||
}
|
||||
}
|
||||
// if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){
|
||||
// $('.hideter').show();
|
||||
// if($(this).is(':checked')){
|
||||
// $('.hidecoter').show();
|
||||
// }else{
|
||||
// $('.hidecoter').hide();
|
||||
// }
|
||||
// }else{
|
||||
// $('.hideter').hide();
|
||||
// }
|
||||
// }
|
||||
|
||||
// $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||||
// $(this).val(''); // Clear value
|
||||
// console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||||
// });
|
||||
// // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||||
// // $(this).val(''); // Clear value
|
||||
// // console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||||
// // });
|
||||
|
||||
} else {
|
||||
$('.add-insurer-button').addClass('d-none');
|
||||
$('.payby').addClass('d-none');
|
||||
// $('#bro_payable_by').prop('checked', false);
|
||||
$('.card_group_2').hide()
|
||||
$('.card_group_3').hide()
|
||||
$('.card_group_7').hide()
|
||||
$('.card_group_35').addClass('d-none');
|
||||
$('.hidecoter').hide()
|
||||
$('.hidecotp').hide()
|
||||
// } else {
|
||||
// $('.add-insurer-button').addClass('d-none');
|
||||
// $('.payby').addClass('d-none');
|
||||
// // $('#bro_payable_by').prop('checked', false);
|
||||
// $('.card_group_2').hide()
|
||||
// $('.card_group_3').hide()
|
||||
// $('.card_group_7').hide()
|
||||
// $('.card_group_35').addClass('d-none');
|
||||
// $('.hidecoter').hide()
|
||||
// $('.hidecotp').hide()
|
||||
|
||||
// $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||||
// $(this).val(''); // Clear value
|
||||
// console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||||
// });
|
||||
// // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () {
|
||||
// // $(this).val(''); // Clear value
|
||||
// // console.log('Input cleared:', $(this).attr('name')); // Log cleared input
|
||||
// // });
|
||||
// }
|
||||
// });
|
||||
|
||||
$('#cop_yes').change(function () {
|
||||
|
||||
const isCoPayYes = $(this).is(':checked');
|
||||
|
||||
const selectedOption = $('#policy_type_id option:selected');
|
||||
const bap = selectedOption.data('bap');
|
||||
const allocg = selectedOption.data('allocg');
|
||||
|
||||
const $allPremiumCols = $('.csslabel, .cssbp, .csstp, .csstep');
|
||||
|
||||
/* =========================
|
||||
VISIBILITY LOGIC
|
||||
========================= */
|
||||
if (isCoPayYes) {
|
||||
|
||||
$('.add-insurer-button, .payby').removeClass('d-none');
|
||||
$('.card_group_2, .card_group_3, .card_group_7').show();
|
||||
$('.card_group_35').removeClass('d-none');
|
||||
|
||||
if (allocg === "EB") {
|
||||
$('.hideter, .hidetp, .hidecoter, .hidecotp').hide();
|
||||
} else {
|
||||
|
||||
$('.hidetp').show();
|
||||
$('.hidecotp').show();
|
||||
|
||||
if (['Fire','Marine Cargo','Marine Hull'].includes(bap)) {
|
||||
$('.hideter, .hidecoter').show();
|
||||
} else {
|
||||
$('.hideter, .hidecoter').hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
$('.add-insurer-button, .payby').addClass('d-none');
|
||||
$('.card_group_2, .card_group_3, .card_group_7').hide();
|
||||
$('.card_group_35').addClass('d-none');
|
||||
|
||||
$('.hideter, .hidetp, .hidecoter, .hidecotp').hide();
|
||||
}
|
||||
|
||||
/* =========================
|
||||
COLUMN LAYOUT LOGIC
|
||||
========================= */
|
||||
$allPremiumCols
|
||||
.filter(':visible')
|
||||
.removeClass('col-3 col-4 col-6');
|
||||
|
||||
if (allocg === "EB") {
|
||||
|
||||
$allPremiumCols
|
||||
.filter(':visible')
|
||||
.addClass('col-6');
|
||||
|
||||
} else if (['Fire','Marine Cargo','Marine Hull'].includes(bap)) {
|
||||
|
||||
$allPremiumCols
|
||||
.filter(':visible')
|
||||
.addClass('col-3');
|
||||
|
||||
} else {
|
||||
|
||||
$allPremiumCols
|
||||
.filter(':visible')
|
||||
.addClass('col-4');
|
||||
}
|
||||
|
||||
/* =========================
|
||||
CO-SHARE RECALC
|
||||
========================= */
|
||||
co_share_percentage_calculation();
|
||||
});
|
||||
|
||||
|
||||
$('#client_type').change(function() {
|
||||
|
||||
@ -4348,7 +4572,7 @@
|
||||
style="font-size: x-small;">
|
||||
</small>
|
||||
</label>
|
||||
<select class="form-control follow_insurer_cd" data-count="${insurerCount}" id="cd_ac_no_${insurerCount}" name="cd_ac_no_for_child[]" onchange="addCDAccountNumber(this); restrictCDACNO(this);">
|
||||
<select class="form-control follow_insurer_cd" data-count="${insurerCount}" id="cd_ac_no_${insurerCount}" name="cd_ac_no_for_child[]" onchange="addCDAccountNumber(this);">
|
||||
<option value="" selected>Select CD No</option>
|
||||
<option value="add_cd"> + Add CD No</option>
|
||||
</select>
|
||||
|
||||
455
app/Views/pos_list.php
Normal file
455
app/Views/pos_list.php
Normal file
@ -0,0 +1,455 @@
|
||||
<style>
|
||||
.dataTables_filter {
|
||||
position: absolute;
|
||||
}
|
||||
.dataTables_length label {height: 21px !important;}
|
||||
</style>
|
||||
|
||||
<!-- End ADD and EDIT Page HTML -->
|
||||
<div class="row" id="List-page">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body maincard">
|
||||
<table data-custom-table-css="table" class="table table-sm m-0 table-centered dt-responsive nowrap w-100" cellspacing="a" id="user-table">
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th class="font-weight-medium">S.No.</th>
|
||||
<th class="font-weight-medium">POS Name</th>
|
||||
<th class="font-weight-medium">POS Code</th>
|
||||
<th class="font-weight-medium">Email</th>
|
||||
<th class="font-weight-medium">Mobile</th>
|
||||
<th class="font-weight-medium">Manager</th>
|
||||
<th class="font-weight-medium">Status</th>
|
||||
<th class="font-weight-medium">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if(isset($data['pos_list'])) { $slno = 1; ?>
|
||||
<?php foreach($data['pos_list'] as $index => $row) { ?>
|
||||
<tr>
|
||||
<td class="text-center"><?= $slno++; ?></td>
|
||||
<td><?= $row['name']; ?></td>
|
||||
<td><?= $row['pos_code']; ?></td>
|
||||
<td><?= $row['email']; ?></td>
|
||||
<td><?= $row['mobile']; ?></td>
|
||||
<td><?= $row['manager_name']; ?></td>
|
||||
<td>
|
||||
<span class="<?php if($row['is_active'] == 1){ echo 'badge badge-primary'; }else{ echo 'badge badge-danger'; } ?>">
|
||||
<?php if($row['is_active'] == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group dropdown" style="position: relative !important;left:0px !important;top:0px !important;">
|
||||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||||
<div class="dropdown-menu dropdown-menu-right" style="cursor: pointer;">
|
||||
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('edit', this)">
|
||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||||
</a>
|
||||
<?php if ($row['is_active'] == 1): ?>
|
||||
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('remove', this)">
|
||||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } else { ?>
|
||||
<tr>
|
||||
<td colspan="3" class="text-center">No data available</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- modal content -->
|
||||
<div id="con-close-modal" class="modal fade app-font-family" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;" data-backdrop="static">
|
||||
<div class="modal-dialog modal-dialog-centered modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="modalLabel">Add POS Details</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body p-4">
|
||||
<!-- <form class="parsley-examples" id="partnerPOSForm" enctype="multipart/form-data"> -->
|
||||
<form id="partnerPOSForm" enctype="multipart/form-data">
|
||||
<input type="hidden" name="pk" id="pos_id"/>
|
||||
<div class="form-group">
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-12">
|
||||
<label for="manager_id">Manager<span class="text-danger">*</span></label>
|
||||
<select class="form-control" id="manager_id" name="manager_id" required>
|
||||
<option value="" selected>Select Manager</option>
|
||||
<?php if (!empty($data['manager_list'])): ?>
|
||||
<?php foreach ($data['manager_list'] as $value): ?>
|
||||
<option value="<?= esc($value['id']) ?>">
|
||||
<?= esc($value['name']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="name">Name<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="name" name="name" placeholder="Enter Name" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="pos_code">POS Code<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="pos_code" name="pos_code" placeholder="Enter Code" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="email">Email<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="email" name="email" placeholder="Enter Email" required>
|
||||
<small id="email_error" class="text-danger d-none"></small>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Enter mobile" maxlength="10" inputmode="numeric" pattern="[0-9]{10}" required>
|
||||
<small id="mobile_error" class="text-danger d-none"></small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-3">
|
||||
<label for="aadhar">Aadhaar Number<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="aadhar" name="aadhar" placeholder="Enter Aadhaar Number" maxlength="12" inputmode="numeric" pattern="[0-9]{12}" required>
|
||||
<small id="aadhar_error" class="text-danger d-none"></small>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="aadhar_file_name">Aadhar</label>
|
||||
<div class="input-icon">
|
||||
<input type="file" class="form-control" name="aadhar_file_name" id="aadhar_file_name" accept="image/*,application/pdf">
|
||||
<i class="mdi mdi-upload additional-icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="pan">PAN Number<span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="pan" name="pan" placeholder="Enter PAN Number" maxlength="10" style="text-transform:uppercase" pattern="[A-Z]{5}[0-9]{4}[A-Z]{1}" required>
|
||||
<small id="pan_error" class="text-danger d-none"></small>
|
||||
</div>
|
||||
<div class="form-group col-md-3">
|
||||
<label for="pan_file_name">PAN</label>
|
||||
<div class="input-icon">
|
||||
<input type="file" class="form-control" name="pan_file_name" id="pan_file_name" accept="image/*,application/pdf">
|
||||
<i class="mdi mdi-upload additional-icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-12">
|
||||
<label for="certificate_file_name">Certificate</label>
|
||||
<div class="input-icon">
|
||||
<input type="file" class="form-control" name="certificate_file_name" id="certificate_file_name" accept="image/*,application/pdf">
|
||||
<i class="mdi mdi-upload additional-icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<!-- <legend>Bank Details</legend> -->
|
||||
<div class="form-group col-md-3">
|
||||
<label for="bank_name">Bank Name</label>
|
||||
<input type="text" id="bank_name" name="bank_name" class="form-control" placeholder="Enter Bank Name">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="account_holder_name">Account Holder Name</label>
|
||||
<input type="text" id="account_holder_name" name="account_holder_name" class="form-control" placeholder="Enter Account Holder Name">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="account_number">Account Number</label>
|
||||
<input type="text" id="account_number" name="account_number" class="form-control" placeholder="Enter Account Number">
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label for="ifsc_code">IFSC Code</label>
|
||||
<input type="text" id="ifsc_code" name="ifsc_code" class="form-control" placeholder="Enter IFSC Code">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group text-right m-b-0">
|
||||
<!-- <button type="button" class="btn app-btn-secondary waves-effect waves-light" id="btnSubmit" onclick="handleSaveEditAndDelete('submit')">Submit</button> -->
|
||||
<button type="submit" class="btn app-btn-secondary" id="btnSubmit">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var table;
|
||||
$(document).ready(function () {
|
||||
$('#manager_id').select2();
|
||||
var ticketsTable = $('#user-table');
|
||||
ticketsTable.DataTable({
|
||||
scrollX: true,
|
||||
// dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
// "<'row'<'col-sm-12'tr>>" +
|
||||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
{
|
||||
text: 'Add',
|
||||
className: 'btn app-btn-primary mr-2',
|
||||
action: function(e, dt, node, config) {
|
||||
openModal()
|
||||
}
|
||||
},
|
||||
{
|
||||
extend: 'collection',
|
||||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||||
className: 'btn app-btn-secondary ',
|
||||
buttons: [
|
||||
{
|
||||
extend: 'csv',
|
||||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||
title: 'POS-List',
|
||||
className: 'app-btn-primary ',
|
||||
exportOptions: {
|
||||
columns: ':not(:last-child)'
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
language: {
|
||||
search: `
|
||||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||||
_INPUT_
|
||||
<i class="mdi mdi-magnify datatable-search-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||||
</div>`,
|
||||
searchPlaceholder: "Search",
|
||||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||||
},
|
||||
paging: true, // Enable pagination
|
||||
pageLength: 10, // Set default number of rows per page (optional)
|
||||
// ordering: false,
|
||||
});
|
||||
});
|
||||
|
||||
$('.close').click(function(){ resetValues(); })
|
||||
|
||||
function openModal(){
|
||||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
||||
myModal.show();
|
||||
}
|
||||
|
||||
function handleSaveEditAndDelete(type = 'submit', el = null) {
|
||||
|
||||
let form = document.getElementById('partnerPOSForm');
|
||||
let url = '<?= base_url('util/partnerPOS') ?>';
|
||||
let method = "POST";
|
||||
let pk = el ? $(el).data('id') : null;
|
||||
|
||||
let formData;
|
||||
|
||||
if (type === 'submit') {
|
||||
|
||||
// if (!form.checkValidity()) {
|
||||
// form.reportValidity();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (!validateForm()) return;
|
||||
|
||||
// CREATE FORMDATA FROM FORM
|
||||
formData = new FormData(form);
|
||||
|
||||
// OPTIONAL: re-append file inputs (safe for edit mode)
|
||||
$('#partnerPOSForm input[type="file"]').each(function () {
|
||||
if (this.files.length > 0) {
|
||||
formData.set(this.name, this.files[0]); // use set(), not append()
|
||||
}
|
||||
});
|
||||
|
||||
} else if (type == 'edit') {
|
||||
method = "GET";
|
||||
if (pk) url += '?pk=' + pk;
|
||||
$('#modalLabel').text('Edit POS Details');
|
||||
$('#partnerPOSForm')[0].reset();
|
||||
|
||||
} else if (type == 'remove') {
|
||||
method = "DELETE";
|
||||
if (pk) url += '?pk=' + pk;
|
||||
}
|
||||
|
||||
$('.loader, .loader-mask').fadeIn();
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: method,
|
||||
data: (type === 'submit') ? formData : null,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (response) {
|
||||
console.log('Response:', response);
|
||||
if (response.status) {
|
||||
if(type == 'edit'){
|
||||
let record = response.data.pos_list[0]; // single record
|
||||
appendEditData(record);
|
||||
} else if(type == 'remove'){
|
||||
toastr.success(response.message, 'Success');
|
||||
// if(el) $(el).closest('tr').remove();
|
||||
window.location.reload();
|
||||
} else if(type == 'submit'){
|
||||
toastr.success(response.message, 'Success');
|
||||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
||||
myModal.hide();
|
||||
$('#partnerPOSForm')[0].reset();
|
||||
window.location.reload();
|
||||
}
|
||||
} else {
|
||||
toastr.warning(response.message, 'Warning');
|
||||
}
|
||||
$('.loader, .loader-mask').fadeOut();
|
||||
},
|
||||
error: function () {
|
||||
$('.loader, .loader-mask').fadeOut();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetValues(){
|
||||
$('#modalLabel').text('Add POS Details');
|
||||
$('#partnerPOSForm')[0].reset();
|
||||
$('#manager_id').val(null).trigger('change');
|
||||
|
||||
}
|
||||
|
||||
|
||||
function appendEditData(data){
|
||||
$('#pos_id').val(data.id);
|
||||
$('#name').val(data.name);
|
||||
$('#email').val(data.email);
|
||||
$('#mobile').val(data.mobile);
|
||||
$('#pos_code').val(data.pos_code);
|
||||
|
||||
// Instead of setting the file input
|
||||
$('#current_file_name').text(data['certificate_file_name'] || 'No file uploaded');
|
||||
|
||||
$('#aadhar').val(data.aadhar);
|
||||
$('#aadhar_file_name').text(data['aadhar_file_name'] || 'No file uploaded');
|
||||
|
||||
$('#pan').val(data.pan);
|
||||
$('#pan_file_name').text(data['pan_file_name'] || 'No file uploaded');
|
||||
|
||||
$('#bank_name').val(data.bank_name);
|
||||
$('#account_holder_name').val(data.account_holder_name);
|
||||
$('#account_number').val(data.account_number);
|
||||
$('#ifsc_code').val(data.ifsc_code);
|
||||
|
||||
openModal();
|
||||
$('#con-close-modal').one('shown.bs.modal', function () {
|
||||
$('#manager_id').val(data.manager_id).trigger('change');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$('#aadhar').on('input', function () {
|
||||
this.value = this.value.replace(/[^0-9]/g, '');
|
||||
});
|
||||
|
||||
$('#pan').on('input', function () {
|
||||
this.value = this.value.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
||||
});
|
||||
|
||||
$('#mobile').on('input', function () {
|
||||
this.value = this.value.replace(/[^0-9]/g, '');
|
||||
});
|
||||
|
||||
|
||||
|
||||
$('#partnerPOSForm').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const form = this;
|
||||
|
||||
// HTML5 built-in validation
|
||||
if (!form.checkValidity()) {
|
||||
form.reportValidity(); // shows required/pattern tooltips
|
||||
return;
|
||||
}
|
||||
|
||||
// Custom validation
|
||||
if (!validateForm()) return;
|
||||
|
||||
// If valid, submit via AJAX
|
||||
handleSaveEditAndDelete('submit');
|
||||
});
|
||||
|
||||
|
||||
function validateForm() {
|
||||
let isValid = true;
|
||||
|
||||
// Clear old errors
|
||||
$('.text-danger').addClass('d-none').text('');
|
||||
|
||||
// Regex patterns
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
const mobileRegex = /^[6-9]\d{9}$/;
|
||||
const aadharRegex = /^\d{12}$/;
|
||||
const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]$/;
|
||||
|
||||
// EMAIL
|
||||
const email = $('#email').val().trim();
|
||||
if (email === '') {
|
||||
$('#email_error').text('Email is required').removeClass('d-none');
|
||||
isValid = false;
|
||||
} else if (!emailRegex.test(email)) {
|
||||
$('#email_error').text('Enter a valid email').removeClass('d-none');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// MOBILE
|
||||
const mobile = $('#mobile').val().trim();
|
||||
if (mobile === '') {
|
||||
$('#mobile_error').text('Mobile number is required').removeClass('d-none');
|
||||
isValid = false;
|
||||
} else if (!mobileRegex.test(mobile)) {
|
||||
$('#mobile_error').text('Enter a valid 10-digit mobile number').removeClass('d-none');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// AADHAAR
|
||||
const aadhar = $('#aadhar').val().trim();
|
||||
if (aadhar === '') {
|
||||
$('#aadhar_error').text('Aadhaar is required').removeClass('d-none');
|
||||
isValid = false;
|
||||
} else if (!aadharRegex.test(aadhar)) {
|
||||
$('#aadhar_error').text('Aadhaar must be 12 digits').removeClass('d-none');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
// PAN
|
||||
const pan = $('#pan').val().trim();
|
||||
if (pan === '') {
|
||||
$('#pan_error').text('PAN is required').removeClass('d-none');
|
||||
isValid = false;
|
||||
} else if (!panRegex.test(pan)) {
|
||||
$('#pan_error').text('Invalid PAN format (AAAPA1234A)').removeClass('d-none');
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@ -212,6 +212,8 @@
|
||||
<label for="description" class="control-label">Description<span class="text-danger">*</span></label>
|
||||
<textarea class="form-control" id="description"
|
||||
placeholder="Write something about the transaction" required></textarea>
|
||||
<input type="hidden" id="cd_ac_pk" value="<?php echo $depositdata[0]->cd_ac_pk?>">
|
||||
<input type="hidden" id="cd_ac_no" value="<?php echo $depositdata[0]->cd_ac_no?>">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -392,6 +394,8 @@
|
||||
var transactionTypeValue = $('input[name="transactionMode"]:checked').val();
|
||||
var subType = "";
|
||||
var record_date = $('#record_date').val();
|
||||
var cd_ac_no = $('#cd_ac_no').val();
|
||||
var cd_ac_pk = $('#cd_ac_pk').val();
|
||||
|
||||
if (amount == "") {
|
||||
toastr.warning('Amount field is required')
|
||||
@ -432,7 +436,8 @@
|
||||
console.log('clientId ', clientId)
|
||||
console.log('insurerId ', insurerId)
|
||||
console.log('subType ', subType)
|
||||
|
||||
console.log('cd_ac_pk ', cd_ac_pk)
|
||||
console.log('cd_ac_no ', cd_ac_no)
|
||||
|
||||
// Send data to the server using Ajax
|
||||
$.ajax({
|
||||
@ -445,7 +450,9 @@
|
||||
sub_type_id: subType, // Include sub_type_id
|
||||
client_id: clientId,
|
||||
insurer_id: insurerId,
|
||||
record_date: record_date
|
||||
record_date: record_date,
|
||||
cd_ac_pk: cd_ac_pk,
|
||||
cd_ac_no: cd_ac_no
|
||||
},
|
||||
success: function(response) {
|
||||
// Handle success response
|
||||
|
||||
Loading…
Reference in New Issue
Block a user