class Toolhound::PurchaseReceipt

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

Public Instance Methods

all(options = {}) click to toggle source
# 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_joins() click to toggle source
# 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_selects() click to toggle source
# 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