updated stuff

This commit is contained in:
Christoffer Müller Madsen 2017-01-30 15:23:50 +01:00
parent 0133798ba6
commit 3d18dc16e0
3 changed files with 29 additions and 33 deletions

View File

@ -105,7 +105,7 @@ $for(to)$
$to$\\ $to$\\
$endfor$ $endfor$
\vspace{6em} %\vspace{6em}
\begin{flushright} \begin{flushright}
\small \small
@ -122,18 +122,18 @@ $endfor$
\STautoround*{2} % Get spreadtab to always display the decimal part \STautoround*{2} % Get spreadtab to always display the decimal part
$if(commasep)$\STsetdecimalsep{,}$endif$ % Use comma as decimal separator $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] \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 $for(service)$ @ \noalign{\vskip 2mm} \refstepcounter{pos} \thepos
& @ $service.description$ & @ $service.description$
$if(service.details)$\newline \begin{itemize} $if(service.details)$\newline \begin{itemize}
$for(service.details)$\scriptsize \item $service.details$ $for(service.details)$\scriptsize \item $service.details$
$endfor$ \end{itemize} $endfor$ \end{itemize}
$endif$ & $service.price$\\$endfor$ \noalign{\vskip 2mm} \hline $endif$ & $service.amount$ & $service.price$\\$endfor$ \noalign{\vskip 2mm} \hline
@ & @ \multicolumn{1}{r}{Subtotal:} & :={sum(c1:[0,-1])} \\ \hhline{~~-} @ & @ \multicolumn{2}{r}{Subtotal:} & :={sum(d1:[0,-1])} \\ \hhline{~~~-}
@ & @ \multicolumn{1}{r}{Rabat fra kantinekort (-10\%):} & -(100-90)/100*[0,-1] \\ \hhline{~~-} @ & @ \multicolumn{2}{r}{Rabat fra kantinekort (-10\%):} & -(100-90)/100*[0,-1] \\ \hhline{~~~-}
@ & @ \multicolumn{1}{r}{\textbf{Total:}} & \textbf{:={[0,-2]+[0,-1]}} \\ \hhline{~~-} @ & @ \multicolumn{2}{r}{\textbf{Total:}} & \textbf{:={[0,-2]+[0,-1]}} \\ \hhline{~~~-}
\end{spreadtab} \end{spreadtab}
\vspace{15mm} \vspace{15mm}

View File

@ -2,21 +2,19 @@
require 'CSV' require 'CSV'
require 'yaml' 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 +45 81 73 02 02
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. forhånd tak.
Best regards, Med venlig hilsen
] } ] }
PATH_BASE = "./pdf/" PATH_BASE = "./pdf/"
PRETTY_NAMES = {"papkaffe" => "Papkrus kaffe (0.35 L)", "kage" => "Kage", "spandaur" => "Spandaur"} PRETTY_PRODUCTS = {"papkaffe" => "Papkrus kaffe (0.35 L)", "kage" => "Kage", "spandaur" => "Spandaur", "kaffekrus" => "Kaffe i krus (0.25 L)"}
PRICES = {'papkaffe' => 7, "kage" => 11} PRETTY_NAMES = {"Alexander" => "Alexander Munch-Hansen", "Jon" => "Jon Michael Aanes"}
PRICES = {'papkaffe' => 7, "kage" => 11, "kaffekrus" => 5}
lines = {} lines = {}
class LogItem class LogItem
@ -29,13 +27,6 @@ class LogItem
attr_accessor :time, :person, :product, :amount attr_accessor :time, :person, :product, :amount
end end
class LineItem
def initialize(type)
@type = type
end
attr_accessor(:type)
end
def read_file(file) def read_file(file)
rows = Array.new rows = Array.new
CSV.foreach(file, col_sep: ';', converters: :float) do |row| CSV.foreach(file, col_sep: ';', converters: :float) do |row|
@ -55,22 +46,27 @@ def partition_rows(rows)
end end
def generate_receipt(skyldnere) def generate_receipt(skyldnere)
counter = 0
skyldnere.each do |person, products| skyldnere.each do |person, products|
counter += 1
yaml = YAML_BASE.clone yaml = YAML_BASE.clone
yaml["to"] = person yaml["to"] = PRETTY_NAMES[person]
products.each do |product, amount| products.each do |product, amount|
yaml["invoice-nr"] = Time.now.strftime('%Y%W') + "-" + counter.to_s
yaml["service"] = Array.new unless yaml["service"] 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] }] yaml["service"] << Hash[hash.map{ |k, v| [k.to_s, v] }]
end 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 end
# pdf_path = PATH_BASE + "temp.pdf"
# return pdf_path
end end
partition = partition_rows(read_file("./log/matkant.log")) partition = partition_rows(read_file("./log/matkant-#{Time.now.strftime('%Y%W')}.log"))
puts partition.inspect
generate_receipt(partition) generate_receipt(partition)

View File

@ -5,6 +5,6 @@ log_dir = "./log/"
amount = 1.0 unless amount 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 << "#{Time.now.to_i};#{person};#{product};#{amount}\n"
output.close output.close