Class: Product

Inherits:
Object
  • Object
show all
Defined in:
app/models/product.rb

Constant Summary collapse

COMPANY_CODE =
Rails.application.config.company_code
HEADERS =
[
  {
    field: 'product_id',
    type: 'number',
    label: 'Id'
  },
  {
    field: 'product_code',
    type: 'string',
    label: 'Product code'
  },
  {
    field: 'product_desc_english',
    type: 'string',
    label: 'Name'
  },
  {
    field: 'brand_description',
    type: 'string',
    label: 'Brand'
  },
  {
    field: 'group_description',
    type: 'string',
    label: 'Group'
  },
  {
    field: 'active',
    type: 'boolean',
    label: 'Active'
  }
]

Class Method Summary collapse

Class Method Details

.create_or_update(product_id:, product_code:, description_english:, description_french:, alternate_description:, product_family_id:, brand_id:, brand_category_id:, group_id:, sub_group_id:, season_id:, royalty_id:, default_storage_uom_id:, default_purchase_uom_id:, default_sales_uom_id:, product_category_id:, approved_to_sell:, approved_to_sell_online:, approved_to_purchase:, product_image_filepath:, memo:, active:, city_id:, warranty_days:, sales_order_multiplier:, product_type:, system_date:, system_user:, production_specs_header_id: 0, package_specs_header_id: 0, initiated_by_company: COMPANY_CODE) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/models/product.rb', line 113

def create_or_update(
  product_id:,
  product_code:,
  description_english:,
  description_french:,
  alternate_description:,
  product_family_id:,
  brand_id:,
  brand_category_id:,
  group_id:,
  sub_group_id:,
  season_id:,
  royalty_id:,
  default_storage_uom_id:, default_purchase_uom_id:, default_sales_uom_id:, product_category_id:, approved_to_sell:, approved_to_sell_online:, approved_to_purchase:, product_image_filepath:, memo:, active:, city_id:, warranty_days:, sales_order_multiplier:, product_type:, system_date:, system_user:, production_specs_header_id: 0,
  package_specs_header_id: 0,
  initiated_by_company: COMPANY_CODE
)
  ActiveRecord::Base.execute_procedure(
    'pr_insert_update_product',
    product_id,
    product_code,
    description_english,
    description_french,
    alternate_description,
    product_family_id,
    brand_id,
    brand_category_id,
    group_id,
    sub_group_id,
    season_id,
    royalty_id,
    production_specs_header_id,
    package_specs_header_id,
    default_storage_uom_id,
    default_purchase_uom_id,
    default_sales_uom_id,
    initiated_by_company,
    product_category_id,
    approved_to_sell,
    approved_to_sell_online,
    approved_to_purchase,
    product_image_filepath,
    memo,
    active,
    city_id,
    warranty_days,
    sales_order_multiplier,
    product_type,
    system_date,
    system_user
  )
end

.find_by!(product_id:, text: '', show_active_only: false) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/product.rb', line 96

def find_by!(
  product_id:,
  text: '',
  show_active_only: false
)
  product = ActiveRecord::Base.execute_procedure(
    'pr_get_product_master',
    product_id,
    text,
    show_active_only
  )

  raise ActiveRecord::RecordNotFound if product.blank?

  product
end

.where(limit:, company_code: Rails.application.config.company_code, fields: [], product_id: '', active_only: false, search_value: '', offset: 0, column_name: 'product_code', column_direction: 'asc', groupping: '') ⇒ Object



38
39
40
41
42
43
44
45
46
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/product.rb', line 38

def where(
  limit:, company_code: Rails.application.config.company_code,
  fields: [],
  product_id: '',
  active_only: false,
  search_value: '',
  offset: 0,
  column_name: 'product_code',
  column_direction: 'asc',
  groupping: ''
)
  # returns array of hashes with keys:
  #  "rowNumber",
  #  "product_id", -
  #  "company_code", -
  #  "active", -
  #  "product_code", -
  #  "product_desc_english", -
  #  "brand_code", -
  #  "brand_description", -
  #  "group_code", -
  #  "group_description", -
  #  "sub_group_code", -
  #  "sub_group_description", -
  #  "product_family_desc", -
  #  "sql_search_string",
  #  "DisplayRecords",
  #  "TotalRecords"
  #
  raw_data = ActiveRecord::Base.execute_procedure(
    'pr_get_products_by_page_kendo',
    company_code,
    product_id,
    active_only,
    limit,
    search_value,
    offset,
    column_name,
    column_direction,
    groupping
  )

  data = raw_data.map do |product|
    product.select { |key, _| fields.include?(key) }
  end

   = {
    total: raw_data.length > 0 ? raw_data.first['TotalRecords'] : 0,
    limit: limit,
    offset: offset
  }

  {
    data: data,
    metadata: 
  }
end