14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/contract_ltd.rb', line 14
def self.invoice
if ARGV.empty?
puts " Create a new invoice.slim template:\n\n invoice new\n\n\n Generate a timesheet (CSV) and invoice (PDF) from existing invoice.slim template.\n\n invoice [-f] [-p] -n [-x|-i [day[am|pm]],[...]]\n -f - overwrite existing timesheet/invoice\n -n - generate timesheet/invoice for n months ago (-0 to -12)\n -x - specify days to exclude (sat/sun excluded anyway)\n -i - specify days to include\n am|pm - just the morning or afternoon was taken off (half a day)\n\n EOB\n exit\n end\n\n # Arguments (other args must be removed before days)\n @days_are_included = ARGV.delete('-i')\n @days_are_excluded = ARGV.delete('-x')\n if @days_are_included && @days_are_excluded\n puts \"Days can only be included or excluded. Not both. Specify -i or -x.\"\n exit 1\n end\n\n @overwrite = ARGV.delete('-f')\n month = (0..12).detect {|n| ARGV.delete(\"-\#{n}\") }\n if ARGV.size > 0\n @days = Hash[*(ARGV.first.split(',').map do |day|\n [day.to_i, day =~ /am|pm/ ? 0.5 : 1.0]\n end.flatten)]\n else\n @days = []\n end\n\n date = month.month.ago.beginning_of_month.to_date\n if File.exist?(timesheet_filename(date)) || File.exist?(invoice_filename(date))\n if @overwrite\n FileUtils.rm_f(timesheet_filename(date))\n FileUtils.rm_f(invoice_filename(date))\n else\n puts \"Existing timesheet and/or invoice detected for \#{date}\"\n puts \"Use -f to overwrite\"\n exit 1\n end\n end\n total_days = write_timesheet(date)\n write_pdf(Invoice.new(date, total_days))\nend\n"
|