feat: better PDF
This commit is contained in:
BIN
index.html
BIN
index.html
Binary file not shown.
@@ -1,6 +1,9 @@
|
|||||||
package issue
|
package issue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
@@ -10,3 +13,23 @@ type Issue struct {
|
|||||||
gitea.Issue
|
gitea.Issue
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i Issue) Shorthand() string {
|
||||||
|
str := i.Repository.Name
|
||||||
|
if strings.Contains(str, "-") {
|
||||||
|
s := strings.Split(str, "-")
|
||||||
|
str = s[len(s)-1]
|
||||||
|
} else if len(str) > 3 {
|
||||||
|
str = str[:3]
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s-%d", strings.ToUpper(str), i.Index)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Issue) CleanBody() string {
|
||||||
|
reBlock := regexp.MustCompile("(?s)```info(.*?)```(.*)")
|
||||||
|
block := reBlock.FindStringSubmatch(i.Body)
|
||||||
|
if len(block) < 3 {
|
||||||
|
return i.Body
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(block[2])
|
||||||
|
}
|
||||||
|
|||||||
17
main.go
17
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"git.schreifuchs.ch/lou-taylor/accounting/issue"
|
"git.schreifuchs.ch/lou-taylor/accounting/issue"
|
||||||
|
"git.schreifuchs.ch/lou-taylor/accounting/model"
|
||||||
"git.schreifuchs.ch/lou-taylor/accounting/pdf"
|
"git.schreifuchs.ch/lou-taylor/accounting/pdf"
|
||||||
"git.schreifuchs.ch/lou-taylor/accounting/report"
|
"git.schreifuchs.ch/lou-taylor/accounting/report"
|
||||||
)
|
)
|
||||||
@@ -57,10 +58,10 @@ func main() {
|
|||||||
issues := issue.FromGiteas(is, time.Minute*15)
|
issues := issue.FromGiteas(is, time.Minute*15)
|
||||||
r := report.New(
|
r := report.New(
|
||||||
issues,
|
issues,
|
||||||
report.Entity{
|
model.Entity{
|
||||||
Name: "schreifuchs.ch",
|
Name: "schreifuchs.ch",
|
||||||
IBAN: "CH06 0079 0042 5877 0443 7",
|
IBAN: "CH06 0079 0042 5877 0443 7",
|
||||||
Address: report.Address{
|
Address: model.Address{
|
||||||
Street: "Kilchbergerweg",
|
Street: "Kilchbergerweg",
|
||||||
Number: "1",
|
Number: "1",
|
||||||
ZIPCode: "3052",
|
ZIPCode: "3052",
|
||||||
@@ -69,9 +70,9 @@ func main() {
|
|||||||
},
|
},
|
||||||
Contact: "Niklas Breitenstein",
|
Contact: "Niklas Breitenstein",
|
||||||
},
|
},
|
||||||
report.Entity{
|
model.Entity{
|
||||||
Name: "Lou Taylor",
|
Name: "Lou Taylor",
|
||||||
Address: report.Address{
|
Address: model.Address{
|
||||||
Street: "Alpenstrasse",
|
Street: "Alpenstrasse",
|
||||||
Number: "22",
|
Number: "22",
|
||||||
ZIPCode: "4950",
|
ZIPCode: "4950",
|
||||||
@@ -84,6 +85,14 @@ func main() {
|
|||||||
)
|
)
|
||||||
html := r.ToHTML()
|
html := r.ToHTML()
|
||||||
|
|
||||||
|
file, err := os.Create("index.html")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
file.Write([]byte(html))
|
||||||
|
|
||||||
// fmt.Print(html)
|
// fmt.Print(html)
|
||||||
pdfs, err := pdf.New("http://localhost:3030")
|
pdfs, err := pdf.New("http://localhost:3030")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
15
model/model.go
Normal file
15
model/model.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type Entity struct {
|
||||||
|
Name string
|
||||||
|
Address Address
|
||||||
|
Contact string
|
||||||
|
IBAN string
|
||||||
|
}
|
||||||
|
type Address struct {
|
||||||
|
Street string
|
||||||
|
Number string
|
||||||
|
ZIPCode string
|
||||||
|
Place string
|
||||||
|
Country string
|
||||||
|
}
|
||||||
@@ -25,14 +25,15 @@ func (s Service) HtmlToPdf(html string) (pdf io.ReadCloser, err error) {
|
|||||||
}
|
}
|
||||||
req := gotenberg.NewHTMLRequest(index)
|
req := gotenberg.NewHTMLRequest(index)
|
||||||
req.PaperSize(gotenberg.A4)
|
req.PaperSize(gotenberg.A4)
|
||||||
req.Margins(gotenberg.PageMargins{
|
// req.Margins(gotenberg.PageMargins{
|
||||||
Top: 0.5,
|
// Top: 0.5,
|
||||||
Bottom: 0.5,
|
// Bottom: 0.5,
|
||||||
Left: 0.5,
|
// Left: 0.5,
|
||||||
Right: 0.6,
|
// Right: 0.6,
|
||||||
Unit: gotenberg.IN,
|
// Unit: gotenberg.IN,
|
||||||
})
|
// })
|
||||||
|
|
||||||
|
req.Margins(gotenberg.NoMargins)
|
||||||
// Skips the IDLE events for faster PDF conversion.
|
// Skips the IDLE events for faster PDF conversion.
|
||||||
req.SkipNetworkIdleEvent(true)
|
req.SkipNetworkIdleEvent(true)
|
||||||
req.EmulatePrintMediaType()
|
req.EmulatePrintMediaType()
|
||||||
|
|||||||
@@ -1,8 +1,28 @@
|
|||||||
|
@page {
|
||||||
|
size: A4;
|
||||||
|
padding: 2cm;
|
||||||
|
}
|
||||||
|
@page:first {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
@media print {
|
||||||
|
.page,
|
||||||
|
.page-break {
|
||||||
|
break-after: page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.first-page {
|
||||||
|
margin-left: 2cm;
|
||||||
|
margin-right: 2cm;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
margin: 40px;
|
font-size: 12pt;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
margin-bottom: 3em;
|
margin-bottom: 3em;
|
||||||
}
|
}
|
||||||
@@ -10,6 +30,7 @@ p {
|
|||||||
margin-top: 0.25em;
|
margin-top: 0.25em;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -23,10 +44,10 @@ h1 {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
}
|
}
|
||||||
.company,
|
h2 {
|
||||||
.client {
|
margin-top: 0.5em;
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
@@ -39,96 +60,27 @@ td {
|
|||||||
}
|
}
|
||||||
th,
|
th,
|
||||||
td {
|
td {
|
||||||
padding: 10px;
|
padding: 0.25em 0.5em;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
th {
|
th {
|
||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
}
|
}
|
||||||
tfoot td {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
h2 {
|
|
||||||
margin-top: 40px;
|
|
||||||
}
|
|
||||||
article {
|
article {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
footer {
|
|
||||||
margin-top: 40px;
|
.issue-title {
|
||||||
font-size: 0.9em;
|
display: flex;
|
||||||
text-align: center;
|
justify-content: space-between;
|
||||||
color: #666;
|
align-items: end;
|
||||||
}
|
|
||||||
.totals {
|
margin-top: 2em;
|
||||||
float: right;
|
margin-bottom: 0.5em;
|
||||||
width: 300px;
|
|
||||||
margin-top: -15px;
|
h3,
|
||||||
}
|
p {
|
||||||
.totals table {
|
|
||||||
border: none;
|
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.totals td {
|
|
||||||
border: none;
|
|
||||||
padding: 5px 10px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media print {
|
|
||||||
.page,
|
|
||||||
.page-break {
|
|
||||||
break-after: page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.qr-section {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 250px 1fr;
|
|
||||||
grid-template-rows: 1fr;
|
|
||||||
gap: 1em;
|
|
||||||
|
|
||||||
width: 100%;
|
|
||||||
/* border-top: 2px solid #000; */
|
|
||||||
/* padding-top: 1rem; */
|
|
||||||
|
|
||||||
h4 {
|
|
||||||
margin-bottom: 0.1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.qr-code {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-between;
|
|
||||||
|
|
||||||
.qr-section-img {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
z-index: 1;
|
|
||||||
width: 40px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.qr-section-info {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
grid-template-rows: 1fr 1fr;
|
|
||||||
justify-items: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.payment-details {
|
|
||||||
font-size: 0.9rem;
|
|
||||||
line-height: 1.4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,13 @@
|
|||||||
<style>
|
<style>
|
||||||
{{ .Style }}
|
{{ .Style }}
|
||||||
</style>
|
</style>
|
||||||
|
<style>
|
||||||
|
|
||||||
|
{{.Invoice.CSS}}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header class="first-page" style="margin-top: 2cm">
|
||||||
<div class="company">
|
<div class="company">
|
||||||
<h2>{{ .Company.Name }}</h2>
|
<h2>{{ .Company.Name }}</h2>
|
||||||
<p>
|
<p>
|
||||||
@@ -23,12 +27,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="invoice-info">
|
<div class="invoice-info">
|
||||||
<p>
|
<p>
|
||||||
<strong>Rechnung:</strong> {{ .ID }} <br />
|
<strong>Rechnung:</strong> {{ .Invoice.Reference }} <br />
|
||||||
<strong>Datum:</strong> {{ .Date | date }} <br />
|
<strong>Datum:</strong> {{ .Date | date }} <br />
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<section class="client">
|
<section class="client first-page">
|
||||||
<h2>Rechnung an:</h2>
|
<h2>Rechnung an:</h2>
|
||||||
<p>
|
<p>
|
||||||
{{ .Client.Name }} <br />
|
{{ .Client.Name }} <br />
|
||||||
@@ -38,90 +42,52 @@
|
|||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="page p1">
|
<section class="page p1 first-page">
|
||||||
<article>
|
<article>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>FID</th>
|
<th style="min-width: 3.5em">FID</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Zeitaufwand</th>
|
<th>Aufwand</th>
|
||||||
<th>Stundensatz</th>
|
<th style="min-width: 5.5em">Preis</th>
|
||||||
<th>Preis CHF</th>
|
|
||||||
<th>Fertiggestellt</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{ range .Issues }}
|
{{ range .Issues }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Index }}</td>
|
<td style="font-family: monospace">{{ .Shorthand }}</td>
|
||||||
<td>{{ .Title }}</td>
|
<td>{{ .Title }}</td>
|
||||||
<td>{{ .Duration | duration }}</td>
|
<td>{{ .Duration | duration }}</td>
|
||||||
<td>16 CHF/h</td>
|
|
||||||
<td>{{ .Duration | price }} CHF</td>
|
<td>{{ .Duration | price }} CHF</td>
|
||||||
|
|
||||||
<td>{{ .Closed | time }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
<tfoot>
|
||||||
|
|
||||||
<div class="totals">
|
|
||||||
<table>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Gesamtbetrag:</td>
|
<th colspan="2" style="text-align: right">Summe:</th>
|
||||||
<td>{{ .Total }} CHF</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
<article class="qr-section">
|
|
||||||
<div class="qr-code">
|
|
||||||
<!-- Replace with your QR code image or generated SVG -->
|
|
||||||
<div class="qr-section-img">
|
|
||||||
<image src="{{ .QRInvoice }}"></image>
|
|
||||||
{{ .ChCross }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="qr-section-info">
|
<td>{{ .Total | duration }}</td>
|
||||||
<h4>Währung</h4>
|
<td>{{ .Total | price}}</td>
|
||||||
<h4>Betrag</h4>
|
</tr>
|
||||||
<p>CHF</p>
|
</tfoot>
|
||||||
<p>{{ .Total}}</p>
|
</table>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="payment-details">
|
|
||||||
<div>
|
|
||||||
<h4 style="margin-top: 0">Konto / Zahlbar an</h4>
|
|
||||||
<p>
|
|
||||||
{{ .Company.IBAN }} <br />
|
|
||||||
{{ .Company.Contact }} <br />
|
|
||||||
{{ .Company.Address.Street}} {{.Company.Address.Number}} <br />
|
|
||||||
{{ .Company.Address.ZIPCode }} {{ .Company.Address.Place }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h4>Referenz</h4>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h4>Zahlbar durch</h4>
|
|
||||||
<p>
|
|
||||||
{{ .Client.Contact }} <br />
|
|
||||||
{{ .Client.Address.Street}} {{.Client.Address.Number}} <br />
|
|
||||||
{{ .Client.Address.ZIPCode }} {{ .Client.Address.Place }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</article>
|
</article>
|
||||||
|
{{ .Invoice.HTML }}
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<h2>Details zu den Features</h2>
|
<h2 style="margin-top: 0">Details zu den Features</h2>
|
||||||
|
|
||||||
{{ range .Issues }}
|
{{ range .Issues }}
|
||||||
<article>
|
<article>
|
||||||
<h3>{{ .Index }}: {{ .Title }}</h3>
|
<div class="issue-title">
|
||||||
{{ .Body | md | oh 3 }}
|
<h3>
|
||||||
|
<span style="font-family: monospace">{{ .Shorthand }}</span>: {{
|
||||||
|
.Title }}
|
||||||
|
</h3>
|
||||||
|
<p>Fertiggestellt: {{ .Closed | time }}</p>
|
||||||
|
</div>
|
||||||
|
{{ .CleanBody | md | oh 3 }}
|
||||||
</article>
|
</article>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package report
|
|
||||||
|
|
||||||
import (
|
|
||||||
"html/template"
|
|
||||||
|
|
||||||
"git.schreifuchs.ch/lou-taylor/accounting/invoice"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (r Report) QRInvoice() template.URL {
|
|
||||||
i := invoice.Invoice{
|
|
||||||
ReceiverIBAN: r.Company.IBAN,
|
|
||||||
IsQrIBAN: false,
|
|
||||||
ReceiverName: r.Company.Name,
|
|
||||||
ReceiverStreet: r.Company.Address.Street,
|
|
||||||
ReceiverNumber: r.Company.Address.Number,
|
|
||||||
ReceiverZIPCode: r.Company.Address.ZIPCode,
|
|
||||||
ReceiverPlace: r.Company.Address.Place,
|
|
||||||
ReceiverCountry: r.Company.Address.Country,
|
|
||||||
Reference: "21 00000 00003 13947 14300 09017",
|
|
||||||
Amount: "25",
|
|
||||||
Currency: "CHF",
|
|
||||||
}
|
|
||||||
src, _ := i.GetQR()
|
|
||||||
return template.URL(src)
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
71
report/invoice/assets/scissors.svg
Normal file
71
report/invoice/assets/scissors.svg
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="64"
|
||||||
|
height="106.131"
|
||||||
|
viewBox="0 0 16.933333 28.080496"
|
||||||
|
version="1.1"
|
||||||
|
id="svg851"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
|
||||||
|
sodipodi:docname="scissors.svg"
|
||||||
|
inkscape:export-xdpi="96"
|
||||||
|
inkscape:export-ydpi="96">
|
||||||
|
<defs
|
||||||
|
id="defs845" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.6582031"
|
||||||
|
inkscape:cx="-135.5963"
|
||||||
|
inkscape:cy="106.75833"
|
||||||
|
inkscape:document-units="mm"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
fit-margin-top="0"
|
||||||
|
fit-margin-left="0"
|
||||||
|
fit-margin-right="0"
|
||||||
|
fit-margin-bottom="0"
|
||||||
|
inkscape:window-width="1920"
|
||||||
|
inkscape:window-height="1080"
|
||||||
|
inkscape:window-x="86"
|
||||||
|
inkscape:window-y="117"
|
||||||
|
inkscape:window-maximized="0" />
|
||||||
|
<metadata
|
||||||
|
id="metadata848">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-52.847684,-108.31232)">
|
||||||
|
<text
|
||||||
|
y="-57.540855"
|
||||||
|
x="117.23324"
|
||||||
|
class="st2 st3"
|
||||||
|
id="text18"
|
||||||
|
style="font-size:11.17903996px;font-family:ZapfDingbatsITC;stroke-width:0.26458332"
|
||||||
|
transform="rotate(90)">✂</text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
111
report/invoice/assets/style.css
Normal file
111
report/invoice/assets/style.css
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
.c6ee15365-8f47-4dab-8bee-2a56a7916c57 {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 240px 1px 1fr;
|
||||||
|
grid-template-rows: 1px 1fr;
|
||||||
|
|
||||||
|
.separator-h {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: 1 / span 3;
|
||||||
|
|
||||||
|
border-top: 1px solid black;
|
||||||
|
svg {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
margin-top: -52px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.separator-v {
|
||||||
|
grid-row: 2;
|
||||||
|
grid-column: 2;
|
||||||
|
|
||||||
|
border-right: 1px solid black;
|
||||||
|
svg {
|
||||||
|
margin-left: -32px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.receiver {
|
||||||
|
grid-row: 2;
|
||||||
|
grid-column: 1;
|
||||||
|
|
||||||
|
font-size: 12pt;
|
||||||
|
padding: 1em;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin: 0;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
h4 {
|
||||||
|
margin-bottom: 0.1em;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.payer {
|
||||||
|
grid-row: 2;
|
||||||
|
grid-column: 3;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 250px 1fr;
|
||||||
|
grid-template-rows: 2em 1fr;
|
||||||
|
padding: 1em;
|
||||||
|
gap: 1em;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
grid-row: 1;
|
||||||
|
grid-column: 1 / 2;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
margin-bottom: 0.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-code {
|
||||||
|
grid-row: 2;
|
||||||
|
grid-column: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.qr-section-img {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
svg {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
z-index: 1;
|
||||||
|
width: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.qr-section-info {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
grid-template-rows: 1fr 1fr;
|
||||||
|
justify-items: center;
|
||||||
|
|
||||||
|
p,
|
||||||
|
h4 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.payment-details {
|
||||||
|
grid-row: 2;
|
||||||
|
grid-column: 2;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
report/invoice/assets/template.html
Normal file
70
report/invoice/assets/template.html
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<article class="c6ee15365-8f47-4dab-8bee-2a56a7916c57">
|
||||||
|
<div class="separator-h">{{ .Scissors }}</div>
|
||||||
|
<div class="receiver">
|
||||||
|
<div class="payment-details">
|
||||||
|
<div>
|
||||||
|
<h2>Empfangsschein</h2>
|
||||||
|
<h4 style="margin-top: 0">Konto / Zahlbar an</h4>
|
||||||
|
<p>
|
||||||
|
{{ .ReceiverIBAN }} <br />
|
||||||
|
{{ .ReceiverName }} <br />
|
||||||
|
{{ .ReceiverStreet}} {{.ReceiverNumber}} <br />
|
||||||
|
{{ .ReceiverZIPCode }} {{ .ReceiverPlace }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4>Referenz</h4>
|
||||||
|
<p>{{ .Reference }}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4>Zahlbar durch</h4>
|
||||||
|
<p>
|
||||||
|
{{ .PayeeName }} <br />
|
||||||
|
{{ .PayeeStreet}} {{.PayeeNumber}} <br />
|
||||||
|
{{ .PayeeZIPCode }} {{ .PayeePlace }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="separator-v">{{ .Scissors }}</div>
|
||||||
|
<div class="payer">
|
||||||
|
<h2>Zahlteil</h2>
|
||||||
|
<div class="qr-code">
|
||||||
|
<!-- Replace with your QR code image or generated SVG -->
|
||||||
|
<div class="qr-section-img">
|
||||||
|
<image src="{{ .GetQR }}"></image>
|
||||||
|
{{ .Cross }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="qr-section-info">
|
||||||
|
<h4>Währung</h4>
|
||||||
|
<h4>Betrag</h4>
|
||||||
|
<p>CHF</p>
|
||||||
|
<p>{{ .Amount }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="payment-details">
|
||||||
|
<div>
|
||||||
|
<h4 style="margin-top: 0">Konto / Zahlbar an</h4>
|
||||||
|
<p>
|
||||||
|
{{ .ReceiverIBAN }} <br />
|
||||||
|
{{ .ReceiverName }} <br />
|
||||||
|
{{ .ReceiverStreet}} {{.ReceiverNumber}} <br />
|
||||||
|
{{ .ReceiverZIPCode }} {{ .ReceiverPlace }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4>Referenz</h4>
|
||||||
|
<p>{{ .Reference }}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4>Zahlbar durch</h4>
|
||||||
|
<p>
|
||||||
|
{{ .PayeeName }} <br />
|
||||||
|
{{ .PayeeStreet}} {{.PayeeNumber}} <br />
|
||||||
|
{{ .PayeeZIPCode }} {{ .PayeePlace }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
42
report/invoice/html.go
Normal file
42
report/invoice/html.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package invoice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed assets/ch-cross.svg
|
||||||
|
var chCross template.HTML
|
||||||
|
|
||||||
|
//go:embed assets/scissors.svg
|
||||||
|
var scissors template.HTML
|
||||||
|
|
||||||
|
//go:embed assets/template.html
|
||||||
|
var htmlTemplate string
|
||||||
|
|
||||||
|
//go:embed assets/style.css
|
||||||
|
var style template.CSS
|
||||||
|
|
||||||
|
type tmpler struct {
|
||||||
|
Invoice
|
||||||
|
Cross template.HTML
|
||||||
|
Scissors template.HTML
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Invoice) CSS() template.CSS {
|
||||||
|
return style
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Invoice) HTML() (html template.HTML, err error) {
|
||||||
|
tmpl := template.Must(template.New("invoice").Parse(htmlTemplate))
|
||||||
|
|
||||||
|
data := tmpler{i, chCross, scissors}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
err = tmpl.Execute(buf, data)
|
||||||
|
html = template.HTML(buf.String())
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.schreifuchs.ch/lou-taylor/accounting/model"
|
||||||
"github.com/skip2/go-qrcode"
|
"github.com/skip2/go-qrcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +33,32 @@ type Invoice struct {
|
|||||||
Currency string `yaml:"currency" default:"CHF"`
|
Currency string `yaml:"currency" default:"CHF"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Invoice) GetQR() (src string, err error) {
|
func New(amount string, receiver model.Entity, payee *model.Entity) Invoice {
|
||||||
|
i := Invoice{
|
||||||
|
ReceiverIBAN: receiver.IBAN,
|
||||||
|
IsQrIBAN: false,
|
||||||
|
ReceiverName: receiver.Name,
|
||||||
|
ReceiverStreet: receiver.Address.Street,
|
||||||
|
ReceiverNumber: receiver.Address.Number,
|
||||||
|
ReceiverZIPCode: receiver.Address.ZIPCode,
|
||||||
|
ReceiverPlace: receiver.Address.Place,
|
||||||
|
ReceiverCountry: receiver.Address.Country,
|
||||||
|
Reference: generateReference(),
|
||||||
|
Amount: amount,
|
||||||
|
Currency: "CHF",
|
||||||
|
}
|
||||||
|
if payee != nil {
|
||||||
|
i.PayeeName = payee.Name
|
||||||
|
i.PayeeStreet = payee.Address.Street
|
||||||
|
i.PayeeNumber = payee.Address.Number
|
||||||
|
i.PayeeZIPCode = payee.Address.ZIPCode
|
||||||
|
i.PayeePlace = payee.Address.Place
|
||||||
|
i.PayeeCountry = payee.Address.Country
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Invoice) GetQR() (src template.URL, err error) {
|
||||||
content, err := i.qrContent()
|
content, err := i.qrContent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -47,7 +73,7 @@ func (i Invoice) GetQR() (src string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
b64 := base64.StdEncoding.EncodeToString(png)
|
b64 := base64.StdEncoding.EncodeToString(png)
|
||||||
src = fmt.Sprintf(`data:image/png;base64,%s`, b64)
|
src = template.URL(fmt.Sprintf(`data:image/png;base64,%s`, b64))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
68
report/invoice/reference.go
Normal file
68
report/invoice/reference.go
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
package invoice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func generateReference() string {
|
||||||
|
// 1) Build the 26-digit payload from time + random suffix
|
||||||
|
now := time.Now().UTC()
|
||||||
|
ts := now.Format("20060102150405") // YYYYMMDDHHMMSS -> 14 chars
|
||||||
|
ns := now.Nanosecond() // 0..999999999
|
||||||
|
// format nanoseconds as 9 digits, zero padded
|
||||||
|
nsStr := fmt.Sprintf("%09d", ns)
|
||||||
|
|
||||||
|
// 3-digit random suffix (000..999) to reach 26 digits
|
||||||
|
randBytes := make([]byte, 2) // we'll read 2 bytes and map to 0..999
|
||||||
|
rand.Read(randBytes)
|
||||||
|
|
||||||
|
// convert to number 0..65535 then mod 1000
|
||||||
|
rnum := int(randBytes[0])<<8 | int(randBytes[1])
|
||||||
|
rnum = rnum % 1000
|
||||||
|
randStr := fmt.Sprintf("%03d", rnum)
|
||||||
|
|
||||||
|
// compose 26-digit payload: 14 + 9 + 3 = 26
|
||||||
|
payload := ts + nsStr + randStr
|
||||||
|
|
||||||
|
// Safety: ensure payload is 26 digits (should always be true)
|
||||||
|
if len(payload) != 26 {
|
||||||
|
panic(fmt.Errorf("internal error: payload length %d != 26", len(payload)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) Compute Modulo-10 recursive check digit
|
||||||
|
check := mod10RecursiveChecksum(payload)
|
||||||
|
|
||||||
|
// 3) Build full 27-digit reference
|
||||||
|
full := payload + fmt.Sprintf("%d", check)
|
||||||
|
|
||||||
|
// 4) Format with grouping: 2-5-5-5-5-5
|
||||||
|
formatted := fmt.Sprintf("%s %s %s %s %s %s",
|
||||||
|
full[0:2],
|
||||||
|
full[2:7],
|
||||||
|
full[7:12],
|
||||||
|
full[12:17],
|
||||||
|
full[17:22],
|
||||||
|
full[22:27],
|
||||||
|
)
|
||||||
|
return formatted
|
||||||
|
}
|
||||||
|
|
||||||
|
// mod10RecursiveChecksum computes the Mod10 recursive check digit for a numeric string.
|
||||||
|
// Implements the table-based recursive mod10 described in Swiss Annex B / ISR implementations.
|
||||||
|
func mod10RecursiveChecksum(digits string) int {
|
||||||
|
// table as used in ISR/QR implementations
|
||||||
|
arrTable := [10]int{0, 9, 4, 6, 8, 2, 7, 1, 3, 5}
|
||||||
|
carry := 0
|
||||||
|
for i := 0; i < len(digits); i++ {
|
||||||
|
ch := digits[i]
|
||||||
|
// assume digits are ASCII '0'..'9'
|
||||||
|
n := int(ch - '0')
|
||||||
|
// update carry
|
||||||
|
idx := (carry + n) % 10
|
||||||
|
carry = arrTable[idx]
|
||||||
|
}
|
||||||
|
// final check digit
|
||||||
|
return (10 - carry) % 10
|
||||||
|
}
|
||||||
@@ -1,43 +1,31 @@
|
|||||||
package report
|
package report
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.schreifuchs.ch/lou-taylor/accounting/issue"
|
"git.schreifuchs.ch/lou-taylor/accounting/issue"
|
||||||
"github.com/google/uuid"
|
"git.schreifuchs.ch/lou-taylor/accounting/model"
|
||||||
|
"git.schreifuchs.ch/lou-taylor/accounting/report/invoice"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(issues []issue.Issue, company, client Entity, rate float64) *Report {
|
type Report struct {
|
||||||
return &Report{
|
Date time.Time
|
||||||
|
Issues []issue.Issue
|
||||||
|
Invoice invoice.Invoice
|
||||||
|
Rate float64
|
||||||
|
Company model.Entity
|
||||||
|
Client model.Entity
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(issues []issue.Issue, company, client model.Entity, rate float64) *Report {
|
||||||
|
r := &Report{
|
||||||
Date: time.Now(),
|
Date: time.Now(),
|
||||||
Issues: issues,
|
Issues: issues,
|
||||||
Rate: rate,
|
Rate: rate,
|
||||||
Company: company,
|
Company: company,
|
||||||
Client: client,
|
Client: client,
|
||||||
ID: uuid.NewString(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
r.Invoice = invoice.New(r.applyRate(r.Total()), r.Company, &r.Client)
|
||||||
|
|
||||||
type Report struct {
|
return r
|
||||||
Date time.Time
|
|
||||||
Issues []issue.Issue
|
|
||||||
Style template.CSS
|
|
||||||
Rate float64
|
|
||||||
ID string
|
|
||||||
Company Entity
|
|
||||||
Client Entity
|
|
||||||
}
|
|
||||||
type Entity struct {
|
|
||||||
Name string
|
|
||||||
Address Address
|
|
||||||
Contact string
|
|
||||||
IBAN string
|
|
||||||
}
|
|
||||||
type Address struct {
|
|
||||||
Street string
|
|
||||||
Number string
|
|
||||||
ZIPCode string
|
|
||||||
Place string
|
|
||||||
Country string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +15,9 @@ var htmlTemplate string
|
|||||||
//go:embed assets/style.css
|
//go:embed assets/style.css
|
||||||
var style template.CSS
|
var style template.CSS
|
||||||
|
|
||||||
//go:embed assets/ch-cross.svg
|
type tmpler struct {
|
||||||
var chCross template.HTML
|
Report
|
||||||
|
Style template.CSS
|
||||||
func (r Report) ChCross() template.HTML {
|
|
||||||
return chCross
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) ToHTML() string {
|
func (r Report) ToHTML() string {
|
||||||
@@ -32,15 +29,13 @@ func (r Report) ToHTML() string {
|
|||||||
"time": fmtDateTime,
|
"time": fmtDateTime,
|
||||||
"date": fmtDate,
|
"date": fmtDate,
|
||||||
"duration": fmtDuration,
|
"duration": fmtDuration,
|
||||||
"brakes": func(text string) template.HTML {
|
|
||||||
return template.HTML(strings.ReplaceAll(template.HTMLEscapeString(text), "\n", "<br>"))
|
|
||||||
},
|
|
||||||
}).Parse(htmlTemplate))
|
}).Parse(htmlTemplate))
|
||||||
|
|
||||||
r.Style = style
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
_ = tmpl.Execute(buf, r)
|
err := tmpl.Execute(buf, tmpler{r, style})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +57,12 @@ func fmtDuration(d time.Duration) string {
|
|||||||
return fmt.Sprintf("%.2f h", d.Hours())
|
return fmt.Sprintf("%.2f h", d.Hours())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Report) Total() string {
|
func (r Report) Total() time.Duration {
|
||||||
dur := time.Duration(0)
|
dur := time.Duration(0)
|
||||||
|
|
||||||
for _, i := range r.Issues {
|
for _, i := range r.Issues {
|
||||||
dur += i.Duration
|
dur += i.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.applyRate(dur)
|
return dur
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user