toolhound-ruby 1.0.32 → 1.0.33

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: c554bbb3b2f61ee999968cf8f330c5509437e96e
4
- data.tar.gz: 7e637af12af27a34901f2cc22a880f05fff3002e
3
+ metadata.gz: a0a074d0a368c009ff282e578f2825a84aa1085d
4
+ data.tar.gz: fe00a3c1678033d581688b68514c93a2db0d58f5
5
5
  SHA512:
6
- metadata.gz: f42674cfdf9780051371cff066ae7507d47929c000656126cc81c56a228eb66a2cf77f3d7c0dfeba255988d246f517ffc3522f484c1819dec55e222bc6be8081
7
- data.tar.gz: 6f02e25cf1779f2f968b03316c828bae1b66ea1e71cdcbc04deefd07f2da228dcb6cc95c746bb0fd32b5b62524bb586962cd93a2bf1c60abd0e4cc1f7db38bee
6
+ metadata.gz: e9107c0798c16c6d7a7adb599192a3962cfbdad1c31be02b09825fd4eefe491173b95381d087a127b6dd9ee3938d97a5fbbe6beb11fcaa190e3901918c19ea00
7
+ data.tar.gz: 07326504bf65b87b3825a5ebe4af11f765c2b48ef7a678f33d995a72f7b6d2fc69d14fca6a660a9f65b8dcd1cdd04395f8f04a0b456971f221be44cea1921278
@@ -231,6 +231,10 @@ module Toolhound
231
231
  arr.join(" AND ")
232
232
  end
233
233
 
234
+ def build_group(groups)
235
+ groups
236
+ end
237
+
234
238
  def _build_where(wheres)
235
239
  arr = []
236
240
  case wheres.class.to_s
@@ -299,8 +303,9 @@ module Toolhound
299
303
  data = []
300
304
  begin
301
305
  results = connection.execute(query)
306
+ opts = {cache_rows: false}.merge(options || {})
302
307
 
303
- results.each(:cache_rows => false) do |row|
308
+ results.each(opts) do |row|
304
309
  data << transform_attributes(row)
305
310
  end
306
311
  data
@@ -312,11 +317,72 @@ module Toolhound
312
317
  finish_statement_handle(results)
313
318
  end
314
319
 
320
+ def update_query(query, options)
321
+ begin
322
+ result = connection.execute(query)
323
+ result.do
324
+ rescue TinyTds::Error
325
+ client.reset_connection
326
+ retry
327
+ end
328
+ ensure
329
+ finish_statement_handle(result)
330
+ end
331
+
315
332
  def build_and_query(options, query_options = {})
316
333
  sql = build_sql(options)
317
334
  results = query(sql, query_options)
318
335
  end
319
336
 
337
+ def update(options, query_options = {})
338
+ sql = build_update_sql(options, query_options)
339
+
340
+ debug = query_options[:debug]
341
+
342
+ if sql && debug != true
343
+ update_query(sql, query_options)
344
+ end
345
+
346
+ end
347
+
348
+ def build_update_sql(options, query_options = {})
349
+ table = options[:table] ? formatted_table_name(options[:table]) : table_name
350
+ attributes = build_update_attributes(options[:attributes])
351
+ sql = nil
352
+ where = build_where(options[:where])
353
+ if attributes.length > 0
354
+ attributes = attributes.join(", ")
355
+
356
+ sql = "UPDATE #{table} SET #{attributes} WHERE #{where}"
357
+ puts sql
358
+ end
359
+
360
+ sql
361
+ # update tblCountFinal set
362
+ # intQuantity = isnull(intQuantity,0) + isnull(@p_Quantity,0),
363
+ # intQOH = isnull(intQOH,0) + isnull(@p_QuantityOnHand,0)
364
+ # where intCountFinalID = @CountFinalID
365
+ end
366
+
367
+ def build_update_attributes(attributes)
368
+ arr = []
369
+ case attributes.class.to_s
370
+ when "String"
371
+ arr << attributes
372
+ when "Hash"
373
+ attributes.each do |k, v|
374
+ name = formmatted_column_name(k)
375
+ arr << "#{name} = '#{v}'"
376
+ end
377
+ when "Array"
378
+ attributes.each do |v|
379
+ arr += build_update_attributes(v)
380
+ end
381
+ end
382
+ arr
383
+
384
+ end
385
+
320
386
 
321
387
  def build_sql(obj)
322
388
  limit = obj[:limit]
@@ -325,14 +391,16 @@ module Toolhound
325
391
  from = obj[:from] ? formatted_table_name(obj[:from]) : table_name
326
392
  where = obj[:where] ? build_where(obj[:where]) : nil
327
393
  order = obj[:order]
394
+ group = obj[:group] ? build_group(obj[:group]) : nil
328
395
 
329
396
  selects = "*" if selects.strip.length == 0
330
397
 
331
398
  limit_str = limit ? "TOP(#{limit})" : ""
332
- where_str = where.length > 0 ? "WHERE #{where}" : ""
399
+ where_str = where && where.length > 0 ? "WHERE #{where}" : ""
333
400
  order_str = order ? "ORDER BY #{order}" : ""
401
+ group_str = group ? "GROUP BY #{group}" : ""
334
402
 
335
- sql = "SELECT #{limit_str} #{selects} FROM #{from} #{joins} #{where_str} #{order_str}"
403
+ sql = "SELECT #{limit_str} #{selects} FROM #{from} #{joins} #{where_str} #{order_str} #{group_str}"
336
404
  puts sql
337
405
  sql
338
406
  end
@@ -66,13 +66,53 @@ module Toolhound
66
66
 
67
67
  end
68
68
 
69
+ def count(options = {})
70
+
71
+ entity_id = options[:entity_id]
72
+
73
+ selects = {
74
+ job_text: [:int_job_id],
75
+ inventory_item: [{ int_inventory_item_id: {as: :tool_count, agg: :count} }] #[{"count(*)" => {raw: true, as: :tools_assigned}}]
76
+ }
77
+ joins = []
78
+ joins << "INNER JOIN tblInventory ON (tblInventory.intInventoryID = tblInventoryItem.intInventoryID AND tblInventory.bolDeleted = 0)"
79
+ joins << "INNER JOIN tblInventoryID ON tblInventoryID.intInventoryItemID = tblInventoryItem.intInventoryItemID"
80
+ joins << "INNER JOIN tblInventoryType ON tblInventoryType.intInventoryTypeID = tblInventoryItem.intInventoryTypeID AND tblInventoryType.bolSerialized = 1"
81
+ joins << "INNER JOIN(
82
+ SELECT tblRentalItem.intInventoryIDID FROM tblRentalItem
83
+ INNER JOIN tblRentalDetail ON tblRentalDetail.intRentalDetailID = tblRentalItem.intRentalDetailID
84
+ INNER JOIN tblRental ON tblRental.intRentalID = tblRentalDetail.intRentalID AND tblRental.intEntityID = '#{entity_id}'
85
+ GROUP BY tblRentalItem.intInventoryIDID
86
+ ) AS tblRentalQuery ON tblRentalQuery.intInventoryIDID = tblInventoryID.intInventoryIdID"
87
+
88
+ joins << "LEFT OUTER JOIN (
89
+ SELECT rc.intInventoryIDID, MAX(rc.intRentalChargeID) AS latest_id
90
+ FROM tblRentalCharge as rc
91
+ WHERE rc.intEntityID = '#{entity_id}'
92
+ GROUP BY rc.intInventoryIDID
93
+ ) AS tblLatestCharge ON tblLatestCharge.intInventoryIDID = tblInventoryID.intInventoryIdID"
94
+
95
+ joins << "LEFT OUTER JOIN (
96
+ SELECT intJobID, intRentalChargeID, intRentalItemID
97
+ FROM tblRentalCharge
98
+ WHERE intEntityID = '#{entity_id}'
99
+ ) AS tblJobCharge ON tblJobCharge.intRentalChargeID = tblLatestCharge.latest_id"
100
+
101
+ joins << "LEFT OUTER JOIN tblJobText on tblJobText.intJobID = tblJobCharge.intJobID AND tblJobText.varLocaleID = '#{locale}'"
102
+
103
+ build_and_query(selects: selects, joins: joins, group: "tblJobText.intJobID")
104
+
105
+ # GROUP BY tblJobText.intJobID
106
+
107
+ end
108
+
69
109
  def charges(options = {})
70
110
  options = (options || {}).dup
71
111
 
72
112
  job_id = options[:job_id]
73
113
  entity_id = options[:entity_id]
74
114
  order = options[:order] || "tblInventoryText.varPartNo"
75
-
115
+ # 249
76
116
 
77
117
  joins = default_joins
78
118
  entity_query = ""
@@ -130,7 +170,35 @@ module Toolhound
130
170
 
131
171
  end
132
172
 
173
+ def reassign(options)
174
+ options = (options || {}).dup
175
+ entity_id = options[:entity_id]
176
+ inventory_id_id = options[:inventory_id_id]
177
+ job_id = options[:job_id]
178
+
179
+ query_opts = {}
180
+ query_opts[:debug] = options.delete(:debug) if options[:debug]
133
181
 
182
+ raise ArgumentError.new(:entity_id) unless entity_id
183
+ raise ArgumentError.new(:inventory_id_id) unless inventory_id_id
184
+ raise ArgumentError.new(:job_id) unless job_id
134
185
 
186
+ sql = build_sql(from: "job", where: [{"job.int_job_id" => job_id}], limit: 1)
187
+ result = query(sql, first: true)
188
+
189
+ raise ArgumentError.new(:no_job) if result.length == 0
190
+
191
+
192
+ sql = "SELECT * FROM tblRentalCharge WHERE intInventoryIDID = '#{inventory_id_id}' AND intEntityID = '#{entity_id}' "
193
+ result = query(sql, first: true)
194
+
195
+ raise ArgumentError.new(:no_charge) if result.length == 0
196
+
197
+ id = result.first[:rental_charge_id]
198
+ update({attributes: {
199
+ int_job_id: job_id
200
+ }, table: "rental_charge", where: [{"rental_charge.int_rental_charge_id" => id}]}, query_opts)
201
+
202
+ end
135
203
  end
136
204
  end
@@ -1,3 +1,3 @@
1
1
  module Toolhound
2
- VERSION = "1.0.32"
2
+ VERSION = "1.0.33"
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.32
4
+ version: 1.0.33
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-03-22 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tiny_tds