Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
9e12217d41
@ -13,6 +13,7 @@ use App\Filters\AuthMVC;
|
|||||||
use App\Filters\HttpRequestLog;
|
use App\Filters\HttpRequestLog;
|
||||||
use App\Filters\CloseDbConnection;
|
use App\Filters\CloseDbConnection;
|
||||||
use App\Filters\AuthClientApi;
|
use App\Filters\AuthClientApi;
|
||||||
|
use App\Filters\CommissionApiFilter;
|
||||||
|
|
||||||
use App\Filters\AuthJWT;
|
use App\Filters\AuthJWT;
|
||||||
|
|
||||||
@ -36,7 +37,8 @@ class Filters extends BaseConfig
|
|||||||
'HttpRequestLog' => HttpRequestLog::class,
|
'HttpRequestLog' => HttpRequestLog::class,
|
||||||
'authJWT' => AuthJWT::class,
|
'authJWT' => AuthJWT::class,
|
||||||
'AuthClientApi' => AuthClientApi::class,
|
'AuthClientApi' => AuthClientApi::class,
|
||||||
'CloseDbConnection' => CloseDbConnection::class
|
'CloseDbConnection' => CloseDbConnection::class,
|
||||||
|
'CommissionApiFilter' => CommissionApiFilter::class
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -34,6 +34,8 @@ $routes->get("updateRenewalData", "ClientController::updateRenewalData");
|
|||||||
$routes->get("updateRenewalDataNotExistingClient", "ClientController::updateRenewalDataNotExistingClient");
|
$routes->get("updateRenewalDataNotExistingClient", "ClientController::updateRenewalDataNotExistingClient");
|
||||||
$routes->get("updateRenewalInsurerData", "ClientController::updateRenewalInsurerData");
|
$routes->get("updateRenewalInsurerData", "ClientController::updateRenewalInsurerData");
|
||||||
$routes->get("sendMutipleToEmails", "MasterController::sendMutipleToEmails");
|
$routes->get("sendMutipleToEmails", "MasterController::sendMutipleToEmails");
|
||||||
|
$routes->post("getCommission", "InsuranceCommissionController::initiateCommissionCalc",['filter' => 'CommissionApiFilter']);
|
||||||
|
$routes->get("importRules", "RuleImportController::upload");
|
||||||
// $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
|
// $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
|
||||||
// $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail");
|
// $routes->get("sendCroneRemainderMail", "DashboardController::sendCroneRemainderMail");
|
||||||
// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
// $routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
||||||
@ -478,6 +480,7 @@ $routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
|
|||||||
$routes->get("driveListFiles", "GoogleDriveController::listFiles");
|
$routes->get("driveListFiles", "GoogleDriveController::listFiles");
|
||||||
$routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
$routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
||||||
$routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
$routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
||||||
|
$routes->get('payouts', 'PolicyTransactionController::payouts', ['filter' => 'authMVC']);
|
||||||
$routes->get('downloadGdriveFile', 'GoogleDriveController::downloadGdriveFile', ['filter' => 'authMVC']);
|
$routes->get('downloadGdriveFile', 'GoogleDriveController::downloadGdriveFile', ['filter' => 'authMVC']);
|
||||||
$routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP');
|
$routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP');
|
||||||
|
|
||||||
@ -736,7 +739,6 @@ $routes->get('testTracelog','TestBusinessController::a');
|
|||||||
$routes->get("claimView", "EmployeeRestController::claimView");
|
$routes->get("claimView", "EmployeeRestController::claimView");
|
||||||
|
|
||||||
// General Tickets
|
// General Tickets
|
||||||
|
|
||||||
$routes->post("ticketSave", "ThzController::ticketSave");
|
$routes->post("ticketSave", "ThzController::ticketSave");
|
||||||
$routes->get("ticketList", "ThzController::ticketList");
|
$routes->get("ticketList", "ThzController::ticketList");
|
||||||
$routes->post("ticketConversationSave", "ThzController::ticketConversationSave");
|
$routes->post("ticketConversationSave", "ThzController::ticketConversationSave");
|
||||||
@ -766,3 +768,11 @@ $routes->group('test', function($routes) {
|
|||||||
});
|
});
|
||||||
$routes->cli('cli/testcli', 'TestingController::testcli');
|
$routes->cli('cli/testcli', 'TestingController::testcli');
|
||||||
|
|
||||||
|
//PARTNER PAYOUT
|
||||||
|
$routes->group('payout', function($routes) {
|
||||||
|
$routes->match (['get','post'],'list',"PayoutController::payoutList");
|
||||||
|
$routes->post('fetchUtrDetails',"PayoutController::fetchUtrDetails");
|
||||||
|
$routes->post('saveUtrDetails',"PayoutController::saveUtrDetails");
|
||||||
|
$routes->post('removeUtrDetails',"PayoutController::removeUtrDetails");
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use App\Libraries\Slug;
|
|||||||
use App\Libraries\MyLogger;
|
use App\Libraries\MyLogger;
|
||||||
use App\Libraries\GmailAPI;
|
use App\Libraries\GmailAPI;
|
||||||
use App\Libraries\MyGoogleDrive;
|
use App\Libraries\MyGoogleDrive;
|
||||||
|
use App\Libraries\RuleImportService;
|
||||||
use App\Libraries\DataServiceSqlite;
|
use App\Libraries\DataServiceSqlite;
|
||||||
use App\Controllers\Home;
|
use App\Controllers\Home;
|
||||||
|
|
||||||
@ -80,5 +81,14 @@ class Services extends BaseService
|
|||||||
|
|
||||||
return new MyGoogleDrive();
|
return new MyGoogleDrive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ruleImportService($getShared = true)
|
||||||
|
{
|
||||||
|
if ($getShared) {
|
||||||
|
return static::getSharedInstance('ruleImportService');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RuleImportService();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5673,6 +5673,10 @@ class ClientController extends AdminController
|
|||||||
// $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx");
|
// $response = $ticketServiceController->extractExcelData("claims_dump_form_client.xlsx");
|
||||||
// dd($response);
|
// dd($response);
|
||||||
|
|
||||||
|
// $TicketController = new TicketController();
|
||||||
|
// $response = $TicketController->getMoreInfo($requestFrom = 'rest', $ticket_id = 70);
|
||||||
|
// dd($response);
|
||||||
|
|
||||||
// ---------- EMP SERVICE CONTROLLER --------------------------------------------------------------------------------
|
// ---------- EMP SERVICE CONTROLLER --------------------------------------------------------------------------------
|
||||||
|
|
||||||
$empServiceController = new EmployeeServiceController();
|
$empServiceController = new EmployeeServiceController();
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -2471,7 +2471,7 @@ class EmployeeServiceController extends AdminController
|
|||||||
$member_data_count = count($member_data);
|
$member_data_count = count($member_data);
|
||||||
|
|
||||||
if ($inception_data_count !== $member_data_count) {
|
if ($inception_data_count !== $member_data_count) {
|
||||||
$result['error_summary'][] = 15;
|
$result['error_summary'][] = 101;
|
||||||
$result['error_message'] = "
|
$result['error_message'] = "
|
||||||
<strong>Inception Data Count:</strong>
|
<strong>Inception Data Count:</strong>
|
||||||
<span class='badge badge-danger'>{$inception_data_count}</span>
|
<span class='badge badge-danger'>{$inception_data_count}</span>
|
||||||
@ -2504,7 +2504,7 @@ class EmployeeServiceController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$match_found) {
|
if (!$match_found) {
|
||||||
array_push($result['error_summary'], 14);
|
array_push($result['error_summary'], 100);
|
||||||
$result['error_data'][$inception_key]['sno']['error'][] = "This inception row was not found in the member data list.";
|
$result['error_data'][$inception_key]['sno']['error'][] = "This inception row was not found in the member data list.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
274
app/Controllers/InsuranceCommissionController.php
Normal file
274
app/Controllers/InsuranceCommissionController.php
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use CodeIgniter\Controller;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
|
||||||
|
class InsuranceCommissionController extends AdminController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
|
||||||
|
private $rules = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
set_session_context('Client');
|
||||||
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
|
// Load rules file if present in writable config path
|
||||||
|
// $rulesPath = WRITEPATH . 'config/insurance_rules.json';
|
||||||
|
// if (file_exists($rulesPath)) {
|
||||||
|
// $this->loadRulesFromFile($rulesPath);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /insurance/calculate
|
||||||
|
* Accepts JSON body with policy data and returns commission calculation
|
||||||
|
*/
|
||||||
|
public function initiateCommissionCalc()
|
||||||
|
{
|
||||||
|
// Accept POST params (JSON, form-data, x-www-form-urlencoded)
|
||||||
|
$input = $this->request->getPost();
|
||||||
|
|
||||||
|
if (empty($input)) {
|
||||||
|
$json = $this->request->getJSON(true);
|
||||||
|
if ($json) {
|
||||||
|
$input = $json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($input)) {
|
||||||
|
return $this->failValidationError('No input data received');
|
||||||
|
}
|
||||||
|
// -------- Required Params Check --------
|
||||||
|
if (empty($input['policy_issue_date'])) {
|
||||||
|
return $this->failValidationError('policy_issue_date is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($input['department'])) {
|
||||||
|
return $this->failValidationError('department is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($input['insurer_id'])) {
|
||||||
|
return $this->failValidationError('insurer_id is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -------- Build Dynamic Rules Path --------
|
||||||
|
$policyDate = strtotime($input['policy_issue_date']);
|
||||||
|
if (!$policyDate) {
|
||||||
|
return $this->failValidationError('Invalid policy_issue_date');
|
||||||
|
}
|
||||||
|
|
||||||
|
$month = strtoupper(date('M', $policyDate)); // SEP
|
||||||
|
$year = date('Y', $policyDate); // 2025
|
||||||
|
$folderName = $month . $year; // SEP2025
|
||||||
|
|
||||||
|
$insurerId = $input['insurer_id']; // 5
|
||||||
|
$department = ucfirst(strtolower($input['department'])); // Motor, Health, Fire
|
||||||
|
|
||||||
|
// Final Path: WRITEPATH/rules/SEP2025/5_Motor.json
|
||||||
|
$rulesPath = WRITEPATH . "uploads/commission/rules/{$folderName}/{$insurerId}_{$department}.json";
|
||||||
|
// echo $rulesPath;die();
|
||||||
|
|
||||||
|
if (!file_exists($rulesPath)) {
|
||||||
|
return $this->fail("Rules file not found at: {$rulesPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the dynamic rule set
|
||||||
|
$this->loadRulesFromFile($rulesPath);
|
||||||
|
|
||||||
|
// -------- Execute Rule Matching & Commission Calculation --------
|
||||||
|
try {
|
||||||
|
$result = $this->calculateCommission($input);
|
||||||
|
|
||||||
|
$comment = isset($result['rule']['name'])
|
||||||
|
? "Matched rule: " . $result['rule']['name']
|
||||||
|
: "Matched rule: (unnamed rule)";
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'success' => true,
|
||||||
|
'data' => [
|
||||||
|
'payout' => $result['payout'],
|
||||||
|
'rule' => $result['rule'],
|
||||||
|
'comment' => $comment,
|
||||||
|
// 'rules_path_used' => $rulesPath
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load rules JSON and normalise department keys to lowercase for lookups
|
||||||
|
*/
|
||||||
|
private function loadRulesFromFile(string $filePath)
|
||||||
|
{
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
throw new \Exception("Rules file not found: {$filePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = file_get_contents($filePath);
|
||||||
|
$parsed = json_decode($json, true);
|
||||||
|
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
throw new \Exception('Invalid JSON in rules file: ' . json_last_error_msg());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalise department keys to lowercase for consistent lookups
|
||||||
|
$this->rules = [];
|
||||||
|
foreach ($parsed as $dept => $rules) {
|
||||||
|
$this->rules[strtolower($dept)] = $rules;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function calculateCommission(array $policyData)
|
||||||
|
{
|
||||||
|
$department = $policyData['department'] ?? '';
|
||||||
|
$deptKey = strtolower($department);
|
||||||
|
|
||||||
|
if (!isset($this->rules[$deptKey])) {
|
||||||
|
throw new \Exception("No rules found for department: {$department}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$matchingRules = [];
|
||||||
|
|
||||||
|
foreach ($this->rules[$deptKey] as $rule) {
|
||||||
|
if ($this->evaluateConditions($rule['conditions'] ?? [], $policyData)) {
|
||||||
|
$matchingRules[] = $rule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($matchingRules)) {
|
||||||
|
throw new \Exception('No matching rules found for the policy data');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the first matching rule. In future you can implement priority/weighting
|
||||||
|
$applicableRule = $matchingRules[0];
|
||||||
|
|
||||||
|
$payout = $this->applyCalculation($applicableRule['calculation'], $policyData);
|
||||||
|
|
||||||
|
return ['rule' => $applicableRule, 'payout' => $payout];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function evaluateConditions(array $conditions, array $data): bool
|
||||||
|
{
|
||||||
|
foreach ($conditions as $condition) {
|
||||||
|
$field = $condition['field'];
|
||||||
|
$operator = $condition['operator'];
|
||||||
|
$expectedValue = $condition['value'];
|
||||||
|
|
||||||
|
if (!array_key_exists($field, $data)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualValue = $data[$field];
|
||||||
|
|
||||||
|
if (!$this->compareValues($actualValue, $operator, $expectedValue)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function compareValues($actual, string $operator, $expected): bool
|
||||||
|
{
|
||||||
|
switch ($operator) {
|
||||||
|
case '==':
|
||||||
|
return $actual == $expected;
|
||||||
|
case '!=':
|
||||||
|
return $actual != $expected;
|
||||||
|
case '>':
|
||||||
|
return $actual > $expected;
|
||||||
|
case '>=':
|
||||||
|
return $actual >= $expected;
|
||||||
|
case '<':
|
||||||
|
return $actual < $expected;
|
||||||
|
case '<=':
|
||||||
|
return $actual <= $expected;
|
||||||
|
case 'between':
|
||||||
|
return is_array($expected) && $actual >= $expected[0] && $actual <= $expected[1];
|
||||||
|
case 'in':
|
||||||
|
return is_array($expected) && in_array($actual, $expected);
|
||||||
|
default:
|
||||||
|
throw new \Exception("Unsupported operator: {$operator}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function applyCalculation(array $calculation, array $policyData)
|
||||||
|
{
|
||||||
|
$type = $calculation['type'] ?? null;
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 'percentage':
|
||||||
|
$percentage = $calculation['value'] ?? 0;
|
||||||
|
$base = $calculation['on'] ?? null;
|
||||||
|
|
||||||
|
if ($base === null || !isset($policyData[$base])) {
|
||||||
|
throw new \Exception("Base value for calculation not found: {$base}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($percentage / 100) * $policyData[$base];
|
||||||
|
|
||||||
|
case 'composite':
|
||||||
|
$total = 0;
|
||||||
|
|
||||||
|
foreach ($calculation['components'] as $component) {
|
||||||
|
$percentage = $component['percentage'] ?? 0;
|
||||||
|
$base = $component['on'] ?? null;
|
||||||
|
|
||||||
|
if ($base === null || !isset($policyData[$base])) {
|
||||||
|
throw new \Exception("Base value for calculation not found: {$base}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($component['only_first_year'])) {
|
||||||
|
if (!empty($policyData['is_renewal'])) {
|
||||||
|
continue; // Skip this component for renewals
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$total += ($percentage / 100) * $policyData[$base];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
|
||||||
|
case 'fixed':
|
||||||
|
$fixedAmount = $calculation['value'] ?? 0;
|
||||||
|
|
||||||
|
// If 'on' specified but not needed, return fixed amount as-is
|
||||||
|
return $fixedAmount;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new \Exception('Unsupported calculation type: ' . $type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVolumeReward(array $premiumData)
|
||||||
|
{
|
||||||
|
$annualPremium = $premiumData['annual_premium'] ?? 0;
|
||||||
|
$department = $premiumData['department'] ?? '';
|
||||||
|
|
||||||
|
if ($department === 'Fire' || $department === 'Marine' || $department === 'Engineering') {
|
||||||
|
if ($annualPremium > 20000000) {
|
||||||
|
return 0.01 * $annualPremium;
|
||||||
|
} elseif ($annualPremium > 10000000) {
|
||||||
|
return 0.005 * $annualPremium;
|
||||||
|
} elseif ($annualPremium > 5000000) {
|
||||||
|
return 0.0025 * $annualPremium;
|
||||||
|
}
|
||||||
|
} elseif ($department === 'Motor') {
|
||||||
|
if ($annualPremium > 15000000) {
|
||||||
|
return 0.02 * $annualPremium;
|
||||||
|
} elseif ($annualPremium > 7500000) {
|
||||||
|
return 0.01 * $annualPremium;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1976,6 +1976,9 @@ class MasterController extends AdminController
|
|||||||
'lead_files' => WRITEPATH . 'uploads/lead_files/',
|
'lead_files' => WRITEPATH . 'uploads/lead_files/',
|
||||||
'claim_files' => WRITEPATH . 'uploads/claim_files/',
|
'claim_files' => WRITEPATH . 'uploads/claim_files/',
|
||||||
'claim_dump_excel' => WRITEPATH . 'uploads/claim_dump_excel/',
|
'claim_dump_excel' => WRITEPATH . 'uploads/claim_dump_excel/',
|
||||||
|
'commission' => WRITEPATH . 'uploads/commission/',
|
||||||
|
'files' => WRITEPATH . 'uploads/commission/files',
|
||||||
|
'rules' => WRITEPATH . 'uploads/commission/rules',
|
||||||
'claim_sample_forms' => ROOTPATH . 'public/claim_sample_forms/',
|
'claim_sample_forms' => ROOTPATH . 'public/claim_sample_forms/',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
191
app/Controllers/PayoutController.php
Normal file
191
app/Controllers/PayoutController.php
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\API\ResponseTrait;
|
||||||
|
use App\Models\InvoiceItemModel;
|
||||||
|
use App\Models\InvoiceModel;
|
||||||
|
use App\Models\InvoiceUtrModel;
|
||||||
|
use App\Models\PolicyTransactionModel;
|
||||||
|
|
||||||
|
class PayoutController extends BaseController
|
||||||
|
{
|
||||||
|
use ResponseTrait;
|
||||||
|
protected $myLogger;
|
||||||
|
protected $invoiceItemModel;
|
||||||
|
protected $invoiceModel;
|
||||||
|
protected $invoiceUtrModel;
|
||||||
|
protected $policyTransactionModel;
|
||||||
|
protected $payout_status;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
set_session_context('PayoutController');
|
||||||
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
|
|
||||||
|
$this->payout_status = [
|
||||||
|
1 => "Draft",
|
||||||
|
2 => "Pending",
|
||||||
|
3 => "Complete",
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->invoiceItemModel = new InvoiceItemModel();
|
||||||
|
$this->invoiceModel = new InvoiceModel();
|
||||||
|
$this->invoiceUtrModel = new InvoiceUtrModel();
|
||||||
|
$this->policyTransactionModel = new PolicyTransactionModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function payoutList()
|
||||||
|
{
|
||||||
|
// for filtering list
|
||||||
|
if($this->request->is('post')){
|
||||||
|
try{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
// print_r($data); die;
|
||||||
|
|
||||||
|
$agent_id = $data['agent_id'] ?? null;
|
||||||
|
$status_id = $data['status_id'] ?? null;
|
||||||
|
$start_date = $data['start_date'] ?? null;
|
||||||
|
$end_date = $data['end_date'] ?? null;
|
||||||
|
|
||||||
|
$payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date);
|
||||||
|
|
||||||
|
$payout_data['payout_list_data'] = $payout_data;
|
||||||
|
$payout_data = view('payout_list', $payout_data);
|
||||||
|
|
||||||
|
if(!empty($payout_data)){
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200);
|
||||||
|
}
|
||||||
|
}catch (\Throwable $th) {
|
||||||
|
|
||||||
|
$this->myLogger->logme("error", "PayoutController - payoutList: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString());
|
||||||
|
$errorData = [
|
||||||
|
'message' => $th->getMessage(),
|
||||||
|
'file' => $th->getFile(),
|
||||||
|
'line' => $th->getLine(),
|
||||||
|
'code' => $th->getCode(),
|
||||||
|
'trace' => $th->getTraceAsString(),
|
||||||
|
'trace_array' => $th->getTrace(), // full array version (optional)
|
||||||
|
'function' => $th->getTrace()[0]['function'] ?? null,
|
||||||
|
'class' => $th->getTrace()[0]['class'] ?? null,
|
||||||
|
];
|
||||||
|
$payout_data = view('payout_list');
|
||||||
|
return $this->respond(['status' => false, 'code' => 500, 'data' => $payout_data, "message" => "No data found", 'error_data' => $errorData], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for list
|
||||||
|
$data['payout_status'] = $this->payout_status;
|
||||||
|
$data['agent_list'] = $this->invoiceModel->agentList();
|
||||||
|
$payout_data['payout_list_data'] = $this->invoiceModel->invoiceList();
|
||||||
|
$data['payout_list'] = view('payout_list', $payout_data);
|
||||||
|
|
||||||
|
// dd($data);
|
||||||
|
return $this->loadLayout('payout_list_handler', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchUtrDetails()
|
||||||
|
{
|
||||||
|
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||||
|
$payout_data = $this->constructUtrDetails($invoice_id);
|
||||||
|
|
||||||
|
if(!empty($payout_data)){
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "No data found"], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function constructUtrDetails($invoice_id)
|
||||||
|
{
|
||||||
|
$utr_data = $this->invoiceUtrModel->where('is_active', 1)->where('invoice_id', $invoice_id)->findAll();
|
||||||
|
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||||
|
|
||||||
|
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']) {
|
||||||
|
$data['invoice_completed'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['utr_list_data'] = $utr_data;
|
||||||
|
$data['summary'] = $summary_data;
|
||||||
|
$data = view('payout_utr_details', $data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveUtrDetails()
|
||||||
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
$invoice_id = $this->request->getPost('invoice_id') ?? null;
|
||||||
|
$utr_id = $this->request->getPost('utr_pk') ?? null;
|
||||||
|
|
||||||
|
if(isset($data['utr_date'])){
|
||||||
|
$data['utr_date'] = change_date_format($data['utr_date']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(!empty($utr_id)){
|
||||||
|
|
||||||
|
$update = $this->invoiceUtrModel->where('id', $utr_id)->set($data)->update();
|
||||||
|
$payout_edit_data = $this->constructUtrDetails($invoice_id);
|
||||||
|
|
||||||
|
if($update){
|
||||||
|
|
||||||
|
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||||
|
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){
|
||||||
|
$sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?";
|
||||||
|
db_connect()->query($sql, [$invoice_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_edit_data, "message" => "UTR successfully updated"], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_edit_data, "message" => "Failed to update UTR"], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
unset($data['utr_pk']);
|
||||||
|
$insert_id = $this->invoiceUtrModel->insert($data);
|
||||||
|
$payout_data = $this->constructUtrDetails($invoice_id);
|
||||||
|
|
||||||
|
if($insert_id){
|
||||||
|
|
||||||
|
$summary_data = $this->invoiceModel->utrSummary($invoice_id);
|
||||||
|
if($summary_data['invoice_amount'] == $summary_data['total_utr_amount']){
|
||||||
|
$sql = "UPDATE partner_invoice SET payout_status = 2 WHERE id = ?";
|
||||||
|
db_connect()->query($sql, [$invoice_id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR added successfully"], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to add UTR"], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeUtrDetails()
|
||||||
|
{
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
|
if(isset($data['utr_id'])){
|
||||||
|
|
||||||
|
$sql = "UPDATE partner_invoice_utr SET is_active = 0 WHERE id = ?";
|
||||||
|
$update = db_connect()->query($sql, [$data['utr_id']]);
|
||||||
|
|
||||||
|
$payout_data = $this->constructUtrDetails($data['invoice_id'] ?? "");
|
||||||
|
|
||||||
|
if($update){
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $payout_data, "message" => "UTR removed successfully"], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'data' => $payout_data, "message" => "Failed to remove UTR"], 200);
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
return $this->respond(['status' => false, 'code' => 500, 'data' => "", "message" => "Failed to remove UTR"], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -2811,6 +2811,20 @@
|
|||||||
$this->loadLayout('dms_search', $data);
|
$this->loadLayout('dms_search', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function payouts()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data['tab_name'] = 'Payouts';
|
||||||
|
$data['page_name'] = 'Payouts';
|
||||||
|
$data['payouts'] = [];
|
||||||
|
$data['agents'] = [ 1 => "Agent 1", 2 => "Agent 2", 3 => "Agent 3", 4 => "Agent 4", 5 => "Agent 5", 6 => "Agent 6", 7 => "Agent 7", 8 => "Agent 8"];
|
||||||
|
$data['brokers'] = [];
|
||||||
|
|
||||||
|
if ($this->request->is('post')) {}
|
||||||
|
if ($this->request->is('get')) {}
|
||||||
|
|
||||||
|
$this->loadLayout('policy_transaction_payouts', $data);
|
||||||
|
}
|
||||||
//---------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public function getCoShareStatementDetails($pt_id)
|
public function getCoShareStatementDetails($pt_id)
|
||||||
|
|||||||
350
app/Controllers/RuleImportController.php
Normal file
350
app/Controllers/RuleImportController.php
Normal file
@ -0,0 +1,350 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
class RuleImportController extends AdminController
|
||||||
|
{
|
||||||
|
protected $ruleImportService;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->ruleImportService = \Config\Services::ruleImportService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload endpoint for form (POST)
|
||||||
|
* Input form field: 'rules_file'
|
||||||
|
*/
|
||||||
|
public function uploadORI()
|
||||||
|
{
|
||||||
|
// echo 'hi';
|
||||||
|
!dd($result = $this->ruleImportService->processUpload(['id' => 1,'file_name' => 'sample_commission.csv','insurer_id' => 5, 'department' => 'motor' ,'commission_month' => '2025-11-10']));die;
|
||||||
|
try {
|
||||||
|
$file = $this->request->getFile('rules_file');
|
||||||
|
if (!$file || !$file->isValid()) {
|
||||||
|
return $this->response->setJSON(['status'=>'error','message'=>'No file uploaded or upload error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move uploaded file to writable temp location
|
||||||
|
$tmpPath = WRITEPATH . 'uploads/' . $file->getRandomName();
|
||||||
|
$file->move(WRITEPATH . 'uploads', $file->getName()); // keep original name inside uploads
|
||||||
|
$uploadedFullPath = $file->getTempName(); // Note: CI may store in tmp; we will use moved file path instead
|
||||||
|
$movedPath = WRITEPATH . 'uploads/' . $file->getName();
|
||||||
|
|
||||||
|
// Process file
|
||||||
|
$result = $this->ruleImportService->processUpload($movedPath, $file->getName());
|
||||||
|
|
||||||
|
// Return JSON with annotated file link if present
|
||||||
|
if (isset($result['annotated_file']) && $result['annotated_file']) {
|
||||||
|
$annotUrl = base_url('writable/uploads/annotated/' . basename($result['annotated_file']));
|
||||||
|
$result['annotated_url'] = $annotUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response->setJSON($result);
|
||||||
|
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
log_message('critical', 'RuleImportController::upload ' . $e->getMessage());
|
||||||
|
return $this->response->setJSON(['status'=>'exception','message'=>$e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upload()
|
||||||
|
{
|
||||||
|
// Make sure filesystem helpers available if you need them
|
||||||
|
helper(['filesystem']);
|
||||||
|
|
||||||
|
// CommissionFilesModel – adjust namespace if different
|
||||||
|
$commissionFilesModel = new \App\Models\CommissionFilesModel();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 1. Get uploaded file
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
$file = $this->request->getFile('rules_file');
|
||||||
|
if (!$file || !$file->isValid()) {
|
||||||
|
log_message('warning', 'RuleImportController::upload - No file or invalid upload.');
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'No file uploaded or upload error.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 2. Read POST fields
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
$insurerId = $this->request->getPost('insurer_id');
|
||||||
|
$department = $this->request->getPost('department');
|
||||||
|
$commissionMonth = $this->request->getPost('commission_month');
|
||||||
|
$createdBy = $this->request->getPost('created_by');
|
||||||
|
|
||||||
|
if (empty($insurerId) || empty($department) || empty($commissionMonth) || empty($createdBy)) {
|
||||||
|
log_message('warning', 'RuleImportController::upload - Missing required POST data.', [
|
||||||
|
'insurer_id' => $insurerId,
|
||||||
|
'department' => $department,
|
||||||
|
'commission_month' => $commissionMonth,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
]);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Missing required fields: insurer_id, department, commission_month, created_by.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional / default fields
|
||||||
|
$postedFileName = $this->request->getPost('file_name') ?: $file->getClientName();
|
||||||
|
$fileStatus = $this->request->getPost('file_status') ?: 'pending';
|
||||||
|
$isActive = $this->request->getPost('is_active') !== null ? (int)$this->request->getPost('is_active') : 1;
|
||||||
|
// rules_count is given by user but we will override it after processing on success
|
||||||
|
$postedRulesCount = $this->request->getPost('rules_count') !== null
|
||||||
|
? (int)$this->request->getPost('rules_count')
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 3. Move file to WRITEPATH/uploads/commission/files using user filename
|
||||||
|
// (no random name as per your requirement)
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
$uploadDir = WRITEPATH . 'uploads/commission/files/';
|
||||||
|
if (!is_dir($uploadDir)) {
|
||||||
|
if (!mkdir($uploadDir, 0755, true) && !is_dir($uploadDir)) {
|
||||||
|
throw new \RuntimeException("Failed to create upload directory: {$uploadDir}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sanitize user file name but keep it deterministic (no random, no timestamp)
|
||||||
|
$safeName = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $postedFileName);
|
||||||
|
$targetFileName = $safeName;
|
||||||
|
$movedFullPath = $uploadDir . $targetFileName;
|
||||||
|
|
||||||
|
$file->move($uploadDir, $targetFileName);
|
||||||
|
if (!file_exists($movedFullPath)) {
|
||||||
|
log_message('error', "RuleImportController::upload - Failed to move uploaded file to {$movedFullPath}");
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to store uploaded file.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('info', "RuleImportController::upload - File moved to {$movedFullPath}");
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 4. Insert commission_files row with status pending
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
$insertData = [
|
||||||
|
'file_name' => $targetFileName,
|
||||||
|
'insurer_id' => (int)$insurerId,
|
||||||
|
'department' => $department,
|
||||||
|
'commission_month'=> $commissionMonth,
|
||||||
|
'rules_count' => 0, // will update on success
|
||||||
|
'file_status' => $fileStatus, // 'pending' by default
|
||||||
|
'is_active' => $isActive,
|
||||||
|
'created_by' => (int)$createdBy,
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$commissionFilesModel->insert($insertData);
|
||||||
|
$insertId = $commissionFilesModel->getInsertID();
|
||||||
|
|
||||||
|
if (empty($insertId)) {
|
||||||
|
log_message('error', 'RuleImportController::upload - Failed to insert commission_files record', ['data' => $insertData]);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to record upload in database.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('info', "RuleImportController::upload - commission_files inserted id={$insertId}", $insertData);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 5. Call ruleImportService->processUpload with inserted file info
|
||||||
|
// As per your spec:
|
||||||
|
// $this->ruleImportService->processUpload([
|
||||||
|
// 'id' => 1,
|
||||||
|
// 'file_name' => 'sample_commission.csv',
|
||||||
|
// 'insurer_id' => 5,
|
||||||
|
// 'department' => 'motor',
|
||||||
|
// 'commission_month' => '2025-11-10'
|
||||||
|
// ])
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
$payload = [
|
||||||
|
'id' => (int)$insertId,
|
||||||
|
'file_name' => $targetFileName,
|
||||||
|
'insurer_id' => (int)$insurerId,
|
||||||
|
'department' => $department,
|
||||||
|
'commission_month' => $commissionMonth,
|
||||||
|
];
|
||||||
|
|
||||||
|
log_message('info', 'RuleImportController::upload - Calling ruleImportService->processUpload', ['payload' => $payload]);
|
||||||
|
|
||||||
|
$result = $this->ruleImportService->processUpload($payload);
|
||||||
|
|
||||||
|
if (!is_array($result) || !isset($result['status'])) {
|
||||||
|
log_message('error', 'RuleImportController::upload - Invalid service response', ['response' => $result]);
|
||||||
|
// update file status as failed
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'failed',
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Invalid response from import service.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 6. Handle SUCCESS
|
||||||
|
// - result['rules'] exists
|
||||||
|
// - result['errors'] empty
|
||||||
|
// - NO annotated_file
|
||||||
|
// - Save rules as JSON in WRITEPATH/uploads/commission/json/{insurer_id}_{department}.json
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
if ($result['status'] === 'success') {
|
||||||
|
$rulesArray = isset($result['rules']) && is_array($result['rules']) ? $result['rules'] : [];
|
||||||
|
$rulesCount = count($rulesArray);
|
||||||
|
|
||||||
|
// Save JSON to WRITEPATH . 'uploads/commission/json/{insurer_id}_{department}.json'
|
||||||
|
$jsonDir = WRITEPATH . 'uploads/commission/json/';
|
||||||
|
if (!is_dir($jsonDir)) {
|
||||||
|
if (!mkdir($jsonDir, 0755, true) && !is_dir($jsonDir)) {
|
||||||
|
throw new \RuntimeException("Failed to create JSON output directory: {$jsonDir}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$deptSlug = preg_replace('/[^a-zA-Z0-9_\-]/', '_', strtolower($department));
|
||||||
|
$jsonName = (int)$insurerId . '_' . $deptSlug . '.json';
|
||||||
|
$jsonPath = $jsonDir . $jsonName;
|
||||||
|
|
||||||
|
$jsonData = json_encode($rulesArray, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
|
if ($jsonData === false) {
|
||||||
|
log_message('error', 'RuleImportController::upload - json_encode failed for rules', [
|
||||||
|
'last_error' => json_last_error_msg()
|
||||||
|
]);
|
||||||
|
// mark as failed since we cannot save rules
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'failed',
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to encode rules as JSON.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_put_contents($jsonPath, $jsonData) === false) {
|
||||||
|
log_message('error', 'RuleImportController::upload - Failed to write rules JSON file', ['json_path' => $jsonPath]);
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'failed',
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Failed to store rules JSON file.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
log_message('info', 'RuleImportController::upload - Rules JSON written', [
|
||||||
|
'file_id' => $insertId,
|
||||||
|
'json_path' => $jsonPath,
|
||||||
|
'rules_cnt' => $rulesCount,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Update DB: status, rules_count, updated_by
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'processed',
|
||||||
|
'rules_count' => $rulesCount,
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
// If you have a column for JSON path, uncomment:
|
||||||
|
// 'json_file_path' => $jsonPath,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'success',
|
||||||
|
'message' => 'File processed successfully.',
|
||||||
|
'file_id' => $insertId,
|
||||||
|
'rules_count' => $rulesCount,
|
||||||
|
'json_file' => $jsonPath,
|
||||||
|
'service' => $result, // optional: return full service response if you want
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 7. Handle ERROR (validation failed etc.)
|
||||||
|
// - Do NOT save any rules JSON
|
||||||
|
// - Update file_status to validation_failed
|
||||||
|
// - Store annotated_file path if you have such a column
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
if ($result['status'] === 'error') {
|
||||||
|
$annotatedPath = $result['annotated_file'] ?? null;
|
||||||
|
$errors = $result['errors'] ?? [];
|
||||||
|
|
||||||
|
$updateData = [
|
||||||
|
'file_status' => 'validation_failed',
|
||||||
|
'rules_count' => 0, // do not save rules
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
|
||||||
|
// If you have a column for annotated file path, e.g. annotated_file_path
|
||||||
|
if ($annotatedPath) {
|
||||||
|
$updateData['annotated_file_path'] = $annotatedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
$commissionFilesModel->update($insertId, $updateData);
|
||||||
|
|
||||||
|
log_message('warning', "RuleImportController::upload - Validation failed for file_id={$insertId}", [
|
||||||
|
'errors' => $errors,
|
||||||
|
'annotated_file' => $annotatedPath
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Validation failed. No rules saved.',
|
||||||
|
'file_id' => $insertId,
|
||||||
|
'errors' => $errors,
|
||||||
|
'annotated_file' => $annotatedPath,
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// 8. Unexpected status
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
log_message('error', 'RuleImportController::upload - Unexpected result status from service', ['result' => $result]);
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'failed',
|
||||||
|
'updated_by' => (int)$createdBy,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Unexpected import service result.'
|
||||||
|
], 500);
|
||||||
|
|
||||||
|
} catch (\Throwable $ex) {
|
||||||
|
log_message('critical', 'RuleImportController::upload exception: ' . $ex->getMessage(), [
|
||||||
|
'trace' => $ex->getTraceAsString()
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Try to update the commission_files record if insertId exists
|
||||||
|
if (isset($insertId) && !empty($insertId)) {
|
||||||
|
try {
|
||||||
|
$commissionFilesModel->update($insertId, [
|
||||||
|
'file_status' => 'failed',
|
||||||
|
'updated_by' => isset($createdBy) ? (int)$createdBy : null,
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
'notes' => 'Upload exception: ' . $ex->getMessage(),
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $e2) {
|
||||||
|
log_message('error', 'RuleImportController::upload - failed to update commission_files after exception: ' . $e2->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => 'exception',
|
||||||
|
'message' => $ex->getMessage(),
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2011,6 +2011,7 @@ class TicketController extends BaseController
|
|||||||
{
|
{
|
||||||
$received_data = $this->request->getPost();
|
$received_data = $this->request->getPost();
|
||||||
$ticket_type_id = $this->request->getPost('ticket_type_id') ?? null;
|
$ticket_type_id = $this->request->getPost('ticket_type_id') ?? null;
|
||||||
|
$client_id = $this->request->getPost('client_id') ?? null;
|
||||||
$emp_id = $received_data['emp_id'];
|
$emp_id = $received_data['emp_id'];
|
||||||
|
|
||||||
// Get all client policy IDs for the given employee
|
// Get all client policy IDs for the given employee
|
||||||
@ -2027,6 +2028,9 @@ class TicketController extends BaseController
|
|||||||
$builder->where('e.is_active', 1);
|
$builder->where('e.is_active', 1);
|
||||||
$builder->where('ep.is_active', 1);
|
$builder->where('ep.is_active', 1);
|
||||||
$builder->where('e.emp_code', $self_data['emp_code']);
|
$builder->where('e.emp_code', $self_data['emp_code']);
|
||||||
|
if(!empty($client_id)){
|
||||||
|
$builder->where('e.client_id', $client_id);
|
||||||
|
}
|
||||||
$builder->groupBy('client_policy_id');
|
$builder->groupBy('client_policy_id');
|
||||||
|
|
||||||
$query = $builder->get();
|
$query = $builder->get();
|
||||||
|
|||||||
55
app/Filters/CommissionApiFilter.php
Normal file
55
app/Filters/CommissionApiFilter.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use CodeIgniter\Filters\FilterInterface;
|
||||||
|
|
||||||
|
class CommissionApiFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
public function before(RequestInterface $request, $arguments = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Read API key from header
|
||||||
|
// $authHeader = $request->getHeaderLine('X');
|
||||||
|
$authHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
|
||||||
|
// echo $authHeader;die();
|
||||||
|
if (empty($authHeader)) {
|
||||||
|
return service('response')->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'error' => 'Authorization header missing'
|
||||||
|
])->setStatusCode(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expected format: Bearer YOUR_API_KEY
|
||||||
|
if (stripos($authHeader, 'Bearer ') !== 0) {
|
||||||
|
return service('response')->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'error' => 'Invalid Authorization format. Expected: Bearer <token>'
|
||||||
|
])->setStatusCode(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$apiKey = trim(substr($authHeader, 7)); // extract token after 'Bearer '
|
||||||
|
|
||||||
|
$envKeys = getenv('ALLOWED_COMMISSION_API_KEYS');
|
||||||
|
// Convert CSV -> Array
|
||||||
|
$allowedKeys = array_map('trim', explode(',', $envKeys));
|
||||||
|
// print_r($allowedKeys);die();
|
||||||
|
// Validate
|
||||||
|
if (!in_array($apiKey, $allowedKeys, true)) {
|
||||||
|
return service('response')->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'error' => 'Invalid API Key'
|
||||||
|
])->setStatusCode(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow request to proceed
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
|
||||||
|
{
|
||||||
|
// Not needed
|
||||||
|
}
|
||||||
|
}
|
||||||
1373
app/Libraries/RuleImportService.php
Normal file
1373
app/Libraries/RuleImportService.php
Normal file
File diff suppressed because it is too large
Load Diff
67
app/Models/CommissionFilesModel.php
Normal file
67
app/Models/CommissionFilesModel.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class CommissionFilesModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'commission_files';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false;
|
||||||
|
|
||||||
|
protected $allowedFields = [
|
||||||
|
'file_name',
|
||||||
|
'insurer_id',
|
||||||
|
'department',
|
||||||
|
'commission_month',
|
||||||
|
'file_status',
|
||||||
|
'is_active',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Auto timestamps by CI4
|
||||||
|
protected $useTimestamps = true;
|
||||||
|
protected $createdField = 'created_at';
|
||||||
|
protected $updatedField = 'updated_at';
|
||||||
|
|
||||||
|
// Validation rules (optional)
|
||||||
|
// protected $validationRules = [
|
||||||
|
// 'file_name' => 'required|min_length[1]|max_length[100]',
|
||||||
|
// 'insurer_id' => 'permit_empty|integer',
|
||||||
|
// 'department' => 'permit_empty|max_length[45]',
|
||||||
|
// 'commission_month' => 'permit_empty|valid_date',
|
||||||
|
// 'file_status' => 'permit_empty|max_length[10]',
|
||||||
|
// 'is_active' => 'permit_empty|in_list[0,1]'
|
||||||
|
// ];
|
||||||
|
|
||||||
|
protected $validationMessages = [];
|
||||||
|
protected $skipValidation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get files with optional filters
|
||||||
|
*/
|
||||||
|
// public function getFiles($filters = [])
|
||||||
|
// {
|
||||||
|
// if (!empty($filters['insurer_id'])) {
|
||||||
|
// $this->where('insurer_id', $filters['insurer_id']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!empty($filters['department'])) {
|
||||||
|
// $this->where('department', $filters['department']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (!empty($filters['file_status'])) {
|
||||||
|
// $this->where('file_status', $filters['file_status']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (isset($filters['is_active'])) {
|
||||||
|
// $this->where('is_active', $filters['is_active']);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return $this->orderBy('id', 'DESC')->findAll();
|
||||||
|
// }
|
||||||
|
}
|
||||||
41
app/Models/InvoiceItemModel.php
Normal file
41
app/Models/InvoiceItemModel.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class InvoiceItemModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'partner_invoice_items';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false;
|
||||||
|
|
||||||
|
protected $allowedFields = [
|
||||||
|
'invoice_id',
|
||||||
|
'policy_id',
|
||||||
|
'policy_no',
|
||||||
|
'commission_amount',
|
||||||
|
'is_active',
|
||||||
|
'created_at',
|
||||||
|
'created_by',
|
||||||
|
'updated_at',
|
||||||
|
'updated_by'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $useTimestamps = false;
|
||||||
|
protected $createdField = 'created_at';
|
||||||
|
protected $updatedField = 'updated_at';
|
||||||
|
|
||||||
|
protected $validationRules = [
|
||||||
|
'invoice_id' => 'required|integer',
|
||||||
|
'policy_id' => 'required|integer',
|
||||||
|
'policy_no' => 'required|max_length[100]',
|
||||||
|
'commission_amount' => 'decimal'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $validationMessages = [];
|
||||||
|
protected $skipValidation = false;
|
||||||
|
}
|
||||||
190
app/Models/InvoiceModel.php
Normal file
190
app/Models/InvoiceModel.php
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class InvoiceModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'partner_invoice';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false;
|
||||||
|
|
||||||
|
protected $allowedFields = [
|
||||||
|
'invoice_no',
|
||||||
|
'invoice_amount',
|
||||||
|
'agent_id',
|
||||||
|
'invoice_date',
|
||||||
|
'is_active',
|
||||||
|
'created_at',
|
||||||
|
'created_by',
|
||||||
|
'updated_at',
|
||||||
|
'payout_status',
|
||||||
|
];
|
||||||
|
|
||||||
|
// Timestamps
|
||||||
|
protected $useTimestamps = false;
|
||||||
|
protected $createdField = 'created_at';
|
||||||
|
protected $updatedField = 'updated_at';
|
||||||
|
|
||||||
|
// Validation (optional)
|
||||||
|
protected $validationRules = [
|
||||||
|
'invoice_no' => 'required|max_length[100]',
|
||||||
|
'invoice_amount' => 'decimal',
|
||||||
|
'agent_id' => 'required|integer',
|
||||||
|
'invoice_date' => 'required|valid_date',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $validationMessages = [];
|
||||||
|
protected $skipValidation = false;
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
protected $allowCallbacks = true;
|
||||||
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||||
|
protected $afterInsert = [];
|
||||||
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||||
|
protected $afterUpdate = [];
|
||||||
|
protected $beforeFind = [];
|
||||||
|
protected $afterFind = [];
|
||||||
|
protected $beforeDelete = [];
|
||||||
|
protected $afterDelete = [];
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null)
|
||||||
|
{
|
||||||
|
$data = $this->select("
|
||||||
|
partner_invoice.*,
|
||||||
|
|
||||||
|
-- Total UTR Amount
|
||||||
|
(SELECT SUM(piu.amount)
|
||||||
|
FROM partner_invoice_utr piu
|
||||||
|
WHERE piu.invoice_id = partner_invoice.id
|
||||||
|
AND piu.is_active = 1
|
||||||
|
) AS total_utr_amount,
|
||||||
|
|
||||||
|
-- Balance Amount
|
||||||
|
(partner_invoice.invoice_amount -
|
||||||
|
IFNULL(
|
||||||
|
(SELECT SUM(piu2.amount)
|
||||||
|
FROM partner_invoice_utr piu2
|
||||||
|
WHERE piu2.invoice_id = partner_invoice.id
|
||||||
|
AND piu2.is_active = 1
|
||||||
|
),
|
||||||
|
0)
|
||||||
|
) AS balance_amount,
|
||||||
|
|
||||||
|
-- Payout status
|
||||||
|
CASE
|
||||||
|
WHEN payout_status = 1 THEN 'Pending'
|
||||||
|
WHEN payout_status = 2 THEN 'Complete'
|
||||||
|
END AS status_text,
|
||||||
|
|
||||||
|
partner_agent.name as agent_name
|
||||||
|
")
|
||||||
|
->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id')
|
||||||
|
->where('partner_invoice.is_active', 1);
|
||||||
|
|
||||||
|
if(!empty($agent_id)){
|
||||||
|
$data->where('partner_invoice.agent_id', $agent_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($status_id)){
|
||||||
|
$data->where('partner_invoice.payout_status', $status_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($start_date) && !empty($end_date)) {
|
||||||
|
|
||||||
|
$startDate = date('Y-m-d 00:00:00', strtotime($start_date));
|
||||||
|
$endDate = date('Y-m-d 23:59:59', strtotime($end_date));
|
||||||
|
|
||||||
|
$data->where('partner_invoice.invoice_date >=', $startDate)
|
||||||
|
->where('partner_invoice.invoice_date <=', $endDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){
|
||||||
|
|
||||||
|
$fromDate = date('Y-m-d', strtotime('-60 days'));
|
||||||
|
$toDate = date('Y-m-d 23:59:59');
|
||||||
|
|
||||||
|
$data->where('partner_invoice.created_at >=', $fromDate)
|
||||||
|
->where('partner_invoice.created_at <=', $toDate);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$return_data = $data->orderBy('partner_invoice.id','desc')->findAll();
|
||||||
|
|
||||||
|
// print_r($this->db->getLastQuery()); die;
|
||||||
|
|
||||||
|
return $return_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function agentList()
|
||||||
|
{
|
||||||
|
return $this->db->table('partner_agent')->where('is_active', 1)->get()->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function utrSummary($invoice_id)
|
||||||
|
{
|
||||||
|
$data = $this->select("
|
||||||
|
|
||||||
|
partner_invoice.*,
|
||||||
|
|
||||||
|
-- Total UTR Amount
|
||||||
|
(SELECT SUM(piu.amount)
|
||||||
|
FROM partner_invoice_utr piu
|
||||||
|
WHERE piu.invoice_id = partner_invoice.id
|
||||||
|
AND piu.is_active = 1
|
||||||
|
) AS total_utr_amount,
|
||||||
|
|
||||||
|
-- Balance Amount
|
||||||
|
(partner_invoice.invoice_amount -
|
||||||
|
IFNULL(
|
||||||
|
(SELECT SUM(piu2.amount)
|
||||||
|
FROM partner_invoice_utr piu2
|
||||||
|
WHERE piu2.invoice_id = partner_invoice.id
|
||||||
|
AND piu2.is_active = 1
|
||||||
|
),
|
||||||
|
0)
|
||||||
|
) AS balance_amount,
|
||||||
|
|
||||||
|
-- Payout status
|
||||||
|
CASE
|
||||||
|
WHEN payout_status = 1 THEN 'Pending'
|
||||||
|
WHEN payout_status = 2 THEN 'Complete'
|
||||||
|
END AS status_text,
|
||||||
|
|
||||||
|
partner_agent.name as agent_name
|
||||||
|
")
|
||||||
|
->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id')
|
||||||
|
->where('partner_invoice.is_active', 1)
|
||||||
|
->where('partner_invoice.id', $invoice_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
73
app/Models/InvoiceUtrModel.php
Normal file
73
app/Models/InvoiceUtrModel.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
|
class InvoiceUtrModel extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'partner_invoice_utr';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $useAutoIncrement = true;
|
||||||
|
|
||||||
|
protected $returnType = 'array';
|
||||||
|
protected $useSoftDeletes = false;
|
||||||
|
|
||||||
|
protected $allowedFields = [
|
||||||
|
'invoice_id',
|
||||||
|
'utr_no',
|
||||||
|
'amount',
|
||||||
|
'utr_date',
|
||||||
|
'is_active',
|
||||||
|
'created_at',
|
||||||
|
'created_by',
|
||||||
|
'updated_at',
|
||||||
|
'updated_by'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $useTimestamps = false;
|
||||||
|
protected $createdField = 'created_at';
|
||||||
|
protected $updatedField = 'updated_at';
|
||||||
|
|
||||||
|
protected $validationRules = [
|
||||||
|
'invoice_id' => 'required|integer',
|
||||||
|
'utr_no' => 'required|max_length[100]',
|
||||||
|
'amount' => 'decimal'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $validationMessages = [];
|
||||||
|
protected $skipValidation = false;
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
protected $allowCallbacks = true;
|
||||||
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||||
|
protected $afterInsert = [];
|
||||||
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||||
|
protected $afterUpdate = [];
|
||||||
|
protected $beforeFind = [];
|
||||||
|
protected $afterFind = [];
|
||||||
|
protected $beforeDelete = [];
|
||||||
|
protected $afterDelete = [];
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ class TicketClaimStatusModel extends Model
|
|||||||
protected $returnType = 'array';
|
protected $returnType = 'array';
|
||||||
protected $useSoftDeletes = false;
|
protected $useSoftDeletes = false;
|
||||||
protected $protectFields = true;
|
protected $protectFields = true;
|
||||||
protected $allowedFields = ["id", "ticket_type", "claim_status", "created_by", "updated_by", "is_active"];
|
protected $allowedFields = ["id", "ticket_type", "claim_status", "display_name", "created_by", "updated_by", "is_active"];
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
protected $allowCallbacks = true;
|
protected $allowCallbacks = true;
|
||||||
|
|||||||
@ -548,14 +548,14 @@ function fetchFileError(file_id) {
|
|||||||
"<strong>Rule conflict: Twofold relationship found within family</strong> <span class='badge badge-danger float-right'>" +
|
"<strong>Rule conflict: Twofold relationship found within family</strong> <span class='badge badge-danger float-right'>" +
|
||||||
err_count + "</span>";
|
err_count + "</span>";
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 100:
|
||||||
hasError14 = true;
|
hasError14 = true;
|
||||||
error_code = 14;
|
error_code = 14;
|
||||||
file_error_html +=
|
file_error_html +=
|
||||||
"<strong>This inception row was not found in the member data list.</strong> <span class='badge badge-danger float-right'>" +
|
"<strong>This inception row was not found in the member data list.</strong> <span class='badge badge-danger float-right'>" +
|
||||||
err_count + "</span>";
|
err_count + "</span>";
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 101:
|
||||||
hasError15 = true;
|
hasError15 = true;
|
||||||
error_code = 15;
|
error_code = 15;
|
||||||
file_error_html +=
|
file_error_html +=
|
||||||
|
|||||||
@ -144,7 +144,7 @@
|
|||||||
// $listed_pre[] = $policies['branch_id'].'-'.$policies['policy_no'];
|
// $listed_pre[] = $policies['branch_id'].'-'.$policies['policy_no'];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if($value['pre_branch_id'] !== $policies['branch_id']){
|
if(empty($value['pre_hr_id']) || $value['pre_branch_id'] !== $policies['branch_id']){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -212,7 +212,7 @@
|
|||||||
// $listed_post[] = $policies['branch_id'].'-'.$policies['policy_no'];
|
// $listed_post[] = $policies['branch_id'].'-'.$policies['policy_no'];
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if($value['post_branch_id'] !== $policies['branch_id']){
|
if(empty($value['post_hr_id']) || $value['post_branch_id'] !== $policies['branch_id']){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2017,6 +2017,12 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?= base_url('/payouts') ?>">
|
||||||
|
<i class="ri-book-open-line"></i>
|
||||||
|
<span> Payouts</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@ -95,6 +95,7 @@ p{
|
|||||||
background-image:url('<?= $client_logo ?>');
|
background-image:url('<?= $client_logo ?>');
|
||||||
background-size:contain;
|
background-size:contain;
|
||||||
background-repeat:no-repeat;
|
background-repeat:no-repeat;
|
||||||
|
background-position: center;
|
||||||
">
|
">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
357
app/Views/payout_list.php
Normal file
357
app/Views/payout_list.php
Normal file
@ -0,0 +1,357 @@
|
|||||||
|
<style>
|
||||||
|
|
||||||
|
.table th,
|
||||||
|
.table td {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.dataTable tbody td {
|
||||||
|
padding: 4px 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.col-12 {
|
||||||
|
|
||||||
|
max-width: 98% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_filter {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.right-align-input {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-container {
|
||||||
|
background: #F0F0F0;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 14px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-box {
|
||||||
|
background: #e3f2fd;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-left: 4px solid #2196F3;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
.summary-box {
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-row:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: bold;
|
||||||
|
padding-top: 4px;
|
||||||
|
border-top: 1px solid #2196F3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-row {
|
||||||
|
padding: 0px 0;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.summary-row span:last-child {
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-section {
|
||||||
|
margin-top: 15px;
|
||||||
|
padding-top: 15px;
|
||||||
|
border-top: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-heading {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-form-group {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-label {
|
||||||
|
font-size: 13px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-small-text {
|
||||||
|
color: #666;
|
||||||
|
display: block;
|
||||||
|
margin-top: 3px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-submit-wrapper {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-list {
|
||||||
|
margin-top: 15px;
|
||||||
|
border-top: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table thead tr {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table tbody {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-dropdown-item {
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 5px 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-icon {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#payout_modal .modal-body {
|
||||||
|
max-height: 550px; /* adjust as needed */
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.utr-table td,
|
||||||
|
.utr-table th {
|
||||||
|
padding: 3px 8px !important;
|
||||||
|
vertical-align: middle;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table tbody tr {
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table thead th {
|
||||||
|
padding: 5px 8px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table .btn-sm {
|
||||||
|
padding: 1px 6px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table .mdi {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-table .dropdown-menu {
|
||||||
|
min-width: 110px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.utr-dropdown-item {
|
||||||
|
padding: 7px 10px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
table[data-custom-table-css="table"] tbody tr td {
|
||||||
|
padding: 1px 10px !important;
|
||||||
|
line-height: 12px;
|
||||||
|
min-height: 40px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row" style="padding-bottom: 10px;">
|
||||||
|
<div class="col-6" style="align-self: center;">
|
||||||
|
<h4 style="position: relative;">Payout List <span id="payout_title"></span></h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table data-custom-table-css="table" id="scroll-horizontal-datatable" class="table w-100 nowrap">
|
||||||
|
<thead class="bg-light">
|
||||||
|
<tr>
|
||||||
|
<th class="font-weight-medium">S.No.</th>
|
||||||
|
<th class="font-weight-medium">Inovice No</th>
|
||||||
|
<th class="font-weight-medium">Invoice Date</th>
|
||||||
|
<th class="font-weight-medium">Invoice Amount</th>
|
||||||
|
<th class="font-weight-medium">UTR Total Amount</th>
|
||||||
|
<th class="font-weight-medium">Balance</th>
|
||||||
|
<th class="font-weight-medium">Status</th>
|
||||||
|
<th class="font-weight-medium">Agent</th>
|
||||||
|
<th class="font-weight-medium">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (isset($payout_list_data) && !empty($payout_list_data)) { ?>
|
||||||
|
<?php foreach($payout_list_data as $index => $row){ ?>
|
||||||
|
<tr>
|
||||||
|
<td> <?= $index + 1 ?> </td>
|
||||||
|
<td> <?= $row['invoice_no'] ?> </td>
|
||||||
|
<td> <?= change_date_format($row['invoice_no'], null, 'd-M-Y') ?? "" ?> </td>
|
||||||
|
<td> <?= format_indian_number($row['invoice_amount']) ?> </td>
|
||||||
|
<td> <?= format_indian_number($row['total_utr_amount']) ?> </td>
|
||||||
|
<td> <?= format_indian_number($row['balance_amount']) ?> </td>
|
||||||
|
<td> <?= $row['status_text'] ?> </td>
|
||||||
|
<td> <?= $row['agent_name'] ?? " - " ?> </td>
|
||||||
|
<td>
|
||||||
|
<div class="btn-group dropdown">
|
||||||
|
<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">
|
||||||
|
<a class="dropdown-item" onclick="fetchUtrDetails(<?= $row['id'] ?>, '<?= $row['invoice_no'] ?>')"><i class="mdi mdi-bank-transfer mr-2 text-muted font-18 vertical-middle"></i>UTR</a>
|
||||||
|
<a href="<?= base_url('payout/invoices/save?type="edit"') ?>" class="dropdown-item"><i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
||||||
|
<a href="<?= base_url('payout/invoices/save?type="adjustment"') ?>" class="dropdown-item"><i class="mdi mdi-tune mr-2 text-muted font-18 vertical-middle"></i>Adjustment</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div><!-- end col -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="payout_modal" tabindex="-1" role="dialog" aria-hidden="true" aria-modal="true" data-bs-backdrop="static">
|
||||||
|
<div class="modal-dialog modal-lg" style="max-width: 800px;">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header" style="background-color: gainsboro;">
|
||||||
|
<h5 class="modal-title" id="myCenterModalLabel">UTR <span id="heading"></span></h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="modal_body">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-------------------------------------------------------------------------------------------------->
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// Datatable document ready
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
var ticketsTable = $('#scroll-horizontal-datatable');
|
||||||
|
if (ticketsTable.length) {
|
||||||
|
ticketsTable.DataTable({
|
||||||
|
scrollX: true,
|
||||||
|
dom: "<'row'<'col-sm-6'f><'col-sm-6 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
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
extend: 'collection',
|
||||||
|
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||||||
|
className: 'btn app-btn-secondary ',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
extend: 'csv',
|
||||||
|
title: 'List',
|
||||||
|
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
extend: 'excel',
|
||||||
|
title: 'List',
|
||||||
|
sheetName: 'Policy-Tranction-payout-List',
|
||||||
|
text: '<i class="mdi mdi-file-excel " ></i><span class=" btn-custom"> EXCEL </span>',
|
||||||
|
className: 'app-btn-primary ',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
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
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error("Table atet found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function fetchUtrDetails(invoice_id, invoice_no)
|
||||||
|
{
|
||||||
|
if (!invoice_id) {
|
||||||
|
toastr.warning("Invoice Id not found!", "WARNING");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let heading_text = ' - ( Invoice No : ' + invoice_no + ' )';
|
||||||
|
|
||||||
|
$('#modal_body').empty();
|
||||||
|
$('#heading').text(heading_text);
|
||||||
|
$('#modal_body').append('<div class="text-center p-5"><div class="spinner-border text-primary" role="status"><span class="sr-only">Loading...</span></div></div>');
|
||||||
|
|
||||||
|
var myModal = new bootstrap.Modal(document.getElementById('payout_modal'));
|
||||||
|
myModal.show();
|
||||||
|
|
||||||
|
let url = '<?= base_url('payout/fetchUtrDetails') ?>';
|
||||||
|
|
||||||
|
// Data to send in the AJAX request
|
||||||
|
let requestData = {
|
||||||
|
invoice_id: invoice_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
// Send AJAX request
|
||||||
|
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
|
||||||
|
$('#modal_body').empty();
|
||||||
|
$('#heading').text(heading_text);
|
||||||
|
$('#modal_body').append(response.data);
|
||||||
|
|
||||||
|
if (response.status == false) {
|
||||||
|
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
|
||||||
|
}, function(xhr, status, error) {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
184
app/Views/payout_list_handler.php
Normal file
184
app/Views/payout_list_handler.php
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
<div class="container-fluid-min">
|
||||||
|
<div class="col-12" id="bds_filter">
|
||||||
|
<div class="card-body">
|
||||||
|
<div id="accordion" class="mb-3">
|
||||||
|
<div class="card mb-1">
|
||||||
|
<h4 class="m-1">
|
||||||
|
<span>Filter</span>
|
||||||
|
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
|
||||||
|
aria-expanded="true">
|
||||||
|
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
||||||
|
</a>
|
||||||
|
</h4>
|
||||||
|
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="client_branch">Agents<span class="text-danger"></span></label>
|
||||||
|
<select class="form-control" id="agent_id" name="agent_id">
|
||||||
|
<option value="">Select Agent</option>
|
||||||
|
<?php if (isset($agent_list) && !empty($agent_list)) : ?>
|
||||||
|
<?php foreach ($agent_list as $agent) : ?>
|
||||||
|
<option value="<?= $agent['id']; ?>"><?= $agent['name']; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="client_branch_id">Status<span class="text-danger"></span></label>
|
||||||
|
<select class="form-control" id="status_id" name="status_id">
|
||||||
|
<option value="">Select status</option>
|
||||||
|
<?php if (isset($payout_status) && !empty($payout_status)) : ?>
|
||||||
|
<?php foreach ($payout_status as $id => $status) : ?>
|
||||||
|
<option value="<?= $id; ?>"><?= $status; ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3" style="display: true;" id="date_div">
|
||||||
|
<label>Date<span class="text-danger"></span></label>
|
||||||
|
<div class="input-icon">
|
||||||
|
<input type="text" id="reportrange" class="form-control" readonly style="caret-color: transparent;">
|
||||||
|
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="startDate">
|
||||||
|
<input type="hidden" id="endDate">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-12 text-right m-b-0" style="margin-top: 29px;">
|
||||||
|
<a class="btn btn-secondary" id="clear-filters">Clear</a>
|
||||||
|
<a class="btn btn-primary" id="get-emp-list" onclick="fetchPayoutList(this);">Submit</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- end page title -->
|
||||||
|
<div id="payout_list">
|
||||||
|
<?php if(isset($payout_list) && !empty($payout_list)) { echo $payout_list; }else{ } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('#agent_id').select2();
|
||||||
|
$('#startDate').val('');
|
||||||
|
$('#endDate').val('');
|
||||||
|
$('#reportrange').val('');
|
||||||
|
})
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
const params = new URLSearchParams(url.search);
|
||||||
|
|
||||||
|
// Get start and end dates from URL parameters, or use default values
|
||||||
|
const startDateParam = params.get('start_date') || moment().subtract(60, 'days').format('DD-MM-YYYY');
|
||||||
|
const endDateParam = params.get('end_date') || moment().format('DD-MM-YYYY');
|
||||||
|
|
||||||
|
// Parse the dates to moment objects
|
||||||
|
var start = moment(startDateParam, 'DD-MM-YYYY');
|
||||||
|
var end = moment(endDateParam, 'DD-MM-YYYY');
|
||||||
|
|
||||||
|
function cb(start, end) {
|
||||||
|
$('#reportrange').val(start.format('D-MM-YYYY') + ' - ' + end.format('D-MM-YYYY'));
|
||||||
|
$('#startDate').val(start.format('DD-MM-YYYY'));
|
||||||
|
$('#endDate').val(end.format('DD-MM-YYYY'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#reportrange').daterangepicker({
|
||||||
|
startDate: start,
|
||||||
|
endDate: end,
|
||||||
|
locale: {
|
||||||
|
format: 'DD-MM-YYYY'
|
||||||
|
},
|
||||||
|
ranges: {
|
||||||
|
'Today': [moment(), moment()],
|
||||||
|
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||||
|
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||||
|
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
|
||||||
|
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
||||||
|
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
||||||
|
},
|
||||||
|
autoUpdateInput: false
|
||||||
|
}, cb);
|
||||||
|
|
||||||
|
// Only update inputs when user selects a date range
|
||||||
|
$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
|
||||||
|
cb(picker.startDate, picker.endDate);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#clear-filters').on('click', function() {
|
||||||
|
// Reset all select dropdowns to the first option
|
||||||
|
$('#agent_id').val('').change();
|
||||||
|
$('#status_id').val('').change();
|
||||||
|
|
||||||
|
// Clear the date range inputs
|
||||||
|
$('#reportrange').val('');
|
||||||
|
$('#startDate').val('');
|
||||||
|
$('#endDate').val('');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function fetchPayoutList()
|
||||||
|
{
|
||||||
|
let agent_id = $('#agent_id').val();
|
||||||
|
let status_id = $('#status_id').val();
|
||||||
|
let start_date = $('#startDate').val();
|
||||||
|
let end_date = $('#endDate').val();
|
||||||
|
|
||||||
|
if (!agent_id && !status_id && !start_date && !end_date) {
|
||||||
|
toastr.warning("Please select any one filter!", "WARNING");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = '<?= base_url('payout/list') ?>';
|
||||||
|
|
||||||
|
// Data to send in the AJAX request
|
||||||
|
let requestData = {
|
||||||
|
agent_id: agent_id,
|
||||||
|
status_id: status_id,
|
||||||
|
start_date: start_date,
|
||||||
|
end_date: end_date,
|
||||||
|
};
|
||||||
|
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
// Send AJAX request
|
||||||
|
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
|
||||||
|
$('#payout_list').empty();
|
||||||
|
$('#payout_list').append(response.data);
|
||||||
|
|
||||||
|
if (response.status == false) {
|
||||||
|
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
|
||||||
|
}, function(xhr, status, error) {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
$('#payout_list').empty();
|
||||||
|
$('#payout_list').append(response.data);
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
280
app/Views/payout_utr_details.php
Normal file
280
app/Views/payout_utr_details.php
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
<div>
|
||||||
|
|
||||||
|
<div class="summary-box">
|
||||||
|
<div class="summary-row">
|
||||||
|
<span>Invoice Amount:</span>
|
||||||
|
<span id="utrInvoiceAmount" data-id="<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? $summary['invoice_amount'] : ""?>">
|
||||||
|
₹<?php echo isset($summary['invoice_amount']) && !empty($summary['invoice_amount']) ? format_indian_number($summary['invoice_amount']) : "0.00"?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span>Total Paid:</span>
|
||||||
|
<span id="utrTotalPaid" data-id="<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? $summary['total_utr_amount'] : ""?>">
|
||||||
|
₹<?php echo isset($summary['total_utr_amount']) && !empty($summary['total_utr_amount']) ? format_indian_number($summary['total_utr_amount']) : "0.00"?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span>Remaining Balance:</span>
|
||||||
|
<span id="utrRemaining" data-id="<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? $summary['balance_amount'] : ""?>">
|
||||||
|
₹<?php echo isset($summary['balance_amount']) && !empty($summary['balance_amount']) ? format_indian_number($summary['balance_amount']) : "0.00"?>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="utrContent">
|
||||||
|
<div class="utr-section">
|
||||||
|
<!-- <h5 class="utr-heading">Add New UTR</h5> -->
|
||||||
|
<form id="utrForm" role="form" class="parsley-examples">
|
||||||
|
<input type="hidden" name="utr_pk" id="utr_pk">
|
||||||
|
<input type="hidden" name="invoice_id" value="<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ""?>">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="form-group utr-form-group">
|
||||||
|
<label class="utr-label">UTR Number <span class="text-danger">*</span></label>
|
||||||
|
<input type="text" name="utr_no" id="utrNumber" class="form-control form-control-sm" placeholder="Enter UTR number" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="form-group utr-form-group">
|
||||||
|
<label class="utr-label">Amount (₹) <span class="text-danger">*</span></label>
|
||||||
|
<input type="number" name="amount" id="utrAmount" oninput="checkSum(this)" class="form-control form-control-sm" step="0.01" placeholder="Enter amount" required>
|
||||||
|
<!-- <small class="utr-small-text">
|
||||||
|
Max: <span id="maxUtrAmount">₹0.00</span>
|
||||||
|
</small> -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="form-group utr-form-group">
|
||||||
|
<label class="utr-label">Date <span class="text-danger">*</span></label>
|
||||||
|
<input type="text" name="utr_date" id="utrDate" class="form-control form-control-sm" placeholder="DD/MM/YYYY" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-3" style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>">
|
||||||
|
<div class="form-group utr-submit-wrapper">
|
||||||
|
<a onclick="resetvalues()" class="btn btn-secondary btn-sm">Clear</a>
|
||||||
|
<button id="utr_submit_btn" onclick="saveUtrDetails(event)" class="btn btn-primary btn-sm">Add UTR</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="utr-list" id="utrList">
|
||||||
|
<h5 class="utr-heading">Existing UTRs</h5>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table data-custom-table-css="table" id="ticket-table" class="table table-sm w-100 nowrap utr-table">
|
||||||
|
<thead class="bg-light">
|
||||||
|
<tr>
|
||||||
|
<th class="font-weight-medium">S.No.</th>
|
||||||
|
<th class="font-weight-medium">UTR No</th>
|
||||||
|
<th class="font-weight-medium">Amount</th>
|
||||||
|
<th class="font-weight-medium">Date</th>
|
||||||
|
<!-- <th class="font-weight-medium">User</th> -->
|
||||||
|
<th class="font-weight-medium">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (isset($utr_list_data) && !empty($utr_list_data)) { ?>
|
||||||
|
<?php foreach($utr_list_data as $index => $row){
|
||||||
|
$row['utr_date'] = change_date_format($row['utr_date'], null, 'd/m/Y') ?? " - "
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td> <?= $index + 1 ?> </td>
|
||||||
|
<td> <?= $row['utr_no'] ?> </td>
|
||||||
|
<td> <?= format_indian_number($row['amount']) ?> </td>
|
||||||
|
<td> <?= $row['utr_date'] ?> </td>
|
||||||
|
<!-- <td> <?php // format_indian_number($row['created_user']) ?> </td> -->
|
||||||
|
<td>
|
||||||
|
<div class="btn-group dropdown">
|
||||||
|
<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">
|
||||||
|
|
||||||
|
<a style="<?= !isset($invoice_completed) ? 'display: block;' : 'display: none;' ?>" class="dropdown-item utr-dropdown-item" onclick='updateUtr(<?= htmlspecialchars(json_encode($row ?? []), ENT_QUOTES, "UTF-8") ?>)'><i class="mdi mdi-pencil mr-2 text-muted utr-icon vertical-middle"></i>Edit</a>
|
||||||
|
<a class="dropdown-item utr-dropdown-item" onclick="removeUtrApi(<?php echo isset($summary['id']) && !empty($summary['id']) ? $summary['id'] : ''?>, <?= $row['id'] ?>)"><i class="mdi mdi-delete mr-2 text-muted utr-icon vertical-middle"></i>Delete</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var dob = flatpickr("#utrDate", {
|
||||||
|
dateFormat: "d/m/Y",
|
||||||
|
allowInput: false,
|
||||||
|
maxDate: "today"
|
||||||
|
});
|
||||||
|
|
||||||
|
function saveUtrDetails(e) {
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
console.log('saveUtrDetails function called');
|
||||||
|
|
||||||
|
var isValid = $('#utrForm').parsley().validate();
|
||||||
|
if (!isValid) {
|
||||||
|
$('#utrForm').find('input, select, textarea').each(function() {
|
||||||
|
if ($(this).parsley().isValid() === false && !$(this).val()) {
|
||||||
|
console.log(' :) Empty field ID:', this.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log('Form is Empty', 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var formData = new FormData($('#utrForm')[0]);
|
||||||
|
|
||||||
|
// Show loading state
|
||||||
|
$('#utr_submit_btn').prop('disabled', true).text('Saving...');
|
||||||
|
|
||||||
|
let url = '<?= base_url('payout/saveUtrDetails') ?>';
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'POST',
|
||||||
|
data: formData,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
|
||||||
|
if (response.status == true) {
|
||||||
|
toastr.success(response.message, 'SUCCESS');
|
||||||
|
$('#modal_body').empty();
|
||||||
|
$('#modal_body').append(response.data);
|
||||||
|
}else{
|
||||||
|
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-enable button
|
||||||
|
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
||||||
|
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$('#utr_submit_btn').prop('disabled', false).text('Add UTR');
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
resetvalues();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateUtr(data){
|
||||||
|
console.log("data", data)
|
||||||
|
if(data){
|
||||||
|
$('#utr_pk').val(data.id);
|
||||||
|
$('#utrNumber').val(data.utr_no);
|
||||||
|
$('#utrAmount').val(data.amount);
|
||||||
|
$('#utrDate').val(data.utr_date);
|
||||||
|
$('#utr_submit_btn').text('Update UTR');
|
||||||
|
$('#utrNumber').trigger('focus');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetvalues(){
|
||||||
|
$('#utr_pk').val("");
|
||||||
|
$('#utrNumber').val("");
|
||||||
|
$('#utrAmount').val("");
|
||||||
|
$('#utrDate').val("");
|
||||||
|
$('#utr_submit_btn').text('Add UTR');
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeUtrApi(invoice_id, utr_id) {
|
||||||
|
Swal.fire({
|
||||||
|
title: "Are you sure?",
|
||||||
|
text: "Do you want to remove this UTR?",
|
||||||
|
icon: "warning",
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "Yes, Proceed!",
|
||||||
|
cancelButtonText: "Cancel"
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
removeUtr(invoice_id, utr_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeUtr(invoice_id, utr_id){
|
||||||
|
|
||||||
|
let url = '<?= base_url('payout/removeUtrDetails') ?>';
|
||||||
|
|
||||||
|
// Data to send in the AJAX request
|
||||||
|
let requestData = {
|
||||||
|
invoice_id: invoice_id,
|
||||||
|
utr_id: utr_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
$('.loader').fadeIn();
|
||||||
|
$('.loader-mask').fadeIn();
|
||||||
|
|
||||||
|
// Send AJAX request
|
||||||
|
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
|
||||||
|
$('#modal_body').empty();
|
||||||
|
$('#modal_body').append(response.data);
|
||||||
|
|
||||||
|
if (response.status == true) {
|
||||||
|
toastr.success(response.message, 'SUCCESS');
|
||||||
|
}else{
|
||||||
|
toastr.warning(response.message || 'Unable to fetch data', 'WARNING');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
|
||||||
|
}, function(xhr, status, error) {
|
||||||
|
$('.loader').fadeOut();
|
||||||
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
toastr.error('An error occurred while fetching the data.', 'ERROR');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSum(input) {
|
||||||
|
|
||||||
|
let invoice_amt = parseFloat($('#utrInvoiceAmount').data('id')) || 0;
|
||||||
|
let utr_amt = parseFloat($('#utrTotalPaid').data('id')) || 0;
|
||||||
|
let balance_amt = parseFloat($('#utrRemaining').data('id')) || 0;
|
||||||
|
|
||||||
|
let input_amt = parseFloat($(input).val()) || 0;
|
||||||
|
|
||||||
|
console.log({ invoice_amt, utr_amt, balance_amt, input_amt });
|
||||||
|
|
||||||
|
let total_amt = utr_amt + input_amt;
|
||||||
|
|
||||||
|
if (total_amt > invoice_amt) {
|
||||||
|
toastr.warning('UTR amount exceeds the invoice amount');
|
||||||
|
$(input).val('');
|
||||||
|
$('#utr_submit_btn').prop('disabled', true);
|
||||||
|
}else{
|
||||||
|
$('#utr_submit_btn').prop('disabled', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
0
app/Views/policy_transaction_payouts.php
Normal file
0
app/Views/policy_transaction_payouts.php
Normal file
@ -948,16 +948,21 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
function getClientPolicy() {
|
function getClientPolicy() {
|
||||||
|
|
||||||
console.log("get policy function called");
|
console.log("get policy function called");
|
||||||
hiddenData = $("#empIDHidden").val();
|
hiddenData = $("#empIDHidden").val();
|
||||||
hiddenData = JSON.parse(hiddenData);
|
hiddenData = JSON.parse(hiddenData);
|
||||||
console.log('employee id ', hiddenData['emp_id']);
|
console.log('employee id ', hiddenData['emp_id']);
|
||||||
let ticket_type_id = $('#ticket_type_id').val();
|
let ticket_type_id = $('#ticket_type_id').val();
|
||||||
console.log("ticket_type_id", ticket_type_id);
|
let client_id = $('#mobile_emp_client_data_list').val();
|
||||||
|
console.log({ticket_type_id, client_id});
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
emp_id: hiddenData['emp_id'],
|
emp_id: hiddenData['emp_id'],
|
||||||
ticket_type_id: ticket_type_id,
|
ticket_type_id: ticket_type_id,
|
||||||
|
client_id: client_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?= base_url("/ticket/getPoliciesbyEmpID") ?>',
|
url: '<?= base_url("/ticket/getPoliciesbyEmpID") ?>',
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user