Class: SaleOrder

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

Class Method Summary collapse

Class Method Details

.cancel_procedure(sales_order_header_id:, deletion_reason:, memo:, user:) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'app/models/sale_order.rb', line 202

def cancel_procedure(
  sales_order_header_id:,
  deletion_reason:,
  memo:,
  user:
)
  ActiveRecord::Base.execute_procedure(
    'pr_cancel_sales_order_header',
    sales_order_header_id,
    deletion_reason,
    memo,
    user
  )[0]
end

.cancellation_reasonsObject



238
239
240
241
242
243
# File 'app/models/sale_order.rb', line 238

def cancellation_reasons
  TypesMaster
    .select(:types_id, :type, :type_description, :description_french)
    .where(element: 'DELETION REASON')
    .order(:sort_order)
end

.create_or_update_proceudre(sales_order_header_id:, edi_850_header_id:, marketplace_id:, po_no:, po_release_no:, po_type:, po_merchandise_type:, po_department:, order_type:, order_stage:, order_date:, required_date:, cancel_date:, must_arrive_by_date:, accept_back_order:, edi_currency_code:, currency_id:, exchange_rate:, edi_payment_term:, payment_term_id:, edi_freight_term:, freight_term_id:, edi_shipping_company:, ship_via_id:, ship_from_warehouse_id:, shipment_no:, invoice_no:, gl_register_no:, hold_reason:, deletion_reason:, salesman_key:, credit_reason_id:, ar_invoice_header_id:, ar_invoice_detail_id:, memo:, user:) ⇒ Object



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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'app/models/sale_order.rb', line 99

def create_or_update_proceudre(
  sales_order_header_id:,
  edi_850_header_id:,
  marketplace_id:,
  po_no:,
  po_release_no:,
  po_type:,
  po_merchandise_type:,
  po_department:,
  order_type:,
  order_stage:,
  order_date:,
  required_date:,
  cancel_date:,
  must_arrive_by_date:,
  accept_back_order:,
  edi_currency_code:,
  currency_id:,
  exchange_rate:,
  edi_payment_term:,
  payment_term_id:,
  edi_freight_term:,
  freight_term_id:,
  edi_shipping_company:,
  ship_via_id:,
  ship_from_warehouse_id:,
  shipment_no:,
  invoice_no:,
  gl_register_no:,
  hold_reason:,
  deletion_reason:,
  salesman_key:,
  credit_reason_id:,
  ar_invoice_header_id:,
  ar_invoice_detail_id:,
  memo:,
  user:
)
  result = ActiveRecord::Base.execute_procedure(
    'pr_insert_update_sales_order_header',
    sales_order_header_id,
    edi_850_header_id,
    marketplace_id,
    po_no,
    po_release_no,
    po_type,
    po_merchandise_type,
    po_department,
    order_type,
    order_stage,
    order_date,
    required_date,
    cancel_date,
    must_arrive_by_date,
    accept_back_order,
    edi_currency_code,
    currency_id,
    exchange_rate,
    edi_payment_term,
    payment_term_id,
    edi_freight_term,
    freight_term_id,
    edi_shipping_company,
    ship_via_id,
    ship_from_warehouse_id,
    shipment_no,
    invoice_no,
    gl_register_no,
    hold_reason,
    deletion_reason,
    salesman_key,
    credit_reason_id,
    ar_invoice_header_id,
    ar_invoice_detail_id,
    memo,
    user
  )[0]

  SaleOrder.find_by(sale_order_id: result['sales_order_header_id'])
end

.find_by(sale_order_id:) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'app/models/sale_order.rb', line 180

def find_by(
  sale_order_id:
)
  headers = ActiveRecord::Base.execute_procedure(
    'pr_get_sales_order_header',
    sale_order_id
  )

  raise ActiveRecord::RecordNotFound if headers.blank?

  details = ActiveRecord::Base.execute_procedure(
    'pr_get_sales_order_details',
    sale_order_id,
    0 # sales_order_detail_id
  )

  {
    header: headers.first,
    details: details
  }
end

.stagesObject



231
232
233
234
235
236
# File 'app/models/sale_order.rb', line 231

def stages
  TypesMaster
    .select(:types_id, :type, :type_description, :description_french)
    .where(element: 'SO STAGE', active: true)
    .order(:sort_order)
end

.verify_procedure(sales_order_header_id:) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'app/models/sale_order.rb', line 217

def verify_procedure(sales_order_header_id:)
  result = ActiveRecord::Base.execute_procedure(
    'pr_verify_sales_order',
    sales_order_header_id
  )

  result.each do |data|
    data[:status] = data[:verification_status_description].starts_with?('Success') ? 'success' : 'failure'
    data[:verification_status_description] = data[:verification_status_description].split(' - ')[1].to_s
  end

  result.sort_by! { |data| data[:status] }
end

.where(company_code: Rails.application.config.company_code, fields: [], marketplace_id: 1, order_date_from: '2017-01-01', order_date_to: '2017-01-10', limit: 10, search_value: '', offset: 0, column_name: 'sales_order_header_id', column_dir: 'asc', grouping: 'sales_order_header_id desc', so_stage: '0', so_type: '0', warehouse_id: nil) ⇒ Object



3
4
5
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
33
34
35
36
37
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
95
96
97
# File 'app/models/sale_order.rb', line 3

def where(
  company_code: Rails.application.config.company_code,
  fields: [],
  marketplace_id: 1,
  order_date_from: '2017-01-01',
  order_date_to: '2017-01-10',
  limit: 10,
  search_value: '',
  offset: 0,
  column_name: 'sales_order_header_id',
  column_dir: 'asc',
  grouping: 'sales_order_header_id desc',
  so_stage: '0',
  so_type: '0',
  warehouse_id: nil
)
  # returns array of hashes with keys:
  #
  # "sales_order_header_id",
  # "order_number",
  # "revision_number",
  # "marketplace_id",
  # "marketplace_code",
  # "customer_order_number",
  # "order_type",
  # "order_type_description_english",
  # "order_stage",
  # "order_stage_description_english",
  # "order_date",
  # "required_date",
  # "cancel_date",
  # "ship_date",
  # "store_customer_id",
  # "filling_percentage",
  # "actual_filling_percentage",
  # "quantity_ordered",
  # "distribution_customer_id",
  # "invoice_number",
  # "order_promotion_type",
  # "order_promotion_type_description",
  # "head_office_key",
  # "ship_to_key",
  # "salesman_key",
  # "ar_invoice_header_id",
  # "ship_from_warehouse_id",
  # "count_of_order_comments",
  # "count_of_order_attachments",
  # "store_code",
  # "head_office_customer_id",
  # "store_name",
  # "bill_to_code",
  # "bill_to_name",
  # "ship_via_id",
  # "ship_via_code",
  # "ship_via_name",
  # "ship_to_code",
  # "ship_to_name",
  # "picking_slip_printed",
  # "packing_slip_printed",
  # "commission",
  # "DisplayRecords",
  # "TotalRecords"

  raw_data = ActiveRecord::Base.execute_procedure(
    'pr_get_sales_order_header_by_page_kendo',
    company_code,
    marketplace_id,
    order_date_from,
    order_date_to,
    limit,
    search_value,
    offset,
    column_name,
    column_dir,
    grouping,
    so_stage,
    so_type,
    warehouse_id
  )

  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