Class: Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/contract_ltd/invoice.rb

Instance Method Summary collapse

Constructor Details

#initialize(date, total_days) ⇒ Invoice

Returns a new instance of Invoice.



32
33
34
35
36
# File 'lib/contract_ltd/invoice.rb', line 32

def initialize(date, total_days)
  @name = 'invoice'
  @date = date
  @total_days = total_days
end

Instance Method Details

#daysObject



66
67
68
# File 'lib/contract_ltd/invoice.rb', line 66

def days
  @total_days
end

#filenameObject



86
87
88
# File 'lib/contract_ltd/invoice.rb', line 86

def filename
  invoice_filename(@date)
end

#invoice_numObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/contract_ltd/invoice.rb', line 38

def invoice_num
  previous_invoice_count = Dir['invoice_*'].size
  if previous_invoice_count == 0
    puts "WARNING: NO PREVIOUS INVOICES DETECTED"
    puts "If this is the first invoice you can ignore this warning"
    puts "Otherwise make sure previous invoices are in the correct format:"
    puts "    #{timesheet_filename(@date)}"
    puts "    #{invoice_filename(@date)}"
  end
  '%03d' % (previous_invoice_count + 1)
end

#month_yearObject



50
51
52
# File 'lib/contract_ltd/invoice.rb', line 50

def month_year
  @date.to_s(:month_name_year)
end

#name(ext) ⇒ Object



82
83
84
# File 'lib/contract_ltd/invoice.rb', line 82

def name(ext)
  "#{@name}.#{ext}"
end

#rate(rate = nil) ⇒ Object



62
63
64
# File 'lib/contract_ltd/invoice.rb', line 62

def rate(rate = nil)
  @rate ||= rate
end

#subtotalObject



70
71
72
# File 'lib/contract_ltd/invoice.rb', line 70

def subtotal
  rate * days
end

#todays_dateObject



54
55
56
# File 'lib/contract_ltd/invoice.rb', line 54

def todays_date
  Date.today.to_s(:long)
end

#totalObject



78
79
80
# File 'lib/contract_ltd/invoice.rb', line 78

def total
  subtotal + vat
end

#total_hoursObject



58
59
60
# File 'lib/contract_ltd/invoice.rb', line 58

def total_hours
  @total_days * 7.5
end

#vatObject



74
75
76
# File 'lib/contract_ltd/invoice.rb', line 74

def vat
  subtotal * 0.2
end