Class: Customer

Inherits:
ApplicationRecord show all
Includes:
CustomerProcedures, HasAddress, HasProvince
Defined in:
app/models/customer.rb

Constant Summary collapse

ENTITY_TYPE =
'C'.freeze

Constants included from CustomerProcedures

CustomerProcedures::HEADERS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasAddress

#address, #comma_separated_address, #line_separated_address, #space_separated_address

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Class Method Details

.store_translations_table_data(head_office_key:, offset:, limit:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/customer.rb', line 22

def self.store_translations_table_data(
  head_office_key:,
  offset:,
  limit:
)
  query = <<-SQL
    SELECT
      c.customer_id AS partner_id,
      c.code AS code,
      c.name AS name,
      c.edi_store_code AS edi_store_code,
      c.address_line1 AS address_line1,
      c.address_line2 AS address_line2,
      c.city AS city,
      c.hierarchy AS hierarchy,
      c.postal_code AS postal_code,
      c.active AS active
    FROM
      customers c
    WHERE
      c.belongs_to_ho_id = ?
    ORDER BY
      c.customer_id
    OFFSET ? ROWS
    FETCH NEXT ? ROWS ONLY;
  SQL

  Customer.find_by_sql([query, head_office_key, offset, limit])
end

Instance Method Details

#edi_partnerObject



14
15
16
# File 'app/models/customer.rb', line 14

def edi_partner
  EdiPartner.find_by(entity_type: ENTITY_TYPE, head_office_id: customer_id)
end

#edi_sku_translationsObject



18
19
20
# File 'app/models/customer.rb', line 18

def edi_sku_translations
  EdiSkuTranslation.where(translation_type: ENTITY_TYPE, customer_supplier_id: customer_id)
end

#entity_typeObject



52
53
54
# File 'app/models/customer.rb', line 52

def entity_type
  ENTITY_TYPE
end