Browse Source

Add invoice detail view

Fabs 10 years ago
parent
commit
1ba1c4512f

+ 31 - 140
coin/billing/templates/billing/invoice.html

@@ -1,140 +1,31 @@
-{% load static %}
-<html>
-	<head>
-		<title>Facture N°{{ invoice.number }}</title>
-
-		<style>
-		    @page {
-		        size: a4 portrait;
-		        @frame header_frame {          
-		            -pdf-frame-content: header_content;
-		            left: 50pt; width: 512pt; top: 50pt; height: 70pt;
-		        }
-		        @frame content_frame {
-		            left: 50pt; width: 512pt; top: 120pt; height: 632pt;
-		        }
-		        @frame footer_frame { 
-		            -pdf-frame-content: footer_content;
-		            left: 50pt; width: 512pt; top: 772pt; height: 30pt;
-		        }
-		    }
-		    body {
-		    	font-size: 9pt;
-		    }
-		    #coordonnees_illyse {
-		    	font-size:9pt;
-		    }
-		    #coordonnees_client {
-		    	vertical-align: top;
-		    }
-
-		    table#details {
-		    	width:100%;
-		    }
-		    th.cell {border:0px;}
-		    .cell.result {border:0px; font-weight: bold}
-		    .cell { padding:2pt; border:1px solid #DDD; }
-		    .cell.label { width:400pt;}
-		    .cell.quantity {width:50pt;}
-		    .cell.amount {width:50pt;}
-		    .cell.total {width:50pt;}
-
-		    .period {color:#888;}
-
-		    #paiements {
-		    	background-color:#EEE;
-		    	padding:5pt;
-		    	font-size:80%;
-		    }
-		    #page_number {
-		    	float:right;
-		    }
-		</style>
-
-	</head>
-<body>
-	<div id="header_content">
-		<table widht="100%">
-			<tr>
-				<td><img id="logo" src="{% static "billing/invoice_logo.jpg" %}" height="70" /></td>
-				<td><h1>Facture N°{{ invoice.number }}</h1>
-					Le {{ invoice.date }}</td>
-			</tr>
-		</table>		
-	</div>
-	<div id="footer_content">
-		<hr />
-		<table widht="100%">
-			<tr>
-				<td width="50"><img id="logo" src="{% static "billing/invoice_logo.jpg" %}" height="20" /></td>
-				<td>ILLYSE, association loi de 1901 à but non lucratif - SIRET : 539 453 191 00014</td>
-				<td width="20"><pdf:pagenumber>
-					/<pdf:pagecount>
-				</td>
-			</tr>
-		</table>
-	</div>
-	<table>
-		<tr>
-			<td id="coordonnees_illyse">
-				<p>
-				Association ILLYSE<br />
-				c/o Jean-François MOURGUES<br />
-				225 route de Genas<br />
-				69100 Villeurbanne</p>
-				<p>conctact@illyse.org<br/>
-				<a href="http://www.illyse.net">http://www.illyse.net</a></p>
-			</td>
-			<td id="coordonnees_client">
-				<strong>Facturé à :</strong><br/>
-				{{ member.last_name }} {{ member.first_name }}<br />
-				{% if member.organization_name != "" %}{{ member.organization_name }}<br />{% endif %}
-				{{ member.address }}<br />
-				{{ member.postal_code }} {{ member.city}}
-			</td>
-		</tr>
-	</table>
-
-	<hr />
-	Facture N°{{ invoice.number }}
-
-	<table id="details" repeat="1">
-		<thead>
-			<tr>
-				<th class="cell label"></th>
-				<th class="cell quantity">Quantité</th>
-				<th class="cell amount">PU</th>
-				<th class="cell total">Total</th>
-			</tr>
-		</thead>
-		<tbody>
-			{% for detail in invoice.details.all %}
-			<tr>
-				<td class="cell label">{{ detail.label }}
-					{% if detail.period_from and detail.period_to %}<br/><span class="period">Pour la période du {{ detail.period_from }} au {{ detail.period_to }}{% endif %}</span></td>
-				<td class="cell quantity">{{ detail.quantity }}</td>
-				<td class="cell amount">{{ detail.amount }}€</td>
-				<td class="cell total">{{ detail.total }}€</td>
-			</tr>
-			{% endfor %}
-			<tr>
-				<td class="cell result"></td>
-				<td class="cell result total_ttc" colspan="2">Total TTC</td>
-				<td class="cell result invoice_amount">{{ invoice.amount }}€</td>
-			</tr>
-		</tbody>
-	</table>
-	<div id="paiements">
-		<p><strong>Merci de préférer si possible le paiement par virement</strong></p>
-
-		<strong>Virement</strong><br />
-		Titulaire du compte : ILLYSE<br/>
-		RIB : 42559 00012 41020023285 19<br/>
-		IBAN : FR76 4255 9000 1241 0200 2328 519<br />
-
-		<strong>Chèque</strong><br />
-		Paiement par chèque à l'ordre de "Association ILLYSE" envoyé à l'adresse : Association ILLYSE, c/o Jean-François MOURGUES, 225 route de Genas, 69100 Villeurbanne
-	</div>
-
-</body>
-</html>
+{% extends "base.html" %}
+
+{% block content %}
+<h2>Facture N°{{ invoice.number }}</h2>
+<p>Émise le {{ invoice.date }}</p>
+
+<table id="invoice_details" class="full-width">
+    <thead>
+        <tr>
+            <th></th>
+            <th>Quantité</th>
+            <th>PU</th>
+            <th>Total</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for detail in invoice.details.all %}
+        <tr>
+            <td>{{ detail.label }}
+                {% if detail.period_from and detail.period_to %}<br/><span class="period">Pour la période du {{ detail.period_from }} au {{ detail.period_to }}{% endif %}</span></td>
+            <td>{{ detail.quantity }}</td>
+            <td>{{ detail.amount }}€</td>
+            <td>{{ detail.total }}€</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+
+<a href="{% url 'billing:invoice_pdf' id=invoice.number %}" target="_blank" class="button">Télécharger en PDF</a>
+
+{% endblock %}

+ 1 - 0
coin/billing/urls.py

@@ -5,5 +5,6 @@ from coin.billing import views
 urlpatterns = patterns(
     '',
     url(r'^invoice/(?P<id>.+).pdf$', views.invoice_pdf, name="invoice_pdf"),
+    url(r'^invoice/(?P<id>.+).html$', views.invoice_html, name="invoice_html"),
     url('invoice/create_all_members_invoices_for_a_period', views.gen_invoices)
 )

+ 26 - 2
coin/billing/views.py

@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 from django.http import HttpResponse
-from django.shortcuts import render, get_object_or_404
+from django.template import RequestContext
+from django.shortcuts import render, get_object_or_404, render_to_response
 from django.core.exceptions import PermissionDenied
 from coin.billing.models import Invoice
 from coin.members.models import Member
@@ -29,7 +30,7 @@ def invoice_pdf(request, id):
 
     context = {"invoice": invoice, 'member': member}
 
-    pdf = render_as_pdf('billing/invoice.html', context)
+    pdf = render_as_pdf('billing/invoice_pdf.html', context)
 
     response = HttpResponse(content_type='application/pdf')
     #response['Content-Disposition'] = 'attachment; filename="facture.pdf"'
@@ -37,3 +38,26 @@ def invoice_pdf(request, id):
     response.write(pdf)
 
     return response
+
+def invoice_html(request, id):
+    """
+    Renvoi une facture générée en format pdf
+    id peut être soit la pk d'une facture, soit le numero de facture
+    """
+    try:
+        invoice = Invoice.objects.get(pk=id)
+    except:
+        invoice = get_object_or_404(Invoice, number=id)
+
+    if not invoice.has_owner(request.user.username)\
+       and not request.user.is_superuser:
+        raise PermissionDenied
+
+    member = invoice.member
+
+    context = {"invoice": invoice, 'member': member}
+
+    return render_to_response('billing/invoice.html', context,
+                              context_instance=RequestContext(request))
+
+    return response

+ 1 - 10
coin/members/templates/members/invoices.html

@@ -15,7 +15,7 @@
     <tbody>
         {% for invoice in invoices %}
         <tr>
-            <td>{{ invoice.number }}</td>
+            <td><a href="{% url 'billing:invoice_html' id=invoice.number %}">{{ invoice.number }}</a></td>
             <td>{{ invoice.date }}</td>
             <td>{{ invoice.amount }}</td>
             <td><a href="{% url 'billing:invoice_pdf' id=invoice.number %}">PDF</a></td>
@@ -23,14 +23,5 @@
         {% endfor %}
     </tbody>
 </table>
-<!--
-     <div class="panel">
-         <h3>Stats générales ADSL</h3>
-         <a class="button">Voir l'ADSL</a>
-     </div>
-     <div class="panel">
-         <h3>Stats générales VPN</h3>
-         <a class="button">Voir le VPN</a>
-     </div>-->
 
 {% endblock %}

+ 1 - 1
coin/members/views.py

@@ -41,7 +41,7 @@ def invoices(request):
         #TODO: logger: ce cas ne devrait pas exister
         raise Http404
 
-    invoices = member.invoices.all()
+    invoices = member.invoices.all().order_by('-date')
 
     return render_to_response('members/invoices.html',
                               {'invoices':invoices},

+ 6 - 0
coin/static/css/illyse.css

@@ -134,3 +134,9 @@ table.full-width {
     background-position: center top;
     height:50px;
 }
+
+
+/* Invoice */
+#invoice_details .period {
+    color:#999;
+}

+ 2 - 2
coin/templates/base.html

@@ -46,7 +46,7 @@
         </ul>
     </aside>
 
-    
+
     <div id="footer">
         {% block footer %}
         <div class="row">
@@ -56,7 +56,7 @@
         </div>
         {% endblock %}
     </div>
-    
+
 
     <script src="{% static "js/vendor/jquery.js" %}"></script>
     <script src="{% static "js/foundation.min.js" %}"></script>