effective_qb_online 0.1.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7fc21efb0c22e83527301d73ea8361950ac6509df72473f6b508c02a4395033
4
- data.tar.gz: d64a65682a39acda71d381395cf88075f8ac52d2675c1edd0056d417a8c082dc
3
+ metadata.gz: f761163092d4217a1ba74cbc4903332f914c4ebb87f8cb5400d0801062aec74f
4
+ data.tar.gz: '0529a8121cd5ad7fdd16349c7643539f47d09c8420da35312575558d9ca93fd6'
5
5
  SHA512:
6
- metadata.gz: 8906f78473bcdbd0f52968e7e5071296116bbdda9bb772fcc02c76bc6bf6d21cbe53767550687417b896cf0d171f63b3e7758526259777c4a709dc22d87640f4
7
- data.tar.gz: 642358ce67927f0fd30dc7af890d082a35291fed20a0b8ef2497ebeec41dc88154d0ab4d278836cb56d63b1eed638f3be9620475c0c2bf19316473d212534b65
6
+ metadata.gz: '08195220d727d8b4229a00a54d5b331b825836e4a45aebe1a921ad5b0e31a0d2e8e9628b6310fd896d6c737013f97b9fa7b1db333032a1146f0946c27244d1bd'
7
+ data.tar.gz: 2f950c7623f4f195b4615fc85b393d720b5c92c3e5a63d8332057df2b7cff76c0cb38ee74c6361cb60f0564aa9ad6dcbb3800a373a52f9ffa47e26b0d47ad274
@@ -1,12 +1,15 @@
1
1
  module Admin
2
2
  class EffectiveQbItemsDatatable < Effective::Datatable
3
3
  datatable do
4
- col :name, label: 'QuickBooks Item Name'
5
4
  col :id, label: 'QuickBooks Item Id'
5
+ col :name, label: 'QuickBooks Item Name'
6
+ col :fully_qualified_name, label: 'QuickBooks Fully Qualified Name'
6
7
  end
7
8
 
8
9
  collection do
9
- EffectiveQbOnline.api.items_collection.values.flatten(1)
10
+ EffectiveQbOnline.api.items.map do |item|
11
+ [item.id, item.name, item.fully_qualified_name]
12
+ end
10
13
  end
11
14
 
12
15
  end
@@ -25,22 +25,41 @@ module Effective
25
25
  # Find and validate items
26
26
  items = api.items()
27
27
 
28
+ # Credit card surcharge item
29
+ surcharge_item = if EffectiveOrders.try(:credit_card_surcharge_qb_item_name).present?
30
+ name = EffectiveOrders.credit_card_surcharge_qb_item_name
31
+
32
+ item = items.find do |item|
33
+ [scrub(item.id), scrub(item.name), scrub(item.fully_qualified_name)].include?(scrub(name))
34
+ end
35
+
36
+ raise("Missing Credit Card Surcharge item #{name}. Please add this to your Quickbooks items.") unless item.present?
37
+
38
+ item
39
+ end
40
+
28
41
  receipt.qb_receipt_items.each do |receipt_item|
29
42
  purchasable = receipt_item.order_item.purchasable
30
43
  raise("Expected a purchasable for Effective::OrderItem #{receipt_item.order_item.id}") unless purchasable.present?
31
44
 
32
45
  # Either of these could match
33
- purchasable_id_name = [purchasable.try(:qb_item_id), purchasable.try(:qb_item_name)].compact
46
+ purchasable_id_name = [
47
+ (scrub(purchasable.qb_item_id) if purchasable.try(:qb_item_id)),
48
+ (scrub(purchasable.qb_item_name) if purchasable.try(:qb_item_name))
49
+ ].compact
34
50
 
35
51
  # Find item by receipt item
36
- item = items.find { |item| [item.id, item.name].include?(receipt_item.item_id) }
52
+ item = items.find do |item|
53
+ [scrub(item.id), scrub(item.name), scrub(item.fully_qualified_name)].include?(scrub(receipt_item.item_id))
54
+ end
37
55
 
38
56
  # Find item by purchasable qb_item_id and qb_item_name
39
- item ||= begin
40
- items.find { |item| ([item.id, item.name] & purchasable_id_name).present? }
57
+ item ||= items.find do |item|
58
+ ([scrub(item.id), scrub(item.name), scrub(item.fully_qualified_name)] & purchasable_id_name).present?
41
59
  end
42
60
 
43
61
  if item.blank?
62
+ purchasable_id_name = [purchasable.try(:qb_item_id), purchasable.try(:qb_item_name)].compact
44
63
  raise("Unknown Item #{purchasable_id_name.join(' or ')} from #{purchasable} (#{purchasable.class.name} ##{purchasable.id})")
45
64
  end
46
65
 
@@ -92,6 +111,23 @@ module Effective
92
111
  sales_receipt.line_items << line_item
93
112
  end
94
113
 
114
+ # Add Credit Card Surcharge
115
+ if order.try(:surcharge).to_i != 0
116
+ raise("Expected a Credit Card Surcharge QuickBooks item to exist for Effective::Order #{order.id} with non-zero surcharge amount. Please check your configuration.") unless surcharge_item.present?
117
+
118
+ line_item = Quickbooks::Model::Line.new(amount: api.price_to_amount(order.surcharge), description: 'Credit Card Surcharge')
119
+
120
+ line_item.sales_item! do |line|
121
+ line.item_id = surcharge_item.item_id
122
+ line.tax_code_id = tax_code.id # Surcharge is taxed at same rate as items
123
+
124
+ line.unit_price = api.price_to_amount(order.surcharge)
125
+ line.quantity = 1
126
+ end
127
+
128
+ sales_receipt.line_items << line_item
129
+ end
130
+
95
131
  # Double check
96
132
  raise("Invalid SalesReceipt generated for Effective::Order #{order.id}") unless sales_receipt.valid?
97
133
 
@@ -99,5 +135,11 @@ module Effective
99
135
  sales_receipt
100
136
  end
101
137
 
138
+ private
139
+
140
+ def self.scrub(value)
141
+ value.to_s.downcase.strip
142
+ end
143
+
102
144
  end
103
145
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
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.1.7
4
+ version: 0.3.0
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: 2022-06-06 00:00:00.000000000 Z
11
+ date: 2022-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails