ria/app/Views/editconfig.php
2025-03-25 12:33:44 +05:30

804 lines
37 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
function al() {
alert($('#ConfigId').val());
}
</script>
<?php
$ConfigId = '';
$ConfigName = '';
$Comments = '';
$ConfigValue = '';
if (!empty($master)) {
foreach ($master as $con) {
$ConfigId = $con->Config_ID;
$ConfigName = $con->ConfigName;
$Comments = $con->Comments;
}
}
?>
<style>
.modal-content {
width: 800px ! important;
}
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title">Edit Config <?= ' - ' . $ConfigName; ?> Details</h4>
<a class="btn btn-secondary" href="<?php echo base_url(); ?>configlisting"><span
class="bold">Back</span></a>
</div>
</div>
</div>
<?php
helper('form');
$error = session()->getFlashdata('error');
if ($error) {
?>
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo session()->getFlashdata('error'); ?>
</div>
<?php } ?>
<?php
$success = session()->getFlashdata('success');
if ($success) {
?>
<div class="alert alert-info alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<?php echo session()->getFlashdata('success'); ?>
</div>
<?php } ?>
<!-- end page title -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'editConfig');
echo form_open(base_url() . 'configurationctrl/updateconfig', $attributes); ?>
<div class="form-row" style="margin-top:10px">
<div class="col-md-2">
<label class="col-form-label" for="ConfigId">Configuration ID</label>
<font color="Red">*</font>
<?php
$data = array('name' => 'ConfigId', 'value' => set_value('ConfigId', $ConfigId), 'id' => 'ConfigId', 'class' => 'form-control', 'required' => 'true', 'readonly' => 'true');
echo form_input($data);
?>
</div>
<div class="col-md-2">
<label class="col-form-label" for="ConfigName">Configuration Name</label>
<font color="Red">*</font>
<?php
$data = array('name' => 'ConfigName', 'value' => set_value('ConfigName', $ConfigName), 'id' => 'ConfigName', 'class' => 'form-control', 'required' => 'true', 'maxlength' => '30');
echo form_input($data);
?>
</div>
<div class="col-md-2">
<label class="col-form-label" for="Remarks"> Comments </label>
<font color="Red">*</font>
<?php
$data = array('name' => 'Remarks', 'value' => set_value('Remarks', $Comments), 'id' => 'Remarks', 'class' => 'form-control', 'required' => 'true', 'maxlength' => '20');
echo form_input($data);
?>
</div>
<div class="col-md-3 mt-3">
<a data-toggle="modal" href="#AddConfiguration" style="margin-right: 10px;"
class="btn btn-success"><i class="fa fa-plus"></i>&nbsp;&nbsp;
Configuration Value</a>
</div>
<?php echo form_close(); ?>
<div class="col-md-3 mt-4" align="right">
<form id="archiveFormId" action="<?php echo base_url("/configurationctrl/editconfig")?>" method="post">
<input class="form-check-input" type="checkbox" id="showArchiveId"
name="showArchive" value="1" <?php echo $showArchive ? "checked" : " " ?>
style="width: 18px; height: 18px;">
<input type="hidden" name="ConfigID" value="<?=$ConfigId?>" >
<label class="form-check-label" for="showArchiveId"
style="font-size: 1rem; margin-left: 8px;">
Show Archive
</label>
</form>
</div>
</div>
<div>
</div>
<div class="form-row" style="margin-top:10px">
<div class="col-md-12">
<table id="configtable"
class="table table-bordered table-hover responsive-utilities jambo_table"
style="background-color:#fff;font-size:12px;">
<thead>
<tr>
<th>S.NO</th>
<th>Configuration Value</th>
<th>Action</th>
</tr>
</thead>
<tbody id="tempAppend">
<?php if (!empty($master && $child)) {
$index = 0;
foreach ($child as $con) {
$index++;
?>
<input type="hidden" name="DbKey<?php echo $index ?>"
id="DbKey<?php echo $index ?>" value="<?php echo $con->Key ?>">
<input type="hidden" name="configVal<?php echo $index ?>"
id="configVal<?php echo $index ?>"
value="<?php echo $con->ConfigValue ?>">
<tr>
<td>
<?php echo $index; ?></td>
<?php if($con->Config_ID === 'C023'){ ?>
<td>
<a
class="config-category"
data-value="<?php echo $con->ConfigValue;?>"
data-key="<?php echo $con->Key; ?>"
style="cursor: pointer;">
<?php echo $con->ConfigValue ?>
</a>
</td>
<?php }else{ ?>
<td><?php echo $con->ConfigValue; ?></td>
<?php } ?>
<td>
<?php if ($con->isActive == 0) { ?>
<a onclick="confirmReActivateConfig(event)" href="<?php echo base_url() . 'activeInactiveConfigValue
?key=' . $con->Key .
'&value=1'.
'&ConfigID=' . $con->Config_ID
; ?>"
data-toggle="tooltip" title="<?php echo $con->Config_ID ?> - Click here to Re
activate Config Details"><i class="fas fa-key"></i>
</a>
<?php } else { ?>
<!-- edit section -->
<a
class="editConfigurationBtn"
data-id="<?php echo $index; ?>"
data-key="<?php echo $con->Key; ?>"
data-code="<?php echo $con->Config_ID; ?>"
data-userid="<?php echo $index; ?>"
data-configvalue="<?php echo $con->ConfigValue; ?>"
href="#EditConfiguration"><i class="fas fa-edit" data-toggle="tooltip"
title="Click here to Edit Config Value"></i>
</a>
&nbsp;&nbsp; &nbsp;&nbsp;
<!-- delete section -->
<a onclick="confirmDeleteConfig(event)"
data-key="<?php echo $con->Key; ?>"
data-code="<?php echo $con->Config_ID; ?>"
href="<?php echo base_url() . 'activeInactiveConfigValue
?key=' . $con->Key .
'&value=0' .
'&ConfigID=' . $con->Config_ID
;
?>"
data-toggle="tooltip"
title="<?php echo $con->ConfigValue ?> - Click here to Delete Config Details">
<i class="fas fa-trash" data-toggle="tooltip" title="Click here to Delete the Config Value"></i>
</a>
<?php } ?>
</td>
</tr>
<input type="hidden" name="txtRowCount" id="txtRowCount"
value="<?php echo $index ?>" />
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="form-row text-right" style="margin-top:10px; text-align:right">
<div class="col-md-12 text-right">
<a href="<?php echo base_url() ?>configlisting" class="btn btn-secondary">Cancel</a>
<input type="button" id="updateConfigBtnId" class="btn btn-success" value="Update" />
</div>
</div>
</div>
</div>
</div>
</div>
<!-- modal_sec_starts -->
<!-- Modal For Add Configuration -->
<div class="modal fade" id="AddConfiguration" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Add Configuration</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="row">
<div class="col-md-4">
Configuration Value :
</div>
<div class="col-md-5">
<input class="form-control" name="AddConfigValue" id="AddConfigValue"
type="text">
</div>
</div>
</div>
</form>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<a class="btn btn-success" style="background-color: grey;border: none;margin-right:10px"
data-dismiss="modal">Cancel</a>
<button type="button" class="btn btn-success font " id="tempClickAdd"> Add </button>
</div>
</div>
</div>
</div>
<!-- Modal For Edit Configuration -->
<div class="modal fade" id="EditConfiguration" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Edit Configuration</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="row" >
<div class="col-md-3 col-md-offset-2">
Key :
</div>
<div class="col-md-5">
<?php
$data = array('name' => 'key', 'value' => set_value('key'), 'id' => 'key', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 col-md-offset-2">
Config ID :
</div>
<div class="col-md-5">
<?php
$data = array('name' => 'Config_ID', 'value' => set_value('Config_ID'), 'id' => 'Config_ID', 'class' => 'form-control', 'readonly' => 'true');
echo form_input($data);
?>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-3 col-md-offset-2">
Configuration Value :
</div>
<div class="col-md-5">
<?php
$data = array('name' => 'configValue', 'value' => set_value('configValue'), 'id' => 'configValue', 'class' => 'form-control');
echo form_input($data);
?>
</div>
</div>
</div>
</form>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<a class="btn btn-success" style="background-color: grey;border: none;margin-right:10px"
data-dismiss="modal">Cancel</a>
<button
type="button"
class=" btn btn-success font " id="tempClickUpdate"><i
class="fas fa-edit"></i>&nbsp;&nbsp;Update
</button>
</div>
</div>
</div>
</div>
<!-- Material listing Modal -->
<div class="modal fade" id="scrollable-modal" tabindex="-1" role="dialog" aria-labelledby="scrollableModalTitle" aria-hidden="true" style="max-width: 100%;">
<div class="modal-dialog modal-dialog-scrollable" role="document" style="max-width: 50%;">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="scrollableModalTitle"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Table will be dynamically inserted here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div>
</div>
<!-- script_sec_starts -->
<!-- prevent duplicate entries made in the config by checking it during on change event of the config value in add or edit -->
<script>
$('#AddConfigValue,#configValue').on('change', function() {
let configValue = $(this).val().trim(); //
$('#loader').show();
$.ajax({
type: 'POST',
url: "<?php echo base_url('configurationctrl/configValueCheck'); ?>",
data: {
configId: $('#ConfigId').val().trim(),
configValue: configValue
},
success: function(data) {
console.log(data);
if (data.length > 0) {
if (data[0]?.isActive == 1) {
alert("This Configuration Value is already present. Kindly change it.");
$('#AddConfigValue').val('');
$('#configValue').val('');
event.preventDefault();
}
if (data[0]?.isActive == 0) {
alert("This Configuration Value is already present in deleted section. Kindly reactivate it if needed.");
$('#AddConfigValue').val('');
$('#configValue').val('');
event.preventDefault();
}
}
},
error: function(xhr, status, error) {
console.log("Error occurred: ", error);
},
complete: function() {
$('#loader').hide();
console.log('AJAX call completed in change.');
}
});
});
</script>
<!-- add or update config value -->
<script>
$(document).ready(function() {
// add config modals add button
$('#tempClickAdd').click( function() {
if ($("#AddConfigValue").val() != '-1' && $("#AddConfigValue").val() != null && $("#AddConfigValue").val().trim() != '') {
$('#loader').show();
$.ajax({
url: "<?php echo base_url('configurationctrl/saveConfigValue'); ?>",
data: {
ConfigID: $('#ConfigId').val(),
ConfigValue: $("#AddConfigValue").val()
},
method: 'POST',
success: function(response) {
if (response.status) {
alert('Config Value added successfully');
location.reload();
} else {
alert('Failed to add Config Value');
}
},
error: function(xhr, status, error) {
console.log("Error occurred: ", error);
},
complete: function() {
console.log('AJAX call completed in tempClickAdd.');
$('#loader').hide();
}
});
} else {
alert('Please enter all the values');
}
});
$(document).on('click', '.editConfigurationBtn', function() {
var id = $(this).data('id');
var key = $(this).data('key');
var code = $(this).data('code');
var configValue = $(this).data('configvalue');
$('#key').val(key);
$('#Config_ID').val(code);
$('#configValue').val(configValue);
$('#EditConfiguration').modal('show');
});
// edit config modals update button
$('#tempClickUpdate').click(function() {
if ($("#configValue").val() != '-1' && $("#configValue").val() != null && $("#configValue").val().trim() != '') {
$('#loader').show();
$.ajax({
url: "<?php echo base_url('configurationctrl/saveConfigValue'); ?>",
data: {
key : $('#key').val(),
ConfigID: $('#Config_ID').val(),
ConfigValue: $("#configValue").val()
},
method: 'POST',
success: function(response) {
if (response.status) {
alert('Config Value updated successfully');
location.reload();
} else {
alert('Failed to update Config Value');
}
},
error: function(xhr, status, error) {
console.log("Error occurred: ", error);
},
complete: function() {
console.log('AJAX call completed.');
$('#loader').hide();
}
});
} else {
alert('Please enter all the values');
}
});
//this click function is used for showing material codes in modal window , MC created using a particular configuration value
$(document).on("click", ".config-category", function () {
const key_id = $(this).data("key");
const value = $(this).data("value");
console.log(value);
$('#loader').show();
$('#scrollableModalTitle').text(`List of Materials created using ${value} `);
// AJAX API call
$.ajax({
url: "<?php echo base_url('materialCodesConfigCategory'); ?>",
data: { configKey: key_id },
method: 'POST',
success: function (response) {
if (response.length > 0) {
let tableHtml = `
<table class="table table-bordered">
<thead style="background-color: #539754; color: white; font-size: 12px;">
<tr>
<th style="text-align: center;" >Material Code</th>
<th style="text-align: center;" >Material Name</th>
<th style="text-align: center;" >Material Type</th>
<th style="text-align: center;" >Material Status</th>
</tr>
</thead>
<tbody>
`;
response.forEach(item => {
tableHtml += `
<tr>
<td class="mc-cell"
data-materialCode="${item.MaterialCode}"
data-materialType="${item.MaterialType}"
data-uom="${item.UOM}"
style="cursor: pointer; color: #4d3a6d;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
<u>${item.MaterialCode}</u>
</td>
<td style="text-align:left; overflow: hidden;text-overflow: ellipsis; word-wrap: break-word !important;
white-space: normal !important; width: 100px !important; ">${item.MaterialName}</td>
<td style="text-align:left; overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">${item.MaterialType}</td>
<td style="text-align:left; overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">${item.IsActive?"Active":"InActive"}</td>
</tr>
`;
});
tableHtml += `
</tbody>
</table>
`;
// Insert the table into the modal body
$('#scrollable-modal .modal-body').html(tableHtml);
// Show the modal
$('#scrollable-modal').modal('show');
// Attach click event to PONO cells after the table is rendered
$('.mc-cell').click(function () {
const materialCode = $(this).attr('data-materialCode');
const materialType = $(this).attr('data-materialType');
const UOM =$(this).attr('data-uom');
let today = new Date();
let day = String(today.getDate()).padStart(2, '0'); // Ensure two-digit format
let month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
let year = today.getFullYear();
let currentDate = `${day}-${month}-${year}`;
const url = '<?php echo base_url(); ?>viewRawmaterial?RID='+materialCode+'&MType='+materialType+'&UOM='+UOM+'&date1='+currentDate;
window.open(url, '_blank');
});
} else {
$('#scrollable-modal .modal-body').html('<p>No data found.</p>');
$('#scrollable-modal').modal('show');
}
},
error: function (xhr, status, error) {
// Handle any errors
console.error("API Error:", error);
alert("Failed to load material data.");
},
complete: function() {
$('#loader').hide();
console.log('ajax call completed..!!');
}
});
});
});
</script>
<script>
//final update button for master config add / update action made in the editConfig page
$('#updateConfigBtnId').click(function() {
if($('#ConfigName').val().trim() == ''){
alert('Please enter Configuration Name..!!');
return;
}
if($('#Remarks').val().trim() == ''){
alert('Please enter comments..!!');
return;
}
$('#loader').show();
$.ajax({
data: {
configName: $('#ConfigName').val().trim(),
configId: $('#ConfigId').val().trim()
},
type: 'POST',
url: "<?php echo base_url(); ?>configurationctrl/configNameCheck",
success: function(data) {
if (data && data.length > 0) {
if (data[0]?.isActive == 1) {
alert("This Configuration Name is already present. kindly change it..!!");
$('#ConfigName').val('');
event.preventDefault();
return false;
} else {
alert("This Configuration Name is already present in deleted section. kindly reactivate it If needed..!!");
$('#ConfigName').val('');
event.preventDefault();
return false;
}
}else{
$('#editConfig').submit();
}
},
error: function(error) {
console.log("error occured..!!", error);
},
complete: function() {
$('#loader').hide();
console.log('ajax call completed..!!');
}
});
});
</script>
<script>
//confirm delete configuration
function confirmDeleteConfig(event) {
event.preventDefault(); // Prevent default link action
let key_id = $(event.currentTarget).data('key');
let code_value = $(event.currentTarget).data('code');
let deleteUrl = event.currentTarget.href; // Store the href URL
if (code_value == 'C023') {
$.ajax({
type: 'POST',
url: "<?php echo base_url('materialCodesConfigCategory'); ?>",
data: { configKey: key_id },
success: function(data) {
let content = "Do you want to delete this configuration?";
if (data.length > 0) {
content += "\n\nCreated Material Codes are - ";
data.forEach(function(item) {
content += "\n- " + item.MaterialCode;
});
let result = confirm(content);
if (result) {
window.location.assign(deleteUrl); // Use assign() instead of href
}
}else{
let result = confirm(content);
if (result) {
window.location.assign(deleteUrl); // Use assign() instead of href
}
}
},
error: function(xhr, status, error) {
console.log("Error occurred: ", error);
},
complete: function() {
console.log('AJAX call completed.');
}
});
} else {
let result = confirm("Do you want to delete this configuration?");
if (result) {
window.location.href = event.currentTarget.href; // Proceed with deletion
}
}
}
//reactivate deleted configuration
function confirmReActivateConfig(event) {
let result = confirm("Do You want to Re activate deleted configuration ?");
if (result) {
return;
} else {
event.preventDefault();
}
}
</script>
<!-- Preventing default Enter key behavior to avoid submitting form in add or edit config values-->
<script>
$(document).on('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault(); // Prevent default Enter key behavior
}
});
</script>
<!-- submitting form when show archive checkbox changes -->
<script>
$(document).on("change", "#showArchiveId", function () {
console.log("Checkbox changed, submitting form...");
$("#archiveFormId").submit();
});
</script>
<!-- data table added for the config value table -->
<script>
document.addEventListener("DOMContentLoaded", function () {
new DataTable("#configtable", {
paging: true, // Enable Pagination
ordering: true, // Enable Sorting
searching: true // Enable Search
});
});
</script>