diff --git a/clients/urls.py b/clients/urls.py index 120525e..7287373 100644 --- a/clients/urls.py +++ b/clients/urls.py @@ -1,5 +1,11 @@ from django.urls import path -from clients.views import ClientListView, ClientView, ClientAddView, ClientEditView, ClientDeleteView +from clients.views import (ClientListView, + ClientView, + ClientAddView, + ClientEditView, + ClientDeleteView, + ClientInvoice + ) urlpatterns = [ @@ -8,4 +14,5 @@ path('client/add/', ClientAddView.as_view(), name='client_add'), path('client/edit//', ClientEditView.as_view(), name='client_edit'), path('client/delete//', ClientDeleteView.as_view(), name='client_delete'), + path('client/invoice//', ClientInvoice.as_view(), name='client_invoice') ] \ No newline at end of file diff --git a/clients/views.py b/clients/views.py index 3c346f0..0261507 100644 --- a/clients/views.py +++ b/clients/views.py @@ -1,9 +1,10 @@ import time +from django.core import serializers from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib import messages from django.db.models import Q -from django.http import Http404 +from django.http import Http404, JsonResponse from django.shortcuts import render, redirect, get_object_or_404 from django.views.generic import TemplateView from django.views import View @@ -25,14 +26,45 @@ def get(self, *args, **kwargs): """displaying the data of clients """ context = {} - clients = Client.objects.filter(company=self.request.user.company, archive=False).order_by('-date_updated') + clients = Client.objects.filter(company=self.request.user.company, + archive=False + ).order_by('-date_updated') + + client_invoices = [Invoice.objects.filter(client=client, + company=self.request.user.company + ) for client in clients] + + invoices = Invoice.objects.filter(company=self.request.user.company) query = self.request.GET.get("q") if query: - clients = clients.filter(display_name__icontains=query, archive=False).order_by('-date_updated') - context['clients'] = clients + clients = clients.filter(display_name__icontains=query, + archive=False + ).order_by('-date_updated') + context['clients'] = clients + context['invoices'] = invoices + context['client_invoices'] = client_invoices return render(self.request, self.template_name, context) +class ClientInvoice(View): + """ Display invoices of client + """ + def get(self, *args, **kwargs): + client = get_object_or_404(Client, id=kwargs['client_id']) + + invoices = Invoice.objects.filter(client=client,company=self.request.user.company,) + data = serializers.serialize('json', invoices) + + return JsonResponse({'invoices': data, + 'prefix': client.prefix, + 'get_prefix' : client.get_prefix(), + }, + safe = False, + status=200 + ) + + + class ClientView(UserIsOwnerMixin,TemplateView): """ Display client information """ diff --git a/templates/base.html b/templates/base.html index d85cace..7c56509 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,7 +22,7 @@ @@ -108,5 +108,11 @@ + +{% block js %} +{% endblock %} + + + \ No newline at end of file diff --git a/templates/clients/all_client.html b/templates/clients/all_client.html index 86042ea..c1c706a 100644 --- a/templates/clients/all_client.html +++ b/templates/clients/all_client.html @@ -4,53 +4,163 @@ {% block content_auth %} {% if messages %} - +
+
    + {% for message in messages %} + {{ message }} + × + {% endfor %} +
+
{% endif %} -
- - -
ADD
-
- - - - - - - - - - - - - - - - - {% for client in clients %} - - - - - - - - - - - {% endfor %} - -
CompanyEmailFull NameMobileDate CreatedInvoiceEditDelete
- -    - {{ client.client_company|title }} - {{ client.email }}{{ client.full_name|title }}{{ client.mobile }}{{ client.date_created|date:"F d, Y" }}make an invoiceEditDelete
-{% endblock %} \ No newline at end of file +
+
ADD
+
+ + + + + + + + + + + + + + {% for client in clients %} + + + + + + + + + + {% endfor %} + +
CompanyEmailFull NameMobileDate CreatedEditDelete
+ + +    + + {{ client.client_company|title }} + + + {{ client.email }}{{ client.full_name|title }}{{ client.mobile }}{{ client.date_created|date:"F d, Y" }}EditDelete
+ + + + + +{% endblock %} + +{% block js %} + +{% endblock %}