erp_invoicing 3.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/app/models/extensions/party.rb +15 -3
  3. data/app/models/invoice.rb +33 -1
  4. data/app/models/invoice_party_role.rb +16 -0
  5. data/app/models/payment_application.rb +17 -1
  6. data/lib/erp_invoicing/engine.rb +1 -1
  7. data/lib/erp_invoicing/version.rb +6 -2
  8. metadata +31 -234
  9. data/app/assets/javascripts/erp_invoicing/application.js +0 -9
  10. data/app/assets/stylesheets/erp_invoicing/application.css +0 -7
  11. data/app/controllers/erp_invoicing/erp_app/organizer/bill_pay/accounts_controller.rb +0 -166
  12. data/app/controllers/erp_invoicing/erp_app/organizer/bill_pay/base_controller.rb +0 -22
  13. data/app/controllers/erp_invoicing/erp_app/shared/billing_accounts_controller.rb +0 -111
  14. data/app/controllers/erp_invoicing/erp_app/shared/files_controller.rb +0 -52
  15. data/app/controllers/erp_invoicing/erp_app/shared/invoices_controller.rb +0 -208
  16. data/app/controllers/erp_invoicing/sms_controller.rb +0 -156
  17. data/app/helpers/erp_invoicing/application_helper.rb +0 -4
  18. data/app/views/layouts/erp_invoicing/application.html.erb +0 -14
  19. data/db/data_migrations/20111121153349_create_bill_pay_organizer_application.rb +0 -14
  20. data/db/data_migrations/20120118181839_create_invoice_management_desktop_application.rb +0 -26
  21. data/db/data_migrations/20120229174322_add_billpay_widget.rb +0 -26
  22. data/public/javascripts/erp_app/desktop/applications/invoice_management/billing_accounts_panel.js +0 -79
  23. data/public/javascripts/erp_app/desktop/applications/invoice_management/invoices_panel.js +0 -48
  24. data/public/javascripts/erp_app/desktop/applications/invoice_management/module.js +0 -36
  25. data/public/javascripts/erp_app/organizer/applications/bill_pay/base.js +0 -146
  26. data/public/javascripts/erp_app/organizer/applications/bill_pay/extensions.js +0 -21
  27. data/public/javascripts/erp_app/organizer/applications/bill_pay/make_payment_window.js +0 -109
  28. data/public/javascripts/erp_app/organizer/applications/bill_pay/payment_accounts_grid_panel.js +0 -105
  29. data/public/javascripts/erp_app/organizer/applications/bill_pay/transactions_grid_panel.js +0 -84
  30. data/public/javascripts/erp_app/shared/add_invoice_window.js +0 -220
  31. data/public/javascripts/erp_app/shared/billing_accounts_grid_panel.js +0 -316
  32. data/public/javascripts/erp_app/shared/invoice_items_grid_panel.js +0 -152
  33. data/public/javascripts/erp_app/shared/invoices_grid_panel.js +0 -361
  34. data/public/javascripts/erp_app/shared/payments_grid_panel.js +0 -74
  35. data/spec/dummy/db/data_migrations/20101011152441_payment_gateway_actions.erp_commerce.rb +0 -28
  36. data/spec/dummy/db/data_migrations/20101014142230_financial_txn_types.erp_txns_and_accts.rb +0 -16
  37. data/spec/dummy/db/data_migrations/20110109173616_create_capability_scope_types.erp_tech_svcs.rb +0 -15
  38. data/spec/dummy/db/data_migrations/20110324010232_product_role_types.erp_products.rb +0 -24
  39. data/spec/dummy/db/data_migrations/20110509223702_add_publisher_role.knitkit.rb +0 -22
  40. data/spec/dummy/db/data_migrations/20110525001935_add_usd_currency.erp_base_erp_svcs.rb +0 -12
  41. data/spec/dummy/db/data_migrations/20110527160807_add_default_prod_avail_types.erp_products.rb +0 -27
  42. data/spec/dummy/db/data_migrations/20110605231556_create_order_party_roles.erp_orders.rb +0 -24
  43. data/spec/dummy/db/data_migrations/20110608185830_create_default_dynamic_models_and_forms.erp_forms.rb +0 -33
  44. data/spec/dummy/db/data_migrations/20110609150135_add_iso_codes.erp_base_erp_svcs.rb +0 -19
  45. data/spec/dummy/db/data_migrations/20110728201729_erp_app_setup.erp_app.rb +0 -252
  46. data/spec/dummy/db/data_migrations/20110728201730_create_desktop_app_product_manager.erp_products.rb +0 -26
  47. data/spec/dummy/db/data_migrations/20110728201731_create_desktop_app_order_manager.erp_orders.rb +0 -26
  48. data/spec/dummy/db/data_migrations/20110728201732_create_organizer_app_order_management.erp_orders.rb +0 -15
  49. data/spec/dummy/db/data_migrations/20110728201733_update_preferences.erp_app.rb +0 -53
  50. data/spec/dummy/db/data_migrations/20110802200222_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +0 -16
  51. data/spec/dummy/db/data_migrations/20110816153456_add_knitkit_application.knitkit.rb +0 -32
  52. data/spec/dummy/db/data_migrations/20110816161238_create_desktop_app_audit_log_viewer.erp_app.rb +0 -21
  53. data/spec/dummy/db/data_migrations/20110817160743_add_file_manager_application.erp_app.rb +0 -32
  54. data/spec/dummy/db/data_migrations/20110828190913_create_desktop_app_dynamic_forms.erp_forms.rb +0 -19
  55. data/spec/dummy/db/data_migrations/20110913145838_setup_compass_ae_instance.erp_base_erp_svcs.rb +0 -12
  56. data/spec/dummy/db/data_migrations/20111108183739_add_default_capabilities.erp_app.rb +0 -23
  57. data/spec/dummy/db/data_migrations/20111108183740_add_new_contact_widgets.erp_app.rb +0 -42
  58. data/spec/dummy/db/data_migrations/20111111144706_setup_audit_log_types.erp_tech_svcs.rb +0 -22
  59. data/spec/dummy/db/data_migrations/20111118182910_setup_knitkit_capabilities.knitkit.rb +0 -128
  60. data/spec/dummy/db/data_migrations/20111121153349_create_bill_pay_organizer_application.erp_invoicing.rb +0 -15
  61. data/spec/dummy/db/data_migrations/20120109173616_create_download_capability_type.erp_tech_svcs.rb +0 -14
  62. data/spec/dummy/db/data_migrations/20120118181839_create_invoice_management_desktop_application.erp_invoicing.rb +0 -27
  63. data/spec/dummy/db/data_migrations/20120127144444_create_website_role_types.knitkit.rb +0 -14
  64. data/spec/dummy/db/data_migrations/20120127150505_create_website_default_configuration.knitkit.rb +0 -73
  65. data/spec/dummy/db/data_migrations/20120127150506_add_primary_host_to_website_configuration.knitkit.rb +0 -34
  66. data/spec/dummy/db/data_migrations/20120229160222_add_userinfo_widget.erp_app.rb +0 -29
  67. data/spec/dummy/db/data_migrations/20120229174322_add_billpay_widget.erp_invoicing.rb +0 -27
  68. data/spec/dummy/db/data_migrations/20120229174343_add_orders_widget.erp_orders.rb +0 -29
  69. data/spec/dummy/db/data_migrations/20120316150424_add_is_template_to_default_website_config.knitkit.rb +0 -17
  70. data/spec/dummy/db/data_migrations/20120405193721_create_party_and_role_type_for_communication_events.erp_app.rb +0 -11
  71. data/spec/dummy/db/data_migrations/20120411180756_create_user_management_mobile_application.erp_app.rb +0 -19
  72. data/spec/dummy/db/data_migrations/20120418164215_create_configuration_management_desktop_application.erp_app.rb +0 -23
  73. data/spec/dummy/db/data_migrations/20120605154637_add_calculate_balance_strategy_types.erp_invoicing.rb +0 -21
  74. data/spec/dummy/db/data_migrations/20120809020508_update_website_and_configuration.knitkit.rb +0 -78
  75. data/spec/dummy/db/data_migrations/20120824013449_create_ticket_form.erp_forms.rb +0 -67
  76. data/spec/dummy/db/data_migrations/20121026013449_update_ticket_form.erp_forms.rb +0 -65
  77. data/spec/dummy/db/data_migrations/20121026191738_update_contact_form.erp_forms.rb +0 -27
  78. data/spec/dummy/db/data_migrations/20121116155018_create_group_relationship_and_role_types.erp_tech_svcs.rb +0 -20
  79. data/spec/dummy/db/data_migrations/20121129185611_upgrade_website_role_iid.knitkit.rb +0 -21
  80. data/spec/dummy/db/data_migrations/20121130201859_upgrade_remove_system_mgmt_app.erp_app.rb +0 -16
  81. data/spec/dummy/db/data_migrations/20121130212146_note_capabilities.erp_tech_svcs.rb +0 -24
  82. data/spec/dummy/db/data_migrations/20121218175028_create_security_management_desktop_application.erp_app.rb +0 -23
  83. data/spec/dummy/db/migrate/20121214000230_base_erp_services.erp_base_erp_svcs.rb +0 -461
  84. data/spec/dummy/db/migrate/20121214000231_base_tech_services.erp_tech_svcs.rb +0 -255
  85. data/spec/dummy/db/migrate/20121214000232_create_has_attribute_tables.erp_tech_svcs.rb +0 -39
  86. data/spec/dummy/db/migrate/20121214000233_base_app_framework.erp_app.rb +0 -276
  87. data/spec/dummy/db/migrate/20121214000234_dynamic_forms.erp_forms.rb +0 -95
  88. data/spec/dummy/db/migrate/20121214000235_create_tickets.erp_forms.rb +0 -19
  89. data/spec/dummy/db/migrate/20121214000236_upgrade_dynamic_forms_table.erp_forms.rb +0 -32
  90. data/spec/dummy/db/migrate/20121214000237_setup_knitkit.knitkit.rb +0 -316
  91. data/spec/dummy/db/migrate/20121214000238_invoicing_services.erp_invoicing.rb +0 -277
  92. data/spec/dummy/db/migrate/20121214000239_base_inventory.erp_inventory.rb +0 -91
  93. data/spec/dummy/db/migrate/20121214000240_base_inventory_indexes.erp_inventory.rb +0 -48
  94. data/spec/dummy/db/migrate/20121214000241_base_txns_and_accts.erp_txns_and_accts.rb +0 -364
  95. data/spec/dummy/db/migrate/20121214000242_agreements_services.erp_agreements.rb +0 -160
  96. data/spec/dummy/db/migrate/20121214000243_agreements_services_indexes.erp_agreements.rb +0 -52
  97. data/spec/dummy/db/migrate/20121214000244_base_orders.erp_orders.rb +0 -178
  98. data/spec/dummy/db/migrate/20121214000245_base_products.erp_products.rb +0 -234
  99. data/spec/dummy/db/migrate/20121214000246_base_products_indexes.erp_products.rb +0 -59
  100. data/spec/dummy/db/migrate/20121214000247_erp_commerce_base.erp_commerce.rb +0 -442
  101. data/spec/dummy/db/migrate/20121214000248_base_work_efforts.erp_work_effort.rb +0 -211
  102. data/spec/dummy/db/migrate/20130107181155_create_groups.erp_tech_svcs.rb +0 -19
  103. data/spec/dummy/db/migrate/20130107181156_upgrade_security.erp_tech_svcs.rb +0 -54
  104. data/spec/dummy/db/migrate/20130107181157_upgrade_security2.erp_tech_svcs.rb +0 -270
  105. data/spec/dummy/db/schema.rb +0 -2569
  106. data/spec/dummy/db/spec.sqlite3 +0 -0
  107. data/spec/dummy/log/spec.log +0 -64744
@@ -1,166 +0,0 @@
1
- module ErpInvoicing
2
- module ErpApp
3
- module Organizer
4
- module BillPay
5
- class AccountsController < ::ErpApp::Organizer::BaseController
6
-
7
- class Helper
8
- include Singleton
9
- include ActionView::Helpers::NumberHelper
10
- end
11
-
12
- def help
13
- Helper.instance
14
- end
15
-
16
- def index
17
- accounts = {:totalCount => 1, :accounts => [{
18
- :id => 1,
19
- :account_number => '123455667',
20
- :payment_due => help.number_to_currency(33.45),
21
- :billing_date => '10/31/2011',
22
- :due_date => '11/15/2011',
23
- :account_id => 1,
24
- :party_id => 1
25
- }]}
26
-
27
- render :json => accounts
28
- end
29
-
30
- def transactions
31
- transactions = {:totalCount => 2, :transactions => [
32
- {
33
- :date => '10/10/2011',
34
- :description => 'Monthly Billing Amount',
35
- :amount => help.number_to_currency(50.00)
36
- },
37
- {
38
- :date => '10/15/2011',
39
- :description => 'Payment Recieved',
40
- :amount => help.number_to_currency(-50.00)
41
- }
42
- ]}
43
-
44
- render :json => transactions
45
- end
46
-
47
- def make_payment_on_account
48
- #get configuration
49
-
50
- @message = nil
51
-
52
- #get subscription selection if it is there
53
- @subscription_selection = get_subscription_selection if params[:subscription_selection]
54
-
55
- #get convenience_fee if it is there
56
- @convenience_fee = get_convenience_fee if params[:convenience_fee]
57
-
58
- #get additional payments
59
- #@aditional_payments = get_additional_payments
60
-
61
- @billing_account_payment_amts = get_billing_account_amounts
62
- Rails.logger.debug("##### Billing Acct Payments: #{@billing_account_payment_amts}")
63
- @payment_account_root = BizTxnAcctRoot.find(params[:payment_account_id])
64
- @payment_account = @payment_account_root.account
65
- @payment_date = params[:payment_date]
66
- @total_payment = params[:total_payment]
67
-
68
- money = Money.create(
69
- :amount => @total_payment.to_d,
70
- :description => "Online Payment",
71
- :currency => Currency.usd
72
- )
73
- financial_txn = FinancialTxn.create(
74
- :apply_date => Date.strptime(@payment_date,"%m/%d/%Y"),
75
- :money => money
76
- )
77
- financial_txn.description = "Online Payment"
78
- financial_txn.account = @payment_account_root
79
- financial_txn.save
80
-
81
- @billing_account_payment_amts.each do |hash|
82
- amount = hash[:amount].to_d rescue 0
83
- if amount > 0
84
- comment = (params[:short_payment_comment] and hash[:short_payment]) ? params[:short_payment_comment] : nil
85
- PaymentApplication.create(
86
- :financial_txn => financial_txn,
87
- :payment_applied_to => hash[:billing_account],
88
- :money => Money.create(:amount => amount),
89
- :comment => comment
90
- )
91
- end
92
- end
93
-
94
- #if financial_txn.apply_date == Date.today
95
- case @payment_account.class.to_s
96
- when "BankAccount"
97
- financial_txn.txn_type = BizTxnType.ach_sale
98
- financial_txn.save
99
-
100
- if financial_txn.apply_date == Date.today
101
- result = @payment_account.purchase(financial_txn, ErpCommerce::Config.active_merchant_gateway_wrapper)
102
- if !result[:payment].nil? and result[:payment].success
103
- @authorization_code = result[:payment].authorization_code
104
- else
105
- @message = result[:message]
106
- end
107
- end
108
- when "CreditCardAccount"
109
- financial_txn.txn_type = BizTxnType.cc_sale
110
- financial_txn.save
111
-
112
- if financial_txn.apply_date == Date.today
113
- result = @payment_account.purchase(financial_txn, params[:cvv], ErpCommerce::Config.active_merchant_gateway_wrapper)
114
- if !result[:payment].nil? and result[:payment].success
115
- @authorization_code = result[:payment].authorization_code
116
- else
117
- @message = result[:message]
118
- end
119
- end
120
- end
121
-
122
-
123
- if @message.nil?
124
- render :json => {:success => true, :message => "Payment Successful!" }
125
- else
126
- render :json => {:success => false, :message => @message }
127
- end
128
- end
129
-
130
- def payment_accounts
131
- party = Party.find(params[:party_id])
132
-
133
- results = party.accounts.map do |acct|
134
- if acct.biz_txn_acct_type == "CreditCardAccount" || acct.biz_txn_acct_type == 'BankAccount'
135
- { :id => acct.id,
136
- :description => acct.description,
137
- :account_type => acct.biz_txn_acct_type
138
- }
139
- end
140
- end
141
-
142
- results.reject!{|x| x.nil?}
143
-
144
- render :json => results
145
- end
146
-
147
- def generate_statement
148
-
149
- end
150
- def get_billing_account_amounts
151
- billing_account_payment_amts = []
152
- billing_account = BillingAccount.find(params["billing_account_id"])
153
- amount = params[:total_payment]
154
- billing_account_payment_amts << {:billing_account => billing_account, :amount => amount, :short_payment => (amount.to_d < billing_account.balance)}
155
-
156
- billing_account_payment_amts
157
- end
158
-
159
- end
160
- end#BillPay
161
- end#Organizer
162
- end#ErpApp
163
- end#ErpInvoicing
164
-
165
-
166
-
@@ -1,22 +0,0 @@
1
- module ErpInvoicing
2
- module ErpApp
3
- module Organizer
4
- module BillPay
5
- class BaseController < ::ErpApp::Organizer::BaseController
6
-
7
- def menu
8
- menu = []
9
-
10
- menu << {:text => 'Bill Pay', :leaf => true, :iconCls => 'icon-creditcards', :applicationCardId => "billpay-application"}
11
-
12
- render :json => menu
13
- end
14
-
15
- end
16
- end#BillPay
17
- end#Organizer
18
- end#ErpApp
19
- end#ErpInvoicing
20
-
21
-
22
-
@@ -1,111 +0,0 @@
1
- module ErpInvoicing
2
- module ErpApp
3
- module Shared
4
- class BillingAccountsController < ::ErpApp::Desktop::BaseController
5
- @@date_format = "%m/%d/%Y"
6
-
7
- def index
8
- render :json => if request.put?
9
- update_billing_account
10
- elsif request.post?
11
- create_billing_account
12
- elsif request.get?
13
- get_billing_accounts
14
- elsif request.delete?
15
- delete_billing_account
16
- end
17
- end
18
-
19
- def get_billing_accounts
20
- result = {:success => true, :billing_accounts => [], :totalCount => 0}
21
-
22
- sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
23
- sort = sort_hash[:sort] || 'created_at'
24
- dir = sort_hash[:dir] || 'DESC'
25
- limit = params[:limit] || 50
26
- start = params[:start] || 0
27
- party_id = params[:party_id] || nil
28
-
29
- billing_accounts = (party_id.blank? ? BillingAccount.scoped.includes(:financial_txn_account) : BillingAccount.scoped.includes(:financial_txn_account => {:biz_txn_acct_root => :biz_txn_acct_party_roles}))
30
- billing_accounts = billing_accounts.where(:financial_txn_accounts => {:account_number => params[:account_number]}) unless params[:account_number].blank?
31
- billing_accounts = billing_accounts.where(:financial_txn_accounts => {:biz_txn_acct_roots => {:biz_txn_acct_party_roles => {:party_id => party_id }}}) unless party_id.blank?
32
- billing_accounts = billing_accounts.order("financial_txn_accounts.#{sort} #{dir}").limit(limit).offset(start)
33
- result[:totalCount] = billing_accounts.count
34
-
35
- result.tap do |result_tap|
36
- result_tap[:billing_accounts] = billing_accounts.all.collect do |billing_account|
37
- billing_account.to_hash(:only => [], :methods => [:id,:send_paper_bills,:payable_online,:account_number,:calculate_balance,:payment_due,:balance,:balance_date,:due_date])
38
- end#end billing_accounts collect
39
- result_tap[:totalCount] = BillingAccount.count(:all)
40
- end#end result tap
41
- end
42
-
43
- def create_billing_account
44
- if params[:billingAccount]
45
- data = params[:billingAccount]
46
- else
47
- data = params
48
- data[:due_date] = Date.strptime(params[:due_date], @@date_format)
49
- data[:balance_date] = Date.strptime(params[:balance_date], @@date_format)
50
- end
51
-
52
- billing_account = BillingAccount.new
53
- billing_account.account_number = data[:account_number]
54
- billing_account.calculate_balance = data[:calculate_balance]
55
- billing_account.payment_due = data[:payment_due]
56
- billing_account.balance = data[:balance]
57
- billing_account.due_date = data[:due_date]
58
- billing_account.balance_date = data[:balance_date]
59
- billing_account.payable_online = data[:payable_online]
60
- billing_account.send_paper_bills = data[:send_paper_bills]
61
-
62
- if params[:party_id]
63
- party = Party.find(params[:party_id])
64
- primary_role_type = BizTxnAcctPtyRtype.find_by_internal_identifier('primary')
65
- billing_account.add_party_with_role(party, primary_role_type)
66
- end
67
-
68
- if billing_account.save
69
- {:success => true, :billing_accounts => billing_account.to_hash(:only => [], :methods => [:id,:send_paper_bills,:payable_online,:account_number,:calculate_balance,:payment_due,:balance,:balance_date,:due_date])}
70
- else
71
- {:success => false}
72
- end
73
- end
74
-
75
- def update_billing_account
76
- if params[:billingAccount]
77
- data = params[:billingAccount]
78
- else
79
- data = params
80
- data[:due_date] = Date.strptime(params[:due_date], @@date_format)
81
- data[:balance_date] = Date.strptime(params[:balance_date], @@date_format)
82
- end
83
-
84
- billing_account = BillingAccount.find(data[:id])
85
-
86
- billing_account.account_number = data[:account_number]
87
- billing_account.calculate_balance = data[:calculate_balance]
88
- billing_account.due_date = data[:due_date]
89
- billing_account.balance_date = data[:balance_date]
90
- billing_account.payable_online = data[:payable_online]
91
- billing_account.send_paper_bills = data[:send_paper_bills]
92
- billing_account.payment_due = data[:payment_due]
93
- billing_account.balance = data[:balance]
94
-
95
- if billing_account.save
96
- {:success => true, :billing_accounts => billing_account.to_hash(:only => [], :methods => [:id,:send_paper_bills,:payable_online,:account_number,:calculate_balance,:payment_due,:balance,:balance_date,:due_date])}
97
- else
98
- {:success => false}
99
- end
100
- end
101
-
102
- def delete_billing_account
103
- BillingAccount.find(params[:id]).destroy
104
-
105
- {:success => true}
106
- end
107
-
108
- end#BillingAccountsController
109
- end#Shared
110
- end#ErpApp
111
- end#ErpInvoicing
@@ -1,52 +0,0 @@
1
- module ErpInvoicing
2
- module ErpApp
3
- module Shared
4
- class FilesController < ::ErpApp::Desktop::FileManager::BaseController
5
- before_filter :set_invoice
6
-
7
- def base_path
8
- @base_path = File.join(@file_support.root, Rails.application.config.erp_tech_svcs.file_assets_location, 'documents', @invoice.invoice_number)
9
- end
10
-
11
- def upload_file
12
- clear_files
13
-
14
- result = {}
15
- upload_path = params[:directory]
16
- name = params[:name]
17
- data = request.raw_post
18
-
19
- begin
20
- @invoice.add_file(data, File.join(base_path, name))
21
- result = {:success => true}
22
- rescue Exception=>ex
23
- Rails.logger.error ex.message
24
- Rails.logger.error ex.backtrace.join("\n")
25
- result = {:success => false, :error => "Error uploading file."}
26
- end
27
-
28
- #the awesome uploader widget whats this to mime type text, leave it render :inline
29
- render :inline => result.to_json
30
- end
31
-
32
- def set_invoice
33
- @invoice = Invoice.find(params[:invoice_id])
34
- end
35
-
36
- def set_file_support
37
- @file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
38
- end
39
-
40
- private
41
-
42
- def clear_files
43
- @invoice.files.each do |file|
44
- result, message, is_folder = @file_support.delete_file(File.join(@file_support.root,file.directory,file.name))
45
- file.destroy
46
- end
47
- end
48
-
49
- end#FilesController
50
- end#Shared
51
- end#ErpApp
52
- end#ErpInvoicing
@@ -1,208 +0,0 @@
1
- module ErpInvoicing
2
- module ErpApp
3
- module Shared
4
- class InvoicesController < ::ErpApp::Desktop::BaseController
5
-
6
- def parties
7
- render :json => {
8
- :parties => Party.all.collect{|party|
9
- {:id => party.id, :description => party.description}
10
- }
11
- }
12
- end
13
-
14
- def sms_notification
15
- invoice = Invoice.find(params[:id])
16
- if invoice.billing_account.send_sms_notification
17
- render :json => {:success => true}
18
- else
19
- render :json => {:success => false}
20
- end
21
- end
22
-
23
- def billing_accounts
24
- render :json => {
25
- :billing_accounts => BillingAccount.all.collect{|billing_account|
26
- {:id => billing_account.id, :account_number => billing_account.account_number}
27
- }
28
- }
29
- end
30
-
31
- def email_invoice
32
- invoice = Invoice.find(params[:id])
33
- DocumentMailer.email_document(params[:to_email], invoice.document).deliver
34
-
35
- render :json => {:success => true}
36
- end
37
-
38
- def print_invoice
39
- invoice = Invoice.find(params[:id])
40
- send_data(File.read(invoice.files.first.data.path), {type: 'application/pdf', disposition: 'inline'})
41
- end
42
-
43
- def invoices
44
- render :json => if request.put?
45
- #update_invoice #not implemented yet
46
- elsif request.get?
47
- get_invoices
48
- elsif request.delete?
49
- delete_invoice
50
- end
51
- end
52
-
53
- def get_invoices
54
- result = {:success => true, :invoices => [], :totalCount => 0}
55
-
56
- sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
57
- sort = sort_hash[:sort] || 'created_at'
58
- dir = sort_hash[:dir] || 'DESC'
59
- limit = params[:limit] || 50
60
- start = params[:start] || 0
61
-
62
- invoices = Invoice.scoped
63
- invoices = invoices.where('invoice_number = ?', params[:invoice_number]) unless params[:invoice_number].blank?
64
- invoices = invoices.where('billing_account_id = ?', params[:billing_account_id]) unless params[:billing_account_id].blank?
65
- invoices = invoices.order("#{sort} #{dir}").limit(limit).offset(start)
66
- result[:totalCount] = invoices.count
67
-
68
-
69
- invoices.all.each do |invoice|
70
- result[:invoices] << {
71
- :id => invoice.id,
72
- :invoice_number => invoice.invoice_number,
73
- :description => invoice.description,
74
- :message => invoice.message,
75
- :invoice_date => invoice.invoice_date,
76
- :due_date => invoice.due_date,
77
- :billing_account => invoice.billing_account.account_number,
78
- :payment_due => invoice.payment_due
79
- #:billed_to_party => (invoice.find_parties_by_role_type('billed_to').first.description rescue ''),
80
- #:billed_from_party => (invoice.find_parties_by_role_type('billed_from').first.description rescue '')
81
- }
82
- end
83
-
84
- result
85
- end
86
-
87
- def create_invoice
88
- invoice_date = Date.strptime(params[:invoice_date],"%m/%d/%Y")
89
- due_date = Date.strptime(params[:due_date],"%m/%d/%Y")
90
-
91
- invoice = Invoice.new(
92
- :invoice_number => params[:invoice_number],
93
- :invoice_date => invoice_date,
94
- :due_date => due_date,
95
- :message => params[:message],
96
- :description => params[:description]
97
- )
98
-
99
- if invoice.save
100
- billing_account = BillingAccount.find(params[:billing_account_id])
101
- billing_account.invoices << invoice
102
- billing_account.save
103
-
104
- render :json => {:success => true}
105
- else
106
-
107
- render :json => {:success => false}
108
- end
109
- end
110
-
111
- def delete_invoice
112
- Invoice.find(params[:id]).destroy
113
-
114
- {:success => true}
115
- end
116
-
117
- def invoice_items
118
- render :json => if request.post?
119
- create_invoice_item
120
- elsif request.put?
121
- update_invoice_item
122
- elsif request.get?
123
- get_invoice_items
124
- elsif request.delete?
125
- delete_invoice_item
126
- end
127
- end
128
-
129
- def create_invoice_item
130
- data = params[:data]
131
- invoice = Invoice.find(params[:invoice_id])
132
- invoice_item = InvoiceItem.create(:amount => data[:amount].to_d, :quantity => data[:quantity], :item_description => data[:item_description])
133
- invoice.items << invoice_item
134
-
135
- {:success => true,
136
- :invoice_items => {
137
- :item_description => invoice_item.item_description,
138
- :quantity => invoice_item.quantity,
139
- :amount => invoice_item.amount,
140
- :id => invoice_item.id,
141
- :created_at => invoice_item.created_at
142
- }
143
- }
144
- end
145
-
146
- def update_invoice_item
147
- data = params[:data]
148
- invoice_item = InvoiceItem.find(data[:id])
149
- invoice_item.amount = data[:amount].to_d
150
- invoice_item.quantity = data[:quantity]
151
- invoice_item.item_description = data[:item_description]
152
- invoice_item.save
153
-
154
- {:success => true,
155
- :invoice_items => {
156
- :item_description => invoice_item.item_description,
157
- :quantity => invoice_item.quantity,
158
- :amount => invoice_item.amount,
159
- :id => invoice_item.id,
160
- :created_at => invoice_item.created_at
161
- }
162
- }
163
- end
164
-
165
- def get_invoice_items
166
- result = {:success => true, :invoice_items => [], :totalCount => 0}
167
-
168
- invoice = Invoice.find(params[:invoice_id])
169
- result[:totalCount] = invoice.items.count
170
- invoice.items.each do |item|
171
- result[:invoice_items] << {
172
- :item_description => item.item_description,
173
- :quantity => item.quantity,
174
- :amount => item.amount,
175
- :id => item.id,
176
- :created_at => item.created_at
177
- }
178
- end
179
- result
180
- end
181
-
182
- def delete_invoice_item
183
- InvoiceItem.find(params[:id]).destroy
184
-
185
- {:success => true}
186
- end
187
-
188
- def invoice_payments
189
- result = {:success => true, :payments => [], :totalCount => 0}
190
-
191
- invoice = Invoice.find(params[:invoice_id])
192
-
193
- invoice.payment_applications.each do |item|
194
- result[:payments] << {
195
- :payment_date => item.financial_txn.apply_date,
196
- :post_date => item.financial_txn.captured_payment.created_at,
197
- :payment_account => item.financial_txn.account.description,
198
- :amount => item.financial_txn.money.amount
199
- }
200
- end
201
-
202
- render :json => result
203
- end
204
-
205
- end#InvoicesController
206
- end#Shared
207
- end#ErpApp
208
- end#ErpInvoicing