From 0806a5dc1af7a9d5732aac1d26e4cb891915d6ee Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 30 Jun 2018 18:16:32 +0300 Subject: Add: first version --- docstory.yaml | 12 ++ lasku.py | 91 ++++++++++++ lasku.yaml | 32 ++++ template.tex | 467 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 602 insertions(+) create mode 100644 docstory.yaml create mode 100755 lasku.py create mode 100644 lasku.yaml create mode 100644 template.tex diff --git a/docstory.yaml b/docstory.yaml new file mode 100644 index 0000000..3aa8fbe --- /dev/null +++ b/docstory.yaml @@ -0,0 +1,12 @@ +company: Docstory Tmi +companycode: Y-TUNNUS? +companyperson: Soile Mottisenkangas +companyaddr: Pohjavedenkatu 12 F 39 +companypostcode: "00980" +companypostoffice: Helsinki +companytown: Helsinki +companyurl: http://www.docstory.fi +companyemail: soile@docstory.fi +companyphone: "+358 40 370 5224" +companyiban: "FI98 0000 0000 0000 00" +companyvat: FI00000000 diff --git a/lasku.py b/lasku.py new file mode 100755 index 0000000..8f9e185 --- /dev/null +++ b/lasku.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + + +import sys + +import yaml + + +def euros(cents): + return '%.02f' % (cents / 100.0) + + +class Item: + + def __init__(self, itemdict): + self.dict = itemdict + + count = itemdict['count'] + unit_cents = int(itemdict['unit'] * 100) + vatpc = float(itemdict['vatpc']) / 100.0 + + self.total_cents = count * unit_cents + self.vat_cents = int(unit_cents * vatpc) + + self.dict.update({ + 'total_cents': self.total_cents, + 'total': euros(self.total_cents), + 'vat_cents': self.vat_cents, + 'vat': euros(self.vat_cents), + 'vatsum': euros(self.vat_cents * count), + 'totalwithvat': euros(count * (unit_cents + self.vat_cents)), + }) + + +item_template = ( + r'\raggedbottom #number# & ' + r'\parbox[t]{5.5cm}{#desc#\\#date#} & ' + r'\raggedbottom #count# & ' + r'\raggedbottom #unit# & ' + r'\raggedbottom #vat# & ' + r'\raggedbottom #vatpc#\% & ' + r'\raggedbottom #total# & ' + r'\raggedbottom #vatsum# & ' + r'\raggedbottom #totalwithvat# \\[2.2ex]' +) + + +def cat(filename): + with open(filename) as f: + return f.read() + + +def substitute_all(text, subst): + for key, value in subst.items(): + pattern = '#{}#'.format(key) + text = str(value).join(text.split(pattern)) + return text + + +text = cat('template.tex') + +with open(sys.argv[1]) as f: + company = yaml.safe_load(f) +with open(sys.argv[2]) as f: + invoice = yaml.safe_load(f) + +items = invoice['invoiceitems'] +values = dict(company) +values.update(invoice) + +itemtext = '' +total_cents = 0 +total_vat = 0 +total_sum = 0 + +for item in items: + it = Item(item) + itemtext += substitute_all(item_template, it.dict) + total_cents += it.total_cents + total_vat += it.vat_cents + total_sum += it.total_cents + it.vat_cents + +values['itemtext'] = itemtext +values['totalraw'] = euros(total_cents) +values['totalvat'] = euros(total_vat) +values['totalsum'] = euros(total_sum) + +values['amount'] = values['totalsum'] + +text = substitute_all(text, values) +sys.stdout.write(text) diff --git a/lasku.yaml b/lasku.yaml new file mode 100644 index 0000000..c77128e --- /dev/null +++ b/lasku.yaml @@ -0,0 +1,32 @@ +title: Lasku 1/2018 +date: 1.7.2018 + +payee: QvarnLabs Ab +payeeaddr: Bulevardi 7 +payeepostcode: "00120" +payeepostoffice: Helsinki + +invoicenumber: 1/2018 +payeenumber: 12765 +duedate: 15.7.2018 +terms: 14 pv netto + +noticeperiod: 8 vrk +latepercent: 10,0 +remindfee: 5,00 +invoicerefcode: 5123010105 + +invoiceitems: +- number: 1 + desc: Elokuvaohjaus + date: 1-15.6.2018 + count: 1 + unit: 100.00 + vatpc: 24 + +- number: 2 + desc: Elämää + date: 1.5.2018 + count: 1 + unit: 100.00 + vatpc: 33 diff --git a/template.tex b/template.tex new file mode 100644 index 0000000..cdf306f --- /dev/null +++ b/template.tex @@ -0,0 +1,467 @@ +% Standard Finnish Invoice Template v0.4 +% Copyright 2008 Jaakko Heusala +% +% See README in finnish for instructions. +% +% $Id: invoice.tex 4581 2008-02-24 18:59:30Z jheusala $ +% [The zlib/libpng License] +% +% This software is provided 'as-is', without any express or implied +% warranty. In no event will the authors be held liable for any damages +% arising from the use of this software. +% +% Permission is granted to anyone to use this software for any purpose, +% including commercial applications, and to alter it and redistribute it +% freely, subject to the following restrictions: +% +% 1. The origin of this software must not be misrepresented; you must not +% claim that you wrote the original software. If you use this software +% in a product, an acknowledgment in the product documentation would be +% appreciated but is not required. +% +% 2. Altered source versions must be plainly marked as such, and must not be +% misrepresented as being the original software. +% +% 3. This notice may not be removed or altered from any source +% distribution. +% + +\documentclass[a4paper,10pt]{letter} +\title{#title#} +\date{#date#} +\usepackage{pslatex} +\usepackage[utf8]{inputenc} +\usepackage[finnish]{babel} +\pagestyle{empty} +\usepackage[left=0cm,top=0cm,right=0cm,bottom=0cm,nohead,nofoot]{geometry} +\usepackage[gen]{eurosym} +\usepackage{color} +%\usepackage{pstricks} +%\usepackage{pst-barcode} +\usepackage{rotating} +\usepackage[T1]{fontenc} % Fixes scandinavian character problem +\input code128 +\begin{document} + +\setlength{\unitlength}{1mm} +\begin{picture}(210,297)(0,0) + +%% Document Header +\fontsize{12pt}{14pt} +\selectfont +\put(20,277){ + \begin{tabular}[t]{@{}p{8.5cm}@{}p{8.5cm}@{}r} + \parbox[t]{9.5cm}{ + \fontsize{16pt}{18pt} + \selectfont + \textsc{#company#} \\ + \fontsize{12pt}{14pt} + \selectfont + #companyperson# \\ + #companyaddr# \\ + #companypostcode# #companypostoffice# \\ + \\ + \\ + #payee# \\ + #payeeaddr# \\ + #payeepostcode# #payeepostoffice# + } + & + \parbox[t]{8.5cm}{ + LASKU \\ + \\ + #date# + \\ + \\ + \\ + \framebox{ + \fontsize{10pt}{11pt} + \selectfont + \begin{tabular}[t]{@{}l@{}l@{}} + \begin{tabular}[t]{@{}ll} + Laskun numero: & #invoicenumber# \\ + Asiakasnumero: & #payeenumber# \\ + Päivämäärä: & #date# \\ + Maksuehdot: & #terms# \\ + Eräpäivä: & #duedate# \\ + \end{tabular} + & + \begin{tabular}[t]{@{}ll} + Maksettava: & #amount# \euro \\ + Huomautusaika: & #noticeperiod# \\ + Viivästyskorko: & #latepercent#\% \\ + Muistutusmaksu: & #remindfee# \euro \\ + \end{tabular} + \end{tabular} + } + } & 1 (1) \\ + \end{tabular} +} + + +\fontsize{8pt}{9pt} +\selectfont +\put(10,222){ + +\begin{tabular}[t]{@{}rlrrrrrrr@{}} + \parbox[t]{0.50cm}{\raggedleft Rivi\\nro} & + \parbox[t]{5.5cm}{Tuote/palvelu} & + \parbox[t]{0.50cm}{\raggedleft KPL} & + \parbox[t]{1.5cm}{\raggedleft A-hinta\\veroton} & + \parbox[t]{1.5cm}{\raggedleft A-hinta\\verollinen} & + \parbox[t]{1.5cm}{\raggedleft ALV-\%} & + \parbox[t]{1.5cm}{\raggedleft Veroton\\yhteensä} & + \parbox[t]{1.5cm}{\raggedleft ALV\\yhteensä} & + \parbox[t]{1.5cm}{\raggedleft Verollinen\\yhteensä} \\[2.5ex] +\hline +#itemtext# +\hline +& Yhteensä & & & & & #totalraw# & #totalvat# & #totalsum# \\ +\end{tabular} +} + + + +%% Additional info +\put(10,120){ \parbox[t]{200cm}{Muistutuksesta perimme #remindfee# euron muistutusmaksun.} } + + +%% Company Contact Info +\fontsize{8pt}{8.5pt} +\selectfont +\put(10,110){ + \begin{tabular}{p{3cm}p{3cm}p{4cm}p{4cm}p{3.25cm}@{}} + \hline + \\ + \parbox[t]{3cm}{ + \textbf{#company#}\\ + \mbox{#companyaddr#}\\ + \mbox{#companypostcode# #companypostoffice#} + } & + \parbox[t]{3cm}{ + Y-tunnus: \mbox{#companycode#} \\ + Kotipaikka: #companytown# \\ + {\tt \mbox{#companyurl#}} + } & + \parbox[t]{4cm}{ + Sähköposti: {\tt \mbox{#companyemail#}}\\ + Puhelin: \mbox{#companyphone#} + } & + \parbox[t]{4cm}{ + Tilinumero:\\ + IBAN: {\tt \mbox{#companyiban#}} + } & + \parbox[t]{3.25cm}{ + Viitenumero: {\tt \mbox{#invoicerefcode#}} \\ + VAT: {\tt \mbox{#companyvat#}} + } \\ + \end{tabular} +} + +%% Standard Finnish Bank Transfer Form +\linethickness{0.5mm} + +%% For debug +%\color{red} +%\put(0,0){\circle{10}} +%\put(210,0){\circle{10}} +%\put(0,101.6){\circle{10}} +%\put(210,101.6){\circle{10}} +% +%% For debug +%\put(5,5){\makebox(0,0){0,0}} +%\put(200,5){\makebox(0,0){210,0}} +%\put(7,99){\makebox(0,0){0,101.6}} +%\put(200,99){\makebox(0,0){210,101.6}} + +% Bold Vertical lines +\color{blue} +%\put(20.32,69.85){\circle{10}} +\put(20.32,69.85){\line(0,1){31.75}} +%\put(111.76,27.5166667){\circle{10}} +\put(111.76,27.5166667){\line(0,1){74.0833333}} +%\put(124.46,27.5166667){\circle{10}} +\put(124.46,27.5166667){\line(0,1){16.9333333}} +%\put(157.48,27.5166667){\circle{10}} +\put(157.48,27.5166667){\line(0,1){8.46666667}} + +% Bold Horizontal lines +%\put(111.76,84.6666667){\circle{10}} +\put(111.76,84.6666667){\line(-1,0){106.68}} +\put(111.76,84.6666667){\line(1,0){91.44}} + +%\put(111.76,69.85){\circle{10}} +\put(111.76,69.85){\line(-1,0){106.68}} + +%\put(111.76,44.45){\circle{10}} +\put(111.76,44.45){\line(1,0){91.44}} + +%\put(111.76,35.9833333){\circle{10}} +\put(111.76,35.9833333){\line(-1,0){106.68}} +\put(111.76,35.9833333){\line(1,0){91.44}} + +%\put(111.76,27.5166667){\circle{10}} +\put(111.76,27.5166667){\line(-1,0){106.68}} +\put(111.76,27.5166667){\line(1,0){91.44}} + +%\put(52.49333333,29.6333333){\line(1,0){1.69333333}} % Tilinumeron viiva + +%\put(20.32,27.5166667){\circle{10}} +\put(20.32,27.5166667){\line(0,1){8.46666667}} + +% Normal lines +\linethickness{0.13mm} + +%% Debug line +%\color{red} +%\put(0,101.6){\line(1,0){210}} +%\color{blue} + +% Normal Vertical Lines +%\put(20.32,27.5166667){\circle{10}} +%\put(20.32,27.5166667){\line(0,1){8.46666667}} +%\put(25.40,27.5166667){\line(0,1){2.11666667}} % 01 +%\put(30.48,27.5166667){\line(0,1){2.11666667}} % 02 +%\put(35.56,27.5166667){\line(0,1){2.11666667}} % 03 +%\put(40.64,27.5166667){\line(0,1){2.11666667}} % 04 +%\put(45.72,27.5166667){\line(0,1){2.11666667}} % 05 +%\put(50.80,27.5166667){\line(0,1){2.11666667}} % 06 +%\put(55.88,27.5166667){\line(0,1){2.11666667}} % 07 +%\put(60.96,27.5166667){\line(0,1){2.11666667}} % 08 +%\put(66.04,27.5166667){\line(0,1){2.11666667}} % 09 +%\put(71.12,27.5166667){\line(0,1){2.11666667}} % 10 +%\put(76.20,27.5166667){\line(0,1){2.11666667}} % 11 +%\put(81.28,27.5166667){\line(0,1){2.11666667}} % 12 +%\put(86.36,27.5166667){\line(0,1){2.11666667}} % 13 +%\put(91.44,27.5166667){\line(0,1){2.11666667}} % 14 +%\put(96.52,27.5166667){\line(0,1){2.11666667}} % 15 + +%\put(161.29,84.6666667){\circle{10}} +\put(161.29,84.6666667){\line(0,1){16.9333333}} + +% Normal Horizontal lines +%\put(20.02,40.2166667){\circle{10}} +\put(20.02,40.2166667){\line(1,0){91.44}} % 20.02 should be 20.32 (8/10 inches) + +% Texts + +% Tilinumero +\put(0,84.6666667){ + \makebox(19,16.9333333)[r]{ + \begin{minipage}[r]{19mm} + \fontsize{7pt}{8pt} + \selectfont + \begin{flushright} + Saajan\\ + tilinumero\\ + Mottagarens\\ + kontonummer + \end{flushright} + \end{minipage} + } +} + +% Saaja +\put(0,69.85){ + \makebox(19,14.8166667)[r]{ + \begin{minipage}[r]{19mm} + \fontsize{7pt}{8pt} + \selectfont + \begin{flushright} + Saaja\\ + Mottagare + \end{flushright} + \end{minipage} + } +} + +% Maksaja +\put(0,52){ + \makebox(19,14.8166667)[r]{ + \begin{minipage}[r]{19mm} + \fontsize{7pt}{8pt} + \selectfont + \begin{flushright} + Maksajan\\ + nimi ja\\ + osoite \\ + Betalarens \\ + namn och \\ + adress + \end{flushright} + \end{minipage} + } +} + +% Allekirjoitus +\put(0,35.9833333){ + \makebox(19,14.8166667)[r]{ + \begin{minipage}[r]{19mm} + \fontsize{7pt}{8pt} + \selectfont + \begin{flushright} + Alle-\\ + kirjoitus\\ + Underskrift + \end{flushright} + \end{minipage} + } +} + +% Tililtä nro +\put(0,27.5166667){ + \makebox(19,8.46666667)[r]{ + \begin{minipage}[r]{19mm} + \fontsize{7pt}{8pt} + \selectfont + \begin{flushright} + Tililtä nro\\ + Från konto nr + \end{flushright} + \end{minipage} + } +} + +% Viitenumero +\put(111.5,35.9833333){ + \makebox(12.7,8.46666667)[l]{ + \begin{minipage}[l]{12.7mm} + \fontsize{7pt}{8pt} + \selectfont + Viitenro\\ + Ref.nr + \end{minipage} + } +} + +% Eräpäivä +\put(111.5,27.5166667){ + \makebox(12.7,8.46666667)[l]{ + \begin{minipage}[l]{12.7mm} + \fontsize{7pt}{8pt} + \selectfont + Eräpäivä\\ + Förf.dag + \end{minipage} + } +} + +% Euro +\put(157,26.5){ + \makebox(12.7,8.46666667)[tl]{ + \begin{minipage}[tl]{12.7mm} + \fontsize{7pt}{8pt} + \selectfont + Euro + \end{minipage} + } +} + + +% Tilisiirtoteksti +\put(4.5,37){ + \begin{sideways} + \fontsize{8pt}{8.5pt} + \selectfont + \textbf{TILISIIRTO GIRERING} + \end{sideways} +} + +% Maksu välitetään -teksti +%\put(150,5){\circle{10}} +\put(150,5){ + \makebox(52,12)[t]{ + \begin{minipage}[t]{52mm} + \fontsize{5pt}{5.5pt} + \selectfont + Maksu välitetään saajalle vain Suomessa Kotimaan maksujenvälityksen yleisten + ehtojen mukaisesti ja vain maksajan ilmoittaman tilinumeron perusteella. \\ + Betalningen förmedlas till mottagare endast i Finland enligt Allmänna villkor för + inrikes betalningsförmedling och endast till det kontonummer betalaren angivit. + \end{minipage} + } +} + + +\color{black} +\fontsize{9pt}{10pt} +\selectfont + +% Saajan tilinumero +%\put(20.32,86.5){\circle{10}} +\put(20.32,86.5){ + \makebox(91.44,16.9333333)[bl]{ + \begin{minipage}[bl]{91.44mm} + \fontsize{9pt}{10pt} + \selectfont + #companyiban# + \end{minipage} + } +} + +% Saaja + +\put(20.32,68.25){ + \makebox(91.44,13.7)[tl]{ + \begin{minipage}[tl]{91.44mm} + \fontsize{9pt}{10pt} + \selectfont + #company# \\ + #companyaddr# \\ + #companypostcode# #companypostoffice# + \end{minipage} + } +} + +% Maksaja +\put(20.32,35.9833333){ + \makebox(91.44,29.6333333)[tl]{ + \begin{minipage}[tl]{91.44mm} + \fontsize{9pt}{10pt} + \selectfont + #payee# \\ + #payeeaddr# \\ + #payeepostcode# #payeepostoffice# + \end{minipage} + } +} + +% Viestiosa +\put(114.3,44.45){ + \makebox(81.28,38)[tl]{ + \begin{minipage}[tl]{81.28mm} + \fontsize{9pt}{10pt} + \selectfont + Laskunumero: #invoicenumber# \\ + Asiakasnumero: #payeenumber# \\ + \\ + \\ + \\ + \\ + \\ + Viitenumero mainittava maksaessa! + \end{minipage} + } +} + +% Viitenumero +\put(132.08,39){ #invoicerefcode# } % Viitenumero +\put(132.08,30){ #duedate# } % Eräpäivä +\put(168,30){ #amount# } % Summa + + +%% Viivakoodi +%\put(20.32,3){ +% \X=.25mm +% \barheight=12mm +% \code{2574136020371846000964220000000000512301010508081000001} +%} + +% Pankki-teksti +\color{blue} +\fontsize{6pt}{10pt} +\selectfont +\put(185,2){ PANKKI BANKEN } + +\end{picture} +\end{document} -- cgit v1.2.1