Class: PayrollInvoice

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payroll_invoice_header_id) ⇒ PayrollInvoice

Returns a new instance of PayrollInvoice.



4
5
6
# File 'app/models/payroll_invoice.rb', line 4

def initialize(payroll_invoice_header_id)
  @payroll_invoice_header_id = payroll_invoice_header_id
end

Instance Attribute Details

#payroll_invoice_header_idObject (readonly)

Returns the value of attribute payroll_invoice_header_id.



2
3
4
# File 'app/models/payroll_invoice.rb', line 2

def payroll_invoice_header_id
  @payroll_invoice_header_id
end

Class Method Details

.find_by(payroll_invoice_header_id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'app/models/payroll_invoice.rb', line 17

def find_by(payroll_invoice_header_id)
  header = PayrollInvoiceHeader.where_procedure(payroll_invoice_header_id)
  details = PayrollInvoiceDetails.where_procedure(payroll_invoice_header_id)

  {
    header: header,
    details: details
  }
end

.find_by_page(company_id:, display_length:, search_value: '', display_start_from_no: 0, grouping: 'payroll_invoice_header_id desc') ⇒ Object



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

def find_by_page(
  company_id:,
  display_length:,
  search_value: '',
  display_start_from_no: 0,
  grouping: 'payroll_invoice_header_id desc'
)
  # Fetch paginated invoice headers
  paginated_headers = PayrollInvoiceHeader.find_by_page(
    company_id: company_id,
    display_length: display_length,
    search_value: search_value,
    display_start_from_no: display_start_from_no,
    grouping: grouping
  )

  # Extract header IDs from results
  payroll_invoice_header_ids = paginated_headers.map { |header| header[:payroll_invoice_header_id] }.uniq

  # Fetch details for all retrieved invoice headers
  payroll_invoice_details = payroll_invoice_header_ids.index_with do |header_id|
    PayrollInvoiceDetails.where_procedure(header_id)
  end

  # Return combined results
  {
    headers: paginated_headers,
    details: payroll_invoice_details
  }
end

Instance Method Details

#detailsObject



12
13
14
# File 'app/models/payroll_invoice.rb', line 12

def details
  PayrollInvoiceDetails.where_procedure(payroll_invoice_header_id)
end

#headerObject



8
9
10
# File 'app/models/payroll_invoice.rb', line 8

def header
  PayrollInvoiceHeader.where_procedure(payroll_invoice_header_id)
end