Class: SkuSalePriceController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sku_sale_price_controller.rb

Instance Method Summary collapse

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#create_or_updateObject



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
# File 'app/controllers/sku_sale_price_controller.rb', line 46

def create_or_update
  sku_sale_price_id = params[:sku_sale_price_id]
  sku_id = params[:sku_id]
  company_id = params[:company_id]
  currency_id = params[:currency_id]
  uom_id = params[:uom_id]
  effective_from_date = params[:effective_from_date]
  price = params[:price]
  discount = params[:discount]
  user = params[:user] || 'Admin'

  SkuSalePrice.create_or_update_procedure(
    sku_sale_price_id: sku_sale_price_id,
    sku_id: sku_id,
    company_id: company_id,
    currency_id: currency_id,
    uom_id: uom_id,
    effective_from_date: effective_from_date,
    price: price,
    discount: discount,
    user: user
  )

  render json: { message: 'SKU sale price inserted/updated successfully',
                 redirect_to: "/app/settings/products_services/#{params[:sku_id]}/notes" }
end

#duplicate_errorObject



73
74
75
76
# File 'app/controllers/sku_sale_price_controller.rb', line 73

def duplicate_error
  render json: { message: I18n.t('payroll.system_parameters.validations.sku_price_record_duplicate') },
         status: :unprocessable_entity
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/sku_sale_price_controller.rb', line 6

def index
  sku_sale_price_id = params[:sku_sale_price_id]
  sku_id = params[:sku_id]
  company_id = params[:company_id]
  currency_id = params[:currency_id]
  uom_id = params[:uom_id]
  effective_date = params[:effective_date]
  language = params[:language]

  result = SkuSalePrice.where_procedure(
    sku_sale_price_id: sku_sale_price_id,
    sku_id: sku_id,
    company_id: company_id,
    currency_id: currency_id,
    uom_id: uom_id,
    effective_date: effective_date,
    language: language
  )

  translated_result = result.map do |row|
    row.merge(
      'company_name' => I18n.locale == :fr ? row['company_french_name'] : row['company_english_name']
    )
  end

  render json: translated_result
end

#showObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/sku_sale_price_controller.rb', line 34

def show
  sku_id = params[:id]
  result = SkuSalePrice.find_procedure(sku_id)
  translated_result = result.map do |row|
    row.merge(
      'company_name' => I18n.locale == :fr ? row['company_french_name'] : row['company_english_name'],
      'currency_name' => I18n.locale == :fr ? row['currency_french_name'] : row['currency_english_name']
    )
  end
  render json: translated_result
end