Class: Toolhound::PurchaseReceipt

Inherits:
Base
  • Object
show all
Defined in:
lib/toolhound-ruby/purchase_receipt.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

#client, #connection

Instance Method Summary collapse

Methods inherited from Base

#_build_joins, #_build_selects, #_build_where, #build_and_query, #build_group, #build_joins, #build_selects, #build_sql, #build_update_attributes, #build_update_sql, #build_where, #default_wheres, #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, #update, #update_query

Methods included from Util

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

Constructor Details

This class inherits a constructor from Toolhound::Base

Instance Method Details

#all(options = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/toolhound-ruby/purchase_receipt.rb', line 47

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

  from    = options.delete(:from)
  to      = options.delete(:to)
  fixed   = options.delete(:fixed_assets)
  consumable = options.delete(:consumable)
  wheres  = []

  selects = default_selects
  joins   = default_joins

  # wheres << "tblInventoryReceipt.dteReceivedDate BETWEEN '#{parse_time(from)}' AND '#{parse_time(to)}'" if from && to
  wheres << {"inventory_receipt.dte_received_date" => {value: [parse_time(from), parse_time(to)], op: :between} } if from && to
  wheres <<  "(
   	  (tblInventoryType.bolSerialized = 1 AND tblInventoryReceiptDetail.decCost > 1499.00) OR
   	  (tblInventoryType.bolBulk = 1 AND (tblInventoryReceiptDetail.decCost * tblInventoryReceiptDetail.intReceivedQty) > 20000.00)
    )" if fixed

  wheres << {"inventory_type.bol_consumable" => {value: 1}} if consumable

  build_and_query(
    joins: joins,
    selects: selects,
    where: wheres,
    from: 'tblInventoryReceiptDetail'
  )

end

#default_joinsObject



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

def default_joins
  arr = []
  arr << "INNER JOIN tblInventoryReceipt ON tblInventoryReceipt.intInventoryReceiptID = tblInventoryReceiptDetail.intInventoryReceiptID"
  arr << "INNER JOIN tblInventoryReceiptText ON tblInventoryReceiptText.intInventoryReceiptID = tblInventoryReceipt.intInventoryReceiptID AND tblInventoryReceiptText.varLocaleID = '#{locale}'"
  arr << "INNER JOIN tblPurchaseOrder ON tblPurchaseOrder.intPOID = tblInventoryReceipt.intPOID"
  arr << "LEFT OUTER JOIN tblVendor ON tblVendor.intVendorID = tblInventoryReceipt.intVendorID"
  arr << "LEFT OUTER JOIN tblVendorText ON tblVendor.intVendorID = tblVendorText.intVendorID"
  arr << "INNER JOIN tblInventoryID ON tblInventoryID.intInventoryIdID = tblInventoryReceiptDetail.intInventoryIDID"
  arr << "INNER JOIN tblInventory ON tblInventoryID.intInventoryID = tblInventory.intInventoryID"
  arr << "INNER JOIN tblInventoryText ON tblInventoryText.intInventoryID = tblInventory.intInventoryID AND tblInventoryText.varLocaleID = '#{locale}'"
  arr << "INNER JOIN tblInventoryType ON tblInventoryType.intInventoryTypeID = tblInventory.intInventoryTypeID"

  arr
end

#default_selectsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/toolhound-ruby/purchase_receipt.rb', line 11

def default_selects
  {
    inventory: [:int_category_id, :int_sub_category_id],
    inventory_type: [:bol_serialized, :bol_bulk, :bol_consumable],
    inventory_text: [:var_part_no, :var_description, {varUserField1: "varGlRevenue"}, {varUserField2: "varGlCOGSCode"}, {varUserField3: "varPhaseCode"}],
    inventory_receipt_detail: [
      :int_inventory_receipt_detail_id, :int_received_qty, :var_serial_number, :dec_cost, 'intInventoryIDID',
      {"(ISNULL(tblInventoryReceiptDetail.intReceivedQty, 0) * ISNULL(tblInventoryReceiptDetail.decCost, 0))" => {raw: true, as: :dec_total_cost}}
    ],
    inventory_id: [{var_inventory_id: "varInventoryIdNo"}],
    purchase_order: [{"varPONO" => :po_no}],
    inventory_receipt_text: [:var_notes],
    inventory_receipt: [
      :int_inventory_receipt_id, {'intPOID' => :po_id}, :var_receipt_no, :var_invoice_number, :dte_created_date, :dte_modified_date,
      :dte_received_date, :int_vendor_id
    ],
    vendor: [{var_vendor_id: "varVendorNo"}],
    vendor_text: [:var_organization]
  }
end