hospital-management/templates/inventory/suppliers/supplier_confirm_delete.html
2025-08-12 13:33:25 +03:00

532 lines
26 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete {{ object.name }} - Suppliers - {{ block.super }}{% endblock %}
{% block content %}
<div class="container-fluid">
<!-- Page Header -->
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h1 class="h3 mb-1 text-danger">
<i class="fas fa-exclamation-triangle me-2"></i>Delete Supplier
</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="{% url 'inventory:dashboard' %}">Inventory</a></li>
<li class="breadcrumb-item"><a href="{% url 'inventory:supplier_list' %}">Suppliers</a></li>
<li class="breadcrumb-item"><a href="{% url 'inventory:supplier_detail' object.pk %}">{{ object.name }}</a></li>
<li class="breadcrumb-item active">Delete</li>
</ol>
</nav>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-8">
<!-- Warning Card -->
<div class="card border-danger mb-4">
<div class="card-header bg-danger text-white">
<h5 class="mb-0">
<i class="fas fa-exclamation-triangle me-2"></i>Confirm Supplier Deletion
</h5>
</div>
<div class="card-body">
<div class="alert alert-danger d-flex align-items-center" role="alert">
<i class="fas fa-exclamation-triangle fa-2x me-3"></i>
<div>
<h6 class="alert-heading mb-1">Warning: This action cannot be undone!</h6>
<p class="mb-0">You are about to permanently delete the supplier <strong>"{{ object.name }}"</strong>. This will remove all associated data and purchase history.</p>
</div>
</div>
<!-- Supplier Information -->
<div class="row mb-4">
<div class="col-md-6">
<h6 class="text-muted mb-3">Supplier Details</h6>
<table class="table table-borderless table-sm">
<tr>
<td class="text-muted" width="100">Code:</td>
<td class="fw-semibold">{{ object.supplier_code }}</td>
</tr>
<tr>
<td class="text-muted">Name:</td>
<td class="fw-semibold">{{ object.name }}</td>
</tr>
<tr>
<td class="text-muted">Type:</td>
<td>
<span class="badge bg-secondary">{{ object.get_supplier_type_display }}</span>
</td>
</tr>
<tr>
<td class="text-muted">Status:</td>
<td>
<span class="badge bg-{% if object.is_active %}success{% else %}secondary{% endif %}">
{% if object.is_active %}Active{% else %}Inactive{% endif %}
</span>
</td>
</tr>
<tr>
<td class="text-muted">Created:</td>
<td>{{ object.created_at|date:"M d, Y" }}</td>
</tr>
</table>
</div>
<div class="col-md-6">
<h6 class="text-muted mb-3">Contact Information</h6>
<table class="table table-borderless table-sm">
<tr>
<td class="text-muted" width="100">Contact:</td>
<td>{{ object.contact_person|default:"—" }}</td>
</tr>
<tr>
<td class="text-muted">Phone:</td>
<td>{{ object.phone|default:"—" }}</td>
</tr>
<tr>
<td class="text-muted">Email:</td>
<td>{{ object.email|default:"—" }}</td>
</tr>
<tr>
<td class="text-muted">Rating:</td>
<td>
{% if object.rating %}
<div class="text-warning">
{% for i in "12345" %}
{% if forloop.counter <= object.rating %}
<i class="fas fa-star small"></i>
{% else %}
<i class="far fa-star small"></i>
{% endif %}
{% endfor %}
</div>
{% else %}
{% endif %}
</td>
</tr>
</table>
</div>
</div>
<!-- Impact Assessment -->
<div class="card border-warning mb-4">
<div class="card-header bg-warning text-dark">
<h6 class="mb-0">
<i class="fas fa-impact me-2"></i>Deletion Impact Assessment
</h6>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-3 text-center mb-3">
<div class="bg-primary bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-shopping-cart fa-lg text-white"></i>
</div>
<h4 class="text-primary mb-0">{{ related_orders_count }}</h4>
<small class="text-muted">Purchase Orders</small>
{% if related_orders_count > 0 %}
<div class="text-warning small mt-1">History preserved</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-info bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-boxes fa-lg text-white"></i>
</div>
<h4 class="text-info mb-0">{{ related_items_count }}</h4>
<small class="text-muted">Inventory Items</small>
{% if related_items_count > 0 %}
<div class="text-danger small mt-1">Will be unlinked</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-success bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-dollar-sign fa-lg text-white"></i>
</div>
<h4 class="text-success mb-0">${{ total_spent|floatformat:0 }}</h4>
<small class="text-muted">Total Spent</small>
{% if total_spent > 0 %}
<div class="text-warning small mt-1">History preserved</div>
{% endif %}
</div>
<div class="col-md-3 text-center mb-3">
<div class="bg-secondary bg-gradient rounded-circle d-flex align-items-center justify-content-center mx-auto mb-2" style="width: 60px; height: 60px;">
<i class="fas fa-file-alt fa-lg text-white"></i>
</div>
<h4 class="text-secondary mb-0">{{ related_documents_count }}</h4>
<small class="text-muted">Documents</small>
{% if related_documents_count > 0 %}
<div class="text-warning small mt-1">Will be archived</div>
{% endif %}
</div>
</div>
{% if related_orders_count > 0 or related_items_count > 0 %}
<div class="alert alert-warning mt-3" role="alert">
<i class="fas fa-exclamation-triangle me-2"></i>
<strong>Data Impact:</strong>
This supplier has {{ related_orders_count }} purchase order{{ related_orders_count|pluralize }}
and {{ related_items_count }} inventory item{{ related_items_count|pluralize }} associated with it.
Purchase order history will be preserved, but inventory items will lose their supplier association.
</div>
{% endif %}
{% if object.is_active %}
<div class="alert alert-danger mt-3" role="alert">
<i class="fas fa-exclamation-circle me-2"></i>
<strong>Active Supplier Warning:</strong>
This supplier is currently active and may have pending orders or ongoing business relationships.
Consider deactivating it first instead of deleting.
</div>
{% endif %}
</div>
</div>
<!-- Related Data Preview -->
{% if related_orders_count > 0 %}
<div class="card border-info mb-4">
<div class="card-header bg-light">
<h6 class="mb-0">
<i class="fas fa-shopping-cart me-2"></i>Recent Purchase Orders ({{ related_orders_count }})
</h6>
</div>
<div class="card-body">
<div class="row">
{% for order in recent_orders|slice:":6" %}
<div class="col-md-6 mb-2">
<div class="d-flex align-items-center">
<i class="fas fa-shopping-cart text-primary me-2"></i>
<div>
<div class="fw-semibold small">{{ order.order_number }}</div>
<div class="text-muted small">{{ order.order_date|date:"M d, Y" }} - ${{ order.total_amount|floatformat:2 }}</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% if related_orders_count > 6 %}
<div class="text-muted small mt-2">
... and {{ related_orders_count|add:"-6" }} more order{{ related_orders_count|add:"-6"|pluralize }}
</div>
{% endif %}
</div>
</div>
{% endif %}
<!-- Data Handling Options -->
<div class="card border-info mb-4">
<div class="card-header bg-info text-white">
<h6 class="mb-0">
<i class="fas fa-cog me-2"></i>Data Handling Options
</h6>
</div>
<div class="card-body">
<div class="form-check mb-3">
<input class="form-check-input" type="radio" name="dataHandling" id="preserveHistory" value="preserve" checked>
<label class="form-check-label" for="preserveHistory">
<strong>Preserve Purchase History</strong>
<div class="text-muted small">Keep all purchase order records for audit purposes (recommended)</div>
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="radio" name="dataHandling" id="archiveData" value="archive">
<label class="form-check-label" for="archiveData">
<strong>Archive All Data</strong>
<div class="text-muted small">Move all related data to archive before deletion</div>
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="unlinkItems" checked>
<label class="form-check-label" for="unlinkItems">
Unlink inventory items from this supplier (items will remain but lose supplier association)
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="notifyStakeholders">
<label class="form-check-label" for="notifyStakeholders">
Notify relevant stakeholders about supplier removal
</label>
</div>
</div>
</div>
<!-- Confirmation Requirements -->
<div class="card border-dark">
<div class="card-header bg-dark text-white">
<h6 class="mb-0">
<i class="fas fa-check-square me-2"></i>Confirmation Requirements
</h6>
</div>
<div class="card-body">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmUnderstand" required>
<label class="form-check-label" for="confirmUnderstand">
I understand that this action will permanently delete the supplier record
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmDataImpact" required>
<label class="form-check-label" for="confirmDataImpact">
I acknowledge the impact on {{ related_orders_count }} purchase order{{ related_orders_count|pluralize }} and {{ related_items_count }} inventory item{{ related_items_count|pluralize }}
</label>
</div>
{% if object.is_active %}
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="confirmActive" required>
<label class="form-check-label" for="confirmActive">
I understand that this supplier is currently active and deleting it may affect ongoing operations
</label>
</div>
{% endif %}
<div class="form-check mb-4">
<input class="form-check-input" type="checkbox" id="confirmNoUndo" required>
<label class="form-check-label" for="confirmNoUndo">
I confirm that this action cannot be undone and I have backed up any necessary data
</label>
</div>
<div class="mb-3">
<label for="confirmationText" class="form-label">
Type <strong>"{{ object.name }}"</strong> to confirm deletion:
</label>
<input type="text" class="form-control" id="confirmationText"
placeholder="Enter supplier name exactly as shown" required>
<div class="form-text">This helps prevent accidental deletions</div>
</div>
</div>
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="card">
<div class="card-body">
<form method="post" id="deleteForm">
{% csrf_token %}
<input type="hidden" name="data_handling" id="dataHandlingInput" value="preserve">
<input type="hidden" name="unlink_items" id="unlinkItemsInput" value="true">
<input type="hidden" name="notify_stakeholders" id="notifyStakeholdersInput" value="false">
<div class="d-flex justify-content-between align-items-center">
<div>
<a href="{% url 'inventory:supplier_detail' object.pk %}" class="btn btn-outline-secondary">
<i class="fas fa-arrow-left me-2"></i>Cancel
</a>
{% if object.is_active %}
<a href="{% url 'inventory:supplier_update' object.pk %}" class="btn btn-outline-warning">
<i class="fas fa-pause me-2"></i>Deactivate Instead
</a>
{% endif %}
</div>
<div>
<button type="button" class="btn btn-outline-info me-2" onclick="exportSupplierData()">
<i class="fas fa-download me-2"></i>Export Data First
</button>
<button type="submit" class="btn btn-danger" id="deleteButton" disabled>
<i class="fas fa-trash me-2"></i>Delete Supplier Permanently
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
// Supplier delete confirmation functionality
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
const confirmationText = document.getElementById('confirmationText');
const deleteButton = document.getElementById('deleteButton');
const deleteForm = document.getElementById('deleteForm');
const supplierName = '{{ object.name }}';
// Data handling options
const dataHandlingRadios = document.querySelectorAll('input[name="dataHandling"]');
const unlinkItemsCheckbox = document.getElementById('unlinkItems');
const notifyStakeholdersCheckbox = document.getElementById('notifyStakeholders');
function validateForm() {
const requiredCheckboxes = document.querySelectorAll('input[type="checkbox"][required]');
const allChecked = Array.from(requiredCheckboxes).every(cb => cb.checked);
const textMatches = confirmationText.value.trim() === supplierName;
deleteButton.disabled = !(allChecked && textMatches);
if (allChecked && textMatches) {
deleteButton.classList.remove('btn-danger');
deleteButton.classList.add('btn-outline-danger');
} else {
deleteButton.classList.remove('btn-outline-danger');
deleteButton.classList.add('btn-danger');
}
}
function updateHiddenInputs() {
const selectedDataHandling = document.querySelector('input[name="dataHandling"]:checked').value;
document.getElementById('dataHandlingInput').value = selectedDataHandling;
document.getElementById('unlinkItemsInput').value = unlinkItemsCheckbox.checked;
document.getElementById('notifyStakeholdersInput').value = notifyStakeholdersCheckbox.checked;
}
// Add event listeners
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', validateForm);
});
dataHandlingRadios.forEach(radio => {
radio.addEventListener('change', updateHiddenInputs);
});
unlinkItemsCheckbox.addEventListener('change', updateHiddenInputs);
notifyStakeholdersCheckbox.addEventListener('change', updateHiddenInputs);
confirmationText.addEventListener('input', validateForm);
// Form submission with final confirmation
deleteForm.addEventListener('submit', function(e) {
e.preventDefault();
if (!deleteButton.disabled) {
updateHiddenInputs();
const finalConfirm = confirm(
`FINAL CONFIRMATION\n\n` +
`You are about to permanently delete "${supplierName}".\n\n` +
`This will affect:\n` +
`• {{ related_orders_count }} purchase order{{ related_orders_count|pluralize }}\n` +
`• {{ related_items_count }} inventory item{{ related_items_count|pluralize }}\n` +
`${{ total_spent|floatformat:0 }} in purchase history\n\n` +
`This action CANNOT be undone.\n\n` +
`Are you absolutely sure you want to proceed?`
);
if (finalConfirm) {
// Show loading state
deleteButton.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Deleting...';
deleteButton.disabled = true;
// Submit the form
this.submit();
}
}
});
// Initial validation
validateForm();
updateHiddenInputs();
});
function exportSupplierData() {
const supplierId = '{{ object.pk }}';
fetch(`/inventory/suppliers/${supplierId}/export/`, {
method: 'GET',
headers: {
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value,
},
})
.then(response => response.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `{{ object.name|slugify }}-supplier-data.json`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
alert('Supplier data exported successfully. You can now proceed with deletion if needed.');
})
.catch(error => {
console.error('Error exporting supplier data:', error);
alert('Error exporting supplier data. Please try again.');
});
}
// Prevent accidental page navigation
window.addEventListener('beforeunload', function(e) {
const checkboxes = document.querySelectorAll('input[type="checkbox"]:checked');
const confirmationText = document.getElementById('confirmationText');
if (checkboxes.length > 0 || confirmationText.value.trim() !== '') {
e.preventDefault();
e.returnValue = '';
return 'You have unsaved changes. Are you sure you want to leave?';
}
});
</script>
<style>
.bg-gradient {
background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
}
.table-borderless td {
border: none;
padding: 0.25rem 0;
}
.form-check-label {
cursor: pointer;
line-height: 1.4;
}
.form-check-input:checked {
background-color: #dc3545;
border-color: #dc3545;
}
.alert-heading {
font-weight: 600;
}
.card-header.bg-danger {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.card-header.bg-warning {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.card-header.bg-info {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.card-header.bg-dark {
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
@media (max-width: 768px) {
.d-flex.justify-content-between {
flex-direction: column;
gap: 1rem;
}
.btn-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.col-md-3 {
margin-bottom: 1rem;
}
}
</style>
{% endblock %}