add bill transaction table
This commit is contained in:
parent
c94c0e0de4
commit
02885f2e5b
@ -1,10 +1,13 @@
|
||||
from typing import Union
|
||||
from random import randint
|
||||
from django import template
|
||||
from calendar import month_abbr
|
||||
from django.urls import reverse
|
||||
from calendar import month_abbr
|
||||
from django.conf import settings
|
||||
from django.forms import ValidationError
|
||||
from django.utils.formats import number_format
|
||||
from django_ledger.io.io_core import get_localdate,validate_activity
|
||||
from django.conf import settings
|
||||
from django_ledger.models import InvoiceModel, JournalEntryModel, BillModel
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@ -390,3 +393,28 @@ def bill_item_formset_table(context, item_formset):
|
||||
'total_amount__sum': context['total_amount__sum'],
|
||||
'item_formset': item_formset,
|
||||
}
|
||||
|
||||
@register.inclusion_tag('bill/transactions/tags/txs_table.html')
|
||||
def transactions_table(object_type: Union[JournalEntryModel, BillModel, InvoiceModel], style='detail'):
|
||||
if isinstance(object_type, JournalEntryModel):
|
||||
transaction_model_qs = object_type.transactionmodel_set.all().with_annotated_details().order_by(
|
||||
'-timestamp')
|
||||
elif isinstance(object_type, BillModel):
|
||||
transaction_model_qs = object_type.get_transaction_queryset(annotated=True).order_by('-timestamp')
|
||||
elif isinstance(object_type, InvoiceModel):
|
||||
transaction_model_qs = object_type.get_transaction_queryset(annotated=True).order_by('-timestamp')
|
||||
else:
|
||||
raise ValidationError(
|
||||
'Cannot handle object of type {} to get transaction model queryset'.format(type(object_type))
|
||||
)
|
||||
|
||||
total_credits = sum(tx.amount for tx in transaction_model_qs if tx.is_credit())
|
||||
total_debits = sum(tx.amount for tx in transaction_model_qs if tx.is_debit())
|
||||
|
||||
return {
|
||||
'style': style,
|
||||
'transaction_model_qs': transaction_model_qs,
|
||||
'total_debits': total_debits,
|
||||
'total_credits': total_credits,
|
||||
'object': object_type
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
{% load django_ledger %}
|
||||
{% load custom_filters %}
|
||||
|
||||
{% block title %}Bill Details - {{ block.super }}{% endblock %}
|
||||
|
||||
@ -64,7 +65,7 @@
|
||||
<div class="border rounded p-3">
|
||||
<h6 class="text-uppercase text-xs text-muted mb-2">
|
||||
{% trans 'Cash Account' %}:
|
||||
<a href="{% url 'django_ledger:account-detail' account_pk=bill.cash_account.uuid coa_slug=bill.cash_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
|
||||
<a href="{% url 'account_detail' bill.cash_account.uuid %}"
|
||||
class="text-decoration-none ms-1">
|
||||
{{ bill.cash_account.code }}
|
||||
</a>
|
||||
@ -79,7 +80,7 @@
|
||||
<div class="border rounded p-3">
|
||||
<h6 class="text-uppercase text-xs text-muted mb-2">
|
||||
{% trans 'Prepaid Account' %}:
|
||||
<a href="{% url 'django_ledger:account-detail' account_pk=bill.prepaid_account.uuid coa_slug=bill.prepaid_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
|
||||
<a href="{% url 'account_detail' bill.prepaid_account.uuid %}"
|
||||
class="text-decoration-none ms-1">
|
||||
{{ bill.prepaid_account.code }}
|
||||
</a>
|
||||
@ -93,7 +94,7 @@
|
||||
<div class="border rounded p-3">
|
||||
<h6 class="text-uppercase text-xs text-muted mb-2">
|
||||
{% trans 'Accounts Payable' %}:
|
||||
<a href="{% url 'django_ledger:account-detail' account_pk=bill.unearned_account.uuid coa_slug=bill.unearned_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
|
||||
<a href="{% url 'account_detail' bill.unearned_account.uuid %}"
|
||||
class="text-decoration-none ms-1">
|
||||
{{ bill.unearned_account.code }}
|
||||
</a>
|
||||
|
||||
73
templates/bill/transactions/tags/txs_table.html
Normal file
73
templates/bill/transactions/tags/txs_table.html
Normal file
@ -0,0 +1,73 @@
|
||||
{% load i18n %}
|
||||
{% load django_ledger %}
|
||||
|
||||
{% if style == 'detail' %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>{% trans 'Timestamp' %}</th>
|
||||
<th>{% trans 'Account' %}</th>
|
||||
<th>{% trans 'Account Name' %}</th>
|
||||
<th>{% trans 'Unit' %}</th>
|
||||
<th>{% trans 'Credit' %}</th>
|
||||
<th>{% trans 'Debit' %}</th>
|
||||
<th>{% trans 'Description' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for transaction_model in transaction_model_qs %}
|
||||
<tr>
|
||||
<td>{{ transaction_model.timestamp }}</td>
|
||||
<td>{{ transaction_model.account_code }}</td>
|
||||
<td>{{ transaction_model.account_name }}</td>
|
||||
<td>{% if transaction_model.entity_unit_name %}{{ transaction_model.entity_unit_name }}{% endif %}</td>
|
||||
<td>{% if transaction_model.is_credit %}${{ transaction_model.amount | currency_format }}{% endif %}</td>
|
||||
<td>{% if transaction_model.is_debit %}${{ transaction_model.amount | currency_format }}{% endif %}</td>
|
||||
<td>{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="fw-bold">
|
||||
<td colspan="3"></td>
|
||||
<td class="text-end">{% trans 'Total' %}</td>
|
||||
<td>{% currency_symbol %}{{ total_credits | currency_format }}</td>
|
||||
<td>{% currency_symbol %}{{ total_debits | currency_format }}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% elif style == 'compact' %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-bordered table-hover">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>{% trans 'Account' %}</th>
|
||||
<th>{% trans 'Account Name' %}</th>
|
||||
<th>{% trans 'Credit' %}</th>
|
||||
<th>{% trans 'Debit' %}</th>
|
||||
<th>{% trans 'Description' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for transaction_model in transaction_model_qs %}
|
||||
<tr>
|
||||
<td>{{ transaction_model.account_code }}</td>
|
||||
<td>{{ transaction_model.account_name }}</td>
|
||||
<td>{% if transaction_model.is_credit %}${{ transaction_model.amount | currency_format }}{% endif %}</td>
|
||||
<td>{% if transaction_model.is_debit %}${{ transaction_model.amount | currency_format }}{% endif %}</td>
|
||||
<td>{% if transaction_model.description %}{{ transaction_model.description }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr class="fw-bold">
|
||||
<td colspan="1"></td>
|
||||
<td class="text-end">{% trans 'Total' %}</td>
|
||||
<td>{% currency_symbol %}{{ total_credits | currency_format }}</td>
|
||||
<td>{% currency_symbol %}{{ total_debits | currency_format }}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@ -38,7 +38,14 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'purchase_order_list' %}">
|
||||
<div class="d-flex align-items-center">
|
||||
<span class="nav-link-icon"><span class="fas fa-plus-circle"></span></span><span class="nav-link-text">{% trans "purchase Orders"|capfirst %}</span>
|
||||
<span class="nav-link-icon"><span class="fas fa-warehouse"></span></span><span class="nav-link-text">{% trans "purchase Orders"|capfirst %}</span>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'upload_cars' %}">
|
||||
<div class="d-flex align-items-center">
|
||||
<span class="nav-link-icon"><span class="fas fa-file-invoice"></span></span><span class="nav-link-text">{% trans "Upload Cars"|capfirst %}</span>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -145,6 +145,10 @@
|
||||
hx-on::after-request="filter_after_request()">{{ _("Search") }}</button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<form class="update-price-form d-flex flex-row align-items-center ms-auto w-25 d-none" action="" method="post" style="float:right;">
|
||||
<input class="form-control me-2" type="number" placeholder='{{ _("Search") }}' name="price" aria-label="Price">
|
||||
<button class="btn btn-outline-primary" type="submit">{{ _("Search") }}</button>
|
||||
</form>
|
||||
<div class="table-responsive scrollbar transition">
|
||||
<div class="d-flex flex-wrap align-items-center justify-content-between py-3 pe-0 fs-9">
|
||||
<div class="d-flex"
|
||||
@ -160,6 +164,11 @@
|
||||
<table class="table align-items-center table-flush">
|
||||
<thead class="text-body">
|
||||
<tr class="bg-body-highlight">
|
||||
<th class="sort white-space-nowrap align-middle" scope="col">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="select-all" />
|
||||
</div>
|
||||
</th>
|
||||
<th class="sort white-space-nowrap align-middle" scope="col">{{ _("VIN") }}</th>
|
||||
<th class="sort white-space-nowrap align-middle" scope="col">{{ _("Make") }}</th>
|
||||
<th class="sort white-space-nowrap align-middle" scope="col">{{ _("Model") }}</th>
|
||||
@ -174,7 +183,12 @@
|
||||
</thead>
|
||||
<tbody class="list" id="project-list-table-body">
|
||||
{% for car in cars %}
|
||||
<tr class="position-static">
|
||||
<tr class="position-static">
|
||||
<td class="align-middle white-space-nowrap">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input car-checkbox" type="checkbox" name="car" id="car-{{car.pk}}">
|
||||
</div>
|
||||
</td>
|
||||
<td class="align-middle white-space-nowrap ps-1">
|
||||
<a class="fw-bold" href="{% url 'car_detail' car.slug %}">{{ car.vin }}</a>
|
||||
</td>
|
||||
@ -297,5 +311,20 @@
|
||||
document.querySelector('.car_status').removeAttribute('disabled')
|
||||
}
|
||||
|
||||
document.getElementById('select-all').addEventListener('change', function() {
|
||||
const checkboxes = document.querySelectorAll('#project-list-table-body input[type="checkbox"]');
|
||||
checkboxes.forEach(checkbox => {
|
||||
checkbox.checked = this.checked;
|
||||
});
|
||||
});
|
||||
document.getElementById('car-checkbox').addEventListener('change', function() {
|
||||
const form = document.querySelector('.update-price-form');
|
||||
if (this.checked) {
|
||||
form.classList.remove('d-none');
|
||||
} else {
|
||||
form.classList.add('d-none');
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endblock customJS %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user