summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/simpleinvoice/simpleinvoice.sty
blob: 3b3dbd98a64950c9af5d9a219dcd52d33c186e0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
% Package for creating invoices.
% Implemented by Mathias Lohne (mathialo@ifi.uio.no).
% (c) 2017 Mathias Lohne
% Version 2017-11-03.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{simpleinvoice}[2017/11/03 package simpleinvoice]

% Fall back to english if option parsing fails
\def \INV@lang {eng}

% Language options
\DeclareOption{american}{\def \INV@lang  {eng}}
\DeclareOption{english}{\def \INV@lang   {eng}}
\DeclareOption{UKenglish}{\def \INV@lang {eng}}
\DeclareOption{USenglish}{\def \INV@lang {eng}}
\DeclareOption{norsk}{\def \INV@lang     {nobm}}
\DeclareOption{norwegian}{\def \INV@lang {nobm}}
\DeclareOption{bokmaal}{\def \INV@lang {nobm}}

\ProcessOptions

% Translations
\def \INV@text@invoice@eng {Invoice}
\def \INV@text@ourref@eng {Our ref}
\def \INV@text@yourref@eng {Your ref}
\def \INV@text@invnum@eng {Invoice number}
\def \INV@text@invdate@eng {Invoice date}
\def \INV@text@deadline@eng {Deadline}
\def \INV@text@description@eng {Description}
\def \INV@text@itemprice@eng {Item price}
\def \INV@text@vat@eng {VAT}
\def \INV@text@itemtotal@eng {Sum}
\def \INV@text@subtotal@eng {Subtotal}
\def \INV@text@total@eng {Total}
\def \INV@text@paymentinfo@eng {Payment info}
\def \INV@text@totallong@eng {Total}
\def \INV@text@accountnum@eng {Account number}
\def \INV@text@warning@eng {By paying after deadline, additional interest and fees may apply.}

\def \INV@text@invoice@nobm {Faktura}
\def \INV@text@ourref@nobm {Vår ref}
\def \INV@text@yourref@nobm {Deres ref}
\def \INV@text@invnum@nobm {Fakturanummer}
\def \INV@text@invdate@nobm {Fakturadato}
\def \INV@text@deadline@nobm {Forfallsdato}
\def \INV@text@description@nobm {Beskrivelse}
\def \INV@text@itemprice@nobm {Enhetspris}
\def \INV@text@vat@nobm {MVA}
\def \INV@text@itemtotal@nobm {Sum}
\def \INV@text@subtotal@nobm {MVA-grunnlag}
\def \INV@text@total@nobm {Å betale}
\def \INV@text@paymentinfo@nobm {Betalingsinformasjon}
\def \INV@text@totallong@nobm {Sum å betale}
\def \INV@text@accountnum@nobm {Kontonummer}
\def \INV@text@warning@nobm {Ved betaling etter forfall kan det påløpe renter og gebyr etter statens satser. Ved innsigelse vil kravet kunne bli sendt til forliksrådet, jf. tvistelovens § 5-2.}

% Import neccesary libraries
\RequirePackage{advdate}
\RequirePackage{hyperref}
\RequirePackage{url}
\RequirePackage{tabularx}
\RequirePackage{etoolbox}
\RequirePackage{xcolor}
\RequirePackage{colortbl}
\RequirePackage{babel}

% Define colors
\definecolor{linecolor}{HTML}{b2b2b2}

% Miscellanous styling
\setlength{\tabcolsep}{0em}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}

% Links
\RequirePackage{hyperref}
\RequirePackage{url}

% Table
\RequirePackage{tabularx}

% Commands
\RequirePackage{etoolbox}

% Line seperator
\newcommand{\linesep}{\vspace{6pt} {\color{linecolor}\hrule} \vspace{6pt}}

% Standard values
\def \INV@content@num {{\color{red} No number}}
\def \INV@content@title {\csname INV@text@invoice@\INV@lang\endcsname}
\def \INV@content@date {\today}
\def \INV@content@deadline {\DayAfter[14]}
\def \INV@content@name {{\color{red} Your name}}
\def \INV@content@addr {{\color{red} Address line 1 \\ Address line 2}}
\def \INV@content@addroneline {{\color{red} Address line 1 / Address line 2}}
\def \INV@content@toname {{\color{red} Company}}
\def \INV@content@toaddr {{\color{red} Address line 1 \\ Address line 2}}
\def \INV@content@subtotal {{\color{red} Subtotal}}
\def \INV@content@vat {{\color{red} VAT}}
\def \INV@content@total {{\color{red} Total}}
\def \INV@content@accountnum {{\color{red} Bank account}}

% Functions for overriding standard values
\newcommand{\setinvoicetitle}[1]{\def \INV@content@title {#1}}
\newcommand{\setinvoicenumber}[1]{\def \INV@content@num {#1}}
\newcommand{\setreceivername}[1]{\def \INV@content@toname {#1}}
\newcommand{\setreceiveraddress}[1]{\def \INV@content@toaddr {#1}}
\newcommand{\setname}[1]{\def \INV@content@name {#1}}
\newcommand{\setaddress}[2]{\def \INV@content@addr {#1}
	\def \INV@content@addroneline {#2}
}
\newcommand{\setphonenumber}[1]{\def \INV@content@phonenum {#1}}
\newcommand{\setemail}[1]{\def \INV@content@email {\href{mailto:#1}{#1}}}
\newcommand{\setyourref}[1]{\def \INV@content@yourref {#1}}
\newcommand{\setourref}[1]{\def \INV@content@ourref {#1}}
\newcommand{\setinvoicedate}[1]{\def \INV@content@date {#1}}
\newcommand{\setdeadline}[1]{\def \INV@content@deadline {\DayAfter[#1]}}
\newcommand{\additem}[4]{\ifdef{\INV@content@list}{\appto \INV@content@list {\\ #1 & #2 & #3 \% & #4}}{\def \INV@content@list {#1 & #2 & #3 \% & #4}}}
\newcommand{\setsubtotal}[1]{\def \INV@content@subtotal {#1}}
\newcommand{\setvat}[1]{\def \INV@content@vat {#1}}
\newcommand{\settotal}[1]{\def \INV@content@total {#1}}
\newcommand{\setaccountnumber}[1]{\def \INV@content@accountnum {#1}}

% Make invoice function
\def \makeinvoice {
	\begin{minipage}[b]{0.5\textwidth}
		{\large \textbf{\INV@content@toname}} \\
		\INV@content@toaddr
	\end{minipage}
	\begin{minipage}[b]{0.5\textwidth}
		\hfill {\Huge \INV@content@title}
		
		\linesep
		
		{\large \textbf{\INV@content@name}} \\
		\INV@content@addr \ifdef{\INV@content@phonenum}{\\ \INV@content@phonenum}{} \ifdef{\INV@content@email}{\\ \INV@content@email}{}
		
		\linesep
		
		{ \footnotesize
			\ifdef{\INV@content@ourref}{\csname INV@text@ourref@\INV@lang\endcsname: \INV@content@ourref \\}{}
			\ifdef{\INV@content@yourref}{\csname INV@text@yourref@\INV@lang\endcsname: \INV@content@yourref \\}{}
			\csname INV@text@invnum@\INV@lang\endcsname: \INV@content@num \\
			\csname INV@text@invdate@\INV@lang\endcsname: \INV@content@date \\
			\csname INV@text@deadline@\INV@lang\endcsname: \INV@content@deadline
		}
	\end{minipage}
	
	\vspace{3cm}
	
	\renewcommand{\arraystretch}{1.5}
	\begin{tabularx}{\textwidth}{X c c r}
		\textbf{\csname INV@text@description@\INV@lang\endcsname} & \textbf{\csname INV@text@itemprice@\INV@lang\endcsname} & \hspace{10pt}\textbf{\csname INV@text@vat@\INV@lang\endcsname}\hspace{10pt} & \textbf{\csname INV@text@itemtotal@\INV@lang\endcsname} \\ \arrayrulecolor{linecolor}\hline
		\ifdef{\INV@content@list}{\INV@content@list}{{\color{red} No Items yet} & & &}
	\end{tabularx}
	
	\vspace{2cm}
	\hfill
	\renewcommand{\arraystretch}{1}
	\begin{tabular}{r r}
		\csname INV@text@subtotal@\INV@lang\endcsname: \hspace{10pt} & \INV@content@subtotal \\
		\csname INV@text@vat@\INV@lang\endcsname: \hspace{10pt} & \INV@content@vat \\ 
		{\Large \csname INV@text@total@\INV@lang\endcsname: \hspace{10pt}} & {\Large \INV@content@total}
	\end{tabular}
	
	\vfill
	
	{{\color{gray} \itshape \csname INV@text@warning@\INV@lang\endcsname} \vspace{10pt} \\
		{\huge \csname INV@text@paymentinfo@\INV@lang\endcsname}
		\linesep
		\begin{tabularx}{\textwidth}{X r}
			\csname INV@text@invnum@\INV@lang\endcsname: & \INV@content@num  \\
			\csname INV@text@totallong@\INV@lang\endcsname: & \INV@content@total \\
			\csname INV@text@accountnum@\INV@lang\endcsname: & \INV@content@accountnum 
		\end{tabularx}
		
		\vspace{1 cm}
		\linesep
		{\footnotesize \color{gray} \INV@content@name \hfill \INV@content@addroneline \ifdef{\INV@content@phonenum}{\hfill \INV@content@phonenum}{} \ifdef{\INV@content@email}{\hfill \INV@content@email}{}}}
}