Class: Toolhound::InventoryItem

Inherits:
Base
  • Object
show all
Defined in:
lib/toolhound-ruby/inventory_item.rb

Overview

Class to parse GitHub repository owner and name from URLs and to generate URLs

Constant Summary

Constants inherited from Base

Base::DATE_TIME_FORMAT, Base::DB_TYPE_REGEX

Instance Attribute Summary

Attributes inherited from Base

#connection

Instance Method Summary collapse

Methods inherited from Base

#_build_joins, #_build_selects, #_build_where, #all, #build_and_query, #build_joins, #build_selects, #build_sql, #build_where, #find, #formatted_table_and_column, #formatted_table_name, #formmatted_column_name, #get_operator, #initialize, #insert, #locale, #merge_options, #parse_time, primary_key, #primary_key, primary_key=, #procedure, #query, rename_attributes, renamed_attributes, #table_name, table_name, table_name=, #transform_attribute_key, #transform_attributes, #transform_procedure_key, #transform_procedure_value, #transform_procedure_variables

Methods included from Util

#acronym_regex, #acronyms, #camelize, #demodulize, #underscore

Constructor Details

This class inherits a constructor from Toolhound::Base

Instance Method Details

#charges(options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/toolhound-ruby/inventory_item.rb', line 69

def charges(options = {})
  options = (options || {}).dup

  job_id      = options[:job_id]
  entity_id   = options[:entity_id]
  order       = options[:order] || "tblInventoryText.varPartNo"


  joins                 = default_joins
  entity_query          = ""
  charge_entity_query   = ""
  charge_entity_query1  = ""
  if entity_id
    entity_query          = "AND tblRental.intEntityID = '#{entity_id}'"
    charge_entity_query   = "WHERE rc.intEntityID = '#{entity_id}'"
    charge_entity_query1  = "WHERE intEntityID = '#{entity_id}'"
  end

  joins << "INNER JOIN tblInventoryType ON tblInventoryType.intInventoryTypeID = tblInventoryItem.intInventoryTypeID AND tblInventoryType.bolSerialized = 1"
  joins << "INNER JOIN(
 	            SELECT tblRentalItem.intInventoryIDID, SUM(tblRentalItem.decTotalRent) AS decTotalRent
   	          FROM tblRentalItem
              INNER JOIN tblRentalDetail ON tblRentalDetail.intRentalDetailID = tblRentalItem.intRentalDetailID
              INNER JOIN tblRental ON tblRental.intRentalID = tblRentalDetail.intRentalID #{entity_query}
              GROUP BY tblRentalItem.intInventoryIDID
   ) AS tblRentalQuery ON tblRentalQuery.intInventoryIDID = tblInventoryID.intInventoryIdID"

  joins << "LEFT OUTER JOIN (
              SELECT rc.intInventoryIDID, MAX(rc.intRentalChargeID) AS latest_id
              FROM tblRentalCharge as rc
              #{charge_entity_query}
              GROUP BY rc.intInventoryIDID
    ) AS tblLatestCharge ON tblLatestCharge.intInventoryIDID = tblInventoryID.intInventoryIdID"

  joins << "LEFT OUTER JOIN  (
              SELECT tblRentalCharge.intJobID, tblRentalCharge.intRentalChargeID
              FROM tblRentalCharge
              #{charge_entity_query1}
            ) AS tblJobCharge ON tblJobCharge.intRentalChargeID = tblLatestCharge.latest_id"

  joins << "LEFT OUTER JOIN tblJobText on tblJobText.intJobID = tblJobCharge.intJobID AND tblJobText.varLocaleID = '#{locale}'"

  selects                 = default_selects
  selects[:job_text]      = [:int_job_id, :int_job_text_id, :var_job_number, :var_job]
  selects[:rental_query]  = [:dec_total_rent]

  wheres = []
  if job_id
    if job_id == :null
      wheres << "(tblJobText.intJobID IS NULL)"
    else
      wheres << "(tblJobText.intJobID = #{job_id})"
    end
  end

  build_and_query(selects: selects, where: wheres, joins: joins, order: order)

end

#default_joinsObject



51
52
53
54
55
56
57
58
59
# File 'lib/toolhound-ruby/inventory_item.rb', line 51

def default_joins
  arr = []
  arr << "INNER JOIN tblInventory ON (tblInventory.intInventoryID = tblInventoryItem.intInventoryID AND tblInventory.bolDeleted = 0)"
  arr << "INNER JOIN tblInventoryText	ON (tblInventoryText.intInventoryID = tblInventory.intInventoryID and tblInventoryText.varLocaleID ='#{locale}')"
  arr << "INNER JOIN tblInventoryItemText ON (tblInventoryItem.intInventoryItemID = tblInventoryItemText.intInventoryItemID and tblInventoryItemText.varLocaleID = '#{locale}')"
  arr << "INNER JOIN tblInventoryID ON tblInventoryID.intInventoryItemID = tblInventoryItem.intInventoryItemID"

  arr
end

#default_selectsObject

def default_selects

selects = {
  inventory: ["intInventoryID", "intCategoryID", "intSubCategoryID", "intManufacturerID", "intVendorID", "dteCreatedDate", "dteModifiedDate"],
  inventory_text: ["varPartNo", "varDescription", "txtNotes", {varUserField1: "varGlRevenue"}, {varUserField2: "varGlCOGSCode"}, {varUserField3: "varPhaseCode"}],
  unit_of_measure_text: ["varUnitOfMeasure"],
  category: ["varCategory"],
  sub_category: ["varCategory"]
}

end def default_joins

arr = []
arr << "INNER JOIN tblInventoryType ON tblInventory.intInventoryTypeID = tblInventoryType.intInventoryTypeID"
arr << "INNER JOIN tblInventoryText ON (tblInventoryText.intInventoryID = tblInventory.intInventoryID AND tblInventoryText.varLocaleID = '#{locale}')"
arr << "LEFT OUTER JOIN tblUnitOfMeasureText ON (tblUnitOfMeasureText.intUofMID = tblInventory.intUofMID )"
arr << "LEFT OUTER JOIN tblCategoryText AS tblCategory ON (tblCategory.intCategoryID = tblInventory.intCategoryID AND tblCategory.varLocaleID = '#{locale}')"
arr << "LEFT OUTER JOIN tblCategoryText AS tblSubCategory ON (tblSubCategory.intCategoryID = tblInventory.intSubCategoryID AND tblSubCategory.varLocaleID = '#{locale}')"

end



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/toolhound-ruby/inventory_item.rb', line 32

def default_selects
  # decCost = purchase amount
  {
    inventory_item:       [
      :int_inventory_item_id, "intQOH", :int_inventory_id, :int_inventory_type_id, :dec_cost, :dte_created_date, :dte_modified_date,
      {int_curr_location_id: :entity_id}
    ],
    inventory_item_text:  [:var_serial_number, :var_user_field1, :var_user_field2, :var_user_field3, :var_bin],
    inventory:            [:int_category_id, :int_sub_category_id],
    inventory_text:       [:var_description, :var_part_no, {varUserField1: "varGlRevenue"}, {varUserField2: "varGlCOGSCode"}, {varUserField3: "varPhaseCode"}],
    inventory_id:         ["intInventoryIdID", {varInventoryID: "inventory_idid"}]
  }

end

#default_wheresObject



47
48
49
# File 'lib/toolhound-ruby/inventory_item.rb', line 47

def default_wheres
  [{bolActive: 1 }, {bolDeleted: 0}]
end

#for_entity(entity_id) ⇒ Object



61
62
63
# File 'lib/toolhound-ruby/inventory_item.rb', line 61

def for_entity(entity_id)
  all(where: [{int_curr_location_id: entity_id}])
end

#for_inventory(inventory_id) ⇒ Object



65
66
67
# File 'lib/toolhound-ruby/inventory_item.rb', line 65

def for_inventory(inventory_id)

end