38086-vm/core/templates/core/quotations.html
2026-02-13 03:08:35 +00:00

240 lines
13 KiB
HTML

{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Quotations" %} | {{ site_settings.business_name }}{% endblock %}
{% block content %}
<div class="container-fluid px-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<div>
<h2 class="fw-bold mb-0">{% trans "Quotations" %}</h2>
<p class="text-muted small mb-0">{% trans "Manage and track your price proposals" %}</p>
</div>
<a href="{% url 'quotation_create' %}" class="btn btn-primary rounded-3 px-4 shadow-sm">
<i class="bi bi-plus-circle me-2"></i>{% trans "New Quotation" %}
</a>
</div>
{% if messages %}
<div class="mb-4">
{% for message in messages %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show rounded-3 shadow-sm border-0" role="alert">
<i class="bi bi-info-circle me-2"></i>{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
</div>
{% endif %}
<div class="card border-0 shadow-sm rounded-4">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="bg-light">
<tr>
<th class="ps-4">{% trans "Quotation #" %}</th>
<th>{% trans "Date" %}</th>
<th>{% trans "Customer" %}</th>
<th>{% trans "Total" %}</th>
<th>{% trans "User" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Valid Until" %}</th>
<th class="text-end pe-4">{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for q in quotations %}
<tr>
<td class="ps-4 fw-bold">
{{ q.quotation_number|default:q.id }}
</td>
<td>{{ q.created_at|date:"Y-m-d" }}</td>
<td>{{ q.customer.name|default:_("Guest") }}</td>
<td class="fw-bold text-dark">{{ site_settings.currency_symbol }}{{ q.total_amount|floatformat:3 }}</td>
<td>
<span class="text-muted small">
<i class="bi bi-person me-1"></i>{{ q.created_by.username|default:"System" }}
</span>
</td>
<td>
{% if q.status == 'draft' %}
<span class="badge bg-secondary-subtle text-secondary rounded-pill px-3">{% trans "Draft" %}</span>
{% elif q.status == 'sent' %}
<span class="badge bg-info-subtle text-info rounded-pill px-3">{% trans "Sent" %}</span>
{% elif q.status == 'accepted' %}
<span class="badge bg-success-subtle text-success rounded-pill px-3">{% trans "Accepted" %}</span>
{% elif q.status == 'converted' %}
<span class="badge bg-primary-subtle text-primary rounded-pill px-3">{% trans "Converted" %}</span>
{% elif q.status == 'rejected' %}
<span class="badge bg-danger-subtle text-danger rounded-pill px-3">{% trans "Rejected" %}</span>
{% endif %}
</td>
<td>{{ q.valid_until|date:"Y-m-d"|default:"-" }}</td>
<td class="text-end pe-4">
<div class="btn-group shadow-sm rounded-3">
{% if q.status != 'converted' %}
<a href="{% url 'quotation_edit' q.id %}" class="btn btn-sm btn-white border text-primary" title="{% trans 'Edit' %}">
<i class="bi bi-pencil"></i>
</a>
{% endif %}
<button type="button" class="btn btn-sm btn-white border text-success"
onclick="openWhatsAppModal('{{ q.id }}', '{{ q.customer.phone|default:'' }}', '{{ q.quotation_number|default:q.id }}')"
title="{% trans 'Send via WhatsApp' %}">
<i class="bi bi-whatsapp"></i>
</button>
<a href="{% url 'quotation_detail' q.id %}" class="btn btn-sm btn-white border" title="{% trans 'View & Print' %}">
<i class="bi bi-printer"></i>
</a>
{% if q.status != 'converted' %}
<button type="button" class="btn btn-sm btn-white border text-success" data-bs-toggle="modal" data-bs-target="#convertModal{{ q.id }}" title="{% trans 'Convert to Invoice' %}">
<i class="bi bi-arrow-right-circle"></i>
</button>
{% endif %}
<button type="button" class="btn btn-sm btn-white border text-danger" data-bs-toggle="modal" data-bs-target="#deleteModal{{ q.id }}">
<i class="bi bi-trash"></i>
</button>
</div>
<!-- Convert Modal -->
<div class="modal fade text-start" id="convertModal{{ q.id }}" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content border-0 shadow rounded-4">
<div class="modal-body p-4 text-center">
<div class="text-primary mb-3">
<i class="bi bi-question-circle" style="font-size: 3rem;"></i>
</div>
<h4 class="fw-bold">{% trans "Convert to Invoice?" %}</h4>
<p class="text-muted">{% trans "This will create a sales invoice and deduct items from stock. You won't be able to undo this easily." %}</p>
<div class="d-grid gap-2">
<a href="{% url 'convert_quotation_to_invoice' q.id %}" class="btn btn-primary rounded-3 py-2">{% trans "Yes, Convert to Invoice" %}</a>
<button type="button" class="btn btn-light rounded-3 py-2" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
</div>
</div>
</div>
</div>
</div>
<!-- Delete Modal -->
<div class="modal fade text-start" id="deleteModal{{ q.id }}" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content border-0 shadow rounded-4">
<div class="modal-body p-4 text-center">
<div class="text-danger mb-3">
<i class="bi bi-exclamation-octagon" style="font-size: 3rem;"></i>
</div>
<h4 class="fw-bold">{% trans "Delete Quotation?" %}</h4>
<p class="text-muted">{% trans "Are you sure you want to delete this quotation? This action cannot be undone." %}</p>
<div class="d-grid gap-2">
<a href="{% url 'delete_quotation' q.id %}" class="btn btn-danger rounded-3 py-2">{% trans "Yes, Delete" %}</a>
<button type="button" class="btn btn-light rounded-3 py-2" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
</div>
</div>
</div>
</div>
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8" class="text-center py-5">
<img src="https://illustrations.popsy.co/gray/work-from-home.svg" alt="Empty" style="width: 200px;" class="mb-3">
<p class="text-muted">{% trans "No quotations found." %}</p>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include "core/pagination.html" with page_obj=quotations %}
</div>
</div>
<!-- WhatsApp Modal -->
<div class="modal fade" id="whatsappModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content border-0 shadow rounded-4">
<div class="modal-header border-0">
<h5 class="fw-bold">{% trans "Send Quotation via WhatsApp" %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" id="waQuotationId">
<div class="mb-3">
<label class="form-label small fw-bold">{% trans "Quotation #" %}</label>
<input type="text" id="waQuotationNum" class="form-control-plaintext fw-bold" readonly>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">{% trans "Phone Number" %}</label>
<input type="text" id="waPhone" class="form-control rounded-3" placeholder="e.g. 628123456789">
<div class="form-text">{% trans "Enter number with country code (e.g., 62...)" %}</div>
</div>
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-light rounded-3" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
<button type="button" class="btn btn-success rounded-3 px-4" onclick="sendWhatsAppFromList()">
<span id="waSpinner" class="spinner-border spinner-border-sm d-none me-2"></span>
{% trans "Send Message" %}
</button>
</div>
</div>
</div>
</div>
</div>
<script>
function openWhatsAppModal(quotationId, phone, quotationNum) {
document.getElementById('waQuotationId').value = quotationId;
document.getElementById('waPhone').value = phone;
document.getElementById('waQuotationNum').value = quotationNum;
new bootstrap.Modal(document.getElementById('whatsappModal')).show();
}
async function sendWhatsAppFromList() {
const quotationId = document.getElementById('waQuotationId').value;
const phone = document.getElementById('waPhone').value;
const btn = document.querySelector('#whatsappModal .btn-success');
const spinner = document.getElementById('waSpinner');
if (!phone) {
alert("{% trans 'Please enter a phone number.' %}");
return;
}
btn.disabled = true;
spinner.classList.remove('d-none');
try {
// Call Backend API to generate and send PDF
const response = await fetch("{% url 'send_quotation_whatsapp' %}", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({
quotation_id: quotationId,
phone: phone
})
});
const data = await response.json();
if (data.success) {
alert('{% trans "Quotation sent via WhatsApp successfully!" %}');
const waModalEl = document.getElementById('whatsappModal');
const modalInstance = bootstrap.Modal.getInstance(waModalEl);
if (modalInstance) {
modalInstance.hide();
}
} else {
alert('{% trans "WhatsApp Error:" %} ' + data.error + '\n\n{% trans "Please check your System Settings > WhatsApp Gateway configuration." %}');
}
} catch (e) {
alert("{% trans 'An error occurred while sending the quotation.' %}");
console.error(e);
} finally {
btn.disabled = false;
spinner.classList.add('d-none');
}
}
</script>
{% endblock %}