add support for printing addresses in invoices
This commit is contained in:
parent
83047ea410
commit
c81ac0c2cf
13
invoice.rb
13
invoice.rb
|
@ -35,9 +35,10 @@ Product = Struct.new(:id, :description, :price) do
|
||||||
end
|
end
|
||||||
|
|
||||||
class Person
|
class Person
|
||||||
def initialize(id, name)
|
def initialize(id, name, address)
|
||||||
@id = id
|
@id = id
|
||||||
@name = name
|
@name = name
|
||||||
|
@address = address
|
||||||
@purchases = {}
|
@purchases = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ class Person
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :id
|
attr_reader :id
|
||||||
attr_accessor :name, :purchases
|
attr_accessor :name, :purchases, :address
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_file(file)
|
def read_file(file)
|
||||||
|
@ -76,7 +77,11 @@ end
|
||||||
def load_persons_from_db(db)
|
def load_persons_from_db(db)
|
||||||
persons = {}
|
persons = {}
|
||||||
db.query("SELECT * FROM Persons").each do |row|
|
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
|
persons[row['id']] = person
|
||||||
if Options[:verbose]
|
if Options[:verbose]
|
||||||
puts "Found person: #{person}"
|
puts "Found person: #{person}"
|
||||||
|
@ -130,7 +135,7 @@ def generate_receipt(persons,products,db,draft)
|
||||||
total_payment = 0
|
total_payment = 0
|
||||||
|
|
||||||
yaml = YAML_BASE.clone
|
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
|
yaml["invoice-nr"] = Time.now.strftime('%Y%W') + "-" + counter.to_s
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user