Class: PayrollInvoicesController
Instance Method Summary
collapse
#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_update_detail ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/payroll_invoices_controller.rb', line 56
def create_or_update_detail
detail = detail_params
new_update_detail = PayrollInvoiceDetails.create_or_update_procedure(
payroll_invoice_detail_id: detail[:payroll_invoice_detail_id],
payroll_invoice_header_id: detail[:payroll_invoice_header_id],
sku_id: detail[:sku_id],
uom_id: detail[:uom_id],
quantity: detail[:quantity],
price: detail[:price],
discount_percentage: detail[:discount_percentage],
final_sale_price: detail[:final_sale_price],
memo: detail[:memo],
user: detail[:user]
)
render json: {
message: 'Payroll invoice detail created or updated successfully',
redirect_to: "/app/settings/payroll_invoices/#{detail[:payroll_invoice_header_id]}/details"
}, status: :ok
rescue StandardError => e
render json: { error: 'Failed to create or update payroll invoice detail', details: e.message },
status: :unprocessable_entity
end
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/payroll_invoices_controller.rb', line 39
def
=
= PayrollInvoiceHeader.create_or_update_procedure(**.to_h.symbolize_keys)
= .first if .is_a?(Array)
if
message = [:payroll_invoice_header].present? ? 'Payroll invoice header updated successfully' : 'Payroll invoice header created successfully'
render json: {
message: message,
header: ,
redirect_to: "/app/settings/payroll_invoices/#{[:payroll_invoice_header]}/details"
}, status: :ok
else
render json: { error: 'Failed to create or update payroll invoice header' }, status: :unprocessable_entity
end
end
|
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/payroll_invoices_controller.rb', line 27
def form
render json: {
payment_terms: PaymentTerms.select(:description, :code, :payment_term_id).order(:description),
uoms: UnitOfMeasurement.select(:code, :unit_of_measurement_id, :description).order(:code),
skus: SkuMasterView.select(:sku_id, :sku_code, :description_english, :description_french,
:unit_of_measurement_id).where(active: 1)
.order(:sku_code).as_json(
methods: [:type_description]
)
}
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'app/controllers/payroll_invoices_controller.rb', line 5
def index
invoices = PayrollInvoice.find_by_page(
company_id: params[:company_id].to_i,
display_length: params[:display_length].to_i,
search_value: params[:search_value] || '',
display_start_from_no: params[:display_start_from_no].to_i,
grouping: params[:grouping] || 'payroll_invoice_header_id desc'
)
render json: invoices, status: :ok
end
|
#show ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/payroll_invoices_controller.rb', line 17
def show
invoice = PayrollInvoice.find_by(params[:id].to_i)
if invoice
render json: invoice
else
render json: { error: 'Invoice not found' }, status: :not_found
end
end
|
#update_from_table_edits ⇒ Object
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
|
# File 'app/controllers/payroll_invoices_controller.rb', line 81
def update_from_table_edits
request.params[:rows_edits].each do |row_edits|
row_hash = row_edits[:rowHash]
edits = row_edits[:edits]
PayrollInvoiceDetails.create_or_update_procedure(
payroll_invoice_detail_id: row_hash[:payroll_invoice_detail_id],
payroll_invoice_header_id: row_hash[:payroll_invoice_header_id],
sku_id: row_hash[:sku_id],
uom_id: row_hash[:uom_id],
quantity: edits[:quantity] || row_hash[:quantity],
price: edits[:price] || row_hash[:price],
discount_percentage: 0,
final_sale_price: edits[:price] || row_hash[:price],
memo: edits[:memo] || row_hash[:memo],
user: current_user.user_name
)
end
render json: {
message: 'Payroll invoice detail created or updated successfully',
redirect_to: "/app/settings/payroll_invoices/#{request.params[:rows_edits][0][:rowHash][:payroll_invoice_header_id]}/details"
}, status: :ok
rescue ActiveRecord::RecordInvalid => e
render json: {
message: e.record.errors.full_messages.join(', ')
}, status: :bad_request
end
|