diff --git a/pandoc/template.tex b/pandoc/template.tex index d7e223a..0d6f06d 100644 --- a/pandoc/template.tex +++ b/pandoc/template.tex @@ -20,6 +20,12 @@ $if(letterhead)$ \ULCornerWallPaper{1}{letterhead.pdf} $endif$ +$if(draft)$ +\usepackage{draftwatermark} +\SetWatermarkText{$drafttext$} +\SetWatermarkScale{1} +$endif$ + % TYPOGRAPHY %-------------------------------- \usepackage{fontspec} diff --git a/receipt.rb b/receipt.rb index 8533b6c..ead3fbb 100644 --- a/receipt.rb +++ b/receipt.rb @@ -84,6 +84,12 @@ def generate_receipt(skyldnere) hash = {description: PRODUCTS[product], price: PRICES[product].to_i*amount, amount: amount} yaml["service"] << Hash[hash.map{ |k, v| [k.to_s, v] }] end + + unless Date.today.sunday? + yaml["draft"] = "true" + yaml["drafttext"] = "Udkast" + end + output = Hash[yaml.map{ |k, v| [k.to_s, v] }].to_yaml output += "---\n" file = File.open("./pandoc/details.yml","w") @@ -109,6 +115,5 @@ def date_of_prev(day) date - delta end -#partition = partition_rows(read_file("./log/matkant-#{Time.now.strftime('%Y%W')}.log")) partition = partition_rows(read_db(db)) generate_receipt(partition) diff --git a/update.rb b/update.rb index 371d95d..c239d3c 100644 --- a/update.rb +++ b/update.rb @@ -11,6 +11,15 @@ log_dir = "./log/" amount = 1.0 unless amount +valid_products = [] +db.query("SELECT * FROM products").each do |product| + valid_products << product['id'] +end + +unless valid_products.include? product + raise "Product not found in table\nValid products are: #{valid_products}" +end + statement = db.prepare("INSERT INTO transactions (buyer, product, amount) VALUES (?, ?, ?)") result = statement.execute(person,product,amount) puts result