324 lines
18 KiB
PHP
324 lines
18 KiB
PHP
<?php
|
|
// show_temp_indent_upload_data.php
|
|
include('techsyn_header.php');
|
|
include('db_connection.php');
|
|
|
|
$interm_id = $_GET['indent_interm_id'] ?? 0;
|
|
|
|
// Handle Cancel button click
|
|
if(isset($_POST['cancel'])) {
|
|
$delete_query = "DELETE FROM temp_indent_upload WHERE id = ?";
|
|
$delete_stmt = $conn->prepare($delete_query);
|
|
if($delete_stmt) {
|
|
$delete_stmt->bind_param("i", $interm_id);
|
|
if($delete_stmt->execute()) {
|
|
// Bootstrap success alert
|
|
echo '<div class="alert alert-success alert-dismissible fade in" style="position: fixed; top: 20px; right: 20px; z-index: 9999;">
|
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
|
<strong>Success!</strong> Upload cancelled. Temporary data deleted.
|
|
</div>';
|
|
echo '<script>
|
|
setTimeout(function() {
|
|
window.location.href = "bulk_indent_upload.php";
|
|
}, 2000);
|
|
</script>';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="main-container ace-save-state" id="main-container">
|
|
<?php include('techsyn_sidebar.php'); ?>
|
|
|
|
<div class="main-content">
|
|
<div class="main-content-inner">
|
|
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
|
|
<ul class="breadcrumb">
|
|
<li class="active">Indent</li>
|
|
<li class="active">Bulk Indent Upload Preview</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="page-content">
|
|
<div class="table-responsiv">
|
|
<div class="panel panel-primary">
|
|
<div class="panel-heading">
|
|
|
|
</div>
|
|
<div class="panel-body">
|
|
<?php
|
|
$query = "SELECT excel_data, created_date FROM temp_indent_upload WHERE id = ?";
|
|
$stmt = $conn->prepare($query);
|
|
$stmt->bind_param("i", $interm_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if($row = $result->fetch_assoc()) {
|
|
$data = json_decode($row['excel_data'], true);
|
|
$created_date = $row['created_date'];
|
|
|
|
|
|
|
|
|
|
echo '<form method="post" action="process_indent_upload.php" id="processForm">';
|
|
echo '<input type="hidden" name="interm_id" value="' . $interm_id . '">';
|
|
echo '<div class="table-responsive">';
|
|
echo '<table class="table table-bordered table-striped table-hover">';
|
|
echo '<thead>
|
|
<tr class="info">
|
|
<th><i class="fa fa-calendar"></i> Indent Date</th>
|
|
<th><i class="fa fa-tasks"></i> Activity Name</th>
|
|
<th><i class="fa fa-barcode"></i> Item Code</th>
|
|
<th><i class="fa fa-cubes"></i> Indent Quantity</th>
|
|
<th><i class="fa fa-check-circle"></i> Status</th>
|
|
</tr>
|
|
</thead><tbody>';
|
|
|
|
$all_valid = true;
|
|
$invalid_count = 0;
|
|
foreach($data as $index => $row_data) {
|
|
$row_class = '';
|
|
$status = validate_indent_row($row_data);
|
|
|
|
if(strpos($status, 'label-danger') !== false) {
|
|
$all_valid = false;
|
|
$invalid_count++;
|
|
$row_class = 'danger';
|
|
} elseif(strpos($status, 'label-warning') !== false) {
|
|
$row_class = 'warning';
|
|
} else {
|
|
$row_class = 'success';
|
|
}
|
|
|
|
echo '<tr class="' . $row_class . '">';
|
|
echo '<td>' . htmlspecialchars($row_data[0]) . '</td>';
|
|
echo '<td>' . htmlspecialchars($row_data[1]) . '</td>';
|
|
echo '<td>' . htmlspecialchars($row_data[2]) . '</td>';
|
|
echo '<td>' . htmlspecialchars($row_data[3]) . '</td>';
|
|
echo '<td>' . $status . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
|
|
echo '</tbody></table>';
|
|
echo '</div>';
|
|
|
|
// Summary box
|
|
|
|
|
|
// Buttons section
|
|
echo '<div class="text-center" style="margin-top: 20px; padding: 20px; background-color: #f5f5f5; border-radius: 5px;">';
|
|
|
|
if($all_valid) {
|
|
echo '<button type="button" class="btn btn-success btn-lg" data-toggle="modal" data-target="#processModal">
|
|
<i class="fa fa-check-circle"></i> Process Indent Upload
|
|
</button>';
|
|
} else {
|
|
echo '<div class="alert alert-danger">
|
|
<i class="fa fa-exclamation-triangle"></i>
|
|
<strong>Please fix the errors highlighted in red before processing.</strong>
|
|
</div>';
|
|
echo '<button type="button" class="btn btn-success btn-lg" disabled>
|
|
<i class="fa fa-times-circle"></i> Fix Errors First
|
|
</button>';
|
|
}
|
|
|
|
echo ' ';
|
|
echo '<button type="button" class="btn btn-danger btn-lg" data-toggle="modal" data-target="#cancelModal">
|
|
<i class="fa fa-times-circle"></i> Cancel & Delete Upload
|
|
</button>';
|
|
|
|
echo '</div>';
|
|
echo '</form>';
|
|
|
|
// ✅ Separate form for Cancel (hidden)
|
|
echo '<form method="post" action="" id="cancelForm"></form>';
|
|
|
|
// ✅ Bootstrap Modals
|
|
?>
|
|
|
|
<!-- Process Confirmation Modal -->
|
|
<div class="modal fade" id="processModal" tabindex="-1" role="dialog" aria-labelledby="processModalLabel">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
<h4 class="modal-title" id="processModalLabel">
|
|
<i class="fa fa-question-circle text-success"></i> Confirm Processing
|
|
</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="alert alert-warning">
|
|
<h4><i class="fa fa-warning"></i> Are you sure?</h4>
|
|
<p>This action will:</p>
|
|
<ul>
|
|
<li>Create <strong><?php echo count($data); ?> indent(s)</strong> in the system</li>
|
|
<li>Delete the temporary upload data</li>
|
|
<li>This action cannot be undone</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">
|
|
<i class="fa fa-times"></i> No, Go Back
|
|
</button>
|
|
<button type="button" class="btn btn-success" onclick="submitProcessForm()">
|
|
<i class="fa fa-check"></i> Yes, Process Upload
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Cancel Confirmation Modal -->
|
|
<div class="modal fade" id="cancelModal" tabindex="-1" role="dialog" aria-labelledby="cancelModalLabel">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
<h4 class="modal-title" id="cancelModalLabel">
|
|
<i class="fa fa-exclamation-triangle text-danger"></i> Confirm Cancellation
|
|
</h4>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="alert alert-danger">
|
|
<h4><i class="fa fa-trash"></i> Delete Upload Data?</h4>
|
|
<p>This action will:</p>
|
|
<ul>
|
|
<li>Permanently delete all temporary upload data</li>
|
|
<li>Cancel the current upload process</li>
|
|
<li>You will need to upload the file again</li>
|
|
<li>This action cannot be undone</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-default" data-dismiss="modal">
|
|
<i class="fa fa-times"></i> No, Keep Data
|
|
</button>
|
|
<button type="button" class="btn btn-danger" onclick="submitCancelForm()">
|
|
<i class="fa fa-trash"></i> Yes, Delete & Cancel
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function submitProcessForm() {
|
|
// Show loading state
|
|
$('#processModal .btn-success').html('<i class="fa fa-spinner fa-spin"></i> Processing...').prop('disabled', true);
|
|
|
|
// Submit form after delay
|
|
setTimeout(function() {
|
|
document.getElementById('processForm').submit();
|
|
}, 500);
|
|
}
|
|
|
|
function submitCancelForm() {
|
|
// Create dynamic form for cancel
|
|
var form = document.getElementById('cancelForm');
|
|
var input = document.createElement('input');
|
|
input.type = 'hidden';
|
|
input.name = 'cancel';
|
|
input.value = '1';
|
|
form.appendChild(input);
|
|
|
|
// Show loading state
|
|
$('#cancelModal .btn-danger').html('<i class="fa fa-spinner fa-spin"></i> Deleting...').prop('disabled', true);
|
|
|
|
// Submit form
|
|
setTimeout(function() {
|
|
form.submit();
|
|
}, 500);
|
|
}
|
|
|
|
// Auto-hide alerts after 5 seconds
|
|
setTimeout(function() {
|
|
$('.alert:not(.alert-permanent)').fadeOut('slow');
|
|
}, 5000);
|
|
</script>
|
|
|
|
<?php
|
|
|
|
} else {
|
|
echo '<div class="alert alert-danger">
|
|
<div class="media">
|
|
<div class="media-left">
|
|
<i class="fa fa-exclamation-triangle fa-3x"></i>
|
|
</div>
|
|
<div class="media-body">
|
|
<h4 class="media-heading">Data Not Found!</h4>
|
|
<p>The temporary upload data could not be found. It may have been already processed or deleted.</p>
|
|
<a href="bulk_indent_upload.php" class="btn btn-primary">
|
|
<i class="fa fa-arrow-left"></i> Back to Upload
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
function validate_indent_row($row) {
|
|
global $conn;
|
|
|
|
if(count($row) < 4) {
|
|
return '<span class="label label-danger"><i class="fa fa-times"></i> Incomplete</span>';
|
|
}
|
|
|
|
// Check date format
|
|
$date_formats = ['Y-m-d', 'd-m-Y', 'd/m/Y', 'm-d-Y', 'm/d/Y'];
|
|
$date_valid = false;
|
|
foreach($date_formats as $format) {
|
|
$date = DateTime::createFromFormat($format, $row[0]);
|
|
if($date && $date->format($format) == $row[0]) {
|
|
$date_valid = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!$date_valid) {
|
|
return '<span class="label label-danger"><i class="fa fa-calendar-times-o"></i> Invalid Date</span>';
|
|
}
|
|
|
|
// Check activity exists
|
|
$stmt = $conn->prepare("SELECT program_id FROM program_master WHERE program_code = ? LIMIT 1");
|
|
$stmt->bind_param("s", $row[1]);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if($result->num_rows == 0) {
|
|
return '<span class="label label-danger"><i class="fa fa-tasks"></i> Activity Not Found</span>';
|
|
}
|
|
|
|
// Check item code exists
|
|
$stmt = $conn->prepare("SELECT item_id FROM tbl_items WHERE item_code = ? LIMIT 1");
|
|
$stmt->bind_param("s", $row[2]);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if($result->num_rows == 0) {
|
|
return '<span class="label label-danger"><i class="fa fa-barcode"></i> Item Not Found</span>';
|
|
}
|
|
|
|
// Check quantity
|
|
if(!is_numeric($row[3]) || $row[3] <= 0) {
|
|
return '<span class="label label-danger"><i class="fa fa-balance-scale"></i> Invalid Qty</span>';
|
|
}
|
|
|
|
return '<span class="label label-success"><i class="fa fa-check"></i> Valid</span>';
|
|
}
|
|
|
|
include('techsyn_footer.php');
|
|
?>
|