toolhound-ruby 1.0.10 → 1.0.11

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
  SHA1:
3
- metadata.gz: 7761f294852261ed89a157bcab5af11358aebffc
4
- data.tar.gz: 4a26e851dfb390c4682e3c669eee190af2b21bcb
3
+ metadata.gz: f4b7320fb09cf1d6d020be8caab6ea0e0a06f7a1
4
+ data.tar.gz: 393645f776dd26590718bb020a3423e85f35ccc7
5
5
  SHA512:
6
- metadata.gz: 1b74b5a02e68365aaf80d302f08a83cd9d1bf0d2bd41b3e6eeeb3956217e59345160b68ece60da74c9fc31901f8ac7d554720c1ce24ba2aae654349a4222945a
7
- data.tar.gz: 51c8ede5ea2586ab053b75e4cb02e8a10976a7b51cab2bb726bdde07275cbc7497a48014321e084b96365449d895b86e4b6492c1745c647ec27d299e09428575
6
+ metadata.gz: 0ab2999cbc0846eb533a3227cefd245ba4ef9c46e3d21f00c7711d0bc44d7a8ecca298b424e897747665dd2e2b7ce352b4f6f509d359b1eb55d813d350ea1fa3
7
+ data.tar.gz: f9aa7ba6d92e068c678147806225d27c319a4ceab8e15e771884900883bb1db71fd0666e7c15cf7d02c7690fe8550956f8cb7acf513595e82d2b43b0b94293d1
@@ -18,12 +18,14 @@ require "toolhound-ruby/client"
18
18
  require "toolhound-ruby/default"
19
19
  require "toolhound-ruby/base"
20
20
 
21
+ require "toolhound-ruby/job"
21
22
  require "toolhound-ruby/project"
22
23
  require "toolhound-ruby/inventory"
23
24
  require "toolhound-ruby/inventory_item"
24
25
  require "toolhound-ruby/rental"
25
26
  require "toolhound-ruby/rental_item"
26
27
  require "toolhound-ruby/rental_charge"
28
+ require "toolhound-ruby/transaction"
27
29
 
28
30
  require "toolhound-ruby/vendor"
29
31
  require "toolhound-ruby/manufacturer"
@@ -87,6 +87,26 @@ module Toolhound
87
87
  results.first
88
88
  end
89
89
 
90
+ def procedure(procedure_name, variables = {})
91
+ # procedure_name = "Job_GetList"
92
+
93
+ # EXECUTE HumanResources.uspGetEmployees @FirstName = N'Pilar', @LastName = N'Ackerman';
94
+ vars = transform_procedure_variables(variables)
95
+ pairs = vars.map {|pair| pair.join(" = ") }
96
+ vars_query = pairs.join(", ")
97
+
98
+ # EXECUTE HumanResources.uspGetEmployees @FirstName = N'Pilar', @LastName = N'Ackerman';
99
+
100
+ sql = "EXECUTE dbo.#{procedure_name} #{vars_query};"
101
+ results = connection.execute(sql)
102
+ # results = connection.execute(query)
103
+ end
104
+
105
+ def insert(table, variables)
106
+
107
+
108
+ end
109
+
90
110
  def merge_options(defaults, options = {})
91
111
  where = options.delete :where
92
112
  selects = options.delete :selects
@@ -209,7 +229,7 @@ module Toolhound
209
229
  arr = []
210
230
  case wheres.class.to_s
211
231
  when "String"
212
- return wheres
232
+ arr << wheres
213
233
  when "Hash"
214
234
  wheres.each do |k, v|
215
235
  table, column = formatted_table_and_column(k)
@@ -269,7 +289,7 @@ module Toolhound
269
289
 
270
290
  end
271
291
 
272
- def query(query, options)
292
+ def query(query, options = {})
273
293
  data = []
274
294
  results = connection.execute(query)
275
295
  results.each(:cache_rows => false) do |row|
@@ -323,6 +343,24 @@ module Toolhound
323
343
  hash
324
344
  end
325
345
 
346
+ def transform_procedure_variables(variables)
347
+ vars = []
348
+ variables.each do |key, value|
349
+ vars << [transform_procedure_key(key), transform_procedure_value(value)]
350
+ end
351
+ vars
352
+ end
353
+
354
+ def transform_procedure_value(value)
355
+ "'#{value}'"
356
+ end
357
+
358
+ def transform_procedure_key(key)
359
+ key = key.to_s
360
+ key = camelize(key, true)
361
+ "@p_#{key}"
362
+ end
363
+
326
364
  def transform_attribute_key(key)
327
365
  renamed = self.class.renamed_attributes
328
366
  if renamed.include? key
@@ -101,6 +101,14 @@ module Toolhound
101
101
  @connection = nil
102
102
  end
103
103
 
104
+ def job
105
+ @job ||= Toolhound::Job.new(self)
106
+ end
107
+
108
+ def transaction
109
+ @transaction ||= Toolhound::Transaction.new(self)
110
+ end
111
+
104
112
  def inventory
105
113
  @inventory ||= Toolhound::Inventory.new(self)
106
114
  end
@@ -38,7 +38,7 @@ module Toolhound
38
38
  ],
39
39
  inventory_item_text: [:var_serial_number, :var_user_field1, :var_user_field2, :var_user_field3, :var_bin],
40
40
  inventory: [:int_category_id, :int_sub_category_id],
41
- inventory_text: [:var_description, :var_part_no],
41
+ inventory_text: [:var_description, :var_part_no, {varUserField1: "varGlRevenue"}, {varUserField2: "varGlCOGSCode"}, {varUserField3: "varPhaseCode"}],
42
42
  inventory_id: ["intInventoryIdID", {varInventoryID: "inventory_idid"}]
43
43
  }
44
44
 
@@ -66,7 +66,7 @@ module Toolhound
66
66
 
67
67
  end
68
68
 
69
- def charges_for_entity(entity_id)
69
+ def charges_for_entity(entity_id, job_id=nil)
70
70
  joins = default_joins
71
71
  joins << "INNER JOIN tblInventoryType ON tblInventoryType.intInventoryTypeID = tblInventoryItem.intInventoryTypeID AND tblInventoryType.bolSerialized = 1"
72
72
  joins << "INNER JOIN(
@@ -76,11 +76,33 @@ module Toolhound
76
76
  INNER JOIN tblRental ON tblRental.intRentalID = tblRentalDetail.intRentalID AND tblRental.intEntityID = '#{entity_id}'
77
77
  GROUP BY tblRentalItem.intInventoryIDID
78
78
  ) AS tblRentalQuery ON tblRentalQuery.intInventoryIDID = tblInventoryID.intInventoryIdID"
79
+ joins << "LEFT OUTER JOIN (
80
+ SELECT rc.intInventoryIDID, MAX(rc.intRentalChargeID) AS latest_id
81
+ FROM tblRentalCharge as rc
82
+ WHERE rc.intEntityID = '#{entity_id}'
83
+ GROUP BY rc.intInventoryIDID
84
+ ) AS tblLatestCharge ON tblLatestCharge.intInventoryIDID = tblInventoryID.intInventoryIdID"
85
+ joins << "LEFT OUTER JOIN (
86
+ SELECT tblRentalCharge.intJobID, tblRentalCharge.intRentalChargeID
87
+ FROM tblRentalCharge
88
+ WHERE intEntityID = '#{entity_id}'
89
+ ) AS tblJobCharge ON tblJobCharge.intRentalChargeID = tblLatestCharge.latest_id"
90
+ joins << "LEFT OUTER JOIN tblJobText on tblJobText.intJobID = tblJobCharge.intJobID AND tblJobText.varLocaleID = '#{locale}'"
79
91
 
80
92
  selects = default_selects
93
+ selects[:job_text] = [:int_job_id, :int_job_text_id, :var_job_number, :var_job]
81
94
  selects[:rental_query] = [:dec_total_rent]
82
95
 
83
- build_and_query(selects: selects, where: [], joins: joins, order: "tblInventoryText.varPartNo")
96
+ # (tblInventoryItem.intQOH=@p_QOH OR @p_QOH IS NULL)
97
+ wheres = []
98
+ if job_id
99
+ if job_id == :null
100
+ wheres << "(tblJobText.intJobID IS NULL)"
101
+ else
102
+ wheres << "(tblJobText.intJobID = #{job_id})"
103
+ end
104
+ end
105
+ build_and_query(selects: selects, where: wheres, joins: joins, order: "tblInventoryText.varPartNo")
84
106
 
85
107
  # SELECT tblInventoryItem.*, subquery1.total_rent FROM tblInventoryItem
86
108
  # INNER JOIN tblInventoryID ON tblInventoryItem.intInventoryItemID = tblInventoryID.intInventoryItemID
@@ -81,7 +81,6 @@ module Toolhound
81
81
  end
82
82
 
83
83
 
84
-
85
84
  # rename_attributes intLocationID: 'location_id'
86
85
 
87
86
  end
@@ -1,3 +1,3 @@
1
1
  module Toolhound
2
- VERSION = "1.0.10"
2
+ VERSION = "1.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolhound-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Klooth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tiny_tds