Added invoice paperwork functionality

This commit is contained in:
David Taylor
2015-05-22 15:20:43 +01:00
parent 0b787aeb33
commit 095d17c703
5 changed files with 204 additions and 88 deletions

View File

@@ -1,10 +1,16 @@
import cStringIO as StringIO
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.db import connection from django.db import connection
from django.http import Http404, HttpResponseRedirect from django.http import Http404, HttpResponseRedirect
from django.views import generic from django.views import generic
from django.template import RequestContext
from django.template.loader import get_template
from django.http import HttpResponse
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.contrib import messages from django.contrib import messages
import datetime import datetime
from z3c.rml import rml2pdf
from RIGS import models from RIGS import models
@@ -33,6 +39,34 @@ class InvoiceIndex(generic.ListView):
class InvoiceDetail(generic.DetailView): class InvoiceDetail(generic.DetailView):
model = models.Invoice model = models.Invoice
class InvoicePrint(generic.View):
def get(self, request, pk):
invoice = get_object_or_404(models.Invoice, pk=pk)
object = invoice.event
template = get_template('RIGS/event_print.xml')
copies = ('TEC', 'Client')
context = RequestContext(request, {
'object': object,
'fonts': {
'opensans': {
'regular': 'RIGS/static/fonts/OPENSANS-REGULAR.TTF',
'bold': 'RIGS/static/fonts/OPENSANS-BOLD.TTF',
}
},
'invoice':invoice,
})
rml = template.render(context)
buffer = StringIO.StringIO()
buffer = rml2pdf.parseString(rml)
pdfData = buffer.read()
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = "filename=Invoice %05d | %s.pdf" % (invoice.pk, object.name)
response.write(pdfData)
return response
class InvoiceVoid(generic.View): class InvoiceVoid(generic.View):
def get(self, *args, **kwargs): def get(self, *args, **kwargs):

View File

@@ -22,17 +22,25 @@
<paraStyle name="style.Heading2" fontName="OpenSans-Bold" fontSize="10" spaceAfter="2"/> <paraStyle name="style.Heading2" fontName="OpenSans-Bold" fontSize="10" spaceAfter="2"/>
<paraStyle name="style.Heading3" fontName="OpenSans" fontSize="10" spaceAfter="0"/> <paraStyle name="style.Heading3" fontName="OpenSans" fontSize="10" spaceAfter="0"/>
<paraStyle name="center" alignment="center"/> <paraStyle name="center" alignment="center"/>
<paraStyle name="invoice-head" alignment="center" fontName="OpenSans-Bold" fontSize="16" leading="18" spaceAfter="0"/>
<paraStyle name="style.event_description" fontName="OpenSans" textColor="DarkGray" /> <paraStyle name="style.event_description" fontName="OpenSans" textColor="DarkGray" />
<paraStyle name="style.item_description" fontName="OpenSans" textColor="DarkGray" leftIndent="10" /> <paraStyle name="style.item_description" fontName="OpenSans" textColor="DarkGray" leftIndent="10" />
<paraStyle name="style.specific_description" fontName="OpenSans" textColor="DarkGray" fontSize="10" /> <paraStyle name="style.specific_description" fontName="OpenSans" textColor="DarkGray" fontSize="10" />
<paraStyle name="style.times" fontName="OpenSans" fontSize="10" /> <paraStyle name="style.times" fontName="OpenSans" fontSize="10" />
<paraStyle name="style.invoice_titles" fontName="OpenSans-Bold" fontSize="10" />
<paraStyle name="style.invoice_numbers" fontName="OpenSans" fontSize="10" />
<blockTableStyle id="eventSpecifics"> <blockTableStyle id="eventSpecifics">
<blockValign value="top"/> <blockValign value="top"/>
<lineStyle kind="LINEAFTER" colorName="LightGrey" start="0,0" stop="1,0" thickness="1"/> <lineStyle kind="LINEAFTER" colorName="LightGrey" start="0,0" stop="1,0" thickness="1"/>
</blockTableStyle> </blockTableStyle>
<blockTableStyle id="invoiceLayout">
<blockValign value="top"/>
</blockTableStyle>
<blockTableStyle id="eventDetails"> <blockTableStyle id="eventDetails">
<blockValign value="top"/> <blockValign value="top"/>
<blockTopPadding start="0,0" stop="-1,0" length="0"/> <blockTopPadding start="0,0" stop="-1,0" length="0"/>
@@ -91,7 +99,7 @@
<setFont name="OpenSans" size="10" /> <setFont name="OpenSans" size="10" />
<drawCenteredString x="302.5" y="50">[{{ copy }} Copy]</drawCenteredString> {% if not invoice %}<drawCenteredString x="302.5" y="50">[{{ copy }} Copy]</drawCenteredString>{% endif %}
<drawCenteredString x="302.5" y="38">[Page <pageNumber/> of <getName id="lastPage" default="0" />]</drawCenteredString> <drawCenteredString x="302.5" y="38">[Page <pageNumber/> of <getName id="lastPage" default="0" />]</drawCenteredString>
</pageGraphics> </pageGraphics>
@@ -101,7 +109,7 @@
<pageTemplate id="Main"> <pageTemplate id="Main">
<pageGraphics> <pageGraphics>
<setFont name="OpenSans" size="10"/> <setFont name="OpenSans" size="10"/>
<drawCenteredString x="302.5" y="50">[{{ copy }} Copy]</drawCenteredString> {% if not invoice %}<drawCenteredString x="302.5" y="50">[{{ copy }} Copy]</drawCenteredString>{% endif %}
<drawCenteredString x="302.5" y="38">[Page <pageNumber/> of <getName id="lastPage" default="0" />]</drawCenteredString> <drawCenteredString x="302.5" y="38">[Page <pageNumber/> of <getName id="lastPage" default="0" />]</drawCenteredString>
</pageGraphics> </pageGraphics>
<frame id="main" x1="50" y1="65" width="495" height="727"/> <frame id="main" x1="50" y1="65" width="495" height="727"/>

View File

@@ -1,16 +1,59 @@
<setNextFrame name="main"/> <setNextFrame name="main"/>
<nextFrame/> <nextFrame/>
{% if invoice %}
<blockTable style="invoiceLayout" colWidths="330,165">
<tr>
<td>
{% endif %}
<h1><b>N{{ object.pk|stringformat:"05d" }}:</b> '{{ object.name }}'<small></small></h1> <h1><b>N{{ object.pk|stringformat:"05d" }}:</b> '{{ object.name }}'<small></small></h1>
<para style="style.event_description"> <para style="style.event_description">
<b>{{object.start_date|date:"D jS N Y"}}</b> <b>{{object.start_date|date:"D jS N Y"}}</b>
</para> </para>
<keepInFrame maxHeight="30"> <keepInFrame maxHeight="30">
<para style="style.event_description"> <para style="style.event_description">
{{ object.description|default_if_none:""|linebreaks }} {{ object.description|default_if_none:""|linebreaks }}
</para> </para>
</keepInFrame> </keepInFrame>
{% if invoice %}
</td>
<td>
<para style="invoice-head">INVOICE</para>
<spacer length="10"/>
<blockTable style="eventDetails" colWidths="100,175">
<tr>
<td><para style="invoice_titles">Invoice Number</para></td>
<td>
<para style="invoice_numbers">{{ invoice.pk|stringformat:"05d" }}</para>
</td>
</tr>
<tr>
<td><para style="invoice_titles">Invoice Date</para></td>
<td>
<para style="invoice_numbers">{{ invoice.invoice_date|date:"d/m/Y" }}</para>
</td>
</tr>
<tr>
<td><para style="invoice_titles">PO Number</para></td>
<td>
<para style="invoice_numbers">{{ object.purchase_order|default_if_none:"" }}hello</para>
</td>
</tr>
</blockTable>
</td>
</tr>
</blockTable>
{% endif %}
<spacer length="15"/> <spacer length="15"/>
<blockTable style="eventSpecifics" colWidths="165,165,165"> <blockTable style="eventSpecifics" colWidths="165,165,165">
<tr> <tr>
@@ -18,7 +61,15 @@
<h2>Hirer</h2> <h2>Hirer</h2>
<h3>{{ object.person.name }}</h3> <h3>{{ object.person.name }}</h3>
<h3>{{ object.organisation.name|default_if_none:"" }}</h3> <h3>{{ object.organisation.name|default_if_none:"" }}</h3>
{% if invoice %}
<keepInFrame>
{% if object.organisation.address %}
<para style="specific_description">{{ object.organisation.address|default_if_none:""|linebreaksbr }}</para>
{% elif object.person.address %}
<para style="specific_description">{{ object.person.address|default_if_none:""|linebreaksbr }}</para>
{% endif %}
</keepInFrame>
{% endif %}
<keepInFrame> <keepInFrame>
{% if object.person.phone %} {% if object.person.phone %}
<para style="specific_description">{{ object.person.phone }}</para> <para style="specific_description">{{ object.person.phone }}</para>
@@ -27,19 +78,29 @@
{% endif %} {% endif %}
</keepInFrame> </keepInFrame>
<keepInFrame> <keepInFrame>
{% if invoice %}
{% if object.organisation.email %}
<para style="specific_description">{{ object.organisation.email }}</para>
{% elif object.person.email %}
<para style="specific_description">{{ object.person.email }}</para>
{% endif %}
{% else %}
{% if object.person.email %} {% if object.person.email %}
<para style="specific_description">{{ object.person.email }}</para> <para style="specific_description">{{ object.person.email }}</para>
{% elif object.organisation.email %} {% elif object.organisation.email %}
<para style="specific_description">{{ object.organisation.email }}</para> <para style="specific_description">{{ object.organisation.email }}</para>
{% endif %} {% endif %}
{% endif %}
</keepInFrame> </keepInFrame>
</td> </td>
<td> <td>
<h2>Venue</h2> <h2>Venue</h2>
<h3>{{ object.venue.name }}</h3> <h3>{{ object.venue.name }}</h3>
{% if not invoice %}
<keepInFrame> <keepInFrame>
<para style="specific_description">{{ object.venue.address|default_if_none:""|linebreaks }}</para> <para style="specific_description">{{ object.venue.address|default_if_none:""|linebreaks }}</para>
</keepInFrame> </keepInFrame>
{% endif %}
</td> </td>
<td rightPadding="0"> <td rightPadding="0">
@@ -61,7 +122,7 @@
</para> </para>
</td> </td>
</tr> </tr>
{% if object.access_at %} {% if object.access_at and not invoice%}
<tr> <tr>
<td leftPadding="0"><h3>Access</h3></td> <td leftPadding="0"><h3>Access</h3></td>
<td> <td>
@@ -139,9 +200,11 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<para> <para>
<b>The full hire fee is payable at least 10 days before the event.</b> <b>The full hire fee is payable at least 10 days before the event.</b>
</para> </para>
</td> </td>
<td> <td>
<para> <para>
@@ -156,6 +219,7 @@
</tr> </tr>
</blockTable> </blockTable>
</keepTogether> </keepTogether>
{% if not invoice %}
<keepTogether> <keepTogether>
<blockTable style="infoTable"> <blockTable style="infoTable">
<tr> <tr>
@@ -240,4 +304,5 @@
{% include "RIGS/event_print_signature.xml" %} {% include "RIGS/event_print_signature.xml" %}
</keepTogether> </keepTogether>
{% endif %}
<namedString id="lastPage"><pageNumber/></namedString> <namedString id="lastPage"><pageNumber/></namedString>

View File

@@ -10,9 +10,15 @@
</div> </div>
<div class="col-sm-4 text-right"> <div class="col-sm-4 text-right">
<div class="btn-group btn-page">
<a href="{% url 'invoice_void' object.pk %}" class="btn btn-default" title="Void Invoice"> <a href="{% url 'invoice_void' object.pk %}" class="btn btn-default" title="Void Invoice">
<span class="glyphicon glyphicon-ban-circle"></span> <span class="glyphicon glyphicon-ban-circle"></span> <span
class="hidden-xs">Void</span>
</a> </a>
<a href="{% url 'invoice_print' object.pk %}" target="_blank" class="btn btn-default"><span
class="glyphicon glyphicon-print"></span> <span
class="hidden-xs">Print</span></a>
</div>
</div> </div>
</div> </div>

View File

@@ -99,6 +99,9 @@ urlpatterns = patterns('',
url(r'^invoice/(?P<pk>\d+)/$', url(r'^invoice/(?P<pk>\d+)/$',
permission_required_with_403('RIGS.view_invoice')(finance.InvoiceDetail.as_view()), permission_required_with_403('RIGS.view_invoice')(finance.InvoiceDetail.as_view()),
name='invoice_detail'), name='invoice_detail'),
url(r'^invoice/(?P<pk>\d+)/print/$',
permission_required_with_403('RIGS.view_invoice')(finance.InvoicePrint.as_view()),
name='invoice_print'),
url(r'^invoice/(?P<pk>\d+)/void/$', url(r'^invoice/(?P<pk>\d+)/void/$',
permission_required_with_403('RIGS.change_invoice')(finance.InvoiceVoid.as_view()), permission_required_with_403('RIGS.change_invoice')(finance.InvoiceVoid.as_view()),
name='invoice_void'), name='invoice_void'),