effective_qb_online 0.6.4 → 0.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e972afaa191b14e8348a7efe55ed2f5b21ecb5d39c2fbf5de0a0766c3dec8179
4
- data.tar.gz: 99b89c7dc278bce7f6478e0e386c5a0a726df3cf4574888255b875aca0491313
3
+ metadata.gz: 15867b1dfe0acb70639a0d07a4f772288659f3bbb48161fc95587f13c4709365
4
+ data.tar.gz: 7836486e1ca0178fb7defd247a5e338a78f9124e1e401fc28e29f1b1da175b0c
5
5
  SHA512:
6
- metadata.gz: 00dae06cea1f1c336310beba68b5224e8f8ec9f4c6a86fa06fe7d1ae65eaa5977ce69c7b87fa36663b9a13ec848b1b2d20a470c9328935373fe5b88efe1b5bd6
7
- data.tar.gz: 81e48c7baa086d9a8b6f86f51df0880f5867ff40540eb95d7f5d2fa06a52093f4e6cbbaa8439f2cdcfee741bc8930987f1553a517325394a667c056cb8cdb5f6
6
+ metadata.gz: e9876ee172702a699a7892957df6a8f129c2b4045a9a4ce66ab1f0b1162eb6c5bdd2b06339afbb61f13f78bf14c79d0f024a3228070d19b83f6a5aa0104d2bb7
7
+ data.tar.gz: 6b41207fbf79478358b629fb329521e0b9b7c8c819ff914cf632e82d73d618bf9bd8ef5ccdf2ad088bbb7d1456b80977bf8520fd3abce4797a047e5f14c5728b
@@ -0,0 +1,19 @@
1
+ module Effective
2
+ class QbOnlineMailer < EffectiveQbOnline.parent_mailer_class
3
+ include EffectiveMailer
4
+
5
+ def sync_error(resource, opts = {})
6
+ raise('expected an Effective::QbReceipt') unless resource.kind_of?(Effective::QbReceipt)
7
+
8
+ @qb_receipt = resource
9
+ @order = resource.order
10
+
11
+ to = EffectiveOrders.qb_online_sync_error_recipients.presence || EffectiveOrders.mailer_admin
12
+ subject = subject_for(__method__, "Quickbooks Sync Error - Order ##{@order.to_param}", resource, opts)
13
+ headers = headers_for(resource, opts)
14
+
15
+ mail(to: to, subject: subject, **headers)
16
+ end
17
+
18
+ end
19
+ end
@@ -14,8 +14,9 @@ module Effective
14
14
  refresh_token_expires_at :datetime
15
15
 
16
16
  # Set on /admin/quickbooks
17
- deposit_to_account_id :string
18
- payment_method_id :string
17
+ deposit_to_account_id :string
18
+ payment_method_id :string
19
+ order_number_as_transaction_number :boolean, default: false
19
20
 
20
21
  timestamps
21
22
  end
@@ -74,7 +74,7 @@ module Effective
74
74
  assign_attributes(result: 'completed successfully', sales_receipt_id: sales_receipt.id)
75
75
  complete!
76
76
  rescue => e
77
- result = [e.message, *("(intuit_tid: #{e.intuit_tid})" if e.try(:intuit_tid).present?), e.backtrace.first(15).join("\n\n")].join(' ')
77
+ result = [e.message, ("(intuit_tid: #{e.intuit_tid})" if e.try(:intuit_tid).present?), e.backtrace.first(15)].compact.flatten.join("\n\n")
78
78
  assign_attributes(result: result)
79
79
  error!
80
80
  end
@@ -93,6 +93,7 @@ module Effective
93
93
  def error!
94
94
  errored!
95
95
  EffectiveLogger.error(result, associated: self) if defined?(EffectiveLogger)
96
+ EffectiveQbOnline.send_email(:sync_error, self)
96
97
 
97
98
  false
98
99
  end
@@ -70,12 +70,14 @@ module Effective
70
70
  receipt.update!(customer_id: customer.id)
71
71
  end
72
72
 
73
+ doc_number = (order.to_param if api.realm.order_number_as_transaction_number?)
74
+
73
75
  # Receipt
74
76
  sales_receipt = Quickbooks::Model::SalesReceipt.new(
75
77
  customer_id: receipt.customer_id,
76
78
  deposit_to_account_id: api.realm.deposit_to_account_id, # The ID of the Account Entity you want the SalesReceipt to be deposited to
77
79
  payment_method_id: api.realm.payment_method_id, # The ID of the PaymentMethod Entity
78
- doc_number: order.to_param, # This is the transaction # field
80
+ doc_number: doc_number, # This is the transaction # field
79
81
  payment_ref_number: order.to_param, # Optional payment reference number/string
80
82
  txn_date: order.purchased_at.to_date,
81
83
  customer_memo: order.note_to_buyer,
@@ -84,6 +86,9 @@ module Effective
84
86
  email_status: 'EmailSent'
85
87
  )
86
88
 
89
+ # Allows QuickBooks to auto-generate the transaction number
90
+ sales_receipt.auto_doc_number! if doc_number.blank?
91
+
87
92
  # Addresses
88
93
  sales_receipt.bill_address = api.build_address(order.billing_address) if order.billing_address.present?
89
94
  sales_receipt.ship_address = api.build_address(order.shipping_address) if order.shipping_address.present?
@@ -32,6 +32,15 @@
32
32
  .col= f.select :payment_method_id, api.payment_methods_collection, label: false
33
33
  .col= f.save
34
34
 
35
+ %tr
36
+ %td Transaction Number
37
+ %td
38
+ = effective_form_with(model: [:admin, api.realm], engine: true) do |f|
39
+ .row
40
+ - collection = [["Use our order receipt number", true], ["Use QuickBooks auto-generated number", false]]
41
+ .col= f.select :order_number_as_transaction_number, collection, label: false
42
+ .col= f.save
43
+
35
44
  %tr
36
45
  %td Items
37
46
  %td= link_to 'Quickbooks Items', effective_qb_online.admin_quickbooks_items_path
@@ -0,0 +1,44 @@
1
+ %p An error occurred while synchronizing Order ##{@order.to_param} to Quickbooks Online
2
+
3
+ %div
4
+ %strong Error Message
5
+ = simple_format(@qb_receipt.result)
6
+
7
+ %div
8
+ %strong= "Order ##{@order.to_param}"
9
+ %br
10
+ = @order.created_at
11
+ %br
12
+ = @order.billing_name
13
+ %p
14
+ - @order.order_items.each do |oi|
15
+ = "#{oi.name} (#{oi.try(:qb_item_name)})"
16
+ %br
17
+
18
+ %p
19
+ %strong Resolution Steps
20
+ %br
21
+
22
+ - if @qb_receipt.result.to_s.include?('Duplicate Name Exists')
23
+ %ul
24
+ %li This customer could not be created because they share a name with an existing Item Name. This could be as a Vendor, Product, or Service.
25
+ %li Search QuickBooks for the non-customer item name and rename it. Ex: rename "John Doe" to "John Doe (Vendor)"
26
+ %li Re-run the QuickBooks Sync
27
+ - elsif @qb_receipt.result.to_s.include?('Unknown Item')
28
+ %ul
29
+ %li Confirm the QuickBooks Item Names for this Order within QuickBooks
30
+ %li If this Item Name does not exist, add it to QuickBooks
31
+ %li Otherwise, #{link_to('click here', effective_qb_online.edit_admin_qb_receipt_url(@qb_receipt))} to assign the correct Item Name to this Order
32
+ %li Re-run the QuickBooks Sync
33
+ - else
34
+ %ul
35
+ %li This is an error without a predefined resolution.
36
+ %li Please contact support.
37
+
38
+ %hr
39
+
40
+ %p{style: "text-align: center;"}
41
+ = link_to "View Quickbooks Sales Receipts", effective_qb_online.admin_quickbooks_url
42
+
43
+ %p{style: "text-align: center;"}
44
+ = link_to "View Order ##{@order.to_param}", effective_orders.admin_order_url(@order)
@@ -12,8 +12,18 @@ EffectiveQbOnline.setup do |config|
12
12
  # https://github.com/ruckus/quickbooks-ruby
13
13
  Quickbooks.sandbox_mode = (ENV['QUICKBOOKS_ONLINE_SANDBOX'].to_s == 'true')
14
14
 
15
- # Effective Orders
16
- # Add the following to your config/intializers/effective_orders.rb
17
- # config.use_effective_qb_online = true
18
-
15
+ # Mailer Settings
16
+ # Please see config/initializers/effective_resources.rb for default effective_* gem mailer settings
17
+ #
18
+ # Configure the class responsible to send e-mails.
19
+ # config.mailer = 'Effective::QbOnlineMailer'
20
+ #
21
+ # Override effective_resource mailer defaults
22
+ #
23
+ # config.parent_mailer = nil # The parent class responsible for sending emails
24
+ # config.deliver_method = nil # The deliver method, deliver_later or deliver_now
25
+ # config.mailer_layout = nil # Default mailer layout
26
+ # config.mailer_sender = nil # Default From value
27
+ # config.mailer_admin = nil # Default To value for Admin correspondence
28
+ # config.mailer_subject = nil # Proc.new method used to customize Subject
19
29
  end
@@ -1,10 +1,10 @@
1
1
  class CreateEffectiveQbOnline < ActiveRecord::Migration[6.0]
2
2
  def change
3
- create_table :qb_realms do |t|
3
+ create_table :qb_realms, if_not_exists: true do |t|
4
4
  t.string :realm_id
5
5
 
6
- t.integer :deposit_to_account_id
7
- t.integer :payment_method_id
6
+ t.string :deposit_to_account_id
7
+ t.string :payment_method_id
8
8
 
9
9
  t.text :access_token
10
10
  t.datetime :access_token_expires_at
@@ -12,12 +12,16 @@ class CreateEffectiveQbOnline < ActiveRecord::Migration[6.0]
12
12
  t.text :refresh_token
13
13
  t.datetime :refresh_token_expires_at
14
14
 
15
+ t.boolean :order_number_as_transaction_number, default: false
16
+
15
17
  t.timestamps
16
18
  end
17
19
 
18
- create_table :qb_receipts do |t|
20
+ create_table :qb_receipts, if_not_exists: true do |t|
19
21
  t.integer :order_id
20
- t.integer :customer_id
22
+
23
+ t.string :customer_id
24
+ t.string :sales_receipt_id
21
25
 
22
26
  t.text :result
23
27
 
@@ -27,13 +31,13 @@ class CreateEffectiveQbOnline < ActiveRecord::Migration[6.0]
27
31
  t.timestamps
28
32
  end
29
33
 
30
- add_index :qb_receipts, :order_id
34
+ add_index :qb_receipts, :order_id, if_not_exists: true
31
35
 
32
- create_table :qb_receipt_items_name do |t|
36
+ create_table :qb_receipt_items, if_not_exists: true do |t|
33
37
  t.integer :qb_receipt_id
34
38
  t.integer :order_item_id
35
39
 
36
- t.integer :item_id
40
+ t.string :item_id
37
41
 
38
42
  t.timestamps
39
43
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.6.4'.freeze
2
+ VERSION = '0.7.1'.freeze
3
3
  end
@@ -8,6 +8,7 @@ module EffectiveQbOnline
8
8
  def self.config_keys
9
9
  [
10
10
  :qb_realms_table_name, :qb_receipts_table_name, :qb_receipt_items_table_name,
11
+ :mailer, :parent_mailer, :deliver_method, :mailer_layout, :mailer_sender, :mailer_admin, :mailer_subject,
11
12
  :oauth_client_id, :oauth_client_secret,
12
13
  :layout
13
14
  ]
@@ -15,6 +16,10 @@ module EffectiveQbOnline
15
16
 
16
17
  include EffectiveGem
17
18
 
19
+ def self.mailer_class
20
+ mailer&.constantize || Effective::QbOnlineMailer
21
+ end
22
+
18
23
  def self.oauth2_client
19
24
  OAuth2::Client.new(
20
25
  oauth_client_id,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_qb_online
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
11
+ date: 2025-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -216,6 +216,7 @@ files:
216
216
  - app/datatables/admin/effective_qb_receipts_datatable.rb
217
217
  - app/helpers/effective_qb_online_helper.rb
218
218
  - app/jobs/qb_sync_order_job.rb
219
+ - app/mailers/effective/qb_online_mailer.rb
219
220
  - app/models/effective/qb_api.rb
220
221
  - app/models/effective/qb_realm.rb
221
222
  - app/models/effective/qb_receipt.rb
@@ -229,6 +230,7 @@ files:
229
230
  - app/views/admin/qb_receipts/_form.html.haml
230
231
  - app/views/admin/qb_receipts/edit.html.haml
231
232
  - app/views/admin/qb_receipts/new.html.haml
233
+ - app/views/effective/qb_online_mailer/sync_error.html.haml
232
234
  - config/effective_qb_online.rb
233
235
  - config/routes.rb
234
236
  - db/migrate/101_create_effective_qb_online.rb