Marwan Alwali 263292f6be update
2025-11-04 00:50:06 +03:00

271 lines
17 KiB
HTML

{% extends 'base.html' %}
{% load static %}
{% block title %}Medical Bills - Billing{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h3 mb-0">Medical Bills</h1>
<a href="{% url 'billing:bill_create' %}" class="btn btn-primary">
<i class="fas fa-plus"></i> Create Bill
</a>
</div>
<!-- Statistics Cards -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card bg-primary text-white">
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h6 class="card-title">Total Bills</h6>
<h4 class="mb-0">{{ stats.total_bills }}</h4>
</div>
<i class="fas fa-file-invoice fa-2x opacity-75"></i>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-success text-white">
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h6 class="card-title">Total Amount</h6>
<h4 class="mb-0">${{ stats.total_amount|floatformat:2 }}</h4>
</div>
<i class="fas fa-dollar-sign fa-2x opacity-75"></i>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-info text-white">
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h6 class="card-title">Total Paid</h6>
<h4 class="mb-0">${{ stats.total_paid|floatformat:2 }}</h4>
</div>
<i class="fas fa-check-circle fa-2x opacity-75"></i>
</div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-warning text-white">
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h6 class="card-title">Balance Due</h6>
<h4 class="mb-0">${{ stats.total_balance|floatformat:2 }}</h4>
</div>
<i class="fas fa-exclamation-triangle fa-2x opacity-75"></i>
</div>
</div>
</div>
</div>
</div>
<!-- Filters -->
<div class="card mb-4">
<div class="card-body">
<form method="get" class="row g-3">
<div class="col-md-2">
<label for="status" class="form-label">Status</label>
<select name="status" id="status" class="form-select">
<option value="">All Statuses</option>
<option value="DRAFT" {% if status == 'DRAFT' %}selected{% endif %}>Draft</option>
<option value="PENDING" {% if status == 'PENDING' %}selected{% endif %}>Pending</option>
<option value="SUBMITTED" {% if status == 'SUBMITTED' %}selected{% endif %}>Submitted</option>
<option value="PARTIAL_PAID" {% if status == 'PARTIAL_PAID' %}selected{% endif %}>Partially Paid</option>
<option value="PAID" {% if status == 'PAID' %}selected{% endif %}>Paid</option>
<option value="OVERDUE" {% if status == 'OVERDUE' %}selected{% endif %}>Overdue</option>
<option value="COLLECTIONS" {% if status == 'COLLECTIONS' %}selected{% endif %}>Collections</option>
<option value="WRITTEN_OFF" {% if status == 'WRITTEN_OFF' %}selected{% endif %}>Written Off</option>
<option value="CANCELLED" {% if status == 'CANCELLED' %}selected{% endif %}>Cancelled</option>
</select>
</div>
<div class="col-md-2">
<label for="bill_type" class="form-label">Bill Type</label>
<select name="bill_type" id="bill_type" class="form-select">
<option value="">All Types</option>
<option value="INPATIENT" {% if bill_type == 'INPATIENT' %}selected{% endif %}>Inpatient</option>
<option value="OUTPATIENT" {% if bill_type == 'OUTPATIENT' %}selected{% endif %}>Outpatient</option>
<option value="EMERGENCY" {% if bill_type == 'EMERGENCY' %}selected{% endif %}>Emergency</option>
<option value="SURGERY" {% if bill_type == 'SURGERY' %}selected{% endif %}>Surgery</option>
<option value="LABORATORY" {% if bill_type == 'LABORATORY' %}selected{% endif %}>Laboratory</option>
<option value="RADIOLOGY" {% if bill_type == 'RADIOLOGY' %}selected{% endif %}>Radiology</option>
<option value="PHARMACY" {% if bill_type == 'PHARMACY' %}selected{% endif %}>Pharmacy</option>
</select>
</div>
<div class="col-md-2">
<label for="date_from" class="form-label">Date From</label>
<input type="date" name="date_from" id="date_from" class="form-control" value="{{ date_from }}">
</div>
<div class="col-md-2">
<label for="date_to" class="form-label">Date To</label>
<input type="date" name="date_to" id="date_to" class="form-control" value="{{ date_to }}">
</div>
<div class="col-md-3">
<label for="search" class="form-label">Search</label>
<input type="text" name="search" id="search" class="form-control"
placeholder="Bill number, patient name, MRN..." value="{{ search }}">
</div>
<div class="col-md-1">
<label class="form-label">&nbsp;</label>
<button type="submit" class="btn btn-primary d-block">Filter</button>
</div>
</form>
</div>
</div>
<!-- Bills Table -->
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Medical Bills</h5>
<a href="{% url 'billing:export_bills' %}" class="btn btn-outline-secondary btn-sm">
<i class="fas fa-download"></i> Export CSV
</a>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead class="table-light">
<tr>
<th>Bill Number</th>
<th>Patient</th>
<th>Type</th>
<th>Bill Date</th>
<th>Due Date</th>
<th>Total Amount</th>
<th>Paid Amount</th>
<th>Balance</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for bill in bills %}
<tr>
<td>
<a href="{% url 'billing:bill_detail' bill.bill_id %}" class="text-decoration-none">
{{ bill.bill_number }}
</a>
</td>
<td>
<div>
<strong>{{ bill.patient.get_full_name }}</strong><br>
<small class="text-muted">MRN: {{ bill.patient.mrn }}</small>
</div>
</td>
<td>
<span class="badge bg-secondary">{{ bill.get_bill_type_display }}</span>
</td>
<td>{{ bill.bill_date|date:"M d, Y" }}</td>
<td>
{{ bill.due_date|date:"M d, Y" }}
{% if bill.is_overdue %}
<br><small class="text-danger">Overdue</small>
{% endif %}
</td>
<td>${{ bill.total_amount|floatformat:2 }}</td>
<td>${{ bill.paid_amount|floatformat:2 }}</td>
<td>
<strong class="{% if bill.balance_amount > 0 %}text-warning{% else %}text-success{% endif %}">
${{ bill.balance_amount|floatformat:2 }}
</strong>
</td>
<td>
{% if bill.status == 'DRAFT' %}
<span class="badge bg-secondary">Draft</span>
{% elif bill.status == 'PENDING' %}
<span class="badge bg-warning">Pending</span>
{% elif bill.status == 'SUBMITTED' %}
<span class="badge bg-info">Submitted</span>
{% elif bill.status == 'PARTIAL_PAID' %}
<span class="badge bg-primary">Partially Paid</span>
{% elif bill.status == 'PAID' %}
<span class="badge bg-success">Paid</span>
{% elif bill.status == 'OVERDUE' %}
<span class="badge bg-danger">Overdue</span>
{% elif bill.status == 'COLLECTIONS' %}
<span class="badge bg-dark">Collections</span>
{% elif bill.status == 'WRITTEN_OFF' %}
<span class="badge bg-secondary">Written Off</span>
{% elif bill.status == 'CANCELLED' %}
<span class="badge bg-secondary">Cancelled</span>
{% endif %}
</td>
<td>
<div class="btn-group btn-group-sm">
<a href="{% url 'billing:bill_detail' bill.bill_id %}"
class="btn btn-outline-primary" title="View Details">
<i class="fas fa-eye"></i>
</a>
{% if bill.status == 'DRAFT' %}
<form method="post" action="{% url 'billing:submit_bill' bill.bill_id %}" class="d-inline">
{% csrf_token %}
<button type="submit" class="btn btn-outline-success" title="Submit Bill">
<i class="fas fa-paper-plane"></i>
</button>
</form>
{% endif %}
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="10" class="text-center py-4">
<div class="text-muted">
<i class="fas fa-file-invoice fa-3x mb-3"></i>
<p>No medical bills found.</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<!-- Pagination -->
{% if page_obj.has_other_pages %}
<nav aria-label="Bills pagination" class="mt-4">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page=1{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.bill_type %}&bill_type={{ request.GET.bill_type }}{% endif %}{% if request.GET.date_from %}&date_from={{ request.GET.date_from }}{% endif %}{% if request.GET.date_to %}&date_to={{ request.GET.date_to }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}">First</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.bill_type %}&bill_type={{ request.GET.bill_type }}{% endif %}{% if request.GET.date_from %}&date_from={{ request.GET.date_from }}{% endif %}{% if request.GET.date_to %}&date_to={{ request.GET.date_to }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}">Previous</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.bill_type %}&bill_type={{ request.GET.bill_type }}{% endif %}{% if request.GET.date_from %}&date_from={{ request.GET.date_from }}{% endif %}{% if request.GET.date_to %}&date_to={{ request.GET.date_to }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}">Next</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% if request.GET.status %}&status={{ request.GET.status }}{% endif %}{% if request.GET.bill_type %}&bill_type={{ request.GET.bill_type }}{% endif %}{% if request.GET.date_from %}&date_from={{ request.GET.date_from }}{% endif %}{% if request.GET.date_to %}&date_to={{ request.GET.date_to }}{% endif %}{% if request.GET.search %}&search={{ request.GET.search }}{% endif %}">Last</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
</div>
</div>
</div>
{% endblock %}