Class: Sunnyside::ManualPayment

Inherits:
Object
  • Object
show all
Includes:
Sunnyside
Defined in:
lib/sunnyside/cash_receipts/cash_receipt.rb

Constant Summary

Constants included from Sunnyside

DB, DRIVE, PRIVATE_CLIENTS, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sunnyside

access_ftp, add_denial_data, add_provider_to_ftp, add_providers, advanced_opts, cash_receipt, check_prompt, create_folders, create_tables, determine_browser, edi_parser, expiring_auth, ledger_file, parse_pdf, #payable_csv, private_clients, process_private, query, rails_server, #receivable_csv, run_mco_mltc, run_report

Constructor Details

#initialize(invoices, post_date, prov, check) ⇒ ManualPayment

Returns a new instance of ManualPayment.



130
131
132
133
134
135
136
137
138
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 130

def initialize(invoices, , prov, check)
  @denied_invoices = invoices.select { |inv| inv.include?('-d') }.map { |inv| Invoice[inv.gsub(/-d/, '')] }
  @paid_invoices   = invoices.reject { |inv| inv.include?('-d') }.map { |inv| Invoice[inv] }
  @post_date       = 
  @provider        = prov
  @check           = check
  @payment_id      = Payment.insert(check_number: check, post_date: , provider_id: prov.id)
  @total           = 0.0
end

Instance Attribute Details

#checkObject (readonly)

Returns the value of attribute check.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def check
  @check
end

#denied_invoicesObject (readonly)

Returns the value of attribute denied_invoices.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def denied_invoices
  @denied_invoices
end

Returns the value of attribute paid_invoices.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def paid_invoices
  @paid_invoices
end

#payment_idObject (readonly)

Returns the value of attribute payment_id.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def payment_id
  @payment_id
end

#post_dateObject (readonly)

Returns the value of attribute post_date.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def 
  @post_date
end

#providerObject (readonly)

Returns the value of attribute provider.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def provider
  @provider
end

#totalObject (readonly)

Returns the value of attribute total.



128
129
130
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 128

def total
  @total
end

Instance Method Details

#adjust_claim(inv) ⇒ Object



218
219
220
221
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 218

def adjust_claim(inv)
  service_sum = Service.where(payment_id: payment_id, invoice_id: inv.invoice_number).sum(:paid).round(2)
  Claim.where(invoice_id: inv.invoice_number, payment_id: payment_id).update(:paid => service_sum)
end

#check_totalObject



223
224
225
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 223

def check_total
  Claim.where(payment_id: payment_id).sum(:paid).round(2)
end

#claimsObject



161
162
163
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 161

def claims
  (denied_invoices + paid_invoices).map { |inv| Claim.where(invoice_id: inv.invoice_number, payment_id: payment_id).first }
end

#create_claim(invoice) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 165

def create_claim(invoice)
  paid =  if invoice.provider_id == 22  # for the stupid rate that village care max pays
            (invoice.amount * 0.999365).round(2)
          else
            invoice.amount
          end

  Claim.insert(
    :invoice_id   => invoice.invoice_number, 
    :client_id    => invoice.client_id, 
    :billed       => invoice.amount, 
    :paid         => paid, 
    :payment_id   => payment_id, 
    :provider_id  => invoice.provider_id
  )
end

#create_csvObject



152
153
154
155
156
157
158
159
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 152

def create_csv
  claims.each { |clm| 
    if clm.paid > 0.0 
      self.receivable_csv(clm, Payment[payment_id], ) 
    end
  }
  Payment[payment_id].update(check_total: check_total)
end

#create_services(invoice, claim_id) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 182

def create_services(invoice, claim_id)
  visits(invoice).each { |visit| 
    Service.insert(
      :invoice_id   => visit.invoice_id, 
      :payment_id   => payment_id, 
      :claim_id     => claim_id, 
      :service_code => visit.service_code, 
      :paid         => visit.amount, 
      :billed       => visit.amount, 
      :dos          => visit.dos,
      :units        => visit.units,
      :client_id    => Claim[claim_id].client_id
    )
  }
end

#edit_servicesObject



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 202

def edit_services
  denied_invoices.each { |inv| 
    services     = Service.where(invoice_id: inv.invoice_number, payment_id: payment_id)
    edit_service = EditService.new(services) 
    edit_service.show_all

    edit_service.adjust
    
    adjust_claim(inv)
  }
end

#not_fully_paid?(clm) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 148

def not_fully_paid?(clm)
  Claim.where(invoice_id: clm.invoice_id).sum(:paid).round(2) < Invoice[clm.invoice_id].amount
end

#seed_claims_and_servicesObject



140
141
142
143
144
145
146
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 140

def seed_claims_and_services
  (denied_invoices + paid_invoices).each do |invoice|
    claim_id = create_claim(invoice)
    create_services(invoice, claim_id)
  end
  edit_services if denied_invoices.length > 0
end

#visits(invoice) ⇒ Object



198
199
200
# File 'lib/sunnyside/cash_receipts/cash_receipt.rb', line 198

def visits(invoice)
  Visit.where(invoice_id: invoice.invoice_number).all
end