54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/gitquickbooks/cli.rb', line 54
def process
path = File.expand_path(options.file)
start_date = Date.parse(options.start_on)
end_date = Date.today
GitWakaTime.config.setup_local_db
api = GitQuickBooks::Api.new
@time_service = Quickbooks::Service::TimeActivity.new
@time_service.access_token = api.access_token
@time_service.company_id = api.realm
@customer_service = Quickbooks::Service::Customer.new
@customer_service.access_token = api.access_token
@customer_service.company_id = api.realm
customer = @customer_service.fetch_by_id(options.customer)
puts "running for #{customer.display_name} for #{start_date} #{end_date}".blue
return unless customer
@total_time = 0
controller = GitWakaTime::Controller.new(path: path, date: start_date)
@timer = controller.timer
@slips = @timer.map do |date, commits|
next unless date >= start_date
next unless date <= end_date
commits = commits.reject { |c| c.message.to_s.downcase.delete(' ').include?('nocharge') }
total_time = commits.map(&:time_in_seconds).compact.reduce(&:+) || 0
recorded_time = GitWakaTime::Heartbeat.where(
'DATE(time) >= ? and DATE(time) <= ? ', date.to_time.utc.to_date, date.to_time.utc.to_date
).where(project: controller.project).sum(:duration) || 0
msgs = commits.map(&:message)
message = CommitMsgCleaner.new(msgs).call
@total_time += total_time
hours = (total_time / 60.0 / 60).floor
minutes = (total_time / 60.0).remainder(60).ceil
GitWakaTime::Log.new format(
'%-100s %-30s %-30s %30s'.purple,
date,
"Recorded #{ChronicDuration.output recorded_time}",
"Commited #{ChronicDuration.output total_time}",
seconds_to_money(total_time, rate: options.rate)
)
message.split("\n").each do |msg_line|
GitWakaTime::Log.new format(
'%-120s'.green,
msg_line
)
end
slip = Quickbooks::Model::TimeActivity.new
slip.txn_date = date
slip.customer_id = options.customer
slip.name_of = 'Employee'
slip.employee_id = 196
slip.billable_status = 'Billable' slip.taxable = false
slip.hours = hours
slip.hourly_rate = options.rate
slip.minutes = minutes
slip.description = message
slip
end
GitWakaTime::Log.new format(
'%-120s %-30s %30s'.red,
"#{@slips.size} slips",
"Total #{ChronicDuration.output @total_time}",
seconds_to_money(@total_time, rate: options.rate)
)
return unless options.add_to_qb
@slips.compact.each do |slip|
next unless ((slip.hours * 60) + slip.minutes) > 0
puts 'Saving Slip'
@time_service.create(slip)
end
end
|