From 3d18dc16e096d9e57665be6121496e0a11c7c9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Mon, 30 Jan 2017 15:23:50 +0100 Subject: [PATCH] updated stuff --- pandoc/template.tex | 14 +++++++------- receipt.rb | 46 +++++++++++++++++++++------------------------ update.rb | 2 +- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/pandoc/template.tex b/pandoc/template.tex index c15419e..d7e223a 100644 --- a/pandoc/template.tex +++ b/pandoc/template.tex @@ -105,7 +105,7 @@ $for(to)$ $to$\\ $endfor$ -\vspace{6em} +%\vspace{6em} \begin{flushright} \small @@ -122,18 +122,18 @@ $endfor$ \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}} +\begin{spreadtab}{{tabular}[t t t t]{lp{7.2cm}cr}} \hdashline[1pt/1pt] - @ \noalign{\vskip 2mm} \textbf{\#} & @ \textbf{Produkt} & @ \textbf{Priser i $currency$} \\ \hline + @ \noalign{\vskip 2mm} \textbf{\#} & @ \textbf{Produkt} & @ \textbf{Antal} & @ \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{~~-} + $endif$ & $service.amount$ & $service.price$\\$endfor$ \noalign{\vskip 2mm} \hline + @ & @ \multicolumn{2}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\ \hhline{~~~-} + @ & @ \multicolumn{2}{r}{Rabat fra kantinekort (-10\%):} & -(100-90)/100*[0,-1] \\ \hhline{~~~-} + @ & @ \multicolumn{2}{r}{\textbf{Total:}} & \textbf{:={[0,-2]+[0,-1]}} \\ \hhline{~~~-} \end{spreadtab} \vspace{15mm} diff --git a/receipt.rb b/receipt.rb index 117a538..2d1bd51 100644 --- a/receipt.rb +++ b/receipt.rb @@ -2,21 +2,19 @@ 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: +YAML_BASE = {"author": "Christoffer Müller Madsen", "city": "Aarhus", "from": ["Falstersgade 18, 4. th", "8000 Aarhus C"], '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[Overfør venligst det anførte beløb via MobilePay til følgende telefonnummer i løbet af de næste 14 dage: - Mustermann GmbH - Kreditinstitut: Deutsche Postbank AG - IBAN: DE18 3601 0043 9999 9999 99 - BIC: PBNKDEFF + +45 81 73 02 02 - We really appreciate your business and look forward to future projects together. +På forhånd tak. - Best regards, +Med venlig hilsen ] } PATH_BASE = "./pdf/" -PRETTY_NAMES = {"papkaffe" => "Papkrus kaffe (0.35 L)", "kage" => "Kage", "spandaur" => "Spandaur"} -PRICES = {'papkaffe' => 7, "kage" => 11} +PRETTY_PRODUCTS = {"papkaffe" => "Papkrus kaffe (0.35 L)", "kage" => "Kage", "spandaur" => "Spandaur", "kaffekrus" => "Kaffe i krus (0.25 L)"} +PRETTY_NAMES = {"Alexander" => "Alexander Munch-Hansen", "Jon" => "Jon Michael Aanes"} +PRICES = {'papkaffe' => 7, "kage" => 11, "kaffekrus" => 5} lines = {} class LogItem @@ -29,13 +27,6 @@ class LogItem 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| @@ -55,22 +46,27 @@ def partition_rows(rows) end def generate_receipt(skyldnere) + counter = 0 skyldnere.each do |person, products| + counter += 1 yaml = YAML_BASE.clone - yaml["to"] = person + yaml["to"] = PRETTY_NAMES[person] products.each do |product, amount| + yaml["invoice-nr"] = Time.now.strftime('%Y%W') + "-" + counter.to_s yaml["service"] = Array.new unless yaml["service"] - hash = {description: PRETTY_NAMES[product], price: PRICES[product]*amount, amount: amount} + hash = {description: PRETTY_PRODUCTS[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 - + output = Hash[yaml.map{ |k, v| [k.to_s, v] }].to_yaml + output += "---\n" + file = File.open("./pandoc/details.yml","w") + file << output + file.close + `cd pandoc/; make -B` + `cp pandoc/output.pdf pdf/#{yaml["invoice-nr"]}.pdf` + puts "#{person}: #{yaml["invoice-nr"]}.pdf" end -# pdf_path = PATH_BASE + "temp.pdf" - -# return pdf_path end -partition = partition_rows(read_file("./log/matkant.log")) -puts partition.inspect +partition = partition_rows(read_file("./log/matkant-#{Time.now.strftime('%Y%W')}.log")) generate_receipt(partition) diff --git a/update.rb b/update.rb index c6078f3..0250b5d 100644 --- a/update.rb +++ b/update.rb @@ -5,6 +5,6 @@ log_dir = "./log/" amount = 1.0 unless amount -output = File.open("#{log_dir}/matkant.log","a") +output = File.open("#{log_dir}/matkant-#{Time.now.strftime('%Y%W')}.log","a+") output << "#{Time.now.to_i};#{person};#{product};#{amount}\n" output.close