FEAT_COND_COMMISSION_FILE_UPLOAD_JSON_STRUCTURE_CHANGE
This commit is contained in:
parent
4121fee9aa
commit
e6d9d073bd
@ -787,5 +787,6 @@ $routes->group('commission', function($routes) {
|
|||||||
$routes->get('downloadErrorFile',"RuleImportController::downloadErrorFile");
|
$routes->get('downloadErrorFile',"RuleImportController::downloadErrorFile");
|
||||||
$routes->get("deleteCommissionData/(:any)", "RuleImportController::deleteCommissionData/$1");
|
$routes->get("deleteCommissionData/(:any)", "RuleImportController::deleteCommissionData/$1");
|
||||||
$routes->get('checkSameEntry',"RuleImportController::checkSameEntry");
|
$routes->get('checkSameEntry',"RuleImportController::checkSameEntry");
|
||||||
|
$routes->get('checkRuleUsage',"RuleImportController::checkRuleUsage");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,9 @@ namespace App\Controllers;
|
|||||||
use CodeIgniter\API\ResponseTrait;
|
use CodeIgniter\API\ResponseTrait;
|
||||||
use App\Models\CommissionFilesModel;
|
use App\Models\CommissionFilesModel;
|
||||||
use App\Models\InsurerModel;
|
use App\Models\InsurerModel;
|
||||||
|
use App\Models\PartnerPolicyModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RuleImportController extends AdminController
|
class RuleImportController extends AdminController
|
||||||
{
|
{
|
||||||
@ -13,6 +16,7 @@ class RuleImportController extends AdminController
|
|||||||
protected $commissionFilesModel;
|
protected $commissionFilesModel;
|
||||||
protected $departments;
|
protected $departments;
|
||||||
protected $insurerModel;
|
protected $insurerModel;
|
||||||
|
protected $partnerPolicyModel;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -20,7 +24,7 @@ class RuleImportController extends AdminController
|
|||||||
|
|
||||||
$this->myLogger = \Config\Services::mylogger();
|
$this->myLogger = \Config\Services::mylogger();
|
||||||
$this->ruleImportService = \Config\Services::ruleImportService();
|
$this->ruleImportService = \Config\Services::ruleImportService();
|
||||||
|
$this->partnerPolicyModel = new partnerPolicyModel();
|
||||||
$this->commissionFilesModel = new CommissionFilesModel();
|
$this->commissionFilesModel = new CommissionFilesModel();
|
||||||
$this->insurerModel = new InsurerModel();
|
$this->insurerModel = new InsurerModel();
|
||||||
$this->departments = [
|
$this->departments = [
|
||||||
@ -194,6 +198,8 @@ class RuleImportController extends AdminController
|
|||||||
'insurer_id' => (int)$insurerId,
|
'insurer_id' => (int)$insurerId,
|
||||||
'department' => $department,
|
'department' => $department,
|
||||||
'commission_month' => $commissionMonth,
|
'commission_month' => $commissionMonth,
|
||||||
|
'created_by' => (int)$createdBy,
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->myLogger->logme('info', 'RuleImportController::upload - Calling ruleImportService->processUpload', ['payload' => $payload]);
|
$this->myLogger->logme('info', 'RuleImportController::upload - Calling ruleImportService->processUpload', ['payload' => $payload]);
|
||||||
@ -262,10 +268,22 @@ class RuleImportController extends AdminController
|
|||||||
// handle existing JSON file based on $override (bool)
|
// handle existing JSON file based on $override (bool)
|
||||||
if (file_exists($jsonPath)) {
|
if (file_exists($jsonPath)) {
|
||||||
if ($overwrite) {
|
if ($overwrite) {
|
||||||
// delete existing file before writing (deterministic overwrite)
|
// rename existing file before overwrite
|
||||||
if (!@unlink($jsonPath)) {
|
if (file_exists($jsonPath)) {
|
||||||
$this->myLogger->logme('warning', 'RuleImportController::upload - Failed to delete existing JSON before overwrite', ['json_path' => $jsonPath]);
|
|
||||||
// proceed to overwrite anyway by writing to the same path
|
$backupPath = $jsonPath . '.' . date('YmdHis') . '.bak';
|
||||||
|
|
||||||
|
if (!@rename($jsonPath, $backupPath)) {
|
||||||
|
$this->myLogger->logme(
|
||||||
|
'warning',
|
||||||
|
'RuleImportController::upload - Failed to rename existing JSON before overwrite',
|
||||||
|
[
|
||||||
|
'json_path' => $jsonPath,
|
||||||
|
'backup_path' => $backupPath
|
||||||
|
]
|
||||||
|
);
|
||||||
|
// continue anyway; writing to same path will overwrite
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$finalJson = $jsonData;
|
$finalJson = $jsonData;
|
||||||
} else {
|
} else {
|
||||||
@ -641,5 +659,14 @@ class RuleImportController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkRuleUsage()
|
||||||
|
{
|
||||||
|
$rule_id = $this->request->getGet('rule_id');
|
||||||
|
|
||||||
|
$count = $this->partnerPolicyModel->where('commission_applied_rule', $ruleName)
|
||||||
|
->countAllResults();
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'count' => $count, 'message' => ""], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -916,7 +916,11 @@ class RuleImportService
|
|||||||
'is_deleted' => false,
|
'is_deleted' => false,
|
||||||
'file_id' => $this->uploadedCommissionFileID,
|
'file_id' => $this->uploadedCommissionFileID,
|
||||||
'conditions' => $conditions,
|
'conditions' => $conditions,
|
||||||
'calculation' => $calculation
|
'calculation' => $calculation,
|
||||||
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
|
'updated_at' => date('Y-m-d H:i:s'),
|
||||||
|
'created_by' => $this->incomingData['created_by'],
|
||||||
|
'updated_by' => $this->incomingData['created_by'],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user