Class: SalePrice

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

Constant Summary collapse

COMPANY_CODE =
Rails.application.config.company_code
HEADERS =
[
  {
    field: 'customer_name',
    type: 'string',
    label: 'Marketplace'
  },
  {
    field: 'effective_from_date',
    type: 'date',
    label: 'Effective from'
  },
  {
    field: 'sku_sale_price_id',
    type: 'number',
    label: 'Sku Sale Price Id'
  },
  {
    field: 'sku_id',
    type: 'number',
    label: 'Sku Id'
  },
  {
    field: 'currency_id',
    type: 'number',
    label: 'Currency Id'
  },
  {
    field: 'currency_description_english',
    type: 'string',
    label: 'Currency'
  },
  {
    field: 'price',
    type: 'price',
    label: 'Price'
  },
  {
    field: 'discount',
    type: 'percentage',
    label: 'Discount'
  },
  {
    field: 'uom_id',
    type: 'number',
    label: 'UOM Id'
  },
  {
    field: 'uom_code',
    type: 'string',
    label: 'Unit of measurement'
  }
]

Class Method Summary collapse

Class Method Details

.create_or_update_sale_price(sku_id:, currency_id:, uom_id:, effective_from_date:, price:, discount:, product_id:, system_date:, system_user:, sku_sale_price_id: 0, price_type: 'S', customer_key: 3, memo: nil, category_id: 1, minimum_quantity: 1) ⇒ Object



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
# File 'app/models/sale_price.rb', line 130

def create_or_update_sale_price(
  sku_id:, currency_id:, uom_id:, effective_from_date:, price:, discount:, product_id:, system_date:, system_user:, sku_sale_price_id: 0,
  price_type: 'S',
  customer_key: 3,
  memo: nil,
  category_id: 1,
  minimum_quantity: 1
)
  ActiveRecord::Base.execute_procedure(
    'pr_insert_update_sku_sale_price',
    sku_sale_price_id,
    price_type,
    sku_id,
    customer_key,
    currency_id,
    uom_id,
    effective_from_date,
    price,
    discount,
    memo,
    product_id,
    category_id,
    minimum_quantity,
    system_date,
    system_user
  )
end

.where(product_id: '', company_code: COMPANY_CODE, column_name: 'effective_from_date', column_dir: 'desc', limit: 10, offset: 0, query: '') ⇒ Object



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
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
127
128
# File 'app/models/sale_price.rb', line 58

def where(
  product_id: '',
  company_code: COMPANY_CODE,
  column_name: 'effective_from_date',
  column_dir: 'desc',
  limit: 10,
  offset: 0,
  query: ''
)
  # returns array of hashes with keys:
  # sku_sale_price_id
  # company_code
  # price_type
  # sku_id
  # customer_key -> marketplace_id
  # customer_name -> marketplace_name
  # currency_id
  # currency_code
  # currency_description_english
  # currency_description_french
  # uom_id
  # effective_from_date
  # price
  # discount
  # minimum_quantity
  # color_id
  # color_description_english
  # color_description_french
  # design_id
  # design_description_english
  # design_description_french
  # size_id
  # size_description_english
  # size_description_french
  # creation_date
  # created_by
  # modification_date
  # modified_by
  # record_modified
  # memo
  # uom_code

  raw_data = ActiveRecord::Base.execute_procedure(
    'pr_get_sku_price_by_product',
    product_id,
    company_code
  )

  if query.present?
    raw_data = raw_data.select do |row|
      row.any? do |_key, value|
        value.to_s.downcase.include?(query.downcase)
      end
    end
  end

  raw_data = raw_data.sort_by { |row| row[column_name] }
  raw_data = raw_data.reverse if column_dir == 'desc'

  data = raw_data.drop(offset).take(limit)
   = {
    total: raw_data.length,
    limit: limit,
    offset: offset
  }

  {
    data: data,
    metadata: 
  }
end