sunnyside 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,12 +15,11 @@ module Sunnyside
15
15
  debit = gets.chomp
16
16
  print "And finally, type in the FUND number that is used in FUND EZ: "
17
17
  fund = gets.chomp
18
- puts "---------------------------------------------------"
19
- puts "--------Please review the below information--------"
20
- puts ""
21
- puts "Name: #{provider}, Credit Account: #{credit}, Debit Account: #{debit}, Fund: #{fund}, Abbreviation: #{abbrev}"
22
- puts ""
23
- puts "---------------------------------------------------"
18
+ review = "--------Name: #{provider}, Credit Account: #{credit}, Debit Account: #{debit}, Fund: #{fund}, Abbreviation: #{abbrev}--------"
19
+ puts "Please review the below information."
20
+ puts '-' * review.length
21
+ puts review
22
+ puts '-' * review.length
24
23
  print "Is this correct? (Y for yes, N for No): "
25
24
  raise 'You have an empty field! Start over!' if [provider, credit, debit, fund, abbrev].any? { |elem| elem.empty? }
26
25
  if gets.chomp.upcase == 'Y'
@@ -35,16 +34,57 @@ module Sunnyside
35
34
  end
36
35
 
37
36
  def self.rails_server
38
- puts "Open your web browser and type in this in the address bar (and then press enter): http://localhost:3000/providers"
39
37
  puts "Please wait..."
40
- Dir.chdir("#{DRIVE}/Program Files/Mozilla Firefox")
38
+ Sunnyside.determine_browser
41
39
 
42
40
  %x(start /max http://localhost:3000/providers)
43
41
 
44
42
  puts "Web browser launched. Now launching server..."
45
-
43
+
46
44
  Dir.chdir("#{DRIVE}/sunnyside-files/sunnyside-app")
47
45
 
48
46
  %x(rails s)
49
47
  end
48
+
49
+ def self.determine_browser
50
+ if Dir.exist?("#{DRIVE}/Program Files (x86)")
51
+ Dir.chdir("#{DRIVE}/Program Files (x86)/Mozilla Firefox")
52
+ else
53
+ Dir.chdir("#{DRIVE}/Program Files/Mozilla Firefox")
54
+ end
55
+ end
56
+
57
+ def self.add_provider_to_ftp
58
+ Provider.all.each { |prov| puts "#{prov.id}: #{prov.name}"}
59
+ print "Type in the corresponding ID Number for the provider you would like to add to FTP: "
60
+
61
+ provider = Provider[gets.chomp].abbreviation
62
+
63
+ puts "You've selected #{provider}"
64
+
65
+ print "Type in the ftp address now: "
66
+ site = gets.chomp
67
+
68
+ print "Type in the username now: "
69
+ username = gets.chomp
70
+
71
+ print "Type in the password now: "
72
+ password = gets.chomp
73
+
74
+ review = "-------Provider: #{provider}, Site: #{site}, Username: #{username}, Password: #{password}--------------"
75
+ puts "Please review the following information: "
76
+ puts '-' * review.length
77
+ puts review
78
+ puts '-' * review.length
79
+
80
+ puts "Is this correct? Type Y or N."
81
+ if gets.chomp.downcase == 'y'
82
+ Login.insert(site: site, username: username, password: password, provider: provider)
83
+ Dir.mkdir("#{DRIVE}/sunnyside-files/ftp/835/#{provider}")
84
+ Dir.mkdir("#{DRIVE}/sunnyside-files/ftp/837/#{provider}")
85
+ else
86
+ puts 'Please try again.'
87
+ Sunnyside.add_provider_to_ftp
88
+ end
89
+ end
50
90
  end
@@ -62,9 +62,10 @@ module Sunnyside
62
62
  end
63
63
  end
64
64
 
65
- def invoices_exist?(invoices)
66
- invoices.map { |invoice| invoice.gsub(/-d/, '') }.all? { |invoice| !Invoice[invoice].nil? }
67
- end
65
+ end
66
+
67
+ def invoices_exist?(invoices)
68
+ invoices.map { |invoice| invoice.gsub(/-d/, '') }.all? { |invoice| !Invoice[invoice].nil? }
68
69
  end
69
70
 
70
71
  def provider
@@ -108,12 +109,14 @@ module Sunnyside
108
109
  puts "----------------------------------------------------------------------------------------------------------"
109
110
  end
110
111
 
112
+
113
+
111
114
  def not_fully_paid?(clm)
112
115
  Claim.where(invoice_id: clm.invoice_id).sum(:paid).round(2) < clm.paid
113
116
  end
114
117
 
115
118
  def denied_services
116
- Service.where(payment_id: payment.id).exclude(denial_reas on: nil).count
119
+ Service.where(payment_id: payment.id).exclude(denial_reason: nil).count
117
120
  end
118
121
  end
119
122
 
@@ -140,16 +143,17 @@ module Sunnyside
140
143
  end
141
144
 
142
145
  def not_fully_paid?(clm)
143
- Claim.where(invoice_id: clm.invoice_id).sum(:paid).round(2) < clm.paid
146
+ Claim.where(invoice_id: clm.invoice_id).sum(:paid).round(2) < Invoice[clm.invoice_id].amount
144
147
  end
145
148
 
146
149
  def create_csv
147
150
  claims.each { |clm|
148
- if clm.paid > 0.0 && !not_fully_paid?(clm)
151
+ if clm.paid > 0.0
149
152
  puts "-----------------------Total so far: #{total += clm.paid}"
150
153
  self.receivable_csv(clm, Payment[payment_id], post_date)
151
154
  end
152
155
  }
156
+ Payment[payment_id].update(check_total: check_total)
153
157
  end
154
158
 
155
159
  def claims
@@ -157,11 +161,17 @@ module Sunnyside
157
161
  end
158
162
 
159
163
  def create_claim(invoice)
164
+ paid = if invoice.provider_id == 22 # for the stupid rate that village care max pays
165
+ (invoice.amount * 0.999365).round(2)
166
+ else
167
+ invoice.amount
168
+ end
169
+
160
170
  Claim.insert(
161
171
  :invoice_id => invoice.invoice_number,
162
172
  :client_id => invoice.client_id,
163
173
  :billed => invoice.amount,
164
- :paid => invoice.amount,
174
+ :paid => paid,
165
175
  :payment_id => payment_id,
166
176
  :provider_id => invoice.provider_id
167
177
  )
@@ -207,6 +217,10 @@ module Sunnyside
207
217
  service_sum = Service.where(payment_id: payment_id, invoice_id: inv.invoice_number).sum(:paid).round(2)
208
218
  Claim.where(invoice_id: inv.invoice_number, payment_id: payment_id).update(:paid => service_sum)
209
219
  end
220
+
221
+ def check_total
222
+ Claim.where(payment_id: payment.id).sum(:paid).round(2)
223
+ end
210
224
  end
211
225
 
212
226
  class EditService
data/lib/sunnyside/ftp.rb CHANGED
@@ -3,12 +3,11 @@ require 'rubygems'
3
3
 
4
4
  module Sunnyside
5
5
  def self.access_ftp
6
- CSV.foreach("#{DRIVE}/sunnyside-files/ftp/login.csv") do |row|
7
- access = SunnyFTP.new(username: row[1], password: row[2], provider: row[0])
6
+ Login.all.each do |login|
7
+ access = SunnyFTP.new(site: login.site, username: login.username, password: login.password, provider: login.provider)
8
8
  access.log_on
9
9
  puts "Logged into #{access.name}..."
10
- access.download_files
11
- access.upload_files
10
+ access.check_for_new_files
12
11
  end
13
12
  end
14
13
 
@@ -16,7 +15,7 @@ module Sunnyside
16
15
  attr_reader :ftp, :username, :password, :name, :directory
17
16
 
18
17
  def initialize(login = {})
19
- @ftp = Net::FTP.new('depot.per-se.com')
18
+ @ftp = Net::FTP.new(login[:site])
20
19
  @username = login[:username]
21
20
  @password = login[:password]
22
21
  @name = login[:provider]
@@ -26,65 +25,100 @@ module Sunnyside
26
25
  ftp.login(username, password)
27
26
  end
28
27
 
29
- def empty?(folder)
30
- ftp.list(folder) == ["total 0"]
28
+ def check_for_new_files
29
+ ftp.chdir("../outgoing")
30
+ incoming = IncomingFiles.new(ftp, name)
31
+ incoming.download_files
32
+
33
+ ftp.chdir("../incoming")
34
+ outgoing = OutgoingFiles.new(ftp, name)
35
+ outgoing.upload_files
36
+
37
+ puts "Exiting #{name}..."
38
+ ftp.close
39
+ end
40
+
41
+
42
+ def new_files
43
+ files.map { |file| timestamp(file) + "-#{file}" }.select { |file| provider_folder.include?(timestamp(file)) }.size > 0
44
+ end
45
+ end
46
+
47
+ class IncomingFiles < SunnyFTP
48
+ attr_reader :file_records, :ftp_files, :ftp, :name
49
+
50
+ def initialize(ftp, name)
51
+ @file_records = Dir["#{DRIVE}/sunnyside-files/ftp/835/#{name}/*.pgp"].map { |file| File.basename(file).gsub(/^.{11}/, '') }
52
+ @ftp_files = ftp.nlst.select { |file| file.include?('835') }
53
+ @ftp = ftp
54
+ @name = name
31
55
  end
32
56
 
33
- def outgoing_contents
34
- ftp.nlst('../outgoing') if empty?('../outgoing')
57
+ def new_files
58
+ ftp_files.select { |file| !file_records.include?(file) }
35
59
  end
36
60
 
37
- def download_folder
38
- ftp.chdir('../outgoing')
39
- if ftp.nlst.size == 0
40
- puts "No files found. Exiting..."
41
- ftp.close
42
- return []
61
+ def download_files
62
+ if new_files.size > 0
63
+ new_files.each { |file| download_file(file) }
43
64
  else
44
- return ftp.nlst
65
+ puts "No new files to download."
45
66
  end
46
67
  end
47
68
 
48
- def up_files
49
- Dir["#{DRIVE}/sunnyside-files/ftp/837/#{name}/*.txt"]
69
+ def timestamp(file)
70
+ ftp.mtime(file).strftime('%Y-%m-%d') + "-#{File.basename(file)}"
50
71
  end
51
72
 
52
- def upload_files
53
- up_files.each { |file|
54
- if file.include?(name)
55
- puts "uploading #{file} for #{name}"
56
- ftp.putbinaryfile(file)
57
- puts "Upload complete."
58
- puts "deleting #{file} in local folder."
59
- FileUtils.mv(file, "#{DRIVE}/sunnyside-files/ftp/837/#{name}/#{File.basename(file)}")
60
- end
61
- }
62
- ftp.close
73
+ def download_file(file)
74
+ puts "Downloading #{file}..."
75
+ ftp.getbinaryfile(file, "#{DRIVE}/sunnyside-files/ftp/835/#{name}/#{timestamp(file)}")
63
76
  end
77
+ end
64
78
 
65
- def provider_folder
66
- Dir["#{DRIVE}/sunnyside-files/ftp/835/#{name}"].map { |file| File.basename(file) }
67
- end
79
+ class OutgoingFiles < SunnyFTP
80
+ attr_reader :ftp, :name
68
81
 
69
- def new_file?(file)
70
- provider_folder.include?(file)
82
+ def initialize(ftp, name)
83
+ @name = name
84
+ @ftp = ftp
71
85
  end
72
86
 
73
- def timestamp(file)
74
- ftp.mtime(file).strftime('%Y-%m-%d')
87
+ def new_files
88
+ Dir["#{DRIVE}/sunnyside-files/ftp/837/#{name}/*.txt"]
75
89
  end
76
90
 
77
- def download_files
78
- download_folder.each do |file|
79
- if !provider_folder.include?(file)
80
- if file.include?('835')
81
- puts "Downloading #{file}..."
82
- ftp.getbinaryfile(file, "#{DRIVE}/sunnyside-files/ftp/835/#{name}/#{timestamp(file)}-#{file}")
83
- puts "#{file} placed, dated: #{timestamp(file)}."
84
- end
85
- end
91
+ def upload_files
92
+ if new_files.size > 0
93
+ new_files.each { |file| upload_file(file) }
94
+ else
95
+ puts "No new files to upload."
86
96
  end
87
- ftp.close
97
+ end
98
+
99
+ def upload_file(file)
100
+ ftp.putbinaryfile(file)
101
+ puts "#{file} uploaded."
102
+ puts "Deleting local file..."
103
+ File.delete(file)
104
+ puts "File deleted."
88
105
  end
89
106
  end
90
107
  end
108
+
109
+ # def up_files
110
+ # Dir["#{DRIVE}/sunnyside-files/ftp/837/#{name}/*.txt"]
111
+ # end
112
+
113
+ # def upload_files
114
+ # up_files.each { |file|
115
+ # if file.include?(name)
116
+ # puts "uploading #{file} for #{name}"
117
+ # ftp.putbinaryfile(file)
118
+ # puts "Upload complete."
119
+ # puts "deleting #{file} in local folder."
120
+ # FileUtils.mv(file, "#{DRIVE}/sunnyside-files/ftp/837/#{name}/#{File.basename(file)}")
121
+ # end
122
+ # }
123
+ # ftp.close
124
+ # end
@@ -2,7 +2,8 @@ require 'prawn'
2
2
  module Sunnyside
3
3
  # This should be redone.
4
4
  def self.ledger_file
5
- Dir["#{DRIVE}/sunnyside-files/summary/*.PDF"].each {|file|
5
+ files = Dir["#{DRIVE}/sunnyside-files/summary/*.PDF"]
6
+ files.each do |file|
6
7
  if Filelib.where(filename: file).count == 0
7
8
  puts "processing #{file}..."
8
9
  ledger = Ledger.new(file)
@@ -11,7 +12,29 @@ module Sunnyside
11
12
  FileUtils.mv(file, "#{DRIVE}/sunnyside-files/summary/archive/#{File.basename(file)}")
12
13
  ledger.export_to_csv
13
14
  end
14
- }
15
+ end
16
+
17
+ if files.size == 0
18
+ puts "It appears there are no new files to process. Do you wish to create a csv file for a specific post date? (Y or N) "
19
+ if gets.chomp.downcase == 'y'
20
+ print "enter the date (YYYY-MM-DD): "
21
+ post_date = Date.parse(gets.chomp)
22
+ puts "File being created..."
23
+ LedgerReport.new(post_date)
24
+ end
25
+ end
26
+ end
27
+
28
+ class LedgerReport
29
+ include Sunnyside
30
+
31
+ def initialize(post_date)
32
+ create_report(post_date)
33
+ end
34
+
35
+ def create_report(post_date)
36
+ Invoice.where(post_date: post_date).all.each { |inv| self.payable_csv(inv, post_date) }
37
+ end
15
38
  end
16
39
 
17
40
  class Ledger
@@ -35,7 +58,7 @@ module Sunnyside
35
58
  end
36
59
 
37
60
  def export_to_csv
38
- CSV.open("#{DRIVE}/sunnyside-files/new-ledger/#{inv.post_date}-IMPORT-FUND-EZ-LEDGER.csv", "a+") { |row| row << ['Seq','inv','post_date','other id','prov','invoice','header memo','batch','doc date','detail memo','fund','account','cc1','cc2','cc3','debit','credit'] }
61
+ CSV.open("#{DRIVE}/sunnyside-files/new-ledger/#{post_date}-IMPORT-FUND-EZ-LEDGER.csv", "a+") { |row| row << ['Seq','inv','post_date','other id','prov','invoice','header memo','batch','doc date','detail memo','fund','account','cc1','cc2','cc3','debit','credit'] }
39
62
  Invoice.where(post_date: post_date).all.each { |inv| self.payable_csv(inv, post_date) }
40
63
  end
41
64
  end
@@ -9,10 +9,12 @@ module Sunnyside
9
9
  puts " 5.) CASH RECEIPT IMPORT"
10
10
  puts " 6.) ACCESS FTP"
11
11
  puts " 7.) EXPIRING AUTHORIZATION REPORT"
12
+ puts " 8.) EXPORT PRIVATE CLIENT PDF'S"
12
13
  puts " 9.) MCO - MLTC HOURS UPDATE"
13
14
  puts "10.) CUSTOM QUERY"
14
15
  puts "11.) ADD A NEW PROVIDER"
15
16
  puts "12.) VIEW DATABASE ON WEB BROWSER"
17
+ puts "13.) ADD LOGIN CREDENTIALS FOR NEW FTP EDI FILE TRANSFER"
16
18
  print "select option: "
17
19
  case gets.chomp
18
20
  when '1'
@@ -31,7 +33,7 @@ module Sunnyside
31
33
  when '7'
32
34
  Sunnyside.show_opts
33
35
  when '8'
34
- Sunnyside.process_private
36
+ Sunnyside.private_clients
35
37
  when '9'
36
38
  Sunnyside.run_mco_mltc
37
39
  when '10'
@@ -40,6 +42,8 @@ module Sunnyside
40
42
  Sunnyside.advanced_opts
41
43
  when '12'
42
44
  Sunnyside.rails_server
45
+ when '13'
46
+ Sunnyside.add_provider_to_ftp
43
47
  else
44
48
  exit
45
49
  end
@@ -1,25 +1,6 @@
1
1
  module Sunnyside
2
2
 
3
3
  class << self
4
-
5
- def create_ftp_login_data
6
- CSV.open("#{DRIVE}/sunnyside-files/ftp/login.csv", 'a+') do |row|
7
- print "How many providers do you want to enter? "
8
- gets.chomp.to_i.times do
9
- print 'Enter in the name of the provider (please omit the use of special characters - make it a single word, if possible): '
10
- provider = gets.chomp.upcase
11
- puts "Enter in the username and the password for #{provider}, each seperated by a single space."
12
- username, pass = gets.chomp.split
13
-
14
- row << [provider, username, pass]
15
-
16
- if !Dir.exist?("#{DRIVE}/sunnyside-files/ftp/#{provider}")
17
- ["#{provider}" ,"#{provider}/835", "#{provider}/837"].each { |prov| Dir.mkdir("#{DRIVE}/sunnyside-files/ftp/#{prov}/") }
18
- end
19
- end
20
- end
21
- end
22
-
23
4
  def create_folders
24
5
  folders = ['db', '835', '837', 'summary', 'cash_receipts', 'new-ledger', 'private', 'private/archive',
25
6
  'summary/archive', '837/archive', '835/archive', 'ftp', 'ftp/837', 'ftp/837/GUILDNET', 'ftp/837/CPHL', 'ftp/837/ELDERSERVE',
@@ -160,7 +141,7 @@ module Sunnyside
160
141
  end
161
142
 
162
143
  def add_denial_data
163
- CSV.foreach('examples/denial_data.csv', 'r') { |row| DB[:denials].insert(denial_code: row[0], denial_explanation: row[1]) }
144
+ # CSV.foreach('examples/denial_data.csv', 'r') { |row| DB[:denials].insert(denial_code: row[0], denial_explanation: row[1]) }
164
145
  end
165
146
 
166
147
  def add_providers
@@ -10,4 +10,5 @@ module Sunnyside
10
10
  class Provider < Sequel::Model; end
11
11
  class Visit < Sequel::Model; end
12
12
  class Denial < Sequel::Model; end
13
+ class Login < Sequel::Model; end
13
14
  end
@@ -2,34 +2,35 @@ module Sunnyside
2
2
  PRIVATE_CLIENTS = ['TABICKMAN', 'JIBAJA', 'SUNNYSIDE COMMUNITY', 'BARROW', 'JENSEN']
3
3
 
4
4
  def self.private_clients
5
- Dir['private/*.PDF'].each { |file| PrivateClient.new(file).create_pdfs }
5
+ Dir.mkdir("#{DRIVE}/sunnyside-files/pdf-reports/private") if !Dir.exist?("#{DRIVE}/sunnyside-files/pdf-reports/private")
6
+
7
+ file = Dir["#{DRIVE}/sunnyside-files/private/archive/*.PDF"].last
8
+ post_date = Date.parse(File.basename(file)[0..7])
9
+ Invoice.where(post_date: post_date, provider_id: 16).all.each { |inv| puts "#{inv.client_id} #{Client[inv.client_id].client_name}"}
10
+ puts "Type in the IDs next to the client's name, each separated by a space. "
11
+ clients = gets.chomp.split.map { |client| Client[client].client_name }.push('SUNNYSIDE COMMUNITY')
12
+
13
+ private_client = PrivateClient.new(file, post_date)
14
+ clients.each { |client| private_client.create_doc(client) }
6
15
  end
7
16
 
8
17
  class PrivateClient
9
- attr_reader :file
18
+ attr_reader :file, :post_date
10
19
 
11
- def initialize(file)
12
- @file = file
13
- @selected = []
20
+ def initialize(file, post_date)
21
+ @file = file
22
+ @post_date = post_date
14
23
  end
15
24
 
16
25
  def selected_pages(name)
17
26
  PDF::Reader.new(file).pages.select { |page| page.text.include?(name) && page.text.include?('Client Copy') }.map { |page| page.number }
18
27
  end
19
28
 
20
- def date_parse
21
- Date.parse(file[8..15])
22
- end
23
-
24
29
  def create_doc(client)
25
- Prawn::Document.generate("./private/archive/#{client}-#{date_parse}.PDF", :skip_page_creation => true) { |pdf|
30
+ Prawn::Document.generate("#{DRIVE}/sunnyside-files/pdf-reports/private/#{client}-#{post_date}.PDF", :skip_page_creation => true) { |pdf|
26
31
  selected_pages(client).each { |page| pdf.start_new_page(:template => file, :template_page => page) }
27
32
  }
28
- puts 'files created in ../private/archive/'
29
- end
30
-
31
- def create_pdfs
32
- PRIVATE_CLIENTS.each { |client| create_doc(client) }
33
+ puts "file #{client}-#{post_date}.PDF created in #{DRIVE}/sunnyside-files/pdf-reports/private"
33
34
  end
34
35
  end
35
- end
36
+ end
@@ -100,16 +100,18 @@ module Sunnyside
100
100
  Payment.where(provider_id: provider.id).all.each { |check| puts "#{check.id}: Number - #{check.check_number} Amount - #{check.check_total}"}
101
101
  print "Type in the Check ID: "
102
102
 
103
- payment = Payment[gets.chomp]
103
+ payments = gets.chomp.split.map { |chk| Payment[chk] }
104
104
 
105
105
  # For ICS checks, since for some reason the check number doesn't match the EDI TRN field.
106
106
 
107
- if payment.provider_id == 12
108
- print "type in the correct ICS check #: "
109
- Payment.update(:check_number => gets.chomp)
110
- end
107
+ payments.each do |payment|
108
+ if payment.provider_id == 12
109
+ print "type in the correct ICS check #: "
110
+ payment.update(:check_number => gets.chomp)
111
+ end
111
112
 
112
- yield payment
113
+ yield payment
114
+ end
113
115
  end
114
116
 
115
117
  end
@@ -1,3 +1,3 @@
1
1
  module Sunnyside
2
- VERSION = "0.0.8" # stupid, no-good, lousy rubygems not letting me yank my bad install. grumble grumble...
2
+ VERSION = "0.0.9" # stupid, no-good, lousy rubygems not letting me yank my bad install. grumble grumble...
3
3
  end
data/lib/sunnyside.rb CHANGED
@@ -22,7 +22,6 @@ module Sunnyside
22
22
  DRIVE = ENV["HOMEDRIVE"]
23
23
 
24
24
  Sunnyside.create_folders if !Dir.exist?("#{DRIVE}/sunnyside-files")
25
- Sunnyside.create_ftp_login_data if !File.exist?("#{DRIVE}/sunnyside-files/ftp/login.csv")
26
25
  Dir.chdir("R:/Departments/AR Department")
27
26
  DB = Sequel.connect("sqlite://sunnyside.db")
28
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunnyside
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2014-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3