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
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/pxmyportal/agent.rb', line 37
def save_payslips
let_redirect
existing_payslips = (YAML.load_file(@payslips_path) rescue []) || []
pages = Set[PXMyPortal::Page::BONUS]
unless @bonus_only
pages << @page
end
pages.each do |page|
let_redirect(path: page.path)
payslips = payslips_for_page(page)
payslips.each do |payslip|
if !@force && existing_payslips&.find { |candidate| payslip == candidate }
@logger.info("skipping") { payslip }
next
end
path = @page.confirm_path
data = PXMyPortal::DocumentDownloader.new(
path:,
form_data: payslip.form_data,
http: @http,
logger: @logger,
).post
path = File.join(@payslip_dir, payslip.filename)
FileUtils.mkdir_p(@payslip_dir)
@logger.info("saving payslip...") { path }
File.write(path, data) unless @test
existing_payslips << payslip.metadata
end
end
File.open(payslips_path, "w") { |file| YAML.dump(existing_payslips, file) } \
unless @test
self
end
|