Class: C2eCore::Drops::FinancialReportDrop

Inherits:
BaseDrop
  • Object
show all
Includes:
Helpers::FinancialReportConversions
Defined in:
/build/app/mailers/c2e_core/drops/financial_report_drop.rb

Instance Method Summary collapse

Methods included from Helpers::FinancialReportConversions

#converted_price, #format_price

Constructor Details

#initialize(financial_report) ⇒ FinancialReportDrop

Returns a new instance of FinancialReportDrop.



8
9
10
11
12
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 8

def initialize(financial_report)
  super()
  @financial_report = financial_report
  @payment_types = PaymentType.all.map { |pt| [pt.id, pt] }.to_h
end

Instance Method Details

#currencyObject



64
65
66
67
68
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 64

def currency
  stored_value __method__ do
    CurrencyDrop.new @financial_report.currency
  end
end

#descriptionString

Returns - Description of financial report, which includes reportable type, reportable id and report sequence. E.g.: “CompanyBranch ~ 10 ~ 1”.

Returns:

  • (String)
    • Description of financial report, which includes reportable type, reportable id and report

    sequence. E.g.: “CompanyBranch ~ 10 ~ 1”.



39
40
41
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 39

def description
  @financial_report.description
end

#formatted_total_incomesString

Returns - Sum of all incomes converted to financial report’s currency and formatted. E.g.: "123,45 Kč".

Returns:

  • (String)
    • Sum of all incomes converted to financial report’s currency and formatted.

    E.g.: "123,45 Kč".



92
93
94
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 92

def formatted_total_incomes
  format_price(total_incomes)
end

#formatted_total_with_credit_funds_transfersString

Returns - Formatted sum of all incomes and credit funds transfers values. E.g.: "123,45 Kč".

Returns:

  • (String)
    • Formatted sum of all incomes and credit funds transfers values. E.g.: "123,45 Kč".



147
148
149
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 147

def formatted_total_with_credit_funds_transfers
  format_price(total_with_credit_funds_transfers)
end

#funds_transfersFinancialReportCreditTransferDrop?

Returns - Returns financial report for funds credit transfers as drop object, if any transfer is present.

Returns:



118
119
120
121
122
123
124
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 118

def funds_transfers
  stored_value __method__ do
    next unless @financial_report.has_any_funds_transfers?

    FinancialReportCreditTransferDrop.new @financial_report
  end
end

#grouped_incomesArray[FinancialReportPaymentTypeDrop]

Returns - Array of all incomes statistics from financial report grouped by payment method.

Returns:



74
75
76
77
78
79
80
81
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 74

def grouped_incomes
  @financial_report.grouped_incomes.map do |incomes_element|
    payment_type = @payment_types[incomes_element[:payment_type]]
    value = converted_price(incomes_element.dig(:income, :value))
    orders_count = incomes_element.dig(:orders_count)
    FinancialReportPaymentTypeDrop.new(@financial_report, payment_type, value, orders_count)
  end
end

#grouped_total_with_credit_funds_transfersArray[FinancialReportPaymentTypeDrop]

Returns - Array of statistics on the balance of credit funds transfers and incomes grouped by payment method.

Returns:



130
131
132
133
134
135
136
137
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 130

def grouped_total_with_credit_funds_transfers
  @financial_report.total_balance.map do |incomes_element|
    payment_type = @payment_types[incomes_element[:payment_type]]
    value = incomes_element.dig(:income, :value)
    orders_count = incomes_element.dig(:orders_count)
    FinancialReportPaymentTypeDrop.new(@financial_report, payment_type, value, orders_count)
  end
end

#idInteger

Returns - ID of financial report in database.

Returns:

  • (Integer)
    • ID of financial report in database.



17
18
19
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 17

def id
  @financial_report.id
end

#report_datetimeDateTime

Returns - The date and time when the report was created. E.g.: "2023-11-16T11:38:56+01:00".

Returns:

  • (DateTime)
    • The date and time when the report was created. E.g.: "2023-11-16T11:38:56+01:00"



22
23
24
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 22

def report_datetime
  @financial_report.report_datetime
end

#report_datetime_fromDateTime?

Returns - The date and time from which the report calculations begin. E.g.: "2023-11-16T11:38:56+01:00".

Returns:

  • (DateTime, nil)
    • The date and time from which the report calculations begin.

    E.g.: "2023-11-16T11:38:56+01:00"



28
29
30
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 28

def report_datetime_from
  @financial_report.report_datetime_from
end

#report_sequenceInteger

Returns - Financial report sequence number. E.g.: 142.

Returns:

  • (Integer)
    • Financial report sequence number. E.g.: 142



33
34
35
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 33

def report_sequence
  @financial_report.report_sequence
end

#reportableCashBoxDrop, ...

Returns - Returns the object for which the report was generated (cash box or company branch) as a drop object.

Returns:

  • (CashBoxDrop, CompanyBranchDrop, nil)
    • Returns the object for which the report was generated

    (cash box or company branch) as a drop object.



55
56
57
58
59
60
61
62
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 55

def reportable
  stored_value __method__ do
    reportable_type = @financial_report.reportable_type
    next CashBoxDrop.new(@financial_report.reportable) if reportable_type == CashBox.name

    CompanyBranchDrop.new(@financial_report.reportable) if reportable_type == CompanyBranch.name
  end
end

#terminal_financial_reportTerminalFinancialReportDrop?

Returns - Returns the terminal financial report as a drop object, if it is present.

Returns:



45
46
47
48
49
50
51
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 45

def terminal_financial_report
  stored_value __method__ do
    next if @financial_report.terminal_financial_report.nil?

    TerminalFinancialReportDrop.new(@financial_report.terminal_financial_report)
  end
end

#total_incomesFloat

Returns - Sum of all incomes converted into financial report’s currency. E.g.: 78.

Returns:

  • (Float)
    • Sum of all incomes converted into financial report’s currency. E.g.: 78



84
85
86
87
88
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 84

def total_incomes
  stored_value __method__ do
    converted_price(@financial_report.total_incomes[:value])
  end
end

#total_orders_and_transfers_countInteger

Returns - Number of orders and credit funds transfers. E.g.: 42.

Returns:

  • (Integer)
    • Number of orders and credit funds transfers. E.g.: 42



152
153
154
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 152

def total_orders_and_transfers_count
  @financial_report.total_orders_and_transfers_count
end

#total_orders_and_transfers_storno_countInteger

Returns - Number of canceled orders and canceled credit funds transfers. E.g.: 42.

Returns:

  • (Integer)
    • Number of canceled orders and canceled credit funds transfers. E.g.: 42



157
158
159
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 157

def total_orders_and_transfers_storno_count
  @financial_report.total_orders_and_transfers_storno_count
end

#total_orders_countInteger

Returns - The number of orders that belong to financial report. E.g.: 42.

Returns:

  • (Integer)
    • The number of orders that belong to financial report. E.g.: 42



97
98
99
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 97

def total_orders_count
  @financial_report.total_orders_count
end

#total_storno_countInteger

Returns - The number of canceled orders that belong to financial report. E.g.: 42.

Returns:

  • (Integer)
    • The number of canceled orders that belong to financial report. E.g.: 42



102
103
104
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 102

def total_storno_count
  @financial_report.total_storno_count
end

#total_vat_summarizationArray[FinancialReportVatDrop]

Returns - Array of all VAT statistic from financial report.

Returns:



107
108
109
110
111
112
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 107

def total_vat_summarization
  @financial_report.total_vat_summarization.map do |vat_element|
    value = converted_price(vat_element.dig(:vat, :value, :value))
    FinancialReportVatDrop.new(@financial_report, CountryVat.find(vat_element.dig(:vat, :vat)), value)
  end
end

#total_with_credit_funds_transfersFloat

Returns - Sum of all incomes and credit funds transfers values. E.g.: 78.

Returns:

  • (Float)
    • Sum of all incomes and credit funds transfers values. E.g.: 78



140
141
142
143
144
# File '/build/app/mailers/c2e_core/drops/financial_report_drop.rb', line 140

def total_with_credit_funds_transfers
  stored_value __method__ do
    @financial_report.total_balance_value[:value]
  end
end