Class: ErpInvoicing::ErpApp::Organizer::BillPay::AccountsController

Inherits:
ErpApp::Organizer::BaseController
  • Object
show all
Defined in:
app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb

Defined Under Namespace

Classes: Helper

Instance Method Summary collapse

Instance Method Details

#generate_statementObject



147
148
149
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 147

def generate_statement

end

#get_billing_account_amountsObject



150
151
152
153
154
155
156
157
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 150

def 
   = []
   = BillingAccount.find(params["billing_account_id"])
  amount = params[:total_payment]
   << {:billing_account => , :amount => amount, :short_payment => (amount.to_d < .balance)}

  
end

#helpObject



12
13
14
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 12

def help
  Helper.instance
end

#indexObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 16

def index
  accounts = {:totalCount => 1, :accounts => [{
        :id => 1,
        :account_number => '123455667',
        :payment_due => help.number_to_currency(33.45),
        :billing_date => '10/31/2011',
        :due_date => '11/15/2011',
        :account_id => 1,
        :party_id => 1
      }]}

  render :json => accounts
end

#make_payment_on_accountObject



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
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
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 47

def 
  #get configuration

  @message = nil

  #get subscription selection if it is there
  @subscription_selection = get_subscription_selection if params[:subscription_selection]

  #get convenience_fee if it is there
  @convenience_fee = get_convenience_fee if params[:convenience_fee]

  #get additional payments
  #@aditional_payments = get_additional_payments

  @billing_account_payment_amts = 
  Rails.logger.debug("##### Billing Acct Payments: #{@billing_account_payment_amts}")
  @payment_account_root = BizTxnAcctRoot.find(params[:payment_account_id])
  @payment_account = @payment_account_root.
  @payment_date = params[:payment_date]
  @total_payment = params[:total_payment]

  money = Money.create(
    :amount => @total_payment.to_d,
    :description => "Online Payment",
    :currency => Currency.usd
  )
  financial_txn = FinancialTxn.create(
    :apply_date => Date.strptime(@payment_date,"%m/%d/%Y"),
    :money => money
  )
  financial_txn.description = "Online Payment"
  financial_txn. = @payment_account_root
  financial_txn.save

  @billing_account_payment_amts.each do |hash|
    amount = hash[:amount].to_d rescue 0
    if amount > 0
      comment = (params[:short_payment_comment] and hash[:short_payment]) ? params[:short_payment_comment] : nil
      PaymentApplication.create(
        :financial_txn => financial_txn,
        :payment_applied_to => hash[:billing_account],
        :money => Money.create(:amount => amount),
        :comment => comment
      )
    end
  end

  #if financial_txn.apply_date == Date.today
  case @payment_account.class.to_s
    when "BankAccount"
      financial_txn.txn_type = BizTxnType.ach_sale
      financial_txn.save
      
      if financial_txn.apply_date == Date.today
        result = @payment_account.purchase(financial_txn, ErpCommerce::Config.active_merchant_gateway_wrapper)
        if !result[:payment].nil? and result[:payment].success
          @authorization_code = result[:payment].authorization_code
        else
          @message = result[:message]
        end
      end
    when "CreditCardAccount"
      financial_txn.txn_type = BizTxnType.cc_sale
      financial_txn.save
      
      if financial_txn.apply_date == Date.today
        result = @payment_account.purchase(financial_txn, params[:cvv], ErpCommerce::Config.active_merchant_gateway_wrapper)
        if !result[:payment].nil? and result[:payment].success
          @authorization_code = result[:payment].authorization_code
        else
          @message = result[:message]
        end
      end
  end
  

  if @message.nil?
    render :json => {:success => true, :message => "Payment Successful!" }
  else 
    render :json => {:success => false, :message => @message }
  end
end

#payment_accountsObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 130

def payment_accounts
  party = Party.find(params[:party_id])

  results = party.accounts.map do |acct|
    if acct.biz_txn_acct_type == "CreditCardAccount" || acct.biz_txn_acct_type == 'BankAccount'
      { :id => acct.id,
        :description => acct.description,
        :account_type => acct.biz_txn_acct_type
      }
    end
  end

  results.reject!{|x| x.nil?}

  render :json => results
end

#transactionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb', line 30

def transactions
  transactions = {:totalCount => 2, :transactions => [
      {
        :date => '10/10/2011',
        :description => 'Monthly Billing Amount',
        :amount => help.number_to_currency(50.00)
      },
      {
        :date => '10/15/2011',
        :description => 'Payment Recieved',
        :amount => help.number_to_currency(-50.00)
      }
    ]}

  render :json => transactions
end