FEAT_BDS_BULK_UPLOAD
This commit is contained in:
parent
5d1eb6e0b7
commit
78ccef216f
@ -806,3 +806,11 @@ $routes->group('commission', function($routes) {
|
||||
$routes->get('checkRuleUsage',"RuleImportController::checkRuleUsage");
|
||||
});
|
||||
|
||||
//BDS BULK UPLOAD
|
||||
|
||||
$routes->group('bds_upload', function($routes) {
|
||||
$routes->match (['get','post'],'list',"PolicyTransactionController::policyBulkUpload");
|
||||
$routes->get('downloadBDSDumpFile',"PolicyTransactionController::downloadBDSDumpFile");
|
||||
$routes->get('getBdsDumpFileErrorData',"PolicyTransactionController::getBdsDumpFileErrorData");
|
||||
$routes->get('getBdsDumpExcelFileErrors/(:any)',"PolicyTransactionController::getBdsDumpExcelFileErrors/$1");
|
||||
});
|
||||
|
||||
@ -483,6 +483,8 @@ class EmployeeController extends AdminController
|
||||
$filePath = ROOTPATH . 'public/sample_excel/Sample_Member_Data.xlsx';
|
||||
}else if ($actionType == 'all') {
|
||||
$filePath = ROOTPATH . 'public/sample_excel/sample_multievent_file.xlsx';
|
||||
}else if ($actionType == 'bds_upload') {
|
||||
$filePath = ROOTPATH . 'public/sample_excel/sample_bds_bulk_upload_excel.xlsx';
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
|
||||
@ -179,6 +179,14 @@ class JobWorker extends AdminController
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\MediAssistApiController',
|
||||
],
|
||||
'bdsDumpExcelFileFormatValidation' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\PolicyTransactionController',
|
||||
],
|
||||
'insertBulkBdsData' => [
|
||||
'type' => 'CC', // Handler Category
|
||||
'handler' => 'App\Controllers\PolicyTransactionController',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
||||
@ -1980,6 +1980,7 @@ class MasterController extends AdminController
|
||||
'files' => WRITEPATH . 'uploads/commission/files',
|
||||
'rules' => WRITEPATH . 'uploads/commission/rules',
|
||||
'claim_sample_forms' => ROOTPATH . 'public/claim_sample_forms/',
|
||||
'bds_dump_excel' => WRITEPATH . 'uploads/bds_dump_excel/',
|
||||
];
|
||||
|
||||
foreach ($folders as $folderName => $folderPath) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -2948,3 +2948,392 @@ if (!function_exists('validatet_family_floter_rata_premium')) {
|
||||
return $family;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('validate_excel_value')) {
|
||||
function validate_excel_value($value, $data_type, $format = null, $allowed_values = null)
|
||||
{
|
||||
switch ($data_type) {
|
||||
|
||||
case 'date':
|
||||
return validate_date_value($value, $format);
|
||||
|
||||
case 'mobile':
|
||||
return validate_mobile_value($value);
|
||||
|
||||
case 'email':
|
||||
return validate_email_value($value);
|
||||
|
||||
case 'vehicle':
|
||||
return validate_indian_vehicle_number($value);
|
||||
|
||||
default:
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_date_value')) {
|
||||
function validate_date_value($value, $format)
|
||||
{
|
||||
if(empty($value)) {
|
||||
return ['status' => true, 'error' => null]; // allow empty
|
||||
}
|
||||
|
||||
$d = DateTime::createFromFormat($format, $value);
|
||||
|
||||
if ($d && $d->format($format) === $value) {
|
||||
return ['status' => true, 'error' => null];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Invalid date format. Expected format: {$format}"
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_mobile_value')) {
|
||||
function validate_mobile_value($value)
|
||||
{
|
||||
if (preg_match('/^[0-9]{10}$/', $value)) {
|
||||
return ['status' => true, 'error' => null];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Invalid mobile number. Expected 10 digits."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_email_value')) {
|
||||
function validate_email_value($value)
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
return ['status' => true, 'error' => null];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Invalid email address."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_indian_vehicle_number')) {
|
||||
function validate_indian_vehicle_number($number)
|
||||
{
|
||||
$number = strtoupper(trim($number));
|
||||
|
||||
// Normal Format:
|
||||
// 2 letters (state) + 2 digits (district) + 1 or 2 letters (series) + 4 digits
|
||||
$normalPattern = '/^[A-Z]{2}[0-9]{2}[A-Z]{1,2}[0-9]{4}$/';
|
||||
|
||||
// BH Series: 22BH1234AA
|
||||
$bhPattern = '/^[0-9]{2}BH[0-9]{4}[A-Z]{2}$/';
|
||||
|
||||
if (preg_match($normalPattern, $number)) {
|
||||
return ['status' => true, 'error' => null];
|
||||
}
|
||||
|
||||
if (preg_match($bhPattern, $number)) {
|
||||
return ['status' => true, 'error' => null];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Invalid Vehicle Number"
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_user_exist')) {
|
||||
function check_user_exist($row, $col_key, $user_data)
|
||||
{
|
||||
// Get the uploaded value from the column
|
||||
$input_value = trim($row[$col_key]);
|
||||
|
||||
// Loop DB user list
|
||||
foreach ($user_data as $user) {
|
||||
|
||||
// Check if DB has 'first_name' key and matches input
|
||||
if (isset($user['first_name']) && strtolower(trim($user['first_name'])) === strtolower($input_value)) {
|
||||
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'user' => $user,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If no user matched
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "User '{$input_value}' not found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_agent_exist')) {
|
||||
function check_agent_exist($row, $agent_data)
|
||||
{
|
||||
// Get agent code from the uploaded row
|
||||
$agent_code = trim($row[15]); // or use index if needed
|
||||
|
||||
// Loop agent data from DB
|
||||
foreach ($agent_data as $agent) {
|
||||
// Assuming DB keys: agent_code
|
||||
if (isset($agent['agent_code']) && $agent['agent_code'] == $agent_code) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'agent' => $agent,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If not matched
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Agent code '{$agent_code}' not found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_rto_data')) {
|
||||
function check_rto_data($row, $rto_master)
|
||||
{
|
||||
// Vehicle number from uploaded row
|
||||
$vehicle_no = strtoupper(trim($row[2])); // Example: TN10AB1234
|
||||
|
||||
// Must be at least 4 characters to extract RTO
|
||||
if (strlen($vehicle_no) < 4) {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Invalid vehicle number format: '{$vehicle_no}'"
|
||||
];
|
||||
}
|
||||
|
||||
// Extract State (first 2 letters) and RTO Code (next 2 digits)
|
||||
$state_code = substr($vehicle_no, 0, 2); // TN
|
||||
$rto_code = substr($vehicle_no, 2, 2); // 10
|
||||
|
||||
// Validate they are correct format
|
||||
if (!ctype_alpha($state_code) || !ctype_digit($rto_code)) {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Vehicle number '{$vehicle_no}' has invalid state or RTO code."
|
||||
];
|
||||
}
|
||||
|
||||
// Loop RTO master data
|
||||
foreach ($rto_master as $rto) {
|
||||
|
||||
// Expected DB fields: rto_state, rto_code
|
||||
if (
|
||||
isset($rto['rto_state']) &&
|
||||
isset($rto['rto_code']) &&
|
||||
strtoupper($rto['rto_state']) === $state_code &&
|
||||
(string)$rto['rto_code'] === $rto_code
|
||||
) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'rto_data' => $rto
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Not found in RTO master
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "RTO '{$state_code} {$rto_code}' not found in RTO master."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_vehicle_type')) {
|
||||
function check_vehicle_type($row, $vehicle_type)
|
||||
{
|
||||
// Vehicle type from uploaded Excel row
|
||||
$input_type = strtolower(trim($row[3])); // Example: CAR
|
||||
|
||||
// Loop vehicle type master
|
||||
foreach ($vehicle_type as $vt) {
|
||||
|
||||
if (isset($vt['vehicle_type']) && strtolower($vt['vehicle_type']) == $input_type) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'vehicle_type' => $vt,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Not found in master
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Vehicle type '{$input_type}' not found in master."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_policy_no')) {
|
||||
function check_policy_no($row, $pt_data)
|
||||
{
|
||||
// Get policy number from Excel row
|
||||
$policy_no = strtolower(trim($row[4]));
|
||||
|
||||
// Empty policy number
|
||||
if ($policy_no === '') {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Policy number is empty."
|
||||
];
|
||||
}
|
||||
|
||||
// Loop all policy transactions (pt_data)
|
||||
foreach ($pt_data as $pt) {
|
||||
|
||||
// Check policy_no exists in DB list
|
||||
if (isset($pt['policy_no']) && strtolower($pt['policy_no']) == $policy_no) {
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Duplicate policy number '{$policy_no}' found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// If no match found → not duplicate
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_insurer_exist')) {
|
||||
function check_insurer_exist($row, $insurer_master)
|
||||
{
|
||||
// Get insurer short name from Excel row (col 7)
|
||||
$short_name = strtolower(trim($row[7]));
|
||||
|
||||
foreach ($insurer_master as $insurer) {
|
||||
if (
|
||||
isset($insurer['short_name']) &&
|
||||
strtolower($insurer['short_name']) === $short_name
|
||||
) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'insurer' => $insurer // return entire insurer row for next validation
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Insurer '{$short_name}' not found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_insurer_branch_exist')) {
|
||||
function check_insurer_branch_exist($row, $insurer_branch_master, $insurer)
|
||||
{
|
||||
// Get branch code from Excel row (col 8)
|
||||
$branch_code = strtolower(trim($row[8]));
|
||||
|
||||
// Loop all branches
|
||||
foreach ($insurer_branch_master as $branch) {
|
||||
|
||||
if (
|
||||
isset($insurer['id']) && $branch['insurer_id'] == $insurer['id'] &&
|
||||
strtolower($branch['branch_code']) == $branch_code
|
||||
) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'branch' => $branch
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Branch code '{$branch_code}' not found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_nhance_branch')) {
|
||||
function check_nhance_branch($row, $nhance_branch_master)
|
||||
{
|
||||
// Get branch name from Excel row (col 8)
|
||||
$branch_name = strtolower(trim($row[1]));
|
||||
|
||||
// Loop all branches
|
||||
foreach ($nhance_branch_master as $branch) {
|
||||
|
||||
if (
|
||||
isset($branch['branch_name']) &&
|
||||
strtolower($branch['branch_name']) == $branch_name
|
||||
) {
|
||||
return [
|
||||
'status' => true,
|
||||
'error' => null,
|
||||
'branch' => $branch
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'error' => "Branch '{$branch_name}' not found in database."
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('calculate_gst_amount')) {
|
||||
function calculate_gst_amount($row) {
|
||||
|
||||
// Extract values
|
||||
$base_premium = (float)trim($row[16]);
|
||||
$non_commission_premium_amount = (float)trim($row[17]);
|
||||
$tp_premium = (float)trim($row[18]);
|
||||
$igst = (float)trim($row[19]);
|
||||
$cgst = (float)trim($row[20]);
|
||||
$sgst = (float)trim($row[21]);
|
||||
|
||||
// Total GST percentage
|
||||
$gst_percentage = $igst + $cgst + $sgst;
|
||||
|
||||
// Step 1: Choose taxable amount
|
||||
if ($non_commission_premium_amount > 0) {
|
||||
// GST on non-commission premium
|
||||
$taxable_amount = $non_commission_premium_amount;
|
||||
} else {
|
||||
// GST on base premium + TP premium
|
||||
$taxable_amount = $base_premium + $tp_premium;
|
||||
}
|
||||
|
||||
// Step 2: GST Amount calculation
|
||||
$gst_amount = ($taxable_amount * $gst_percentage) / 100;
|
||||
|
||||
return round($gst_amount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
55
app/Models/BDSDumpModel.php
Normal file
55
app/Models/BDSDumpModel.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class BDSDumpModel extends Model
|
||||
{
|
||||
protected $table = 'bds_dump_files';
|
||||
protected $primaryKey = 'id';
|
||||
protected $allowedFields = [
|
||||
"id",
|
||||
"file_name",
|
||||
"status",
|
||||
"reason",
|
||||
"created_by",
|
||||
"created_at",
|
||||
"updated_by",
|
||||
"updated_at",
|
||||
"is_active",
|
||||
];
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@ -69,6 +69,7 @@ class PTCOShareDetailsModel extends Model
|
||||
'cotp_amt',
|
||||
'cotep_amt',
|
||||
'pt_policy_issue_date',
|
||||
'file_id',
|
||||
];
|
||||
|
||||
public function getNonReconcileredPolicyTransactions(string $insurer_id,string $insurer_branch_id)
|
||||
|
||||
@ -81,6 +81,9 @@
|
||||
'install_due_date',
|
||||
'policy_with_corr',
|
||||
'is_cd_reduce_from_bds',
|
||||
'agent_id',
|
||||
'agent_code',
|
||||
'file_id',
|
||||
];
|
||||
|
||||
|
||||
|
||||
394
app/Views/bds_dump_file_list.php
Normal file
394
app/Views/bds_dump_file_list.php
Normal file
@ -0,0 +1,394 @@
|
||||
<style>
|
||||
|
||||
.reload:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.table th,
|
||||
.table td {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
table.dataTable tbody td {
|
||||
padding: 4px 4px !important;
|
||||
}
|
||||
|
||||
.addbtnStyle{
|
||||
margin-left: 20px !important;
|
||||
}
|
||||
|
||||
.dataTables_filter {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.dataTables_length label {height: 21px !important;}
|
||||
</style>
|
||||
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<table data-custom-table-css="table" class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0" id="tickets-table">
|
||||
<thead class="bg-light">
|
||||
<tr>
|
||||
<th class="font-weight-medium">S.No </th>
|
||||
<th class="font-weight-medium">File name</th>
|
||||
<th class="font-weight-medium">User/Time</th>
|
||||
<th class="font-weight-medium">Status</th>
|
||||
<th class="font-weight-medium">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="font-12">
|
||||
<?php
|
||||
if (isset($bds_dump_file_data)) {
|
||||
foreach ($bds_dump_file_data as $key => $file) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td class="text-center"><b><?php echo ($key + 1) ?></b></td>
|
||||
<td style="overflow: hidden;" class="reload truncate" data-toggle="tooltip" data-placement="top" title="<?php echo $file['file_name'] ?>">
|
||||
<?php echo $file['file_name'] ?>
|
||||
</td>
|
||||
<td><?php echo change_date_format($file['created_at'], 'Y-m-d H:i:s', 'd M Y h:i A') . ' by <strong>' . $file['user_name'] . '</strong>' ?> </td>
|
||||
<td>
|
||||
<?php if ($file['status'] == "failed") { ?>
|
||||
<span style="color : #BD0707 ;"> <?= $file['status'] ?> </span>
|
||||
<span class='col-xl-3 col-lg-4 col-sm-6'>
|
||||
<!-- <a href="<?= base_url('util/bds_dump_excel_error/') . $file['file_id'] ?>" target="_blank" class='fe-alert-circle' data-err="<?= $file['file_id'] ?>"></a> -->
|
||||
<a href="#" class='fe-alert-circle' onclick="fetchFileError(<?= $file['file_id'] ?>)"></a>
|
||||
</span>
|
||||
<?php } else if ($file['status'] == "inprogress") { ?>
|
||||
<a data-id="<?= $file['status'] ?>" class="reload" href="#"
|
||||
style="color : #938e04ff ;">
|
||||
<?= $file['status'] ?>
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<span style="color : #34A853 ;"> <?= $file['status'] ?> </span>
|
||||
<?php } ?>
|
||||
</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 target="_blank" class="dropdown-item" href="<?= base_url("bds_upload/downloadBDSDumpFile/") . $file['file_id']; ?>"><i class="mdi mdi-download mr-2 text-muted font-18 vertical-middle"></i>Download</a>
|
||||
<!-- <a data-id="<?php echo $file['file_id'] ?>" data-toggle="modal" data-target="#full-width-modal-emp-list" class="dropdown-item view_emp_list" href="#"><i class="mdi mdi-eye mr-2 text-muted font-18 vertical-middle"></i>View</a> -->
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php }
|
||||
} ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- end col -->
|
||||
|
||||
<!-- Center modal content -->
|
||||
<div class="modal fade" id="bds-dump-file-err-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="myCenterModalLabel">File Rejected Reason</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div id="modal_body" class="modal-body">
|
||||
<div class="spinner-border text-primary" role="status" style="position: relative; left: 200px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
<!-- Center modal content for upload file-->
|
||||
<div class="modal fade" id="bds-file-upload-modal" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="myCenterModalLabel">BDS Bulk Upload</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="parsley-examples" id="bds-upload-form" enctype="multipart/form-data">
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
<div class="form-group float-right-end offset-8 col-4">
|
||||
<span><a href="<?= base_url("util/download-excel/bds_upload"); ?>" id="download_sample_file" style="font-size: small; color:red !important;">Download sample file</a></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row" id="file_upload">
|
||||
<div class="form-group col-md-9">
|
||||
<label>Upload file</label>
|
||||
<!-- [ <a href="#" id="excel_download" data-toggle="tooltip" data-placement="top" title="Download Sample Excel">Sample Excel</a> ] -->
|
||||
<input type="file" name="bds_dump_list" id="bds_dump_list" accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet" required>
|
||||
</div>
|
||||
<div class="form-group col-md-3" style="margin-top: 40px;">
|
||||
<button id="bds_form_submit_button" type="submit" class="btn btn-primary waves-effect waves-light justify-content-end">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
|
||||
<script>
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
// AJAX Form Submit Function
|
||||
$('#bds-upload-form').on('submit', function(e) {
|
||||
e.preventDefault(); // Prevent default form submission
|
||||
|
||||
// Get form data
|
||||
var formData = new FormData(this);
|
||||
var fileInput = $('#bds_dump_list')[0];
|
||||
|
||||
// Validate file type
|
||||
var allowedTypes = [
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.oasis.opendocument.spreadsheet'
|
||||
];
|
||||
|
||||
var selectedFile = fileInput.files[0];
|
||||
if (!allowedTypes.includes(selectedFile.type)) {
|
||||
alert('Please upload a valid Excel file (.xlsx, .xls, .ods)');
|
||||
return false;
|
||||
}
|
||||
|
||||
//form submit url;
|
||||
let url = `<?php echo base_url('bds_upload/list'); ?>`;
|
||||
|
||||
// Show loading state
|
||||
var submitButton = $('#bds_form_submit_button');
|
||||
var originalText = submitButton.text();
|
||||
submitButton.prop('disabled', true).text('Uploading...');
|
||||
|
||||
|
||||
// AJAX request
|
||||
$.ajax({
|
||||
url: url, // Your route URL
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false, // CRITICAL: Don't process the data
|
||||
contentType: false, // CRITICAL: Don't set content-type header
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
|
||||
// Handle successful response
|
||||
console.log('Upload successful:', response);
|
||||
|
||||
if (response.status == true) {
|
||||
toastr.success(response.message, "SUCCESS");
|
||||
} else {
|
||||
toastr.error(response.message, "ERROR");
|
||||
}
|
||||
|
||||
// Reset form
|
||||
$('#bds-upload-form')[0].reset();
|
||||
$('.close').click();
|
||||
window.location.reload();
|
||||
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response
|
||||
console.error('Upload failed:', error);
|
||||
console.error('Upload failed:', error);
|
||||
},
|
||||
complete: function() {
|
||||
// Reset button state
|
||||
submitButton.prop('disabled', false).text(originalText);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// File input change event for additional validation
|
||||
$('#bds_dump_list').on('change', function() {
|
||||
var fileInput = this;
|
||||
var file = fileInput.files[0];
|
||||
|
||||
if (file) {
|
||||
// Check file size (optional - set max size as needed, e.g., 10MB)
|
||||
var maxSize = 10 * 1024 * 1024; // 10MB in bytes
|
||||
if (file.size > maxSize) {
|
||||
toastr.warning('File size should not exceed 10MB');
|
||||
$(this).val(''); // Clear the input
|
||||
return false;
|
||||
}
|
||||
|
||||
// Display selected file name
|
||||
var fileName = file.name;
|
||||
if ($('#selected-file').length === 0) {
|
||||
$('<div id="selected-file" class="mt-2 text-muted"><small>Selected file: <span id="file-name"></span></small></div>')
|
||||
.insertAfter('#bds_dump_list');
|
||||
}
|
||||
$('#file-name').text(fileName);
|
||||
}
|
||||
});
|
||||
|
||||
$('body').on('click', '.reload', function() {
|
||||
status = this.getAttribute('data-id')
|
||||
console.log(status);
|
||||
if (status == 'inprogress') {
|
||||
window.location.reload(true);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
// Datatable document ready
|
||||
$(document).ready(function() {
|
||||
|
||||
var ticketsTable = $('#tickets-table');
|
||||
|
||||
if (ticketsTable.length) {
|
||||
ticketsTable.DataTable({
|
||||
scrollX: true,
|
||||
// dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
// "<'row'<'col-sm-12'tr>>" +
|
||||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||||
"<'row'<'col-sm-12'tr>>" +
|
||||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||||
buttons: [
|
||||
{
|
||||
text: 'Add',
|
||||
className: 'buttons-html5 addbtnStyle',
|
||||
action: function (e, dt, node, config) {
|
||||
openDumpUploadModal();
|
||||
}
|
||||
}
|
||||
],
|
||||
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: 15, // Set default number of rows per page (optional)
|
||||
});
|
||||
} else {
|
||||
console.error("Table not found.");
|
||||
}
|
||||
});
|
||||
|
||||
function fetchFileError(file_id) {
|
||||
|
||||
var url = '<?php echo base_url('bds_upload/getBdsDumpFileErrorData/'); ?>';
|
||||
let requestData = { file_id: file_id };
|
||||
|
||||
var myModal = new bootstrap.Modal(document.getElementById('bds-dump-file-err-modal'));
|
||||
myModal.show();
|
||||
|
||||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||||
console.log('Data fetched successfully:', response);
|
||||
|
||||
$('#modal_body').empty();
|
||||
if (response.status === true) {
|
||||
|
||||
var file_error_data = (JSON.parse(response.data));
|
||||
var file_error_html = "";
|
||||
|
||||
for (var key in file_error_data['error_summary']) {
|
||||
var err_id = parseInt(key);
|
||||
var err_count = file_error_data['error_summary'][key];
|
||||
switch (err_id) {
|
||||
case 0:
|
||||
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
|
||||
break;
|
||||
case 1:
|
||||
file_error_html += "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 2:
|
||||
file_error_html += "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 3:
|
||||
file_error_html += "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 4:
|
||||
file_error_html += "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 5:
|
||||
file_error_html += "<strong>" + (file_error_data['error_data'] || 'Error data not available') + "</strong>";
|
||||
break;
|
||||
case 6:
|
||||
file_error_html += "<strong>" + (file_error_data['error_data'] || 'Error data not available') + "</strong>";
|
||||
break;
|
||||
case 7:
|
||||
file_error_html += "<strong>Bds already exist</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 8:
|
||||
file_error_html += "<strong>Policy not found</strong> <span class='badge badge-warning float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 9:
|
||||
file_error_html += "<strong>Employee not found</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
case 10:
|
||||
file_error_html += "<strong>ACM not found</strong> <span class='badge badge-danger float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
default:
|
||||
file_error_html += "<strong>Unknown error type</strong> <span class='badge badge-secondary float-right'>" +
|
||||
err_count + "</span><br>";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (err_id != 5 && err_id != 6 && err_id != 0) {
|
||||
file_error_html += (file_error_html != "" ?
|
||||
"<a href ='<?php echo base_url('bds_upload/getBdsDumpExcelFileErrors/') ?>" + file_id +
|
||||
"' target=_blank>click here to more details...</a>" : "");
|
||||
}
|
||||
|
||||
// console.log(file_error_html);
|
||||
$('#modal_body').append(file_error_html);
|
||||
|
||||
} else {
|
||||
console.log('Response status was false');
|
||||
$('#modal_body').append('<div class="alert alert-warning">No error data available.</div>');
|
||||
}
|
||||
|
||||
}, function(xhr, status, error) {
|
||||
console.error('Error fetching data:', error);
|
||||
console.error('Status:', status);
|
||||
console.error('Response:', xhr.responseText);
|
||||
|
||||
// Show error message to user
|
||||
$('#modal_body').empty().append(
|
||||
'<div class="alert alert-danger">Failed to fetch error data. Please try again.</div>'
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$('.close').click(function(){
|
||||
$('#modal_body').empty()
|
||||
let html = `<div class="spinner-border text-primary" role="status" style="position: relative; left: 200px;"></div>`
|
||||
$('#modal_body').append(html);
|
||||
});
|
||||
|
||||
function openDumpUploadModal() {
|
||||
var myModal = new bootstrap.Modal(document.getElementById('bds-file-upload-modal'));
|
||||
myModal.show();
|
||||
}
|
||||
|
||||
</script>
|
||||
BIN
public/sample_excel/sample_bds_bulk_upload_excel.xlsx
Normal file
BIN
public/sample_excel/sample_bds_bulk_upload_excel.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user