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

437 lines
22 KiB
HTML

{% extends "base.html" %}
{% load static %}
{% block title %}Delete Stock Record{% endblock %}
{% block content %}
<div class="d-flex align-items-center mb-3">
<div>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'inventory:dashboard' %}">Inventory</a></li>
<li class="breadcrumb-item"><a href="{% url 'inventory:stock_list' %}">Stock</a></li>
<li class="breadcrumb-item"><a href="{% url 'inventory:stock_detail' object.pk %}">{{ object.item.name }}</a></li>
<li class="breadcrumb-item active">Delete</li>
</ol>
<h1 class="page-header mb-0">Delete Stock Record</h1>
</div>
<div class="ms-auto">
<a href="{% url 'inventory:stock_detail' object.pk %}" class="btn btn-secondary">
<i class="fas fa-arrow-left me-2"></i>Back to Stock
</a>
</div>
</div>
<div class="row justify-content-center">
<div class="col-xl-8">
<div class="card">
<div class="card-header bg-danger text-white">
<h4 class="card-title mb-0">
<i class="fas fa-exclamation-triangle me-2"></i>
Confirm Stock Record Deletion
</h4>
</div>
<div class="card-body">
<div class="alert alert-warning">
<h5 class="alert-heading">
<i class="fas fa-exclamation-triangle me-2"></i>
Are you sure you want to delete this stock record?
</h5>
<p class="mb-0">
This action cannot be undone. The stock record and all associated transaction history will be permanently removed from the system.
</p>
</div>
<!-- Stock Details -->
<div class="row mb-4">
<div class="col-md-6">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-cube me-2"></i>Item Information
</h6>
<div class="mb-2">
<strong>Item:</strong> {{ object.item.name }}
</div>
<div class="mb-2">
<strong>SKU:</strong> {{ object.item.sku }}
</div>
<div class="mb-2">
<strong>Category:</strong> {{ object.item.category.name }}
</div>
<div>
<strong>Unit:</strong> {{ object.item.unit_of_measure }}
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-boxes me-2"></i>Stock Information
</h6>
<div class="mb-2">
<strong>Current Quantity:</strong>
<span class="fs-5 fw-bold {% if object.current_quantity <= object.minimum_quantity %}text-danger{% elif object.current_quantity <= object.reorder_level %}text-warning{% else %}text-success{% endif %}">
{{ object.current_quantity }}
</span>
{{ object.item.unit_of_measure }}
</div>
<div class="mb-2">
<strong>Location:</strong> {{ object.location.name }}
</div>
<div class="mb-2">
<strong>Unit Cost:</strong> ${{ object.unit_cost|floatformat:2 }}
</div>
<div>
<strong>Total Value:</strong>
<span class="fs-5 fw-bold text-primary">
${{ object.total_value|floatformat:2 }}
</span>
</div>
</div>
</div>
</div>
</div>
<!-- Stock Levels -->
<div class="row mb-4">
<div class="col-12">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-chart-line me-2"></i>Stock Levels
</h6>
<div class="row">
<div class="col-md-4">
<div class="text-center">
<div class="fs-4 fw-bold text-danger">{{ object.minimum_quantity }}</div>
<div class="small text-muted">Minimum Quantity</div>
</div>
</div>
<div class="col-md-4">
<div class="text-center">
<div class="fs-4 fw-bold text-warning">{{ object.reorder_level }}</div>
<div class="small text-muted">Reorder Level</div>
</div>
</div>
<div class="col-md-4">
<div class="text-center">
<div class="fs-4 fw-bold text-success">{{ object.maximum_quantity|default:"∞" }}</div>
<div class="small text-muted">Maximum Quantity</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% if object.batch_number or object.expiry_date %}
<div class="row mb-4">
<div class="col-12">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-barcode me-2"></i>Batch Information
</h6>
<div class="row">
{% if object.batch_number %}
<div class="col-md-6">
<div class="mb-2">
<strong>Batch Number:</strong> {{ object.batch_number }}
</div>
</div>
{% endif %}
{% if object.expiry_date %}
<div class="col-md-6">
<div class="mb-2">
<strong>Expiry Date:</strong> {{ object.expiry_date|date:"M d, Y" }}
{% if object.days_until_expiry <= 30 %}
<span class="badge bg-{% if object.days_until_expiry <= 0 %}danger{% elif object.days_until_expiry <= 7 %}warning{% else %}info{% endif %} ms-2">
{% if object.days_until_expiry <= 0 %}
Expired
{% else %}
{{ object.days_until_expiry }} days left
{% endif %}
</span>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if object.notes %}
<div class="row mb-4">
<div class="col-12">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-sticky-note me-2"></i>Notes
</h6>
<div class="alert alert-info mb-0">
{{ object.notes }}
</div>
</div>
</div>
</div>
</div>
{% endif %}
<!-- Transaction History Summary -->
{% if recent_transactions %}
<div class="row mb-4">
<div class="col-12">
<div class="card bg-light">
<div class="card-body">
<h6 class="card-title">
<i class="fas fa-history me-2"></i>Recent Transaction History
</h6>
<div class="table-responsive">
<table class="table table-sm">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Quantity</th>
<th>Balance</th>
<th>User</th>
</tr>
</thead>
<tbody>
{% for transaction in recent_transactions|slice:":5" %}
<tr>
<td>{{ transaction.date|date:"M d, Y" }}</td>
<td>
<span class="badge bg-{% if transaction.transaction_type == 'in' %}success{% elif transaction.transaction_type == 'out' %}warning{% else %}info{% endif %}">
{{ transaction.get_transaction_type_display }}
</span>
</td>
<td>
<span class="{% if transaction.transaction_type == 'in' %}text-success{% elif transaction.transaction_type == 'out' %}text-warning{% endif %}">
{% if transaction.transaction_type == 'in' %}+{% elif transaction.transaction_type == 'out' %}-{% endif %}{{ transaction.quantity }}
</span>
</td>
<td>{{ transaction.balance_after }}</td>
<td>{{ transaction.user.get_full_name|default:"System" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if recent_transactions.count > 5 %}
<div class="text-center mt-2">
<small class="text-muted">And {{ recent_transactions.count|add:"-5" }} more transactions...</small>
</div>
{% endif %}
</div>
</div>
</div>
</div>
{% endif %}
<!-- Deletion Form -->
<form method="post">
{% csrf_token %}
<div class="mb-3">
<label for="deletion_reason" class="form-label">
<strong>Reason for Deletion *</strong>
</label>
<select class="form-select" id="deletion_reason" name="deletion_reason" required>
<option value="">Select a reason</option>
<option value="item_discontinued">Item Discontinued</option>
<option value="location_closed">Location Closed</option>
<option value="data_error">Data Entry Error</option>
<option value="duplicate_record">Duplicate Record</option>
<option value="system_migration">System Migration</option>
<option value="inventory_adjustment">Inventory Adjustment</option>
<option value="compliance">Compliance Requirement</option>
<option value="other">Other</option>
</select>
</div>
<div class="mb-3">
<label for="deletion_notes" class="form-label">
<strong>Additional Notes</strong>
</label>
<textarea class="form-control"
id="deletion_notes"
name="deletion_notes"
rows="3"
placeholder="Provide additional details about why this stock record is being deleted..."></textarea>
<div class="form-text">
These notes will be recorded for audit purposes and inventory tracking.
</div>
</div>
<div class="form-check mb-3">
<input class="form-check-input"
type="checkbox"
id="confirm_deletion"
name="confirm_deletion"
required>
<label class="form-check-label" for="confirm_deletion">
I understand that this action cannot be undone and confirm the deletion of this stock record.
</label>
</div>
<div class="form-check mb-3">
<input class="form-check-input"
type="checkbox"
id="create_adjustment"
name="create_adjustment">
<label class="form-check-label" for="create_adjustment">
Create an inventory adjustment transaction to account for the removed stock.
</label>
</div>
<div class="alert alert-info">
<h6 class="alert-heading">
<i class="fas fa-info-circle me-2"></i>What happens when you delete this stock record?
</h6>
<ul class="mb-0">
<li>The stock record will be permanently removed from the system</li>
<li>All transaction history for this stock will be deleted</li>
<li>Inventory reports and statistics will be affected</li>
<li>Any pending orders or transfers may need manual adjustment</li>
<li>This action will be logged in the audit trail</li>
<li>Stock alerts and notifications will be updated</li>
<li>The item will remain in the system but without stock at this location</li>
</ul>
</div>
<div class="d-flex justify-content-between">
<a href="{% url 'inventory:stock_detail' object.pk %}" class="btn btn-secondary">
<i class="fas fa-times me-2"></i>Cancel
</a>
<button type="submit" class="btn btn-danger" onclick="return confirmDeletion()">
<i class="fas fa-trash me-2"></i>Delete Stock Record
</button>
</div>
</form>
</div>
</div>
<!-- Impact Warning -->
{% if object.current_quantity > 0 %}
<div class="card mt-4">
<div class="card-header bg-warning text-dark">
<h5 class="card-title mb-0">
<i class="fas fa-exclamation-triangle me-2"></i>
Stock Value Impact
</h5>
</div>
<div class="card-body">
<div class="alert alert-warning">
<strong>Financial Impact:</strong> Deleting this stock record will remove inventory worth
<strong>${{ object.total_value|floatformat:2 }}</strong> from your system.
</div>
{% if object.current_quantity <= object.minimum_quantity %}
<div class="alert alert-danger">
<strong>Critical Stock Level:</strong> This item is already at or below minimum stock levels.
Deleting this record may cause stockouts and affect patient care.
</div>
{% endif %}
{% if object.expiry_date and object.days_until_expiry <= 30 %}
<div class="alert alert-info">
<strong>Expiring Stock:</strong> This stock is approaching expiry
({{ object.days_until_expiry }} days remaining). Consider if this deletion is due to expired stock.
</div>
{% endif %}
</div>
</div>
{% endif %}
<!-- Related Information -->
<div class="card mt-4">
<div class="card-header">
<h5 class="card-title">
<i class="fas fa-link me-2"></i>
Related Information
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<h6>Stock Details</h6>
<ul class="list-unstyled">
<li><strong>Stock ID:</strong> {{ object.pk }}</li>
<li><strong>Created:</strong> {{ object.created_at|date:"M d, Y g:i A" }}</li>
<li><strong>Last Updated:</strong> {{ object.updated_at|date:"M d, Y g:i A" }}</li>
<li><strong>Created By:</strong> {{ object.created_by.get_full_name|default:"System" }}</li>
</ul>
</div>
<div class="col-md-6">
<h6>System Information</h6>
<ul class="list-unstyled">
<li><strong>Item ID:</strong> {{ object.item.pk }}</li>
<li><strong>Location ID:</strong> {{ object.location.pk }}</li>
{% if recent_transactions %}
<li><strong>Transactions:</strong> {{ recent_transactions.count }} recorded</li>
{% endif %}
{% if object.batch_number %}
<li><strong>Batch Tracked:</strong> Yes</li>
{% endif %}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function confirmDeletion() {
const reason = document.getElementById('deletion_reason').value;
const confirmed = document.getElementById('confirm_deletion').checked;
if (!reason) {
alert('Please select a reason for deletion.');
return false;
}
if (!confirmed) {
alert('Please confirm that you understand this action cannot be undone.');
return false;
}
const stockId = "{{ object.pk }}";
const itemName = "{{ object.item.name }}";
const quantity = "{{ object.current_quantity }}";
const value = "{{ object.total_value|floatformat:2 }}";
const message = `Are you absolutely sure you want to delete this stock record?\n\nItem: ${itemName}\nQuantity: ${quantity} {{ object.item.unit_of_measure }}\nValue: $${value}\nStock ID: ${stockId}\n\nThis action cannot be undone and will affect inventory reports and statistics.`;
return confirm(message);
}
document.addEventListener('DOMContentLoaded', function() {
// Auto-focus on deletion reason
document.getElementById('deletion_reason').focus();
// Show/hide additional notes based on reason
const reasonSelect = document.getElementById('deletion_reason');
const notesTextarea = document.getElementById('deletion_notes');
reasonSelect.addEventListener('change', function() {
if (this.value === 'other') {
notesTextarea.required = true;
notesTextarea.placeholder = 'Please specify the reason for deletion...';
} else {
notesTextarea.required = false;
notesTextarea.placeholder = 'Provide additional details about why this stock record is being deleted...';
}
});
});
</script>
{% endblock %}