Class: PurchasePrice

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

Constant Summary collapse

COMPANY_CODE =
Rails.application.config.company_code
HEADERS =
[
  {
    field: 'effective_from_date',
    type: 'date',
    label: 'Effective from'
  },
  {
    field: 'sku_purchase_price_id',
    type: 'number',
    label: 'Sku Purchase Price Id'
  },
  {
    field: 'sku_id',
    type: 'number',
    label: 'Sku Id'
  },
  {
    field: 'supplier_name',
    type: 'string',
    label: 'Vendor'
  },
  {
    field: 'currency_id',
    type: 'number',
    label: 'Currency Id'
  },
  {
    field: 'currency_code',
    type: 'string',
    label: 'Currency'
  },
  {
    field: 'uom_id',
    type: 'number',
    label: 'UOM Id'
  },
  {
    field: 'price',
    type: 'price',
    label: 'Price'
  },
  {
    field: 'discount',
    type: 'percentage',
    label: 'Discount'
  },
  {
    field: 'minimum_quantity',
    type: 'number',
    label: 'Minimum Quantity'
  },
  {
    field: 'uom_code',
    type: 'string',
    label: 'Unit of measurement'
  }
]

Class Method Summary collapse

Class Method Details

.create_or_update(sku_id:, supplier_key:, currency_id:, uom_id:, effective_from_date:, price:, discount:, product_id:, system_date:, system_user:, id: 0, price_type: 'S', memo: '', category_id: '1', minimum_quantity: 0, landed_cost: 0) ⇒ Object



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

def create_or_update(
  sku_id:, supplier_key:, currency_id:, uom_id:, effective_from_date:, price:, discount:, product_id:, system_date:, system_user:, id: 0,
  price_type: 'S',
  memo: '',
  category_id: '1',
  minimum_quantity: 0,
  landed_cost: 0
)
  ActiveRecord::Base.execute_procedure(
    'pr_insert_update_sku_purchase_price',
    id,
    price_type,
    sku_id,
    supplier_key,
    currency_id,
    uom_id,
    effective_from_date,
    price,
    discount,
    memo,
    product_id,
    category_id,
    minimum_quantity,
    landed_cost,
    system_date,
    system_user
  )
end

.find_by(id:) ⇒ Object



152
153
154
155
156
157
158
159
# File 'app/models/purchase_price.rb', line 152

def find_by(
  id:
)
  ActiveRecord::Base.execute_procedure(
    'pr_get_sku_purchase_price_by_id_web',
    id
  )
end

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



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

def where(
  product_id:,
  company_code: COMPANY_CODE,
  limit: 10,
  query: '',
  offset: 0,
  column_name: '',
  column_dir: '',
  grouping: ''
)

  # returns an array of hashes with these keys:
  # sku_purchase_price_id
  # rowNumber
  # price_type
  # sku_id
  # color_description_english
  # design_description_english
  # size_description_english
  # supplier_key
  # supplier_name
  # currency_id
  # currency_code
  # uom_id
  # uom_code
  # effective_from_date
  # price
  # discount
  # minimum_quantity
  # landed_cost
  # TotalRecords
  # DisplayRecords

  raw_data = ActiveRecord::Base.execute_procedure(
    'pr_get_sku_purchase_price_by_product_by_page_kendo',
    product_id,
    company_code,
    limit,
    query,
    offset,
    column_name,
    column_dir,
    grouping
  )

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

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

  {
    data: raw_data,
    metadata: 
  }
end