From c81ac0c2cfff0fc23ba698f745de6c1197fd869d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Wed, 8 Feb 2017 17:22:52 +0100 Subject: [PATCH] add support for printing addresses in invoices --- invoice.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/invoice.rb b/invoice.rb index b911882..0aa5db6 100644 --- a/invoice.rb +++ b/invoice.rb @@ -35,9 +35,10 @@ Product = Struct.new(:id, :description, :price) do end class Person - def initialize(id, name) + def initialize(id, name, address) @id = id @name = name + @address = address @purchases = {} end @@ -46,7 +47,7 @@ class Person end attr_reader :id - attr_accessor :name, :purchases + attr_accessor :name, :purchases, :address end def read_file(file) @@ -76,7 +77,11 @@ end def load_persons_from_db(db) persons = {} db.query("SELECT * FROM Persons").each do |row| - person = Person.new(row['id'],row['name']) + address = [] + if (row['address']) + address << row['address'] + end + person = Person.new(row['id'],row['name'],address) persons[row['id']] = person if Options[:verbose] puts "Found person: #{person}" @@ -130,7 +135,7 @@ def generate_receipt(persons,products,db,draft) total_payment = 0 yaml = YAML_BASE.clone - yaml["to"] = person.name + yaml["to"] = [person.name].concat person.address yaml["invoice-nr"] = Time.now.strftime('%Y%W') + "-" + counter.to_s