commit 0133798ba6af917102bea9aa37a8110fa6d58403 Author: Christoffer Müller Madsen Date: Mon Jan 30 14:06:38 2017 +0100 initial commit diff --git a/pandoc/makefile b/pandoc/makefile new file mode 100644 index 0000000..8798961 --- /dev/null +++ b/pandoc/makefile @@ -0,0 +1,10 @@ +TEX = pandoc +src = template.tex details.yml +FLAGS = --latex-engine=xelatex + +output.pdf : $(src) + $(TEX) $(filter-out $<,$^ ) -o $@ --template=$< $(FLAGS) + +.PHONY: clean +clean : + rm output.pdf diff --git a/pandoc/template.tex b/pandoc/template.tex new file mode 100644 index 0000000..c15419e --- /dev/null +++ b/pandoc/template.tex @@ -0,0 +1,149 @@ +%!TEX TS-program = xelatex +%!TEX encoding = UTF-8 Unicode + +\documentclass[$fontsize$, a4paper]{article} + +% LAYOUT +%-------------------------------- +\usepackage{geometry} +\geometry{$geometry$} + +% No page numbers +\pagenumbering{gobble} + +% Left align +\usepackage[document]{ragged2e} + +$if(letterhead)$ + % To include the letterhead + \usepackage{wallpaper} + \ULCornerWallPaper{1}{letterhead.pdf} +$endif$ + +% TYPOGRAPHY +%-------------------------------- +\usepackage{fontspec} +\usepackage{xunicode} +\usepackage{xltxtra} + +% converts LaTeX specials (quotes, dashes etc.) to Unicode +\defaultfontfeatures{Mapping=tex-text} +\setromanfont [Ligatures={Common}, Numbers={OldStyle}]{$seriffont$} +\setsansfont[Scale=0.9]{$sansfont$} + +% Set paragraph break +\setlength{\parskip}{1em} + +% Custom ampersand +\newcommand{\amper}{{\fontspec[Scale=.95]{$seriffont$}\selectfont\itshape\&}} + +$if(seriffont)$ +\setmainfont[SmallCapsFeatures={LetterSpace=5,Letters=SmallCaps}]{$seriffont$} +$endif$ +$if(sansfont)$ + \setsansfont{$sansfont$} +$endif$ + +% Command required by how Pandoc handles the list conversion +\providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} + +% TABLE CUSTOMIZATION +%-------------------------------- +\usepackage{spreadtab} +\usepackage[compact]{titlesec} % For customizing title sections +\titlespacing*{\section}{0pt}{3pt}{-7pt} % Remove margin bottom from the title +\usepackage{arydshln} % For the dotted line on the table +\renewcommand{\arraystretch}{1.5} % Apply vertical padding to table cells +\usepackage{hhline} % For single-cell borders +\usepackage{enumitem} % For customizing lists +\setlist{nolistsep} % No whitespace around list items +\setlist[itemize]{leftmargin=0.5cm} % Reduce list left indent +\setlength{\tabcolsep}{9pt} % Larger gutter between columns + + +% LANGUAGE +%-------------------------------- +$if(lang)$ +\usepackage{polyglossia} +\setmainlanguage{$lang$} +$endif$ + +% PDF SETUP +%-------------------------------- +\usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref} +\hypersetup +{ + pdfauthor=$author$, + pdfsubject=Faktura nr. $invoice-nr$, + pdftitle=Faktura nr. $invoice-nr$, + linkcolor=blue, + citecolor=blue, + filecolor=black, + urlcolor=blue +} + +% To display custom date +% \usepackage[nodayofweek]{datetime} +% \newdate{date}{01}{12}{1867} +% \date{\displaydate{date}} +% Use this instead of \today: % \displaydate{date} + +% DOCUMENT +%-------------------------------- +\begin{document} +\small +\textsc{\textbf{$author$}} +$for(from)$ +\textbullet{} \textsc{$from$} +$endfor$ + +\vspace{1em} + +\normalsize \sffamily +$for(to)$ +$to$\\ +$endfor$ + +\vspace{6em} + +\begin{flushright} + \small + $city$, \today +\end{flushright} + +\vspace{1em} + + +\section*{\textsc{Invoice} \textsc{\#$invoice-nr$}} +\footnotesize +\newcounter{pos} +\setcounter{pos}{0} +\STautoround*{2} % Get spreadtab to always display the decimal part +$if(commasep)$\STsetdecimalsep{,}$endif$ % Use comma as decimal separator + +\begin{spreadtab}{{tabular}[t t t]{lp{8.2cm}r}} + \hdashline[1pt/1pt] + @ \noalign{\vskip 2mm} \textbf{\#} & @ \textbf{Produkt} & @ \textbf{Priser i $currency$} \\ \hline + $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos + & @ $service.description$ + $if(service.details)$\newline \begin{itemize} + $for(service.details)$\scriptsize \item $service.details$ + $endfor$ \end{itemize} + $endif$ & $service.price$\\$endfor$ \noalign{\vskip 2mm} \hline + @ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(c1:[0,-1])} \\ \hhline{~~-} + @ & @ \multicolumn{1}{r}{Rabat fra kantinekort (-10\%):} & -(100-90)/100*[0,-1] \\ \hhline{~~-} + @ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-2]+[0,-1]}} \\ \hhline{~~-} +\end{spreadtab} + +\vspace{15mm} + +\sffamily +\small +$closingnote$ + +\medskip + +$author$ + +\end{document} diff --git a/receipt.rb b/receipt.rb new file mode 100644 index 0000000..117a538 --- /dev/null +++ b/receipt.rb @@ -0,0 +1,76 @@ +# coding: utf-8 +require 'CSV' +require 'yaml' + +YAML_BASE = {"invoice-nr" => "2017-01-31", "author": "Christoffer Müller Madsen", 'currency': 'DKK', 'commasep': true, 'lang': 'danish', 'seriffont': 'Hoefler Text', 'sansfont': 'Helvetica Neue', 'fontsize': '10pt', 'geometry': 'a4paper, left=43mm, right=43mm, top=51mm, bottom=17mm', 'closingnote': %Q[Please transfer the due amount to the following bank account within the next 14 days: + + Mustermann GmbH + Kreditinstitut: Deutsche Postbank AG + IBAN: DE18 3601 0043 9999 9999 99 + BIC: PBNKDEFF + + We really appreciate your business and look forward to future projects together. + + Best regards, +] } + +PATH_BASE = "./pdf/" +PRETTY_NAMES = {"papkaffe" => "Papkrus kaffe (0.35 L)", "kage" => "Kage", "spandaur" => "Spandaur"} +PRICES = {'papkaffe' => 7, "kage" => 11} +lines = {} + +class LogItem + def initialize(time,person,product,amount: 1) + @time = time + @person = person + @product = product + @amount = amount + end + attr_accessor :time, :person, :product, :amount +end + +class LineItem + def initialize(type) + @type = type + end + attr_accessor(:type) +end + +def read_file(file) + rows = Array.new + CSV.foreach(file, col_sep: ';', converters: :float) do |row| + rows << LogItem.new(row[0],row[1],row[2],amount: row[3]) + end + rows +end + +def partition_rows(rows) + skyldnere = Hash.new + rows.each do |row| + skyldnere[row.person] = Hash.new unless skyldnere[row.person] + skyldnere[row.person][row.product] = 0 unless skyldnere[row.person][row.product] + skyldnere[row.person][row.product] += row.amount + end + skyldnere +end + +def generate_receipt(skyldnere) + skyldnere.each do |person, products| + yaml = YAML_BASE.clone + yaml["to"] = person + products.each do |product, amount| + yaml["service"] = Array.new unless yaml["service"] + hash = {description: PRETTY_NAMES[product], price: PRICES[product]*amount, amount: amount} + yaml["service"] << Hash[hash.map{ |k, v| [k.to_s, v] }] + end + puts Hash[yaml.map{ |k, v| [k.to_s, v] }].to_yaml + + end +# pdf_path = PATH_BASE + "temp.pdf" + +# return pdf_path +end + +partition = partition_rows(read_file("./log/matkant.log")) +puts partition.inspect +generate_receipt(partition) diff --git a/update.rb b/update.rb new file mode 100644 index 0000000..c6078f3 --- /dev/null +++ b/update.rb @@ -0,0 +1,10 @@ +person = ARGV[0] +product = ARGV[1] +amount = ARGV[2] +log_dir = "./log/" + +amount = 1.0 unless amount + +output = File.open("#{log_dir}/matkant.log","a") +output << "#{Time.now.to_i};#{person};#{product};#{amount}\n" +output.close