haikal/templates/sales/invoices/invoice_detail.html
2024-12-31 15:44:49 +00:00

205 lines
11 KiB
HTML

{% extends "base.html" %}
{% load i18n %}
{% block title %}{{ _("View Estimate") }}{% endblock title %}
{% block content %}
<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header bg-primary">
<h5 class="modal-title text-light" id="confirmModalLabel">{% trans 'Confirm' %}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{% trans 'Are you sure' %}
<div class="modal-footer">
<button type="button"
class="btn btn-sm btn-danger"
data-bs-dismiss="modal">
{% trans 'No' %}
</button>
<form id="confirmForm" method="POST" action="{% url 'invoice_mark_as' invoice.pk %}?mark=accept" class="d-inline">
{% csrf_token %}
<button type="submit" class="btn btn-success btn-sm">{% trans "Yes" %}</button>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- ============================================-->
<!-- <section> begin ============================-->
<section class="pt-5 pb-9 bg-body-emphasis dark__bg-gray-1200 border-top">
<div class="container-small mt-3">
<div class="d-flex justify-content-between align-items-end mb-4">
<h2 class="mb-0">Invoice</h2>
<div class="d-flex align-items-center gap-2">
{% if invoice.invoice_status == 'in_review' %}
<button id="accept_invoice" class="btn btn-phoenix-secondary" data-bs-toggle="modal" data-bs-target="#confirmModal"><span class="d-none d-sm-inline-block">Accept</span></button>
{% endif %}
{% if invoice.invoice_status == 'approved' %}
<a href="{% url 'payment_create' invoice.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">Record Payment</span></a>
{% endif %}
<a href="{% url 'invoice_preview' invoice.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">Preview</span></a>
</div>
</div>
<!-- ============================================-->
<div class="card mb-5">
<div class="card-body">
<div class="row g-4 g-xl-1 g-xxl-3 justify-content-between">
<div class="col-sm-auto">
<div class="d-sm-block d-inline-flex d-md-flex flex-xl-column flex-xxl-row align-items-center align-items-xl-start align-items-xxl-center">
<div class="d-flex bg-success-subtle rounded flex-center me-3 mb-sm-3 mb-md-0 mb-xl-3 mb-xxl-0" style="width:32px; height:32px"><span class="text-success-dark" data-feather="dollar-sign" style="width:24px; height:24px"></span></div>
<div>
<p class="fw-bold mb-1">Paid Amount</p>
<h4 class="fw-bolder text-nowrap">${{invoice.amount_paid}}</h4>
</div>
</div>
</div>
<div class="col-sm-auto">
<div class="d-sm-block d-inline-flex d-md-flex flex-xl-column flex-xxl-row align-items-center align-items-xl-start align-items-xxl-center border-start-sm ps-sm-5 border-translucent">
<div class="d-flex bg-primary-subtle rounded flex-center me-3 mb-sm-3 mb-md-0 mb-xl-3 mb-xxl-0" style="width:32px; height:32px"><span class="text-primary-dark" data-feather="layout" style="width:24px; height:24px"></span></div>
<div>
<p class="fw-bold mb-1">Due Amount</p>
<h4 class="fw-bolder text-nowrap">${{invoice.amount_due}} </h4>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- <section> begin ============================-->
<div class="bg-body dark__bg-gray-1100 p-4 mb-4 rounded-2">
<div class="row g-4">
<div class="col-12 col-lg-3">
<div class="row g-4 g-lg-2">
<div class="col-12 col-sm-6 col-lg-12">
<div class="row align-items-center g-0">
<div class="col-auto col-lg-6 col-xl-5">
<h6 class="mb-0 me-3">invoice No :</h6>
</div>
<div class="col-auto col-lg-6 col-xl-7">
<p class="fs-9 text-body-secondary fw-semibold mb-0">#{{invoice.invoice_number}}</p>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-12">
<div class="row align-items-center g-0">
<div class="col-auto col-lg-6 col-xl-5">
<h6 class="me-3">invoice Date :</h6>
</div>
<div class="col-auto col-lg-6 col-xl-7">
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{invoice.created}}</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-5">
<div class="row align-items-center g-0">
<div class="col-auto col-lg-6 col-xl-5">
<h6 class="mb-2 me-3">Customer :</h6>
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{invoice.customer.customer_name}}</p>
</div>
<div class="col-12 col-lg-4">
<h6 class="mb-2"> Email :</h6>
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{invoice.customer.email}}</p>
</div>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4">
<div class="row g-4">
<div class="col-12 col-lg-6">
<h6 class="mb-2"> invoice Status :</h6>
<div class="fs-9 text-body-secondary fw-semibold mb-0">
{% if invoice.invoice_status == 'draft' %}
<span class="badge text-bg-warning">Draft</span>
{% elif invoice.invoice_status == 'in_review' %}
<span class="badge text-bg-info">Sent</span>
{% elif invoice.invoice_status == 'approved' %}
<span class="badge text-bg-success">Approved</span>
{% elif invoice.invoice_status == 'declined' %}
<span class="badge text-bg-danger">Declined</span>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="px-0">
<div class="table-responsive scrollbar">
<table id="invoice-table" class="table fs-9 text-body mb-0">
<thead class="bg-body-secondary">
<tr>
<th scope="col" style="width: 24px;">#</th>
<th scope="col" style="min-width: 260px;">Item</th>
<th scope="col" style="min-width: 60px;">Quantity</th>
<th scope="col" style="min-width: 60px;">Unit Price</th>
<th scope="col" style="min-width: 60px;">Total</th>
</tr>
</thead>
<tbody>
{% for item in invoice.get_itemtxs_data.0 %}
<tr>
<td class="">{{forloop.counter}}</td>
<td class="">{{item.item_model.name}}</td>
<td class="align-middle">{{item.quantity}}</td>
<td class="align-middle ps-5">{{item.unit_cost}}</td>
<td class="align-middle text-body-tertiary fw-semibold">{{item.total_amount}}</td>
</tr>
{% endfor %}
<tr class="bg-body-secondary total-sum">
<td class="align-middle ps-4 fw-bold text-body-highlight" colspan="4">Vat ({{vat}}%)</td>
<td class="align-middle text-start fw-bold">
<span id="grand-total">{{vat_amount}}</span>
</td>
</tr>
<tr class="bg-body-secondary total-sum">
<td class="align-middle ps-4 fw-bold text-body-highlight" colspan="4">Grand Total</td>
<td class="align-middle text-start fw-bold">
<span id="grand-total">{{total}}</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script>
function calculateTotals() {
const table = document.getElementById('estimate-table');
const rows = table.getElementsByTagName('tbody')[0].rows;
let grandTotal = 0;
for (let row of rows) {
// Ensure the row has the expected number of cells
if (row.cells.length >= 5) {
const quantity = parseFloat(row.cells[2].textContent); // Quantity column
const unitPrice = parseFloat(row.cells[3].textContent); // Unit Price column
if (!isNaN(quantity) && !isNaN(unitPrice)) {
const total = quantity * unitPrice;
row.cells[4].textContent = total.toFixed(2); // Populate Total column
grandTotal += total; // Add to grand total
}
}
}
// Display the grand total
document.getElementById('grand-total').textContent = grandTotal.toFixed(2);
}
// Run the function on page load
window.onload = calculateTotals;
</script>
{% endblock %}