218 lines
13 KiB
HTML
218 lines
13 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 'estimate_mark_as' estimate.pk %}?mark=approved" 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="row-small mt-3">
|
|
<div class="d-flex justify-content-between align-items-end mb-4 mx-3">
|
|
<h2 class="mb-0">{% trans 'Estimate' %}</h2>
|
|
<div class="d-flex align-items-center gap-2">
|
|
{% if estimate.status == 'draft' %}
|
|
<a href="{% url 'send_email' estimate.pk %}" class="btn btn-phoenix-primary me-2"><span class="fa-regular fa-paper-plane me-sm-2"></span><span class="d-none d-sm-inline-block">{% trans 'Send Estimate' %}</span></a>
|
|
<button id="mark_as_sent_estimate" class="btn btn-phoenix-secondary" onclick="setFormAction('review')" data-bs-toggle="modal" data-bs-target="#confirmModal"><span class="d-none d-sm-inline-block">{% trans 'Mark As Sent' %}</span></button>
|
|
{% elif estimate.status == 'in_review' %}
|
|
<button id="accept_estimate" onclick="setFormAction('approved')" class="btn btn-phoenix-secondary" data-bs-toggle="modal" data-bs-target="#confirmModal"><span class="d-none d-sm-inline-block">{% trans 'Mark As Accept' %}</span></button>
|
|
{% elif estimate.status == 'approved' %}
|
|
{% if estimate.sale_orders.first %}
|
|
<a href="{% url 'invoice_create' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Create Invoice' %}</span></a>
|
|
{% else %}
|
|
<a href="{% url 'create_sale_order' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Create Sale Order' %}</span></a>
|
|
{% comment %} <a href="{% url 'preview_sale_order' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Preview Sale Order' %}</span></a> {% endcomment %}
|
|
{% endif %}
|
|
{% elif estimate.status == 'in_review' %}
|
|
<a href="{% url 'estimate_preview' estimate.pk %}" class="btn btn-phoenix-primary"><span class="d-none d-sm-inline-block">{% trans 'Preview' %}</span></a>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
<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">{% trans 'Estimate Number' %} :</h6>
|
|
</div>
|
|
<div class="col-auto col-lg-6 col-xl-7">
|
|
<p class="fs-9 text-body-secondary fw-semibold mb-0">#{{estimate.estimate_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">{% trans 'Estimate Date' %} :</h6>
|
|
</div>
|
|
<div class="col-auto col-lg-6 col-xl-7">
|
|
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{estimate.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">{% trans 'Customer' %} :</h6>
|
|
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{estimate.customer.customer_name}}</p>
|
|
</div>
|
|
<div class="col-12 col-lg-4">
|
|
<h6 class="mb-2"> {% trans 'Email' %} :</h6>
|
|
<p class="fs-9 text-body-secondary fw-semibold mb-0">{{estimate.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"> {% trans "Estimate Status" %} :</h6>
|
|
<div class="fs-9 text-body-secondary fw-semibold mb-0">
|
|
{% if estimate.status == 'draft' %}
|
|
<span class="badge text-bg-warning">{% trans "Draft" %}</span>
|
|
{% elif estimate.status == 'in_review' %}
|
|
<span class="badge text-bg-info">{% trans "In Review" %}</span>
|
|
{% elif estimate.status == 'approved' %}
|
|
<span class="badge text-bg-success">{% trans "Approved" %}</span>
|
|
{% elif estimate.status == 'completed' %}
|
|
<span class="badge text-bg-success">{% trans "completed" %}</span>
|
|
{% elif estimate.status == 'canceled' %}
|
|
<span class="badge text-bg-danger">{% trans "canceled" %}</span>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="px-0">
|
|
<div class="table-responsive scrollbar">
|
|
<table id="estimate-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;">{% trans "Make" %}</th>
|
|
<th scope="col" style="min-width: 260px;">{% trans "Model" %}</th>
|
|
<th scope="col" style="min-width: 260px;">{% trans "Year" %}</th>
|
|
<th scope="col" style="min-width: 60px;">{% trans "Quantity" %}</th>
|
|
<th scope="col" style="min-width: 60px;">{% trans "Unit Price" %}</th>
|
|
<th scope="col" style="min-width: 60px;">{% trans "Total" %}</th>
|
|
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for item in data.cars %}
|
|
<tr>
|
|
<td class="align-middle"></td>
|
|
<td class="align-middle">{{item.make}}</td>
|
|
<td class="align-middle">{{item.model}}</td>
|
|
<td class="align-middle">{{item.year}}</td>
|
|
<td class="align-middle">{{item.quantity}}</td>
|
|
<td class="align-middle ps-5">{{item.unit_price}}</td>
|
|
<td class="align-middle text-body-tertiary fw-semibold">{{item.total}}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
<tr class="bg-body-secondary total-sum">
|
|
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Vat" %} ({{data.vat}}%)</td>
|
|
<td class="align-middle text-start fw-semibold">
|
|
<span id="grand-total">+ {{data.total_vat_amount}}</span>
|
|
</td>
|
|
</tr>
|
|
<tr class="bg-body-secondary total-sum">
|
|
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Discount Amount" %}</td>
|
|
<td class="align-middle text-start text-danger fw-semibold ">
|
|
<span id="grand-total">- {{data.total_discount}}</span>
|
|
</td>
|
|
</tr>
|
|
<tr class="bg-body-secondary total-sum">
|
|
<td class="align-middle ps-4 fw-semibold text-body-highlight" colspan="6">{% trans "Additional Services" %}</td>
|
|
<td class="align-middle text-start fw-semibold">
|
|
{% for service in data.additionals %}
|
|
<small><span class="fw-semibold">+ {{service.name}} - {{service.total}}</span></small><br>
|
|
{% endfor %}
|
|
</td>
|
|
</tr>
|
|
<tr class="bg-body-secondary total-sum">
|
|
<td class="align-middle ps-4 fw-bolder text-body-highlight" colspan="6">{% trans "Grand Total" %}</td>
|
|
<td class="align-middle text-start fw-bolder">
|
|
<span id="grand-total">{{data.grand_total}}</span>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- end of .row-->
|
|
|
|
</section>
|
|
<!-- <section> close ============================-->
|
|
<!-- ============================================-->
|
|
{% endblock %}
|
|
|
|
{% block customJS %}
|
|
<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;
|
|
|
|
function setFormAction(action) {
|
|
// Get the form element
|
|
const form = document.getElementById('confirmForm');
|
|
// Set the form action with the query parameter
|
|
form.action = "{% url 'estimate_mark_as' estimate.pk %}?mark=" + action;
|
|
}
|
|
</script>
|
|
|
|
{% endblock %} |