CHANGE_DELETE_FILE_JSON

This commit is contained in:
VENKATESHWARAN 2025-11-18 18:40:33 +05:30
parent 8099ef3373
commit 7b56067adc
2 changed files with 142 additions and 69 deletions

View File

@ -77,7 +77,7 @@ class RuleImportController extends AdminController
return $this->response->setJSON($result);
} catch (\Throwable $e) {
$this->myLogger->logme('critical', 'RuleImportController::upload ' . $e->getMessage());
$this->myLogger->logme('error', 'RuleImportController::upload ' . $e->getMessage());
return $this->response->setJSON(['status'=>false,'message'=>$e->getMessage()]);
}
}
@ -417,7 +417,7 @@ class RuleImportController extends AdminController
'message' => $result['message']
], 200);
} catch (\Throwable $ex) {
$this->myLogger->logme('critical', 'RuleImportController::upload exception: ' . $ex->getMessage(), [
$this->myLogger->logme('error', 'RuleImportController::upload exception: ' . $ex->getMessage(), [
'trace' => $ex->getTraceAsString()
]);
@ -485,11 +485,83 @@ class RuleImportController extends AdminController
}
public function deleteCommissionData($id)
{
$return = $this->updateCommissionRules($id);
if($return['status'] == true){
$this->commissionFilesModel->where('id', $id)->set(['is_active' => 0])->update();
return $this->respond(['status' => true, 'code' => 200, 'message' => "File removed successfully"], 200);
}else{
return $this->respond(['status' => false, 'code' => 400, 'message' => "Failed to remove file"], 200);
}
}
public function updateCommissionRules($id)
{
$this->commissionFilesModel->where('id', $id)
->set(['is_active' => 0])
->update();
return $this->respond(['status' => true, 'code' => 200, 'message' => "File removed successfully"], 200);
// 1. Fetch commission record
$commission_data = $this->commissionFilesModel
->where('is_active', 1)
->where('id', $id)
->first();
if (!$commission_data) {
$this->myLogger->logme("error","Commission record not found for ID: $id");
return ['status' => false, 'message' => 'Commission record not found'];
}
// 2. Convert commission_month → OCT2025
$month = date("M", strtotime($commission_data['commission_month']));
$year = date("Y", strtotime($commission_data['commission_month']));
$monthFolder = strtoupper($month . $year); // OCT2025
// 3. Build file name & path
$fileName = $commission_data['insurer_id'] . '_' . $commission_data['department'] . '.json';
$filePath = WRITEPATH . "uploads/commission/rules/" . $monthFolder . "/" . $fileName;
if (!file_exists($filePath)) {
$this->myLogger->logme("error","Rule file not found: $filePath");
return ['status' => false, 'message' => 'Rule file not found'];
}
// 4. Read file
$json = file_get_contents($filePath);
$rules = json_decode($json, true);
// dd($rules);
if (!is_array($rules)) {
$this->myLogger->logme("error","Invalid JSON structure in file: $filePath");
return ['status' => false, 'message' => 'Invalid rule file'];
}
// 5. Remove rule where file_id == commission_data id
$updatedRules = array_filter($rules, function ($rule) use ($id) {
return isset($rule['file_id']) && $rule['file_id'] != $id;
});
$updatedRules = array_values($updatedRules);
// 6. If empty → delete file
if (empty($updatedRules)) {
unlink($filePath);
$this->myLogger->logme("error","Rule removed. File deleted because no rules left: $filePath");
return [
'status' => true,
'message' => 'Rule deleted and file removed (no rules left)'
];
}
// 7. Write updated JSON
file_put_contents($filePath, json_encode($updatedRules, JSON_PRETTY_PRINT));
$this->myLogger->logme("error","Rule removed successfully and file updated: $filePath");
return [
'status' => true,
'message' => 'Rule removed and file updated successfully'
];
}
public function checkSameEntry()

View File

@ -185,7 +185,7 @@
<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">
<?php if($row['file_status'] == "failed") : ?>
<a href="<?= base_url('commission/downloadErrorFile?file_id=') . $row['id'] ?>" class="dropdown-item" target="_blank"><i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Download Error File</a>
<a href="<?= base_url('commission/downloadErrorFile?file_id=') . $row['id'] ?>" class="dropdown-item" target="_blank"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download Error File</a>
<?php endif; ?>
<a class="dropdown-item btnEdit" data-id="<?= $row['id']; ?>" onclick="deleteCommissionData(<?= $row['id']; ?>)">
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
@ -285,84 +285,85 @@
let isDublicateFound = false;
document.addEventListener("DOMContentLoaded", function() {
const table = document.getElementById("tickets-table");
// document.addEventListener("DOMContentLoaded", function() {
// const table = document.getElementById("tickets-table");
// Create custom dropdown
function createCustomDropdown(row) {
const originalDropdown = row.querySelector('.dropdown-menu');
if (!originalDropdown) return null;
// // Create custom dropdown
// function createCustomDropdown(row) {
// const originalDropdown = row.querySelector('.dropdown-menu');
// console.log('originalDropdown', originalDropdown)
// if (!originalDropdown) return null;
const customDropdown = document.createElement('div');
customDropdown.className = 'custom-dropdown-menu';
customDropdown.innerHTML = originalDropdown.innerHTML;
// const customDropdown = document.createElement('div');
// customDropdown.className = 'custom-dropdown-menu';
// customDropdown.innerHTML = originalDropdown.innerHTML;
// Remove inline onclick handlers and store them in data attributes
const originalItems = originalDropdown.querySelectorAll('.dropdown-item');
customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => {
const originalOnclick = originalItems[index].getAttribute('onclick');
item.removeAttribute('onclick'); // Remove the inline handler
item.setAttribute('data-onclick', originalOnclick); // Store in data attribute
});
// // Remove inline onclick handlers and store them in data attributes
// const originalItems = originalDropdown.querySelectorAll('.dropdown-item');
// customDropdown.querySelectorAll('.dropdown-item').forEach((item, index) => {
// const originalOnclick = originalItems[index].getAttribute('onclick');
// item.removeAttribute('onclick'); // Remove the inline handler
// item.setAttribute('data-onclick', originalOnclick); // Store in data attribute
// });
return customDropdown;
}
// return customDropdown;
// }
let activeDropdown = null;
// let activeDropdown = null;
// Add click event listener to rows
table.querySelectorAll("tbody tr").forEach(row => {
const customDropdown = createCustomDropdown(row);
if (!customDropdown) return;
// // Add click event listener to rows
// table.querySelectorAll("tbody tr").forEach(row => {
// const customDropdown = createCustomDropdown(row);
// if (!customDropdown) return;
document.body.appendChild(customDropdown);
// document.body.appendChild(customDropdown);
row.addEventListener("click", function(event) {
// Ignore clicks on the first column
if (event.target.closest('td:first-child')) return;
// row.addEventListener("click", function(event) {
// // Ignore clicks on the first column
// if (event.target.closest('td:first-child')) return;
if (activeDropdown) activeDropdown.style.display = 'none';
// if (activeDropdown) activeDropdown.style.display = 'none';
const rect = event.target.getBoundingClientRect();
customDropdown.style.display = 'block';
customDropdown.style.position = 'fixed';
customDropdown.style.left = `${rect.left}px`;
customDropdown.style.top = `${rect.bottom + 5}px`;
activeDropdown = customDropdown;
// const rect = event.target.getBoundingClientRect();
// customDropdown.style.display = 'block';
// customDropdown.style.position = 'fixed';
// customDropdown.style.left = `${rect.left}px`;
// customDropdown.style.top = `${rect.bottom + 5}px`;
// activeDropdown = customDropdown;
event.stopPropagation();
});
// Handle custom dropdown clicks
customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
item.addEventListener('click', function(e) {
e.preventDefault();
// event.stopPropagation();
// });
// // Handle custom dropdown clicks
// customDropdown.querySelectorAll('.dropdown-item').forEach(item => {
// item.addEventListener('click', function(e) {
// e.preventDefault();
// Execute the original onclick from data attribute
const onclickAttr = this.getAttribute('data-onclick');
if (onclickAttr) eval(onclickAttr);
// // Execute the original onclick from data attribute
// const onclickAttr = this.getAttribute('data-onclick');
// if (onclickAttr) eval(onclickAttr);
// Handle href navigation
const href = this.getAttribute('href');
if (href && href !== '#') window.location.href = href;
// // Handle href navigation
// const href = this.getAttribute('href');
// if (href && href !== '#') window.location.href = href;
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
// if (activeDropdown) {
// activeDropdown.style.display = 'none';
// activeDropdown = null;
// }
e.stopPropagation();
});
});
});
// e.stopPropagation();
// });
// });
// });
// Close dropdown on outside click
document.addEventListener("click", function() {
if (activeDropdown) {
activeDropdown.style.display = 'none';
activeDropdown = null;
}
});
});
// // Close dropdown on outside click
// document.addEventListener("click", function() {
// if (activeDropdown) {
// activeDropdown.style.display = 'none';
// activeDropdown = null;
// }
// });
// });
//datatable
$(document).ready(function() {