Skip to content

Commit

Permalink
Add sample invoice template
Browse files Browse the repository at this point in the history
  • Loading branch information
wadevries committed Apr 26, 2021
1 parent 21d406b commit fc123d7
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 0 deletions.
29 changes: 29 additions & 0 deletions samples/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2011-2021, Simon Sapin and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19 changes: 19 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Sample template

This directory contains a modified version of the 'Invoice'
sample from [WeasyPrint](https://weasyprint.org/samples/) ([source code](https://github.com/Kozea/WeasyPrint/tree/gh-pages/samples/invoice)).

Styling, markup, layout and appearance are all made by WeasyPrint. Please read the
LICENSE contained in this directory.

## Usage

To generate the sample invoice, clone/checkout/download this directory. Then,
to generate an invoice with the invoice date set to 'today':

```shell
pcloadletter --template samples/invoice.html --context-file samples/context.yml date=`date +%Y-%m-%d`
```

This takes some content from [context.yml](context.yml). JSON formatted files are also accepted (as
JSON is a subset of YAML), see [context.json](context.json).
10 changes: 10 additions & 0 deletions samples/context.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"address": " C. Ustomer\nPaystreet 42\n12340 Cashville",
"items": [
{
"description": "Filing TPS Reports",
"price": 85.15,
"quantity": 15.3
}
]
}
13 changes: 13 additions & 0 deletions samples/context.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
address: |
C. Ustomer
Paystreet 42
12340 Cashville
items:
- description: Filing TPS Reports
price: 85.15
quantity: 15.3

- description: Paperclips
price: 0.0025
quantity: 500
128 changes: 128 additions & 0 deletions samples/invoice.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
@charset "UTF-8";
@import url("https://fonts.googleapis.com/css?family=Pacifico|Source+Sans+Pro:400,700");

@page {
margin: 3cm;
@bottom-left {
color: #1ee494;
font-family: Pacifico;
content: '♥ Thank you!';
}
@bottom-right {
color: #a9a;
content: '[email protected] | +33 4 78 84 19 28 | community.kozea.fr';
font-family: Pacifico;
font-size: 9pt;
}
}

html {
color: #14213d;
font-family: Source Sans Pro;
/*font-family: Fira Sans;*/
font-size: 11pt;
line-height: 1.6;
}

html body {
margin: 0;
}

html h1 {
color: #1ee494;
font-family: Pacifico;
font-size: 40pt;
margin: 0;
}

html aside {
display: flex;
margin: 2em 0 4em;
}

html aside address {
font-style: normal;
white-space: pre-line;
}

html aside address#from {
color: #a9a;
flex: 1;
}

html aside address#to {
text-align: right;
}

html dl {
text-align: right;
position: absolute;
right: 0;
top: 0;
}

html dl dt, html dl dd {
display: inline;
margin: 0;
}

html dl dt {
color: #a9a;
}

html dl dt::before {
content: '';
display: block;
}

html dl dt::after {
content: ':';
}

html table {
border-collapse: collapse;
width: 100%;
}

html table th {
border-bottom: .2mm solid #a9a;
color: #a9a;
font-size: 10pt;
font-weight: 400;
padding-bottom: .25cm;
text-transform: uppercase;
}

html table td {
padding-top: 7mm;
}

html table td:last-of-type {
color: #1ee494;
font-weight: bold;
text-align: right;
}

html table th, html table td {
text-align: center;
}

html table th:first-of-type, html table td:first-of-type {
text-align: left;
}

html table th:last-of-type, html table td:last-of-type {
text-align: right;
}

html table#total {
background: #f6f6f6;
border-color: #f6f6f6;
border-style: solid;
border-width: 2cm 3cm;
bottom: 0;
font-size: 20pt;
margin: 0 -3cm;
position: absolute;
width: 18cm;
}
81 changes: 81 additions & 0 deletions samples/invoice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link href="invoice.css" media="print" rel="stylesheet">
<title>Invoice</title>
<meta name="description" content="Invoice demo sample">
<meta name="author" content="Kozea">
</head>

<body>
<h1>Invoice</h1>

<aside>
<address id="from">
P.C. Loadletter
123 Fakestreet
90210 Springfield
</address>

<address id="to">
{% if address is defined -%}
{{ address }}
{%- else -%}
Our awesome developers
From all around the world
Earth
{%- endif -%}
</address>
</aside>

<dl id="informations">
<dt>Invoice number</dt>
<dd>{{ number }}</dd>
<dt>Date</dt>
<dd>{{ date | date('%b %d, %Y') }}</dd>
</dl>

<table>
<thead>
<tr>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
{% set total = namespace(total=0) %}

{% for item in items %}
{% set item_total = item.price * item.quantity %}
{% set total.total = total.total + item_total %}
<tr>
<td>{{ item.description }}</td>
<td>€ {{ item.price }}</td>
<td>{{ item.quantity }}</td>
<td>€ {{ "{:,.2f}".format(item_total) }}</td>
</tr>
{% endfor %}
</tbody>
</table>

<table id="total">
<thead>
<tr>
<th>Due by</th>
<th>Account number</th>
<th>Total due</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ date | add_days(14) | date('%b %d, %Y') }}</td>
<td>132 456 789 012</td>
<td>€ {{ "{:,.2f}".format(total.total) }}</td>
</tr>
</tbody>
</table>
</body>
</html>

0 comments on commit fc123d7

Please sign in to comment.